[1428] | 1 | C0CMED1 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS ;01/10/09
|
---|
[1433] | 2 | ;;1.2;C0C;;May 11, 2012;Build 47
|
---|
[1428] | 3 | ;;Last modified Sat Jan 10 21:42:27 PST 2009
|
---|
| 4 | ; Copyright 2009 WorldVistA. Licensed under the terms of the GNU
|
---|
| 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 | ;
|
---|
| 24 | EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT,FLAGS) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
|
---|
| 25 | ;
|
---|
| 26 | ; INXML AND OUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
|
---|
| 27 | ; INXML WILL CONTAIN ONLY THE MEDICATIONS SECTION OF THE OVERALL TEMPLATE
|
---|
| 28 | ;
|
---|
| 29 | ; MEDS is return array from RPC.
|
---|
| 30 | ; MAP is a mapping variable map (store result) for each med
|
---|
| 31 | ; MED is holds each array element from MEDS(J), one medicine
|
---|
| 32 | ; MEDCOUNT is a counter passed by Reference.
|
---|
| 33 | ; FLAGS are: MEDALL(bool)^MEDLIMIT(int)^MEDACTIVE(bool)^MEDPENDING(bool)
|
---|
| 34 | ; FLAGS are set-up in C0CMED.
|
---|
| 35 | ;
|
---|
| 36 | ; RX^PSO52API is a Pharmacy Re-Enginnering (PRE) API to get all
|
---|
| 37 | ; med data available.
|
---|
| 38 | ; http://www.va.gov/vdl/documents/Clinical/Pharm-Outpatient_Pharmacy/phar_1_api_r0807.pdf
|
---|
| 39 | ; Output of API is ^TMP($J,"SUBSCRIPT",DFN,RXIENS).
|
---|
| 40 | ; D PARY^C0CXPATH(MINXML)
|
---|
| 41 | N MEDS,MAP
|
---|
| 42 | K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
|
---|
| 43 | N ALL S ALL=+FLAGS
|
---|
| 44 | N ACTIVE S ACTIVE=$P(FLAGS,U,3)
|
---|
[1433] | 45 | N PENDING S PENDING=$P(FLAGS,U,4) ;OHUM/RUT 3120504 ADDED FOR VALIDATION OF PENDING MEDICATIONS
|
---|
[1428] | 46 | ; Below, X1 is today; X2 is the number of days we want to go back
|
---|
| 47 | ; X is the result of this calculation using C^%DTC.
|
---|
| 48 | N X,X1,X2
|
---|
| 49 | S X1=DT
|
---|
| 50 | S X2=-$P($P(FLAGS,U,2),"-",2)
|
---|
| 51 | D C^%DTC
|
---|
| 52 | ; I discovered that I shouldn't put an ending date (last parameter)
|
---|
| 53 | ; because it seems that it will get meds whose beginning is after X but
|
---|
| 54 | ; whose exipriation is before the ending date.
|
---|
| 55 | D RX^PSO52API(DFN,"CCDCCR","","","",X,"")
|
---|
| 56 | M MEDS=^TMP($J,"CCDCCR",DFN)
|
---|
| 57 | ; @(0) contains the number of meds or -1^NO DATA FOUND
|
---|
| 58 | ; If it is -1, we quit.
|
---|
| 59 | I $P(MEDS(0),U)=-1 S @OUTXML@(0)=0 Q
|
---|
| 60 | ZWRITE:$G(DEBUG) MEDS
|
---|
| 61 | N RXIEN S RXIEN=0
|
---|
| 62 | F S RXIEN=$O(MEDS(RXIEN)) Q:$G(RXIEN)="" D ; FOR EACH MEDICATION IN THE LIST
|
---|
| 63 | . N MED M MED=MEDS(RXIEN)
|
---|
| 64 | . I 'ALL,ACTIVE,$P(MED(100),U,2)'="ACTIVE" QUIT
|
---|
[1433] | 65 | . I 'ALL,PENDING,$P(MED(100),U,2)'="PENDING" QUIT ;OHUM/RUT 3120504 ADDED FOR VALIDATION OF PENDING MEDICATIONS
|
---|
[1428] | 66 | . S MEDCOUNT=MEDCOUNT+1
|
---|
| 67 | . W:$G(DEBUG) "RXIEN IS ",RXIEN,!
|
---|
| 68 | . S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
|
---|
| 69 | . ; K @MAP DO NOT KILL HERE, WAS CLEARED IN C0CMED
|
---|
| 70 | . W:$G(DEBUG) "MAP= ",MAP,!
|
---|
| 71 | . S @MAP@("MEDOBJECTID")="MED"_MEDCOUNT ; MEDCOUNT FOR ID
|
---|
| 72 | . ; S @MAP@("MEDOBJECTID")="MED"_MED(.01) ;Rx Number
|
---|
| 73 | . S @MAP@("MEDISSUEDATETXT")="Issue Date"
|
---|
| 74 | . S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL($P(MED(1),U))
|
---|
| 75 | . S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
|
---|
| 76 | . S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^C0CUTIL($P($G(MED(101)),U))
|
---|
| 77 | . S @MAP@("MEDRXNOTXT")="Prescription Number"
|
---|
| 78 | . S @MAP@("MEDRXNO")=MED(.01)
|
---|
| 79 | . S @MAP@("MEDTYPETEXT")="Medication"
|
---|
| 80 | . S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
---|
| 81 | . S @MAP@("MEDSTATUSTEXT")=$P(MED(100),U,2)
|
---|
| 82 | . S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$P(MED(4),U)
|
---|
| 83 | . S @MAP@("MEDPRODUCTNAMETEXT")=$P(MED(6),U,2)
|
---|
| 84 | . ; 12/30/08: I will be using RxNorm for coding...
|
---|
| 85 | . ; 176.001 is the file for Concepts; 176.003 is the file for
|
---|
| 86 | . ; sources (i.e. for RxNorm Version)
|
---|
| 87 | . ;
|
---|
| 88 | . ; We need the VUID first for the National Drug File entry first
|
---|
| 89 | . ; We get the VUID of the drug, by looking up the VA Product entry
|
---|
| 90 | . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
|
---|
| 91 | . ; Field 99.99 is the VUID.
|
---|
| 92 | . ;
|
---|
| 93 | . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
|
---|
| 94 | . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
|
---|
| 95 | . ; $$GET1^DIQ.
|
---|
| 96 | . ;
|
---|
| 97 | . ; I get the RxNorm name and version from the RxNorm Sources (file
|
---|
| 98 | . ; 176.003), by searching for "RXNORM", then get the data.
|
---|
| 99 | . N MEDIEN S MEDIEN=$P(MED(6),U)
|
---|
| 100 | . D NDF^PSS50(MEDIEN,,,,,"NDF")
|
---|
| 101 | . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
---|
| 102 | . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
---|
| 103 | . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
---|
| 104 | . ;
|
---|
| 105 | . ; NDFIEN is not necessarily defined; it won't be if the drug
|
---|
| 106 | . ; is not matched to the national drug file (e.g. if the drug is
|
---|
| 107 | . ; new on the market, compounded, or is a fake drug [blue pill].
|
---|
| 108 | . ; To protect against failure, I will put an if/else block
|
---|
| 109 | . ;
|
---|
| 110 | . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
---|
| 111 | . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
---|
| 112 | . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
|
---|
| 113 | . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
|
---|
| 114 | . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
|
---|
| 115 | . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
---|
| 116 | . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
---|
| 117 | . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
---|
| 118 | . ;
|
---|
| 119 | . E S (RXNORM,RXNNAME,RXNVER)=""
|
---|
| 120 | . ; End if/else block
|
---|
| 121 | . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
---|
| 122 | . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
---|
| 123 | . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
---|
| 124 | . ;
|
---|
| 125 | . S @MAP@("MEDBRANDNAMETEXT")=MED(6.5)
|
---|
| 126 | . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
---|
| 127 | . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
---|
| 128 | . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
---|
| 129 | . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
---|
| 130 | . ; Units, concentration, etc, come from another call
|
---|
| 131 | . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
---|
| 132 | . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
---|
| 133 | . ; NDF Entry IEN, and VA Product IEN
|
---|
| 134 | . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
---|
| 135 | . ; These have been collected above.
|
---|
| 136 | . N CONCDATA
|
---|
| 137 | . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
---|
| 138 | . ; and this will crash the call. So...
|
---|
| 139 | . I NDFIEN="" S CONCDATA=""
|
---|
| 140 | . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
---|
| 141 | . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
---|
| 142 | . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
---|
| 143 | . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
---|
| 144 | . S @MAP@("MEDQUANTITYVALUE")=MED(7)
|
---|
| 145 | . ; Oddly, there is no easy place to find the dispense unit.
|
---|
| 146 | . ; It's not included in the original call, so we have to go to the drug file.
|
---|
| 147 | . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
---|
| 148 | . ; Node 14.5 is the Dispense Unit
|
---|
| 149 | . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
---|
| 150 | . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
---|
| 151 | . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
---|
| 152 | . ;
|
---|
| 153 | . ; --- START OF DIRECTIONS ---
|
---|
| 154 | . ; Sig data not in any API :-( Oh yes, you can get the whole thing, but...
|
---|
| 155 | . ; we want the compoenents.
|
---|
| 156 | . ; It's in node 6 of ^PSRX(IEN)
|
---|
| 157 | . ; So, here we go again
|
---|
| 158 | . ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
|
---|
| 159 | . ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
|
---|
| 160 | . ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
|
---|
| 161 | . ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
|
---|
| 162 | . ;
|
---|
| 163 | . N DIRNUM S DIRNUM=0 ; Sigline number
|
---|
| 164 | . S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
|
---|
| 165 | . F S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM="" D
|
---|
| 166 | . . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
|
---|
| 167 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
|
---|
| 168 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
|
---|
| 169 | . . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
|
---|
| 170 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
|
---|
| 171 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
|
---|
| 172 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
|
---|
| 173 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
|
---|
| 174 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
|
---|
| 175 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
|
---|
| 176 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
|
---|
| 177 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
|
---|
| 178 | . . ; Invervals... again another call.
|
---|
| 179 | . . ; In the wisdom of the original programmers, the schedule is a free text field
|
---|
| 180 | . . ; However, it gets translated by a call to the administration schedule file
|
---|
| 181 | . . ; to see if that schedule exists.
|
---|
| 182 | . . ; That's the same thing I am going to do.
|
---|
| 183 | . . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
|
---|
| 184 | . . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
|
---|
| 185 | . . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
|
---|
| 186 | . . ; So...
|
---|
| 187 | . . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
|
---|
| 188 | . . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
|
---|
| 189 | . . N INTERVAL
|
---|
| 190 | . . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
|
---|
| 191 | . . E D
|
---|
| 192 | . . . N SUB S SUB=$O(SCHEDATA(0))
|
---|
| 193 | . . . S INTERVAL=SCHEDATA(SUB,2)
|
---|
| 194 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
|
---|
| 195 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
|
---|
| 196 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
|
---|
| 197 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
|
---|
| 198 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
|
---|
| 199 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
|
---|
| 200 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
|
---|
| 201 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
|
---|
| 202 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
|
---|
| 203 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
|
---|
| 204 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
|
---|
| 205 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
|
---|
| 206 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
|
---|
| 207 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
|
---|
| 208 | . . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
|
---|
| 209 | . . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
|
---|
| 210 | . ;
|
---|
| 211 | . ; --- END OF DIRECTIONS ---
|
---|
| 212 | . ;
|
---|
| 213 | . ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
|
---|
| 214 | . S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
|
---|
| 215 | . ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
|
---|
| 216 | . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
|
---|
| 217 | . S @MAP@("MEDRFNO")=MED(9)
|
---|
| 218 | . N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
|
---|
| 219 | . K @RESULT
|
---|
| 220 | . D MAP^C0CXPATH(MINXML,MAP,RESULT)
|
---|
| 221 | . ; MAPPING DIRECTIONS
|
---|
| 222 | . N DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
---|
| 223 | . N DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
---|
| 224 | . D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
---|
| 225 | . D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
|
---|
| 226 | . ; N MDZ1,MDZNA
|
---|
| 227 | . I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
---|
| 228 | . . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
---|
| 229 | . . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
---|
| 230 | . . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
|
---|
| 231 | . . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
---|
| 232 | . I MEDCOUNT=1 D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
|
---|
| 233 | . E D INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
---|
| 234 | N MEDTMP,MEDI
|
---|
| 235 | D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
---|
| 236 | I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
---|
| 237 | . W "MEDICATION MISSING ",!
|
---|
| 238 | . F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
---|
| 239 | Q
|
---|
| 240 | ;
|
---|