source: WorldVistAEHR/trunk/r/MASTER_PATIENT_INDEX_VISTA-MPIF/MPIFQ0.m@ 1696

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

initial load of WorldVistAEHR

File size: 9.3 KB
Line 
1MPIFQ0 ;ALB/RJS-QUERY HANDLER TOP LEVEL ;2/8/07 22:22
2 ;;1.0; MASTER PATIENT INDEX VISTA ;**1,3,8,14,13,16,17,21,20,24,26,28,31,33,35,38,43,40**;30 Apr 99;Build 13
3 ; Modified from FOIA VISTA,
4 ; GPL Copyright (C) 2007 WorldVistA
5INTACTV ;Interactive standalone query
6 N DFN,NAME1,MPIFLL
7 K DTOUT,DUOUT,X,Y,DIC
8 S MPIFRES="",MPIFINT="",DIC="^DPT(",DIC(0)="AEMQ" D ^DIC
9 I ($D(DTOUT))!($D(DUOUT))!((+$G(Y))<0) W:'$D(MPIFRPC) !,"TRY AGAIN LATER" G END
10 S DFN=+Y,HLP("ACKTIME")=300
11 W:'$D(MPIFRPC) !
12CIRNEXC ; Exception Entry Point
13 I +$$GETICN^MPIF001(DFN)>0,$$IFLOCAL^MPIF001(DFN)'=1 W:'$D(MPIFRPC) !,"Patient already has an ICN" G END
14 N LOCDATA ;Data Returned from GETDATA in ICN array
15 D GETDATA("^DPT(",DFN,"LOCDATA",".01;.02;.03;.09;.301;391;1901")
16 S LOCDATA(2,DFN,991.01)=$P($$MPINODE^MPIFAPI(DFN),"^"),TSSN=LOCDATA(2,DFN,.09)
17 I $$IFLOCAL^MPIF001(DFN)=1 S MPIFLL=""
18 I $G(LOCDATA(2,DFN,991.01))>0&('$D(MPIFLL)) W:'$D(MPIFRPC) !,"Patient already has an ICN" G END
19 S HLP("ACKTIME")=300,MPIQRYNM="EXACT_MATCH_QUERY"
20 ;MPIQRYNM="VTQ_PID_ICN_NO_LOAD" CHANGING QUERY NAME
21 G JUMP
22VTQ G:$G(DFN)']"" END
23 N LOCDATA ;Data Returned from GETDATA in ICN array
24 D GETDATA("^DPT(",DFN,"LOCDATA",".01;.02;.03;.09;.301;391;1901")
25 S LOCDATA(2,DFN,991.01)=$P($$MPINODE^MPIFAPI(DFN),"^"),TSSN=LOCDATA(2,DFN,.09)
26 ;S MPIQRYNM="VTQ_PID_ICN_NO_LOAD" CHANGING QUERY NAME
27 S MPIQRYNM="EXACT_MATCH_QUERY"
28 I $G(LOCDATA(2,DFN,991.01))>0 S MPIFRTN="ALREADY HAS ICN" G END ;If Pt already has ICN don't connect to MPI
29 ;New VOE code
30 ;Agency EHR does not use MPI
31 I '($G(DUZ("AG"))="V"!$$GET^XPAR("SYS","MPIF VOE MPI")) G END ;DAOU/WCJ;WV/CJS
32 ;End EHR modifications
33JUMP N TIME,% D NOW^%DTC S TIME=%
34 N HL,MPIINM,MPIOUT,MPIIN,MPIMCNT,MPICNT,MPICS,HEADER,TEST,SITE,MPIDC,SSN
35 I $G(HLP("ACKTIME"))="" S HLP("ACKTIME")=30 ;If the HLP("ACKTIME") is not already set for the D/C
36 S HL("ECH")="^~\&",HL("FS")="|"
37 I '$D(MPIQRYNM) S MPIQRYNM="VTQ_PID_ICN"
38 S MPIIN="",MPIMCNT=DFN,MPICNT=1,MPICS=$E(HL("ECH"),1)
39 D VTQ1^MPIFVTQ(DFN,.MPIOUT,.HL,.MPIQRYNM) ; **33 remove field list to get all now
40 I +MPIOUT(0)=-1 D G EXIT
41 .S ^TMP($J,"MPIFQ0-ERROR-LOG",DFN,TIME)=$G(MPIOUT(0)),MPIFRTN="CONTINUE"
42 ;Create MSH
43 S SITE=$$SITE^VASITE,SITE=$P(SITE,"^",3),SITE=SITE\1,HEADER="MSH"_HL("FS")_HL("ECH")_HL("FS")_"MPI_LOAD"_HL("FS")_SITE_HL("FS")
44 S HEADER=HEADER_"MPI-ICN"_HL("FS")_HL("FS")_HL("FS")_HL("FS")_"VQQ"_MPICS_"Q02"_HL("FS")_MPIMCNT_"-"_MPICNT_HL("FS") ;**38 changed VTQ to VQQ
45 S MPIOUT(1)=HEADER K MPIOUT(0)
46 I '$D(MPIFS) W:'$D(MPIFRPC) !!,"Attempting to connect to the Master Patient Index in Austin...",!,"If no SSN or inexact DOB or common name, this request",!,"may take some time, please be patient...",!
47 S TEST=$$EN^HLCSAC("MPIVA DIR","MPIOUT","MPIDC")
48 K HLP("ACKTIME") ;kill the HLP array set for the ack timeout
49 I +TEST=-1 D G EXIT
50 .S ^TMP($J,"MPIFQ0-ERROR-LOG",DFN,TIME)=TEST
51 .I '$D(MPIFS) W:'$D(MPIFRPC) !!,"Could not connect to MPI or Timed Out, assigning local ICN (if not already assigned)..."
52 .D LOCAL^MPIFQ3(DFN) S MPIFRTN="ASSIGNING LOCAL"
53 K ^TMP("MPIFVQQ",$J),^TMP("MPIFQ0",$J) ;array data is parsed into for display in LM
54INIPARS ;
55 N SEG,INDEX,SKIP,CHECK,AL,TTF2,TFLL,TF,TF2,MPIREP,MPICOMP
56 S INDEX=0 K CHECK
57LOOP1 ;
58 ;process in ADT type messages
59 N MPIX S MPIX=0 N REP,SG,MSG,MPIQUIT,MPINODE
60 K TWODFN S MPIQUIT=0
61 F MPIX=0:1 X "D LOOP2" D K MPINODE,MSG Q:MPIQUIT'>0
62 . I $D(MPINODE(1)) S SG=$E(MPINODE(1),1,3) S MSG(1)=MPINODE(1) D
63 .. S MPIJ=1 F S MPIJ=$O(MPINODE(MPIJ)) Q:'MPIJ S MSG(MPIJ)=MPINODE(MPIJ)
64 .. D:SG?2A1(1A,1N) @SG
65DECIDE ;If no data in ^TMP that means the patient was not found in the MPI w/VTQ Query. So we go to A28 to add the patient to the MPI.
66 N EXC,TEXT,EXACT,EXACT2
67 I '$D(^TMP("MPIFVQQ",$J)) D G EXIT
68 .I '$D(MPIFS) W:'$D(MPIFRPC) !!,"Exact match for Patient was not found in the MPI..."
69 .D A28^MPIFQ3(DFN) S MPIFRTN="DID A28"
70 .; log potential match exception if exist
71 .I MPIPOT=1 D
72 ..D START^RGHLLOG(0),EXC^RGHLLOG(218,"Potential match(es) found, please review via MPI/PD Exception Handler",DFN),STOP^RGHLLOG(0)
73 ..K MPIPOT
74 ;If INDEX=1 it means we got 1 match check SSN see if definitely same pt
75 I (INDEX=1) D G EXIT
76 .; Removed &(TSSN=SSN) from line above, only be an exact match returned now
77 .N CCMOR,ICN,DATA,TICN,SNM,SNM2,IEN
78 .S DATA=^TMP("MPIFVQQ",$J,INDEX,"DATA"),CMOR=$P(DATA,"^",5),ICN=$P(DATA,"^",6),IEN=$$IEN^XUAF4(CMOR)
79 .D START^RGHLLOG(0)
80 .S TICN=$$GETDFN^MPIF001(+ICN)
81 .I TICN>0,DFN'=TICN D
82 ..D TWODFNS^MPIF002(TICN,DFN,ICN) S TWODFN=1
83 ..I '$D(MPIFS) W:'$D(MPIFRPC) !!,"Exception logged, another patient has the ICN returned already, requesting new ICN for this patient..."
84 ..D A28^MPIFQ3(DFN),STOP^RGHLLOG(0) S MPIFRTN="Did A28" Q
85 .;I TICN>0&(DFN'=TICN)
86 .; CHECK IF NAME IS SAME - IF NOT POTENTIAL MATCH EXCEPTION
87 .; **43 remove checks here as only exact match will be returned from the MPI
88 .;S SNM=LOCDATA(2,DFN,.01) D NAME^VAFCPID2(DFN,.SNM,0) ;reformat name to DG 149 standard
89 .;S SNM2=$P(DATA,"^") D NAME^VAFCPID2(0,.SNM2,0) S $P(DATA,"^")=SNM2
90 .;I $P(SNM,",")=$P(SNM2,",")&($P($P(SNM2,",",2)," ")=$P($P(SNM,",",2)," ")) D
91 .; ^first and last match - check for middle name vs middle initial
92 .;N SNMN,SNMN2
93 .;S SNMN=$P($P(SNM,",",2)," ",2),SNMN2=$P($P(SNM2,",",2)," ",2)
94 .;I $L(SNMN)>1&($L(SNMN2)=1),$E(SNMN,1)=SNMN2 S EXACT=1
95 .;I $L(SNMN2)>1&($L(SNMN)=1),$E(SNMN2,1)=SNMN S EXACT=1
96 .;I $P($G(^DPT(DFN,0)),"^",2)'=$P(DATA,"^",11) S EXC=209,TEXT="Gender fields don't match between site and MPI for DFN "_DFN S EXACT2=1
97 .;I SNM2'=SNM&('$D(EXACT))!($D(EXACT2)) D Q
98 .;I '$D(EXC) S EXC=214,TEXT="Name fields don't match between site and MPI for DFN "_DFN
99 .;I $D(MPIFINT) D START^MPIFQ1(INDEX) Q
100 .;I '$D(MPIFINT) D LOC2^MPIFQ3(DFN) Q
101 .I '$D(MPIFS)&('$D(TWODFN)) W:'$D(MPIFRPC) !!,"Found Patient "_$G(LOCDATA(2,DFN,.01))_" on MPI",!," Updating ICN to "_+ICN_" and CMOR to "_$P($$NS^XUAF4(IEN),"^")_" ("_CMOR_") - just a minute..."
102 .D STOP^RGHLLOG(0),UPDATE(DFN,ICN,CMOR) S MPIFRTN="GOT 1 HIT FROM MPI"
103 ;I '$D(MPIFINT) D G EXIT
104 ;. came in via PIMS options to d/c with MPI
105 ;.I '$D(MPIFS) W:'$D(MPIFRPC) !!,"Potential Matches Found, Assigning Local ICN..."
106 ;.I '$D(EXC) S EXC=218,TEXT="Potential matches found for patient DFN= "_DFN_" Use Single Patient Initialization to MPI option to manually process."
107 ;.D START^RGHLLOG(0),EXC^RGHLLOG(EXC,TEXT,DFN),STOP^RGHLLOG(0)
108 ;.D LOCAL^MPIFQ3(DFN) S MPIFRTN="ASSIGNING LOCAL"
109 ;D START^MPIFQ1(INDEX) G END
110EXIT I $D(MPIFINT) K MPIFINT,MPIFRES,MPIQRYNM,TSSN,TWODFN
111 K VALMCNT,VALMLST,CCMOR,FICN H 3 W:'$D(MPIFRPC) !!
112END K ^TMP("MPIFVQQ",$J),^TMP("MPIFQ0",$J) Q
113 ;
114UPDATE(DFN,ICN,CMOR) ;
115 N TICN,CHKSUM,SETICN,SETLOC,CHANGE,RGLOG,LOCAL
116 S CHKSUM=$P(ICN,"V",2),ICN=$P(ICN,"V",1),TICN=$$GETDFN^MPIF001(+ICN)
117 I TICN>0,TICN'=DFN,'$D(TWODFN) D TWODFNS^MPIF002(TICN,DFN,ICN) Q
118 S SETICN=$$SETICN^MPIF001(DFN,ICN,CHKSUM)
119 I +SETICN'>0 S ^TMP($J,"MPIFQ0-ERROR-LOG",DFN,TIME)="COULD NOT SET ICN IN MPIFQ0" Q
120 S SETLOC=1,LOCAL="N"
121 I $E(ICN,1,3)=$P($$SITE^VASITE(),"^",3) S LOCAL="Y"
122 I $G(LOCAL)="Y" S SETLOC=$$SETLOC^MPIF001(DFN,1)
123 I $G(LOCAL)'="Y" S SETLOC=$$SETLOC^MPIF001(DFN,0)
124 I +SETLOC'>0 S ^TMP($J,"MPIFQ0-ERROR-LOG",DFN,TIME)="COULD NOT SETLOC IN MPIFQ0" Q
125 N CMOR1 S CMOR1=$$LKUP^XUAF4(CMOR)
126 I CMOR1'="" S CHANGE=$$CHANGE^MPIF001(DFN,CMOR1)
127 I CMOR1="" S CHANGE=-1
128 I $G(LOCAL)="Y" S CHANGE=$$CHANGE^MPIF001(DFN,$P($$SITE^VASITE,"^"))
129 I +CHANGE'>0 S ^TMP($J,"MPIFQ0-ERROR-LOG",DFN,TIME)="COULD NOT SET CMOR IN MPIFQ0" Q
130 Q:$G(LOCAL)="Y"
131 N RESLT S RESLT=$$A24^MPIFA24B(DFN)
132 I +RESLT<0 D EXC^RGHLLOG(208,"Problem building A24 (ADD TF) for DFN= "_DFN,DFN)
133 ; create treating facility list
134 I $D(^TMP("MPIFVQQ",$J,INDEX,"TF")) D
135 . N MPINTFI,MPINTF,TFSTRG,TFIEN,MPIFMDT
136 . S MPINTFI=0
137 . F S MPINTFI=$O(^TMP("MPIFVQQ",$J,INDEX,"TF",MPINTFI)) Q:'MPINTFI D
138 .. S MPINTF=^TMP("MPIFVQQ",$J,INDEX,"TF",MPINTFI)
139 .. S TFIEN=$$IEN^XUAF4($P(MPINTF,"^",1))
140 .. S MPIFMDT=$$HL7TFM^XLFDT($P(MPINTF,"^",2)) I MPIFMDT<0 S MPIFMDT=""
141 .. S TFSTRG=TFIEN_"^"_$G(MPIFMDT)_"^"_$P(MPINTF,"^",3)
142 .. D FILE^VAFCTFU(DFN,TFSTRG,1)
143 Q
144GETDATA(DIC,DA,MPIFAR,DR,EI) ;
145 N DIQ S DIQ=MPIFAR
146 I $G(EI)]"" S DIQ(0)=EI
147 D EN^DIQ1
148 Q
149LOOP2 ;
150 N MPIDONE,MPII,MPIJ
151 S MPII=0,MPIDONE=0
152 F S MPIQUIT=$O(MPIDC(MPIQUIT)) Q:'MPIQUIT D Q:MPIDONE
153 . I MPIDC(MPIQUIT)="" S MPIDONE=1 Q
154 . S MPII=MPII+1,MPINODE(MPII)=$G(MPIDC(MPIQUIT)) Q
155 Q
156MSH ;
157 S MPIREP=$E(HL("ECH"),2),MPICOMP=$E(HL("ECH"),1)
158 Q
159MSA ;
160 Q
161RDF ;
162 Q
163QAK ; check potential matches
164 K MPIPOT S MPIPOT=0
165 I MSG(1)["POTENTIAL MATCHES" S MPIPOT=1
166 Q
167RDT ;
168 N NAME,ICN,BIRTHDAY,CMOR,IEN,SEG,HEREICN,STRING,LASTNAME,FRSTNAME,MIDDLE,SUFF,SEX
169 S STRING="",INDEX=$G(INDEX)+1
170 D RDT^MPIFSA3(.INDEX,.HL,.MSG)
171 S SEG=^TMP("MPIFVQQ",$J,INDEX,"DATA")
172 S FRSTNAME=$P(SEG,"^",7),LASTNAME=$P(SEG,"^",2),MIDDLE=$P(SEG,"^",10),SUFF=$P(SEG,"^",15)
173 S SSN=$P(SEG,"^",3),NAME=LASTNAME_","_FRSTNAME
174 I MIDDLE'="" S NAME=NAME_" "_MIDDLE
175 I SUFF'="" S NAME=NAME_" "_SUFF
176 S SEX=$P(SEG,"^",11)
177 S ICN=$P(SEG,"^",6)
178 S BIRTHDAY=$P(SEG,"^",4)
179 S CMOR=$P(SEG,"^",5),IEN=$$IEN^XUAF4(CMOR)
180 S CMOR=$P($$NS^XUAF4(IEN),"^")
181 S HEREICN=$$HEREICN^MPIFQ3($P(ICN,"V",1))
182 I HEREICN S STRING=$$SETSTR^VALM1("*",STRING,1,1),^TMP("MPIFVQQ",$J,INDEX,"INDICATOR")="*"_"^"_HEREICN
183 S STRING=$$SETSTR^VALM1(INDEX,STRING,2,4),STRING=$$SETSTR^VALM1($E(NAME,1,23),STRING,6,23)
184 S STRING=$$SETSTR^VALM1(SSN,STRING,30,9),STRING=$$SETSTR^VALM1(BIRTHDAY,STRING,41,10)
185 S STRING=$$SETSTR^VALM1(CMOR,STRING,54,20)
186 S ^TMP("MPIFVQQ",$J,INDEX,0)=STRING,^TMP("MPIFVQQ",$J,"IDX",INDEX,INDEX)=""
187 Q
Note: See TracBrowser for help on using the repository browser.