- VAFCMSG1 ;ALB/JRP-ADT/R MESSAGE BUILDING ; 22 Jan 2002 10:31 AM
- ;;5.3;Registration;**91,149,494**;Aug 13, 1993
- ;
- BLDMSG(DFN,EVNTHL7,EVNTDATE,EVNTINFO,XMITARRY,INSRTPNT) ;Entry point
- ; for building HL7 ADT messages for a given patient
- ;
- ;Input : DFN - Pointer to entry in PATIENT file (#2) to build
- ; message for
- ; EVNTHL7 - HL7 ADT event to build message for (Defaults to A08)
- ; Currently supported event types:
- ; A04, A08, A28
- ; EVNTDATE - Date/time event occurred in FileMan format
- ; - Defaults to current date/time (NOW)
- ; EVNTINFO - Array containing further event information needed
- ; when building HL7 segments/message. Use and
- ; subscripting of array is determined by segment
- ; and/or message being built.
- ; - Defaults to ^TMP("VAFCMSG",$J,"EVNTINFO")
- ; Current subscripts include:
- ; EVNTINFO("DFN") = Pointer to PATIENT file (#2)
- ; EVNTINFO("EVENT") = Event type
- ; EVNTINFO("DATE") = Event date/time
- ; EVNTINFO("PIVOT") = Pointer to ADT/HL7 PIVOT
- ; file (#391.71)
- ; EVNTINFO("REASON",X) = Event reason codes
- ; EVNTINFO("USER") = User associated with the event
- ; XMITARRY - Array to build message into (full global reference)
- ; - Defaults to ^TMP("HLS",$J)
- ; INSRTPNT - Line to begin inserting message text at
- ; - Defaults to 1 (can not be zero or less)
- ;Output : LastLine^TotalLine = ADT-Axx message was build
- ; LastLine = Last line number in message
- ; TotalLine = Number of lines in message
- ; (this total includes continuation lines)
- ; XMITARRY will be in format compatible with HL7 package
- ; XMITARRY(N) = Line N of message
- ; XMITARRY(N,M) = Continuation number M of line N
- ; -1^ErrorText = Error generating ADT-Axx message
- ;Notes : It is the responsibility of the calling program to
- ; initialize XMITARRY
- ;
- ;Check input
- S DFN=+$G(DFN)
- Q:('$D(^DPT(DFN,0))) "-1^Could not find entry in PATIENT file"
- S EVNTHL7=$G(EVNTHL7)
- S:(EVNTHL7="") EVNTHL7="A08"
- S EVNTDATE=+$G(EVNTDATE)
- S:('EVNTDATE) EVNTDATE=$$NOW^VAFCMSG5()
- S EVNTINFO=$G(EVNTINFO)
- S:(EVNTINFO="") EVNTINFO="^TMP(""VAFCMSG"","_$J_",""EVNTINFO"")"
- S XMITARRY=$G(XMITARRY)
- S:(XMITARRY="") XMITARRY="^TMP(""HLS"","_$J_")"
- S INSRTPNT=+$G(INSRTPNT)
- S:(INSRTPNT<1) INSRTPNT=1
- ;Declare variables
- N HLEID,HL,HLFS,HLECH,HLQ
- N VAFSTR,LASTLINE,LINESADD,SEGARRY
- N SEGORDR,SEGNAME,LINETAG,OK,TMP
- S SEGARRY="^TMP(""VAFC SEGMENTS"","_$J_")"
- K @SEGARRY
- ;Check for supported event
- S OK=0
- F TMP="A04","A08","A28" I TMP=EVNTHL7 S OK=1 Q
- Q:('OK) "-1^Event type not supported"
- ;
- K HL
- I $G(@EVNTINFO@("SERVER PROTOCOL"))]"" DO
- . D INIT^HLFNC2(@EVNTINFO@("SERVER PROTOCOL"),.HL)
- ;or Get pointer to HL7 Server Protocol
- E DO Q:'HLEID "-1^Server Protocol not found"
- .S HLEID=$$GETSRVR^VAFCMSG5(EVNTHL7)
- .Q:('HLEID)
- .;Initialize HL7 variables
- .D INIT^HLFNC2(HLEID,.HL)
- Q:($O(HL(""))="") "-1^Unable to initialize HL7 variables"
- ;
- ;Get list of segments
- N SEGERR
- D SEGMENTS^VAFCMSG4(EVNTHL7,SEGARRY)
- Q:('$O(@SEGARRY@(0))) "-1^Unable to determine list of segments to transmit"
- ;Loop through list of segments
- S LASTLINE=INSRTPNT-1
- S LINESADD=0
- S SEGORDR=0
- F S SEGORDR=+$O(@SEGARRY@(SEGORDR)) Q:('SEGORDR) D Q:$G(SEGERR)
- .S SEGNAME=""
- .F S SEGNAME=$O(@SEGARRY@(SEGORDR,SEGNAME)) Q:(SEGNAME="") D
- ..;Build segment
- ..S VAFSTR=$G(@SEGARRY@(SEGORDR,SEGNAME))
- ..S LINETAG=$G(@SEGARRY@(SEGNAME,"BLD"))
- ..I (LINETAG'="") X LINETAG
- ..;Copy segment into HL7 message
- ..S LINETAG=$G(@SEGARRY@(SEGNAME,"CPY"))
- ..I (LINETAG'="") X LINETAG
- ..;Delete variables used by segment builder
- ..S LINETAG=$G(@SEGARRY@(SEGNAME,"DEL"))
- ..I (LINETAG'="") X LINETAG
- ;S ^TMP("HLS",$J,11)="ZFF"_HL("FS")_2_HL("FS")_$P($G(^VAT(391.71,+$G(PIVOTPTR),2)),U)
- ;Clean up and quit
- K @SEGARRY
- I $G(SEGERR) Q SEGERR
- Q LASTLINE_"^"_LINESADD
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAFCMSG1 4342 printed Feb 19, 2025@00:28:02 Page 2
- VAFCMSG1 ;ALB/JRP-ADT/R MESSAGE BUILDING ; 22 Jan 2002 10:31 AM
- +1 ;;5.3;Registration;**91,149,494**;Aug 13, 1993
- +2 ;
- BLDMSG(DFN,EVNTHL7,EVNTDATE,EVNTINFO,XMITARRY,INSRTPNT) ;Entry point
- +1 ; for building HL7 ADT messages for a given patient
- +2 ;
- +3 ;Input : DFN - Pointer to entry in PATIENT file (#2) to build
- +4 ; message for
- +5 ; EVNTHL7 - HL7 ADT event to build message for (Defaults to A08)
- +6 ; Currently supported event types:
- +7 ; A04, A08, A28
- +8 ; EVNTDATE - Date/time event occurred in FileMan format
- +9 ; - Defaults to current date/time (NOW)
- +10 ; EVNTINFO - Array containing further event information needed
- +11 ; when building HL7 segments/message. Use and
- +12 ; subscripting of array is determined by segment
- +13 ; and/or message being built.
- +14 ; - Defaults to ^TMP("VAFCMSG",$J,"EVNTINFO")
- +15 ; Current subscripts include:
- +16 ; EVNTINFO("DFN") = Pointer to PATIENT file (#2)
- +17 ; EVNTINFO("EVENT") = Event type
- +18 ; EVNTINFO("DATE") = Event date/time
- +19 ; EVNTINFO("PIVOT") = Pointer to ADT/HL7 PIVOT
- +20 ; file (#391.71)
- +21 ; EVNTINFO("REASON",X) = Event reason codes
- +22 ; EVNTINFO("USER") = User associated with the event
- +23 ; XMITARRY - Array to build message into (full global reference)
- +24 ; - Defaults to ^TMP("HLS",$J)
- +25 ; INSRTPNT - Line to begin inserting message text at
- +26 ; - Defaults to 1 (can not be zero or less)
- +27 ;Output : LastLine^TotalLine = ADT-Axx message was build
- +28 ; LastLine = Last line number in message
- +29 ; TotalLine = Number of lines in message
- +30 ; (this total includes continuation lines)
- +31 ; XMITARRY will be in format compatible with HL7 package
- +32 ; XMITARRY(N) = Line N of message
- +33 ; XMITARRY(N,M) = Continuation number M of line N
- +34 ; -1^ErrorText = Error generating ADT-Axx message
- +35 ;Notes : It is the responsibility of the calling program to
- +36 ; initialize XMITARRY
- +37 ;
- +38 ;Check input
- +39 SET DFN=+$GET(DFN)
- +40 if ('$DATA(^DPT(DFN,0)))
- QUIT "-1^Could not find entry in PATIENT file"
- +41 SET EVNTHL7=$GET(EVNTHL7)
- +42 if (EVNTHL7="")
- SET EVNTHL7="A08"
- +43 SET EVNTDATE=+$GET(EVNTDATE)
- +44 if ('EVNTDATE)
- SET EVNTDATE=$$NOW^VAFCMSG5()
- +45 SET EVNTINFO=$GET(EVNTINFO)
- +46 if (EVNTINFO="")
- SET EVNTINFO="^TMP(""VAFCMSG"","_$JOB_",""EVNTINFO"")"
- +47 SET XMITARRY=$GET(XMITARRY)
- +48 if (XMITARRY="")
- SET XMITARRY="^TMP(""HLS"","_$JOB_")"
- +49 SET INSRTPNT=+$GET(INSRTPNT)
- +50 if (INSRTPNT<1)
- SET INSRTPNT=1
- +51 ;Declare variables
- +52 NEW HLEID,HL,HLFS,HLECH,HLQ
- +53 NEW VAFSTR,LASTLINE,LINESADD,SEGARRY
- +54 NEW SEGORDR,SEGNAME,LINETAG,OK,TMP
- +55 SET SEGARRY="^TMP(""VAFC SEGMENTS"","_$JOB_")"
- +56 KILL @SEGARRY
- +57 ;Check for supported event
- +58 SET OK=0
- +59 FOR TMP="A04","A08","A28"
- IF TMP=EVNTHL7
- SET OK=1
- QUIT
- +60 if ('OK)
- QUIT "-1^Event type not supported"
- +61 ;
- +62 KILL HL
- +63 IF $GET(@EVNTINFO@("SERVER PROTOCOL"))]""
- Begin DoDot:1
- +64 DO INIT^HLFNC2(@EVNTINFO@("SERVER PROTOCOL"),.HL)
- End DoDot:1
- +65 ;or Get pointer to HL7 Server Protocol
- +66 IF '$TEST
- Begin DoDot:1
- +67 SET HLEID=$$GETSRVR^VAFCMSG5(EVNTHL7)
- +68 if ('HLEID)
- QUIT
- +69 ;Initialize HL7 variables
- +70 DO INIT^HLFNC2(HLEID,.HL)
- End DoDot:1
- if 'HLEID
- QUIT "-1^Server Protocol not found"
- +71 if ($ORDER(HL(""))="")
- QUIT "-1^Unable to initialize HL7 variables"
- +72 ;
- +73 ;Get list of segments
- +74 NEW SEGERR
- +75 DO SEGMENTS^VAFCMSG4(EVNTHL7,SEGARRY)
- +76 if ('$ORDER(@SEGARRY@(0)))
- QUIT "-1^Unable to determine list of segments to transmit"
- +77 ;Loop through list of segments
- +78 SET LASTLINE=INSRTPNT-1
- +79 SET LINESADD=0
- +80 SET SEGORDR=0
- +81 FOR
- SET SEGORDR=+$ORDER(@SEGARRY@(SEGORDR))
- if ('SEGORDR)
- QUIT
- Begin DoDot:1
- +82 SET SEGNAME=""
- +83 FOR
- SET SEGNAME=$ORDER(@SEGARRY@(SEGORDR,SEGNAME))
- if (SEGNAME="")
- QUIT
- Begin DoDot:2
- +84 ;Build segment
- +85 SET VAFSTR=$GET(@SEGARRY@(SEGORDR,SEGNAME))
- +86 SET LINETAG=$GET(@SEGARRY@(SEGNAME,"BLD"))
- +87 IF (LINETAG'="")
- XECUTE LINETAG
- +88 ;Copy segment into HL7 message
- +89 SET LINETAG=$GET(@SEGARRY@(SEGNAME,"CPY"))
- +90 IF (LINETAG'="")
- XECUTE LINETAG
- +91 ;Delete variables used by segment builder
- +92 SET LINETAG=$GET(@SEGARRY@(SEGNAME,"DEL"))
- +93 IF (LINETAG'="")
- XECUTE LINETAG
- End DoDot:2
- End DoDot:1
- if $GET(SEGERR)
- QUIT
- +94 ;S ^TMP("HLS",$J,11)="ZFF"_HL("FS")_2_HL("FS")_$P($G(^VAT(391.71,+$G(PIVOTPTR),2)),U)
- +95 ;Clean up and quit
- +96 KILL @SEGARRY
- +97 IF $GET(SEGERR)
- QUIT SEGERR
- +98 QUIT LASTLINE_"^"_LINESADD