source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLMSG.m@ 794

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

initial load of FOIAVistA 6/30/08 version

File size: 3.5 KB
Line 
1HLMSG ;ALB/CJM-HL7 - APIs for files 772/773 ;02/04/2004
2 ;;1.6;HEALTH LEVEL SEVEN;**118**;Oct 13, 1995
3 ;
4GETMSG(IEN,MSG) ;
5 ;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
6 ;Input:
7 ; IEN - the ien of the message in file 773
8 ;Output:
9 ; Function returns 1 on success, 0 on failure
10 ; MSG (pass by reference, required) These are the subscripts returned:
11 ; "BATCH" = 1 if this is a batch message, 0 if not
12 ; "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.
13 ; "BODY" - ptr to file 772 which contains the body of the message.
14 ; "CURRENT LINE" - a counter used during building and parsing of
15 ; messages to indicate the current line within the message. For
16 ; batch messages where each message within the batch is stored
17 ; separately, this field indicates the position within the current
18 ; individual message
19 ; "HDR" - the header segment, NOT parsed, as a sequence of lines HDR(i)
20 ; "IEN" - ien, file 773
21 ;
22 K MSG
23 Q:'$G(IEN) 0
24 N I
25 S MSG("IEN")=IEN
26 S MSG("BODY")=$P($G(^HLMA(IEN,0)),"^")
27 Q:'MSG("BODY") 0
28 ;
29 S MSG("BATCH")=$S($P(^HL(772,MSG("BODY"),0),"^",14)="B":1,1:0)
30 I MSG("BATCH") S MSG("BATCH","CURRENT MESSAGE")=0
31 S MSG("CURRENT LINE")=0
32 S I=0
33 F S I=$O(^HLMA(IEN,"MSH",I)) Q:'I S MSG("HDR",I)=$G(^HLMA(IEN,"MSH",I,0))
34 Q 1
35 ;
36NEXTSEG(MSG,SEG) ;
37 ;Description: Returns the next segment as a set of lines stored in SEG.
38 ;Input:
39 ; MSG (pass by reference, required)
40 ;Output:
41 ; Function returns 1 on success, 0 on failure (no more segments)
42 ; SEG (pass by reference, required)
43 ;
44 K SEG
45 Q:MSG("CURRENT LINE")=-1 0
46 I 'MSG("BATCH") D
47 .N I,J
48 .S J=1,I=MSG("CURRENT LINE")
49 .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
50 .I 'I S MSG("CURRENT LINE")=-1
51 .I I S MSG("CURRENT LINE")=I
52 I MSG("BATCH") D
53 .N I,J
54 .S I=MSG("CURRENT LINE")
55 .F S I=$O(^HL(772,MSG("BODY"),"IN",I)) Q:'I I $G(^HL(772,MSG("BODY"),"IN",I,0))'="" D Q
56 ..Q:$E($G(^HL(772,MSG("BODY"),"IN",I,0)),1,3)="MSH"
57 ..I $E($G(^HL(772,MSG("BODY"),"IN",I,0)),1,3)="BTS" S MSG("CURRENT LINE")=-1,MSG("BATCH","CURRENT MESSAGE")=-1 Q
58 ..S SEG(1)=$G(^HL(772,MSG("BODY"),"IN",I,0))
59 ..S J=2
60 ..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
61 .I 'I S MSG("CURRENT LINE")=-1
62 .I I S MSG("CURRENT LINE")=I-1
63 Q $S($D(SEG):1,1:0)
64 ;
65NEXTMSG(MSG,HDR) ;
66 ;Advances to the next message in the batch
67 ;Input:
68 ; MSG (pass by reference, required) - defined by $$GETMSG()
69 ;Output:
70 ; Function returns 1 on success, 0 if no more messages
71 ; MSH - updated with current position in the message
72 ; HDR (pass by reference, required) returns the header as an array of 2lines HDR(1),HDR(2)
73 ;
74 K HDR
75 N ARY,I,J
76 S ARY="^HL(772,"_MSG("BODY")_",""IN"")"
77 S I=MSG("CURRENT LINE")
78 F S I=$O(@ARY@(I)) Q:'I D:$G(@ARY@(I,0))'="" Q:$D(HDR) Q:MSG("CURRENT LINE")=-1
79 .I $E($G(@ARY@(I,0)),1,3)="BTS" S MSG("CURRENT LINE")=-1,MSG("BATCH","CURRENT MESSAGE")=-1 Q
80 .I $E($G(@ARY@(I,0)),1,3)="MSH" D
81 ..S J=1
82 ..S HDR(J)=$G(@ARY@(I,0)),MSG("CURRENT LINE")=I,MSG("BATCH","CURRENT MESSAGE")=$G(MSG("BATCH","CURRENT MESSAGE"))+1
83 ..F S I=$O(@ARY@(I)) Q:'I Q:$G(@ARY@(I,0))="" S J=J+1,HDR(J)=$G(@ARY@(I,0))
84 .E D
85 ..F S I=$O(@ARY@(I)) Q:'I Q:$G(@ARY@(I,0))=""
86 Q $S($D(HDR):1,1:0)
Note: See TracBrowser for help on using the repository browser.