2009-05-21 13:12:11 -04:00
|
|
|
C0CMED3 ; WV/CCDCCR/SMH - Meds: Non-VA/Outside Meds for Vista
|
|
|
|
;;1.0;C0C;;May 19, 2009;
|
2009-01-11 00:37:19 -05:00
|
|
|
;;Last Modified: Sun Jan 11 05:45:03 UTC 2009
|
|
|
|
; Copyright 2009 WorldVistA. Licensed under the terms of the GNU
|
2008-10-13 22:49:45 -04:00
|
|
|
; General Public License See attached copy of the License.
|
|
|
|
;
|
|
|
|
; This program is free software; you can redistribute it and/or modify
|
|
|
|
; it under the terms of the GNU General Public License as published by
|
|
|
|
; the Free Software Foundation; either version 2 of the License, or
|
|
|
|
; (at your option) any later version.
|
|
|
|
;
|
|
|
|
; This program is distributed in the hope that it will be useful,
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
; GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
; You should have received a copy of the GNU General Public License along
|
|
|
|
; with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
;
|
|
|
|
W "NO ENTRY FROM TOP",!
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
EXTRACT(MINXML,DFN,OUTXML,MEDCOUNT) ; Extract medications into provided xml template
|
2008-10-13 22:49:45 -04:00
|
|
|
;
|
2009-03-29 16:19:05 -04:00
|
|
|
; MINXML is the Input XML Template, (passed by name)
|
|
|
|
; DFN is Patient IEN (passed by value)
|
|
|
|
; OUTXML is the resultant XML (passed by name)
|
|
|
|
; MEDCOUNT is the number of Meds extracted so far (passed by reference)
|
2008-10-13 22:49:45 -04:00
|
|
|
;
|
|
|
|
; MEDS is return array from RPC.
|
|
|
|
; MAP is a mapping variable map (store result) for each med
|
|
|
|
; MED is holds each array element from MEDS, one medicine
|
|
|
|
;
|
|
|
|
; Non-VA meds don't have an API. They are stored in file 55, subfile 52.2
|
|
|
|
; Discontinued meds are indicated by the presence of a value in fields
|
|
|
|
; 5 or 6 (STATUS 1 or 2, and DISCONTINUED DATE)
|
|
|
|
; Will use Fileman API GETS^DIQ
|
|
|
|
;
|
|
|
|
N MEDS,MAP
|
2009-01-30 13:07:28 -05:00
|
|
|
K ^TMP($J,"CCDCCR") ; PLEASE DON'T KILL ALL OF ^TMP($J) HERE!!!!
|
2009-03-29 16:19:05 -04:00
|
|
|
N NVA
|
2008-10-13 22:49:45 -04:00
|
|
|
D GETS^DIQ(55,DFN,"52.2*","IE","NVA") ; Output in NVA in FDA array format.
|
|
|
|
; If NVA does not exist, then patient has no non-VA meds
|
|
|
|
I $D(NVA)=0 S @OUTXML@(0)=0 QUIT
|
|
|
|
; Otherwise, we go on...
|
|
|
|
M MEDS=NVA(55.05)
|
|
|
|
; We are done with NVA
|
|
|
|
K NVA
|
|
|
|
;
|
|
|
|
I DEBUG ZWR MEDS
|
|
|
|
N FDAIEN S FDAIEN=0 ; For use in $Order in the MEDS array.
|
2008-10-27 18:01:46 -04:00
|
|
|
N MEDFIRST S MEDFIRST=1 ; FLAG FOR FIRST MED PROCESSED HERE
|
2008-10-27 00:50:32 -04:00
|
|
|
F S FDAIEN=$O(MEDS(FDAIEN)) Q:FDAIEN="" D ; FOR EACH MEDICATION IN THE LIST
|
2008-10-13 22:49:45 -04:00
|
|
|
. N MED M MED=MEDS(FDAIEN)
|
|
|
|
. I MED(5,"I")!MED(6,"I") QUIT ; If disconinued, we don't want to pull it.
|
|
|
|
. S MEDCOUNT=MEDCOUNT+1
|
2009-03-17 19:40:10 -04:00
|
|
|
. S MAP=$NA(^TMP("C0CCCR",$J,"MEDMAP",MEDCOUNT))
|
2008-10-13 22:49:45 -04:00
|
|
|
. N RXIEN S RXIEN=$P(FDAIEN,",") ; First piece of FDAIEN is the number of the med for this patient
|
2008-10-27 20:24:40 -04:00
|
|
|
. I DEBUG W "RXIEN IS ",RXIEN,!
|
|
|
|
. I DEBUG W "MAP= ",MAP,!
|
2008-10-13 22:49:45 -04:00
|
|
|
. S @MAP@("MEDOBJECTID")="MED_OUTSIDE"_MEDCOUNT ; MEDCOUNT FOR ID
|
|
|
|
. S @MAP@("MEDISSUEDATETXT")="Documented Date"
|
|
|
|
. ; Field 6 is "Effective date", and we pull it in timson format w/ I
|
2009-03-15 20:14:48 -04:00
|
|
|
. S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^C0CUTIL(MED(11,"I"),"DT")
|
2008-10-13 22:49:45 -04:00
|
|
|
. ; Med never filled; next 4 fields are not applicable.
|
|
|
|
. S @MAP@("MEDLASTFILLDATETXT")=""
|
|
|
|
. S @MAP@("MEDLASTFILLDATE")=""
|
|
|
|
. S @MAP@("MEDRXNOTXT")=""
|
|
|
|
. S @MAP@("MEDRXNO")=""
|
|
|
|
. S @MAP@("MEDTYPETEXT")="Medication"
|
|
|
|
. S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
|
|
|
. S @MAP@("MEDSTATUSTEXT")="ACTIVE" ; nearest status for pending meds
|
|
|
|
. S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_MED(12,"I")
|
|
|
|
. S @MAP@("MEDPRODUCTNAMETEXT")=MED(.01,"E")
|
|
|
|
. ; NDC is field 31 in the drug file.
|
2008-11-23 16:27:27 -05:00
|
|
|
. ; The actual drug entry in the drug file (MEDIEN) is not necessarily supplied.
|
2008-10-13 22:49:45 -04:00
|
|
|
. ; It' node 1, internal form.
|
|
|
|
. N MEDIEN S MEDIEN=MED(1,"I")
|
2009-01-04 17:55:58 -05:00
|
|
|
. I +MEDIEN D ; start of if/else block
|
|
|
|
. . ; 12/30/08: I will be using RxNorm for coding...
|
|
|
|
. . ; 176.001 is the file for Concepts; 176.003 is the file for
|
|
|
|
. . ; sources (i.e. for RxNorm Version)
|
|
|
|
. . ;
|
|
|
|
. . ; We need the VUID first for the National Drug File entry first
|
|
|
|
. . ; We get the VUID of the drug, by looking up the VA Product entry
|
|
|
|
. . ; (file 50.68) using the call NDF^PSS50, returned in node 22.
|
|
|
|
. . ; Field 99.99 is the VUID.
|
|
|
|
. . ;
|
|
|
|
. . ; We use the VUID to look up the RxNorm in file 176.001; same idea.
|
2009-01-30 13:07:28 -05:00
|
|
|
. . ; Get IEN first using $$FIND1^DIC, then get the RxNorm number by
|
2009-01-04 17:55:58 -05:00
|
|
|
. . ; $$GET1^DIQ.
|
|
|
|
. . ;
|
2009-01-30 13:07:28 -05:00
|
|
|
. . ; I get the RxNorm name and version from the RxNorm Sources (file
|
2009-01-04 17:55:58 -05:00
|
|
|
. . ; 176.003), by searching for "RXNORM", then get the data.
|
|
|
|
. . D NDF^PSS50(MEDIEN,,,,,"NDF")
|
|
|
|
. . N NDFDATA M NDFDATA=^TMP($J,"NDF",MEDIEN)
|
|
|
|
. . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
2009-01-30 13:07:28 -05:00
|
|
|
. . N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
2009-01-04 17:55:58 -05:00
|
|
|
. . ;
|
|
|
|
. . ; NDFIEN is not necessarily defined; it won't be if the drug
|
|
|
|
. . ; is not matched to the national drug file (e.g. if the drug is
|
|
|
|
. . ; new on the market, compounded, or is a fake drug [blue pill].
|
|
|
|
. . ; To protect against failure, I will put an if/else block
|
|
|
|
. . N VUID,RXNIEN,RXNORM,SRCIEN,RXNNAME,RXNVER
|
2009-01-11 02:14:30 -05:00
|
|
|
. . I NDFIEN,$D(^C0CRXN) D ; $Data is for Systems that don't have our RxNorm file yet.
|
2009-01-04 17:55:58 -05:00
|
|
|
. . . S VUID=$$GET1^DIQ(50.68,VAPROD,99.99)
|
|
|
|
. . . S RXNIEN=$$FIND1^DIC(176.001,,,VUID,"VUID")
|
|
|
|
. . . S RXNORM=$$GET1^DIQ(176.001,RXNIEN,.01)
|
|
|
|
. . . S SRCIEN=$$FIND1^DIC(176.003,,"B","RXNORM")
|
|
|
|
. . . S RXNNAME=$$GET1^DIQ(176.003,SRCIEN,6)
|
|
|
|
. . . S RXNVER=$$GET1^DIQ(176.003,SRCIEN,7)
|
|
|
|
. . ;
|
|
|
|
. . E S (RXNORM,RXNNAME,RXNVER)=""
|
|
|
|
. . ; End if/else block
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODEVALUE")=RXNORM
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=RXNNAME
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODEVERSION")=RXNVER
|
|
|
|
. . ;
|
2008-11-23 16:27:27 -05:00
|
|
|
. . S @MAP@("MEDBRANDNAMETEXT")=""
|
|
|
|
. . D DOSE^PSS50(MEDIEN,,,,,"DOSE")
|
|
|
|
. . N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
|
|
|
|
. . S @MAP@("MEDSTRENGTHVALUE")=DOSEDATA(901)
|
|
|
|
. . S @MAP@("MEDSTRENGTHUNIT")=$P(DOSEDATA(902),U,2)
|
|
|
|
. . ; Units, concentration, etc, come from another call
|
|
|
|
. . ; $$CPRS^PSNAPIS which returns dosage-form^va class^strengh^unit
|
|
|
|
. . ; This call takes nodes 1 and 3 of ^PSDRUG(D0,"ND") as parameters
|
|
|
|
. . ; NDF Entry IEN, and VA Product Name
|
|
|
|
. . ; These can be obtained using NDF^PSS50 (IEN,,,,,"SUBSCRIPT")
|
2009-01-04 17:55:58 -05:00
|
|
|
. . ; Documented in the same manual; executed above.
|
2009-01-30 13:07:28 -05:00
|
|
|
. . ;
|
2008-10-13 22:49:45 -04:00
|
|
|
. . ; If a drug was not matched to NDF, then the NDFIEN is gonna be ""
|
|
|
|
. . ; and this will crash the call. So...
|
|
|
|
. . I NDFIEN="" S CONCDATA=""
|
|
|
|
. . E S CONCDATA=$$CPRS^PSNAPIS(NDFIEN,VAPROD)
|
2008-11-23 16:27:27 -05:00
|
|
|
. . S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
|
|
|
. . S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
|
|
|
. . S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
|
|
|
. . S @MAP@("MEDQUANTITYVALUE")="" ; not provided for in Non-VA meds.
|
|
|
|
. . ; Oddly, there is no easy place to find the dispense unit.
|
|
|
|
. . ; It's not included in the original call, so we have to go to the drug file.
|
|
|
|
. . ; That would be DATA^PSS50(IEN,,,,,"SUBSCRIPT")
|
|
|
|
. . ; Node 14.5 is the Dispense Unit
|
2008-10-13 22:49:45 -04:00
|
|
|
. . D DATA^PSS50(MEDIEN,,,,,"QTY")
|
|
|
|
. . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
|
|
|
. . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
2008-11-23 16:27:27 -05:00
|
|
|
. E D
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODEVALUE")=""
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=""
|
|
|
|
. . S @MAP@("MEDPRODUCTNAMECODEVERSION")=""
|
|
|
|
. . S @MAP@("MEDBRANDNAMETEXT")=""
|
|
|
|
. . S @MAP@("MEDSTRENGTHVALUE")=""
|
|
|
|
. . S @MAP@("MEDSTRENGTHUNIT")=""
|
|
|
|
. . S @MAP@("MEDFORMTEXT")=""
|
|
|
|
. . S @MAP@("MEDCONCVALUE")=""
|
|
|
|
. . S @MAP@("MEDCONCUNIT")=""
|
|
|
|
. . S @MAP@("MEDSIZETEXT")=""
|
|
|
|
. . S @MAP@("MEDQUANTITYVALUE")=""
|
|
|
|
. . S @MAP@("MEDQUANTITYUNIT")=""
|
2009-01-04 17:55:58 -05:00
|
|
|
. ; End If/Else
|
2008-10-13 22:49:45 -04:00
|
|
|
. ; --- START OF DIRECTIONS ---
|
|
|
|
. ; Dosage is field 2, route is 3, schedule is 4
|
|
|
|
. ; These are all free text fields, and don't point to any files
|
|
|
|
. ; For that reason, I will use the field I never used before:
|
|
|
|
. ; MEDDIRECTIONDESCRIPTIONTEXT
|
2008-10-27 18:01:46 -04:00
|
|
|
. S DIRCNT=1 ; THERE IS ONLY ONE DIRECTION FOR OUTSIDE MEDS
|
2008-10-13 22:49:45 -04:00
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONDESCRIPTIONTEXT")=MED(2,"E")_" "_MED(3,"E")_" "_MED(4,"E")
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDOSEINDICATOR")="4" ; means look in description text. See E2369-05.
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDELIVERYMETHOD")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDOSEVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDOSEUNIT")=""
|
2008-10-27 00:45:46 -04:00
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDRATEVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDRATEUNIT")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDVEHICLETEXT")=""
|
2008-10-13 22:49:45 -04:00
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDIRECTIONROUTETEXT")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDFREQUENCYVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDINTERVALVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDINTERVALUNIT")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDURATIONVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDURATIONUNIT")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPRNFLAG")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMOBJECTID")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMTYPETXT")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMDESCRIPTION")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODEVALUE")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGSYSTEM")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMCODINGVERSION")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDPROBLEMSOURCEACTORID")=""
|
2008-10-27 00:45:46 -04:00
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDSTOPINDICATOR")=""
|
2008-10-13 22:49:45 -04:00
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDDIRSEQ")=""
|
|
|
|
. S @MAP@("M","DIRECTIONS",1,"MEDMULDIRMOD")=""
|
|
|
|
. ;
|
|
|
|
. ; --- END OF DIRECTIONS ---
|
|
|
|
. ;
|
|
|
|
. ; S @MAP@("MEDPTINSTRUCTIONS","F")="52.41^105"
|
2008-10-27 20:17:14 -04:00
|
|
|
. I $D(MED(10,1)) D ;
|
|
|
|
. . S @MAP@("MEDPTINSTRUCTIONS")=MED(10,1) ; WP Field
|
|
|
|
. E S @MAP@("MEDPTINSTRUCTIONS")=""
|
|
|
|
. I $D(MED(14,1)) D ;
|
|
|
|
. . S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=MED(14,1) ; WP Field
|
|
|
|
. E S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=""
|
2008-10-13 22:49:45 -04:00
|
|
|
. S @MAP@("MEDRFNO")=""
|
2009-03-17 19:40:10 -04:00
|
|
|
. N RESULT S RESULT=$NA(^TMP("C0CCCR",$J,"MAPPED"))
|
2008-10-13 22:49:45 -04:00
|
|
|
. K @RESULT
|
2009-03-17 19:40:10 -04:00
|
|
|
. D MAP^C0CXPATH(MINXML,MAP,RESULT)
|
|
|
|
. ; D PARY^C0CXPATH(RESULT)
|
2008-10-13 22:49:45 -04:00
|
|
|
. ; MAPPING DIRECTIONS
|
|
|
|
. N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
|
|
|
|
. N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
|
2009-03-17 19:40:10 -04:00
|
|
|
. D QUERY^C0CXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
|
|
|
|
. D REPLACE^C0CXPATH(RESULT,"","//Medications/Medication/Directions")
|
2008-10-13 22:49:45 -04:00
|
|
|
. ; N MDZ1,MDZNA
|
|
|
|
. I DIRCNT>0 D ; IF THERE ARE DIRCTIONS
|
|
|
|
. . F MDZ1=1:1:DIRCNT D ; FOR EACH DIRECTION
|
|
|
|
. . . S MDZNA=$NA(@MAP@("M","DIRECTIONS",MDZ1))
|
2009-03-17 19:40:10 -04:00
|
|
|
. . . D MAP^C0CXPATH(DIRXML1,MDZNA,DIRXML2)
|
|
|
|
. . . D INSERT^C0CXPATH(RESULT,DIRXML2,"//Medications/Medication")
|
2008-10-27 20:17:14 -04:00
|
|
|
. I MEDFIRST D ;
|
|
|
|
. . S MEDFIRST=0 ; RESET FIRST FLAG
|
2009-03-17 19:40:10 -04:00
|
|
|
. . D CP^C0CXPATH(RESULT,OUTXML) ; First one is a copy
|
|
|
|
. D:'MEDFIRST INSINNER^C0CXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
|
2008-10-13 22:49:45 -04:00
|
|
|
N MEDTMP,MEDI
|
2009-03-17 19:40:10 -04:00
|
|
|
D MISSING^C0CXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
|
2008-10-13 22:49:45 -04:00
|
|
|
I MEDTMP(0)>0 D ; IF THERE ARE MISSING VARS - MARKED AS @@X@@
|
|
|
|
. W "MEDICATION MISSING ",!
|
|
|
|
. F MEDI=1:1:MEDTMP(0) W MEDTMP(MEDI),!
|
|
|
|
Q
|
|
|
|
;
|