HLOMSG1 ;ALB/CJM-HL7 - APIs for files 777/778 (CONTINUED) ;02/04/2004
;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
;
FINDMSG(MSGID,LIST) ;
;Given a message id, this function finds the file 778 entries having that message id. The count is returned as the function value. If the message
;is within a batch, it might be in the subfile. The list of found
;records is in the format LIST(1)=<IEN>^<SUBIEN>,LIST(2)=<IEN>^<SUBIEN>,
;etc., where SUBIEN="" if the message is not within a batch.
;
N COUNT,MSG
K LIST
Q:$G(MSGID)="" 0
S (MSG,COUNT)=0
F S MSG=$O(^HLB("B",MSGID,MSG)) Q:'MSG S COUNT=COUNT+1,LIST(COUNT)=MSG
S MSG=""
F S MSG=$O(^HLB("AE",MSGID,MSG)) Q:MSG="" S COUNT=COUNT+1,LIST(COUNT)=MSG
Q COUNT
;
ACKTOIEN(MSGID,ACKTO) ;
;finds the ien of the initial message
;Input:
; MSGID - the msg id of the ack message
; ACKTO - msgid of the original message
;Output: Function returns "" if not found, otherwise the IEN, or, if the message is in a batch, the <ien>^<subien>
;
N LIST,RETURN
S RETURN=""
I $$FINDMSG(ACKTO,.LIST) D
.N COUNT
.S COUNT=0
.F S COUNT=$O(LIST(COUNT)) Q:'COUNT D Q:RETURN
..N IEN,SUBIEN
..S IEN=$P(LIST(COUNT),"^"),SUBIEN=$P(LIST(COUNT),"^",2)
..I 'SUBIEN D
...I $P($G(^HLB(IEN,0)),"^",7)=MSGID S RETURN=IEN
..E D
...I $P($G(^HLB(IEN,3,SUBIEN,0)),"^",4)=MSGID S RETURN=IEN_"^"_SUBIEN
Q RETURN
;
;
ACKBYIEN(MSGID,ACKBY) ;
;finds the ien of the ack message
;Input:
; MSGID - the msg id of the initial message
; ACKBY - msgid of the ack message
;Output: Function returns "" if not found, otherwise the IEN, or, if the message is in a batch, the <ien>^<subien>
;
N LIST,RETURN
S RETURN=""
I $$FINDMSG(ACKBY,.LIST) D
.N COUNT
.S COUNT=0
.F S COUNT=$O(LIST(COUNT)) Q:'COUNT D Q:RETURN
..N IEN,SUBIEN
..S IEN=$P(LIST(COUNT),"^"),SUBIEN=$P(LIST(COUNT),"^",2)
..I 'SUBIEN D
...I $P($G(^HLB(IEN,0)),"^",3)=MSGID S RETURN=IEN
..E D
...I $P($G(^HLB(IEN,3,SUBIEN,0)),"^",3)=MSGID S RETURN=IEN_"^"_SUBIEN
Q RETURN
;
GETMSGB(MSG,SUBIEN,SUBMSG) ;
;gets a message from within a batch
;Input:
; MSG (required, pass by reference) from $$GETMSG
; SUBIEN - the subrecord #
;Output:
; SUBMSG (pass by reference) These subscripts are returned:
; "ACK BY" - if this msg was app acked, the msg id if this msg that was app
; "ACK TO" - if this msg is an app ack, the msg id of msg being acked
; "EVENT" - HL7 Event
; "HDR",1) - fields 1-6 of the header segment
; "HDR",2) - fields 7-End of the header segment
; "ID" - Message Control ID
; "MESSAGE TYPE" - HL7 Message Type
; "STATUS" - completion status for the individual message
;
N NODE
S NODE=$G(^HLB(MSG("IEN"),3,SUBIEN,0))
S SUBMSG("ID")=$P(NODE,"^",2)
S SUBMSG("ACK TO")=$P(NODE,"^",3)
S SUBMSG("ACK BY")=$P(NODE,"^",4)
S SUBMSG("STATUS")=$P(NODE,"^",5)
S SUBMSG("HDR",1)=$G(^HLB(MSG("IEN"),3,SUBIEN,1)),SUBMSG("HDR",2)=$G(^(2))
S NODE=$G(^HLA(MSG("BODY"),2,SUBIEN,0))
S SUBMSG("MESSAGE TYPE")=$P(NODE,"^",2)
S SUBMSG("EVENT")=$P(NODE,"^",3)
Q
HLOMSG1 ;ALB/CJM-HL7 - APIs for files 777/778 (CONTINUED) ;02/04/2004
+1 ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
+2 ;
FINDMSG(MSGID,LIST) ;
+1 ;Given a message id, this function finds the file 778 entries having that message id. The count is returned as the function value. If the message
+2 ;is within a batch, it might be in the subfile. The list of found
+3 ;records is in the format LIST(1)=<IEN>^<SUBIEN>,LIST(2)=<IEN>^<SUBIEN>,
+4 ;etc., where SUBIEN="" if the message is not within a batch.
+5 ;
+6 NEW COUNT,MSG
+7 KILL LIST
+8 IF $GET(MSGID)=""
QUIT 0
+9 SET (MSG,COUNT)=0
+10 FOR
SET MSG=$ORDER(^HLB("B",MSGID,MSG))
IF 'MSG
QUIT
SET COUNT=COUNT+1
SET LIST(COUNT)=MSG
+11 SET MSG=""
+12 FOR
SET MSG=$ORDER(^HLB("AE",MSGID,MSG))
IF MSG=""
QUIT
SET COUNT=COUNT+1
SET LIST(COUNT)=MSG
+13 QUIT COUNT
+14 ;
ACKTOIEN(MSGID,ACKTO) ;
+1 ;finds the ien of the initial message
+2 ;Input:
+3 ; MSGID - the msg id of the ack message
+4 ; ACKTO - msgid of the original message
+5 ;Output: Function returns "" if not found, otherwise the IEN, or, if the message is in a batch, the <ien>^<subien>
+6 ;
+7 NEW LIST,RETURN
+8 SET RETURN=""
+9 IF $$FINDMSG(ACKTO,.LIST)
Begin DoDot:1
+10 NEW COUNT
+11 SET COUNT=0
+12 FOR
SET COUNT=$ORDER(LIST(COUNT))
IF 'COUNT
QUIT
Begin DoDot:2
+13 NEW IEN,SUBIEN
+14 SET IEN=$PIECE(LIST(COUNT),"^")
SET SUBIEN=$PIECE(LIST(COUNT),"^",2)
+15 IF 'SUBIEN
Begin DoDot:3
+16 IF $PIECE($GET(^HLB(IEN,0)),"^",7)=MSGID
SET RETURN=IEN
End DoDot:3
+17 IF '$TEST
Begin DoDot:3
+18 IF $PIECE($GET(^HLB(IEN,3,SUBIEN,0)),"^",4)=MSGID
SET RETURN=IEN_"^"_SUBIEN
End DoDot:3
End DoDot:2
IF RETURN
QUIT
End DoDot:1
+19 QUIT RETURN
+20 ;
+21 ;
ACKBYIEN(MSGID,ACKBY) ;
+1 ;finds the ien of the ack message
+2 ;Input:
+3 ; MSGID - the msg id of the initial message
+4 ; ACKBY - msgid of the ack message
+5 ;Output: Function returns "" if not found, otherwise the IEN, or, if the message is in a batch, the <ien>^<subien>
+6 ;
+7 NEW LIST,RETURN
+8 SET RETURN=""
+9 IF $$FINDMSG(ACKBY,.LIST)
Begin DoDot:1
+10 NEW COUNT
+11 SET COUNT=0
+12 FOR
SET COUNT=$ORDER(LIST(COUNT))
IF 'COUNT
QUIT
Begin DoDot:2
+13 NEW IEN,SUBIEN
+14 SET IEN=$PIECE(LIST(COUNT),"^")
SET SUBIEN=$PIECE(LIST(COUNT),"^",2)
+15 IF 'SUBIEN
Begin DoDot:3
+16 IF $PIECE($GET(^HLB(IEN,0)),"^",3)=MSGID
SET RETURN=IEN
End DoDot:3
+17 IF '$TEST
Begin DoDot:3
+18 IF $PIECE($GET(^HLB(IEN,3,SUBIEN,0)),"^",3)=MSGID
SET RETURN=IEN_"^"_SUBIEN
End DoDot:3
End DoDot:2
IF RETURN
QUIT
End DoDot:1
+19 QUIT RETURN
+20 ;
GETMSGB(MSG,SUBIEN,SUBMSG) ;
+1 ;gets a message from within a batch
+2 ;Input:
+3 ; MSG (required, pass by reference) from $$GETMSG
+4 ; SUBIEN - the subrecord #
+5 ;Output:
+6 ; SUBMSG (pass by reference) These subscripts are returned:
+7 ; "ACK BY" - if this msg was app acked, the msg id if this msg that was app
+8 ; "ACK TO" - if this msg is an app ack, the msg id of msg being acked
+9 ; "EVENT" - HL7 Event
+10 ; "HDR",1) - fields 1-6 of the header segment
+11 ; "HDR",2) - fields 7-End of the header segment
+12 ; "ID" - Message Control ID
+13 ; "MESSAGE TYPE" - HL7 Message Type
+14 ; "STATUS" - completion status for the individual message
+15 ;
+16 NEW NODE
+17 SET NODE=$GET(^HLB(MSG("IEN"),3,SUBIEN,0))
+18 SET SUBMSG("ID")=$PIECE(NODE,"^",2)
+19 SET SUBMSG("ACK TO")=$PIECE(NODE,"^",3)
+20 SET SUBMSG("ACK BY")=$PIECE(NODE,"^",4)
+21 SET SUBMSG("STATUS")=$PIECE(NODE,"^",5)
+22 SET SUBMSG("HDR",1)=$GET(^HLB(MSG("IEN"),3,SUBIEN,1))
SET SUBMSG("HDR",2)=$GET(^(2))
+23 SET NODE=$GET(^HLA(MSG("BODY"),2,SUBIEN,0))
+24 SET SUBMSG("MESSAGE TYPE")=$PIECE(NODE,"^",2)
+25 SET SUBMSG("EVENT")=$PIECE(NODE,"^",3)
+26 QUIT