source: FOIAVistA/tag/r/SCHEDULING-SD-SC/SCDXMSG0.m@ 794

Last change on this file since 794 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 5.5 KB
Line 
1SCDXMSG0 ;ALB/JRP - AMB CARE MESSAGE BUILDER;07-MAY-1996 ; 23 Oct 98 1:47 PM
2 ;;5.3;Scheduling;**44,59,66,162,387**;AUG 13, 1993
3 ;
4BUILDHL7(XMITPTR,HL,MID,XMITARRY,INSRTPNT,VALERR) ;Build an HL7 message for an
5 ; entry in the TRANSMITTED OUTPATIENT ENCOUNTER file (#409.73)
6 ;
7 ;Input : XMITPTR - Pointer to entry in TRANSMITTED OUTPATIENT
8 ; ENCOUNTER file (#409.73)
9 ; HL - Array containing HL7 variables - pass by reference
10 ; This is the output of the call to INIT^HLFNC2()
11 ; MID - Message Control ID to use in the MSH segment
12 ; XMITARRY - Array to store HL7 message in (full global ref)
13 ; (Defaults to ^TMP("HLS",$J))
14 ; INSRTPNT - Line to begin inserting message text at
15 ; (Defaults to 1)
16 ;Output : LINES - Number of lines in message (success)
17 ; XMITARRY(N) = Line N of HL7 message
18 ; XMITARRY(N,M) = Continuation number M of line N
19 ; -1^Error - Unable to build message / bad input
20 ;Notes : It is the responsibility of the calling program to
21 ; initialize (i.e. KILL) XMITARRY
22 ; : The MSH segment will not be built if MID is not passed
23 ; : When retransmitting, an EDIT event will be used if the
24 ; OUTPATIENT ENCOUNTER field (#.02) has a value and a
25 ; DELETE event will be used if the DELETED OUTPATIENT
26 ; ENCOUNTER field (#.03) has a value
27 ;
28 ;Check input
29 S XMITPTR=+$G(XMITPTR)
30 Q:('$D(^SD(409.73,XMITPTR,0))) "-1^Did not pass valid pointer to Transmitted Outpatient Encounter file"
31 Q:($O(HL(""))="") "-1^Did not pass variables required to interact with the HL7 package"
32 S MID=$G(MID)
33 S XMITARRY=$G(XMITARRY)
34 S:(XMITARRY="") XMITARRY="^TMP(""HLS"","_$J_")"
35 S INSRTPNT=$G(INSRTPNT)
36 S:(INSRTPNT="") INSRTPNT=1
37 ;Declare variables
38 N ENCDT,NODE,DFN,XMITEVNT,ENCPTR,DELPTR,LINESADD,LINETAG,EVNTDATE
39 N CURLINE,EVNTHL7,VAFARRY,ORIGMTN,ORIGETN,RESULT
40 N ERROR,VERROR,SEGMENTS,SEGORDR,SEGNAME,XMITDATE,VAFSTR,ENCNDT
41 ;Get zero node of Transmitted Outpatient Encounter
42 S NODE=$G(^SD(409.73,XMITPTR,0))
43 ;Get pointer to Outpatient Encounter file
44 S ENCPTR=+$P(NODE,"^",2)
45 ;Get pointer to Deleted Outpatient Encounter file
46 S DELPTR=+$P(NODE,"^",3)
47 ;Pointer to either type of encounter not found - done
48 Q:(('ENCPTR)&('DELPTR)) "-1^Entry in Transmitted Outpatient Encounter file does not reference an encounter"
49 ;Get transmission event
50 S XMITEVNT=+$P(NODE,"^",5)
51 ;Retransmitting - use EDIT event for Outpatient Encounters and
52 ; DELETE event for Deleted Outpatient Encounter
53 S:('XMITEVNT) XMITEVNT=$S(ENCPTR:2,1:3)
54 ;Convert event type to HL7 event
55 ; Using A08 for ADD & EDIT and A23 for DELETE
56 S EVNTHL7="A23"
57 S:(XMITEVNT'=3) EVNTHL7="A08"
58 ;Get event date/time
59 S EVNTDATE=+$P(NODE,"^",6)
60 ;Determine patient and encounter date/time
61 S DFN=0
62 S (ENCDT,ENCNDT)=0
63 ;Get data from Outpatient Encounter
64 I (ENCPTR) D
65 .S NODE=$G(^SCE(ENCPTR,0))
66 .S DFN=+$P(NODE,"^",2)
67 .S ENCDT=+$P($P(NODE,"^"),".")
68 .S ENCNDT=+$P(NODE,"^")
69 ;Get data from Deleted Outpatient Encounter
70 I (DELPTR) D
71 .S NODE=$G(^SD(409.74,DELPTR,1))
72 .S DFN=+$P(NODE,"^",2)
73 .S ENCDT=+$P($P(NODE,"^"),".")
74 .S ENCNDT=+$P(NODE,"^")
75 ;Unable to determine patient - done
76 Q:('DFN) "-1^"_$S(DELPTR:"Deleted ",1:"")_"Outpatient Encounter did not refer to a patient"
77 ;Couldn't determine encounter date/time - use today
78 S:('$G(ENCDT)) ENCDT=DT
79 ;Build MSH segment if MID was passed
80 S LINESADD=0
81 S CURLINE=INSRTPNT
82 S ERROR=0
83 I (MID'="") D
84 .;Remember original message & event types (only applicable to batch)
85 .S ORIGMTN=HL("MTN")
86 .S ORIGETN=HL("ETN")
87 .;Put in message & event types for actual message
88 .S HL("MTN")="ADT"
89 .S HL("ETN")=EVNTHL7
90 .;Build MSH segment
91 .K RESULT D MSH^HLFNC2(.HL,MID,.RESULT)
92 .;Reset message & event types to original values
93 .S HL("MTN")=ORIGMTN
94 .S HL("ETN")=ORIGETN
95 .;Error
96 .I (RESULT="") S ERROR="-1^Unable to create MSH segment" Q
97 .;Copy MSH segment into HL7 message
98 .S @XMITARRY@(CURLINE)=RESULT
99 .;Increment number of lines added
100 .S LINESADD=LINESADD+1
101 .;Check for continuation node
102 .I ($D(RESULT(1))) D
103 ..;Copy continuation into HL7 message
104 ..S @XMITARRY@(CURLINE,1)=RESULT(1)
105 ..;Increment number of lines added
106 ..S LINESADD=LINESADD+1
107 .;Increment current line number
108 .S CURLINE=CURLINE+1
109 ;Error building MSH segment - done
110 Q:(ERROR) ERROR
111 ;Get list of segments
112 D SEGMENTS^SCDXMSG1(EVNTHL7,"SEGMENTS")
113 ;Loop through list of segments
114 S (VERROR,ERROR)=0
115 S SEGORDR=0
116 F S SEGORDR=+$O(SEGMENTS(SEGORDR)) Q:('SEGORDR) D Q:(ERROR)
117 .S SEGNAME=""
118 .F S SEGNAME=$O(SEGMENTS(SEGORDR,SEGNAME)) Q:(SEGNAME="") D Q:(ERROR)
119 ..;Build segment
120 ..S VAFSTR=SEGMENTS(SEGORDR,SEGNAME)
121 ..S VAFARRY="^TMP(""SCDX-XMIT-BLD"","_$J_","""_SEGNAME_""")"
122 ..S LINETAG="BLD"_SEGNAME S ERROR=0 D @LINETAG^SCDXMSG1
123 ..;Error - delete segment & quit
124 ..I (ERROR) S LINETAG="DEL"_SEGNAME D @LINETAG^SCDXMSG1 Q
125 ..;Validate segment, if appropriate
126 ..S LINETAG="VLD"_SEGNAME S ERROR=0 D:$$VSEG() @LINETAG^SCDXMSG1
127 ..I ERROR S VERROR=ERROR
128 ..;Copy segment into HL7 message
129 ..I 'ERROR S LINETAG="CPY"_SEGNAME D @LINETAG^SCDXMSG1
130 ..S ERROR=0
131 ..;Delete segment
132 ..S LINETAG="DEL"_SEGNAME D @LINETAG^SCDXMSG1
133 ..;Increment current line number
134 ..S CURLINE=CURLINE+1
135 ;Error building segment - remove segments already put into HL7
136 ; message & quit
137 I (ERROR)!(VERROR) D UNWIND^SCDXMSG1(XMITARRY,INSRTPNT) Q $S(ERROR:ERROR,1:VERROR)
138 ;Done
139 Q LINESADD
140 ;
141VSEG() ;Determine if segment should be validated
142 ;All segments for 'add' or 'edit' transactions
143 ;Only PID and PV1 segments for 'delete' transactions
144 I EVNTHL7="A08" Q 1
145 I EVNTHL7="A23","PID^PV1"[SEGNAME Q 1
146 Q 0
Note: See TracBrowser for help on using the repository browser.