DGMSTHL7 ;ALB/SCK - Military Sexual Trauma HL7 Message builder ;8 Jan 99
;;5.3;Registration;**195**;Aug 13, 1993
Q
;
EVENT(DFN,DGEVNT,DGRSLT) ; Entry point to initiate HL7 ADT message for a MST status event
; Input
; DFN - IEN of patient in the PATIENT File, #2
; DGEVNT - Event type, currently only A08 supported, Optional
; Default is A08
; DGRSLT - Location of results from event trigger
;
; Output
; DGRSLT= results of event action
;
N EVNTDT,EVNTINFO
;
S DFN=$G(DFN)
I 'DFN S @DGRSLT="-1^Invalid DFN" Q
;
S DGEVNT=$G(DGEVNT)
S:'(DGEVNT]"") DGEVNT="A08"
I DGEVNT'["A08" S @DGRSLT="-1^Event type not supported" Q
;
S DGRSLT=$G(DGRSLT)
Q:'(DGRSLT]"")
;
N GLOREF
S GLOREF="^TMP(""HLS"","_$J_")"
K @GLOREF
;
S EVNTINFO("DFN")=DFN
S EVNTINFO("EVENT")="A08"
S EVNTINFO("DATE")=$$NOW^XLFDT
S EVNTINFO("SERVER")="DGMST A08 SERVER"
;
S @DGRSLT=$$BLDMSG(.EVNTINFO,GLOREF)
I (+@DGRSLT>0) D
. S @DGRSLT=$$SENDMSG(.EVNTINFO,GLOREF)
Q
;
BLDMSG(EVNTINFO,XMTARRY) ;
; Input
; EVNTINFO - Array of event information
; ("DATE") - Event date
; ("DFN") - IEN of patient in PATIENT File (#2)
; ("EVENT") - HL7 message event
; ("SERVER") - HL7 Server protocol
;
; XMTARRY - Location to place HL7 message array, Optional
; Default is ^TMP("HLS",$J)
;
; Output
; XMTARRY - HL7 Message
;
N HLEID,HL,HLFS,HLECH,HLQ,LASTLINE,VAFSTR,LINESADD,HLP
;
S XMTARRY=$G(XMTARRY)
S:(XMTARRY="") XMTARRY="^TMP(""HLS"","_$J_")"
;
Q:$G(EVNTINFO("SERVER"))']"" "-1^Server protocol not defined"
I $G(EVNTINFO("SERVER"))]"" D
. D INIT^HLFNC2(EVNTINFO("SERVER"),.HL)
Q:($O(HL(""))="") "-1^Unable to initialize HL7 variables"
;
;; Build EVN segment
N VAFEVN,VAFSTR
S VAFSTR="1,2,"
S VAFEVN=$$EN^VAFHLEVN(EVNTINFO("EVENT"),EVNTINFO("DATE"),VAFSTR,HL("Q"),HL("FS"))
S $P(VAFEVN,HL("FS"),2)=EVNTINFO("EVENT")
S LASTLINE=1+$G(LASTLINE)
S @XMTARRY@(LASTLINE)=VAFEVN
;
;; Build PID segment
N VAFPID
S VAFSTR="1,2,3,4,5,6,7,8,10,11,12,13,14,16,17,19,"
S VAFPID=$$EN^VAFHLPID(EVNTINFO("DFN"),VAFSTR)
S LASTLINE=1+$G(LASTLINE),LINESADD=1+$G(LINESADD)+$O(VAFPID(""),-1)
M @XMTARRY@(LASTLINE)=VAFPID
;
;; Build ZEL segment, include only the MST status and status change date
N VAFZEL
S VAFSTR="1,23,24,"
S VAFZEL=$$EN^VAFHLZEL(EVNTINFO("DFN"),VAFSTR)
S LASTLINE=1+$G(LASTLINE)
M @XMTARRY@(LASTLINE)=VAFZEL
;
Q LASTLINE_U_LINESADD
;
SENDMSG(EVNTINFO,XMTARRY) ; Send ADT HL7 message
; Input
; EVNTINFO
; XMTARRY
;
; Output
;
;
N ARRY4HL7,KILLARRY,HL,HLRESLT
S XMTARRY=$G(XMTARRY)
S:'(XMTARRY]"") XMTARRY="^TMP(""HLS"","_$J_")"
Q:($O(@XMTARRY@(""))="") "-1^Can not send empty message"
;
K HL
S ARRY4HL7="^TMP(""HLS"","_$J_")"
;
;; If server not specified, then quit with error
Q:$G(EVNTINFO("SERVER"))']"" "-1^Server protocol not defined"
;
;; Initialize HL7 variables
I $G(EVNTINFO("SERVER"))]"" D
. D INIT^HLFNC2(EVNTINFO("SERVER"),.HL)
Q:($O(HL(""))="") "-1^Unable to initialize HL7 variables"
;
;; Check if XMTARRY is ^TMP("HLS",$J)
S KILLARRY=0
I (XMTARRY'=ARRY4HL7) D
. ;; make sure '$J' wasn't used
. Q:(XMTARRY="TMP(""HLS"",$J")
. K @ARRY4HL7
. M @ARRY4HL7=@XMTARRY
. S KILLARRY=1
;
;; Broadcast message
D GENERATE^HLMA(EVNTINFO("SERVER"),"GM",1,.HLRESLT,"",.HLP)
S:('HLRESLT) HLRESLT=$P(HLRESLT,"^",2,3)
;
;; Delete ^TMP("HLS",$J) if XMTARRY was different
K:(KILLARRY) @ARRY4HL7
;
Q $G(HLRESLT)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDGMSTHL7 3612 printed Dec 13, 2024@02:44:25 Page 2
DGMSTHL7 ;ALB/SCK - Military Sexual Trauma HL7 Message builder ;8 Jan 99
+1 ;;5.3;Registration;**195**;Aug 13, 1993
+2 QUIT
+3 ;
EVENT(DFN,DGEVNT,DGRSLT) ; Entry point to initiate HL7 ADT message for a MST status event
+1 ; Input
+2 ; DFN - IEN of patient in the PATIENT File, #2
+3 ; DGEVNT - Event type, currently only A08 supported, Optional
+4 ; Default is A08
+5 ; DGRSLT - Location of results from event trigger
+6 ;
+7 ; Output
+8 ; DGRSLT= results of event action
+9 ;
+10 NEW EVNTDT,EVNTINFO
+11 ;
+12 SET DFN=$GET(DFN)
+13 IF 'DFN
SET @DGRSLT="-1^Invalid DFN"
QUIT
+14 ;
+15 SET DGEVNT=$GET(DGEVNT)
+16 if '(DGEVNT]"")
SET DGEVNT="A08"
+17 IF DGEVNT'["A08"
SET @DGRSLT="-1^Event type not supported"
QUIT
+18 ;
+19 SET DGRSLT=$GET(DGRSLT)
+20 if '(DGRSLT]"")
QUIT
+21 ;
+22 NEW GLOREF
+23 SET GLOREF="^TMP(""HLS"","_$JOB_")"
+24 KILL @GLOREF
+25 ;
+26 SET EVNTINFO("DFN")=DFN
+27 SET EVNTINFO("EVENT")="A08"
+28 SET EVNTINFO("DATE")=$$NOW^XLFDT
+29 SET EVNTINFO("SERVER")="DGMST A08 SERVER"
+30 ;
+31 SET @DGRSLT=$$BLDMSG(.EVNTINFO,GLOREF)
+32 IF (+@DGRSLT>0)
Begin DoDot:1
+33 SET @DGRSLT=$$SENDMSG(.EVNTINFO,GLOREF)
End DoDot:1
+34 QUIT
+35 ;
BLDMSG(EVNTINFO,XMTARRY) ;
+1 ; Input
+2 ; EVNTINFO - Array of event information
+3 ; ("DATE") - Event date
+4 ; ("DFN") - IEN of patient in PATIENT File (#2)
+5 ; ("EVENT") - HL7 message event
+6 ; ("SERVER") - HL7 Server protocol
+7 ;
+8 ; XMTARRY - Location to place HL7 message array, Optional
+9 ; Default is ^TMP("HLS",$J)
+10 ;
+11 ; Output
+12 ; XMTARRY - HL7 Message
+13 ;
+14 NEW HLEID,HL,HLFS,HLECH,HLQ,LASTLINE,VAFSTR,LINESADD,HLP
+15 ;
+16 SET XMTARRY=$GET(XMTARRY)
+17 if (XMTARRY="")
SET XMTARRY="^TMP(""HLS"","_$JOB_")"
+18 ;
+19 if $GET(EVNTINFO("SERVER"))']""
QUIT "-1^Server protocol not defined"
+20 IF $GET(EVNTINFO("SERVER"))]""
Begin DoDot:1
+21 DO INIT^HLFNC2(EVNTINFO("SERVER"),.HL)
End DoDot:1
+22 if ($ORDER(HL(""))="")
QUIT "-1^Unable to initialize HL7 variables"
+23 ;
+24 ;; Build EVN segment
+25 NEW VAFEVN,VAFSTR
+26 SET VAFSTR="1,2,"
+27 SET VAFEVN=$$EN^VAFHLEVN(EVNTINFO("EVENT"),EVNTINFO("DATE"),VAFSTR,HL("Q"),HL("FS"))
+28 SET $PIECE(VAFEVN,HL("FS"),2)=EVNTINFO("EVENT")
+29 SET LASTLINE=1+$GET(LASTLINE)
+30 SET @XMTARRY@(LASTLINE)=VAFEVN
+31 ;
+32 ;; Build PID segment
+33 NEW VAFPID
+34 SET VAFSTR="1,2,3,4,5,6,7,8,10,11,12,13,14,16,17,19,"
+35 SET VAFPID=$$EN^VAFHLPID(EVNTINFO("DFN"),VAFSTR)
+36 SET LASTLINE=1+$GET(LASTLINE)
SET LINESADD=1+$GET(LINESADD)+$ORDER(VAFPID(""),-1)
+37 MERGE @XMTARRY@(LASTLINE)=VAFPID
+38 ;
+39 ;; Build ZEL segment, include only the MST status and status change date
+40 NEW VAFZEL
+41 SET VAFSTR="1,23,24,"
+42 SET VAFZEL=$$EN^VAFHLZEL(EVNTINFO("DFN"),VAFSTR)
+43 SET LASTLINE=1+$GET(LASTLINE)
+44 MERGE @XMTARRY@(LASTLINE)=VAFZEL
+45 ;
+46 QUIT LASTLINE_U_LINESADD
+47 ;
SENDMSG(EVNTINFO,XMTARRY) ; Send ADT HL7 message
+1 ; Input
+2 ; EVNTINFO
+3 ; XMTARRY
+4 ;
+5 ; Output
+6 ;
+7 ;
+8 NEW ARRY4HL7,KILLARRY,HL,HLRESLT
+9 SET XMTARRY=$GET(XMTARRY)
+10 if '(XMTARRY]"")
SET XMTARRY="^TMP(""HLS"","_$JOB_")"
+11 if ($ORDER(@XMTARRY@(""))="")
QUIT "-1^Can not send empty message"
+12 ;
+13 KILL HL
+14 SET ARRY4HL7="^TMP(""HLS"","_$JOB_")"
+15 ;
+16 ;; If server not specified, then quit with error
+17 if $GET(EVNTINFO("SERVER"))']""
QUIT "-1^Server protocol not defined"
+18 ;
+19 ;; Initialize HL7 variables
+20 IF $GET(EVNTINFO("SERVER"))]""
Begin DoDot:1
+21 DO INIT^HLFNC2(EVNTINFO("SERVER"),.HL)
End DoDot:1
+22 if ($ORDER(HL(""))="")
QUIT "-1^Unable to initialize HL7 variables"
+23 ;
+24 ;; Check if XMTARRY is ^TMP("HLS",$J)
+25 SET KILLARRY=0
+26 IF (XMTARRY'=ARRY4HL7)
Begin DoDot:1
+27 ;; make sure '$J' wasn't used
+28 if (XMTARRY="TMP(""HLS"",$J")
QUIT
+29 KILL @ARRY4HL7
+30 MERGE @ARRY4HL7=@XMTARRY
+31 SET KILLARRY=1
End DoDot:1
+32 ;
+33 ;; Broadcast message
+34 DO GENERATE^HLMA(EVNTINFO("SERVER"),"GM",1,.HLRESLT,"",.HLP)
+35 if ('HLRESLT)
SET HLRESLT=$PIECE(HLRESLT,"^",2,3)
+36 ;
+37 ;; Delete ^TMP("HLS",$J) if XMTARRY was different
+38 if (KILLARRY)
KILL @ARRY4HL7
+39 ;
+40 QUIT $GET(HLRESLT)