VistA-ccr/p/CCRMEDS3.m

188 lines
8.6 KiB
Mathematica
Raw Normal View History

2008-10-13 22:49:45 -04:00
CCRMEDS3 ; WV/CCDCCR/SMH - CCR/CCD PROCESSING FOR MEDICATIONS - Outside_non-VA Meds;10/13/08
;;0.1;CCDCCR;;;
; Copyright 2008 WorldVistA. Licensed under the terms of the GNU
; 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
;
EXTRACT(MINXML,DFN,OUTXML) ; EXTRACT MEDICATIONS INTO PROVIDED XML TEMPLATE
;
; MINXML is the Input XML Template, passed by name
; DFN is Patient IEN
; OUTXML is the resultant XML.
;
; 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
K ^TMP($J),NVA
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 00:45:46 -04:00
S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP"))
2008-10-13 22:49:45 -04:00
N MEDCOUNT S MEDCOUNT=@MEDMAP@(0) ; We already have meds in the 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
. S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCOUNT))
. S @MEDMAP@(0)=@MEDMAP@(0)+1 ; INCREMENT TOTAL MEDS IN VAR ARRAY
. 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
. S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL(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.
. ; The actual drug entry in the drug file is not necessarily supplied.
. ; It' node 1, internal form.
. N MEDIEN S MEDIEN=MED(1,"I")
. S @MAP@("MEDPRODUCTNAMECODEVALUE")=$S($L(MEDIEN):$$GET1^DIQ(50,MEDIEN,31,"E"),1:"")
. S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")=$S($L(MEDIEN):"NDC",1:"")
. S @MAP@("MEDPRODUCTNAMECODEVERSION")=$S($L(MEDIEN):"none",1:"")
. S @MAP@("MEDBRANDNAMETEXT")=""
. I $L(MEDIEN) D DOSE^PSS50(MEDIEN,,,,,"DOSE")
. I $L(MEDIEN) N DOSEDATA M DOSEDATA=^TMP($J,"DOSE",MEDIEN)
. S @MAP@("MEDSTRENGTHVALUE")=$S($L(MEDIEN):DOSEDATA(901),1:"")
2008-10-27 20:53:44 -04:00
. S @MAP@("MEDSTRENGTHUNIT")=$S($L(DOSEDATA(902))>0:$P(DOSEDATA(902),U,2),1:"") SAM PLEASE CHECK
2008-10-13 22:49:45 -04:00
. ; 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")
. ; Documented in the same manual.
. N NDFDATA,CONCDATA
. I $L(MEDIEN) D
. . D NDF^PSS50(MEDIEN,,,,,"CONC")
. . M NDFDATA=^TMP($J,"CONC",MEDIEN)
. . N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
. . N VAPROD S VAPROD=$P(NDFDATA(22),U)
. . ; 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)
. E S (NDFDATA,CONCDATA)="" ; This line is defensive programming to prevent undef errors.
. S @MAP@("MEDFORMTEXT")=$S($L(MEDIEN):$P(CONCDATA,U,1),1:"")
. S @MAP@("MEDCONCVALUE")=$S($L(MEDIEN):$P(CONCDATA,U,3),1:"")
. S @MAP@("MEDCONCUNIT")=$S($L(MEDIEN):$P(CONCDATA,U,4),1:"")
. S @MAP@("MEDSIZETEXT")=$S($L(MEDIEN):$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2),1:"")
. 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
. I $L(MEDIEN) D
. . D DATA^PSS50(MEDIEN,,,,,"QTY")
. . N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
. . S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
2008-10-27 20:24:40 -04:00
. E S @MAP@("MEDQUANTITYUNIT")=""
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")=""
. N RESULT S RESULT=$NA(^TMP("GPLCCR",$J,"MAPPED"))
. K @RESULT
. D MAP^GPLXPATH(MINXML,MAP,RESULT)
. ; D PARY^GPLXPATH(RESULT)
. ; MAPPING DIRECTIONS
. N MEDDIR1,DIRXML1 S DIRXML1="MEDDIR1" ; VARIABLE AND NAME VARIABLE TEMPLATE
. N MEDDIR2,DIRXML2 S DIRXML2="MEDDIR2" ; VARIABLE AND NAME VARIABLE RESULT
. D QUERY^GPLXPATH(MINXML,"//Medications/Medication/Directions",DIRXML1)
. D REPLACE^GPLXPATH(RESULT,"","//Medications/Medication/Directions")
. ; 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))
. . . D MAP^GPLXPATH(DIRXML1,MDZNA,DIRXML2)
. . . D INSERT^GPLXPATH(RESULT,DIRXML2,"//Medications/Medication")
2008-10-27 20:17:14 -04:00
. I MEDFIRST D ;
. . S MEDFIRST=0 ; RESET FIRST FLAG
. . D CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
. D:'MEDFIRST INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER FIRST, INSERT INNER XML
2008-10-13 22:49:45 -04:00
N MEDTMP,MEDI
D MISSING^GPLXPATH(OUTXML,"MEDTMP") ; SEARCH XML FOR MISSING VARS
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
;