Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: VAFCQRY1

VAFCQRY1.m

Go to the documentation of this file.
  1. 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
  1. ;
  1. ;Reference to $$GETDFNS^MPIF002 supported by IA #3634.
  1. ;
  1. BLDPID(DFN,CNT,SEQ,PID,HL,ERR) ;build PID from File #2
  1. ; Variable list
  1. ; DFN - internal PATIENT (#2) number
  1. ; CNT - value to be place in PID seq#1 (SET ID)
  1. ; SEQ - variable consisting of sequence numbers delimited by commas
  1. ; that will be used to build the message (default is ALL)
  1. ; PID (passed by reference) - array location to place PID segment
  1. ; result, the array can have existing values when passed.
  1. ; HL - array that contains the necessary HL variables (init^hlsub)
  1. ; ERR - array that is used to return an error
  1. ;
  1. ; DG*5.3*981 introduced changes to support the local modifications for HAC/MVI integration in CH*1.3*22529.
  1. ;
  1. 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
  1. I '$D(SEQ) S SEQ="ALL"
  1. I SEQ="" S SEQ="ALL"
  1. I SEQ'="ALL" D
  1. .; setting up temp array to hold fields to be included in message
  1. .N POS,EN S POS=1 F S EN=$P(SEQ,",",POS) Q:EN="" S SARY(EN)="",POS=POS+1
  1. S HLECH=HL("ECH"),HLFS=HL("FS"),HLQ=HL("Q"),(COMP,HL("COMP"))=$E(HL("ECH"),1)
  1. S (SUBCOMP,HL("SUBCOMP"))=$E(HL("ECH"),4),(REP,HL("REP"))=$E(HL("ECH"),2),HLES=$E(HL("ECH"),3)
  1. ;get Patient File MPI node
  1. S VAFCMN=""
  1. N X S X="MPIFAPI" X ^%ZOSF("TEST") I $T S VAFCMN=$$MPINODE^MPIFAPI(DFN)
  1. I +VAFCMN<0 S VAFCMN=""
  1. S VAFCZN=^DPT(DFN,0),SSN=$P(^DPT(DFN,0),"^",9)
  1. ;**974,Story 841921 (mko): Get the internal Alias values instead of external
  1. ; so that the internal pointer (IEN) of the Name Components entry can be retrieved.
  1. ; In the following code, values are obtained from the "I" nodes instead of the "E" nodes.
  1. N VAFCA,VAFCA1 D GETS^DIQ(2,DFN_",","1*","I","VAFCA") ;**698 GETTING ALIAS INFO
  1. ;** 707 reformat alias information to include ALIAS SSN in PID-3 with a location reference to the name in PID-5
  1. I $D(VAFCA) N CT,ENT S CT=0,ENT="" F S ENT=$O(VAFCA(2.01,ENT)) Q:ENT="" D
  1. .S CT=CT+1
  1. .S VAFCA1(CT,"NAME")=$G(VAFCA(2.01,ENT,.01,"I"))
  1. .;I $G(VAFCA(2.01,ENT,1,"E"))'="" S VAFCA1("SSN")="",VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"E"))
  1. .S VAFCA1(CT,"SSN")=$G(VAFCA(2.01,ENT,1,"I"))
  1. .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
  1. ;custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
  1. S SITE=$$SITE^VASITE,STN=$P($$SITE^VASITE,"^",3) I STN=741 S STN="741MM"
  1. N TMP F TMP=1:1:31 S APID(TMP)=""
  1. S APID(2)=CNT
  1. ;list of fields used for backwards compatibility with HDR
  1. I $D(SARY(2))!(SEQ="ALL") I VAFCMN'="" S APID(3)=$P(VAFCMN,"^")_"V"_$P(VAFCMN,"^",2) ;Patient ID
  1. ;repeat patient ID list including ICN (NI),SSN (SS),CLAIM# (PN) and DFN (PI)
  1. I $D(SARY(3))!(SEQ="ALL") D
  1. .S APID(4)=""
  1. .;National Identifier (ICN)
  1. .I VAFCMN'="",+VAFCMN>0 D
  1. ..I $E($P(VAFCMN,"^"),1,3)=STN S SITA=STN
  1. ..; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
  1. ..I $E($P(VAFCMN,"^"),1,3)=+STN I +STN="741" S SITA=+STN I SITA=741 S SITA="741MM"
  1. ..I $E($P(VAFCMN,"^"),1,3)'=+STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
  1. ..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
  1. ..;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
  1. ..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
  1. .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"
  1. .S NXTC=0,LVL=0 ;**837,MVI_879: Move here, so that LVL gets set before pulling in TIN and FIN
  1. .;**837,MVI_879: Get TIN and FIN from Patient file and put in PID-3
  1. .;**1059, VAMPI-11120 (dri) Get ITIN from Patient file and put in PID-3
  1. .N TIN,FIN,ITIN,REF
  1. .S TIN=$P(VAFCMN,"^",8),FIN=$P(VAFCMN,"^",9),ITIN=$P(VAFCMN,"^",11),REF=$NA(APID(4))
  1. .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)
  1. .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)
  1. .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)
  1. .I $G(DFN)'="" D
  1. ..D ADDLINE(DFN_COMP_COMP_COMP_"USVHA"_SUBCOMP_SUBCOMP_"0363"_COMP_"PI"_COMP_"VA FACILITY ID"_SUBCOMP_STN_SUBCOMP_"L",.LVL,REF,REP)
  1. ..;CLAIM# **707 moved dfn and claim number up here since Alias SSN could be many
  1. ..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)
  1. .I $D(VAFCA1) D
  1. ..;Have Alias SSNs
  1. ..S CT=0 F S CT=$O(VAFCA1(CT)) Q:+CT<1 D
  1. ...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")
  1. ...I LVL=0 D
  1. ....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
  1. ....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
  1. ...I LVL>0 D
  1. ....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
  1. ....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
  1. ...I NXTC=1 S NXTC=0
  1. .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
  1. ..;**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
  1. ..I $G(HISTDT)="" H 2 S VAFCHMN=^DPT(DFN,"MPIFHIS",HIST,0) S HISTDT=$P(VAFCHMN,"^",4) I HISTDT="" S HISTDT=DT
  1. ..I APID(4)'="" D
  1. ...; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
  1. ...I $E($P(VAFCHMN,"^"),1,3)=+STN S SITA=+STN I SITA=741 S SITA="741MM"
  1. ...I $E($P(VAFCHMN,"^"),1,3)'=+STN S SITA="200M" ; **707 update assigning authority for national ICNs to 200M for MPI
  1. ...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
  1. ...I LVL=0 D
  1. ....I $L(APID(4)_NXT)'>244 S APID(4)=APID(4)_REP_NXT Q
  1. ....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
  1. ...I LVL>0 D
  1. ....I $L($G(APID(4,LVL))_NXT)'>245 S APID(4,LVL)=$G(APID(4,LVL))_$S(NXTC=0:REP,1:"")_NXT Q
  1. ....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
  1. ..I NXTC=1 S NXTC=0
  1. ..I APID(4)="" D
  1. ...; custom change - if current site is HAC then use station number 741MM - CH*1.3*22529
  1. ...I $E($P(VAFCHMN,"^"),1,3)=+STN S SITA=+STN I SITA=741 S SITA="741MM"
  1. ...I $E($P(VAFCHMN,"^"),1,3)'=+STN S SITA="200M"
  1. ...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
  1. ;
  1. ALTID ;**874 MVI_3035 (elz) alternate ID
  1. I $D(SARY(4))!(SEQ="ALL") D
  1. . S REF=$NA(APID(5)),@REF="",LVL=0
  1. . I $G(DFN) D
  1. .. ;VIC card number, station 742V1
  1. .. N VAVICF,VAVICX,VAVIC,X
  1. .. S VAVICF=+$$LKUP^XUAF4("742V1")
  1. .. S VAVICX=0 F S VAVICX=$O(^DGCN(391.91,"APAT",DFN,VAVICF,VAVICX)) Q:'VAVICX D
  1. ... F X=0,2 S VAVIC(X)=$G(^DGCN(391.91,VAVICX,X))
  1. ... I $P(VAVIC(2),"^",2),$P(VAVIC(2),"^",3)'="H",$L($P(VAVIC(2),"^")),$L($P(VAVIC(0),"^",9)) D
  1. .... 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)
  1. ;
  1. NAMEPID ;patient name (last^first^middle^suffix^prefix^^"L" for legal)
  1. I $D(SARY(5))!(SEQ="ALL") D
  1. .;**711 code REMOVED PREFIX due to issues with existing PATIENT Name Standardization functionality
  1. .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"
  1. PREFNAME .; Story 455447 (elz)DG*5.3*937 Preferred Name (^preferred name^^^^^"N" for nickname)
  1. .N PREFNAM S PREFNAM=$P($G(^DPT(DFN,.24)),"^",5)
  1. .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"
  1. ALIAS .;patient alias (last^first^middle^suffice^prefix^^"A" for alias - can be multiple)
  1. .N ALIAS,ALIEN,LVL6,NXTC,LNGTH S NXTC=0,LVL6=0
  1. .I $D(VAFCA1) S ALIEN=0 F S ALIEN=$O(VAFCA1(ALIEN)) Q:'ALIEN D
  1. ..;**974,Story 841921 (mko): Get the Name Components themselves
  1. ..; rather than parsing them out of the Name field
  1. ..I $G(VAFCA1(ALIEN,"NCIEN"))>0 D
  1. ...N NAMEC
  1. ...S NAMEC("FILE")=2.01,NAMEC("IENS")=$P(VAFCA1(ALIEN,"NCIEN"),"^",2),NAMEC("FIELD")=.01
  1. ...S ALIAS=$$HLNAME^XLFNAME(.NAMEC,"",$E(HL("ECH")))
  1. ..E S ALIAS=$$HLNAME^XLFNAME(VAFCA1(ALIEN,"NAME"),"",$E(HL("ECH"),1))
  1. ..Q:ALIAS=""
  1. ..S $P(ALIAS,$E(HL("ECH"),1),7)="A"
  1. ..I LVL6=0 D
  1. ...I $L(APID(6)_ALIAS)'>244 S APID(6)=APID(6)_REP_ALIAS Q
  1. ...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
  1. ..I LVL6>0 D
  1. ...I $L($G(APID(6,LVL6))_ALIAS)'>245 S APID(6,LVL6)=$G(APID(6,LVL6))_$S(NXTC=0:REP,1:"")_ALIAS Q
  1. ...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
  1. ..I NXTC=1 S NXTC=0
  1. . I APID(6)="" S APID(6)=HL("Q")
  1. MOTHER ;mother's maiden name (last^first^middle^suffix^prefix^^"M" for maiden name)
  1. I $D(SARY(6))!(SEQ="ALL") D
  1. .S APID(7)=HL("Q")
  1. .I $D(^DPT(DFN,.24)) S VAFCMMN=$P(^DPT(DFN,.24),"^",3) D
  1. ..S APID(7)=$$HLNAME^XLFNAME(VAFCMMN,"",$E(HL("ECH"),1)) I APID(7)="" S APID(7)=HL("Q")
  1. ..I $P(APID(7),$E(HL("ECH"),1),7)'="M" S $P(APID(7),$E(HL("ECH"),1),7)="M"
  1. .I APID(7)="" S APID(7)=HL("Q")
  1. 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
  1. I $D(SARY(8))!(SEQ="ALL") S APID(9)=$P(VAFCZN,"^",2) I APID(9)="" S APID(9)=HL("Q") ;sex
  1. ;place of birth city and state
  1. ;split into 2 routines **707
  1. D CONT^VAFCQRY3(DFN,.APID,.PID,.HL,HLES,.SARY,SEQ,.ERR,REP,COMP,SSN,VAFCMN)
  1. D KVA^VADPT
  1. Q
  1. ;
  1. HL7TXT(HL7STRG,HL,HLES) ; Replace occurrences of embedded HL7 delimiters with
  1. ; HL7 escape sequence
  1. ;
  1. ; Inputs: HL7STRG - Data string to be checked
  1. ; HL("ECH") - HL7 delimiter string
  1. ; Delimiters MUST be in the following order,
  1. ; Escape, Field, Component, Repeat, Subcomponent
  1. ; Example: \^~|&
  1. ;
  1. ; Output: HL7XTRG - Data string with escape sequence added (if needed)
  1. ;
  1. N OCHR,RCHR,RCHRI,TYPE,I,HLES2
  1. ;
  1. I $G(HL("COMP"))="" S HL("COMP")=$E(HL("ECH"),1),HL("REP")=$E(HL("ECH"),2),HL("SUBCOMP")=$E(HL("ECH"),4)
  1. ; Set HL7 escape char
  1. S HLES2=HLES_HL("FS")_HL("COMP")_HL("REP")_HL("SUBCOMP")
  1. ;
  1. ; Search for occurrence of each delimiter and replace it with "\<type>\"
  1. F TYPE="E","F","C","R","S" D
  1. . S RCHRI=$S(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
  1. . ;
  1. . ; OCHR=original char, RCHR=replacement char
  1. . S OCHR=$E(HLES2,RCHRI),RCHR=$E("EFSRT",RCHRI) Q:'$F(HL7STRG,OCHR)
  1. . 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
  1. Q
  1. ;
  1. 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
  1. ; to exceed 245 chars in length, add as much of NXT as possible to the
  1. ; current level, and the remaining at the next level.
  1. ; In:
  1. ; NXT = string to add to the @REF array
  1. ; .LVL = current subscript level (passed by referenced)
  1. ; REF = array reference string
  1. ; REP = repetition character (e.g., |)
  1. ; **837,MVI_879: Created this subroutine to aid in adding TIN and FIN to PID-3.
  1. N LNGTH,CURREF
  1. S:$G(LVL)<1 LVL=0
  1. S CURREF=$S(LVL=0:REF,1:$NA(@REF@(LVL)))
  1. I LVL>0!($G(@CURREF)]"") S NXT=REP_NXT
  1. I $L($G(@CURREF))+$L(NXT)'>245 S @CURREF=$G(@CURREF)_NXT
  1. E S LNGTH=245-$L(@CURREF),@CURREF=@CURREF_$E(NXT,1,LNGTH),LVL=LVL+1,@REF@(LVL)=$E(NXT,LNGTH+1,$L(NXT))
  1. Q
  1. ;