source: FOIAVistA/trunk/r/REGISTRATION-DGQE-DG-DPT-GRPX-VAD-VAF-VAS-VAT-VAU--VA-VIC--DGBT--DGJ--DGYA--VALM/VAFCQRY1.m@ 794

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

initial load of FOIAVistA 6/30/08 version

File size: 9.1 KB
Line 
1VAFCQRY1 ;BIR/DLR-Query for patient demographics ;10/30/02 13:58
2 ;;5.3;Registration;**428,474,477,575,627,648,698,711,707**;Aug 13, 1993;Build 14
3 ;
4 ;Reference to $$GETDFNS^MPIF002 supported by IA #3634.
5 ;
6BLDPID(DFN,CNT,SEQ,PID,HL,ERR) ;build PID from File #2
7 ; Variable list
8 ; DFN - internal PATIENT (#2) number
9 ; CNT - value to be place in PID seq#1 (SET ID)
10 ; SEQ - variable consisting of sequence numbers delimited by commas
11 ; that will be used to build the message (default is ALL)
12 ; PID (passed by reference) - array location to place PID segment
13 ; result, the array can have existing values when passed.
14 ; HL - array that contains the necessary HL variables (init^hlsub)
15 ; ERR - array that is used to return an error
16 ;
17 N VAFCMN,VAFCMMN,SITE,VAFCZN,SSN,SITE,APID,HIST,HISTDT,VAFCHMN,NXT,NXTC,COMP,REP,SUBCOMP,STATE,CITY,CLAIM,HLECH,HLFS,HLQ,STATEIEN,SARY,LVL,LNGTH,X,STN,SITA,HLES
18 I '$D(SEQ) S SEQ="ALL"
19 I SEQ="" S SEQ="ALL"
20 I SEQ'="ALL" D
21 .; setting up temp array to hold fields to be included in message
22 .N POS,EN S POS=1 F S EN=$P(SEQ,",",POS) Q:EN="" S SARY(EN)="",POS=POS+1
23 S HLECH=HL("ECH"),HLFS=HL("FS"),HLQ=HL("Q"),(COMP,HL("COMP"))=$E(HL("ECH"),1)
24 S (SUBCOMP,HL("SUBCOMP"))=$E(HL("ECH"),4),(REP,HL("REP"))=$E(HL("ECH"),2),HLES=$E(HL("ECH"),3)
25 ;get Patient File MPI node
26 S VAFCMN=""
27 N X S X="MPIFAPI" X ^%ZOSF("TEST") I $T S VAFCMN=$$MPINODE^MPIFAPI(DFN)
28 I +VAFCMN<0 S VAFCMN=""
29 S VAFCZN=^DPT(DFN,0),SSN=$P(^DPT(DFN,0),"^",9)
30 N VAFCA,VAFCA1 D GETS^DIQ(2,DFN_",","1*","E","VAFCA") ;**698 GETTING ALIAS INFO
31 ;** 707 reformat alias information to include ALIAS SSN in PID-3 with a location reference to the name in PID-5
32 I $D(VAFCA) N CT,ENT S CT=0,ENT="" F S ENT=$O(VAFCA(2.01,ENT)) Q:ENT="" D
33 .S CT=CT+1
34 .S VAFCA1(CT,"NAME")=$G(VAFCA(2.01,ENT,.01,"E"))
35 .;I $G(VAFCA(2.01,ENT,1,"E"))'="" S VAFCA1("SSN")="",VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"E"))
36 .S VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"E"))
37 S SITE=$$SITE^VASITE,STN=$P($$SITE^VASITE,"^",3)
38 N TMP F TMP=1:1:31 S APID(TMP)=""
39 S APID(2)=CNT
40 ;list of fields used for backwards compatibility with HDR
41 I $D(SARY(2))!(SEQ="ALL") I VAFCMN'="" S APID(3)=$P(VAFCMN,"^")_"V"_$P(VAFCMN,"^",2) ;Patient ID
42 ;repeat patient ID list including ICN (NI),SSN (SS),CLAIM# (PN) AND DFN (PI)
43 I $D(SARY(3))!(SEQ="ALL") D
44 .S APID(4)=""
45 .;National Identifier (ICN)
46 .I VAFCMN'="",+VAFCMN>0 D
47 ..I $E($P(VAFCMN,"^"),1,3)=STN S SITA=STN
48 ..I $E($P(VAFCMN,"^"),1,3)'=STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
49 ..S APID(4)=$P(VAFCMN,"^")_"V"_$P(VAFCMN,"^",2)_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_SITA_SUBCOMP_"L" D
50 ..;Assumption that if this is a local ICN at this point send the message with an expiration date of today, so that it will be treated as a deprecated ID and stored on the MPI as such
51 ..I $E($P(VAFCMN,"^"),1,3)=$P($$SITE^VASITE,"^",3) S APID(4)=APID(4)_COMP_COMP_$$HLDATE^HLFNC(DT,"DT") ;**707 TO ONLY SEND DATE NO TIME
52 .I $G(SSN)'="" S APID(4)=APID(4)_$S(APID(4)'="":REP,1:"")_SSN_COMP_COMP_COMP_"USSSA"_SUBCOMP_SUBCOMP_"0363"_COMP_"SS"_COMP_"VA FACILITY ID"_SUBCOMP_$$STA^XUAF4(+SITE)_SUBCOMP_"L"
53 .I $G(DFN)'="" S APID(4)=APID(4)_$S(APID(4)'="":REP,1:"")_DFN_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PI"_COMP_"VA FACILITY ID"_SUBCOMP_$$STA^XUAF4(+SITE)_SUBCOMP_"L" D
54 ..;CLAIM# **707 moved dfn and claim number up here since Alias SSN could be many
55 ..I $D(^DPT(DFN,.31)) S CLAIM=$P(^DPT(DFN,.31),"^",3) I +CLAIM>0 S APID(4)=APID(4)_REP_CLAIM_COMP_COMP_COMP_"USVBA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PN"_COMP_"VA FACILITY ID"_SUBCOMP_$$STA^XUAF4(+SITE)_SUBCOMP_"L"
56 .S NXTC=0,LVL=0
57 .I $D(VAFCA1) D
58 ..;Have Alias SSNs
59 ..S CT=0 F S CT=$O(VAFCA1(CT)) Q:+CT<1 D
60 ...S NXT=$S($G(VAFCA1(CT,"SSN"))="":HL("Q"),1:$G(VAFCA1(CT,"SSN")))_COMP_COMP_COMP_"USSSA"_SUBCOMP_SUBCOMP_"0363"_COMP_"SS"_COMP_"VA FACILITY ID"_SUBCOMP_$$STA^XUAF4(+SITE)_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(DT,"DT")
61 ...I LVL=0 D
62 ....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
63 ....I $L(APID(4)_NXT)>244 S LVL=1 S LNGTH=244-$L(APID(4)),APID(4)=APID(4)_REP_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)),NXTC=1
64 ...I LVL>0 D
65 ....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
66 ....I $L($G(APID(4,LVL))_NXT)>245 S LNGTH=244-$L(APID(4,LVL)),APID(4,LVL)=APID(4,LVL)_REP_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)) S LVL=LVL+1 S APID(4,LVL)=NXT
67 ...I NXTC=1 S NXTC=0
68 .I $D(^DPT(DFN,"MPIFHIS")) N HIST S HIST=0 F S HIST=$O(^DPT(DFN,"MPIFHIS",HIST)) Q:'HIST S VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0) S HISTDT=$P(VAFCHMN,"^",4) D
69 ..;**477 due to a timing issue if checksum and D/T of deprication of ICN is not present hang two seconds and try again if still not able to get ICN set D/T to DT
70 ..I $G(HISTDT)="" H 2 S VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0) S HISTDT=$P(VAFCHMN,"^",4) I HISTDT="" S HISTDT=DT
71 ..I APID(4)'="" D
72 ...I $E($P(VAFCHMN,"^"),1,3)=STN S SITA=STN
73 ...I $E($P(VAFCHMN,"^"),1,3)'=STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
74 ...S NXT=$P(VAFCHMN,"^")_"V"_$P(VAFCHMN,"^",2)_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_SITA_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(HISTDT,"DT") ;**648 only send date not time
75 ...I LVL=0 D
76 ....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
77 ....I $L(APID(4)_NXT)>244 S LVL=1 S LNGTH=244-$L(APID(4)),APID(4)=APID(4)_REP_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)),NXTC=1
78 ...I LVL>0 D
79 ....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
80 ....I $L($G(APID(4,LVL))_NXT)>245 S LNGTH=244-$L(APID(4,LVL)),APID(4,LVL)=APID(4,LVL)_REP_$E(NXT,1,LNGTH) S LNGTH=LNGTH+1,NXT=$E(NXT,LNGTH,$L(NXT)) S LVL=LVL+1 S APID(4,LVL)=NXT
81 ..I NXTC=1 S NXTC=0
82 ..I APID(4)="" D
83 ...I $E($P(VAFCHMN,"^"),1,3)=STN S SITA=STN
84 ...I $E($P(VAFCHMN,"^"),1,3)'=STN S SITA="200M"
85 ...S APID(4)=$P(VAFCHMN,"^")_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_SITA_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(HISTDT,"DT") ;**707 ONLY DATE NOT TIME
86NAMEPID ;patient name (last^first^middle^suffix^prefix^^"L" for legal)
87 I $D(SARY(5))!(SEQ="ALL") D
88 .;**711 code REMOVED PREFIX due to issues with existing PATIENT Name Standardization functionality
89 .N X S X=$P(VAFCZN,"^") D NAME^VAFCPID2(DFN,.X) S APID(6)=$$HLNAME^XLFNAME(X,"",$E(HL("ECH"),1)) I $P(APID(6),$E(HL("ECH"),1),7)'="L" S $P(APID(6),$E(HL("ECH"),1),7)="L"
90ALIAS .;patient alias (last^first^middle^suffice^prefix^^"A" for alias - can be multiple)
91 .N ALIAS,ALIEN,LVL6,NXTC,LNGTH S NXTC=0,LVL6=0
92 .I $D(VAFCA1) S ALIEN=0 F S ALIEN=$O(VAFCA1(ALIEN)) Q:'ALIEN D
93 ..S ALIAS=$$HLNAME^XLFNAME(VAFCA1(ALIEN,"NAME"),"",$E(HL("ECH"),1))
94 ..Q:ALIAS=""
95 ..S $P(ALIAS,$E(HL("ECH"),1),7)="A"
96 ..I LVL6=0 D
97 ...I $L(APID(6)_ALIAS)'>244 S APID(6)=APID(6)_REP_ALIAS Q
98 ...I $L(APID(6)_ALIAS)>244 S LVL6=1 S LNGTH=244-$L(APID(6)),APID(6)=APID(6)_REP_$E(ALIAS,1,LNGTH) S LNGTH=LNGTH+1,ALIAS=$E(ALIAS,LNGTH,$L(ALIAS)),NXTC=1
99 ..I LVL6>0 D
100 ...I $L($G(APID(6,LVL6))_ALIAS)'>245 S APID(6,LVL6)=$G(APID(6,LVL6))_$S(NXTC=0:REP,1:"")_ALIAS Q
101 ...I $L($G(APID(6,LVL6))_ALIAS)>245 S LNGTH=244-$L(APID(6,LVL6)),APID(6,LVL6)=APID(6,LVL6)_REP_$E(ALIAS,1,LNGTH) S LNGTH=LNGTH+1,ALIAS=$E(ALIAS,LNGTH,$L(ALIAS)) S LVL6=LVL6+1 S APID(6,LVL6)=ALIAS
102 ..I NXTC=1 S NXTC=0
103 . I APID(6)="" S APID(6)=HL("Q")
104MOTHER ;mother's maiden name (last^first^middle^suffix^prefix^^"M" for maiden name)
105 I $D(SARY(6))!(SEQ="ALL") D
106 .S APID(7)=HL("Q")
107 .I $D(^DPT(DFN,.24)) S VAFCMMN=$P(^DPT(DFN,.24),"^",3) D
108 ..S APID(7)=$$HLNAME^XLFNAME(VAFCMMN,"",$E(HL("ECH"),1)) I APID(7)="" S APID(7)=HL("Q")
109 ..I $P(APID(7),$E(HL("ECH"),1),7)'="M" S $P(APID(7),$E(HL("ECH"),1),7)="M"
110 .I APID(7)="" S APID(7)=HL("Q")
111 I $D(SARY(7))!(SEQ="ALL") S APID(8)=$$HLDATE^HLFNC($P(VAFCZN,"^",3)) I APID(8)="" S APID(8)=HL("Q") ;date/time of birth
112 I $D(SARY(8))!(SEQ="ALL") S APID(9)=$P(VAFCZN,"^",2) I APID(9)="" S APID(9)=HL("Q") ;sex
113 ;place of birth city and state
114 ;split into 2 routines **707
115 D CONT^VAFCQRY3(DFN,.APID,.PID,.HL,HLES,.SARY,SEQ,.ERR,REP,COMP,SSN,VAFCMN)
116 D KVA^VADPT
117 Q
118HL7TXT(HL7STRG,HL,HLES) ; Replace occurrences of embedded HL7 delimiters with
119 ; HL7 escape sequence
120 ;
121 ; Inputs: HL7STRG - Data string to be checked
122 ; HL("ECH") - HL7 delimiter string
123 ; Delimiters MUST be in the following order,
124 ; Escape, Field, Component, Repeat, Subcomponent
125 ; Example: \^~|&
126 ;
127 ; Output: HL7XTRG - Data string with escape sequence added (if needed)
128 ;
129 N OCHR,RCHR,RCHRI,TYPE,I,HLES2
130 ;
131 I $G(HL("COMP"))="" S HL("COMP")=$E(HL("ECH"),1),HL("REP")=$E(HL("ECH"),2),HL("SUBCOMP")=$E(HL("ECH"),4)
132 ; Set HL7 escape char
133 S HLES2=HLES_HL("FS")_HL("COMP")_HL("REP")_HL("SUBCOMP")
134 ;
135 ; Search for occurrence of each delimiter and replace it with "\<type>\"
136 F TYPE="E","F","C","R","S" D
137 . S RCHRI=$S(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
138 . ;
139 . ; OCHR=original char, RCHR=replacement char
140 . S OCHR=$E(HLES2,RCHRI),RCHR=$E("EFSRT",RCHRI) Q:'$F(HL7STRG,OCHR)
141 . F I=1:1 Q:$E(HL7STRG,I)="" I $E(HL7STRG,I)=OCHR S HL7STRG=$E(HL7STRG,1,I-1)_HLES_RCHR_HLES_$E(HL7STRG,I+1,999),I=I+2
142 Q
143 Q
Note: See TracBrowser for help on using the repository browser.