source: WorldVistAEHR/trunk/r/ADVERSE_REACTION_TRACKING-GMRA-GMA/GMRAIAD1.m@ 1297

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

initial load of WorldVistAEHR

File size: 8.5 KB
RevLine 
[613]1GMRAIAD1 ;BPOIFO/JG - BUILD HL7 ORU^R01 MESSAGE FOR ADVERSE REACTION - PART 1 ; 18 Feb 2005 2:54 PM
2 ;;4.0;Adverse Reaction Tracking;**22,23**;Mar 29, 1996
3VALID ;;VDEF HL7 MESSAGE BUILDER
4 ; Creates HL7 V2.4 ORU^R01 message for allergy adverse reaction
5 ;
6 ; This routines uses the following IAs:
7 ; #4248 - VDEFEL calls (controlled)
8 ; #3630 - VAFCQRY calls (controlled)
9 ; #2196 - ^PS(50.416,IEN,0) (controlled)
10 ; #4571 - ERR^VDEFREQ (controlled)
11 ;
12 ; This routine is called at tag EN as a Function by VDEFREQ1
13 ;
14 ; This routine calls GMRAIAD2 for a portion of message
15 ;
16 Q
17 ;
18EN(EVIEN,KEY,VFLAG,OUT,MSHP) ;
19 ;
20 ; Inputs: EVIEN = IEN of message in file 577
21 ; KEY - IEN of file to create message from
22 ; VFLAG - "V" for VistA HL7 destination (default)
23 ; OUT - target array, passed by reference
24 ; MSHP - Piece 4 contains message subtype
25 ;
26 ; Output: Two part string with parts separated by "^"
27 ; Part 1: "LM" - output in local array passed in "OUT" parameter
28 ; "GM" - output in ^TMP("HLS",$J)
29 ; Part 2: No longer used
30 ;
31 N DFN,HLFS,HLCM,HLSC,HLRP,HLES,HLQ,ALRDATA,DTE,DTP,ADD
32 N DATA,VAL,I,S,X,Y,Z,X1,X2,HL7RC,IEN,OUTX,LIKE,LIKERSP,GMRAPID,SEQ
33 N SEPF,SEPC,SEPR,SEPE,SEPS,ARRAY,PTC,CMP,GMRAHL
34 ;
35 ; Initialize stuff
36 K ^TMP("HLS",$J) S S=0,ARRAY="OUT("_"""HLS"""_",S)",TARGET="LM^"
37 M GMRAHL=VDEFHL
38 ;
39 ; Set up HL7 delimiters
40 S HLCM=$E(GMRAHL("ECH")),HLRP=$E(GMRAHL("ECH"),2),HLSC=$E(GMRAHL("ECH"),4),HLES=$E(GMRAHL("ECH"),3)
41 S HLFS=GMRAHL("FS"),HLQ=GMRAHL("Q"),HL7RC=HLES_HLFS_HLCM_HLRP_HLSC
42 D SETDLMS^VDEFEL
43 ;
44 ; Get allergy data & patient ID
45 S ALRDATA=$G(^GMR(120.85,KEY,0))
46 I ALRDATA="" D ERR^VDEFREQ("No data in file GMR(120.85) for IEN "_KEY) S ZTSTOP=1 G EXIT
47 S DFN=$P(ALRDATA,U,2)
48 I $G(^DPT(DFN,0))="" D ERR^VDEFREQ("No data in file DPT for DFN "_DFN) S ZTSTOP=1 G EXIT
49 ;
50 ; Build segments for message in OUT, $P # = HL7 field #
51 ;
52 ; PID - Use MPI PID builder
53PID K GMRAPID S OUTX="",S=1,SEQ=""
54 D BLDPID^VAFCQRY(DFN,1,SEQ,.GMRAPID,.GMRAHL)
55 F I=2:1 Q:$G(GMRAPID(I))="" S GMRAPID(1,I-1)=GMRAPID(I) K GMRAPID(I)
56 M OUTX=GMRAPID(1) K GMRAPID D SAVE
57 ;
58 ; OBR
59OBR S S=S+1,OUTX="",$P(OUTX,HLFS)=1,$P(OUTX,HLFS,25)="F"
60 S VAL=KEY_HLCM_$P(SITEPARM,U,6)_"_120.85",$P(OUTX,HLFS,3)=VAL
61 S $P(OUTX,HLFS,4)="ADVERSE REACTION REPORT"_HLCM_HLCM_"L"
62 ;
63 ;Date/time reaction occured
64 S $P(OUTX,HLFS,7)=$$TS^VDEFEL($P(ALRDATA,U,1))
65 ;
66 ; Entering User
67 S VAL=$$XCN200^VDEFEL($P(ALRDATA,U,19)),$P(VAL,HLCM,8)="ENT",$P(OUTX,HLFS,32)=VAL
68 ;
69 ; Observer (Witness)
70 S VAL=$$XCN200^VDEFEL($P(ALRDATA,U,13)),$P(VAL,HLCM,8)="OBS"
71 ;
72 ; Reporter
73 S X=$P($G(^GMR(120.85,KEY,"RPT")),U,1)
74 S X=HLCM_$P(X,",",1)_HLCM_$P($P(X,",",2)," ",1)_HLCM_$P($P(X,",",2)," ",2)
75 S $P(X,HLCM,8)="RPT",$P(OUTX,HLFS,34)=VAL_HLRP_X
76 ;
77 ; Related Reaction
78 S X=$P(ALRDATA,U,15)_HLCM_$P($G(^GMR(120.8,$P(ALRDATA,U,15),0)),U,2)_HLCM_"L"
79 S $P(OUTX,HLFS,47)=X
80 S OUTX="OBR"_HLFS_OUTX D SAVE
81 ;
82 ; OBX 1 - Symptoms
83OBX1 S S=S+1,OUTX=1_HLFS_"CE"_HLFS_"SYMPTOM"_HLFS
84 ;
85 ; Get the reactions
86 S X=0,(Y,Z)="" F S X=$O(^GMR(120.85,KEY,2,X)) Q:X'?1N.N D
87 . S Y=^GMR(120.85,KEY,2,X,0),VAL=$P(Y,U,3)
88 . I $P(Y,U,2)'="" S Z=Z_$P(Y,U,2)_HLRP
89 . E S Z=Z_$P(^GMRD(120.83,+Y,0),U,1)_HLRP
90 S $P(OUTX,HLFS,5)=$E(Z,1,$L(Z)-1)
91 ;
92 ; Severity
93 S $P(OUTX,HLFS,8)=$$GET1^DIQ(120.85,KEY_",",14.5)
94 ;
95 ; Reaction entered by
96 S $P(OUTX,HLFS,16)=$$XCN200^VDEFEL(VAL)
97 S $P(OUTX,HLFS,11)="F"
98 S OUTX="OBX"_HLFS_OUTX D SAVE
99 ;
100 ; RXA/RXE/RXR/OBX Suspected Agent Group
101 G OBX2:$G(^GMR(120.85,KEY,3,1,0))="" S IEN=0
102RXAGRP1 F S IEN=$O(^GMR(120.85,KEY,3,IEN)) Q:IEN'?1N.N D
103 . S S=S+1,OUTX="0"_HLFS_"1" K ALRDATA M ALRDATA=^GMR(120.85,KEY,3,IEN)
104 . ;
105 . ; RXA
106 . ; Start & Stop dates
107 . S VAL=$P($G(ALRDATA(1)),U) I VAL S $P(OUTX,HLFS,3)=$$TS^VDEFEL(VAL)
108 . S VAL=$P($G(ALRDATA(1)),U,2) I VAL S $P(OUTX,HLFS,4)=$$TS^VDEFEL(VAL)
109 . ;
110 . ; Suspected agent & daily dose
111 . S VAL=$P(ALRDATA(0),U),$P(OUTX,HLFS,5)=$$HL7RC(VAL)
112 . S VAL=$P(ALRDATA(0),U,2),$P(OUTX,HLFS,6)=$$HL7RC(VAL)
113 . ;
114 . ; Lot number, Exp. Date, Manufacturer
115 . S VAL=$P(ALRDATA(0),U,8) S:VAL $P(OUTX,HLFS,15)=$$HL7RC(VAL)
116 . S VAL=$P($G(ALRDATA(1)),U,3) I VAL S $P(OUTX,HLFS,16)=$$TS^VDEFEL(VAL)
117 . S VAL=$P(ALRDATA(0),U,7) S:VAL $P(OUTX,HLFS,17)=$$HL7RC(VAL)
118 . ;
119 . ; Indication for use
120 . S VAL=$P(ALRDATA(0),U,4) S:VAL $P(OUTX,HLFS,19)=$$HL7RC(VAL)
121 . ;
122 . ; Set into array
123 . S OUTX="RXA"_HLFS_OUTX D SAVE
124 . ;
125 . ; RXE
126 . S S=S+1,OUTX="",CMP=""
127 . ;
128 . ; Previous doses
129 . S $P(CMP,HLCM,1)=$$HL7RC($P(ALRDATA(0),U,9))
130 . ;
131 . ; Duration
132 . S X1=$P($G(ALRDATA(1)),U,2),X2=$P($G(ALRDATA(1)),U) D ^%DTC S:X="" X=0 S $P(CMP,HLCM,3)=X
133 . ;
134 . ; Last date given
135 . S VAL=$P(ALRDATA(0),U,10) I VAL S $P(CMP,HLCM,5)=$$TS^VDEFEL(VAL)
136 . S $P(OUTX,HLFS)=CMP,CMP=""
137 . ;
138 . ; Give codes
139 . S VAL=$P(ALRDATA(0),U),$P(CMP,HLCM,1)=$$HL7RC(VAL)
140 . S $P(CMP,HLCM,4)=$P($G(ALRDATA(1)),U,4),$P(CMP,HLCM,6)="NDC"
141 . S $P(OUTX,HLFS,2)=CMP,$P(OUTX,HLFS,3)=0
142 . ;
143 . ; SIG
144 . S $P(OUTX,HLFS,7)=$$HL7RC($P($G(ALRDATA(1)),U,5))
145 . ;
146 . ; Daily dose
147 . S $P(OUTX,HLFS,19)=$$HL7RC($P(ALRDATA(0),U,2))
148 . S OUTX="RXE"_HLFS_OUTX D SAVE
149 . ;
150 . ; RXR
151 . ; Route of administration
152 . S OUTX="",VAL=$P(ALRDATA(0),U,3) S:VAL="" VAL="UNKNOWN" S $P(OUTX,HLFS,1)=$$HL7RC(VAL)
153 . S S=S+1,OUTX="RXR"_HLFS_OUTX D SAVE
154 . ;
155 . ; OBX - LIKES
156 . S LIKERSP=$G(ALRDATA("LIKE")) I LIKERSP'="" F LIKE=1:1:6 D
157 . . S S=S+1,OUTX=1_HLFS_"CE"_HLFS
158 . . S VAL="LIKE "_LIKE_HLCM_$P($T(LIKEQ+(LIKE)),";",3),$P(OUTX,HLFS,3)=VAL
159 . . S X=$P(LIKERSP,U,LIKE),X=$S(X="y":"Y",X="n":"N",1:""),VAL=X_HLCM
160 . . S X=$S(X="Y":"YES",X="N":"NO",1:"")
161 . . S VAL=VAL_X_HLCM_"HL70136",$P(OUTX,HLFS,5)=VAL,$P(OUTX,HLFS,11)="F"
162 . . S OUTX="OBX"_HLFS_OUTX D SAVE
163 . . ;
164 . ; Likelihood
165 . S S=S+1,OUTX=1_HLFS_"CE"_HLFS_"LIKELIHOOD"
166 . S VAL=$P(LIKERSP,U,7) S:VAL="" VAL=5
167 . S X=VAL_HLCM_$P("REMOTE,POSSIBLE,PROBABLE,HIGHLY PROBABLE, ",",",VAL)
168 . S $P(OUTX,HLFS,5)=X,$P(OUTX,HLFS,11)="F"
169 . S OUTX="OBX"_HLFS_OUTX D SAVE
170 ;
171 ; OBX2 - Lab Results
172OBX2 S X=$G(^GMR(120.85,KEY,4,0)) G CALL:X=""
173 S IEN=0 F S IEN=$O(^GMR(120.85,KEY,4,IEN)) Q:IEN'?1N.N D
174 . S S=S+1,OUTX=1_HLFS_"CE"_HLFS
175 . S X=^GMR(120.85,KEY,4,IEN,0),$P(OUTX,HLFS,3)=$$HL7RC($P(X,U,1))
176 . S $P(OUTX,HLFS,5)=$$HL7RC($P(X,U,2)),$P(OUTX,HLFS,11)="F"
177 . S $P(OUTX,HLFS,14)=$$TS^VDEFEL($P(X,U,3))
178 . S OUTX="OBX"_HLFS_OUTX D SAVE
179 ;
180 ; Call GMRAIAD2
181CALL D ENTRY^GMRAIAD2
182 ;
183 ; OBX10 - IND/NDA Info
184OBX10 S X=$G(^GMR(120.85,KEY,"MFR2")) G RXAGRP2:X=""
185 S S=S+1,OUTX=1_HLFS_"ST",$P(OUTX,HLFS,5)=$P(X,U,1)
186 S OUTX="OBX"_HLFS_OUTX D SAVE
187 ;
188 ; RXA/RXE Concommitant Drugs Group
189RXAGRP2 S X=$G(^GMR(120.85,KEY,13,0)) G EXIT:X=""
190 S IEN=0 F S IEN=$O(^GMR(120.85,KEY,13,IEN)) Q:IEN'?1N.N D
191 . ;
192 . ; RXA
193 . S X=^GMR(120.85,KEY,13,IEN,0),S=S+1,OUTX=0_HLFS_1
194 . ;
195 . ; Start Date, Stop Date
196 . I $P(X,U,2)'="" S $P(OUTX,HLFS,3)=$$TS^VDEFEL($P(X,U,2))
197 . I $P(X,U,3)'="" S $P(OUTX,HLFS,4)=$$TS^VDEFEL($P(X,U,3))
198 . ;
199 . ; Drug Name
200 . S $P(OUTX,HLFS,5)=$$HL7RC($P(X,U,1)),$P(OUTX,HLFS,6)=0
201 . S OUTX="RXA"_HLFS_OUTX D SAVE
202 . ;
203 . ; RXE
204 . ; Stop Date
205 . S S=S+1,OUTX="",VAL=$$TS^VDEFEL($P(X,U,3))
206 . S Y="",$P(Y,HLCM,5)=VAL,$P(OUTX,HLFS,1)=Y
207 . ;
208 . ; Drug Name
209 . S $P(OUTX,HLFS,2)=$$HL7RC($P(X,U,1)),$P(OUTX,HLFS,3)=0
210 . ;
211 . ; SIG if known
212 . S $P(OUTX,HLFS,5)="UNK",$P(OUTX,HLFS,7)=$$HL7RC($P(X,U,5))
213 . S OUTX="RXE"_HLFS_OUTX D SAVE
214 ;
215 ; Done building segments
216EXIT Q TARGET
217 ;
218 ;
219 ; Place current string into message array
220 ; Turn string into array if length >245.
221 ; Move local array to global if needed
222SAVE N I
223 I $P(OUTX,HLFS)'="PID",$L(OUTX)>245 D
224 . K ADD S ADD=$E(OUTX,1,245),OUTX=$E(OUTX,246,$L(OUTX))
225 . F I=1:1 S ADD(I)=$E(OUTX,1,245),OUTX=$E(OUTX,246,$L(OUTX)) Q:OUTX=""
226 . K OUTX M OUTX=ADD
227 M @ARRAY=OUTX
228 ;
229 ; Move local array to global if it's getting big.
230 I $P(TARGET,U)="LM",$S<16000 D
231 . K ^TMP("HLS",$J) M ^TMP("HLS",$J)=OUT("HLS") K OUT("HLS")
232 . S $P(TARGET,U)="GM",ARRAY="^TMP("_"""HLS"""_",$J,S)"
233 K OUTX,ADD
234 Q
235 ;
236 ; Replace any HL7 coding chars. in strings with HL7 escape sequence
237 ; Input: X = data string
238HL7RC(X) N OCHR,RCHR,RCHRI,TYPE,I F TYPE="E","F","C","R","S" D
239 . S RCHRI=$S(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
240 . S OCHR=$E(HL7RC,RCHRI),RCHR=$E("EFSRT",RCHRI)
241 . Q:'$F(X,OCHR)
242 . F I=1:1 Q:$E(X,I)="" I $E(X,I)=OCHR S X=$E(X,1,I-1)_HLES_RCHR_HLES_$E(X,I+1,999),I=I+2
243 Q X
244 ;
245LIKEQ ; LIKE set
246 ;;1. Reaction normally occurs with this reactant?
247 ;;2. Administration of the reactant was stopped?
248 ;;3. Reaction stopped when the administration of the reactant was terminated?
249 ;;4. Reactant was re-administered?
250 ;;5. Reaction could be due to the patient current clinical condition?
251 ;;6. Reaction reappeared after the reactant was re-administered?
Note: See TracBrowser for help on using the repository browser.