source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOMSG.m@ 1318

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

initial load of FOIAVistA 6/30/08 version

File size: 8.9 KB
Line 
1HLOMSG ;ALB/CJM-HL7 - APIs for files 777/778 ;07/25/2007
2 ;;1.6;HEALTH LEVEL SEVEN;**126,134,137**;Oct 13, 1995;Build 21
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 ; "SEQUENCE QUEUE" - the sequence queue (optional)
46 ;
47 K MSG
48 Q:'$G(IEN) 0
49 N NODE
50 S MSG("IEN")=IEN
51 S NODE=$G(^HLB(IEN,0))
52 S MSG("ID")=$P(NODE,"^")
53 S MSG("BODY")=$P(NODE,"^",2)
54 S MSG("DIRECTION")=$S($E($P(NODE,"^",4))="O":"OUT",$E($P(NODE,"^",4))="I":"IN",1:"")
55 S MSG("ACK TO")=$P(NODE,"^",3)
56 S MSG("ACK BY")=$P(NODE,"^",7)
57 I MSG("ACK TO")]"" S MSG("ACK TO IEN")=$$ACKTOIEN^HLOMSG1($P(NODE,"^"),MSG("ACK TO"))
58 I MSG("ACK BY")]"" S MSG("ACK BY IEN")=$$ACKBYIEN^HLOMSG1($P(NODE,"^"),MSG("ACK BY"))
59 S MSG("DT/TM")=$P(NODE,"^",16)
60 S MSG("STATUS")=$P(NODE,"^",20)
61 ;
62 D
63 .N NODE4
64 .S NODE4=$G(^HLB(IEN,4))
65 .S MSG("STATUS","QUEUE")=$P(NODE,"^",6)
66 .S MSG("STATUS","LINK NAME")=$P(NODE,"^",5)
67 .S MSG("STATUS","PORT")=$P(NODE,"^",8)
68 .S MSG("STATUS","PURGE")=$P(NODE,"^",9)
69 .S MSG("STATUS","ERROR TEXT")=$P(NODE,"^",21)
70 .S MSG("STATUS","APP ACK RESPONSE")=$P(NODE,"^",10,11)
71 .I MSG("STATUS","APP ACK RESPONSE")="^" S MSG("STATUS","APP ACK RESPONSE")=""
72 .S MSG("STATUS","ACCEPT ACK RESPONSE")=$P(NODE,"^",12,13)
73 .I MSG("STATUS","ACCEPT ACK RESPONSE")="^" S MSG("STATUS","ACCEPT ACK RESPONSE")=""
74 .S MSG("STATUS","ACCEPT ACK'D")=$P(NODE,"^",17)
75 .S MSG("STATUS","APP ACK'D")=$P(NODE,"^",18)
76 .S MSG("STATUS")=$P(NODE,"^",20)
77 .S MSG("STATUS","APP HANDOFF")=$P(NODE,"^",19)
78 .S MSG("STATUS","ACCEPT ACK DT/TM")=$P(NODE4,"^")
79 .S MSG("STATUS","ACCEPT ACK ID")=$P(NODE4,"^",2)
80 .S MSG("STATUS","ACCEPT ACK MSA")=$P(NODE4,"^",3,99)
81 ;
82 S MSG("LINE COUNT")=0
83 S MSG("HDR",1)=$G(^HLB(IEN,1))
84 S MSG("HDR",2)=$G(^HLB(IEN,2))
85 I 'MSG("BODY") D Q 0
86 .S MSG("DT/TM CREATED")=""
87 .S MSG("BATCH")=""
88 .S MSG("MESSAGE TYPE")=""
89 .S MSG("EVENT")=""
90 ;
91 S NODE=$G(^HLA(MSG("BODY"),0))
92 S MSG("DT/TM CREATED")=+NODE
93 S MSG("BATCH")=+$P(NODE,"^",2)
94 I MSG("BATCH") S MSG("BATCH","CURRENT MESSAGE")=0
95 I 'MSG("BATCH") D
96 .S MSG("MESSAGE TYPE")=$P(NODE,"^",3)
97 .S MSG("EVENT")=$P(NODE,"^",4)
98 I MSG("DIRECTION")="OUT" D
99 .N NODE5
100 .S NODE5=$G(^HLB(IEN,5))
101 .S MSG("STATUS","SEQUENCE QUEUE")=$P(NODE5,"^")
102 .S MSG("STATUS","MOVED TO OUT QUEUE")=$P(NODE5,"^",2)
103 .S MSG("STATUS","SEQUENCE EXCEPTION RAISED")=$P(NODE5,"^",3)
104 Q 1
105 ;
106HLNEXT(MSG,SEG) ;
107 ;Description: Returns the next segment as a set of lines stored in SEG.
108 ;Input:
109 ; MSG (pass by reference, required)
110 ;Output:
111 ; Function returns 1 on success, 0 on failure (no more segments)
112 ; SEG (pass by reference, required)
113 ;
114 K SEG
115 Q:MSG("LINE COUNT")=-1 0
116 I 'MSG("BATCH") D
117 .N I,J,NODE,START
118 .S START=0
119 .S J=1,I=MSG("LINE COUNT")
120 .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
121 .I 'I D
122 ..S MSG("LINE COUNT")=-1
123 .E S MSG("LINE COUNT")=I
124 I MSG("BATCH") D
125 .N I,J,NODE,START
126 .S J=1,I=MSG("LINE COUNT"),START=0
127 .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
128 .I 'I D
129 ..S MSG("LINE COUNT")=-1
130 .E S MSG("LINE COUNT")=I
131 Q $S($D(SEG):1,1:0)
132 ;
133NEXTMSG(MSG,HDR) ;
134 ;Advances to the next message in the batch
135 ;Input:
136 ; MSG (pass by reference, required) - defined by $$GETMSG()
137 ;Output:
138 ; Function returns 1 on success, 0 if no more messages
139 ; MSG - updated with current position in the message
140 ; HDR (pass by reference, required) returns the header as an array of lines
141 ;
142 ;
143 K HDR
144 S MSG("LINE COUNT")=0
145 N SUBIEN,I
146 ;
147 ;if completed parsing, don't start over
148 I MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
149 ;
150 S I=$O(^HLB(MSG("IEN"),3,"B",MSG("BATCH","CURRENT MESSAGE")))
151 I 'I S MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
152 S MSG("BATCH","CURRENT MESSAGE")=I
153 S SUBIEN=$O(^HLB(MSG("IEN"),3,"B",I,0))
154 S HDR(1)=$G(^HLB(MSG("IEN"),3,SUBIEN,1))
155 S HDR(2)=$G(^HLB(MSG("IEN"),3,SUBIEN,2))
156 Q $S($D(HDR):1,1:0)
157 ;
158ADDSEG(HLMSTATE,SEG) ;Adds a segment to the message.
159 ;Input:
160 ; HLMSTATE() - (pass by reference, required)
161 ; SEG() - (pass by reference, required) The segment as lines SEG(<i>)
162 ;
163 ;Output:
164 ; HLMSTATE()
165 ;
166 N I,J S I=0
167 S J=HLMSTATE("LINE COUNT")
168 ;
169 ;insure a blank line between segments
170 I J S J=J+1,HLMSTATE("UNSTORED LINES",$S(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=""
171 ;
172 S HLMSTATE("CURRENT SEGMENT")=HLMSTATE("CURRENT SEGMENT")+1
173 F S I=$O(SEG(I)) Q:'I D
174 .S J=J+1
175 .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
176 .I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER") D
177 ..I HLMSTATE("DIRECTION")="IN",$$SAVEMSG^HLOF778(.HLMSTATE) Q
178 ..I HLMSTATE("DIRECTION")="OUT",$$SAVEMSG^HLOF777(.HLMSTATE)
179 ;
180 S HLMSTATE("LINE COUNT")=J
181 Q
182 ;
183ADDMSG(HLMSTATE,PARMS) ;
184 ;For outgoing messages, adds a message in the batch. There is no MSH yet, just the message type and event.
185 ;Input:
186 ; HLMSTATE() - (pass by reference, required)
187 ; PARMS("EVENT")
188 ; PARMS("MESSAGE TYPE")
189 ;
190 ;Output:
191 ; HLMSTATE() - (pass by reference, required)
192 ;
193 N I
194 S I=HLMSTATE("BATCH","CURRENT MESSAGE")+1,HLMSTATE("BATCH","CURRENT MESSAGE")=I
195 S HLMSTATE("UNSTORED LINES",I)=PARMS("MESSAGE TYPE")_"^"_PARMS("EVENT")
196 M:$G(PARMS("ACK TO"))]"" HLMSTATE("BATCH","ACK TO",I)=PARMS("ACK TO")
197 S HLMSTATE("CURRENT SEGMENT")=0
198 S HLMSTATE("LINE COUNT")=0
199 S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+100
200 Q
201 ;
202ADDMSG2(HLMSTATE,MSH) ;
203 ;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.
204 ;Input:
205 ; HLMSTATE() - (pass by reference, required)
206 ; MSH(<i>) - the MSH segment as a set of lines
207 ;
208 ;Output:
209 ; HLMSTATE() - (pass by reference, required)
210 ;
211 N FS,CS,VALUE
212 S HLMSTATE("BATCH","CURRENT MESSAGE")=HLMSTATE("BATCH","CURRENT MESSAGE")+1
213 S FS=$E(MSH(1),4)
214 S CS=$E(MSH(1),5)
215 S VALUE=$P(MSH(2),FS,4)
216 S HLMSTATE("UNSTORED LINES",HLMSTATE("BATCH","CURRENT MESSAGE"))=$P(VALUE,CS)_"^"_$P(VALUE,CS,2)
217 S HLMSTATE("UNSTORED MSH")=1
218 M HLMSTATE("UNSTORED MSH",HLMSTATE("BATCH","CURRENT MESSAGE"))=MSH
219 S HLMSTATE("CURRENT SEGMENT")=0
220 S HLMSTATE("LINE COUNT")=0
221 S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+200
222 I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER"),$$SAVEMSG^HLOF778(.HLMSTATE) ;first stores stuff in 777, then headers in file 778
223 Q
Note: See TracBrowser for help on using the repository browser.