Initial Stab at RPMS meds
This commit is contained in:
parent
09da453bbf
commit
8b0d266f4e
43
p/C0CRXNRD.m
43
p/C0CRXNRD.m
|
@ -67,46 +67,5 @@ READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
|
|||
. D ^DIE
|
||||
D CLOSE^%ZISH("FILE")
|
||||
U $P ; reset back to principle device
|
||||
Q
|
||||
;
|
||||
READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
|
||||
I PATH="" QUIT
|
||||
N FILENAME S FILENAME="RXNSAB.RRF"
|
||||
D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
||||
IF POP W "Error reading file..., Please check...",! BREAK
|
||||
F I=1:1 Q:$$STATUS^%ZISH D
|
||||
. U IO
|
||||
. N LINE R LINE
|
||||
. IF $$STATUS^%ZISH QUIT
|
||||
. U $P W I,! U IO ; Write I to the screen, then go back to reading the file
|
||||
. N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SCIT ; Fileman fields numbers below
|
||||
. S VCUI=$P(LINE,"|",1) ; .01
|
||||
. S RCUI=$P(LINE,"|",2) ; 2
|
||||
. S VSAB=$P(LINE,"|",3) ; 3
|
||||
. S RSAB=$P(LINE,"|",4) ; 4
|
||||
. S SON=$P(LINE,"|",5) ; 5
|
||||
. S SF=$P(LINE,"|",6) ; 6
|
||||
. S SVER=$P(LINE,"|",7) ; 7
|
||||
. S SCIT=$P(LINE,"|",25) ; 25
|
||||
. ; Remove embedded "^"
|
||||
. S SCIT=$TR(SCIT,"^")
|
||||
. ; Convert SCIT into an array of 80 characters on each line
|
||||
. ; In each line, chop 80 characters off, reset SCIT to be the rest
|
||||
. N SCITLINE S SCITLINE=$L(SCIT)\80+1
|
||||
. F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
|
||||
. ; Now, construct the FDA array
|
||||
. N RXNFDA
|
||||
. S RXNFDA(176.003,"+"_I_",",.01)=VCUI
|
||||
. S RXNFDA(176.003,"+"_I_",",2)=RCUI
|
||||
. S RXNFDA(176.003,"+"_I_",",3)=VSAB
|
||||
. S RXNFDA(176.003,"+"_I_",",4)=RSAB
|
||||
. S RXNFDA(176.003,"+"_I_",",5)=SON
|
||||
. S RXNFDA(176.003,"+"_I_",",6)=SF
|
||||
. S RXNFDA(176.003,"+"_I_",",7)=SVER
|
||||
. D UPDATE^DIE("","RXNFDA")
|
||||
. I $D(^TMP("DIERR",$J)) U $P BREAK
|
||||
. ; Now, file WP field SCIT
|
||||
. D WP^DIE(176.003,I_",",25,,$NA(SCIT))
|
||||
D CLOSE^%ZISH("FILE")
|
||||
Q
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
CCRMEDS6 ; WV/CCDCCR/SMH - Meds from RPMS;01/10/09
|
||||
;;0.1;CCDCCR;;JUL 16,2008;
|
||||
; 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 and OUTXML are passed by name so globals can be used
|
||||
; MINXML will contain only the medications skeleton of the overall template
|
||||
;
|
||||
; 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(J), one medicine
|
||||
; J is a counter.
|
||||
;
|
||||
; GETRXS^BEHORXFN(ARRAYNAME,DFN,DAYS) will be the the API used.
|
||||
; This API has been developed by Medsphere for IHS for getting
|
||||
; Medications from RPMS. It has most of what we need.
|
||||
; -- ARRAYNAME is passed by name (required)
|
||||
; -- DFN is passed by value (required)
|
||||
; -- DAYS is passed by value (optional; if not passed defaults to 365)
|
||||
;
|
||||
; Return:
|
||||
; ~Type^PharmID^Drug^InfRate^StopDt^RefRem^TotDose^UnitDose^OrderID
|
||||
; ^Status^LastFill^Chronic^Issued^Rx #^Provider^
|
||||
; Status Reason^DEA Handling
|
||||
;
|
||||
N MEDS,MEDS1,MAP
|
||||
D GETRXS^BEHORXFN("MEDS1",DFN,365) ; Days hard set to 365
|
||||
; If MEDS1 is not defined, then no meds
|
||||
I '$D(MEDS1) S @OUTXML@(0)=0 QUIT
|
||||
I DEBUG ZWR MEDS1
|
||||
N MEDCNT S MEDCNT=0 ; Med Count
|
||||
; The next line is a super line. It goes through the array return
|
||||
; and if the first character is a ~, it grabs the line.
|
||||
; That line has the metadata about the med that I need.
|
||||
; The next lines, however many, are the med and the sig.
|
||||
; I won't be using those because I have to get the sig parsed exactly.
|
||||
N J S J="" F S J=$O(MEDS1(J)) Q:J="" I $E(MEDS1(J))="~" S MEDCNT=MEDCNT+1 S MED(MEDCNT)=MEDS1(J)
|
||||
S MEDMAP=$NA(^TMP("GPLCCR",$J,"MEDMAP")) ; this is the variable map
|
||||
S @MEDMAP@(0)=0 ; Initial count of meds
|
||||
F S MEDCNT=$O(MEDS(MEDCNT)) Q:MEDCNT="" D ; for each medication in the list
|
||||
. I DEBUG W "MEDCNT IS ",MEDCNT,!
|
||||
. S MAP=$NA(^TMP("GPLCCR",$J,"MEDMAP",MEDCNT))
|
||||
. ; K @MAP DO NOT KILL HERE, WAS CLEARED IN CCRMEDS
|
||||
. S @MEDMAP@(0)=@MEDMAP@(0)+1 ; increment total meds in var array
|
||||
. I DEBUG W "MAP= ",MAP,!
|
||||
. S @MAP@("MEDOBJECTID")="MED"_MEDCNT ; MEDCNT FOR ID
|
||||
. S @MAP@("MEDISSUEDATETXT")="Issue Date"
|
||||
. S @MAP@("MEDISSUEDATE")=$$FMDTOUTC^CCRUTIL($P(MEDS(MEDCNT),U,13))
|
||||
. S @MAP@("MEDLASTFILLDATETXT")="Last Fill Date"
|
||||
. S @MAP@("MEDLASTFILLDATE")=$$FMDTOUTC^CCRUTIL($P(MEDS(MEDCNT),U,11))
|
||||
. S @MAP@("MEDRXNOTXT")="Prescription Number"
|
||||
. S @MAP@("MEDRXNO")=$P(MEDS(MEDCNT),U,14)
|
||||
. S @MAP@("MEDTYPETEXT")="Medication"
|
||||
. S @MAP@("MEDDETAILUNADORNED")="" ; Leave blank, field has its uses
|
||||
. S @MAP@("MEDSTATUSTEXT")=$P(MEDS(MEDCNT),U,10)
|
||||
. ; Provider only provided in API as text, not DUZ.
|
||||
. ; We need to get DUZ from filman file 52 (Prescription)
|
||||
. ; Field 4;; IEN is Piece 1 of Meds stripped of trailing characters.
|
||||
. S @MAP@("MEDSOURCEACTORID")="ACTORPROVIDER_"_$$GET1^DIQ(52,+$P(MEDS(MEDCNT),U),4,"I")
|
||||
. S @MAP@("MEDPRODUCTNAMETEXT")=$P(MEDS(MEDCNT),U,3)
|
||||
. ; Here we get the RxNorm information
|
||||
. S @MAP@("MEDPRODUCTNAMECODEVALUE")=MED(27)
|
||||
. S @MAP@("MEDPRODUCTNAMECODINGINGSYSTEM")="NDC"
|
||||
. S @MAP@("MEDPRODUCTNAMECODEVERSION")="none"
|
||||
. S @MAP@("MEDBRANDNAMETEXT")=MED(6.5)
|
||||
. N MEDIEN S MEDIEN=$P(MED(6),U)
|
||||
. 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")
|
||||
. ; Documented in the same manual.
|
||||
. D NDF^PSS50(MEDIEN,,,,,"CONC")
|
||||
. N NDFDATA M NDFDATA=^TMP($J,"CONC",MEDIEN)
|
||||
. N NDFIEN S NDFIEN=$P(NDFDATA(20),U)
|
||||
. N VAPROD S VAPROD=$P(NDFDATA(22),U)
|
||||
. N CONCDATA
|
||||
. ; 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)
|
||||
. S @MAP@("MEDFORMTEXT")=$P(CONCDATA,U,1)
|
||||
. S @MAP@("MEDCONCVALUE")=$P(CONCDATA,U,3)
|
||||
. S @MAP@("MEDCONCUNIT")=$P(CONCDATA,U,4)
|
||||
. S @MAP@("MEDSIZETEXT")=$P(NDFDATA(23),U,2)_" "_$P(NDFDATA(24),U,2)
|
||||
. S @MAP@("MEDQUANTITYVALUE")=MED(7)
|
||||
. ; 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
|
||||
. D DATA^PSS50(MEDIEN,,,,,"QTY")
|
||||
. N QTYDATA M QTYDATA=^TMP($J,"QTY",MEDIEN)
|
||||
. S @MAP@("MEDQUANTITYUNIT")=QTYDATA(14.5)
|
||||
. ;
|
||||
. ; --- START OF DIRECTIONS ---
|
||||
. ; Sig data not in any API :-( Oh yes, you can get the whole thing, but...
|
||||
. ; we want the compoenents.
|
||||
. ; It's in node 6 of ^PSRX(IEN)
|
||||
. ; So, here we go again
|
||||
. ; ^PSRX(D0,6,D1,0)= (#.01) DOSAGE ORDERED [1F] ^ (#1) DISPENSE UNITS PER DOSE
|
||||
. ; ==>[2N] ^ (#2) UNITS [3P:50.607] ^ (#3) NOUN [4F] ^ (#4)
|
||||
. ; ==>DURATION [5F] ^ (#5) CONJUNCTION [6S] ^ (#6) ROUTE
|
||||
. ; ==>[7P:51.2] ^ (#7) SCHEDULE [8F] ^ (#8) VERB [9F] ^
|
||||
. ;
|
||||
. N DIRNUM S DIRNUM=0 ; Sigline number
|
||||
. S DIRCNT=0 ; COUNT OF MULTIPLE DIRECTIONS
|
||||
. F S DIRNUM=$O(^PSRX(RXIEN,6,DIRNUM)) Q:DIRNUM="" D
|
||||
. . S DIRCNT=DIRCNT+1 ; INCREMENT DIRECTIONS COUNT
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONDESCRIPTIONTEXT")="" ; This is reserved for systems not able to generate the sig in components.
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEINDICATOR")="1" ; means that we are specifying it. See E2369-05.
|
||||
. . N SIGDATA S SIGDATA=^PSRX(RXIEN,6,DIRNUM,0)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDELIVERYMETHOD")=$P(SIGDATA,U,9)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEVALUE")=$P(SIGDATA,U,1)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDOSEUNIT")=@MAP@("MEDCONCUNIT")
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEVALUE")="" ; For inpatient
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDRATEUNIT")="" ; For inpatient
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDVEHICLETEXT")="" ; For inpatient
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRECTIONROUTETEXT")=$$GET1^DIQ(51.2,$P(SIGDATA,U,7),.01)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDFREQUENCYVALUE")=$P(SIGDATA,U,8)
|
||||
. . ; Invervals... again another call.
|
||||
. . ; In the wisdom of the original programmers, the schedule is a free text field
|
||||
. . ; However, it gets translated by a call to the administration schedule file
|
||||
. . ; to see if that schedule exists.
|
||||
. . ; That's the same thing I am going to do.
|
||||
. . ; The call is AP^PSS51P1(PSSPP,PSSFT,PSSWDIEN,PSSSTPY,LIST,PSSFREQ).
|
||||
. . ; PSSPP is "PSJ" (for some reason, schedules are stored as PSJ, not PSO--
|
||||
. . ; I looked), PSSFT is the name, and list is the ^TMP name to store the data in.
|
||||
. . ; So...
|
||||
. . D AP^PSS51P1("PSJ",$P(SIGDATA,U,8),,,"SCHEDULE")
|
||||
. . N SCHEDATA M SCHEDATA=^TMP($J,"SCHEDULE")
|
||||
. . N INTERVAL
|
||||
. . I $P(SCHEDATA(0),U)=-1 S INTERVAL=""
|
||||
. . E D
|
||||
. . . N SUB S SUB=$O(SCHEDATA(0))
|
||||
. . . S INTERVAL=SCHEDATA(SUB,2)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALVALUE")=INTERVAL
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDINTERVALUNIT")="Minute"
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONVALUE")=$P(SIGDATA,U,5)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDURATIONUNIT")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPRNFLAG")=$P(SIGDATA,U,8)["PRN"
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMOBJECTID")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMTYPETXT")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMDESCRIPTION")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODEVALUE")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGSYSTEM")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMCODINGVERSION")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDPROBLEMSOURCEACTORID")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDSTOPINDICATOR")=""
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDDIRSEQ")=DIRNUM
|
||||
. . N DIRMOD S DIRMOD=$P(SIGDATA,U,6)
|
||||
. . S @MAP@("M","DIRECTIONS",DIRCNT,"MEDMULDIRMOD")=$S(DIRMOD="T":"THEN",DIRMOD="A":"AND",DIRMOD="X":"EXCEPT",1:"")
|
||||
. ;
|
||||
. ; --- END OF DIRECTIONS ---
|
||||
. ;
|
||||
. ; ^PSRX(22,"INS1",1,0)="FOR BLOOD PRESSURE"
|
||||
. S @MAP@("MEDPTINSTRUCTIONS")=$G(^PSRX(RXIEN,"INS1",1,0))
|
||||
. ; ^PSRX(22,"PRC",1,0)="Pharmacist: you must obey my command"
|
||||
. S @MAP@("MEDFULLFILLMENTINSTRUCTIONS")=$G(^PSRX(RXIEN,"PRC",1,0))
|
||||
. S @MAP@("MEDRFNO")=MED(9)
|
||||
. 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")
|
||||
. D:RXIEN=1 CP^GPLXPATH(RESULT,OUTXML) ; First one is a copy
|
||||
. D:RXIEN>1 INSINNER^GPLXPATH(OUTXML,RESULT) ; AFTER THE FIRST, INSERT INNER XML
|
||||
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
|
||||
;
|
Loading…
Reference in New Issue