source: WorldVistAEHR/trunk/r/AUTOMATED_LAB_INSTRUMENTS-LA/LA7VORM1.m@ 1111

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

initial load of WorldVistAEHR

File size: 9.2 KB
Line 
1LA7VORM1 ;DALOI/DLR - LAB ORM (Order) message builder ;1/27/07 12:25
2 ;;5.2;AUTOMATED LAB INSTRUMENTS;**27,51,46,61,64,73**;Sep 27, 1994;Build 7
3 ; Modified from FOIA VISTA,
4 ; Copyright (C) 2007 WorldVistA
5 ;
6 ; This program is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation; either version 2 of the License, or
9 ; (at your option) any later version.
10 ;
11 ; This program is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU General Public License
17 ; along with this program; if not, write to the Free Software
18 ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 ;
20BUILD(LA7628) ;
21 ; Call with LA7628 = ien of entry in file #62.8 Shipping Manifest
22 ;
23 N LA7101,LA762801,LA7629,LA7NVAF,LA7PIDSN,LA7X,ECNT,GBL,SHP,SHPC,SITE,ORUID,NTST
24 N LDATE,LDATE2
25 ;
26 I $G(LA7628)<1!('$D(^LAHM(62.8,+$G(LA7628),0))) D Q
27 . ; Need to add error logging for manifest not found.
28 . D EXIT
29 ;
30 S LDATE2=$P(^LAHM(62.8,LA7628,0),"-",2)
31 S LDATE=($E(LDATE2,1,4)-1700)_$E(LDATE2,5,8)
32 S GBL="^TMP(""HLS"","_$J_")",ECNT=1
33 S LA7628(0)=$G(^LAHM(62.8,LA7628,0))
34 S LA7629=$P(LA7628(0),U,2)
35 S LA7629(0)=$G(^LAHM(62.9,LA7629,0))
36 S LA76248=+$P(LA7629(0),"^",7)
37 S LA76248(0)=$G(^LAHM(62.48,LA76248,0))
38 I '$P(LA76248(0),"^",3) D EXIT Q ; not active
39 ;
40 S LA7V("INST")=$P(LA7629(0),U,11)
41 Q:LA7V("INST")=$P(LA7629(0),U,6) ;Same system shipment
42 ;
43 S LA7NVAF=$$NVAF^LA7VHLU2(+LA7V("INST")),SITE=""
44 I LA7NVAF=0 S SITE=$$GET1^DIQ(4,+$P(LA7629(0),U,11)_",",99)
45 I LA7NVAF=1 S SITE=$$ID^XUAF4("DMIS",+$P(LA7629(0),U,11))
46 S LA7V("NON")=$P(LA7629(0),U,12)
47 I LA7V("NON")'="" S SITE=LA7V("NON")
48 ;
49 S LA7X=$$NVAF^LA7VHLU2(+$P(LA7629(0),U,2))
50 I LA7X=0 S LA7V("CLNT")=$$GET1^DIQ(4,+$P(LA7629(0),U,2)_",",99)
51 I LA7X=1 S LA7V("CLNT")=$$ID^XUAF4("DMIS",+$P(LA7629(0),U,2))
52 S $P(LA7V("CLNT"),U,2)=$$GET1^DIQ(4,+$P(LA7629(0),U,2)_",",.01)
53 ;
54 S LA7X=$$NVAF^LA7VHLU2(+$P(LA7629(0),U,3))
55 I LA7X=0 S LA7V("HOST")=$$GET1^DIQ(4,+$P(LA7629(0),U,3)_",",99)
56 I LA7X=1 S LA7V("HOST")=$$ID^XUAF4("DMIS",+$P(LA7629(0),U,3))
57 S $P(LA7V("HOST"),U,2)=$$GET1^DIQ(4,+$P(LA7629(0),U,3)_",",.01)
58 ;
59 ; Assuming the receiving institution is the primary site (site with the computer system)
60 ;
61 ; Sort tests by patient,UID,test - only need to build one PID, PV1 per patient
62 ; ^TMP("LA7628",$J, LRDFN, accession UID, ien of shipping manifest specimen entry)
63 K ^TMP("LA7628",$J)
64 S LA762801=0
65 F S LA762801=$O(^LAHM(62.8,LA7628,10,LA762801)) Q:'LA762801 D
66 . S X(0)=$G(^LAHM(62.8,LA7628,10,LA762801,0))
67 . I $P(X(0),"^",8)=0 Q ; Removed from manifest
68 . I $P(X(0),"^"),$L($P(X(0),"^",5)) S ^TMP("LA7628",$J,+$P(X(0),"^"),$P(X(0),"^",5),LA762801)=""
69 K LA762801
70 ;
71 ; Nothing to send
72 I '$D(^TMP("LA7628",$J)) D EXIT Q
73 ;
74 ; Set flag = 0 (multiple PID's/message - build one message)
75 ; 1 (one PID/message - build multiple messages)
76 ; 2 (one ORC/message - build multiple messages)
77 S LA7SMSG=+$P(LA76248(0),"^",8)
78 ;
79 I LA7SMSG=0 D Q:$G(HL)
80 . D STARTMSG
81 . I $G(HL) D EXIT
82 ;
83 S (LRDFN,LRI,LA7PIDSN)=0
84 F S LRDFN=$O(^TMP("LA7628",$J,LRDFN)) Q:'LRDFN D Q:$G(HL)
85 . N LA7PID,LA7PV1,ORNUM
86 . I LA7SMSG=1 D STARTMSG Q:$G(HL)
87 . I LA7SMSG<2 D PID,PV1,IN1^LA7VORM4
88 . S LA7UID=""
89 . F S LA7UID=$O(^TMP("LA7628",$J,LRDFN,LA7UID)) Q:LA7UID="" D
90 . . N LA76802,LA7ORC,X,ORCCHK,DGCHK
91 . . S ORCCHK="",DGCHK=""
92 . . S X=$Q(^LRO(68,"C",LA7UID))
93 . . I $QS(X,3)'=LA7UID Q
94 . . S LRAA=$QS(X,4),LRAD=$QS(X,5),LRAN=$QS(X,6)
95 . . F I=0,.3,3 S LA76802(I)=$G(^LRO(68,LRAA,1,LRAD,1,LRAN,I))
96 . . S I=$O(^LRO(68,LRAA,1,LRAD,1,LRAN,5,0))
97 . . S LA76802(5)=$G(^LRO(68,LRAA,1,LRAD,1,LRAN,5,I,0))
98 . . ;check for VOE before inserting insurance
99 . . I DUZ("AG")="E",LA7SMSG=2 D STARTMSG Q:$G(HL) D PID,PV1,IN1^LA7VORM4
100 . . I DUZ("AG")'="E",LA7SMSG=2 D STARTMSG Q:$G(HL) D PID,PV1
101 . . S (LA7OBRSN,LA762801)=0
102 . . F S LA762801=$O(^TMP("LA7628",$J,LRDFN,LA7UID,LA762801)) Q:'LA762801 D
103 . . . N LA7OBR,I
104 . . . F I=0,.1,1,2,5 S LA762801(I)=$G(^LAHM(62.8,LA7628,10,LA762801,I))
105 . . . I $$CHKTST^LA7SMU(LA7628,LA762801)'=0 Q ;deleted accession
106 . . . ; check for VOE to prepare for Diagnosis codes.
107 . . . I DUZ("AG")="E" D ; check for VOE
108 . . . . S ITEMNUM=0
109 . . . . F S ITEMNUM=ITEMNUM+1 Q:ITEMNUM>$P(^LRO(69,LDATE,1,0),"^",4) D
110 . . . . . I LRDFN=$P(^LRO(69,LDATE,1,ITEMNUM,0),"^") S ORNUM=$P(^LRO(69,LDATE,1,ITEMNUM,0),"^",11)
111 . . . . I ORCCHK'=1 D ORC S ORCCHK=1
112 . . . . D OBR^LA7VORM3,OBX^LA7VORM3
113 . . . E D ; not VOE
114 . . . . D ORC,OBR^LA7VORM3,OBX^LA7VORM3
115 . . ; check for VOE before inserting Diagnosis code
116 . . I DUZ("AG")="E",DGCHK'=1 D DG1^LA7VORM4(ORNUM) S DGCHK=1
117 . . I LA7SMSG=2 D BLG,SENDMSG
118 . I LA7SMSG<2 D BLG
119 . I LA7SMSG=1 D SENDMSG
120 ;
121 I LA7SMSG=0 D SENDMSG
122 ;
123 ;
124EXIT ;
125 K @GBL,^TMP("LA7628",$J)
126 K DIC,DFN,EID,HL,HLCOMP,HLFS,HLQ,HLSUB,INT
127 K LA760,LA7628,LA762801,LA7629
128 K LA7ECH,LA7FS,LA7MID,LA7V,LA7HDR,LA7OBRSN,LA7OBXSN,LA7VIEN,LAEVNT
129 K LRAA,LRACC,LRAD,LRAN,LRDFN,LRI
130 K LTST,NLT,NLTIEN,PCNT,RUID,SNIEN,TIEN,X,Y,LA
131 K ORCCHK,DGCHK,LDATE,LDATE2
132 D KVAR^LRX
133 I $D(ZTQUEUED) S ZTREQ="@"
134 Q
135 ;
136 ;
137STARTMSG ; Create/initialize HL message
138 ;
139 K @GBL
140 S (LA76249,LA7PIDSN)=0
141 D STARTMSG^LA7VHLU("LA7V Order to "_SITE,.LA76249)
142 Q
143 ;
144 ;
145SENDMSG ; File HL7 message with HL and LAB packages.
146 ;
147 N LA7DATA,LA7ID
148 S LA7ID="LA7V HOST "_SITE_"-O-"_$P($G(LA7628(0)),"^")
149 ; If no message to send then quit
150 I '$D(^TMP("HLS",$J)) D Q
151 . N FDA,LA7ER
152 . I $G(LA76248) S FDA(1,62.49,LA76249_",",.5)=LA76248
153 . S FDA(1,62.49,LA76249_",",1)="O"
154 . S FDA(1,62.49,LA76249_",",2)="E"
155 . S FDA(1,62.49,LA76249_",",5)=LA7ID
156 . D FILE^DIE("","FDA(1)","LA7ER(1)")
157 . D CLEAN^DILF
158 . L -^LAHM(62.49,LA76249)
159 ;
160 D GEN^LA7VHLU
161 S LA7DATA="SM06"_"^"_$$NOW^XLFDT
162 D SEUP^LA7SMU($P(LA7628(0),"^"),"1",LA7DATA)
163 D UPDT6249
164 ; Unlock entry
165 L -^LAHM(62.49,LA76249)
166 Q
167 ;
168 ;
169UPDT6249 ; update entry in 62.49
170 ;
171 N FDA,LA7ER
172 ;
173 I $G(LA76248) S FDA(1,62.49,LA76249_",",.5)=LA76248
174 S FDA(1,62.49,LA76249_",",1)="O"
175 I $P(^LAHM(62.49,LA76249,0),"^",3)'="E" D
176 . I $G(HL("APAT"))="AL" S FDA(1,62.49,LA76249_",",2)="A"
177 . E S FDA(1,62.49,LA76249_",",2)="X"
178 . I $G(LA7ERR) S FDA(1,62.49,LA76249_",",2)="E"
179 S FDA(1,62.49,LA76249_",",5)=LA7ID
180 I $G(HL("SAN"))'="" S FDA(1,62.49,LA76249_",",102)=HL("SAN")
181 I $G(HL("SAF"))'="" S FDA(1,62.49,LA76249_",",103)=HL("SAF")
182 I $G(HL("MTN"))'="" S FDA(1,62.49,LA76249_",",108)=HL("MTN")
183 I $G(HL("PID"))'="" S FDA(1,62.49,LA76249_",",110)=HL("PID")
184 I $G(HL("VER"))'="" S FDA(1,62.49,LA76249_",",111)=HL("VER")
185 I $P($G(LA7MID),"^")'="" S FDA(1,62.49,LA76249_",",109)=$P(LA7MID,"^")
186 I $P($G(LA7MID),"^",2) D
187 . S FDA(1,62.49,LA76249_",",160)=$P(LA7MID,"^",2)
188 . S FDA(1,62.49,LA76249_",",161)=$P(LA7MID,"^",3)
189 D FILE^DIE("","FDA(1)","LA7ER(1)")
190 D CLEAN^DILF
191 Q
192 ;
193 ;
194PID ; Patient identification
195 S LRDPF=$P(^LR(LRDFN,0),"^",2),DFN=$P(^(0),"^",3)
196 D DEM^LRX
197 D PID^LA7VPID(LRDFN,"",.LA7PID,.LA7PIDSN,.HL,"")
198 ; DoD/CHCS facilities only use 1st repetition of PID-3.
199 I LA7NVAF=1 D
200 . S X=$P(LA7PID(0),LA7FS,4),X=$P(X,$E(LA7ECH,2))
201 . S $P(LA7PID(0),LA7FS,4)=X
202 D FILESEG^LA7VHLU(GBL,.LA7PID)
203 D FILE6249^LA7VHLU(LA76249,.LA7PID)
204 Q
205 ;
206 ;
207PV1 ; Location information
208 ; DoD/CHCS facilities do not use PV1 segment
209 I LA7NVAF=1 Q
210 ;
211 D PV1^LA7VPID(LRDFN,.LA7PV1,LA7FS,LA7ECH)
212 D FILESEG^LA7VHLU(GBL,.LA7PV1)
213 D FILE6249^LA7VHLU(LA76249,.LA7PV1)
214 Q
215 ;
216 ;
217ORC ;Order Control
218 ;
219 N ORC,LA7DATA,LA7DUR,LA7DURU,LA76205,LA762801,LA7X
220 ;
221 S ORC(0)="ORC"
222 S ORC(1)=$$ORC1^LA7VORC("NW")
223 ;
224 ; Place order number - accession UID
225 S ORC(2)=$$ORC2^LA7VORC($P(LA76802(.3),"^"),LA7FS,LA7ECH)
226 ;
227 ; Placer group number - shipping manifest invoice #
228 S ORC(4)=$$ORC4^LA7VORC($P(LA7628(0),"^"),LA7FS,LA7ECH)
229 ;
230 ; Quantity/Timing
231 S (LA76205,LA7DUR,LA7DURU)=""
232 S LA762801=0
233 F S LA762801=$O(^TMP("LA7628",$J,LRDFN,LA7UID,LA762801)) Q:'LA762801 D
234 . N I,LA760
235 . ; Test duration
236 . F I=0,2 S LA762801(I)=$G(^LAHM(62.8,LA7628,10,LA762801,I))
237 . I $P(LA762801(2),"^",4) D
238 . . S LA7DUR=$P(LA762801(2),"^",6) ; collection duration
239 . . S LA7DURU=$P(LA762801(2),"^",7) ; duration units
240 . ; Test urgency - find highest urgency on accession
241 . S LA760=+$P(LA762801(0),"^",2)
242 . S X=+$$GET1^DIQ(68.04,LA760_","_LRAN_","_LRAD_","_LRAA_",",1,"I")
243 . I 'LA76205 S LA76205=X
244 . I LA76205,X<LA76205 S LA76205=X
245 S ORC(7)=$$ORC7^LA7VORC(LA7DUR,LA7DURU,LA76205,LA7FS,LA7ECH)
246 ;
247 ; Order Date/Time - if no order date/time then try draw time
248 I $P(LA76802(0),"^",4) S ORC(9)=$$ORC9^LA7VORC($P(LA76802(0),"^",4))
249 I '$P(LA76802(0),"^",4),$P(LA76802(3),"^") S ORC(9)=$$ORC9^LA7VORC($P(LA76802(3),"^"))
250 ;
251 ; Ordering provider
252 S LA7X=$$FNDOLOC^LA7VHLU2(LA7UID)
253 S ORC(12)=$$ORC12^LA7VORC($P(LA76802(0),"^",8),$P(LA7X,"^",3),LA7FS,LA7ECH)
254 ;
255 ; Entering organization - VA facility
256 S ORC(17)=$$ORC17^LA7VORC($P($G(LA7629(0)),U,2),LA7FS,LA7ECH)
257 ;
258 D BUILDSEG^LA7VHLU(.ORC,.LA7DATA,LA7FS)
259 D FILESEG^LA7VHLU(GBL,.LA7DATA)
260 D FILE6249^LA7VHLU(LA76249,.LA7DATA)
261 Q
262 ;
263BLG ; Billing segment
264 ;
265 N LA7BLG
266 ;
267 I $P(LA7629(0),U,13)="" Q
268 S LA7BLG(0)=$$BLG^LA7VHLU($P(LA7629(0),"^",13),"CO",LA7FS,LA7ECH)
269 D FILESEG^LA7VHLU(GBL,.LA7BLG)
270 D FILE6249^LA7VHLU(LA76249,.LA7BLG)
271 Q
Note: See TracBrowser for help on using the repository browser.