source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLTPCK2.m@ 686

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

initial load of WorldVistAEHR

File size: 6.7 KB
Line 
1HLTPCK2 ;SF/RSD - Message Header Validation (TCP Link) ;09/13/2006
2 ;;1.6;HEALTH LEVEL SEVEN;**19,59,120,133**;Oct 13, 1995;Build 13
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4CHK(HDR,ARY,MSA) ;
5 ;Validate Data in Header Segment (MSH, BHS or FHS) of an HL7 Message
6 ; through TCP link.
7 ;
8 ;This entry point is a subroutine call with parameter passing that
9 ;will return an array (ARY()) consisting of values extracted from
10 ;the message header segment subscripted by the mnemonics for each of
11 ;the message header fields and components.
12 ;The message header can be multiple line longer than 255 characters.
13 ;HDR is an array that is passed by reference.
14 ;If an error is encountered during validation, the array parameter
15 ;(ARY) will be set equal to two pieces, error #^error text.
16 ;
17 ;Required input parameters
18 ; HDR = Message header array, HDR(1,0)=segment (passed by reference)
19 ;
20 ; ARY = The array in which the message header values will be
21 ; returned (passed by reference)
22 ;
23 ;Optional input parameter
24 ; MSA = A variable which contains the message acknowledgement values:
25 ; acknowledgement code^message control ID^text message. Passed
26 ; by reference so that Batch msg. can set this here.
27 ;
28 ;Check for required parameters
29 N ERR S ERR=""
30 I $D(HDR)<10 S ERR="7^"_$G(^HL(771.7,7,0))_" at CHK^HLTPCK2" G EXIT
31 N ECH,HLN,FS,X,X1,X2
32 S ARY="",ARY("Q")=""""""
33 ;
34 ;Validate field separator and encoding characters
35 S (ARY("FS"),FS)=$E(HDR(1,0),4)
36 I FS']"" S ERR="Field Separator Missing" G EXIT
37 I FS?.C S ERR="Invalid Field Separator" G EXIT
38 S (ARY("ECH"),ECH)=$$P(.HDR,2)
39 I ECH']"" S ERR="Encoding Characters Missing" G EXIT
40 I ECH?.C S ERR="Invalid Encoding Characters" G EXIT
41 ;
42 ; patch HL*1.6*120 start
43 ; patch HL*1.6*133
44 ; escape and sub-component characters are optional
45 ; I $L(ECH)'=4 S ERR="Invalid Encoding Characters" G EXIT
46 I $L(ECH)<1 S ERR="Invalid Encoding Characters" G EXIT
47 S ECH(1)=$E(ECH)
48 S ECH(2)=$E(ECH,2)
49 S ECH(3)=$E(ECH,3)
50 S ECH(4)=$E(ECH,4)
51 M ARY("HDR")=HDR
52 ;
53 ;Validate Message Header Type
54 S (ARY("TYPE"),X)=$$P(.HDR,1)
55 S ARY("HDR-1")=X
56 I X=""!("FHS,BHS,MSH"'[X) S ERR="Invalid Message Header" G EXIT
57 ;
58 ;Extract data from message header segment
59 ; S ARY("SAN")=$$P(.HDR,3),ARY("SFN")=$$P(.HDR,4),ARY("RAN")=$$P(.HDR,5),ARY("RFN")=$$P(.HDR,6),ARY("DTM")=$$P(.HDR,7)
60 S ARY("SAN")=$$P(.HDR,3)
61 S ARY("SFN")=$$P(.HDR,4)
62 S ARY("RAN")=$$P(.HDR,5)
63 S ARY("RFN")=$$P(.HDR,6)
64 S ARY("DTM")=$$P(.HDR,7)
65 ;
66 I X="BHS"!(X="FHS") D
67 . ; S ARY("MID")=$$P(.HDR,11),X=$$P(.HDR,9),ARY("PID")=$P(X,$E(ECH),2)
68 . ;
69 . S ARY("MID")=$$P(.HDR,11)
70 . ;
71 . ; BHS-9, Batch name/ID/Type:
72 . ; 2nd component: Processing ID <sub> Processing Mode
73 . ; 3rd component: Message Type <sub> Event Type
74 . ; 4th component: Version ID
75 . ; 5th component: Accept Acknowledgment Type
76 . ; 6th component: Application Acknowledgment Type
77 . S X=$$P(.HDR,9)
78 . S:X]"" ARY("HDR-9")=X
79 . ; original implementation incorrectly treats repetition separator as
80 . ; subcomponent separator
81 . S ECH("SUB-COMPONENT")=ECH(2)
82 . ; if subcomponent separator is correctly applied
83 . ; patch HL*1.6*133
84 . ; I X[ECH(4) S ECH("SUB-COMPONENT")=ECH(4)
85 . I ECH(4)]"",X[ECH(4) S ECH("SUB-COMPONENT")=ECH(4)
86 . ;
87 . S ARY("PID")=$P(X,ECH(1),2)
88 . ; patch HL*1.6*133
89 . ; I ARY("PID")[ECH("SUB-COMPONENT") D
90 . I ECH("SUB-COMPONENT")]"",ARY("PID")[ECH("SUB-COMPONENT") D
91 .. ; 2nd sub-component is Processing mode
92 .. S ARY("PMOD")=$P(ARY("PID"),ECH("SUB-COMPONENT"),2)
93 .. ; first sub-component is Processing id
94 .. S ARY("PID")=$P(ARY("PID"),ECH("SUB-COMPONENT"))
95 . ;
96 . ; S ARY("MTN")=$P($P(X,$E(ECH),3),$E(ECH,2)),ARY("ETN")=$P($P(X,$E(ECH),3),$E(ECH,2),2)
97 . ;
98 . S ARY("MTN")=$P(X,ECH(1),3)
99 . ; 2nd sub-component is event type
100 . ;
101 . ; patch HL*1.6*133 start
102 . S ARY("ETN")=""
103 . ; S ARY("ETN")=$P(ARY("MTN"),ECH("SUB-COMPONENT"),2)
104 . I ECH("SUB-COMPONENT")]"" D
105 .. S ARY("ETN")=$P(ARY("MTN"),ECH("SUB-COMPONENT"),2)
106 . ; 1st sub-component is message type
107 . ; S ARY("MTN")=$P(ARY("MTN"),ECH("SUB-COMPONENT"))
108 . I ECH("SUB-COMPONENT")]"" D
109 .. S ARY("MTN")=$P(ARY("MTN"),ECH("SUB-COMPONENT"))
110 . ; patch HL*1.6*133 end
111 . ;
112 . ; S ARY("VER")=$P(X,$E(ECH),4),ARY("ACAT")=$P(X,$E(ECH),5),ARY("APAT")=$P(X,$E(ECH),6)
113 . S ARY("VER")=$P(X,ECH(1),4)
114 . S:$P(X,ECH(1),5)]"" ARY("ACAT")=$P(X,ECH(1),5)
115 . S:$P(X,ECH(1),6)]"" ARY("APAT")=$P(X,ECH(1),6)
116 . ;
117 . ; BHS-10, batch comment
118 . ; first component: MSA-1, acknowledgment code
119 . ; 2nd component: MSA-3, text message
120 . ; S:$$P(.HDR,10)]"" MSA=$P($$P(.HDR,10),$E(ECH),1),$P(MSA,FS,2)=$$P(.HDR,12),$P(MSA,FS,3)=$P($$P(.HDR,10),$E(ECH),2)
121 . ;
122 . S X=$$P(.HDR,10)
123 . I X]"" D
124 .. S ARY("HDR-10")=X
125 .. ; MSA-1, acknowledgment code: AA,AE,AR,CA,CE,or CR
126 .. S MSA=$P(X,ECH(1),1)
127 .. ; MSA-2 and BHS-12, reference batch control id
128 .. S $P(MSA,FS,2)=$$P(.HDR,12)
129 .. ; MSA-3, text message
130 .. S $P(MSA,FS,3)=$P(X,ECH(1),2)
131 . ;
132 . ; Reference Batch Control ID
133 . S:$$P(.HDR,12)]"" ARY("HDR-12")=$$P(.HDR,12)
134 ;
135 ; I $$P(.HDR,1)="MSH" D
136 I ARY("HDR-1")="MSH" D
137 . ; S ARY("MID")=$$P(.HDR,10),ARY("PID")=$$P(.HDR,11),ARY("MTN")=$P($$P(.HDR,9),$E(ECH)),ARY("ETN")=$P($$P(.HDR,9),$E(ECH),2),ARY("VER")=$$P(.HDR,12)
138 . S ARY("MID")=$$P(.HDR,10)
139 . S ARY("PID")=$$P(.HDR,11)
140 . S X=$$P(.HDR,9)
141 . S ARY("MTN")=$P(X,ECH(1))
142 . S ARY("ETN")=$P(X,ECH(1),2)
143 . ;
144 . ; S:$P($$P(.HDR,9),$E(ECH),3)'="" ARY("MTN_ETN")=$P($$P(.HDR,9),$E(ECH),3)
145 . S:$P(X,ECH(1),3)]"" ARY("MTN_ETN")=$P(X,ECH(1),3)
146 . ;
147 . I ARY("PID")[ECH(1) D
148 .. ; 2nd component is Processing mode
149 .. S ARY("PMOD")=$P(ARY("PID"),ECH(1),2)
150 .. ; first component is Processing id
151 .. S ARY("PID")=$P(ARY("PID"),ECH(1))
152 . ;
153 . S ARY("VER")=$$P(.HDR,12)
154 . ;
155 . ; fields 13 and 14
156 . S:$$P(.HDR,13)]"" ARY("MSH-13")=$$P(.HDR,13)
157 . S:$$P(.HDR,14)]"" ARY("MSH-14")=$$P(.HDR,14)
158 . ;
159 . ; S:$$P(.HDR,15)]"" ARY("ACAT")=$$P(.HDR,15) S:$$P(.HDR,16)]"" ARY("APAT")=$$P(.HDR,16) S:$$P(.HDR,17)]"" ARY("CC")=$$P(.HDR,17)
160 . S:$$P(.HDR,15)]"" ARY("ACAT")=$$P(.HDR,15)
161 . S:$$P(.HDR,16)]"" ARY("APAT")=$$P(.HDR,16)
162 . S:$$P(.HDR,17)]"" ARY("CC")=$$P(.HDR,17)
163 . ;
164 . ; fields 18,19,20 and 21
165 . S:$$P(.HDR,18)]"" ARY("MSH-18")=$$P(.HDR,18)
166 . S:$$P(.HDR,19)]"" ARY("MSH-19")=$$P(.HDR,19)
167 . S:$$P(.HDR,20)]"" ARY("MSH-20")=$$P(.HDR,20)
168 . S:$$P(.HDR,21)]"" ARY("MSH-21")=$$P(.HDR,21)
169 ;
170 ;Invoke continuation routine to perform remaining validation checks
171 D ^HLTPCK2A
172EXIT ;
173 ; patch HL*1.6*120
174 ; the maximum length of field #773,22 (Error Message) is 200
175 I ERR]"" D
176 . S ERR=$E(ERR,1,200)
177 . S ARY=$S('ERR:"13^"_ERR,1:ERR)
178 ; patch HL*1.6*120 end
179 Q
180 ;
181P(MSH,P) ;get piece P from MSH array (passed by ref.)
182 N FS,I,L,L1,L2,X,Y
183 S FS=$E(MSH(1,0),4),(L2,Y)=0,X=""
184 F I=1:1 S L1=$L($G(MSH(I,0)),FS),L=L1+Y-1 D Q:$L(X)!'$D(MSH(I,0))
185 . S:L1=1 L=L+1
186 . S:P'>L X=$P($G(MSH(I-1,0)),FS,P-L2)_$P($G(MSH(I,0)),FS,(P-Y))
187 . S L2=Y,Y=L
188 Q X
189 ;
Note: See TracBrowser for help on using the repository browser.