[416] | 1 | C0CMED3 ; WV/CCDCCR/SMH - Meds: Non-VA/Outside Meds for Vista
|
---|
[220] | 2 | ;;0.1;CCDCCR;;;
|
---|
[319] | 3 | ;;Last Modified: Sun Jan 11 05:45:03 UTC 2009
|
---|
| 4 | ; Copyright 2009 WorldVistA. Licensed under the terms of the GNU
|
---|
[220] | 5 | ; General Public License See attached copy of the License.
|
---|
| 6 | ;
|
---|
| 7 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 8 | ; it under the terms of the GNU General Public License as published by
|
---|
| 9 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 10 | ; (at your option) any later version.
|
---|
| 11 | ;
|
---|
| 12 | ; This program is distributed in the hope that it will be useful,
|
---|
| 13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | ; GNU General Public License for more details.
|
---|
| 16 | ;
|
---|
| 17 | ; You should have received a copy of the GNU General Public License along
|
---|
| 18 | ; with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
| 19 | ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
| 20 | ;
|
---|
| 21 | W "NO ENTRY FROM TOP",!
|
---|
| 22 | Q
|
---|
| 23 | ;
|
---|
[421] | 24 | EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT) ; Extract medications into provided xml template
|
---|
[220] | 25 | ;
|
---|
[421] | 26 | ; MINXML is the Input XML Template, (passed by name)
|
---|
| 27 | ; DFN is Patient IEN (passed by value)
|
---|
| 28 | ; OUTXML is the resultant XML (passed by name)
|
---|
| 29 | ; MEDCOUNT is the number of Meds extracted so far (passed by reference)
|
---|
[220] | 30 | ;
|
---|
| 31 | ; MEDS is return array from RPC.
|
---|
| 32 | ; MAP is a mapping variable map (store result) for each med
|
---|
| 33 | ; MED is holds each array element from MEDS, one medicine
|
---|
| 34 | ;
|
---|
| 35 | ; Non-VA meds don't have an API. They are stored in file 55, subfile 52.2
|
---|
| 36 | ; Discontinued meds are indicated by the presence of a value in fields
|
---|
| 37 | ; 5 or 6 (STATUS 1 or 2, and DISCONTINUED DATE)
|
---|
| 38 | ; Will use Fileman API GETS^DIQ
|
---|
| 39 | ;
|
---|
| 40 | N MEDS,MAP
|
---|
[347] | 41 | K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
|
---|
[421] | 42 | N NVA
|
---|
[220] | 43 | D GETS^DIQ(55,DFN,"52.2*","IE","NVA") ; Output in NVA in FDA array format.
|
---|
| 44 | ; If NVA does not exist, then patient has no non-VA meds
|
---|
| 45 | I $D(NVA)=0 S @OUTXML@(0)=0 QUIT
|
---|
| 46 | ; Otherwise, we go on...
|
---|
| 47 | M MEDS=NVA(55.05)
|
---|
| 48 | ; We are done with NVA
|
---|
| 49 | K NVA
|
---|
| 50 | ;
|
---|
| 51 | I DEBUG ZWR MEDS
|
---|
| 52 | N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
|
---|
[238] | 53 | N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED PROCESSED HERE
|
---|
[234] | 54 | F S FDAIEN=$O(MEDS(FDAIEN)) Q:FDAIEN="" D ; FOR EACH MEDICATION IN THE LIST
|
---|
[220] | 55 | . N MED M MED=MEDS(FDAIEN)
|
---|
| 56 | . I MED(5,"I")!MED(6,"I") QUIT ; If disconinued, we don't want to pull it.
|
---|
| 57 | . S MEDCOUNT=MEDCOUNT+1
|
---|
[412] | 58 | . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
|
---|
[220] | 59 | . N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
|
---|
[242] | 60 | . I DEBUG W "RXIEN IS ",RXIEN,!
|
---|
| 61 | . I DEBUG W "MAP= ",MAP,!
|
---|
[220] | 62 | . S @MAP@("MEDOBJECTID")="MED_OUTSIDE"_MEDCOUNT ; MEDCOUNT FOR ID
|
---|
| 63 | . S @MAP@("MEDISSUEDATETXT")="Documented Date"
|
---|
| 64 | . ; Field 6 is "Effective date", and we pull it in timson format w/ I
|
---|
[396] | 65 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL(MED(11,"I"),"DT")
|
---|
[220] | 66 | . ; Med never filled; next 4 fields are not applicable.
|
---|
| 67 | . S @MAP@("MEDLASTFILLDATETXT")=""
|
---|
| 68 | . S @MAP@("MEDLASTFILLDATE")=""
|
---|
| 69 | . S @MAP@("MEDRXNOTXT")=""
|
---|
| 70 | . S @MAP@("MEDRXNO")=""
|
---|
| 71 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
| 72 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
| 73 | . S @MAP@("MEDSTATUSTEXT")="ACTIVE" ; nearest status for pending meds
|
---|
| 74 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_MED(12,"I")
|
---|
| 75 | . S @MAP@("MEDPRODUCTNAMETEXT")=MED(.01,"E")
|
---|
| 76 | . ; NDC is field 31 in the drug file.
|
---|
[295] | 77 | . ; The actual drug entry in the drug file (MEDIEN) is not necessarily supplied.
|
---|
[220] | 78 | . ; It' node 1, internal form.
|
---|
| 79 | . N MEDIEN S MEDIEN=MED(1,"I")
|
---|
[312] | 80 | . I +MEDIEN D ; start of if/else block
|
---|
| 81 | . . ; 12/30/08: I will be using RxNorm for coding...
|
---|
| 82 | . . ; 176.001 is the file for Concepts; 176.003 is the file for
|
---|
| 83 | . . ; sources (i.e. for RxNorm Version)
|
---|
| 84 | . . ;
|
---|
| 85 | . . ; We need the VUID first for the National Drug File entry first
|
---|
| 86 | . . ; We get the VUID of the drug, by looking up the VA Product entry
|
---|
| 87 | . . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
|
---|
| 88 | . . ; Field 99.99 is the VUID.
|
---|
| 89 | . . ;
|
---|
| 90 | . . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
|
---|
[347] | 91 | . . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
|
---|
[312] | 92 | . . ; $$GET1^DIQ.
|
---|
| 93 | . . ;
|
---|
[347] | 94 | . . ; I get the RxNorm name and version from the RxNorm Sources (file
|
---|
[312] | 95 | . . ; 176.003), by searching for "RXNORM", then get the data.
|
---|
| 96 | . . D NDF^PSS50(MEDIEN,,,,,"NDF")
|
---|
| 97 | . . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
---|
| 98 | . . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
[347] | 99 | . . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
[312] | 100 | . . ;
|
---|
| 101 | . . ; NDFIEN is not necessarily defined; it won't be if the drug
|
---|
| 102 | . . ; is not matched to the national drug file (e.g. if the drug is
|
---|
| 103 | . . ; new on the market, compounded, or is a fake drug [blue pill].
|
---|
| 104 | . . ; To protect against failure, I will put an if/else block
|
---|
| 105 | . . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
---|
[322] | 106 | . . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
---|
[312] | 107 | . . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
|
---|
| 108 | . . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
|
---|
| 109 | . . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
|
---|
| 110 | . . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
---|
| 111 | . . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
---|
| 112 | . . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
---|
| 113 | . . ;
|
---|
| 114 | . . E S (RXNORM,RXNNAME,RXNVER)=""
|
---|
| 115 | . . ; End if/else block
|
---|
| 116 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
---|
| 117 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
---|
| 118 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
---|
| 119 | . . ;
|
---|
[295] | 120 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
| 121 | . . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
| 122 | . . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
| 123 | . . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
---|
| 124 | . . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
---|
| 125 | . . ; Units, concentration, etc, come from another call
|
---|
| 126 | . . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
| 127 | . . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
| 128 | . . ; NDF Entry IEN, and VA Product Name
|
---|
| 129 | . . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
[312] | 130 | . . ; Documented in the same manual; executed above.
|
---|
[347] | 131 | . . ;
|
---|
[220] | 132 | . . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
| 133 | . . ; and this will crash the call. So...
|
---|
| 134 | . . I NDFIEN="" S CONCDATA=""
|
---|
| 135 | . . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
[295] | 136 | . . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
---|
| 137 | . . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
---|
| 138 | . . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
---|
| 139 | . . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
|
---|
| 140 | . . ; Oddly, there is no easy place to find the dispense unit.
|
---|
| 141 | . . ; It's not included in the original call, so we have to go to the drug file.
|
---|
| 142 | . . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
| 143 | . . ; Node 14.5 is the Dispense Unit
|
---|
[220] | 144 | . . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
| 145 | . . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
| 146 | . . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
[295] | 147 | . E D
|
---|
| 148 | . . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
|
---|
| 149 | . . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
|
---|
| 150 | . . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
|
---|
| 151 | . . S @MAP@("MEDBRANDNAMETEXT")=""
|
---|
| 152 | . . S @MAP@("MEDSTRENGTHVALUE")=""
|
---|
| 153 | . . S @MAP@("MEDSTRENGTHUNIT")=""
|
---|
| 154 | . . S @MAP@("MEDFORMTEXT")=""
|
---|
| 155 | . . S @MAP@("MEDCONCVALUE")=""
|
---|
| 156 | . . S @MAP@("MEDCONCUNIT")=""
|
---|
| 157 | . . S @MAP@("MEDSIZETEXT")=""
|
---|
| 158 | . . S @MAP@("MEDQUANTITYVALUE")=""
|
---|
| 159 | . . S @MAP@("MEDQUANTITYUNIT")=""
|
---|
[312] | 160 | . ; End If/Else
|
---|
[220] | 161 | . ; --- START OF DIRECTIONS ---
|
---|
| 162 | . ; Dosage is field 2, route is 3, schedule is 4
|
---|
| 163 | . ; These are all free text fields, and don't point to any files
|
---|
| 164 | . ; For that reason, I will use the field I never used before:
|
---|
| 165 | . ; MEDDIRECTIONDESCRIPTIONTEXT
|
---|
[238] | 166 | . S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
|
---|
[220] | 167 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
|
---|
| 168 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
|
---|
| 169 | . S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
|
---|
| 170 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
|
---|
| 171 | . S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
|
---|
[233] | 172 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
|
---|
| 173 | . S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
|
---|
| 174 | . S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
|
---|
[220] | 175 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
|
---|
| 176 | . S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
|
---|
| 177 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
|
---|
| 178 | . S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
|
---|
| 179 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
|
---|
| 180 | . S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
|
---|
| 181 | . S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
|
---|
| 182 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
|
---|
| 183 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
|
---|
| 184 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
|
---|
| 185 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
|
---|
| 186 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
| 187 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
|
---|
| 188 | . S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
|
---|
[233] | 189 | . S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
|
---|
[220] | 190 | . S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
|
---|
| 191 | . S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
|
---|
| 192 | . ;
|
---|
| 193 | . ; --- END OF DIRECTIONS ---
|
---|
| 194 | . ;
|
---|
| 195 | . ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
|
---|
[241] | 196 | . I $D(MED(10,1)) D ;
|
---|
| 197 | . . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
|
---|
| 198 | . E S @MAP@("MEDPTINSTRUCTIONS")=""
|
---|
| 199 | . I $D(MED(14,1)) D ;
|
---|
| 200 | . . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
|
---|
| 201 | . E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
|
---|
[220] | 202 | . S @MAP@("MEDRFNO")=""
|
---|
[412] | 203 | . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
|
---|
[220] | 204 | . K @RESULT
|
---|
[412] | 205 | . D MAP^C0CXPATH(MINXML,MAP,RESULT)
|
---|
| 206 | . ; D PARY^C0CXPATH(RESULT)
|
---|
[220] | 207 | . ; MAPPING DIRECTIONS
|
---|
| 208 | . N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
| 209 | . N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
[412] | 210 | . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
| 211 | . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
[220] | 212 | . ; N MDZ1,MDZNA
|
---|
| 213 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
| 214 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
| 215 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
[412] | 216 | . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
| 217 | . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
[241] | 218 | . I MEDFIRST D ;
|
---|
| 219 | . . S MEDFIRST=0 ; RESET FIRST FLAG
|
---|
[412] | 220 | . . D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
| 221 | . D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
---|
[220] | 222 | N MEDTMP,MEDI
|
---|
[412] | 223 | D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
[220] | 224 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
| 225 | . W "MEDICATION MISSING ",!
|
---|
| 226 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
| 227 | Q
|
---|
| 228 | ;
|
---|