VAFHADT2 ;ALB/RJS - HL7 ADT MESSAGE BUILDING ROUTINE - MAY 18,1995 ; 3/6/06 8:08am
;;5.3;Registration;**91,692,1015**;Jun 06, 1996;Build 21
;hl7v1.6
;
;This routine builds ADT HL7 messages: A01 = Admission
; A02 = Transfer
; A03 = Discharge
; A08 = Update
; A11 = Cancel Admission
; A12 = Cancel Transfer
; A13 = Cancel Discharge
;
;It is called by VAFHADT1, which is itself is called by the
;DGPM patient movement event driver.
;
;
BLDMSG(DFN,EVENT,VAFHDT,EVCODE,IEN,PIVOT,PV1) ;
;Required Variables are: DFN = IEN of Patient File
; EVENT = HL7 Event, A01, A02, A03, etc.
; VAFHDT = Date/Time of Admission, Transfer, etc
;
;Optional Variables are: Event Code = (EVCODE):A string literal which is
; inserted in the Event Reason
; Code Field of the EVN segment
; of the message. This serves to
; indicate that the message might
; need to be processed in a special
; way. PIMS ADT software uses the
; Event Code to indicate whether
; the message is the most recent
; "Snapshot" of the data "05" or
; a "Snapshot" of data that is
; followed by more recent data "04"
;
;
; IEN = The IEN of the Patient Movement
; that the HL7 message is being
; built from. This is especially
; useful for Discharge Movements
; where date/time (VAFHDT) is not
; enough information to retrieve
; the movement
;
; PIVOT = The PIMS Pivot number that
; uniquely identifies the ADMISSION
;
; PV1 = In the case of a "Deleted
; Admission" the record in the
; Patient Movement File has already
; been deleted. But, a PV1 segment
; can be built from the DGPMP
; variable that has been saved off
; by the DGPM Event Driver. This
; PV1 segment is passed a string
; literal that is built by a call
; to DGBUILD^VAFHAPV1 previous to
; calling this software.
;
K HLA N VAFDIAG
;Q:($G(EVCODE)'="05")
;D INIT^HLTRANS
K HL D INIT^HLFNC2("VAFH "_EVENT,.HL)
I $D(HL)=1 G EXIT
S HLA("HLS",2)=$$EN^VAFHLPID(DFN,",2,3,5,7,8,19")
S $P(HLA("HLS",2),HLFS,2)=1 ;SET ID
;MERGE HLA("HLS",2)=VAFPID
S HLA("HLS",3)=$$EN^VAFHLZPD(DFN,",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")
S $P(HLA("HLS",3),HLFS,2)=1 ;SET ID
I EVENT="A11" D G NEXT
. S HLA("HLS",4)=PV1
. S $P(HLA("HLS",4),HLFS,51)=$G(PIVOT) ; VISIT&SET ID'S
I EVENT="A01"!(EVENT="A03")!(EVENT="A08")!(EVENT="A12")!(EVENT="A13") D G NEXT
. S HLA("HLS",4)=$$IN^VAFHLPV1(DFN,VAFHDT,",2,3,7,8,10,19,44,45",$G(IEN),PIVOT,"",.VAFDIAG)
I EVENT="A02" D G NEXT
. S HLA("HLS",4)=$$IN^VAFHLPV1(DFN,VAFHDT,",2,3,6,7,8,10,19,44,45",$G(IEN),PIVOT,"",.VAFDIAG)
G EXIT
NEXT ;
S $P(HLA("HLS",4),HLFS,2)=1
S HLA("HLS",1)="EVN"_HLFS_EVENT_HLFS_$$HLDATE^HLFNC(VAFHDT,"TS")_HLFS
S HLA("HLS",1)=HLA("HLS",1)_HLFS_$G(EVCODE)
I (EVENT="A01")!(EVENT="A08")!(EVENT="A11")!(EVENT="A12")!(EVENT="A13") S HLA("HLS",6)="DG1"_HLFS_1_HLFS_HLFS_HLFS_$$HLQ^VAFHUTL($G(VAFDIAG))
;Get patient directory call center parameter
N VAFCCON
S VAFCCON=$$GET^XPAR("SYS","DG PT DIRECTORY CALL CENTER")
I VAFCCON S HLA("HLS",5)=$$EN^VAFHLPV2(DFN,IEN,",22,")
D:$D(VATRACE) LOOP
;
S COUNTER=""
F S COUNTER=$O(HLA("HLS",COUNTER)) Q:COUNTER'>0 D
.; I +(HLA("HLS",COUNTER))=-1 S HLERR="Bad "_COUNTER_" Segment"
. I +(HLA("HLS",COUNTER))=-1 S HL="Bad "_COUNTER_" Segment"
.
;
EXIT ;
;I $D(HLERR) D
I $D(HL)=1 DO
. S HLERR(1)=HL
. D EBULL^VAFHUTL2(DFN,VAFHDT,PIVOT,"HLERR(")
;I '$D(HLERR)&($D(HLSDATA)) S HLMTN="ADT"_$E(HLECH)_EVENT D EN^HLTRANS
I $D(HL)>1,$D(HLA("HLS")) S HLMTN="ADT"_$E(HL("ECH"))_EVENT DO
.D GENERATE^HLMA("VAFH "_EVENT,"LM",1,.HLRST)
D KVAR^VADPT,KVAR^VAFHLPV1 K HLA,HLERR
Q
LOOP ;
;
;
W !!
N XX S XX=0
F S XX=$O(HLA("HLS",XX)) Q:XX="" W !,HLA("HLS",XX)
Q
VAFHADT2 ;ALB/RJS - HL7 ADT MESSAGE BUILDING ROUTINE - MAY 18,1995 ; 3/6/06 8:08am
+1 ;;5.3;Registration;**91,692,1015**;Jun 06, 1996;Build 21
+2 ;hl7v1.6
+3 ;
+4 ;This routine builds ADT HL7 messages: A01 = Admission
+5 ; A02 = Transfer
+6 ; A03 = Discharge
+7 ; A08 = Update
+8 ; A11 = Cancel Admission
+9 ; A12 = Cancel Transfer
+10 ; A13 = Cancel Discharge
+11 ;
+12 ;It is called by VAFHADT1, which is itself is called by the
+13 ;DGPM patient movement event driver.
+14 ;
+15 ;
BLDMSG(DFN,EVENT,VAFHDT,EVCODE,IEN,PIVOT,PV1) ;
+1 ;Required Variables are: DFN = IEN of Patient File
+2 ; EVENT = HL7 Event, A01, A02, A03, etc.
+3 ; VAFHDT = Date/Time of Admission, Transfer, etc
+4 ;
+5 ;Optional Variables are: Event Code = (EVCODE):A string literal which is
+6 ; inserted in the Event Reason
+7 ; Code Field of the EVN segment
+8 ; of the message. This serves to
+9 ; indicate that the message might
+10 ; need to be processed in a special
+11 ; way. PIMS ADT software uses the
+12 ; Event Code to indicate whether
+13 ; the message is the most recent
+14 ; "Snapshot" of the data "05" or
+15 ; a "Snapshot" of data that is
+16 ; followed by more recent data "04"
+17 ;
+18 ;
+19 ; IEN = The IEN of the Patient Movement
+20 ; that the HL7 message is being
+21 ; built from. This is especially
+22 ; useful for Discharge Movements
+23 ; where date/time (VAFHDT) is not
+24 ; enough information to retrieve
+25 ; the movement
+26 ;
+27 ; PIVOT = The PIMS Pivot number that
+28 ; uniquely identifies the ADMISSION
+29 ;
+30 ; PV1 = In the case of a "Deleted
+31 ; Admission" the record in the
+32 ; Patient Movement File has already
+33 ; been deleted. But, a PV1 segment
+34 ; can be built from the DGPMP
+35 ; variable that has been saved off
+36 ; by the DGPM Event Driver. This
+37 ; PV1 segment is passed a string
+38 ; literal that is built by a call
+39 ; to DGBUILD^VAFHAPV1 previous to
+40 ; calling this software.
+41 ;
+42 KILL HLA
NEW VAFDIAG
+43 ;Q:($G(EVCODE)'="05")
+44 ;D INIT^HLTRANS
+45 KILL HL
DO INIT^HLFNC2("VAFH "_EVENT,.HL)
+46 IF $DATA(HL)=1
GOTO EXIT
+47 SET HLA("HLS",2)=$$EN^VAFHLPID(DFN,",2,3,5,7,8,19")
+48 ;SET ID
SET $PIECE(HLA("HLS",2),HLFS,2)=1
+49 ;MERGE HLA("HLS",2)=VAFPID
+50 SET HLA("HLS",3)=$$EN^VAFHLZPD(DFN,",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")
+51 ;SET ID
SET $PIECE(HLA("HLS",3),HLFS,2)=1
+52 IF EVENT="A11"
Begin DoDot:1
+53 SET HLA("HLS",4)=PV1
+54 ; VISIT&SET ID'S
SET $PIECE(HLA("HLS",4),HLFS,51)=$GET(PIVOT)
End DoDot:1
GOTO NEXT
+55 IF EVENT="A01"!(EVENT="A03")!(EVENT="A08")!(EVENT="A12")!(EVENT="A13")
Begin DoDot:1
+56 SET HLA("HLS",4)=$$IN^VAFHLPV1(DFN,VAFHDT,",2,3,7,8,10,19,44,45",$GET(IEN),PIVOT,"",.VAFDIAG)
End DoDot:1
GOTO NEXT
+57 IF EVENT="A02"
Begin DoDot:1
+58 SET HLA("HLS",4)=$$IN^VAFHLPV1(DFN,VAFHDT,",2,3,6,7,8,10,19,44,45",$GET(IEN),PIVOT,"",.VAFDIAG)
End DoDot:1
GOTO NEXT
+59 GOTO EXIT
NEXT ;
+1 SET $PIECE(HLA("HLS",4),HLFS,2)=1
+2 SET HLA("HLS",1)="EVN"_HLFS_EVENT_HLFS_$$HLDATE^HLFNC(VAFHDT,"TS")_HLFS
+3 SET HLA("HLS",1)=HLA("HLS",1)_HLFS_$GET(EVCODE)
+4 IF (EVENT="A01")!(EVENT="A08")!(EVENT="A11")!(EVENT="A12")!(EVENT="A13")
SET HLA("HLS",6)="DG1"_HLFS_1_HLFS_HLFS_HLFS_$$HLQ^VAFHUTL($GET(VAFDIAG))
+5 ;Get patient directory call center parameter
+6 NEW VAFCCON
+7 SET VAFCCON=$$GET^XPAR("SYS","DG PT DIRECTORY CALL CENTER")
+8 IF VAFCCON
SET HLA("HLS",5)=$$EN^VAFHLPV2(DFN,IEN,",22,")
+9 IF $DATA(VATRACE)
DO LOOP
+10 ;
+11 SET COUNTER=""
+12 FOR
SET COUNTER=$ORDER(HLA("HLS",COUNTER))
IF COUNTER'>0
QUIT
Begin DoDot:1
+13 ; I +(HLA("HLS",COUNTER))=-1 S HLERR="Bad "_COUNTER_" Segment"
+14 IF +(HLA("HLS",COUNTER))=-1
SET HL="Bad "_COUNTER_" Segment"
+15 End DoDot:1
+16 ;
EXIT ;
+1 ;I $D(HLERR) D
+2 IF $DATA(HL)=1
Begin DoDot:1
+3 SET HLERR(1)=HL
+4 DO EBULL^VAFHUTL2(DFN,VAFHDT,PIVOT,"HLERR(")
End DoDot:1
+5 ;I '$D(HLERR)&($D(HLSDATA)) S HLMTN="ADT"_$E(HLECH)_EVENT D EN^HLTRANS
+6 IF $DATA(HL)>1
IF $DATA(HLA("HLS"))
SET HLMTN="ADT"_$EXTRACT(HL("ECH"))_EVENT
Begin DoDot:1
+7 DO GENERATE^HLMA("VAFH "_EVENT,"LM",1,.HLRST)
End DoDot:1
+8 DO KVAR^VADPT
DO KVAR^VAFHLPV1
KILL HLA,HLERR
+9 QUIT
LOOP ;
+1 ;
+2 ;
+3 WRITE !!
+4 NEW XX
SET XX=0
+5 FOR
SET XX=$ORDER(HLA("HLS",XX))
IF XX=""
QUIT
WRITE !,HLA("HLS",XX)
+6 QUIT