MHV7BU ;WAS/EFJ - HL7 message builder UTILITY ; [12/14/06 11:10am]
;;1.0;My HealtheVet;**2,29**;July 10, 2017;Build 73
;;Per VHA Directive 2004-038, this routine should not be modified.
;
; Utilities common to message and segment builders.
;
Q
;
PID3(PID,ICN,DFN,SSN) ;Build PID3 - Patient Identifier List
; Populates PID array with Patient Identifier List Entries for
; ICN, DFN, and SSN.
;
; Integration Agreements:
; 10112 : $$SITE^VASITE
;
; Input:
; ICN, DFN, SSN - Identifiers
;
; Output:
; PID - PID array
;
N STATION,IDCNT
S STATION=$P($$SITE^VASITE,"^",3)
S IDCNT=0
I ICN'="" D
. S IDCNT=IDCNT+1
. S PID(3,IDCNT,1)=ICN ;Patient ID - ICN
. S PID(3,IDCNT,4,1)="USVHA" ;assigning authority ID
. S PID(3,IDCNT,4,3)="HL70363" ;assigning authority type
. S PID(3,IDCNT,5)="NI" ;Patient ID type
. S PID(3,IDCNT,6,1)="VA FACILITY ID" ;assigning facility
. S PID(3,IDCNT,6,2)=STATION ;Station number
. S PID(3,IDCNT,6,3)="L" ;facility ID type
;
I DFN'="" D
. S IDCNT=IDCNT+1
. S PID(3,IDCNT,1)=DFN ;Patient ID - DFN
. S PID(3,IDCNT,4,1)="USVHA" ;assigning authority ID
. S PID(3,IDCNT,4,3)="HL70363" ;assigning authority type
. S PID(3,IDCNT,5)="PI" ;Patient ID type
. S PID(3,IDCNT,6,1)="VA FACILITY ID" ;assigning facility
. S PID(3,IDCNT,6,2)=STATION ;Station number
. S PID(3,IDCNT,6,3)="L" ;facility ID type
;
I SSN'="" D
. S IDCNT=IDCNT+1
. S PID(3,IDCNT,1)=SSN ;Patient ID - SSN
. S PID(3,IDCNT,4,1)="USSSA" ;assigning authority ID
. S PID(3,IDCNT,4,3)="HL70363" ;assigning authority type
. S PID(3,IDCNT,5)="SS" ;Patient ID type
. S PID(3,IDCNT,6,1)="VA FACILITY ID" ;assigning facility
. S PID(3,IDCNT,6,2)=STATION ;Station number
. S PID(3,IDCNT,6,3)="L" ;facility ID type
Q
;
FMTNAME(NAME,SUBSEG,HL,DATATYPE) ;Format comma/space delimited name
; Populates SUBSEG array with formatted and escaped name components
; based on the DATATYPE passed. XCN types and XPN types differ in
; that XCN has an ID in the first component effectively shifting the
; name components by one.
;
; Integration Agreements:
; 3065 : NAMEFMT^XLFNAME
;
; Input:
; NAME - FileMan formatted name Ex: PATIENT,FIRST M
; HL - HL7 package array variable
; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
;
; Output:
; SUBSEG - Array to hold the formatted name.
;
; Example Usage:
; S NAME="SMITH,BOB A"
; K NMARR
; D FMTNAME^MHV7BU(NAME,.NMARR,.HL,"XCN")
; M PD1(4,1)=NMARR
;
N OFFSET
S OFFSET=(DATATYPE="XCN")
S NAME=$$NAMEFMT^XLFNAME(.NAME,"F","DSP")
S SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",1),.HL) ;family
S SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",2),.HL) ;given
S SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",3),.HL) ;middle
S SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",4),.HL) ;suffix
S SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",5),.HL) ;prefix
S SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",6),.HL) ;degree
Q
;
FMTNAME2(IEN,FILE,SUBSEG,HL,DATATYPE) ;Lookup and format name
; Looks up name components based on IEN and FILE passed.
; Populates SUBSEG array with formatted and escaped name components
; based on the DATATYPE passed. XCN types and XPN types differ in
; that XCN has an ID in the first component effectively shifting the
; name components by one.
;
; Integration Agreements:
; 3065 : NAMEFMT^XLFNAME
;
; Input:
; IEN - IEN of patient/person in FILE
; FILE - File number of file Ex: 2 - PATIENT file
; HL - HL7 package array variable
; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
;
; Output:
; SUBSEG - Array to hold the formatted name.
;
; Example Usage:
; K NMARR
; D FMTNAME^MHV7BU(DFN,2,.NMARR,.HL,"XPN")
; M PID(5,1)=NMARR
;
N NAME,OFFSET
S OFFSET=(DATATYPE="XCN")
S NAME("FILE")=FILE,NAME("FIELD")=.01,NAME("IENS")=IEN_","
S NAME=$$NAMEFMT^XLFNAME(.NAME,"F","DSP")
S SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",1),.HL) ;family
S SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",2),.HL) ;given
S SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",3),.HL) ;middle
S SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",4),.HL) ;suffix
S SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",5),.HL) ;prefix
S SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($P(NAME," ",6),.HL) ;degree
Q
;
FMTNAME3(IEN,FILE,SUBSEG,HL,DATATYPE) ;Lookup and format name
;JAZZ#409966 -NeW Function for Names with Space not showing in SM queries
;========================================================================
; Looks up name components based on IEN and FILE passed.
; Populates SUBSEG array with formatted and escaped name components
; based on the DATATYPE passed. XCN types and XPN types differ in
; that XCN has an ID in the first component effectively shifting the
; name components by one.
;
; Integration Agreements:
; 3065 : NAMEFMT^XLFNAME
;
; Input:
; IEN - IEN of patient/person in FILE
; FILE - File number of file Ex: 2 - PATIENT file
; HL - HL7 package array variable
; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
;
; Output:
; SUBSEG - Array to hold the formatted name.
;
; Example Usage:
; K NMARR
; D FMTNAME^MHV7BU(DFN,2,.NMARR,.HL,"XPN")
; M PID(5,1)=NMARR
;
N NAME,OFFSET
S OFFSET=(DATATYPE="XCN")
S NAME("FILE")=FILE,NAME("FIELD")=.01,NAME("IENS")=IEN_","
S NAME=$$HLNAME^XLFNAME(.NAME)
S SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",1),.HL) ;family
S SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",2),.HL) ;given
S SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",3),.HL) ;middle
S SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",4),.HL) ;suffix
S SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",5),.HL) ;prefix
S SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($P(NAME,"^",6),.HL) ;degree
Q
;
FMTHL7(DT) ;Convert Fileman formatted dates to HL7 format
; Handles imprecise dates properly because $$FMTHL7^XLFDT does not.
; Strips Timezone offset
;
; Integration Agreements:
; 10103 : FMTHL7^XLFDT
;
; Input:
; DT - Fileman formatted date/time
;
; Output: Returns HL7 formatted date/time
;
S DT=$$FMTHL7^XLFDT(DT)
I $E(DT,7,8)="00" S DT=$E(DT,1,6)
I $E(DT,5,6)="00" S DT=$E(DT,1,4)
S DT=$P(DT,"-")
S DT=$P(DT,"+")
Q DT
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMHV7BU 6717 printed Dec 13, 2024@02:15:52 Page 2
MHV7BU ;WAS/EFJ - HL7 message builder UTILITY ; [12/14/06 11:10am]
+1 ;;1.0;My HealtheVet;**2,29**;July 10, 2017;Build 73
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; Utilities common to message and segment builders.
+5 ;
+6 QUIT
+7 ;
PID3(PID,ICN,DFN,SSN) ;Build PID3 - Patient Identifier List
+1 ; Populates PID array with Patient Identifier List Entries for
+2 ; ICN, DFN, and SSN.
+3 ;
+4 ; Integration Agreements:
+5 ; 10112 : $$SITE^VASITE
+6 ;
+7 ; Input:
+8 ; ICN, DFN, SSN - Identifiers
+9 ;
+10 ; Output:
+11 ; PID - PID array
+12 ;
+13 NEW STATION,IDCNT
+14 SET STATION=$PIECE($$SITE^VASITE,"^",3)
+15 SET IDCNT=0
+16 IF ICN'=""
Begin DoDot:1
+17 SET IDCNT=IDCNT+1
+18 ;Patient ID - ICN
SET PID(3,IDCNT,1)=ICN
+19 ;assigning authority ID
SET PID(3,IDCNT,4,1)="USVHA"
+20 ;assigning authority type
SET PID(3,IDCNT,4,3)="HL70363"
+21 ;Patient ID type
SET PID(3,IDCNT,5)="NI"
+22 ;assigning facility
SET PID(3,IDCNT,6,1)="VA FACILITY ID"
+23 ;Station number
SET PID(3,IDCNT,6,2)=STATION
+24 ;facility ID type
SET PID(3,IDCNT,6,3)="L"
End DoDot:1
+25 ;
+26 IF DFN'=""
Begin DoDot:1
+27 SET IDCNT=IDCNT+1
+28 ;Patient ID - DFN
SET PID(3,IDCNT,1)=DFN
+29 ;assigning authority ID
SET PID(3,IDCNT,4,1)="USVHA"
+30 ;assigning authority type
SET PID(3,IDCNT,4,3)="HL70363"
+31 ;Patient ID type
SET PID(3,IDCNT,5)="PI"
+32 ;assigning facility
SET PID(3,IDCNT,6,1)="VA FACILITY ID"
+33 ;Station number
SET PID(3,IDCNT,6,2)=STATION
+34 ;facility ID type
SET PID(3,IDCNT,6,3)="L"
End DoDot:1
+35 ;
+36 IF SSN'=""
Begin DoDot:1
+37 SET IDCNT=IDCNT+1
+38 ;Patient ID - SSN
SET PID(3,IDCNT,1)=SSN
+39 ;assigning authority ID
SET PID(3,IDCNT,4,1)="USSSA"
+40 ;assigning authority type
SET PID(3,IDCNT,4,3)="HL70363"
+41 ;Patient ID type
SET PID(3,IDCNT,5)="SS"
+42 ;assigning facility
SET PID(3,IDCNT,6,1)="VA FACILITY ID"
+43 ;Station number
SET PID(3,IDCNT,6,2)=STATION
+44 ;facility ID type
SET PID(3,IDCNT,6,3)="L"
End DoDot:1
+45 QUIT
+46 ;
FMTNAME(NAME,SUBSEG,HL,DATATYPE) ;Format comma/space delimited name
+1 ; Populates SUBSEG array with formatted and escaped name components
+2 ; based on the DATATYPE passed. XCN types and XPN types differ in
+3 ; that XCN has an ID in the first component effectively shifting the
+4 ; name components by one.
+5 ;
+6 ; Integration Agreements:
+7 ; 3065 : NAMEFMT^XLFNAME
+8 ;
+9 ; Input:
+10 ; NAME - FileMan formatted name Ex: PATIENT,FIRST M
+11 ; HL - HL7 package array variable
+12 ; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
+13 ;
+14 ; Output:
+15 ; SUBSEG - Array to hold the formatted name.
+16 ;
+17 ; Example Usage:
+18 ; S NAME="SMITH,BOB A"
+19 ; K NMARR
+20 ; D FMTNAME^MHV7BU(NAME,.NMARR,.HL,"XCN")
+21 ; M PD1(4,1)=NMARR
+22 ;
+23 NEW OFFSET
+24 SET OFFSET=(DATATYPE="XCN")
+25 SET NAME=$$NAMEFMT^XLFNAME(.NAME,"F","DSP")
+26 ;family
SET SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",1),.HL)
+27 ;given
SET SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",2),.HL)
+28 ;middle
SET SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",3),.HL)
+29 ;suffix
SET SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",4),.HL)
+30 ;prefix
SET SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",5),.HL)
+31 ;degree
SET SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",6),.HL)
+32 QUIT
+33 ;
FMTNAME2(IEN,FILE,SUBSEG,HL,DATATYPE) ;Lookup and format name
+1 ; Looks up name components based on IEN and FILE passed.
+2 ; Populates SUBSEG array with formatted and escaped name components
+3 ; based on the DATATYPE passed. XCN types and XPN types differ in
+4 ; that XCN has an ID in the first component effectively shifting the
+5 ; name components by one.
+6 ;
+7 ; Integration Agreements:
+8 ; 3065 : NAMEFMT^XLFNAME
+9 ;
+10 ; Input:
+11 ; IEN - IEN of patient/person in FILE
+12 ; FILE - File number of file Ex: 2 - PATIENT file
+13 ; HL - HL7 package array variable
+14 ; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
+15 ;
+16 ; Output:
+17 ; SUBSEG - Array to hold the formatted name.
+18 ;
+19 ; Example Usage:
+20 ; K NMARR
+21 ; D FMTNAME^MHV7BU(DFN,2,.NMARR,.HL,"XPN")
+22 ; M PID(5,1)=NMARR
+23 ;
+24 NEW NAME,OFFSET
+25 SET OFFSET=(DATATYPE="XCN")
+26 SET NAME("FILE")=FILE
SET NAME("FIELD")=.01
SET NAME("IENS")=IEN_","
+27 SET NAME=$$NAMEFMT^XLFNAME(.NAME,"F","DSP")
+28 ;family
SET SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",1),.HL)
+29 ;given
SET SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",2),.HL)
+30 ;middle
SET SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",3),.HL)
+31 ;suffix
SET SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",4),.HL)
+32 ;prefix
SET SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",5),.HL)
+33 ;degree
SET SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME," ",6),.HL)
+34 QUIT
+35 ;
FMTNAME3(IEN,FILE,SUBSEG,HL,DATATYPE) ;Lookup and format name
+1 ;JAZZ#409966 -NeW Function for Names with Space not showing in SM queries
+2 ;========================================================================
+3 ; Looks up name components based on IEN and FILE passed.
+4 ; Populates SUBSEG array with formatted and escaped name components
+5 ; based on the DATATYPE passed. XCN types and XPN types differ in
+6 ; that XCN has an ID in the first component effectively shifting the
+7 ; name components by one.
+8 ;
+9 ; Integration Agreements:
+10 ; 3065 : NAMEFMT^XLFNAME
+11 ;
+12 ; Input:
+13 ; IEN - IEN of patient/person in FILE
+14 ; FILE - File number of file Ex: 2 - PATIENT file
+15 ; HL - HL7 package array variable
+16 ; DATATYPE - HL7 data type to be formatted Ex: XCN, XPN
+17 ;
+18 ; Output:
+19 ; SUBSEG - Array to hold the formatted name.
+20 ;
+21 ; Example Usage:
+22 ; K NMARR
+23 ; D FMTNAME^MHV7BU(DFN,2,.NMARR,.HL,"XPN")
+24 ; M PID(5,1)=NMARR
+25 ;
+26 NEW NAME,OFFSET
+27 SET OFFSET=(DATATYPE="XCN")
+28 SET NAME("FILE")=FILE
SET NAME("FIELD")=.01
SET NAME("IENS")=IEN_","
+29 SET NAME=$$HLNAME^XLFNAME(.NAME)
+30 ;family
SET SUBSEG(1+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",1),.HL)
+31 ;given
SET SUBSEG(2+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",2),.HL)
+32 ;middle
SET SUBSEG(3+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",3),.HL)
+33 ;suffix
SET SUBSEG(4+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",4),.HL)
+34 ;prefix
SET SUBSEG(5+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",5),.HL)
+35 ;degree
SET SUBSEG(6+OFFSET)=$$ESCAPE^MHV7U($PIECE(NAME,"^",6),.HL)
+36 QUIT
+37 ;
FMTHL7(DT) ;Convert Fileman formatted dates to HL7 format
+1 ; Handles imprecise dates properly because $$FMTHL7^XLFDT does not.
+2 ; Strips Timezone offset
+3 ;
+4 ; Integration Agreements:
+5 ; 10103 : FMTHL7^XLFDT
+6 ;
+7 ; Input:
+8 ; DT - Fileman formatted date/time
+9 ;
+10 ; Output: Returns HL7 formatted date/time
+11 ;
+12 SET DT=$$FMTHL7^XLFDT(DT)
+13 IF $EXTRACT(DT,7,8)="00"
SET DT=$EXTRACT(DT,1,6)
+14 IF $EXTRACT(DT,5,6)="00"
SET DT=$EXTRACT(DT,1,4)
+15 SET DT=$PIECE(DT,"-")
+16 SET DT=$PIECE(DT,"+")
+17 QUIT DT
+18 ;