source: WorldVistAEHR/trunk/r/DSS_EXTRACTS-ECX/ECXSETUP.m@ 724

Last change on this file since 724 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.3 KB
Line 
1ECXSETUP ;ALB/JAP,BIR/DMA,CML,PTD-Generate Patient Population for a Given Day ; [ 11/25/96 11:26 AM ]
2 ;;3.0;DSS EXTRACTS;**11,8,24**;Dec 22, 1997
3EN ;entry point from option
4 ;Pick a day, find everyone who was in the hospital on that day,
5 ;find the corresponding admission and the last transfer and treating
6 ;speciality change
7 ;This routine should only be run once
8 I '$D(DT) S DT=$$HTFM^XLFDT(+$H)
9 I $P($G(^ECX(728,1,"S")),U,2)]"" W !,"The setup extract is already running.",! Q
10 I $P($G(^ECX(728,1,"S")),U) W !,"The setup extract has already been run.",! Q
11 W !!,"This option will extract the admission data and data for the last",!,"transfer and treating specialty change for all patients who",!,"were in the hospital on the day you select.",!!
12 W !!,"NOTE - This will generate a snapshot of your inpatient population on the",!,"BEGINNING of the day you select, not the end of the day as MAS reports do.",!
13 W "For example, for the inpatient setup extract if you choose October 1, 1994,",!,"the report will start at midnight at the beginning of the day."
14 W " For the MAS",!,"report, you would choose September 30, 1994. The MAS report begins at midnight",!,"at the end of the day.",!!!
15 S Y=$E(DT,1,3) S:'$E(DT,4) Y=Y-1 S ECDEX=$$FMTE^XLFDT(Y_"1001")
16DATE S DIR(0)="D^::EXP",DIR("A")="Select the starting date ",DIR("B")=ECDEX D ^DIR K DIR G END:$D(DIRUT) S ECED=Y I Y>DT W !,"Date must be in the past",! G DATE
17 S ECDEX=$$FMTE^XLFDT(Y)
18 S ZTSAVE("ECED")="",ZTDESC="Find all inpatients on "_ECDEX,ZTIO="",ZTRTN="START^ECXSETUP" D ^%ZTLOAD
19 I $D(ZTSK) W !,"Request queued as Task #",ZTSK,".",!
20 G END
21 ;
22START ;queued entry point
23 I $G(^ECX(728,1,"S"))]"",$G(^("S"))'="^" Q ;already running or finished
24 S $P(^ECX(728,1,"S"),U,2)="R" ; set run flag
25 K ECXDD D FIELD^DID(405,.19,,"SPECIFIER","ECXDD") S ECPRO=$E(+$P(ECXDD("SPECIFIER"),"P",2)) K ECXDD
26 S ECPACK="Admission setup",ECPIECE=13,ECRTN="START^ECXSETUP",ECGRP="ADMS",ECHEAD="ADM",ECFILE=727.82,ECSD=ECED,ECD=ECED,ECVER=7
27 S ECINST=+$P(^ECX(728,1,0),U) K ECXDIC S DA=ECINST,DIC="^DIC(4,",DIQ(0)="I",DIQ="ECXDIC",DR=".01;99"
28 D EN^DIQ1 S ECINST=$G(ECXDIC(4,DA,99,"I")) K DIC,DIQ,DA,DR,ECXDIC
29 S ECRN=0,QFLG=0
30 S ECD0=9999999.9999999-ECD
31 K ^TMP($J)
32 F DFN=0:0 S DFN=$O(^DGPM("ATID1",DFN)) Q:'DFN S EC1=$O(^(DFN,ECD0)) I EC1 S ECDA=+$O(^(EC1,0)) I $D(^DGPM(ECDA,0)) D Q:QFLG
33 .S EC=^(0),ECX=+$P(EC,U,17),ECAS=$P(EC,U,18)=40 D:$S('ECX:1,'$D(^DGPM(ECX,0)):1,^DGPM(ECX,0)>ECD:1,1:0) GET I ECAS D GET1
34 I QFLG S ZTSTOP=1 G END
35 S ECLAST=$O(^ECX(ECFILE,999999999),-1),ECTOTAL=$P(^ECX(ECFILE,0),U,4)+ECRN,$P(^(0),U,3,4)=ECLAST_U_ECTOTAL K ECLAST,ECTOTAL
36 G ^ECXSETU1
37END K DIR,ECD,ECDEX,X,Y,ECD0,DFN,DA,EC0
38 Q
39 ;
40GET ;
41 Q:'$D(^DPT(DFN,0))
42 S D0=^DPT(DFN,0)
43 Q:$E($P(D0,U,9),1,5)="00000"
44 S ECAD=$P(EC,U),^TMP($J,DFN,ECDA)=""
45 S ECTM=$$ECXTIME^ECXUTL(ECAD),ECXYM=$$ECXYM^ECXUTL(ECED)
46 S X=$$PRIMARY^ECXUTL2(DFN,ECD),ECPTTM=$P(X,U,1),ECPTPR=$P(X,U,2)
47 S ECODE=DFN_U_$P(D0,U,9)_U_$E($P($P(D0,U),",")_" ",1,4)_"^3^"_$$ECXDATE^ECXUTL(ECAD,ECXYM)_U_ECPTTM
48 S ECODE=ECODE_U_$P(D0,U,2)_U_$$ECXDOB^ECXUTL($P(D0,U,3))_U_$P(D0,U,8)_U_$P($G(^DPT(DFN,.311)),U,15)_U_+$$INSURED^IBCNS1(DFN,ECD)
49 S D1=$G(^DPT(DFN,.11)),ECSTA=$P(D1,U,5),STATE=$S(ECSTA:$P(^DIC(5,ECSTA,0),U,3),1:"")
50 S ECCTY=$P(D1,U,7),COUNTY=$S(ECCTY:$P(^DIC(5,ECSTA,1,ECCTY,0),U,3),1:"")
51 S ECODE=ECODE_U_STATE_U_COUNTY_U_$P(D1,U,6),D1=$P($G(^DIC(8,+$G(^DPT(DFN,.36)),0)),U,9) I D1 S D1=$C(D1+64)
52 S ECM=$P($G(^DG(408.32,+$P(D0,U,14),0)),U,2)
53 S ECODE=ECODE_U_D1_U_$P($G(^DPT(DFN,"VET")),U)_U_$P($G(^DPT(DFN,.321))_"^^^^",U,1,3)_U_$P($G(^DPT(DFN,.52)),U,5)_U_$P($G(^DIC(21,+$P($G(^DPT(DFN,.32)),U,3),0)),U,3)_U_ECM_U_$P(D0,U,5)
54 S W=$P(EC,U,6),FAC=$P($G(^DIC(42,+W,0)),U,11),W=$P($G(^DIC(42,+W,44)),U)
55 S ECTS="" F J=1:1:100 S ECT1=$G(^DGPM(ECDA+J,0)) I $P(ECT1,U,14)=ECDA,$P(ECT1,U,2)=6 S ECTS=ECT1 Q
56 ;get corresponding Treating specialty - should be the next one, but must be close
57 S ECODE=FAC_U_ECODE_U_W_U_$P($G(^DIC(45.7,+$P(ECTS,U,9),0)),U,2)_U_ECPRO_$P(ECTS,U,19)_U_ECDA
58 S (ECDRG,ECDIA)="",ECPTF=+$P(EC,U,16) I ECPTF,$D(^DGPT(ECPTF,"M")) D PTF S ECODE=ECODE_U_ECDRG_U_ECDIA
59 S $P(ECODE,U,31)=ECTM,$P(ECODE,U,32)=ECPTPR,$P(ECODE,U,33)=$P($G(^DIC(10,+$P(D0,U,6),0)),U,2)_"^"
60 ;facility^dfn^ssn^name^in/out^day^primary care team^sex^dob^religion^employment status^health ins^state^county^zip^eligibility^
61 ;vet^vietnam^agent orange^radiation^pow^period of service^means test^marital status^ward^treating specialty^
62 ;attending physician^mov #^DRG^diagnosis^time^primary care provider^race
63FILE ;file record
64 S EC7=$O(^ECX(ECFILE,999999999),-1),EC7=EC7+1
65 S ^ECX(ECFILE,EC7,0)=EC7_U_ECXYM_U_U_ECODE,ECRN=ECRN+1
66 S $P(^ECX(ECFILE,EC7,1),U,12)=""
67 S DA=EC7,DIK="^ECX("_ECFILE_"," D IX^DIK K DIK,DA
68 I $D(ZTQUEUED),ECRN>499,'(ECRN#500),$$S^%ZTLOAD S QFLG=1
69 Q
70 ;
71GET1 ;look again for admission if the one we found was ASIH (ECAS=1)
72 F EC1=EC1:0 S EC1=$O(^DGPM("ATID1",DFN,EC1)) Q:'EC1 S ECDA=$O(^(EC1,0)) I ECDA,$D(^DGPM(ECDA,0)) S EC=^DGPM(ECDA,0) I $P(EC,U,18)'=40 S ECX=$P(EC,U,17) Q
73 I EC1,ECDA,$S('ECX:1,'$D(^DGPM(ECX,0)):1,^DGPM(ECX,0)>ECD:1,1:0) D GET ; find the admission movement (not ASIH) for this ASIH movement
74 Q
75 ;
76 ;
77PTF ; get admitting DRG and diagnosis from PTF
78 ;use number for DRG and .01 for diagnosis
79 S EC=1 I $D(^DGPT(ECPTF,"M",2,0)) S EC=2
80 S EC2=+$P(^DGPT(ECPTF,"M",EC,0),U,5),ECDRG=$P($G(^DGPT(ECPTF,"M",EC,"P")),U)
81 S ECDIA=$P($G(^ICD9(EC2,0)),U) Q
82 ;
83 ;
Note: See TracBrowser for help on using the repository browser.