source: smart/trunk/p/C0SLAB.m@ 1571

Last change on this file since 1571 was 1571, checked in by George Lilly, 12 years ago

fix for lab units not found and C0STBL analysis routines

File size: 10.8 KB
Line 
1C0SLAB ; GPL - Smart Lab Processing ;4/15/12 17:05
2 ;;1.0;VISTA SMART CONTAINER;;Sep 26, 2012;Build 4
3 ;Copyright 2012 George Lilly. 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 Q
21 ;
22 ; sample VistA NHIN lab result
23 ;
24 ;^TMP("C0STBL",32,"lab",8,"collected@value")=3110626.16
25 ;^TMP("C0STBL",32,"lab",8,"comment")="Report Released Date/Time: Jun 26, 2011@19:00"
26 ;^TMP("C0STBL",32,"lab",8,"comment@xml:space")="preserve"
27 ;^TMP("C0STBL",32,"lab",8,"facility@code")=100
28 ;^TMP("C0STBL",32,"lab",8,"facility@name")="VOE OFFICE INSTITUTION"
29 ;^TMP("C0STBL",32,"lab",8,"groupName@value")="CH 0626 47"
30 ;^TMP("C0STBL",32,"lab",8,"high@value")=" 101"
31 ;^TMP("C0STBL",32,"lab",8,"id@value")="CH;6889372.84;67003"
32 ;^TMP("C0STBL",32,"lab",8,"interpretation@value")="H"
33 ;^TMP("C0STBL",32,"lab",8,"labOrderID@value")=336
34 ;^TMP("C0STBL",32,"lab",8,"localName@value")="FBLDGLU"
35 ;^TMP("C0STBL",32,"lab",8,"loinc@value")="14771-0"
36 ;^TMP("C0STBL",32,"lab",8,"low@value")="69 "
37 ;^TMP("C0STBL",32,"lab",8,"orderID@value")=807
38 ;^TMP("C0STBL",32,"lab",8,"result@value")=178
39 ;^TMP("C0STBL",32,"lab",8,"resulted@value")=3110626.190006
40 ;^TMP("C0STBL",32,"lab",8,"sample@value")="SERUM"
41 ;^TMP("C0STBL",32,"lab",8,"specimen@code")="0X500"
42 ;^TMP("C0STBL",32,"lab",8,"specimen@name")="SERUM"
43 ;^TMP("C0STBL",32,"lab",8,"status@value")="completed"
44 ;^TMP("C0STBL",32,"lab",8,"test@value")="FASTING BLOOD GLUCOSE"
45 ;^TMP("C0STBL",32,"lab",8,"type@value")="CH"
46 ;^TMP("C0STBL",32,"lab",8,"units@value")="MG/DL"
47 ;^TMP("C0STBL",32,"lab",8,"vuid@value")=4656342
48 ;
49 ; sample Smart lab result triples
50 ;
51 ;G("loinc:29571-7","dcterms:identifier")="29571-7"
52 ;G("loinc:29571-7","dcterms:title")="Phe DBS Ql"
53 ;G("loinc:29571-7","rdf:type")="sp:Code"
54 ;G("loinc:29571-7","sp:system")="http://loinc.org/codes/"
55 ;G("loinc:38478-4","dcterms:identifier")="38478-4"
56 ;G("loinc:38478-4","dcterms:title")="Biotinidase DBS Ql"
57 ;G("loinc:38478-4","rdf:type")="sp:Code"
58 ;G("loinc:38478-4","sp:system")="http://loinc.org/codes/"
59 ;G("qqWZZIew993","rdf:type")="sp:Attribution"
60 ;G("qqWZZIew993","sp:startDate")="2007-04-21"
61 ;G("qqWZZIew994","rdf:type")="sp:NarrativeResult"
62 ;G("qqWZZIew994","sp:value")="Normal"
63 ;G("qqWZZIew995","dcterms:title")="Biotinidase DBS Ql"
64 ;G("qqWZZIew995","rdf:type")="sp:CodedValue"
65 ;G("qqWZZIew995","sp:code")="loinc:38478-4"
66 ;G("qqWZZIew997","rdf:type")="sp:Attribution"
67 ;G("qqWZZIew997","sp:startDate")="2007-09-08"
68 ;G("qqWZZIew998","rdf:type")="sp:NarrativeResult"
69 ;G("qqWZZIew998","sp:value")="Normal"
70 ;G("qqWZZIew999","dcterms:title")="Phe DBS Ql"
71 ;G("qqWZZIew999","rdf:type")="sp:CodedValue"
72 ;G("qqWZZIew999","sp:code")="loinc:29571-7"
73 ;G("smart:99912345/lab_results/3d9b39249193","rdf:type")="sp:LabResult"
74 ;G("smart:99912345/lab_results/3d9b39249193","sp:belongsTo")="smart:99912345"
75 ;G("smart:99912345/lab_results/3d9b39249193","sp:labName")="qqWZZIew995"
76 ;G("smart:99912345/lab_results/3d9b39249193","sp:narrativeResult")="qqWZZIew994"
77 ;G("smart:99912345/lab_results/3d9b39249193","sp:specimenCollected")="qqWZZIew993"
78 ;G("smart:99912345/lab_results/426c7adc4f54","rdf:type")="sp:LabResult"
79 ;G("smart:99912345/lab_results/426c7adc4f54","sp:belongsTo")="smart:99912345"
80 ;G("smart:99912345/lab_results/426c7adc4f54","sp:labName")="qqWZZIew999"
81 ;G("smart:99912345/lab_results/426c7adc4f54","sp:narrativeResult")="qqWZZIew998"
82 ;G("smart:99912345/lab_results/426c7adc4f54","sp:specimenCollected")="qqWZZIew997"
83 ;
84 ;
85 ; another Smart example, this one with sp:quantitativeResult
86 ;
87 ;G("loinc:786-4","dcterms:identifier")="786-4"
88 ;G("loinc:786-4","dcterms:title")="MCHC RBC Auto-mCnc"
89 ;G("loinc:786-4","rdf:type")="sp:Code"
90 ;G("loinc:786-4","sp:system")="http://loinc.org/codes/"
91 ;G("nodeID:4439","rdf:type")="sp:ValueAndUnit"
92 ;G("nodeID:4439","sp:unit")="g/dL"
93 ;G("nodeID:4439","sp:value")=36.6
94 ;G("nodeID:4613","rdf:type")="sp:ValueAndUnit"
95 ;G("nodeID:4613","sp:unit")="g/dL"
96 ;G("nodeID:4613","sp:value")=32
97 ;G("nodeID:4672","rdf:type")="sp:Attribution"
98 ;G("nodeID:4672","sp:startDate")="2005-03-10"
99 ;G("nodeID:4866","rdf:type")="sp:ValueAndUnit"
100 ;G("nodeID:4866","sp:unit")="g/dL"
101 ;G("nodeID:4866","sp:value")=36
102 ;G("nodeID:4871","dcterms:title")="MCHC RBC Auto-mCnc"
103 ;G("nodeID:4871","rdf:type")="sp:CodedValue"
104 ;G("nodeID:4871","sp:code")="loinc:786-4"
105 ;G("nodeID:5221","rdf:type")="sp:QuantitativeResult"
106 ;G("nodeID:5221","sp:normalRange")="nodeID:5282"
107 ;G("nodeID:5221","sp:valueAndUnit")="nodeID:4439"
108 ;G("nodeID:5282","rdf:type")="sp:ValueRange"
109 ;G("nodeID:5282","sp:maximum")="nodeID:4866"
110 ;G("nodeID:5282","sp:minimum")="nodeID:4613"
111 ;G("smart:1540505/lab_results/2fc100850766","rdf:type")="sp:LabResult"
112 ;G("smart:1540505/lab_results/2fc100850766","sp:belongsTo")="smart:1540505"
113 ;G("smart:1540505/lab_results/2fc100850766","sp:labName")="nodeID:4871"
114 ;G("smart:1540505/lab_results/2fc100850766","sp:quantitativeResult")="nodeID:5221"
115 ;G("smart:1540505/lab_results/2fc100850766","sp:specimenCollected")="nodeID:4672"
116 ;
117LAB(GRTN,C0SARY) ; GRTN, passed by reference,
118 ; is the return name of the graph created. "" if none
119 ; C0SARY is passed in by reference and is the NHIN array of lab
120 ;
121 I $O(C0SARY("lab",""))="" D Q ;
122 . I $D(DEBUG) W !,"No Labs"
123 S GRTN="" ; default to no labs
124 N C0SGRF
125 S C0SGRF="vistaSmart:"_ZPATID_"/lab_results"
126 I $D(DEBUG) W !,"Processing ",C0SGRF
127 D DELGRAPH^C0XF2N(C0SGRF) ; delete the old graph
128 D INITFARY^C0XF2N("C0XFARY") ; which triple store to use
129 N FARY S FARY="C0XFARY"
130 D USEFARY^C0XF2N(FARY)
131 D VOCINIT^C0XUTIL
132 ;
133 D STARTADD^C0XF2N ; initialize to create triples
134 ;
135 N ZI S ZI=""
136 F S ZI=$O(C0SARY("lab",ZI)) Q:ZI="" D ;
137 . N LRN,ZR ; ZR is the local array for building the new triples
138 . S LRN=$NA(C0SARY("lab",ZI)) ; base for values in this lab result
139 . ;
140 . N RSLTID ; unique Id for this lab result
141 . S RSLTID=C0SGRF_"/"_$$LKY17^C0XF2N ; use a random number
142 . ;
143 . ; i don't like this because the same labs result gets a
144 . ; different ID every time it's reported. Can't trace it back to VistA
145 . ; I'd rather be using id@value ie "id@value")="CH;6889372.84;67003"
146 . ; .. either that or store an OID with the lab result - but that
147 . ; will have to wait for the redesign of file 60.. - gpl 4/16/2012
148 . ;
149 . N LOINC S LOINC=$G(@LRN@("loinc@value"))
150 . I LOINC="" D Q ;
151 . . I $D(DEBUG) W !,"NO LOINC VALUE, SKIPPING"
152 . N LABTST S LABTST=$G(@LRN@("test@value"))
153 . I $D(DEBUG) D ;
154 . . W !,"Processing Lab Result ",RSLTID
155 . . W !,"test: ",LABTST
156 . . W !,"loinc: ",LOINC
157 . ;
158 . ; first do the base result graph
159 . ;
160 . S ZR("rdf:type")="sp:LabResult"
161 . S ZR("sp:belongsTo")=C0SGRF ; the subject for this patient's lab results
162 . ; ie /vista/smart/99912345/lab_results
163 . ;
164 . N LABNAME S LABNAME=$$ANONS^C0XF2N ; new node for lab name
165 . S ZR("sp:labName")=LABNAME
166 . ;
167 . N NARRSLT S NARRSLT=$$ANONS^C0XF2N ; new node for narrative result
168 . S ZR("sp:narrativeResult")=NARRSLT
169 . ;
170 . N QNTRSLT S QNTRSLT=$$ANONS^C0XF2N ; new node for narrative result
171 . S ZR("sp:quantitativeResult")=QNTRSLT
172 . ;
173 . N SPECCOLL S SPECCOLL=$$ANONS^C0XF2N ; new node for specimen collected
174 . S ZR("sp:specimenCollected")=SPECCOLL
175 . ;
176 . D ADDINN^C0XF2N(C0SGRF,RSLTID,.ZR) ; addIfNotNull the triples
177 . K ZR ; clean up
178 . ;
179 . ; create the narrative result graph
180 . ;
181 . N IVAL S IVAL=$G(@LRN@("interpretation@value"))'="" D ; H OR L
182 . I IVAL'=""
183 . . S ZR("rdf:type")="sp:NarrativeResult"
184 . . S ZR("sp:value")=$G(@LRN@("interpretation@value")) ; H or L
185 . . I ZR("sp:value")="L" S ZR("sp:value")="abnormal"
186 . . I ZR("sp:value")="H" S ZR("sp:value")="abnormal"
187 . . I ZR("sp:value")="HH" S ZR("sp:value")="critical"
188 . . I ZR("sp:value")="LL" S ZR("sp:value")="critical"
189 . . D ADDINN^C0XF2N(C0SGRF,NARRSLT,.ZR)
190 . . K ZR
191 . ;
192 . ; create the quantitative result graph
193 . ;
194 . S ZR("rdf:type")="sp:QuantitativeResult"
195 . N NORMNM S NORMNM=$$ANONS^C0XF2N ; new node for normal range graph
196 . N VUNM S VUNM=$$ANONS^C0XF2N ; new node for value and unit graph
197 . N HASNORMAL S HASNORMAL=0
198 . I $G(@LRN@("high@value"))'="" S HASNORMAL=1
199 . I HASNORMAL S ZR("sp:normalRange")=NORMNM
200 . S ZR("sp:valueAndUnit")=VUNM
201 . D ADDINN^C0XF2N(C0SGRF,QNTRSLT,.ZR)
202 . K ZR
203 . ;
204 . ; create the normal range graph
205 . ;
206 . I HASNORMAL D ;
207 . . S ZR("rdf:type")="sp:ValueRange"
208 . . N MAXNM S MAXNM=$$ANONS^C0XF2N ; new node for maximum graph
209 . . N MINNM S MINNM=$$ANONS^C0XF2N ; new node for minimum graph
210 . . S ZR("sp:maximum")=MAXNM
211 . . S ZR("sp:minimum")=MINNM
212 . . D ADDINN^C0XF2N(C0SGRF,NORMNM,.ZR)
213 . . K ZR
214 . . ;
215 . . ; create the maximum graph
216 . . ;
217 . . S ZR("rdf:type")="sp:ValueAndUnit"
218 . . S ZR("sp:unit")=$G(@LRN@("units@value"))
219 . . S ZR("sp:value")=$G(@LRN@("high@value"))
220 . . D ADDINN^C0XF2N(C0SGRF,MAXNM,.ZR)
221 . . K ZR
222 . . ;
223 . . ; create the minimum graph
224 . . ;
225 . . S ZR("rdf:type")="sp:ValueAndUnit"
226 . . S ZR("sp:unit")=$G(@LRN@("units@value"))
227 . . S ZR("sp:value")=$G(@LRN@("low@value"))
228 . . D ADDINN^C0XF2N(C0SGRF,MINNM,.ZR)
229 . . K ZR
230 . ;
231 . ; create the value and unit graph
232 . ;
233 . S ZR("rdf:type")="sp:ValueAndUnit"
234 . S ZR("sp:unit")=$G(@LRN@("units@value"))
235 . I ZR("sp:unit")="" S ZR("sp:unit")="{unknown}" ; was $G(@LRN@("test@value")) gpl
236 . S ZR("sp:value")=$G(@LRN@("result@value"))
237 . D ADDINN^C0XF2N(C0SGRF,VUNM,.ZR)
238 . K ZR
239 . ;
240 . ; create specimen collected graph
241 . ;
242 . S ZR("rdf:type")="sp:Attribution"
243 . S ZR("sp:startDate")=$$SPDATE^C0SUTIL($G(@LRN@("collected@value")))
244 . D ADDINN^C0XF2N(C0SGRF,SPECCOLL,.ZR)
245 . K ZR
246 . ;
247 . ; create lab name graph - this contains the test name and code
248 . ;
249 . I LOINC'="" D ;
250 . . S ZR("rdf:type")="sp:CodedValue"
251 . . S ZR("dcterms:title")=LABTST
252 . . N LOINCNM S LOINCNM="loinc:"_LOINC
253 . . S ZR("sp:code")="loinc:"_LOINC
254 . . D ADDINN^C0XF2N(C0SGRF,LABNAME,.ZR)
255 . . K ZR
256 . . S ZR("dcterms:identifier")=LOINC
257 . . S ZR("dcterms:title")=LABTST
258 . . S ZR("rdf:type")="sp:Code"
259 . . S ZR("sp:system")="http://loinc.org/codes/"
260 . . D ADDINN^C0XF2N(C0SGRF,LOINCNM,.ZR)
261 . . K ZR
262 . ;
263 . ; that's all for now folks (there is more to do like reference ranges
264 . ; and result values)
265 . ;
266 D BULKLOAD^C0XF2N(.C0XFDA)
267 S GRTN=C0SGRF
268 Q
269 ;
270SAMPLE ; import sample lab tests to the triplestore
271 N GN
272 S GN=$NA(^rdf("lab_results"))
273 D INSRDF^C0XF2N(GN,"/smart/lab/samples")
274 Q
275 ;
Note: See TracBrowser for help on using the repository browser.