source: FOIAVistA/trunk/r/MASTER_PATIENT_INDEX_VISTA-MPIF/MPIFQ0.m@ 677

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

initial load of FOIAVistA 6/30/08 version

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