source: ccr/trunk/p/GPLVITAL.m@ 272

Last change on this file since 272 was 187, checked in by George Lilly, 16 years ago

rewrote Date sort routine to fix Vitals bug. debugging meds.

File size: 10.3 KB
Line 
1GPLVITAL ; CCDCCR/CJE - CCR/CCD PROCESSING FOR VITALS ; 07/16/08
2 ;;0.1;CCDCCR;;JUL 16,2008;
3 ;Copyright 2008 WorldVistA. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
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 along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "NO ENTRY FROM TOP",!
21 Q
22 ;
23EXTRACT(VITXML,DFN,VITOUTXML) ; EXTRACT VITALS INTO PROVIDED XML TEMPLATE
24 ;
25 ; VITXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
26 ; IVITXML CONTAINS ONLY THE VITALS SECTION OF THE OVERALL TEMPLATE
27 ;
28 N VITRSLT,J,K,VITPTMP,X,VITVMAP,TBUF,VORDR
29 D VITALS^ORQQVI(.VITRSLT,DFN,"","")
30 I '$D(VITRSLT(1)) S @VITOUTXML@(0)=0 Q ; RETURN NOT FOUND AND QUIT
31 I $P(VITRSLT(1),U,2)="No vitals found." D Q ; NULL RESULT FROM RPC
32 . I DEBUG W "NO VITALS FOUND FROM VITALS RPC",!
33 . S @VITOUTXML@(0)=0
34 I $P(VITRSLT(1),U,2)="No vitals found." Q ; QUIT
35 ; ZWR RPCRSLT
36 S VITTVMAP=$NA(^TMP("GPLCCR",$J,"VITALS"))
37 S VITTARYTMP=$NA(^TMP("GPLCCR",$J,"VITALARYTMP"))
38 K @VITTVMAP,@VITTARYTMP ; KILL OLD ARRAY VALUES
39 N VSORT,VDATES,VCNT ; ARRAY FOR DATE SORTED VITALS INDEX
40 D VITDATES(.VDATES) ; PULL OUT THE DATES INTO AN ARRAY
41 ; I DEBUG ZWR VDATES ;DEBUG
42 S VCNT=$$SORTDT^CCRUTIL(.VSORT,.VDATES,-1) ; PUT VITALS IN REVERSE
43 ; DATE ORDER AND COUNT THEM. VSORT CONTAINS INDIRECT INDEXES ONLY
44 S @VITTVMAP@(0)=VCNT ; SAVE NUMBER OF VITALS
45 F J=1:1:VCNT D ; FOR EACH VITAL IN THE LIST
46 . I $D(VITRSLT(VSORT(J))) D
47 . . S VITVMAP=$NA(@VITTVMAP@(J))
48 . . K @VITVMAP
49 . . I DEBUG W "VMAP= ",VITVMAP,!
50 . . S VITPTMP=VITRSLT(VSORT(J)) ; DATE SORTED VITAL FROM RETURN ARRAY
51 . . I DEBUG W "VITAL ",VSORT(J),!
52 . . I DEBUG W VITRSLT(VSORT(J))," ",$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT"),!
53 . . I DEBUG W $P(VITPTMP,U,4),!
54 . . S @VITVMAP@("VITALSIGNSDATAOBJECTID")="VITAL"_J ; UNIQUE OBJID
55 . . I $P(VITPTMP,U,2)="HT" D
56 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
57 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
58 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="HEIGHT"
59 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
60 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
61 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
62 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="HEIGHT"
63 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="248327008"
64 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
65 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
66 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
67 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
68 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")="in"
69 . . E I $P(VITPTMP,U,2)="WT" D
70 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
71 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
72 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="WEIGHT"
73 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
74 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
75 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
76 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="WEIGHT"
77 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="107647005"
78 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
79 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
80 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
81 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
82 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")="lbs"
83 . . E I $P(VITPTMP,U,2)="BP" D
84 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
85 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
86 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="BLOOD PRESSURE"
87 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
88 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
89 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
90 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="BLOOD PRESSURE"
91 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="392570002"
92 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
93 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
94 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
95 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
96 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")=""
97 . . E I $P(VITPTMP,U,2)="T" D
98 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
99 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
100 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="TEMPERATURE"
101 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
102 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
103 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
104 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="TEMPERATURE"
105 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="309646008"
106 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
107 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
108 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
109 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
110 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")="F"
111 . . E I $P(VITPTMP,U,2)="R" D
112 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
113 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
114 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="RESPIRATION"
115 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
116 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
117 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
118 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="RESPIRATION"
119 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="366147009"
120 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
121 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
122 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
123 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
124 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")=""
125 . . E I $P(VITPTMP,U,2)="P" D
126 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
127 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
128 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="PULSE"
129 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
130 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
131 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
132 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="PULSE"
133 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="366199006"
134 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
135 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
136 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
137 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
138 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")=""
139 . . E I $P(VITPTMP,U,2)="PN" D
140 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
141 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
142 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="PAIN"
143 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
144 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
145 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="OBSERVED"
146 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="PAIN"
147 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")="22253000"
148 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")="SNOMED"
149 . . . S @VITVMAP@("VITALSIGNSCODEVERSION")=""
150 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
151 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
152 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")=""
153 . . E D
154 . . . ;W "IN VITAL: OTHER",!
155 . . . S @VITVMAP@("VITALSIGNSDATETIMETYPETEXT")="OBSERVED"
156 . . . S @VITVMAP@("VITALSIGNSEXACTDATETIME")=$$FMDTOUTC^CCRUTIL($P(VITPTMP,U,4),"DT")
157 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="OTHER VITAL"
158 . . . S @VITVMAP@("VITALSIGNSSOURCEACTORID")="ACTORSYSTEM_1"
159 . . . S @VITVMAP@("VITALSIGNSTESTOBJECTID")="VITALTEST"_J
160 . . . S @VITVMAP@("VITALSIGNSTESTTYPETEXT")="UNKNOWN"
161 . . . S @VITVMAP@("VITALSIGNSDESCRIPTIONTEXT")="OTHER"
162 . . . ;S @VITVMAP@("VITALSIGNSDESCRIPTIONCODEVALUE")=""
163 . . . ;S @VITVMAP@("VITALSIGNSDESCRIPTIONCODINGSYSTEM")=""
164 . . . ;S @VITVMAP@("VITALSIGNSCODEVERSION")=""
165 . . . S @VITVMAP@("VITALSIGNSTESTSOURCEACTORID")="ACTORPROVIDER_"_$P(^GMR(120.5,$P(VITPTMP,U,1),0),U,6)
166 . . . S @VITVMAP@("VITALSIGNSTESTRESULTVALUE")=$P(VITPTMP,U,3)
167 . . . S @VITVMAP@("VITALSIGNSTESTRESULTUNIT")="UNKNOWN"
168 . . S VITARYTMP=$NA(@VITTARYTMP@(J))
169 . . K @VITARYTMP
170 . . D MAP^GPLXPATH(VITXML,VITVMAP,VITARYTMP)
171 . . I J=1 D ; FIRST ONE IS JUST A COPY
172 . . . ; W "FIRST ONE",!
173 . . . D CP^GPLXPATH(VITARYTMP,VITOUTXML)
174 . . . I DEBUG W "VITOUTXML ",VITOUTXML,!
175 . . I J>1 D ; AFTER THE FIRST, INSERT INNER XML
176 . . . D INSINNER^GPLXPATH(VITOUTXML,VITARYTMP)
177 ; ZWR ^TMP($J,"VITALS",*)
178 ; ZWR ^TMP($J,"VITALARYTMP",*) ; SHOW THE RESULTS
179 I DEBUG D PARY^GPLXPATH(VITOUTXML)
180 N VITTMP,I
181 D MISSING^GPLXPATH(VITOUTXML,"VITTMP") ; SEARCH XML FOR MISSING VARS
182 I VITTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
183 . W "VITALS MISSING ",!
184 . F I=1:1:VITTMP(0) W VITTMP(I),!
185 Q
186 ;
187VITDATES(VDT) ; VDT IS PASSED BY REFERENCE AND WILL CONTAIN THE ARRAY
188 ; OF DATES IN THE VITALS RESULTS
189 N VDTI,VDTJ,VTDCNT
190 S VTDCNT=0 ; COUNT TO BUILD ARRAY
191 S VDTJ="" ; USED TO VISIT THE RESULTS
192 F VDTI=0:0 D Q:$O(VITRSLT(VDTJ))="" ; VISIT ALL RESULTS
193 . S VDTJ=$O(VITRSLT(VDTJ)) ; NEXT RESULT
194 . S VTDCNT=VTDCNT+1 ; INCREMENT COUNTER
195 . S VDT(VTDCNT)=$P(VITRSLT(VDTJ),U,4) ; PULL OUT THE DATE
196 S VDT(0)=VTDCNT
197 Q
198 ;
Note: See TracBrowser for help on using the repository browser.