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

SCDXMSG0.m

Go to the documentation of this file.
  1. SCDXMSG0 ;ALB/JRP - AMB CARE MESSAGE BUILDER;07-MAY-1996 ; 23 Oct 98 1:47 PM
  1. ;;5.3;Scheduling;**44,59,66,162,387,1015**;AUG 13, 1993;Build 21
  1. ;
  1. BUILDHL7(XMITPTR,HL,MID,XMITARRY,INSRTPNT,VALERR) ;Build an HL7 message for an
  1. ; entry in the TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
  1. ;
  1. ;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
  1. ; ENCOUNTER file (#409.73)
  1. ; HL - Array containing HL7 variables - pass by reference
  1. ; This is the output of the call to INIT^HLFNC2()
  1. ; MID - Message Control ID to use in the MSH segment
  1. ; XMITARRY - Array to store HL7 message in (full global ref)
  1. ; (Defaults to ^TMP("HLS",$J))
  1. ; INSRTPNT - Line to begin inserting message text at
  1. ; (Defaults to 1)
  1. ;Output : LINES - Number of lines in message (success)
  1. ; XMITARRY(N) = Line N of HL7 message
  1. ; XMITARRY(N,M) = Continuation number M of line N
  1. ; -1^Error - Unable to build message / bad input
  1. ;Notes : It is the responsibility of the calling program to
  1. ; initialize (i.e. KILL) XMITARRY
  1. ; : The MSH segment will not be built if MID is not passed
  1. ; : When retransmitting, an EDIT event will be used if the
  1. ; OUTPATIENT ENCOUNTER field (#.02) has a value and a
  1. ; DELETE event will be used if the DELETED OUTPATIENT
  1. ; ENCOUNTER field (#.03) has a value
  1. ;
  1. ;Check input
  1. S XMITPTR=+$G(XMITPTR)
  1. Q:('$D(^SD(409.73,XMITPTR,0))) "-1^Did not pass valid pointer to Transmitted Outpatient Encounter file"
  1. Q:($O(HL(""))="") "-1^Did not pass variables required to interact with the HL7 package"
  1. S MID=$G(MID)
  1. S XMITARRY=$G(XMITARRY)
  1. S:(XMITARRY="") XMITARRY="^TMP(""HLS"","_$J_")"
  1. S INSRTPNT=$G(INSRTPNT)
  1. S:(INSRTPNT="") INSRTPNT=1
  1. ;Declare variables
  1. N ENCDT,NODE,DFN,XMITEVNT,ENCPTR,DELPTR,LINESADD,LINETAG,EVNTDATE
  1. N CURLINE,EVNTHL7,VAFARRY,ORIGMTN,ORIGETN,RESULT
  1. N ERROR,VERROR,SEGMENTS,SEGORDR,SEGNAME,XMITDATE,VAFSTR,ENCNDT
  1. ;Get zero node of Transmitted Outpatient Encounter
  1. S NODE=$G(^SD(409.73,XMITPTR,0))
  1. ;Get pointer to Outpatient Encounter file
  1. S ENCPTR=+$P(NODE,"^",2)
  1. ;Get pointer to Deleted Outpatient Encounter file
  1. S DELPTR=+$P(NODE,"^",3)
  1. ;Pointer to either type of encounter not found - done
  1. Q:(('ENCPTR)&('DELPTR)) "-1^Entry in Transmitted Outpatient Encounter file does not reference an encounter"
  1. ;Get transmission event
  1. S XMITEVNT=+$P(NODE,"^",5)
  1. ;Retransmitting - use EDIT event for Outpatient Encounters and
  1. ; DELETE event for Deleted Outpatient Encounter
  1. S:('XMITEVNT) XMITEVNT=$S(ENCPTR:2,1:3)
  1. ;Convert event type to HL7 event
  1. ; Using A08 for ADD & EDIT and A23 for DELETE
  1. S EVNTHL7="A23"
  1. S:(XMITEVNT'=3) EVNTHL7="A08"
  1. ;Get event date/time
  1. S EVNTDATE=+$P(NODE,"^",6)
  1. ;Determine patient and encounter date/time
  1. S DFN=0
  1. S (ENCDT,ENCNDT)=0
  1. ;Get data from Outpatient Encounter
  1. I (ENCPTR) D
  1. .S NODE=$G(^SCE(ENCPTR,0))
  1. .S DFN=+$P(NODE,"^",2)
  1. .S ENCDT=+$P($P(NODE,"^"),".")
  1. .S ENCNDT=+$P(NODE,"^")
  1. ;Get data from Deleted Outpatient Encounter
  1. I (DELPTR) D
  1. .S NODE=$G(^SD(409.74,DELPTR,1))
  1. .S DFN=+$P(NODE,"^",2)
  1. .S ENCDT=+$P($P(NODE,"^"),".")
  1. .S ENCNDT=+$P(NODE,"^")
  1. ;Unable to determine patient - done
  1. Q:('DFN) "-1^"_$S(DELPTR:"Deleted ",1:"")_"Outpatient Encounter did not refer to a patient"
  1. ;Couldn't determine encounter date/time - use today
  1. S:('$G(ENCDT)) ENCDT=DT
  1. ;Build MSH segment if MID was passed
  1. S LINESADD=0
  1. S CURLINE=INSRTPNT
  1. S ERROR=0
  1. I (MID'="") D
  1. .;Remember original message & event types (only applicable to batch)
  1. .S ORIGMTN=HL("MTN")
  1. .S ORIGETN=HL("ETN")
  1. .;Put in message & event types for actual message
  1. .S HL("MTN")="ADT"
  1. .S HL("ETN")=EVNTHL7
  1. .;Build MSH segment
  1. .K RESULT D MSH^HLFNC2(.HL,MID,.RESULT)
  1. .;Reset message & event types to original values
  1. .S HL("MTN")=ORIGMTN
  1. .S HL("ETN")=ORIGETN
  1. .;Error
  1. .I (RESULT="") S ERROR="-1^Unable to create MSH segment" Q
  1. .;Copy MSH segment into HL7 message
  1. .S @XMITARRY@(CURLINE)=RESULT
  1. .;Increment number of lines added
  1. .S LINESADD=LINESADD+1
  1. .;Check for continuation node
  1. .I ($D(RESULT(1))) D
  1. ..;Copy continuation into HL7 message
  1. ..S @XMITARRY@(CURLINE,1)=RESULT(1)
  1. ..;Increment number of lines added
  1. ..S LINESADD=LINESADD+1
  1. .;Increment current line number
  1. .S CURLINE=CURLINE+1
  1. ;Error building MSH segment - done
  1. Q:(ERROR) ERROR
  1. ;Get list of segments
  1. D SEGMENTS^SCDXMSG1(EVNTHL7,"SEGMENTS")
  1. ;Loop through list of segments
  1. S (VERROR,ERROR)=0
  1. S SEGORDR=0
  1. F S SEGORDR=+$O(SEGMENTS(SEGORDR)) Q:('SEGORDR) D Q:(ERROR)
  1. .S SEGNAME=""
  1. .F S SEGNAME=$O(SEGMENTS(SEGORDR,SEGNAME)) Q:(SEGNAME="") D Q:(ERROR)
  1. ..;Build segment
  1. ..S VAFSTR=SEGMENTS(SEGORDR,SEGNAME)
  1. ..S VAFARRY="^TMP(""SCDX-XMIT-BLD"","_$J_","""_SEGNAME_""")"
  1. ..S LINETAG="BLD"_SEGNAME S ERROR=0 D @LINETAG^SCDXMSG1
  1. ..;Error - delete segment & quit
  1. ..I (ERROR) S LINETAG="DEL"_SEGNAME D @LINETAG^SCDXMSG1 Q
  1. ..;Validate segment, if appropriate
  1. ..S LINETAG="VLD"_SEGNAME S ERROR=0 D:$$VSEG() @LINETAG^SCDXMSG1
  1. ..I ERROR S VERROR=ERROR
  1. ..;Copy segment into HL7 message
  1. ..I 'ERROR S LINETAG="CPY"_SEGNAME D @LINETAG^SCDXMSG1
  1. ..S ERROR=0
  1. ..;Delete segment
  1. ..S LINETAG="DEL"_SEGNAME D @LINETAG^SCDXMSG1
  1. ..;Increment current line number
  1. ..S CURLINE=CURLINE+1
  1. ;Error building segment - remove segments already put into HL7
  1. ; message & quit
  1. I (ERROR)!(VERROR) D UNWIND^SCDXMSG1(XMITARRY,INSRTPNT) Q $S(ERROR:ERROR,1:VERROR)
  1. ;Done
  1. Q LINESADD
  1. ;
  1. VSEG() ;Determine if segment should be validated
  1. ;All segments for 'add' or 'edit' transactions
  1. ;Only PID and PV1 segments for 'delete' transactions
  1. I EVNTHL7="A08" Q 1
  1. I EVNTHL7="A23","PID^PV1"[SEGNAME Q 1
  1. Q 0