HLOMSG ;ALB/CJM-HL7 - APIs for files 777/778 ;02/04/2004
;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
;
GETMSG(IEN,MSG) ;
;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
;Input:
; IEN - the ien of the message in file 778
;Output:
; Function returns 1 on success, 0 on failure
; MSG (pass by reference, required) These are the subscripts returned:
;
; "ACK BY" - msg id of msg that acknowledges this one
; "ACK BY IEN" - msg IEN of msg that acknowledges this one. If the message is in the batch, the value is <ien>^<subien>
; "ACK TO" - msg id of msg that this msg acknowledges
; "ACK TO IEN" - msg IEN of msg that this msg acknowledges. If the message is in a batch, the value is <ien>^<subien>
; "BATCH" = 1 if this is a batch message, 0 if not
; "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.
; "BODY" - ptr to file 778 which contains the body of the message.
; "DIRECTION" - "IN" if incoming, "OUT" if outgoing
; "DT/TM" - date/time the message was sent or received
; "DT/TM CREATED" - date/time the record was created (.01 field, file #777)
; "LINE COUNT" - a counter used during building and parsing of
; messages to indicate the current line within the message. For
; batch messages where each message within the batch is stored
; separately, this field indicates the position within the current
; individual message
; "HDR" - the header segment, NOT parsed, as HDR(1) and HDR(2)
; "ID" - Message Control ID for an individual message, Batch Control ID for a batch message
; "IEN" - ien, file 778
; "EVENT" - HL7 event, only defined if NOT batch
; "MESSAGE TYPE" - HL7 message type, only defined if NOT batch
; "STATUS" - the completion status
;
; These are lower level subscripts of "STATUS":
; "ACCEPT ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when the accept ack is received
; "ACCEPT ACK'D" - 1 if an accept ack was sent or received in response to this message
; "APP ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when app ack is received
; "APP ACK'D" - 1 if an application ack was sent or received in response to this message
; "ERROR TEXT" - if in error status, a description of the error
; "LINK NAME" the link the message was transmitted through
; "PORT" - remote port over which the message was transmitted
; "PURGE" - scheduled purge dt/tm
; "QUEUE" - the queue that the message was placed on
;
K MSG
Q:'$G(IEN) 0
N NODE
S MSG("IEN")=IEN
S NODE=$G(^HLB(IEN,0))
S MSG("ID")=$P(NODE,"^")
S MSG("BODY")=$P(NODE,"^",2)
Q:'MSG("BODY") 0
S MSG("DIRECTION")=$S($E($P(NODE,"^",4))="O":"OUT",$E($P(NODE,"^",4))="I":"IN",1:"")
S MSG("ACK TO")=$P(NODE,"^",3)
S MSG("ACK BY")=$P(NODE,"^",7)
I MSG("ACK TO")]"" S MSG("ACK TO IEN")=$$ACKTOIEN^HLOMSG1($P(NODE,"^"),MSG("ACK TO"))
I MSG("ACK BY")]"" S MSG("ACK BY IEN")=$$ACKBYIEN^HLOMSG1($P(NODE,"^"),MSG("ACK BY"))
S MSG("DT/TM")=$P(NODE,"^",16)
S MSG("STATUS")=$P(NODE,"^",20)
;
D
.N NODE4
.S NODE4=$G(^HLB(IEN,4))
.S MSG("STATUS","QUEUE")=$P(NODE,"^",6)
.S MSG("STATUS","LINK NAME")=$P(NODE,"^",5)
.S MSG("STATUS","PORT")=$P(NODE,"^",8)
.S MSG("STATUS","PURGE")=$P(NODE,"^",9)
.S MSG("STATUS","ERROR TEXT")=$P(NODE,"^",21)
.S MSG("STATUS","APP ACK RESPONSE")=$P(NODE,"^",10,11)
.I MSG("STATUS","APP ACK RESPONSE")="^" S MSG("STATUS","APP ACK RESPONSE")=""
.S MSG("STATUS","ACCEPT ACK RESPONSE")=$P(NODE,"^",12,13)
.I MSG("STATUS","ACCEPT ACK RESPONSE")="^" S MSG("STATUS","ACCEPT ACK RESPONSE")=""
.S MSG("STATUS","ACCEPT ACK'D")=$P(NODE,"^",17)
.S MSG("STATUS","APP ACK'D")=$P(NODE,"^",18)
.S MSG("STATUS")=$P(NODE,"^",20)
.S MSG("STATUS","APP HANDOFF")=$P(NODE,"^",19)
.S MSG("STATUS","ACCEPT ACK DT/TM")=$P(NODE4,"^")
.S MSG("STATUS","ACCEPT ACK ID")=$P(NODE4,"^",2)
.S MSG("STATUS","ACCEPT ACK MSA")=$P(NODE4,"^",3,99)
;
S NODE=$G(^HLA(MSG("BODY"),0))
S MSG("DT/TM CREATED")=+NODE
S MSG("BATCH")=+$P(NODE,"^",2)
I MSG("BATCH") S MSG("BATCH","CURRENT MESSAGE")=0
I 'MSG("BATCH") D
.S MSG("MESSAGE TYPE")=$P(NODE,"^",3)
.S MSG("EVENT")=$P(NODE,"^",4)
S MSG("LINE COUNT")=0
S MSG("HDR",1)=$G(^HLB(IEN,1))
S MSG("HDR",2)=$G(^HLB(IEN,2))
Q 1
;
HLNEXT(MSG,SEG) ;
;Description: Returns the next segment as a set of lines stored in SEG.
;Input:
; MSG (pass by reference, required)
;Output:
; Function returns 1 on success, 0 on failure (no more segments)
; SEG (pass by reference, required)
;
K SEG
Q:MSG("LINE COUNT")=-1 0
I 'MSG("BATCH") D
.N I,J,NODE,START
.S START=0
.S J=1,I=MSG("LINE COUNT")
.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
.I 'I D
..S MSG("LINE COUNT")=-1
.E S MSG("LINE COUNT")=I
I MSG("BATCH") D
.N I,J,NODE,START
.S J=1,I=MSG("LINE COUNT"),START=0
.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
.I 'I D
..S MSG("LINE COUNT")=-1
.E S MSG("LINE COUNT")=I
Q $S($D(SEG):1,1:0)
;
NEXTMSG(MSG,HDR) ;
;Advances to the next message in the batch
;Input:
; MSG (pass by reference, required) - defined by $$GETMSG()
;Output:
; Function returns 1 on success, 0 if no more messages
; MSG - updated with current position in the message
; HDR (pass by reference, required) returns the header as an array of lines
;
;
K HDR
S MSG("LINE COUNT")=0
N SUBIEN,I
;
;if completed parsing, don't start over
I MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
;
S I=$O(^HLB(MSG("IEN"),3,"B",MSG("BATCH","CURRENT MESSAGE")))
I 'I S MSG("BATCH","CURRENT MESSAGE")=-1 Q 0
S MSG("BATCH","CURRENT MESSAGE")=I
S SUBIEN=$O(^HLB(MSG("IEN"),3,"B",I,0))
S HDR(1)=$G(^HLB(MSG("IEN"),3,SUBIEN,1))
S HDR(2)=$G(^HLB(MSG("IEN"),3,SUBIEN,2))
Q $S($D(HDR):1,1:0)
;
ADDSEG(HLMSTATE,SEG) ;Adds a segment to the message.
;Input:
; HLMSTATE() - (pass by reference, required)
; SEG() - (pass by reference, required) The segment as lines SEG(<i>)
;
;Output:
; HLMSTATE()
;
N I,J S I=0
S J=HLMSTATE("LINE COUNT")
;
;insure a blank line between segments
I J S J=J+1,HLMSTATE("UNSTORED LINES",$S(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=""
;
S HLMSTATE("CURRENT SEGMENT")=HLMSTATE("CURRENT SEGMENT")+1
F S I=$O(SEG(I)) Q:'I D
.S J=J+1
.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
.I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER") D
..I HLMSTATE("DIRECTION")="IN",$$SAVEMSG^HLOF778(.HLMSTATE) Q
..I HLMSTATE("DIRECTION")="OUT",$$SAVEMSG^HLOF777(.HLMSTATE)
;
S HLMSTATE("LINE COUNT")=J
Q
;
ADDMSG(HLMSTATE,PARMS) ;
;For outgoing messages, adds a message in the batch. There is no MSH yet, just the message type and event.
;Input:
; HLMSTATE() - (pass by reference, required)
; PARMS("EVENT")
; PARMS("MESSAGE TYPE")
;
;Output:
; HLMSTATE() - (pass by reference, required)
;
N I
S I=HLMSTATE("BATCH","CURRENT MESSAGE")+1,HLMSTATE("BATCH","CURRENT MESSAGE")=I
S HLMSTATE("UNSTORED LINES",I)=PARMS("MESSAGE TYPE")_"^"_PARMS("EVENT")
M:$G(PARMS("ACK TO"))]"" HLMSTATE("BATCH","ACK TO",I)=PARMS("ACK TO")
S HLMSTATE("CURRENT SEGMENT")=0
S HLMSTATE("LINE COUNT")=0
S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+100
Q
;
ADDMSG2(HLMSTATE,MSH) ;
;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.
;Input:
; HLMSTATE() - (pass by reference, required)
; MSH(<i>) - the MSH segment as a set of lines
;
;Output:
; HLMSTATE() - (pass by reference, required)
;
N FS,CS,VALUE
S HLMSTATE("BATCH","CURRENT MESSAGE")=HLMSTATE("BATCH","CURRENT MESSAGE")+1
S FS=$E(MSH(1),4)
S CS=$E(MSH(1),5)
S VALUE=$P(MSH(2),FS,4)
S HLMSTATE("UNSTORED LINES",HLMSTATE("BATCH","CURRENT MESSAGE"))=$P(VALUE,CS)_"^"_$P(VALUE,CS,2)
S HLMSTATE("UNSTORED MSH")=1
M HLMSTATE("UNSTORED MSH",HLMSTATE("BATCH","CURRENT MESSAGE"))=MSH
S HLMSTATE("CURRENT SEGMENT")=0
S HLMSTATE("LINE COUNT")=0
S HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+200
I HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER"),$$SAVEMSG^HLOF778(.HLMSTATE) ;first stores stuff in 777, then headers in file 778
Q
HLOMSG ;ALB/CJM-HL7 - APIs for files 777/778 ;02/04/2004
+1 ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
+2 ;
GETMSG(IEN,MSG) ;
+1 ;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
+2 ;Input:
+3 ; IEN - the ien of the message in file 778
+4 ;Output:
+5 ; Function returns 1 on success, 0 on failure
+6 ; MSG (pass by reference, required) These are the subscripts returned:
+7 ;
+8 ; "ACK BY" - msg id of msg that acknowledges this one
+9 ; "ACK BY IEN" - msg IEN of msg that acknowledges this one. If the message is in the batch, the value is <ien>^<subien>
+10 ; "ACK TO" - msg id of msg that this msg acknowledges
+11 ; "ACK TO IEN" - msg IEN of msg that this msg acknowledges. If the message is in a batch, the value is <ien>^<subien>
+12 ; "BATCH" = 1 if this is a batch message, 0 if not
+13 ; "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.
+14 ; "BODY" - ptr to file 778 which contains the body of the message.
+15 ; "DIRECTION" - "IN" if incoming, "OUT" if outgoing
+16 ; "DT/TM" - date/time the message was sent or received
+17 ; "DT/TM CREATED" - date/time the record was created (.01 field, file #777)
+18 ; "LINE COUNT" - a counter used during building and parsing of
+19 ; messages to indicate the current line within the message. For
+20 ; batch messages where each message within the batch is stored
+21 ; separately, this field indicates the position within the current
+22 ; individual message
+23 ; "HDR" - the header segment, NOT parsed, as HDR(1) and HDR(2)
+24 ; "ID" - Message Control ID for an individual message, Batch Control ID for a batch message
+25 ; "IEN" - ien, file 778
+26 ; "EVENT" - HL7 event, only defined if NOT batch
+27 ; "MESSAGE TYPE" - HL7 message type, only defined if NOT batch
+28 ; "STATUS" - the completion status
+29 ;
+30 ; These are lower level subscripts of "STATUS":
+31 ; "ACCEPT ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when the accept ack is received
+32 ; "ACCEPT ACK'D" - 1 if an accept ack was sent or received in response to this message
+33 ; "APP ACK RESPONSE" - the application's <tag>^<rtn> to Xecute when app ack is received
+34 ; "APP ACK'D" - 1 if an application ack was sent or received in response to this message
+35 ; "ERROR TEXT" - if in error status, a description of the error
+36 ; "LINK NAME" the link the message was transmitted through
+37 ; "PORT" - remote port over which the message was transmitted
+38 ; "PURGE" - scheduled purge dt/tm
+39 ; "QUEUE" - the queue that the message was placed on
+40 ;
+41 KILL MSG
+42 IF '$GET(IEN)
QUIT 0
+43 NEW NODE
+44 SET MSG("IEN")=IEN
+45 SET NODE=$GET(^HLB(IEN,0))
+46 SET MSG("ID")=$PIECE(NODE,"^")
+47 SET MSG("BODY")=$PIECE(NODE,"^",2)
+48 IF 'MSG("BODY")
QUIT 0
+49 SET MSG("DIRECTION")=$SELECT($EXTRACT($PIECE(NODE,"^",4))="O":"OUT",$EXTRACT($PIECE(NODE,"^",4))="I":"IN",1:"")
+50 SET MSG("ACK TO")=$PIECE(NODE,"^",3)
+51 SET MSG("ACK BY")=$PIECE(NODE,"^",7)
+52 IF MSG("ACK TO")]""
SET MSG("ACK TO IEN")=$$ACKTOIEN^HLOMSG1($PIECE(NODE,"^"),MSG("ACK TO"))
+53 IF MSG("ACK BY")]""
SET MSG("ACK BY IEN")=$$ACKBYIEN^HLOMSG1($PIECE(NODE,"^"),MSG("ACK BY"))
+54 SET MSG("DT/TM")=$PIECE(NODE,"^",16)
+55 SET MSG("STATUS")=$PIECE(NODE,"^",20)
+56 ;
+57 Begin DoDot:1
+58 NEW NODE4
+59 SET NODE4=$GET(^HLB(IEN,4))
+60 SET MSG("STATUS","QUEUE")=$PIECE(NODE,"^",6)
+61 SET MSG("STATUS","LINK NAME")=$PIECE(NODE,"^",5)
+62 SET MSG("STATUS","PORT")=$PIECE(NODE,"^",8)
+63 SET MSG("STATUS","PURGE")=$PIECE(NODE,"^",9)
+64 SET MSG("STATUS","ERROR TEXT")=$PIECE(NODE,"^",21)
+65 SET MSG("STATUS","APP ACK RESPONSE")=$PIECE(NODE,"^",10,11)
+66 IF MSG("STATUS","APP ACK RESPONSE")="^"
SET MSG("STATUS","APP ACK RESPONSE")=""
+67 SET MSG("STATUS","ACCEPT ACK RESPONSE")=$PIECE(NODE,"^",12,13)
+68 IF MSG("STATUS","ACCEPT ACK RESPONSE")="^"
SET MSG("STATUS","ACCEPT ACK RESPONSE")=""
+69 SET MSG("STATUS","ACCEPT ACK'D")=$PIECE(NODE,"^",17)
+70 SET MSG("STATUS","APP ACK'D")=$PIECE(NODE,"^",18)
+71 SET MSG("STATUS")=$PIECE(NODE,"^",20)
+72 SET MSG("STATUS","APP HANDOFF")=$PIECE(NODE,"^",19)
+73 SET MSG("STATUS","ACCEPT ACK DT/TM")=$PIECE(NODE4,"^")
+74 SET MSG("STATUS","ACCEPT ACK ID")=$PIECE(NODE4,"^",2)
+75 SET MSG("STATUS","ACCEPT ACK MSA")=$PIECE(NODE4,"^",3,99)
End DoDot:1
+76 ;
+77 SET NODE=$GET(^HLA(MSG("BODY"),0))
+78 SET MSG("DT/TM CREATED")=+NODE
+79 SET MSG("BATCH")=+$PIECE(NODE,"^",2)
+80 IF MSG("BATCH")
SET MSG("BATCH","CURRENT MESSAGE")=0
+81 IF 'MSG("BATCH")
Begin DoDot:1
+82 SET MSG("MESSAGE TYPE")=$PIECE(NODE,"^",3)
+83 SET MSG("EVENT")=$PIECE(NODE,"^",4)
End DoDot:1
+84 SET MSG("LINE COUNT")=0
+85 SET MSG("HDR",1)=$GET(^HLB(IEN,1))
+86 SET MSG("HDR",2)=$GET(^HLB(IEN,2))
+87 QUIT 1
+88 ;
HLNEXT(MSG,SEG) ;
+1 ;Description: Returns the next segment as a set of lines stored in SEG.
+2 ;Input:
+3 ; MSG (pass by reference, required)
+4 ;Output:
+5 ; Function returns 1 on success, 0 on failure (no more segments)
+6 ; SEG (pass by reference, required)
+7 ;
+8 KILL SEG
+9 IF MSG("LINE COUNT")=-1
QUIT 0
+10 IF 'MSG("BATCH")
Begin DoDot:1
+11 NEW I,J,NODE,START
+12 SET START=0
+13 SET J=1
SET I=MSG("LINE COUNT")
+14 FOR
SET I=$ORDER(^HLA(MSG("BODY"),1,I))
IF 'I
QUIT
SET NODE=$GET(^HLA(MSG("BODY"),1,I,0))
IF (START&(NODE=""))
QUIT
IF NODE'=""
SET SEG(J)=NODE
SET J=J+1
SET START=1
+15 IF 'I
Begin DoDot:2
+16 SET MSG("LINE COUNT")=-1
End DoDot:2
+17 IF '$TEST
SET MSG("LINE COUNT")=I
End DoDot:1
+18 IF MSG("BATCH")
Begin DoDot:1
+19 NEW I,J,NODE,START
+20 SET J=1
SET I=MSG("LINE COUNT")
SET START=0
+21 FOR
SET I=$ORDER(^HLA(MSG("BODY"),2,MSG("BATCH","CURRENT MESSAGE"),1,I))
IF 'I
QUIT
SET NODE=$GET(^HLA(MSG("BODY"),2,MSG("BATCH","CURRENT MESSAGE"),1,I,0))
IF (START&(NODE=""))
QUIT
IF NODE'=""
SET SEG(J)=NODE
SET J=J+1
SET START=1
+22 IF 'I
Begin DoDot:2
+23 SET MSG("LINE COUNT")=-1
End DoDot:2
+24 IF '$TEST
SET MSG("LINE COUNT")=I
End DoDot:1
+25 QUIT $SELECT($DATA(SEG):1,1:0)
+26 ;
NEXTMSG(MSG,HDR) ;
+1 ;Advances to the next message in the batch
+2 ;Input:
+3 ; MSG (pass by reference, required) - defined by $$GETMSG()
+4 ;Output:
+5 ; Function returns 1 on success, 0 if no more messages
+6 ; MSG - updated with current position in the message
+7 ; HDR (pass by reference, required) returns the header as an array of lines
+8 ;
+9 ;
+10 KILL HDR
+11 SET MSG("LINE COUNT")=0
+12 NEW SUBIEN,I
+13 ;
+14 ;if completed parsing, don't start over
+15 IF MSG("BATCH","CURRENT MESSAGE")=-1
QUIT 0
+16 ;
+17 SET I=$ORDER(^HLB(MSG("IEN"),3,"B",MSG("BATCH","CURRENT MESSAGE")))
+18 IF 'I
SET MSG("BATCH","CURRENT MESSAGE")=-1
QUIT 0
+19 SET MSG("BATCH","CURRENT MESSAGE")=I
+20 SET SUBIEN=$ORDER(^HLB(MSG("IEN"),3,"B",I,0))
+21 SET HDR(1)=$GET(^HLB(MSG("IEN"),3,SUBIEN,1))
+22 SET HDR(2)=$GET(^HLB(MSG("IEN"),3,SUBIEN,2))
+23 QUIT $SELECT($DATA(HDR):1,1:0)
+24 ;
ADDSEG(HLMSTATE,SEG) ;Adds a segment to the message.
+1 ;Input:
+2 ; HLMSTATE() - (pass by reference, required)
+3 ; SEG() - (pass by reference, required) The segment as lines SEG(<i>)
+4 ;
+5 ;Output:
+6 ; HLMSTATE()
+7 ;
+8 NEW I,J
SET I=0
+9 SET J=HLMSTATE("LINE COUNT")
+10 ;
+11 ;insure a blank line between segments
+12 IF J
SET J=J+1
SET HLMSTATE("UNSTORED LINES",$SELECT(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=""
+13 ;
+14 SET HLMSTATE("CURRENT SEGMENT")=HLMSTATE("CURRENT SEGMENT")+1
+15 FOR
SET I=$ORDER(SEG(I))
IF 'I
QUIT
Begin DoDot:1
+16 SET J=J+1
+17 SET HLMSTATE("UNSTORED LINES",$SELECT(HLMSTATE("BATCH"):HLMSTATE("BATCH","CURRENT MESSAGE"),1:1),HLMSTATE("CURRENT SEGMENT"),J)=SEG(I)
SET HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+$LENGTH(SEG(I))+50
+18 IF HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER")
Begin DoDot:2
+19 IF HLMSTATE("DIRECTION")="IN"
IF $$SAVEMSG^HLOF778(.HLMSTATE)
QUIT
+20 IF HLMSTATE("DIRECTION")="OUT"
IF $$SAVEMSG^HLOF777(.HLMSTATE)
End DoDot:2
End DoDot:1
+21 ;
+22 SET HLMSTATE("LINE COUNT")=J
+23 QUIT
+24 ;
ADDMSG(HLMSTATE,PARMS) ;
+1 ;For outgoing messages, adds a message in the batch. There is no MSH yet, just the message type and event.
+2 ;Input:
+3 ; HLMSTATE() - (pass by reference, required)
+4 ; PARMS("EVENT")
+5 ; PARMS("MESSAGE TYPE")
+6 ;
+7 ;Output:
+8 ; HLMSTATE() - (pass by reference, required)
+9 ;
+10 NEW I
+11 SET I=HLMSTATE("BATCH","CURRENT MESSAGE")+1
SET HLMSTATE("BATCH","CURRENT MESSAGE")=I
+12 SET HLMSTATE("UNSTORED LINES",I)=PARMS("MESSAGE TYPE")_"^"_PARMS("EVENT")
+13 IF $GET(PARMS("ACK TO"))]""
MERGE HLMSTATE("BATCH","ACK TO",I)=PARMS("ACK TO")
+14 SET HLMSTATE("CURRENT SEGMENT")=0
+15 SET HLMSTATE("LINE COUNT")=0
+16 SET HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+100
+17 QUIT
+18 ;
ADDMSG2(HLMSTATE,MSH) ;
+1 ;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.
+2 ;Input:
+3 ; HLMSTATE() - (pass by reference, required)
+4 ; MSH(<i>) - the MSH segment as a set of lines
+5 ;
+6 ;Output:
+7 ; HLMSTATE() - (pass by reference, required)
+8 ;
+9 NEW FS,CS,VALUE
+10 SET HLMSTATE("BATCH","CURRENT MESSAGE")=HLMSTATE("BATCH","CURRENT MESSAGE")+1
+11 SET FS=$EXTRACT(MSH(1),4)
+12 SET CS=$EXTRACT(MSH(1),5)
+13 SET VALUE=$PIECE(MSH(2),FS,4)
+14 SET HLMSTATE("UNSTORED LINES",HLMSTATE("BATCH","CURRENT MESSAGE"))=$PIECE(VALUE,CS)_"^"_$PIECE(VALUE,CS,2)
+15 SET HLMSTATE("UNSTORED MSH")=1
+16 MERGE HLMSTATE("UNSTORED MSH",HLMSTATE("BATCH","CURRENT MESSAGE"))=MSH
+17 SET HLMSTATE("CURRENT SEGMENT")=0
+18 SET HLMSTATE("LINE COUNT")=0
+19 SET HLMSTATE("UNSTORED LINES")=HLMSTATE("UNSTORED LINES")+200
+20 ;first stores stuff in 777, then headers in file 778
IF HLMSTATE("UNSTORED LINES")>HLMSTATE("SYSTEM","BUFFER")
IF $$SAVEMSG^HLOF778(.HLMSTATE)
+21 QUIT