[1540] | 1 | C0SDEM ; GPL - Smart Demographics Processing ;2/22/12 17:05
|
---|
| 2 | ;;1.0;VISTA SMART CONTAINER;;Sep 26, 2012;Build 2
|
---|
| 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 | ;<?xml version="1.0" encoding="utf-8"?>
|
---|
| 23 | ;<rdf:RDF
|
---|
| 24 | ; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
---|
| 25 | ; xmlns:sp="http://smartplatforms.org/terms#"
|
---|
| 26 | ; xmlns:dcterms="http://purl.org/dc/terms/"
|
---|
| 27 | ; xmlns:v="http://www.w3.org/2006/vcard/ns#"
|
---|
| 28 | ; xmlns:foaf="http://xmlns.com/foaf/0.1/">
|
---|
| 29 | ; <sp:Demographics>
|
---|
| 30 | ;
|
---|
| 31 | ; <v:n>
|
---|
| 32 | ; <v:Name>
|
---|
| 33 | ; <v:given-name>Bob</v:given-name>
|
---|
| 34 | ; <v:additional-name>J</v:additional-name>
|
---|
| 35 | ; <v:family-name>Odenkirk</v:family-name>
|
---|
| 36 | ; </v:Name>
|
---|
| 37 | ; </v:n>
|
---|
| 38 | ;
|
---|
| 39 | ; <v:adr>
|
---|
| 40 | ; <v:Address>
|
---|
| 41 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home" />
|
---|
| 42 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Pref" />
|
---|
| 43 | ;
|
---|
| 44 | ; <v:street-address>15 Main St</v:street-address>
|
---|
| 45 | ; <v:extended-address>Apt 2</v:extended-address>
|
---|
| 46 | ; <v:locality>Wonderland</v:locality>
|
---|
| 47 | ; <v:region>OZ</v:region>
|
---|
| 48 | ; <v:postal-code>54321</v:postal-code>
|
---|
| 49 | ; <v:country>USA</v:country>
|
---|
| 50 | ; </v:Address>
|
---|
| 51 | ; </v:adr>
|
---|
| 52 | ;
|
---|
| 53 | ; <v:tel>
|
---|
| 54 | ; <v:Tel>
|
---|
| 55 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home" />
|
---|
| 56 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Pref" />
|
---|
| 57 | ; <rdf:value>800-555-1212</rdf:value>
|
---|
| 58 | ; </v:Tel>
|
---|
| 59 | ; </v:tel>
|
---|
| 60 | ;
|
---|
| 61 | ; <v:tel>
|
---|
| 62 | ; <v:Tel>
|
---|
| 63 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Cell" />
|
---|
| 64 | ; <rdf:value>800-555-1515</rdf:value>
|
---|
| 65 | ; </v:Tel>
|
---|
| 66 | ; </v:tel>
|
---|
| 67 | ;
|
---|
| 68 | ; <foaf:gender>male</foaf:gender>
|
---|
| 69 | ; <v:bday>1959-12-25</v:bday>
|
---|
| 70 | ; <v:email>bob.odenkirk@example.com</v:email>
|
---|
| 71 | ;
|
---|
| 72 | ; <sp:medicalRecordNumber>
|
---|
| 73 | ; <sp:Code>
|
---|
| 74 | ; <dcterms:title>My Hospital Record 2304575</dcterms:title>
|
---|
| 75 | ; <dcterms:identifier>2304575</dcterms:identifier>
|
---|
| 76 | ; <sp:system>My Hospital Record</sp:system>
|
---|
| 77 | ; </sp:Code>
|
---|
| 78 | ; </sp:medicalRecordNumber>
|
---|
| 79 | ;
|
---|
| 80 | ; </sp:Demographics>
|
---|
| 81 | ;</rdf:RDF><?xml version="1.0" encoding="utf-8"?>
|
---|
| 82 | ;<rdf:RDF
|
---|
| 83 | ; xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
---|
| 84 | ; xmlns:sp="http://smartplatforms.org/terms#"
|
---|
| 85 | ; xmlns:dcterms="http://purl.org/dc/terms/"
|
---|
| 86 | ; xmlns:v="http://www.w3.org/2006/vcard/ns#"
|
---|
| 87 | ; xmlns:foaf="http://xmlns.com/foaf/0.1/">
|
---|
| 88 | ; <sp:Demographics>
|
---|
| 89 | ;
|
---|
| 90 | ; <v:n>
|
---|
| 91 | ; <v:Name>
|
---|
| 92 | ; <v:given-name>Bob</v:given-name>
|
---|
| 93 | ; <v:additional-name>J</v:additional-name>
|
---|
| 94 | ; <v:family-name>Odenkirk</v:family-name>
|
---|
| 95 | ; </v:Name>
|
---|
| 96 | ; </v:n>
|
---|
| 97 | ;
|
---|
| 98 | ; <v:adr>
|
---|
| 99 | ; <v:Address>
|
---|
| 100 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home" />
|
---|
| 101 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Pref" />
|
---|
| 102 | ;
|
---|
| 103 | ; <v:street-address>15 Main St</v:street-address>
|
---|
| 104 | ; <v:extended-address>Apt 2</v:extended-address>
|
---|
| 105 | ; <v:locality>Wonderland</v:locality>
|
---|
| 106 | ; <v:region>OZ</v:region>
|
---|
| 107 | ; <v:postal-code>54321</v:postal-code>
|
---|
| 108 | ; <v:country>USA</v:country>
|
---|
| 109 | ; </v:Address>
|
---|
| 110 | ; </v:adr>
|
---|
| 111 | ;
|
---|
| 112 | ; <v:tel>
|
---|
| 113 | ; <v:Tel>
|
---|
| 114 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Home" />
|
---|
| 115 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Pref" />
|
---|
| 116 | ; <rdf:value>800-555-1212</rdf:value>
|
---|
| 117 | ; </v:Tel>
|
---|
| 118 | ; </v:tel>
|
---|
| 119 | ;
|
---|
| 120 | ; <v:tel>
|
---|
| 121 | ; <v:Tel>
|
---|
| 122 | ; <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Cell" />
|
---|
| 123 | ; <rdf:value>800-555-1515</rdf:value>
|
---|
| 124 | ; </v:Tel>
|
---|
| 125 | ; </v:tel>
|
---|
| 126 | ;
|
---|
| 127 | ; <foaf:gender>male</foaf:gender>
|
---|
| 128 | ; <v:bday>1959-12-25</v:bday>
|
---|
| 129 | ; <v:email>bob.odenkirk@example.com</v:email>
|
---|
| 130 | ;
|
---|
| 131 | ; <sp:medicalRecordNumber>
|
---|
| 132 | ; <sp:Code>
|
---|
| 133 | ; <dcterms:title>My Hospital Record 2304575</dcterms:title>
|
---|
| 134 | ; <dcterms:identifier>2304575</dcterms:identifier>
|
---|
| 135 | ; <sp:system>My Hospital Record</sp:system>
|
---|
| 136 | ; </sp:Code>
|
---|
| 137 | ; </sp:medicalRecordNumber>
|
---|
| 138 | ;
|
---|
| 139 | ; </sp:Demographics>
|
---|
| 140 | ;</rdf:RDF>
|
---|
| 141 | ;G(1)="nodeID:25591^rdf:type^v:Home"
|
---|
| 142 | ;G(2)="nodeID:25591^rdf:type^v:Pref"
|
---|
| 143 | ;G(3)="nodeID:25591^rdf:type^v:Tel"
|
---|
| 144 | ;G(4)="nodeID:25591^rdf:value^800-369-6403"
|
---|
| 145 | ;G(5)="nodeID:25611^rdf:type^v:Name"
|
---|
| 146 | ;G(6)="nodeID:25611^v:additional-name^N"
|
---|
| 147 | ;G(7)="nodeID:25611^v:family-name^Brooks"
|
---|
| 148 | ;G(8)="nodeID:25611^v:given-name^Brian"
|
---|
| 149 | ;G(9)="nodeID:25622^dcterms:identifier^981968"
|
---|
| 150 | ;G(10)="nodeID:25622^dcterms:title^My Hospital Record 981968"
|
---|
| 151 | ;G(11)="nodeID:25622^rdf:type^sp:Code"
|
---|
| 152 | ;G(12)="nodeID:25622^sp:system^My Hospital Record"
|
---|
| 153 | ;G(13)="nodeID:25623^rdf:type^v:Address"
|
---|
| 154 | ;G(14)="nodeID:25623^rdf:type^v:Home"
|
---|
| 155 | ;G(15)="nodeID:25623^rdf:type^v:Pref"
|
---|
| 156 | ;G(16)="nodeID:25623^v:locality^Bixby"
|
---|
| 157 | ;G(17)="nodeID:25623^v:postal-code^74008"
|
---|
| 158 | ;G(18)="nodeID:25623^v:region^OK"
|
---|
| 159 | ;G(19)="nodeID:25623^v:street-address^82 Lake St"
|
---|
| 160 | ;G(20)="smart:981968/demographics^foaf:gender^male"
|
---|
| 161 | ;G(21)="smart:981968/demographics^rdf:type^sp:Demographics"
|
---|
| 162 | ;G(22)="smart:981968/demographics^sp:belongsTo^smart:981968"
|
---|
| 163 | ;G(23)="smart:981968/demographics^sp:medicalRecordNumber^nodeID:25622"
|
---|
| 164 | ;G(24)="smart:981968/demographics^v:adr^nodeID:25623"
|
---|
| 165 | ;G(25)="smart:981968/demographics^v:bday^1956-03-23"
|
---|
| 166 | ;G(26)="smart:981968/demographics^v:email^brian.brooks@example.com"
|
---|
| 167 | ;G(27)="smart:981968/demographics^v:n^nodeID:25611"
|
---|
| 168 | ;G(28)="smart:981968/demographics^v:tel^nodeID:25591"
|
---|
| 169 | Q
|
---|
| 170 | ;
|
---|
| 171 | PATIENT(GRTN,C0SARY) ; GRTN, passed by reference,
|
---|
| 172 | ; is the return name of the graph created. "" if none
|
---|
| 173 | ; C0SARY is passed in by reference and is the NHIN array of patient
|
---|
| 174 | ;
|
---|
| 175 | I $O(C0SARY("patient",""))="" D Q ;
|
---|
| 176 | . I $D(DEBUG) W !,"No Patient array"
|
---|
| 177 | . S GRTN=""
|
---|
| 178 | S GRTN="" ; default to no patient
|
---|
| 179 | N C0SGRF
|
---|
| 180 | S C0SGRF="vistaSmart:"_ZPATID_"/patient"
|
---|
| 181 | S ZPAT=C0SGRF ; subject is the same as the graph name
|
---|
| 182 | I $D(DEBUG) W !,"Processing ",C0SGRF
|
---|
| 183 | D DELGRAPH^C0XF2N(C0SGRF) ; delete the old graph
|
---|
| 184 | D INITFARY^C0XF2N("C0XFARY") ; which triple store to use
|
---|
| 185 | N FARY S FARY="C0XFARY"
|
---|
| 186 | D USEFARY^C0XF2N(FARY)
|
---|
| 187 | D VOCINIT^C0XUTIL
|
---|
| 188 | ;
|
---|
| 189 | N ZPN,ZR
|
---|
| 190 | D STARTADD^C0XF2N
|
---|
| 191 | ;
|
---|
| 192 | ; First do the base demographic graph
|
---|
| 193 | ;
|
---|
| 194 | S ZPN=$NA(C0SARY("patient",1)) ; name of predicate array for this patient
|
---|
| 195 | N SEX S SEX=$G(@ZPN@("gender@value"))
|
---|
| 196 | I SEX="M" S SEX="male"
|
---|
| 197 | I SEX="F" S SEX="female"
|
---|
| 198 | S ZR("foaf:gender")=SEX
|
---|
| 199 | S ZR("rdf:type")="sp:Demographics"
|
---|
| 200 | S ZR("sp:belongsTo")=ZPAT
|
---|
| 201 | N PATIENT
|
---|
| 202 | S PATIENT=$P(ZPAT,"#",2)
|
---|
| 203 | I $D(DEBUG) W !,"PROCESSING PATIENT ",PATIENT
|
---|
| 204 | N NMREC S NMREC=$$ANONS^C0XF2N ; new anonomous subject for med rec graph
|
---|
| 205 | S ZR("sp:medicalRecordNumber")=NMREC
|
---|
| 206 | N NVADR S NVADR=$$ANONS^C0XF2N ; for address
|
---|
| 207 | S ZR("v:adr")=NVADR
|
---|
| 208 | N NNAME S NNAME=$$ANONS^C0XF2N ; for name
|
---|
| 209 | S ZR("v:n")=NNAME
|
---|
| 210 | N NTEL S NTEL=$$ANONS^C0XF2N ; for telephone
|
---|
| 211 | I $D(@ZPN@("telecomList.telecom@value")) S ZR("v:tel")=NTEL ; only if exists
|
---|
| 212 | N BDATE
|
---|
| 213 | S ZX=""
|
---|
| 214 | S ZX=$G(@ZPN@("dob@value")) ; date of birth in fileman format
|
---|
| 215 | S BDATE=$$FMTE^XLFDT(ZX,"7D") ; ordered date
|
---|
| 216 | S BDATE=$TR(BDATE,"/","-") ; change slashes to hyphens
|
---|
| 217 | I BDATE="" S BDATE="UNKNOWN"
|
---|
| 218 | N Z2,Z3
|
---|
| 219 | S Z2=$P(BDATE,"-",2)
|
---|
| 220 | S Z3=$P(BDATE,"-",3)
|
---|
| 221 | I $L(Z2)=1 S $P(BDATE,"-",2)="0"_Z2
|
---|
| 222 | I $L(Z3)=1 S $P(BDATE,"-",3)="0"_Z3
|
---|
| 223 | S ZR("v:bday")=BDATE
|
---|
| 224 | I $D(C0SVISTA) D ;
|
---|
| 225 | . S ZR("vista:SSN")=$G(@ZPN@("ssn@value")) ; SSN
|
---|
| 226 | . S ZR("vista:DFN")=$G(@ZPN@("id@value")) ; DFN
|
---|
| 227 | D ADDINN^C0XF2N(C0SGRF,ZPAT,.ZR) ; create base graph
|
---|
| 228 | K ZR
|
---|
| 229 | ;
|
---|
| 230 | ; create address sub-graph
|
---|
| 231 | ;
|
---|
| 232 | S ZR("rdf:type")="v:Address"
|
---|
| 233 | S ZR("rdf:type")="v:Home"
|
---|
| 234 | S ZR("v:locality")=$G(@ZPN@("address@city"))
|
---|
| 235 | S ZR("v:postal-code")=$G(@ZPN@("address@postalCode"))
|
---|
| 236 | S ZR("v:region")=$G(@ZPN@("address@stateProvince"))
|
---|
| 237 | S ZR("v:street-address")=$G(@ZPN@("address@streetLine1"))
|
---|
| 238 | D ADDINN^C0XF2N(C0SGRF,NVADR,.ZR) ; create the vcard address
|
---|
| 239 | K ZR
|
---|
| 240 | ;
|
---|
| 241 | ; create medical record subgraph
|
---|
| 242 | ;
|
---|
| 243 | S ZR("dcterms:identifier")=$G(@ZPN@("id@value"))
|
---|
| 244 | S ZR("dcterms:title")="VistA Patient Record "_ZR("dcterms:identifier")
|
---|
| 245 | S ZR("rdf:type")="sp:Code"
|
---|
| 246 | S ZR("sp:system")="VistA Patient Record"
|
---|
| 247 | D ADDINN^C0XF2N(C0SGRF,NMREC,.ZR) ; create medical record graph
|
---|
| 248 | K ZR
|
---|
| 249 | ;
|
---|
| 250 | ; create name subgraph
|
---|
| 251 | ;
|
---|
| 252 | N ZNF,ZNL,ZNM,ZNAM
|
---|
| 253 | S ZR("rdf:type")="v:Name"
|
---|
| 254 | S ZX=$G(@ZPN@("givenNames@value")) ; first name and middle names
|
---|
| 255 | S ZNF=$P(ZX," ",1) ; first name is first piece
|
---|
| 256 | S ZNM=$P(ZX," ",2) ; middle names are the rest
|
---|
| 257 | S ZR("v:additional-name")=ZNM
|
---|
| 258 | S ZR("v:family-name")=$G(@ZPN@("familyName@value"))
|
---|
| 259 | S ZR("v:given-name")=ZNF
|
---|
| 260 | D ADDINN^C0XF2N(C0SGRF,NNAME,.ZR) ; insert name graph
|
---|
| 261 | K ZR
|
---|
| 262 | ;
|
---|
| 263 | ; create telephone subgraph
|
---|
| 264 | ;
|
---|
| 265 | D ;
|
---|
| 266 | . S ZR("rdf:value")=$G(@ZPN@("telecomList.telecom@value"))
|
---|
| 267 | . I ZR("rdf:value")="" Q ; telephone number missing, no subgraph
|
---|
| 268 | . S ZR("rdf:type")="v:Tel"
|
---|
| 269 | . D ADDINN^C0XF2N(C0SGRF,NTEL,.ZR)
|
---|
| 270 | K ZR
|
---|
| 271 | ;
|
---|
| 272 | ; load the demographics graph and all sub graphs to the triple store
|
---|
| 273 | ;
|
---|
| 274 | D BULKLOAD^C0XF2N(.C0XFDA)
|
---|
| 275 | S GRTN=C0SGRF
|
---|
| 276 | Q
|
---|
| 277 | ;
|
---|
| 278 | AGES ; LIST ALL PATIENTS AND THEIR AGES
|
---|
| 279 | N ZI S ZI=0
|
---|
| 280 | F S ZI=$O(^DPT(ZI)) Q:+ZI=0 D ; FOR EVERY PATIENT
|
---|
| 281 | . N ZDOB
|
---|
| 282 | . S ZDOB=$$GET1^DIQ(2,ZI_",","DOB","I") ; FILEMAN DOB
|
---|
| 283 | . N ZNAME
|
---|
| 284 | . S ZNAME=$P(^DPT(ZI,0),U)
|
---|
| 285 | . N ZSEX
|
---|
| 286 | . S ZSEX=$$GET1^DIQ(2,ZI_",","SEX")
|
---|
| 287 | . W !,"DFN:",ZI," ",ZNAME," AGE: ",+$$BRIEF^VWTIME(ZDOB)," YEAR OLD ",ZSEX
|
---|
| 288 | Q
|
---|
| 289 | ;
|
---|