source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOMSG.m@ 1261

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

revised back to 6/30/08 version

File size: 8.6 KB
Line 
1HLOMSG ;ALB/CJM-HL7 - APIs for files 777/778 ;02/04/2004
2 ;;1.6;HEALTH LEVEL SEVEN;**126,134**;Oct 13, 1995;Build 30
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5GETMSG(IEN,MSG) ;
6 ;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
7 ;Input:
8 ; IEN - the ien of the message in file 778
9 ;Output:
10 ; Function returns 1 on success, 0 on failure
11 ; MSG (pass by reference, required) These are the subscripts returned:
12 ;
13 ; "ACK BY" - msg id of msg that acknowledges this one
14 ; "ACK BY IEN" - msg IEN of msg that acknowledges this one. If the message is in the batch, the value is <ien>^<subien>
15 ; "ACK TO" - msg id of msg that this msg acknowledges
16 ; "ACK TO IEN" - msg IEN of msg that this msg acknowledges. If the message is in a batch, the value is <ien>^<subien>
17 ; "BATCH" = 1 if this is a batch message, 0 if not
18 ; "CURRENT MESSAGE" - defined only for batch messages - a counter used during building and parsing messages to indicate the current message. It will be set to 0 initially.
19 ; "BODY" - ptr to file 778 which contains the body of the message.
20 ; "DIRECTION" - "IN" if incoming, "OUT" if outgoing
21 ; "DT/TM" - date/time the message was sent or received
22 ; "DT/TM CREATED" - date/time the record was created (.01 field, file #777)
23 ; "LINE COUNT" - a counter used during building and parsing of
24 ; messages to indicate the current line within the message. For
25 ; batch messages where each message within the batch is stored
26 ; separately, this field indicates the position within the current
27 ; individual message
28 ; "HDR" - the header segment, NOT parsed, as HDR(1) and HDR(2)
29 ; "ID" - Message Control ID for an individual message, Batch Control ID for a batch message
30 ; "IEN" - ien, file 778
31 ; "EVENT" - HL7 event, only defined if NOT batch
32 ; "MESSAGE TYPE" - HL7 message type, only defined if NOT batch
33 ; "STATUS" - the completion status
34 ;
35 ; These are lower level subscripts of "STATUS":
36 ; "ACCEPT ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when the accept ack is received
37 ; "ACCEPT ACK'D" - 1 if an accept ack was sent or received in response to this message
38 ; "APP ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when app ack is received
39 ; "APP ACK'D" - 1 if an application ack was sent or received in response to this message
40 ; "ERROR TEXT" - if in error status, a description of the error
41 ; "LINK NAME" the link the message was transmitted through
42 ; "PORT" - remote port over which the message was transmitted
43 ; "PURGE" - scheduled purge dt/tm
44 ; "QUEUE" - the queue that the message was placed on
45 ;
46 K MSG
47 Q:'$G(IEN) 0
48 N NODE
49 S MSG("IEN")=IEN
50 S NODE=$G(^HLB(IEN,0))
51 S MSG("ID")=$P(NODE,"^")
52 S MSG("BODY")=$P(NODE,"^",2)
53 S MSG("DIRECTION")=$S($E($P(NODE,"^",4))="O":"OUT",$E($P(NODE,"^",4))="I":"IN",1:"")
54 S MSG("ACK TO")=$P(NODE,"^",3)
55 S MSG("ACK BY")=$P(NODE,"^",7)
56 I MSG("ACK TO")]"" S MSG("ACK TO IEN")=$$ACKTOIEN^HLOMSG1($P(NODE,"^"),MSG("ACK TO"))
57 I MSG("ACK BY")]"" S MSG("ACK BY IEN")=$$ACKBYIEN^HLOMSG1($P(NODE,"^"),MSG("ACK BY"))
58 S MSG("DT/TM")=$P(NODE,"^",16)
59 S MSG("STATUS")=$P(NODE,"^",20)
60 ;
61 D
62 .N NODE4
63 .S NODE4=$G(^HLB(IEN,4))
64 .S MSG("STATUS","QUEUE")=$P(NODE,"^",6)
65 .S MSG("STATUS","LINK NAME")=$P(NODE,"^",5)
66 .S MSG("STATUS","PORT")=$P(NODE,"^",8)
67 .S MSG("STATUS","PURGE")=$P(NODE,"^",9)
68 .S MSG("STATUS","ERROR TEXT")=$P(NODE,"^",21)
69 .S MSG("STATUS","APP ACK RESPONSE")=$P(NODE,"^",10,11)
70 .I MSG("STATUS","APP ACK RESPONSE")="^" S MSG("STATUS","APP ACK RESPONSE")=""
71 .S MSG("STATUS","ACCEPT ACK RESPONSE")=$P(NODE,"^",12,13)
72 .I MSG("STATUS","ACCEPT ACK RESPONSE")="^" S MSG("STATUS","ACCEPT ACK RESPONSE")=""
73 .S MSG("STATUS","ACCEPT ACK'D")=$P(NODE,"^",17)
74 .S MSG("STATUS","APP ACK'D")=$P(NODE,"^",18)
75 .S MSG("STATUS")=$P(NODE,"^",20)
76 .S MSG("STATUS","APP HANDOFF")=$P(NODE,"^",19)
77 .S MSG("STATUS","ACCEPT ACK DT/TM")=$P(NODE4,"^")
78 .S MSG("STATUS","ACCEPT ACK ID")=$P(NODE4,"^",2)
79 .S MSG("STATUS","ACCEPT ACK MSA")=$P(NODE4,"^",3,99)
80 ;
81 S MSG("LINE COUNT")=0
82 S MSG("HDR",1)=$G(^HLB(IEN,1))
83 S MSG("HDR",2)=$G(^HLB(IEN,2))
84 I 'MSG("BODY") D Q 0
85 .S MSG("DT/TM CREATED")=""
86 .S MSG("BATCH")=""
87 .S MSG("MESSAGE TYPE")=""
88 .S MSG("EVENT")=""
89 ;
90 S NODE=$G(^HLA(MSG("BODY"),0))
91 S MSG("DT/TM CREATED")=+NODE
92 S MSG("BATCH")=+$P(NODE,"^",2)
93 I MSG("BATCH") S MSG("BATCH","CURRENT MESSAGE")=0
94 I 'MSG("BATCH") D
95 .S MSG("MESSAGE TYPE")=$P(NODE,"^",3)
96 .S MSG("EVENT")=$P(NODE,"^",4)
97 Q 1
98 ;
99HLNEXT(MSG,SEG) ;
100 ;Description: Returns the next segment as a set of lines stored in SEG.
101 ;Input:
102 ; MSG (pass by reference, required)
103 ;Output:
104 ; Function returns 1 on success, 0 on failure (no more segments)
105 ; SEG (pass by reference, required)
106 ;
107 K SEG
108 Q:MSG("LINE COUNT")=-1 0
109 I 'MSG("BATCH") D
110 .N I,J,NODE,START
111 .S START=0
112 .S J=1,I=MSG("LINE COUNT")
113 .F S I=$O(^HLA(MSG("BODY"),1,I)) Q:'I S NODE=$G(^HLA(MSG("BODY"),1,I,0)) Q:(START&(NODE="")) I NODE'="" S SEG(J)=NODE,J=J+1,START=1
114 .I 'I D
115 ..S MSG("LINE COUNT")=-1
116 .E S MSG("LINE COUNT")=I
117 I MSG("BATCH") D
118 .N I,J,NODE,START
119 .S J=1,I=MSG("LINE COUNT"),START=0
120 .F S I=$O(^HLA(MSG("BODY"),2,MSG("BATCH","CURRENT MESSAGE"),1,I)) Q:'I S NODE=$G(^HLA(MSG("BODY"),2,MSG("BATCH","CURRENT MESSAGE"),1,I,0)) Q:(START&(NODE="")) I NODE'="" S SEG(J)=NODE,J=J+1,START=1
121 .I 'I D
122 ..S MSG("LINE COUNT")=-1
123 .E S MSG("LINE COUNT")=I
124 Q $S($D(SEG):1,1:0)
125 ;
126NEXTMSG(MSG,HDR) ;
127 ;Advances to the next message in the batch
128 ;Input:
129 ; MSG (pass by reference, required) - defined by $$GETMSG()
130 ;Output:
131 ; Function returns 1 on success, 0 if no more messages
132 ; MSG - updated with current position in the message
133 ; HDR (pass by reference, required) returns the header as an array of lines
134 ;
135 ;
136 K HDR
137 S MSG("LINE COUNT")=0
138 N SUBIEN,I
139 ;
140 ;if completed parsing, don't start over
141 I MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
142 ;
143 S I=$O(^HLB(MSG("IEN"),3,"B",MSG("BATCH","CURRENT MESSAGE")))
144 I 'I S MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
145 S MSG("BATCH","CURRENT MESSAGE")=I
146 S SUBIEN=$O(^HLB(MSG("IEN"),3,"B",I,0))
147 S HDR(1)=$G(^HLB(MSG("IEN"),3,SUBIEN,1))
148 S HDR(2)=$G(^HLB(MSG("IEN"),3,SUBIEN,2))
149 Q $S($D(HDR):1,1:0)
150 ;
151ADDSEG(HLMSTATE,SEG) ;Adds a segment to the message.
152 ;Input:
153 ; HLMSTATE() - (pass by reference, required)
154 ; SEG() - (pass by reference, required) The segment as lines SEG(<i>)
155 ;
156 ;Output:
157 ; HLMSTATE()
158 ;
159 N I,J S I=0
160 S J=HLMSTATE("LINE COUNT")
161 ;
162 ;insure a blank line between segments
163 I J S J=J+1,HLMSTATE("UNSTORED LINES",$S(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=""
164 ;
165 S HLMSTATE("CURRENT SEGMENT")=HLMSTATE("CURRENT SEGMENT")+1
166 F S I=$O(SEG(I)) Q:'I D
167 .S J=J+1
168 .S HLMSTATE("UNSTORED LINES",$S(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=SEG(I),HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+$L(SEG(I))+50
169 .I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER") D
170 ..I HLMSTATE("DIRECTION")="IN",$$SAVEMSG^HLOF778(.HLMSTATE) Q
171 ..I HLMSTATE("DIRECTION")="OUT",$$SAVEMSG^HLOF777(.HLMSTATE)
172 ;
173 S HLMSTATE("LINE COUNT")=J
174 Q
175 ;
176ADDMSG(HLMSTATE,PARMS) ;
177 ;For outgoing messages, adds a message in the batch. There is no MSH yet, just the message type and event.
178 ;Input:
179 ; HLMSTATE() - (pass by reference, required)
180 ; PARMS("EVENT")
181 ; PARMS("MESSAGE TYPE")
182 ;
183 ;Output:
184 ; HLMSTATE() - (pass by reference, required)
185 ;
186 N I
187 S I=HLMSTATE("BATCH","CURRENT MESSAGE")+1,HLMSTATE("BATCH","CURRENT MESSAGE")=I
188 S HLMSTATE("UNSTORED LINES",I)=PARMS("MESSAGE TYPE")_"^"_PARMS("EVENT")
189 M:$G(PARMS("ACK TO"))]"" HLMSTATE("BATCH","ACK TO",I)=PARMS("ACK TO")
190 S HLMSTATE("CURRENT SEGMENT")=0
191 S HLMSTATE("LINE COUNT")=0
192 S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+100
193 Q
194 ;
195ADDMSG2(HLMSTATE,MSH) ;
196 ;For incoming messages adds a message to the batch. This differs from ADDMSG in that the MSH segment is passed in to be stored in file 778.
197 ;Input:
198 ; HLMSTATE() - (pass by reference, required)
199 ; MSH(<i>) - the MSH segment as a set of lines
200 ;
201 ;Output:
202 ; HLMSTATE() - (pass by reference, required)
203 ;
204 N FS,CS,VALUE
205 S HLMSTATE("BATCH","CURRENT MESSAGE")=HLMSTATE("BATCH","CURRENT MESSAGE")+1
206 S FS=$E(MSH(1),4)
207 S CS=$E(MSH(1),5)
208 S VALUE=$P(MSH(2),FS,4)
209 S HLMSTATE("UNSTORED LINES",HLMSTATE("BATCH","CURRENT MESSAGE"))=$P(VALUE,CS)_"^"_$P(VALUE,CS,2)
210 S HLMSTATE("UNSTORED MSH")=1
211 M HLMSTATE("UNSTORED MSH",HLMSTATE("BATCH","CURRENT MESSAGE"))=MSH
212 S HLMSTATE("CURRENT SEGMENT")=0
213 S HLMSTATE("LINE COUNT")=0
214 S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+200
215 I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER"),$$SAVEMSG^HLOF778(.HLMSTATE) ;first stores stuff in 777, then headers in file 778
216 Q
Note: See TracBrowser for help on using the repository browser.