VAFCQRY1 ;BIR/DLR-Query for patient demographics ;7/19/21 10:44
;;5.3;Registration;**428,474,477,575,627,648,698,711,707,837,874,937,974,981,1059**;Aug 13, 1993;Build 6
;
;Reference to $$GETDFNS^MPIF002 supported by IA #3634.
;
BLDPID(DFN,CNT,SEQ,PID,HL,ERR) ;build PID from File #2
; Variable list
; DFN - internal PATIENT (#2) number
; CNT - value to be place in PID seq#1 (SET ID)
; SEQ - variable consisting of sequence numbers delimited by commas
; that will be used to build the message (default is ALL)
; PID (passed by reference) - array location to place PID segment
; result, the array can have existing values when passed.
; HL - array that contains the necessary HL variables (init^hlsub)
; ERR - array that is used to return an error
;
; DG*5.3*981 introduced changes to support the local modifications for HAC/MVI integration in CH*1.3*22529.
;
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
I '$D(SEQ) S SEQ="ALL"
I SEQ="" S SEQ="ALL"
I SEQ'="ALL" D
.; setting up temp array to hold fields to be included in message
.N POS,EN S POS=1 F S EN=$P(SEQ,",",POS) Q:EN="" S SARY(EN)="",POS=POS+1
S HLECH=HL("ECH"),HLFS=HL("FS"),HLQ=HL("Q"),(COMP,HL("COMP"))=$E(HL("ECH"),1)
S (SUBCOMP,HL("SUBCOMP"))=$E(HL("ECH"),4),(REP,HL("REP"))=$E(HL("ECH"),2),HLES=$E(HL("ECH"),3)
;get Patient File MPI node
S VAFCMN=""
N X S X="MPIFAPI" X ^%ZOSF("TEST") I $T S VAFCMN=$$MPINODE^MPIFAPI(DFN)
I +VAFCMN<0 S VAFCMN=""
S VAFCZN=^DPT(DFN,0),SSN=$P(^DPT(DFN,0),"^",9)
;**974,Story 841921 (mko): Get the internal Alias values instead of external
; so that the internal pointer (IEN) of the Name Components entry can be retrieved.
; In the following code, values are obtained from the "I" nodes instead of the "E" nodes.
N VAFCA,VAFCA1 D GETS^DIQ(2,DFN_",","1*","I","VAFCA") ;**698 GETTING ALIAS INFO
;** 707 reformat alias information to include ALIAS SSN in PID-3 with a location reference to the name in PID-5
I $D(VAFCA) N CT,ENT S CT=0,ENT="" F S ENT=$O(VAFCA(2.01,ENT)) Q:ENT="" D
.S CT=CT+1
.S VAFCA1(CT,"NAME")=$G(VAFCA(2.01,ENT,.01,"I"))
.;I $G(VAFCA(2.01,ENT,1,"E"))'="" S VAFCA1("SSN")="",VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"E"))
.S VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"I"))
.S VAFCA1(CT,"NCIEN")=$G(VAFCA(2.01,ENT,100.03,"I"))_"^"_ENT ;**974,Story 841921 (mko): Get Name Components pointer and save IENS of Alias subentry
;custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
S SITE=$$SITE^VASITE,STN=$P($$SITE^VASITE,"^",3) I STN=741 S STN="741MM"
N TMP F TMP=1:1:31 S APID(TMP)=""
S APID(2)=CNT
;list of fields used for backwards compatibility with HDR
I $D(SARY(2))!(SEQ="ALL") I VAFCMN'="" S APID(3)=$P(VAFCMN,"^")_"V"_$P(VAFCMN,"^",2) ;Patient ID
;repeat patient ID list including ICN (NI),SSN (SS),CLAIM# (PN) and DFN (PI)
I $D(SARY(3))!(SEQ="ALL") D
.S APID(4)=""
.;National Identifier (ICN)
.I VAFCMN'="",+VAFCMN>0 D
..I $E($P(VAFCMN,"^"),1,3)=STN S SITA=STN
..; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
..I $E($P(VAFCMN,"^"),1,3)=+STN I +STN="741" S SITA=+STN I SITA=741 S SITA="741MM"
..I $E($P(VAFCMN,"^"),1,3)'=+STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
..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
..;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
..I $E($P(VAFCMN,"^"),1,3)=STN S APID(4)=APID(4)_COMP_COMP_$$HLDATE^HLFNC(DT,"DT") ;**707 TO ONLY SEND DATE NO TIME
.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_STN_SUBCOMP_"L"
.S NXTC=0,LVL=0 ;**837,MVI_879: Move here, so that LVL gets set before pulling in TIN and FIN
.;**837,MVI_879: Get TIN and FIN from Patient file and put in PID-3
.;**1059, VAMPI-11120 (dri) Get ITIN from Patient file and put in PID-3
.N TIN,FIN,ITIN,REF
.S TIN=$P(VAFCMN,"^",8),FIN=$P(VAFCMN,"^",9),ITIN=$P(VAFCMN,"^",11),REF=$NA(APID(4))
.D ADDLINE($S(TIN="":HLQ,1:TIN)_COMP_COMP_COMP_"USDOD"_SUBCOMP_SUBCOMP_"0363"_COMP_"TIN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
.D ADDLINE($S(FIN="":HLQ,1:FIN)_COMP_COMP_COMP_"USDOD"_SUBCOMP_SUBCOMP_"0363"_COMP_"FIN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
.D ADDLINE($S(ITIN="":HLQ,1:ITIN)_COMP_COMP_COMP_"USIRS"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
.I $G(DFN)'="" D
..D ADDLINE(DFN_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PI"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
..;CLAIM# **707 moved dfn and claim number up here since Alias SSN could be many
..I $D(^DPT(DFN,.31)) S CLAIM=$P(^DPT(DFN,.31),"^",3) I +CLAIM>0 D ADDLINE(CLAIM_COMP_COMP_COMP_"USVBA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
.I $D(VAFCA1) D
..;Have Alias SSNs
..S CT=0 F S CT=$O(VAFCA1(CT)) Q:+CT<1 D
...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_STN_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(DT,"DT")
...I LVL=0 D
....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
....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
...I LVL>0 D
....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
....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
...I NXTC=1 S NXTC=0
.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
..;**477 due to a timing issue if checksum and D/T of deprecation of ICN is not present hang two seconds and try again if still not able to get ICN set D/T to DT
..I $G(HISTDT)="" H 2 S VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0) S HISTDT=$P(VAFCHMN,"^",4) I HISTDT="" S HISTDT=DT
..I APID(4)'="" D
...; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
...I $E($P(VAFCHMN,"^"),1,3)=+STN S SITA=+STN I SITA=741 S SITA="741MM"
...I $E($P(VAFCHMN,"^"),1,3)'=+STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
...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
...I LVL=0 D
....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
....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
...I LVL>0 D
....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
....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
..I NXTC=1 S NXTC=0
..I APID(4)="" D
...; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
...I $E($P(VAFCHMN,"^"),1,3)=+STN S SITA=+STN I SITA=741 S SITA="741MM"
...I $E($P(VAFCHMN,"^"),1,3)'=+STN S SITA="200M"
...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
;
ALTID ;**874 MVI_3035 (elz) alternate ID
I $D(SARY(4))!(SEQ="ALL") D
. S REF=$NA(APID(5)),@REF="",LVL=0
. I $G(DFN) D
.. ;VIC card number, station 742V1
.. N VAVICF,VAVICX,VAVIC,X
.. S VAVICF=+$$LKUP^XUAF4("742V1")
.. S VAVICX=0 F S VAVICX=$O(^DGCN(391.91,"APAT",DFN,VAVICF,VAVICX)) Q:'VAVICX D
... F X=0,2 S VAVIC(X)=$G(^DGCN(391.91,VAVICX,X))
... I $P(VAVIC(2),"^",2),$P(VAVIC(2),"^",3)'="H",$L($P(VAVIC(2),"^")),$L($P(VAVIC(0),"^",9)) D
.... D ADDLINE($P(VAVIC(2),"^",2)_COMP_COMP_COMP_$P(VAVIC(2),"^")_SUBCOMP_SUBCOMP_"0363"_COMP_$P(VAVIC(0),"^",9)_COMP_"VA FACILITY ID"_SUBCOMP_"742V1"_SUBCOMP_"L",.LVL,REF,REP)
;
NAMEPID ;patient name (last^first^middle^suffix^prefix^^"L" for legal)
I $D(SARY(5))!(SEQ="ALL") D
.;**711 code REMOVED PREFIX due to issues with existing PATIENT Name Standardization functionality
.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"
PREFNAME .; Story 455447 (elz)DG*5.3*937 Preferred Name (^preferred name^^^^^"N" for nickname)
.N PREFNAM S PREFNAM=$P($G(^DPT(DFN,.24)),"^",5)
.D HL7TXT(.PREFNAM,.HL,HLES) S APID(6)=APID(6)_$S(APID(6)]"":REP,1:"")_$S(PREFNAM]"":PREFNAM,1:"""""")_COMP_COMP_COMP_COMP_COMP_COMP_"N"
ALIAS .;patient alias (last^first^middle^suffice^prefix^^"A" for alias - can be multiple)
.N ALIAS,ALIEN,LVL6,NXTC,LNGTH S NXTC=0,LVL6=0
.I $D(VAFCA1) S ALIEN=0 F S ALIEN=$O(VAFCA1(ALIEN)) Q:'ALIEN D
..;**974,Story 841921 (mko): Get the Name Components themselves
..; rather than parsing them out of the Name field
..I $G(VAFCA1(ALIEN,"NCIEN"))>0 D
...N NAMEC
...S NAMEC("FILE")=2.01,NAMEC("IENS")=$P(VAFCA1(ALIEN,"NCIEN"),"^",2),NAMEC("FIELD")=.01
...S ALIAS=$$HLNAME^XLFNAME(.NAMEC,"",$E(HL("ECH")))
..E S ALIAS=$$HLNAME^XLFNAME(VAFCA1(ALIEN,"NAME"),"",$E(HL("ECH"),1))
..Q:ALIAS=""
..S $P(ALIAS,$E(HL("ECH"),1),7)="A"
..I LVL6=0 D
...I $L(APID(6)_ALIAS)'>244 S APID(6)=APID(6)_REP_ALIAS Q
...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
..I LVL6>0 D
...I $L($G(APID(6,LVL6))_ALIAS)'>245 S APID(6,LVL6)=$G(APID(6,LVL6))_$S(NXTC=0:REP,1:"")_ALIAS Q
...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
..I NXTC=1 S NXTC=0
. I APID(6)="" S APID(6)=HL("Q")
MOTHER ;mother's maiden name (last^first^middle^suffix^prefix^^"M" for maiden name)
I $D(SARY(6))!(SEQ="ALL") D
.S APID(7)=HL("Q")
.I $D(^DPT(DFN,.24)) S VAFCMMN=$P(^DPT(DFN,.24),"^",3) D
..S APID(7)=$$HLNAME^XLFNAME(VAFCMMN,"",$E(HL("ECH"),1)) I APID(7)="" S APID(7)=HL("Q")
..I $P(APID(7),$E(HL("ECH"),1),7)'="M" S $P(APID(7),$E(HL("ECH"),1),7)="M"
.I APID(7)="" S APID(7)=HL("Q")
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
I $D(SARY(8))!(SEQ="ALL") S APID(9)=$P(VAFCZN,"^",2) I APID(9)="" S APID(9)=HL("Q") ;sex
;place of birth city and state
;split into 2 routines **707
D CONT^VAFCQRY3(DFN,.APID,.PID,.HL,HLES,.SARY,SEQ,.ERR,REP,COMP,SSN,VAFCMN)
D KVA^VADPT
Q
;
HL7TXT(HL7STRG,HL,HLES) ; Replace occurrences of embedded HL7 delimiters with
; HL7 escape sequence
;
; Inputs: HL7STRG - Data string to be checked
; HL("ECH") - HL7 delimiter string
; Delimiters MUST be in the following order,
; Escape, Field, Component, Repeat, Subcomponent
; Example: \^~|&
;
; Output: HL7XTRG - Data string with escape sequence added (if needed)
;
N OCHR,RCHR,RCHRI,TYPE,I,HLES2
;
I $G(HL("COMP"))="" S HL("COMP")=$E(HL("ECH"),1),HL("REP")=$E(HL("ECH"),2),HL("SUBCOMP")=$E(HL("ECH"),4)
; Set HL7 escape char
S HLES2=HLES_HL("FS")_HL("COMP")_HL("REP")_HL("SUBCOMP")
;
; Search for occurrence of each delimiter and replace it with "\<type>\"
F TYPE="E","F","C","R","S" D
. S RCHRI=$S(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
. ;
. ; OCHR=original char, RCHR=replacement char
. S OCHR=$E(HLES2,RCHRI),RCHR=$E("EFSRT",RCHRI) Q:'$F(HL7STRG,OCHR)
. 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
Q
;
ADDLINE(NXT,LVL,REF,REP) ; Prepend REP to NXT and add it to the @REF
; array, starting at subscript LVL. If appending NXT causes the node
; to exceed 245 chars in length, add as much of NXT as possible to the
; current level, and the remaining at the next level.
; In:
; NXT = string to add to the @REF array
; .LVL = current subscript level (passed by referenced)
; REF = array reference string
; REP = repetition character (e.g., |)
; **837,MVI_879: Created this subroutine to aid in adding TIN and FIN to PID-3.
N LNGTH,CURREF
S:$G(LVL)<1 LVL=0
S CURREF=$S(LVL=0:REF,1:$NA(@REF@(LVL)))
I LVL>0!($G(@CURREF)]"") S NXT=REP_NXT
I $L($G(@CURREF))+$L(NXT)'>245 S @CURREF=$G(@CURREF)_NXT
E S LNGTH=245-$L(@CURREF),@CURREF=@CURREF_$E(NXT,1,LNGTH),LVL=LVL+1,@REF@(LVL)=$E(NXT,LNGTH+1,$L(NXT))
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAFCQRY1 13309 printed Dec 13, 2024@03:02:15 Page 2
VAFCQRY1 ;BIR/DLR-Query for patient demographics ;7/19/21 10:44
+1 ;;5.3;Registration;**428,474,477,575,627,648,698,711,707,837,874,937,974,981,1059**;Aug 13, 1993;Build 6
+2 ;
+3 ;Reference to $$GETDFNS^MPIF002 supported by IA #3634.
+4 ;
BLDPID(DFN,CNT,SEQ,PID,HL,ERR) ;build PID from File #2
+1 ; Variable list
+2 ; DFN - internal PATIENT (#2) number
+3 ; CNT - value to be place in PID seq#1 (SET ID)
+4 ; SEQ - variable consisting of sequence numbers delimited by commas
+5 ; that will be used to build the message (default is ALL)
+6 ; PID (passed by reference) - array location to place PID segment
+7 ; result, the array can have existing values when passed.
+8 ; HL - array that contains the necessary HL variables (init^hlsub)
+9 ; ERR - array that is used to return an error
+10 ;
+11 ; DG*5.3*981 introduced changes to support the local modifications for HAC/MVI integration in CH*1.3*22529.
+12 ;
+13 NEW 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
+14 IF '$DATA(SEQ)
SET SEQ="ALL"
+15 IF SEQ=""
SET SEQ="ALL"
+16 IF SEQ'="ALL"
Begin DoDot:1
+17 ; setting up temp array to hold fields to be included in message
+18 NEW POS,EN
SET POS=1
FOR
SET EN=$PIECE(SEQ,",",POS)
if EN=""
QUIT
SET SARY(EN)=""
SET POS=POS+1
End DoDot:1
+19 SET HLECH=HL("ECH")
SET HLFS=HL("FS")
SET HLQ=HL("Q")
SET (COMP,HL("COMP"))=$EXTRACT(HL("ECH"),1)
+20 SET (SUBCOMP,HL("SUBCOMP"))=$EXTRACT(HL("ECH"),4)
SET (REP,HL("REP"))=$EXTRACT(HL("ECH"),2)
SET HLES=$EXTRACT(HL("ECH"),3)
+21 ;get Patient File MPI node
+22 SET VAFCMN=""
+23 NEW X
SET X="MPIFAPI"
XECUTE ^%ZOSF("TEST")
IF $TEST
SET VAFCMN=$$MPINODE^MPIFAPI(DFN)
+24 IF +VAFCMN<0
SET VAFCMN=""
+25 SET VAFCZN=^DPT(DFN,0)
SET SSN=$PIECE(^DPT(DFN,0),"^",9)
+26 ;**974,Story 841921 (mko): Get the internal Alias values instead of external
+27 ; so that the internal pointer (IEN) of the Name Components entry can be retrieved.
+28 ; In the following code, values are obtained from the "I" nodes instead of the "E" nodes.
+29 ;**698 GETTING ALIAS INFO
NEW VAFCA,VAFCA1
DO GETS^DIQ(2,DFN_",","1*","I","VAFCA")
+30 ;** 707 reformat alias information to include ALIAS SSN in PID-3 with a location reference to the name in PID-5
+31 IF $DATA(VAFCA)
NEW CT,ENT
SET CT=0
SET ENT=""
FOR
SET ENT=$ORDER(VAFCA(2.01,ENT))
if ENT=""
QUIT
Begin DoDot:1
+32 SET CT=CT+1
+33 SET VAFCA1(CT,"NAME")=$GET(VAFCA(2.01,ENT,.01,"I"))
+34 ;I $G(VAFCA(2.01,ENT,1,"E"))'="" S VAFCA1("SSN")="",VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"E"))
+35 SET VAFCA1(CT,"SSN")=$GET(VAFCA(2.01,ENT,1,"I"))
+36 ;**974,Story 841921 (mko): Get Name Components pointer and save IENS of Alias subentry
SET VAFCA1(CT,"NCIEN")=$GET(VAFCA(2.01,ENT,100.03,"I"))_"^"_ENT
End DoDot:1
+37 ;custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
+38 SET SITE=$$SITE^VASITE
SET STN=$PIECE($$SITE^VASITE,"^",3)
IF STN=741
SET STN="741MM"
+39 NEW TMP
FOR TMP=1:1:31
SET APID(TMP)=""
+40 SET APID(2)=CNT
+41 ;list of fields used for backwards compatibility with HDR
+42 ;Patient ID
IF $DATA(SARY(2))!(SEQ="ALL")
IF VAFCMN'=""
SET APID(3)=$PIECE(VAFCMN,"^")_"V"_$PIECE(VAFCMN,"^",2)
+43 ;repeat patient ID list including ICN (NI),SSN (SS),CLAIM# (PN) and DFN (PI)
+44 IF $DATA(SARY(3))!(SEQ="ALL")
Begin DoDot:1
+45 SET APID(4)=""
+46 ;National Identifier (ICN)
+47 IF VAFCMN'=""
IF +VAFCMN>0
Begin DoDot:2
+48 IF $EXTRACT($PIECE(VAFCMN,"^"),1,3)=STN
SET SITA=STN
+49 ; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
+50 IF $EXTRACT($PIECE(VAFCMN,"^"),1,3)=+STN
IF +STN="741"
SET SITA=+STN
IF SITA=741
SET SITA="741MM"
+51 ; **707 update assigning authority for national ICNs to 200M for MPI
IF $EXTRACT($PIECE(VAFCMN,"^"),1,3)'=+STN
SET SITA="200M"
+52 SET APID(4)=$PIECE(VAFCMN,"^")_"V"_$PIECE(VAFCMN,"^",2)_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_SITA_SUBCOMP_"L"
Begin DoDot:3
End DoDot:3
+53 ;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
+54 ;**707 TO ONLY SEND DATE NO TIME
IF $EXTRACT($PIECE(VAFCMN,"^"),1,3)=STN
SET APID(4)=APID(4)_COMP_COMP_$$HLDATE^HLFNC(DT,"DT")
End DoDot:2
+55 IF $GET(SSN)'=""
SET APID(4)=APID(4)_$SELECT(APID(4)'="":REP,1:"")_SSN_COMP_COMP_COMP_"USSSA"_SUBCOMP_SUBCOMP_"0363"_COMP_"SS"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L"
+56 ;**837,MVI_879: Move here, so that LVL gets set before pulling in TIN and FIN
SET NXTC=0
SET LVL=0
+57 ;**837,MVI_879: Get TIN and FIN from Patient file and put in PID-3
+58 ;**1059, VAMPI-11120 (dri) Get ITIN from Patient file and put in PID-3
+59 NEW TIN,FIN,ITIN,REF
+60 SET TIN=$PIECE(VAFCMN,"^",8)
SET FIN=$PIECE(VAFCMN,"^",9)
SET ITIN=$PIECE(VAFCMN,"^",11)
SET REF=$NAME(APID(4))
+61 DO ADDLINE($SELECT(TIN="":HLQ,1:TIN)_COMP_COMP_COMP_"USDOD"_SUBCOMP_SUBCOMP_"0363"_COMP_"TIN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
+62 DO ADDLINE($SELECT(FIN="":HLQ,1:FIN)_COMP_COMP_COMP_"USDOD"_SUBCOMP_SUBCOMP_"0363"_COMP_"FIN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
+63 DO ADDLINE($SELECT(ITIN="":HLQ,1:ITIN)_COMP_COMP_COMP_"USIRS"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
+64 IF $GET(DFN)'=""
Begin DoDot:2
+65 DO ADDLINE(DFN_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PI"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
+66 ;CLAIM# **707 moved dfn and claim number up here since Alias SSN could be many
+67 IF $DATA(^DPT(DFN,.31))
SET CLAIM=$PIECE(^DPT(DFN,.31),"^",3)
IF +CLAIM>0
DO ADDLINE(CLAIM_COMP_COMP_COMP_"USVBA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PN"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
End DoDot:2
+68 IF $DATA(VAFCA1)
Begin DoDot:2
+69 ;Have Alias SSNs
+70 SET CT=0
FOR
SET CT=$ORDER(VAFCA1(CT))
if +CT<1
QUIT
Begin DoDot:3
+71 SET NXT=$SELECT($GET(VAFCA1(CT,"SSN"))="":HL("Q"),1:$GET(VAFCA1(CT,"SSN")))_COMP_COMP_COMP_"USSSA"_SUBCOMP_SUBCOMP_"0363"_COMP_"SS"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(DT,"DT")
+72 IF LVL=0
Begin DoDot:4
+73 IF $LENGTH(APID(4)_NXT)'>244
SET APID(4)=APID(4)_REP_NXT
QUIT
+74 IF $LENGTH(APID(4)_NXT)>244
SET LVL=1
SET LNGTH=244-$LENGTH(APID(4))
SET APID(4)=APID(4)_REP_$EXTRACT(NXT,1,LNGTH)
SET LNGTH=LNGTH+1
SET NXT=$EXTRACT(NXT,LNGTH,$LENGTH(NXT))
SET NXTC=1
End DoDot:4
+75 IF LVL>0
Begin DoDot:4
+76 IF $LENGTH($GET(APID(4,LVL))_NXT)'>245
SET APID(4,LVL)=$GET(APID(4,LVL))_$SELECT(NXTC=0:REP,1:"")_NXT
QUIT
+77 IF $LENGTH($GET(APID(4,LVL))_NXT)>245
SET LNGTH=244-$LENGTH(APID(4,LVL))
SET APID(4,LVL)=APID(4,LVL)_REP_$EXTRACT(NXT,1,LNGTH)
SET LNGTH=LNGTH+1
SET NXT=$EXTRACT(NXT,LNGTH,$LENGTH(NXT))
SET LVL=LVL+1
SET APID(4,LVL)=NXT
End DoDot:4
+78 IF NXTC=1
SET NXTC=0
End DoDot:3
End DoDot:2
+79 IF $DATA(^DPT(DFN,"MPIFHIS"))
NEW HIST
SET HIST=0
FOR
SET HIST=$ORDER(^DPT(DFN,"MPIFHIS",HIST))
if 'HIST
QUIT
SET VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0)
SET HISTDT=$PIECE(VAFCHMN,"^",4)
Begin DoDot:2
+80 ;**477 due to a timing issue if checksum and D/T of deprecation of ICN is not present hang two seconds and try again if still not able to get ICN set D/T to DT
+81 IF $GET(HISTDT)=""
HANG 2
SET VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0)
SET HISTDT=$PIECE(VAFCHMN,"^",4)
IF HISTDT=""
SET HISTDT=DT
+82 IF APID(4)'=""
Begin DoDot:3
+83 ; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
+84 IF $EXTRACT($PIECE(VAFCHMN,"^"),1,3)=+STN
SET SITA=+STN
IF SITA=741
SET SITA="741MM"
+85 ; **707 update assigning authority for national ICNs to 200M for MPI
IF $EXTRACT($PIECE(VAFCHMN,"^"),1,3)'=+STN
SET SITA="200M"
+86 ;**648 only send date not time
SET NXT=$PIECE(VAFCHMN,"^")_"V"_$PIECE(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")
+87 IF LVL=0
Begin DoDot:4
+88 IF $LENGTH(APID(4)_NXT)'>244
SET APID(4)=APID(4)_REP_NXT
QUIT
+89 IF $LENGTH(APID(4)_NXT)>244
SET LVL=1
SET LNGTH=244-$LENGTH(APID(4))
SET APID(4)=APID(4)_REP_$EXTRACT(NXT,1,LNGTH)
SET LNGTH=LNGTH+1
SET NXT=$EXTRACT(NXT,LNGTH,$LENGTH(NXT))
SET NXTC=1
End DoDot:4
+90 IF LVL>0
Begin DoDot:4
+91 IF $LENGTH($GET(APID(4,LVL))_NXT)'>245
SET APID(4,LVL)=$GET(APID(4,LVL))_$SELECT(NXTC=0:REP,1:"")_NXT
QUIT
+92 IF $LENGTH($GET(APID(4,LVL))_NXT)>245
SET LNGTH=244-$LENGTH(APID(4,LVL))
SET APID(4,LVL)=APID(4,LVL)_REP_$EXTRACT(NXT,1,LNGTH)
SET LNGTH=LNGTH+1
SET NXT=$EXTRACT(NXT,LNGTH,$LENGTH(NXT))
SET LVL=LVL+1
SET APID(4,LVL)=NXT
End DoDot:4
End DoDot:3
+93 IF NXTC=1
SET NXTC=0
+94 IF APID(4)=""
Begin DoDot:3
+95 ; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
+96 IF $EXTRACT($PIECE(VAFCHMN,"^"),1,3)=+STN
SET SITA=+STN
IF SITA=741
SET SITA="741MM"
+97 IF $EXTRACT($PIECE(VAFCHMN,"^"),1,3)'=+STN
SET SITA="200M"
+98 ;**707 ONLY DATE NOT TIME
SET APID(4)=$PIECE(VAFCHMN,"^")_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"NI"_COMP_"VA FACILITY ID"_SUBCOMP_SITA_SUBCOMP_"L"_COMP_COMP_$$HLDATE^HLFNC(HISTDT,"DT")
End DoDot:3
End DoDot:2
End DoDot:1
+99 ;
ALTID ;**874 MVI_3035 (elz) alternate ID
+1 IF $DATA(SARY(4))!(SEQ="ALL")
Begin DoDot:1
+2 SET REF=$NAME(APID(5))
SET @REF=""
SET LVL=0
+3 IF $GET(DFN)
Begin DoDot:2
+4 ;VIC card number, station 742V1
+5 NEW VAVICF,VAVICX,VAVIC,X
+6 SET VAVICF=+$$LKUP^XUAF4("742V1")
+7 SET VAVICX=0
FOR
SET VAVICX=$ORDER(^DGCN(391.91,"APAT",DFN,VAVICF,VAVICX))
if 'VAVICX
QUIT
Begin DoDot:3
+8 FOR X=0,2
SET VAVIC(X)=$GET(^DGCN(391.91,VAVICX,X))
+9 IF $PIECE(VAVIC(2),"^",2)
IF $PIECE(VAVIC(2),"^",3)'="H"
IF $LENGTH($PIECE(VAVIC(2),"^"))
IF $LENGTH($PIECE(VAVIC(0),"^",9))
Begin DoDot:4
+10 DO ADDLINE($PIECE(VAVIC(2),"^",2)_COMP_COMP_COMP_$PIECE(VAVIC(2),"^")_SUBCOMP_SUBCOMP_"0363"_COMP_$PIECE(VAVIC(0),"^",9)_COMP_"VA FACILITY ID"_SUBCOMP_"742V1"_SUBCOMP_"L",.LVL,REF,REP)
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+11 ;
NAMEPID ;patient name (last^first^middle^suffix^prefix^^"L" for legal)
+1 IF $DATA(SARY(5))!(SEQ="ALL")
Begin DoDot:1
+2 ;**711 code REMOVED PREFIX due to issues with existing PATIENT Name Standardization functionality
+3 NEW X
SET X=$PIECE(VAFCZN,"^")
DO NAME^VAFCPID2(DFN,.X)
SET APID(6)=$$HLNAME^XLFNAME(X,"",$EXTRACT(HL("ECH"),1))
IF $PIECE(APID(6),$EXTRACT(HL("ECH"),1),7)'="L"
SET $PIECE(APID(6),$EXTRACT(HL("ECH"),1),7)="L"
PREFNAME ; Story 455447 (elz)DG*5.3*937 Preferred Name (^preferred name^^^^^"N" for nickname)
+1 NEW PREFNAM
SET PREFNAM=$PIECE($GET(^DPT(DFN,.24)),"^",5)
+2 DO HL7TXT(.PREFNAM,.HL,HLES)
SET APID(6)=APID(6)_$SELECT(APID(6)]"":REP,1:"")_$SELECT(PREFNAM]"":PREFNAM,1:"""""")_COMP_COMP_COMP_COMP_COMP_COMP_"N"
ALIAS ;patient alias (last^first^middle^suffice^prefix^^"A" for alias - can be multiple)
+1 NEW ALIAS,ALIEN,LVL6,NXTC,LNGTH
SET NXTC=0
SET LVL6=0
+2 IF $DATA(VAFCA1)
SET ALIEN=0
FOR
SET ALIEN=$ORDER(VAFCA1(ALIEN))
if 'ALIEN
QUIT
Begin DoDot:2
+3 ;**974,Story 841921 (mko): Get the Name Components themselves
+4 ; rather than parsing them out of the Name field
+5 IF $GET(VAFCA1(ALIEN,"NCIEN"))>0
Begin DoDot:3
+6 NEW NAMEC
+7 SET NAMEC("FILE")=2.01
SET NAMEC("IENS")=$PIECE(VAFCA1(ALIEN,"NCIEN"),"^",2)
SET NAMEC("FIELD")=.01
+8 SET ALIAS=$$HLNAME^XLFNAME(.NAMEC,"",$EXTRACT(HL("ECH")))
End DoDot:3
+9 IF '$TEST
SET ALIAS=$$HLNAME^XLFNAME(VAFCA1(ALIEN,"NAME"),"",$EXTRACT(HL("ECH"),1))
+10 if ALIAS=""
QUIT
+11 SET $PIECE(ALIAS,$EXTRACT(HL("ECH"),1),7)="A"
+12 IF LVL6=0
Begin DoDot:3
+13 IF $LENGTH(APID(6)_ALIAS)'>244
SET APID(6)=APID(6)_REP_ALIAS
QUIT
+14 IF $LENGTH(APID(6)_ALIAS)>244
SET LVL6=1
SET LNGTH=244-$LENGTH(APID(6))
SET APID(6)=APID(6)_REP_$EXTRACT(ALIAS,1,LNGTH)
SET LNGTH=LNGTH+1
SET ALIAS=$EXTRACT(ALIAS,LNGTH,$LENGTH(ALIAS))
SET NXTC=1
End DoDot:3
+15 IF LVL6>0
Begin DoDot:3
+16 IF $LENGTH($GET(APID(6,LVL6))_ALIAS)'>245
SET APID(6,LVL6)=$GET(APID(6,LVL6))_$SELECT(NXTC=0:REP,1:"")_ALIAS
QUIT
+17 IF $LENGTH($GET(APID(6,LVL6))_ALIAS)>245
SET LNGTH=244-$LENGTH(APID(6,LVL6))
SET APID(6,LVL6)=APID(6,LVL6)_REP_$EXTRACT(ALIAS,1,LNGTH)
SET LNGTH=LNGTH+1
SET ALIAS=$EXTRACT(ALIAS,LNGTH,$LENGTH(ALIAS))
SET LVL6=LVL6+1
SET APID(6,LVL6)=ALIAS
End DoDot:3
+18 IF NXTC=1
SET NXTC=0
End DoDot:2
+19 IF APID(6)=""
SET APID(6)=HL("Q")
End DoDot:1
MOTHER ;mother's maiden name (last^first^middle^suffix^prefix^^"M" for maiden name)
+1 IF $DATA(SARY(6))!(SEQ="ALL")
Begin DoDot:1
+2 SET APID(7)=HL("Q")
+3 IF $DATA(^DPT(DFN,.24))
SET VAFCMMN=$PIECE(^DPT(DFN,.24),"^",3)
Begin DoDot:2
+4 SET APID(7)=$$HLNAME^XLFNAME(VAFCMMN,"",$EXTRACT(HL("ECH"),1))
IF APID(7)=""
SET APID(7)=HL("Q")
+5 IF $PIECE(APID(7),$EXTRACT(HL("ECH"),1),7)'="M"
SET $PIECE(APID(7),$EXTRACT(HL("ECH"),1),7)="M"
End DoDot:2
+6 IF APID(7)=""
SET APID(7)=HL("Q")
End DoDot:1
+7 ;date/time of birth
IF $DATA(SARY(7))!(SEQ="ALL")
SET APID(8)=$$HLDATE^HLFNC($PIECE(VAFCZN,"^",3))
IF APID(8)=""
SET APID(8)=HL("Q")
+8 ;sex
IF $DATA(SARY(8))!(SEQ="ALL")
SET APID(9)=$PIECE(VAFCZN,"^",2)
IF APID(9)=""
SET APID(9)=HL("Q")
+9 ;place of birth city and state
+10 ;split into 2 routines **707
+11 DO CONT^VAFCQRY3(DFN,.APID,.PID,.HL,HLES,.SARY,SEQ,.ERR,REP,COMP,SSN,VAFCMN)
+12 DO KVA^VADPT
+13 QUIT
+14 ;
HL7TXT(HL7STRG,HL,HLES) ; Replace occurrences of embedded HL7 delimiters with
+1 ; HL7 escape sequence
+2 ;
+3 ; Inputs: HL7STRG - Data string to be checked
+4 ; HL("ECH") - HL7 delimiter string
+5 ; Delimiters MUST be in the following order,
+6 ; Escape, Field, Component, Repeat, Subcomponent
+7 ; Example: \^~|&
+8 ;
+9 ; Output: HL7XTRG - Data string with escape sequence added (if needed)
+10 ;
+11 NEW OCHR,RCHR,RCHRI,TYPE,I,HLES2
+12 ;
+13 IF $GET(HL("COMP"))=""
SET HL("COMP")=$EXTRACT(HL("ECH"),1)
SET HL("REP")=$EXTRACT(HL("ECH"),2)
SET HL("SUBCOMP")=$EXTRACT(HL("ECH"),4)
+14 ; Set HL7 escape char
+15 SET HLES2=HLES_HL("FS")_HL("COMP")_HL("REP")_HL("SUBCOMP")
+16 ;
+17 ; Search for occurrence of each delimiter and replace it with "\<type>\"
+18 FOR TYPE="E","F","C","R","S"
Begin DoDot:1
+19 SET RCHRI=$SELECT(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
+20 ;
+21 ; OCHR=original char, RCHR=replacement char
+22 SET OCHR=$EXTRACT(HLES2,RCHRI)
SET RCHR=$EXTRACT("EFSRT",RCHRI)
if '$FIND(HL7STRG,OCHR)
QUIT
+23 FOR I=1:1
if $EXTRACT(HL7STRG,I)=""
QUIT
IF $EXTRACT(HL7STRG,I)=OCHR
SET HL7STRG=$EXTRACT(HL7STRG,1,I-1)_HLES_RCHR_HLES_$EXTRACT(HL7STRG,I+1,999)
SET I=I+2
End DoDot:1
+24 QUIT
+25 ;
ADDLINE(NXT,LVL,REF,REP) ; Prepend REP to NXT and add it to the @REF
+1 ; array, starting at subscript LVL. If appending NXT causes the node
+2 ; to exceed 245 chars in length, add as much of NXT as possible to the
+3 ; current level, and the remaining at the next level.
+4 ; In:
+5 ; NXT = string to add to the @REF array
+6 ; .LVL = current subscript level (passed by referenced)
+7 ; REF = array reference string
+8 ; REP = repetition character (e.g., |)
+9 ; **837,MVI_879: Created this subroutine to aid in adding TIN and FIN to PID-3.
+10 NEW LNGTH,CURREF
+11 if $GET(LVL)<1
SET LVL=0
+12 SET CURREF=$SELECT(LVL=0:REF,1:$NAME(@REF@(LVL)))
+13 IF LVL>0!($GET(@CURREF)]"")
SET NXT=REP_NXT
+14 IF $LENGTH($GET(@CURREF))+$LENGTH(NXT)'>245
SET @CURREF=$GET(@CURREF)_NXT
+15 IF '$TEST
SET LNGTH=245-$LENGTH(@CURREF)
SET @CURREF=@CURREF_$EXTRACT(NXT,1,LNGTH)
SET LVL=LVL+1
SET @REF@(LVL)=$EXTRACT(NXT,LNGTH+1,$LENGTH(NXT))
+16 QUIT
+17 ;