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

VAFCMSG1.m

Go to the documentation of this file.
  1. VAFCMSG1 ;ALB/JRP-ADT/R MESSAGE BUILDING ; 22 Jan 2002 10:31 AM
  1. ;;5.3;Registration;**91,149,494**;Aug 13, 1993
  1. ;
  1. BLDMSG(DFN,EVNTHL7,EVNTDATE,EVNTINFO,XMITARRY,INSRTPNT) ;Entry point
  1. ; for building HL7 ADT messages for a given patient
  1. ;
  1. ;Input : DFN - Pointer to entry in PATIENT file (#2) to build
  1. ; message for
  1. ; EVNTHL7 - HL7 ADT event to build message for (Defaults to A08)
  1. ; Currently supported event types:
  1. ; A04, A08, A28
  1. ; EVNTDATE - Date/time event occurred in FileMan format
  1. ; - Defaults to current date/time (NOW)
  1. ; EVNTINFO - Array containing further event information needed
  1. ; when building HL7 segments/message. Use and
  1. ; subscripting of array is determined by segment
  1. ; and/or message being built.
  1. ; - Defaults to ^TMP("VAFCMSG",$J,"EVNTINFO")
  1. ; Current subscripts include:
  1. ; EVNTINFO("DFN") = Pointer to PATIENT file (#2)
  1. ; EVNTINFO("EVENT") = Event type
  1. ; EVNTINFO("DATE") = Event date/time
  1. ; EVNTINFO("PIVOT") = Pointer to ADT/HL7 PIVOT
  1. ; file (#391.71)
  1. ; EVNTINFO("REASON",X) = Event reason codes
  1. ; EVNTINFO("USER") = User associated with the event
  1. ; XMITARRY - Array to build message into (full global reference)
  1. ; - Defaults to ^TMP("HLS",$J)
  1. ; INSRTPNT - Line to begin inserting message text at
  1. ; - Defaults to 1 (can not be zero or less)
  1. ;Output : LastLine^TotalLine = ADT-Axx message was build
  1. ; LastLine = Last line number in message
  1. ; TotalLine = Number of lines in message
  1. ; (this total includes continuation lines)
  1. ; XMITARRY will be in format compatible with HL7 package
  1. ; XMITARRY(N) = Line N of message
  1. ; XMITARRY(N,M) = Continuation number M of line N
  1. ; -1^ErrorText = Error generating ADT-Axx message
  1. ;Notes : It is the responsibility of the calling program to
  1. ; initialize XMITARRY
  1. ;
  1. ;Check input
  1. S DFN=+$G(DFN)
  1. Q:('$D(^DPT(DFN,0))) "-1^Could not find entry in PATIENT file"
  1. S EVNTHL7=$G(EVNTHL7)
  1. S:(EVNTHL7="") EVNTHL7="A08"
  1. S EVNTDATE=+$G(EVNTDATE)
  1. S:('EVNTDATE) EVNTDATE=$$NOW^VAFCMSG5()
  1. S EVNTINFO=$G(EVNTINFO)
  1. S:(EVNTINFO="") EVNTINFO="^TMP(""VAFCMSG"","_$J_",""EVNTINFO"")"
  1. S XMITARRY=$G(XMITARRY)
  1. S:(XMITARRY="") XMITARRY="^TMP(""HLS"","_$J_")"
  1. S INSRTPNT=+$G(INSRTPNT)
  1. S:(INSRTPNT<1) INSRTPNT=1
  1. ;Declare variables
  1. N HLEID,HL,HLFS,HLECH,HLQ
  1. N VAFSTR,LASTLINE,LINESADD,SEGARRY
  1. N SEGORDR,SEGNAME,LINETAG,OK,TMP
  1. S SEGARRY="^TMP(""VAFC SEGMENTS"","_$J_")"
  1. K @SEGARRY
  1. ;Check for supported event
  1. S OK=0
  1. F TMP="A04","A08","A28" I TMP=EVNTHL7 S OK=1 Q
  1. Q:('OK) "-1^Event type not supported"
  1. ;
  1. K HL
  1. I $G(@EVNTINFO@("SERVER PROTOCOL"))]"" DO
  1. . D INIT^HLFNC2(@EVNTINFO@("SERVER PROTOCOL"),.HL)
  1. ;or Get pointer to HL7 Server Protocol
  1. E DO Q:'HLEID "-1^Server Protocol not found"
  1. .S HLEID=$$GETSRVR^VAFCMSG5(EVNTHL7)
  1. .Q:('HLEID)
  1. .;Initialize HL7 variables
  1. .D INIT^HLFNC2(HLEID,.HL)
  1. Q:($O(HL(""))="") "-1^Unable to initialize HL7 variables"
  1. ;
  1. ;Get list of segments
  1. N SEGERR
  1. D SEGMENTS^VAFCMSG4(EVNTHL7,SEGARRY)
  1. Q:('$O(@SEGARRY@(0))) "-1^Unable to determine list of segments to transmit"
  1. ;Loop through list of segments
  1. S LASTLINE=INSRTPNT-1
  1. S LINESADD=0
  1. S SEGORDR=0
  1. F S SEGORDR=+$O(@SEGARRY@(SEGORDR)) Q:('SEGORDR) D Q:$G(SEGERR)
  1. .S SEGNAME=""
  1. .F S SEGNAME=$O(@SEGARRY@(SEGORDR,SEGNAME)) Q:(SEGNAME="") D
  1. ..;Build segment
  1. ..S VAFSTR=$G(@SEGARRY@(SEGORDR,SEGNAME))
  1. ..S LINETAG=$G(@SEGARRY@(SEGNAME,"BLD"))
  1. ..I (LINETAG'="") X LINETAG
  1. ..;Copy segment into HL7 message
  1. ..S LINETAG=$G(@SEGARRY@(SEGNAME,"CPY"))
  1. ..I (LINETAG'="") X LINETAG
  1. ..;Delete variables used by segment builder
  1. ..S LINETAG=$G(@SEGARRY@(SEGNAME,"DEL"))
  1. ..I (LINETAG'="") X LINETAG
  1. ;S ^TMP("HLS",$J,11)="ZFF"_HL("FS")_2_HL("FS")_$P($G(^VAT(391.71,+$G(PIVOTPTR),2)),U)
  1. ;Clean up and quit
  1. K @SEGARRY
  1. I $G(SEGERR) Q SEGERR
  1. Q LASTLINE_"^"_LINESADD