source: WorldVistAEHR/trunk/r/GEN_MED_OTHER-GMV/GMVVDEF1.m@ 1311

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

initial load of WorldVistAEHR

File size: 8.0 KB
Line 
1GMVVDEF1 ;BPOIFO/JG,HIOFO/FT - BUILD HL7 ORU^R01 MESSAGE FOR VITALS ; 20 Sep 2005 4:36 PM
2 ;;5.0;GEN. MED. REC. - VITALS;**5,8,12,17,11**;Oct 31, 2002
3 ;11/30/2005 KAM/BAY Remedy Calls 121661 and 122742 changes for HL7 message
4VALID ;;VDEF HL7 MESSAGE BUILDER
5 ; Creates HL7 V2.4 ORU^R01 message for vitals
6 ;
7 ; This routine uses the following IAs:
8 ; #93 - FILE 44 references (controlled)
9 ; #557 - FILE 40.7 references (controlled)
10 ; #2432 - FILE 44 references (controlled)
11 ; #3630 - VAFCQRY calls (controlled)
12 ; #4248 - VDEFEL calls (controlled)
13 ; #4571 - VDEFREQ calls (controlled)
14 ; #10035 - DPT( references (supported)
15 ; #10040 - FILE 44 references (supported)
16 ; #10112 - VASITE calls (supported)
17 ;
18 ; This routine is called at tag EN as a Function by VDEFREQ1
19 ;
20 Q
21 ;
22EN(EVIEN,KEY,VFLAG,OUT,MSHP) ; Entry point
23 ;
24 ; Inputs: EVIEN = IEN of VDEF Event in file 577
25 ; KEY - IEN of file to create message from
26 ; VFLAG - "V" for VistA HL7 destination (default)
27 ; OUT - target array, passed by reference
28 ; MSHP - Piece 4 contains message subtype
29 ;
30 ; Output: Two part string with parts separated by "^"
31 ; Part 1: "LM" - output in local array passed in "OUT" parameter
32 ; "GM" - output in ^TMP("HLS",$J)
33 ; Part 2: No longer used
34 ;
35 N DFN,HLFS,HLCM,HLSC,HLRP,HLES,HLQ,VTLDAT,UM,VTLTYP,DTE,DTP
36 N VTLERR,VAL,I,S,X,XX,Y,QUALS,HL7RC,PIDSEG,IEN1,SEQ,STOPCD,EIEVUID
37 N SEPF,SEPC,SEPR,SEPE,SEPS,VTLNAM,ARRAY,O2SUP,OUTX,ADD,VTLVUID
38 ;
39 ; Initialize stuff
40 K ^TMP("HLS",$J) S S=0,ARRAY="OUT("_"""HLS"""_",S)",TARGET="LM^"
41 ;
42 ; Set up HL7 delimiters
43 S HLCM=$E(VDEFHL("ECH")),HLRP=$E(VDEFHL("ECH"),2),HLSC=$E(VDEFHL("ECH"),4),HLES=$E(VDEFHL("ECH"),3)
44 S HLFS=VDEFHL("FS"),HLQ=VDEFHL("Q"),HL7RC=HLES_HLFS_HLCM_HLRP_HLSC
45 D SETDLMS^VDEFEL
46 ;
47 ; Get the vitals measurement record & patient ID
48 S VTLDAT=$$EN^GMVHDR(KEY)
49 I 'VTLDAT D ERR^VDEFREQ("Invalid data in file GMR(120.5) for IEN "_KEY) S ZTSTOP=1 G EXIT
50 S DFN=$P(VTLDAT,U,2),VTLTYP=$P(VTLDAT,U,7)
51 S VTLVUID=$$GET^GMVUID(120.51,.01,+VTLTYP_",") ;vital type vuid
52 S O2SUP=$P(VTLDAT,U,10),VTLERR=$P(VTLDAT,U,11)
53 S X=$P(VTLDAT,U,5) I +X'=X!(X<0) S $P(VTLDAT,U,5)=""
54 S STOPCD=""
55 I $P(VTLDAT,U,5)'="" D
56 . S STOPCD=$P($G(^SC($P(VTLDAT,U,5),0)),U,7) Q:STOPCD=""
57 . S STOPCD=$G(^DIC(40.7,STOPCD,0))
58 . S STOPCD=$$HL7RC($P(STOPCD,U,2))_";"_$$HL7RC($P(STOPCD,U))
59 ;
60 ; Build segments for message in OUTX, $P # = HL7 field #
61 ;
62 ; PID - Use MPI PID builder
63PID K PIDSEG S OUTX="",S=1,SEQ=""
64 I $G(^DPT(DFN,0))="" D ERR^VDEFREQ("No entry in file DPT for DFN "_DFN) S ZTSTOP=1 G EXIT
65 D BLDPID^VAFCQRY(DFN,1,SEQ,.PIDSEG,.VDEFHL)
66 F I=2:1 Q:$G(PIDSEG(I))="" S PIDSEG(1,I-1)=PIDSEG(I) K PIDSEG(I)
67 M OUTX=PIDSEG(1) K PIDSEG D SAVE
68 ;
69 ; ORC
70ORC S S=S+1,OUTX="RE"
71 ;
72 ; Filler ID
73 S X=KEY_HLCM_$$HL7RC($P(SITEPARM,U,6))_"_120.5",$P(OUTX,HLFS,3)=X
74 ;
75 ; Enterer's location
76 I $P(VTLDAT,U,5)'="" D
77 . S X=$G(^SC($P(VTLDAT,U,5),0)),VAL=$$HL7RC($P(X,U,2))_HLCM_$P(VTLDAT,U,5)
78 . S $P(VAL,HLCM,9)=$$HL7RC($P(X,U)),$P(OUTX,HLFS,13)=VAL
79 . I +$P(X,U,15) S X=$$SITE^VASITE($P(VTLDAT,U),$P(X,U,15)) S:X=-1 X=""
80 . E S X=""
81 . S VAL=$$HL7RC($P(X,U,3))_HLCM_$$HL7RC($P(X,U,2))_HLCM_"L",$P(OUTX,HLFS,17)=VAL
82 ; Parent Facility (Added 04/17/2006)
83 S $P(OUTX,HLFS,21)=$P($$SITE^VASITE(),"^",2)
84 ;
85 S VAL=$P(OUTX,HLFS,3),OUTX="ORC"_HLFS_OUTX D SAVE
86 ;
87 ; OBR
88OBR S S=S+1,OUTX="",VTLNAM=$$HL7RC($P(^GMRD(120.51,VTLTYP,0),U))
89 S X=VTLVUID_HLCM_VTLNAM_HLCM_$$HL7RC("99VA120.51")
90 ;
91 ; Add filler ID from ORC-3 & Procedure name
92 S $P(OUTX,HLFS,3)=VAL,$P(OUTX,HLFS,4)=X
93 ;
94 ; Dates/times vital taken & entered
95 S DTP=$$HL7RC($$TS^VDEFEL($P(VTLDAT,U))),$P(OUTX,HLFS,7)=DTP
96 S DTE=$$HL7RC($$TS^VDEFEL($P(VTLDAT,U,4))),$P(OUTX,HLFS,8)=DTE
97 ;
98 ; Use date/time vital entered for results reported
99 S $P(OUTX,HLFS,22)=DTE
100 ;
101 ; Set result status to Final or Error if entered in error
102 S $P(OUTX,HLFS,25)=$E("FE",VTLERR'=""+1)
103 ;
104 ; Technician name
105 S XX=$$XCN200^VDEFEL($P(VTLDAT,U,6))
106 F II=2:1:7 S $P(XX,SEPC,II)=$$HL7RC($P(XX,SEPC,II))
107 S $P(OUTX,HLFS,34)=XX
108 S OUTX="OBR"_HLFS_OUTX D SAVE
109 ;
110 ; OBX 1 - Vital name
111OBX1 S S=S+1,OUTX=HLFS_"ST"
112 ;
113 ; Observation ID - Vital name
114 S X=VTLVUID_HLCM_VTLNAM_HLCM_$$HL7RC("99VA120.51"),$P(OUTX,HLFS,3)=X
115 ;
116 ; Unit of measure
117 ; If vital not performed, set units to null
118 S UM=$$HL7RC($P(VTLDAT,U,9)) S:$F("Pass Refused Unavailable",$P(VTLDAT,U,8))>0 UM=""
119 S UM=UM_HLCM_UM_HLCM_"L"
120 ;
121 ; Set sub-id if O2 supplements to follow
122 S:O2SUP'="" $P(OUTX,HLFS,4)=1
123 S $P(OUTX,HLFS,5)=$$HL7RC($P(VTLDAT,U,8)),$P(OUTX,HLFS,6)=UM
124 ;
125 ; Set result status to Final or Wrong if errors entered
126 S $P(OUTX,HLFS,11)=$E("FW",VTLERR'=""+1)
127 S XX=$$XCN200^VDEFEL($P(VTLDAT,U,6))
128 F II=2:1:7 S $P(XX,SEPC,II)=$$HL7RC($P(XX,SEPC,II))
129 S $P(OUTX,HLFS,16)=XX
130 S OUTX="OBX"_HLFS_OUTX D SAVE
131 ;
132 ; OBX2 - O2 Supplement
133OBX2 G QUALS:O2SUP="" S (VAL,UM)=""
134 S S=S+1,OUTX=HLFS_"ST"_HLFS_"O2 Supplement" D
135 . I O2SUP["%",O2SUP'["l/min" S VAL=+O2SUP,UM="%" Q
136 . I O2SUP'["%",O2SUP["l/min" S VAL=+O2SUP,UM="l/min"
137 . I O2SUP["%",O2SUP["l/min" S $P(VAL,U)=$P(O2SUP," "),$P(UM,U)="l/min",$P(VAL,U,2)=+$P(O2SUP," ",3),$P(UM,U,2)="%"
138 S X=$P(UM,U),X=X_HLCM_X_HLCM_"L",$P(UM,U)=X
139 I $P(UM,U,2)'="" S X=$P(UM,U,2),X=X_HLCM_X_HLCM_"L",$P(UM,U,2)=X
140 S $P(OUTX,HLFS,4)=2,$P(OUTX,HLFS,5)=$P(VAL,U,1),$P(OUTX,HLFS,6)=$P(UM,U)
141 ;
142 ; Set result status to Final or Wrong if errors entered
143 S $P(OUTX,HLFS,11)=$E("FW",VTLERR'=""+1)
144 S OUTX="OBX"_HLFS_OUTX,X=OUTX D SAVE
145 ; If more than one O2 supplement, add another OBX
146 ; Field offset in OUT is now +1 because OBX has been added
147 S OUTX=X I $P(VAL,U,2)'="" D
148 . S S=S+1,$P(OUTX,HLFS,5)=3,$P(OUTX,HLFS,6)=$P(VAL,U,2),$P(OUTX,HLFS,7)=$P(UM,U,2)
149 . D SAVE
150 ;
151 ; Qualifiers
152QUALS S QUALS="",X=$O(^GMR(120.5,KEY,5,0)) G ERRS:X=""
153 S S=S+1,OUTX=HLFS_"CE"_HLFS_"Qualifiers"_HLFS_HLFS
154 ;
155 ; Get qualifiers
156 S IEN1=0 F S IEN1=$O(^GMR(120.5,KEY,5,IEN1)) Q:'+IEN1 D
157 . S X=^GMR(120.5,KEY,5,IEN1,0),VAL=$$HL7RC($P(^GMRD(120.52,X,0),U))
158 . S X=$$GET^GMVUID(120.52,.01,+X_",") ;qualifier vuid
159 . S VAL=X_HLCM_VAL_HLCM_$$HL7RC("99VA120.52"),QUALS=QUALS_VAL_HLRP
160 ;
161 ; Set result
162 S $P(OUTX,HLFS,5)=$E(QUALS,1,$L(QUALS)-1)
163 ;
164 ; Set result status to Final or Wrong if errors entered
165 S $P(OUTX,HLFS,11)=$E("FW",VTLERR'=""+1)
166 S OUTX="OBX"_HLFS_OUTX D SAVE
167 ;
168 ; Entered in Error
169ERRS G ZSC:VTLERR="" S S=S+1,OUTX=HLFS_"CE"_HLFS_"Error Reasons"_HLFS_HLFS
170 ;
171 ; Error data reason(s)
172 S X=$P(VTLDAT,U,13),VAL=""
173 F I=1:1:$L(X,"~") D
174 .S Y=$P(X,"~",I)
175 .S EIEVUID=$$GET^GMVUID(120.506,.01,$P(Y,"-",1)) ;error vuid
176 .S VAL=VAL_$$HL7RC(EIEVUID)_HLCM_$$HL7RC($P(Y,"-",2))_HLCM_$$HL7RC("99VA8985.1")_HLRP
177 S VAL=$E(VAL,1,$L(VAL)-1),$P(OUTX,HLFS,5)=VAL
178 ;
179 ; Set result status to Final or Wrong if errors entered
180 S $P(OUTX,HLFS,11)=$E("FW",VTLERR'=""+1)
181 ;
182 ; Entered in error by technician
183 S XX=$$XCN200^VDEFEL($P(VTLDAT,U,12))
184 F II=2:1:7 S $P(XX,SEPC,II)=$$HL7RC($P(XX,SEPC,II))
185 S $P(OUTX,HLFS,16)=XX
186 S OUTX="OBX"_HLFS_OUTX D SAVE
187 ;
188 ; Stop Code & Name
189ZSC G EXIT:STOPCD=""
190 S S=S+1,OUTX=HLFS_$P(STOPCD,";")_HLFS_$P(STOPCD,";",2)
191 S OUTX="ZSC"_HLFS_OUTX D SAVE
192 ;
193 ; Done building segments
194EXIT Q TARGET
195 ;
196 ;
197 ; Place current string into message array.
198 ; Turn string into array if length >245.
199 ; Move local array to global if needed.
200SAVE N I
201 I $P(OUTX,HLFS)'="PID",$L(OUTX)>245 D
202 . K ADD S ADD=$E(OUTX,1,245),OUTX=$E(OUTX,246,$L(OUTX))
203 . F I=1:1 S ADD(I)=$E(OUTX,1,245),OUTX=$E(OUTX,246,$L(OUTX)) Q:OUTX=""
204 . K OUTX M OUTX=ADD
205 M @ARRAY=OUTX
206 ;
207 ; Move local array to global if it's getting big.
208 I $P(TARGET,U)="LM",$S<16000 D
209 . K ^TMP("HLS",$J) M ^TMP("HLS",$J)=OUT("HLS") K OUT("HLS")
210 . S $P(TARGET,U)="GM",ARRAY="^TMP("_"""HLS"""_",$J,S)"
211 K OUTX,ADD
212 Q
213 ;
214 ; Replace any HL7 coding chars. in strings with HL7 escape sequence
215 ; Input: X = data string
216HL7RC(X) N OCHR,RCHR,RCHRI,TYPE,I F TYPE="E","F","C","R","S" D
217 . S RCHRI=$S(TYPE="E":1,TYPE="F":2,TYPE="C":3,TYPE="R":4,TYPE="S":5)
218 . S OCHR=$E(HL7RC,RCHRI),RCHR=$E("EFSRT",RCHRI)
219 . Q:'$F(X,OCHR)
220 . 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
221 Q X
Note: See TracBrowser for help on using the repository browser.