Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLMSG

HLMSG.m

Go to the documentation of this file.
  1. HLMSG ;ALB/CJM-HL7 - APIs for files 772/773 ;02/04/2004
  1. ;;1.6;HEALTH LEVEL SEVEN;**118**;Oct 13, 1995
  1. ;
  1. GETMSG(IEN,MSG) ;
  1. ;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
  1. ;Input:
  1. ; IEN - the ien of the message in file 773
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. ; MSG (pass by reference, required) These are the subscripts returned:
  1. ; "BATCH" = 1 if this is a batch message, 0 if not
  1. ; "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.
  1. ; "BODY" - ptr to file 772 which contains the body of the message.
  1. ; "CURRENT LINE" - a counter used during building and parsing of
  1. ; messages to indicate the current line within the message. For
  1. ; batch messages where each message within the batch is stored
  1. ; separately, this field indicates the position within the current
  1. ; individual message
  1. ; "HDR" - the header segment, NOT parsed, as a sequence of lines HDR(i)
  1. ; "IEN" - ien, file 773
  1. ;
  1. K MSG
  1. Q:'$G(IEN) 0
  1. N I
  1. S MSG("IEN")=IEN
  1. S MSG("BODY")=$P($G(^HLMA(IEN,0)),"^")
  1. Q:'MSG("BODY") 0
  1. ;
  1. S MSG("BATCH")=$S($P(^HL(772,MSG("BODY"),0),"^",14)="B":1,1:0)
  1. I MSG("BATCH") S MSG("BATCH","CURRENT MESSAGE")=0
  1. S MSG("CURRENT LINE")=0
  1. S I=0
  1. F S I=$O(^HLMA(IEN,"MSH",I)) Q:'I S MSG("HDR",I)=$G(^HLMA(IEN,"MSH",I,0))
  1. Q 1
  1. ;
  1. NEXTSEG(MSG,SEG) ;
  1. ;Description: Returns the next segment as a set of lines stored in SEG.
  1. ;Input:
  1. ; MSG (pass by reference, required)
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure (no more segments)
  1. ; SEG (pass by reference, required)
  1. ;
  1. K SEG
  1. Q:MSG("CURRENT LINE")=-1 0
  1. I 'MSG("BATCH") D
  1. .N I,J
  1. .S J=1,I=MSG("CURRENT LINE")
  1. .F S I=$O(^HL(772,MSG("BODY"),"IN",I)) Q:'I Q:$G(^HL(772,MSG("BODY"),"IN",I,0))="" S SEG(J)=^HL(772,MSG("BODY"),"IN",I,0),J=J+1
  1. .I 'I S MSG("CURRENT LINE")=-1
  1. .I I S MSG("CURRENT LINE")=I
  1. I MSG("BATCH") D
  1. .N I,J
  1. .S I=MSG("CURRENT LINE")
  1. .F S I=$O(^HL(772,MSG("BODY"),"IN",I)) Q:'I I $G(^HL(772,MSG("BODY"),"IN",I,0))'="" D Q
  1. ..Q:$E($G(^HL(772,MSG("BODY"),"IN",I,0)),1,3)="MSH"
  1. ..I $E($G(^HL(772,MSG("BODY"),"IN",I,0)),1,3)="BTS" S MSG("CURRENT LINE")=-1,MSG("BATCH","CURRENT MESSAGE")=-1 Q
  1. ..S SEG(1)=$G(^HL(772,MSG("BODY"),"IN",I,0))
  1. ..S J=2
  1. ..F S I=$O(^HL(772,MSG("BODY"),"IN",I)) Q:'I Q:$G(^HL(772,MSG("BODY"),"IN",I,0))="" S SEG(J)=^HL(772,MSG("BODY"),"IN",I,0),J=J+1
  1. .I 'I S MSG("CURRENT LINE")=-1
  1. .I I S MSG("CURRENT LINE")=I-1
  1. Q $S($D(SEG):1,1:0)
  1. ;
  1. NEXTMSG(MSG,HDR) ;
  1. ;Advances to the next message in the batch
  1. ;Input:
  1. ; MSG (pass by reference, required) - defined by $$GETMSG()
  1. ;Output:
  1. ; Function returns 1 on success, 0 if no more messages
  1. ; MSH - updated with current position in the message
  1. ; HDR (pass by reference, required) returns the header as an array of 2lines HDR(1),HDR(2)
  1. ;
  1. K HDR
  1. N ARY,I,J
  1. S ARY="^HL(772,"_MSG("BODY")_",""IN"")"
  1. S I=MSG("CURRENT LINE")
  1. F S I=$O(@ARY@(I)) Q:'I D:$G(@ARY@(I,0))'="" Q:$D(HDR) Q:MSG("CURRENT LINE")=-1
  1. .I $E($G(@ARY@(I,0)),1,3)="BTS" S MSG("CURRENT LINE")=-1,MSG("BATCH","CURRENT MESSAGE")=-1 Q
  1. .I $E($G(@ARY@(I,0)),1,3)="MSH" D
  1. ..S J=1
  1. ..S HDR(J)=$G(@ARY@(I,0)),MSG("CURRENT LINE")=I,MSG("BATCH","CURRENT MESSAGE")=$G(MSG("BATCH","CURRENT MESSAGE"))+1
  1. ..F S I=$O(@ARY@(I)) Q:'I Q:$G(@ARY@(I,0))="" S J=J+1,HDR(J)=$G(@ARY@(I,0))
  1. .E D
  1. ..F S I=$O(@ARY@(I)) Q:'I Q:$G(@ARY@(I,0))=""
  1. Q $S($D(HDR):1,1:0)