source: FOIAVistA/trunk/r/MASTER_PATIENT_INDEX_VISTA-MPIF/MPIFQUE3.m@ 1061

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

initial load of FOIAVistA 6/30/08 version

File size: 7.9 KB
Line 
1MPIFQUE3 ;SF/TNV-Generate Batch message for comparison of CMOR score ;FEB 27, 1998
2 ;;1.0; MASTER PATIENT INDEX VISTA ;**1,3**;30 Apr 99
3 ;
4COMP ; Create a batch CMOR request for comparing the CMOR score with the owner
5 ; of this patient. This will be for ALL CMOR SITES. (NOT ONE SITE)
6 ;
7 N DIRUT
8 S DIR("A")="This process will take a while to complete. Are you sure? "
9 S DIR("B")="NO",DIR(0)="YAO" D ^DIR K DIR Q:$D(DIRUT)
10 I Y=0 K DIR Q ; no go
11 I $P($G(^RGSITE(991.8,1,"COMP")),"^")'="" S $P(^("COMP"),"^")=""
12TASK ; Task this job to run
13 S ZTIO="",ZTRTN="EN^MPIFQUE3",ZTSAVE("DUZ")=""
14 S ZTDESC="GENERATE CMOR COMPARISON PROCESS"
15 D ^%ZTLOAD
16 I $D(ZTSK) W " Task#, ",ZTSK," queued" S $P(^RGSITE(991.8,1,"COMP"),U,5)=ZTSK
17 ;
18KILL ; Clean up the partition
19 K DIR,ZTSK,Y,ZTIO,ZTRTN,ZTDESC,ZTSAVE
20 Q
21 ;
22EN ; Entry point for CMOR Batch comparison. This should only be run after
23 ; the initialization to the MPI has been completed.
24 N U,SITE,NODE,MPI,MTIEN,MPILOOP,DTNOW,MSGCOUNT,LINCOUNT,RGLOG
25 S U="^",(MPILOOP,SITE)="",MPISTOP=0
26 D START^RGHLLOG()
27 N X,Y,DIC
28 S DIC="^VA(200,",DIC(0)="MZO",X="`"_+DUZ
29 D ^DIC
30 I $G(Y)<1 S MPINAME=""
31 I $G(Y)>0 S MPINAME=$G(Y(0,0))
32 ; If the job has manually stopped status it should restart at where
33 ; it left off
34 I $P($G(^RGSITE(991.8,1,"COMP")),U,4)="MS" D
35 . I $P($G(^RGSITE(991.8,1,"COMP")),U)="" S $P(^("COMP"),U,4)="C" Q ; Not logical restart from the top
36 . S NODE=$$MPINODE^MPIFAPI(+$P(^RGSITE(991.8,1,"COMP"),U))
37 . S CMOR=$P(NODE,U,3) ; CMOR of the last patient
38 . I +CMOR>0 S SITE=$O(^DPT("ACMOR",CMOR),-1) ; Back up one level
39 . I +CMOR>0 S MPILOOP=+$P(^RGSITE(991.8,1,"COMP"),U) ; Marked the last patient
40 . I +CMOR<1 S (SITE,MPILOOP)=0
41 . K CMOR
42 ; If the job has completed status it should restart at the top
43 I $P($G(^RGSITE(991.8,1,"COMP")),U,4)="C" S $P(^("COMP"),U)=""
44 ; Start the job
45 S ^XTMP("RGVCCMR","@@@@","DFNCOUNT")=0 ; set for counter in CALC^RGVCCMR2
46 D NOW^%DTC S Y=X X ^DD("DD") S DTNOW=Y ; get current date and time
47 S $P(^RGSITE(991.8,1,"COMP"),U,2)=% ; timestamp the job
48 S $P(^RGSITE(991.8,1,"COMP"),U,4)="R" ; mark the status as running
49 S $P(^RGSITE(991.8,1,"COMP"),U,6)="N" ; reset the flag
50 N RGDFN,CALDT,NODE
51 F S SITE=$O(^DPT("ACMOR",SITE)) Q:SITE="" D ; Get the site CMOR on file
52 . Q:MPISTOP=1 ; Trouble occured, user wanted to stop
53 . I +SITE=+$$SITE^VASITE() Q ; Don't process your own
54 . D HDR ; Create batch for each site
55 . F S MPILOOP=$O(^DPT("ACMOR",+SITE,MPILOOP)) Q:MPILOOP="" D Q:MPISTOP=1 ; Start with DFN and go
56 . . S DFN=+MPILOOP Q:DFN<0
57 . . S NODE=$$MPINODE^MPIFAPI(DFN) Q:+NODE<1 ; Was not CIRN'ed
58 . . I $G(^DPT(DFN,.35)),$P($G(^DPT(DFN,.35)),"^")'="" Q ; Death patient
59 . . I $P(NODE,"^")="" D LOG Q ; Log exception if no ICN
60 . . S CALDT=$P(NODE,"^",7) ; current calc date
61 . . I CALDT="" S CALDT=0
62 . . S X="T-90" D ^%DT
63 . . I CALDT<Y S RGDFN=DFN D CALC^RGVCCMR2 ; score is older than 90 days
64 . . S $P(^RGSITE(991.8,1,"COMP"),U)=+DFN ; mark that patient as done
65 . . D INDV
66 . . I MSGCOUNT>99 D SEND D HDR ; send out if over 100 messages
67 . . I $P($G(^RGSITE(991.8,1,"COMP")),U,6)="Y" S MPISTOP=1 D SEND Q
68 . I $O(^TMP("HLS",$J,0)) D SEND ;**3
69 ;
70 ; if user asked to stop set flag = yes and status to MS
71 ; if naturally stop set status to SN
72 I MPISTOP=1 S $P(^RGSITE(991.8,1,"COMP"),U,6)="Y",$P(^("COMP"),U,4)="MS"
73 E S $P(^RGSITE(991.8,1,"COMP"),U,4)="C"
74 D NOW^%DTC S $P(^RGSITE(991.8,1,"COMP"),U,3)=% ; timestamp when it stop
75 D CLEAN
76 D STOP^RGHLLOG()
77 Q
78 ;
79HDR ; Create HL7 batch HEADER message to each of the CMOR site
80 K ^TMP("HLS",$J)
81 D INIT^HLFNC2("MPIF CMOR COMPARISON SERVER",.HL)
82 I $D(HL)=1 D EXC^RGHLLOG(220,"Error Returned in INIT^HLFNC2") K HL S MPISTOP=1 Q
83 D CREATE^HLTF(.HLMID,.MTIEN,.HLDT,.HLDT1)
84 I $D(MTIEN)="" D EXC^RGHLLOG(220,"Error Returned in CREATE^HLTF") K HLMID,HLDT,HLDT1 S MPISTOP=1 Q
85 S LINCOUNT=0 ; Set line counter
86 S MSGCOUNT=1 ; Set counter for 100 message per batch
87 Q
88 ;
89INDV ; Create individual message of the HL7 ADT-A31 batch message
90 ; EVN segment = event, date, CMOR score, requestor name
91 ; PID segment = standard call
92 ; NTE segment = Reason CMOR COMPARISON, site requested
93 D INIT^HLFNC2("MPIF CMOR COMPARISON SERVER",.HL) ; Because HL7 did not know
94 S HL("SAF")=$P($$SITE^VASITE,"^",3) ; the facility # when dynamic
95 ; address of batch. This needs
96 ; to be set. Until HL7 fixs it
97 S MPIID=HLMID_"-"_MSGCOUNT
98 D MSH^HLFNC2(.HL,MPIID,.MPI)
99 N NODE
100 S LINCOUNT=LINCOUNT+1
101 S ^TMP("HLS",$J,LINCOUNT)=MPI
102 S LINCOUNT=LINCOUNT+1
103 S NODE=$$MPINODE^MPIFAPI(DFN)
104 Q:+NODE<1
105 S ^TMP("HLS",$J,LINCOUNT)="EVN"_HL("FS")_"A31"_HL("FS")_$P(NODE,"^",7)_HL("FS")_$P(NODE,U,6)_HL("FS")_MPINAME
106 S LINCOUNT=LINCOUNT+1
107 S ^TMP("HLS",$J,LINCOUNT)=$$EN^VAFCPID(DFN,"2,3,5")
108 S LINCOUNT=LINCOUNT+1
109 ;this is the request to the site for a comparison
110 S ^TMP("HLS",$J,LINCOUNT)="NTE"_HL("FS")_"COMPARISON"_HL("FS")_$P($$SITE^VASITE(),U,3)
111 S MSGCOUNT=MSGCOUNT+1
112 Q
113 ;
114SEND ; Send out the batch message
115 N RESLT
116 D GENERATE^HLMA("MPIF CMOR COMPARISON SERVER","GB",1,.RESLT,MTIEN)
117 I $P(RESLT,U,2)'="" D EXC^RGHLLOG(220,"Error Returned in GENERATE^HLMA "_$P(RESLT,U,2)) S MPISTOP=1
118 Q
119 ;
120LOGIC ; This is where the dynamic address located.
121 ; ** Routing logic field in Protocol file is being used
122 ; instead of GET^HLSUB.
123 ; For now, I have to hard set the receiving logical link, intercept
124 ; the message before it send out, figure out the receiving Logical
125 ; link from the MSH segment and let the Routing logic create the
126 ; HLL("LINKS") array.
127 N RESLT
128 K RGL,RESLT
129 D LINK^HLUTIL3(SITE,.RGL) ; get the logical link to that institution
130 S INSTITU=$O(RGL(0))
131 I INSTITU<1 Q ; if there is no logical link
132 I $E($G(RGL(INSTITU)),1,2)'="VA" D
133 .D START^RGHLLOG()
134 .D EXC^RGHLLOG(224,"Can't send CMOR Comparison message to site, due to non-CIRN logical link for site "_INSTITU)
135 .D STOP^RGHLLOG()
136 .S RESLT=1
137 Q:$D(RESLT)
138 S HLL("LINKS",1)="MPIF CMOR COMPARISON CLIENT"_HL("FS")_RGL(INSTITU)
139 K INSTITU,RGL
140 Q
141 ;
142CLEAN ; Clean up the partition
143 K %,X,Y,MPISTOP,MPINAME,DFN,MPIID
144 K ^XTMP("HLS",$J)
145 Q
146 ;
147LOG ; Log exception for non ICN but CMOR belong to someone else
148 N NAME,SSN,RGLOG,TEXT
149 S XMCHAN=1,NAME=$P(^DPT(DFN,0),"^",1),SSN=$P(^(0),"^",9)
150 S TEXT="This patient "_NAME_" ssn# "_SSN_" is missing the ICN. Log a NOIS regarding this missing ICN."
151 D EXC^RGHLLOG(219,TEXT,DFN)
152 K XMCHAN
153 Q
154 ;
155STOP ; Stop/Restart the CMOR Comparison process
156 I $P($G(^RGSITE(991.8,1,"COMP")),"^",4)'="R" D Q
157 . S DIR("A")="Do you want to RESTART this CMOR Comparison process"
158 . S DIR("B")="N",DIR(0)="Y" D ^DIR
159 . I $G(Y)=1 D TASK
160 I $P($G(^RGSITE(991.8,1,"COMP")),"^",4)="R" D Q
161 . W !
162 . S DIR("A")="Do you want to stop CMOR Comparison process after the current patient"
163 . S DIR("B")="N",DIR(0)="Y" D ^DIR
164 . I $G(Y)=1 S $P(^RGSITE(991.8,1,"COMP"),"^",6)="Y"
165 Q
166 ;
167STATUS ; Where is the process right now?
168 N IEN,NAME,SSN,STATUS,Y
169 I $P($G(^RGSITE(991.8,1,"COMP")),"^",5)="" W !,"The CMOR Comparison process HAS NEVER been tasked" Q
170 W !,"The CMOR Comparison process has been tasked with task # ",$P($G(^RGSITE(991.8,1,"COMP")),"^",5),". The"
171 S STATUS=$P($G(^RGSITE(991.8,1,"COMP")),"^",4)
172 W !,"process ",$S(STATUS="R":"is currently running",STATUS="MS":"was manually stopped",STATUS="C":"has completed",1:"")
173 I (STATUS="C")!(STATUS="MS") S Y=$P($G(^RGSITE(991.8,1,"COMP")),"^",3) X ^DD("DD") W " on ",Y
174 S IEN=$P($G(^RGSITE(991.8,1,"COMP")),"^")
175 I IEN'="" D
176 .S NAME=$P($G(^DPT(+IEN,0)),"^"),SSN=$P($G(^(0)),"^",9)
177 .S CMOR=$P($G(^DPT(+IEN,"MPI")),"^",3)
178 .S CMOR=$P($$NNT^XUAF4(CMOR),"^")
179 .W " and the last patient",!,"was ",NAME," ssn # ",SSN," CMOR= ",CMOR
180 Q
181 ;
Note: See TracBrowser for help on using the repository browser.