Now code add drugs to drug file. Still needs lot more work.

This commit is contained in:
sam 2013-04-11 01:50:51 +00:00
parent ed0fe5f0d1
commit 2de37324e5
2 changed files with 112 additions and 8 deletions

View File

@ -1,4 +1,4 @@
C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-02-21 4:52 PM
C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-04-10 4:23 PM
;;1.1;FILEMAN TRIPLE STORE;;
;
; Get all graphs
@ -25,6 +25,7 @@ PROGRAPH(G) ; Process Graph (i.e. Patient)
SET PARAM("DOB")=$$DOB(DEM)
SET PARAM("MRN")=$$MRN(DEM)
NEW RETURN
WRITE !!,PARAM("NAME"),!
D ADDPT(.RETURN,.PARAM)
N DFN S DFN=$P(RETURN(1),U,2)
I DFN<1 S $EC=",U1," ; Debug.Assert that patient is added.

View File

@ -1,4 +1,4 @@
C0XPT3 ;ISI/MLS,VEN/SMH -- MEDS IMPORT ;2013-02-22 3:38 PM
C0XPT3 ;ISI/MLS,VEN/SMH -- MEDS IMPORT ;2013-04-10 6:54 PM
;;1.0;FILEMAN TRIPLE STORE;;Jun 26,2012;Build 29
;
MEDS(G,DFN) ; Private Proc; Extract Medication Data from a Patient's Graph
@ -6,6 +6,14 @@ MEDS(G,DFN) ; Private Proc; Extract Medication Data from a Patient's Graph
K ^TMP($J,"MEDS")
D ONETYPE^C0XGET3($NA(^TMP($J,"MEDS")),G,"sp:Medication")
;
; PRIVATE TO SAM -- PRIVATE TO SAM -- PRIVATE TO SAM
; Delete the old drugs for this patient
N DIK,DA
S DIK="^PS(55,",DA=DFN D ^DIK ; bye bye
S DIK="^PSRX(" F DA=0:0 S DA=$O(^PSRX(DA)) Q:'DA D:$P(^(DA,0),U,2)=DFN ^DIK
S DIK="^OR(100," F DA=0:0 S DA=$O(^OR(100,DA)) Q:'DA D:+$P(^(DA,0),U,2)=DFN ^DIK
; PRIVATE TO SAM -- PRIVATE TO SAM -- PRIVATE TO SAM
;
; For each medication (C0XI = COUNTER; S = Medication Node as Subject)
N C0XI,S F C0XI=0:0 S C0XI=$O(^TMP($J,"MEDS",C0XI)) Q:'C0XI S S=^(C0XI) DO MED1(G,S,DFN)
K ^TMP($J,"MEDS")
@ -38,7 +46,7 @@ MED1(G,S,DFN) ; Private Procedure; Process each medication in Graph.
N RXN S RXN=$$GSPO1^C0XGET3(G,S,"sp:drugName.sp:code"),RXN=$P(RXN,"/",$L(RXN,"/")) ; RxNorm Code
N DN S DN=$$GSPO1^C0XGET3(G,S,"sp:drugName.dcterms:title") ; Drug Name
;
W S," ",FVALUE_FUNIT," ",DOSE," ",DUNIT," ",INST," ",DN,!
W S," ",FVALUE_FUNIT," ",DOSE," ",DUNIT," ",INST," ",DN," ",RXN,!
;
; 6. Get Fill Dates
N FULF ; Fulfillments
@ -60,7 +68,7 @@ MED1(G,S,DFN) ; Private Procedure; Process each medication in Graph.
. S FILLS(RXN,FILLDATE,"sp:quantityDispensed.sp:value")=$$GSPO1^C0XGET3(G,S,"sp:quantityDispensed.sp:value")
. S FILLS(RXN,FILLDATE,"sp:quantityDispensed.sp:unit")=$TR($$GSPO1^C0XGET3(G,S,"sp:quantityDispensed.sp:unit"),"{}")
;
; ZWRITE:$D(FILLS) FILLS
ZWRITE:$D(FILLS) FILLS
;
D
. N FILDT,FILQTY,FILDAYS
@ -80,10 +88,17 @@ PREP(DFN,RXN,INST,FILDT,FILQTY,FILDAYS,FILLS) ;
; 5. Original fill doesn't have a dispense comment
; 6. Coded sig (FVALUE, FUNIT, DOSE, DUNIT)
; 7. Fill label log section of Rx? Maybe not.
;
I '$$EXIST^C0CRXNLK(RXN) S $EC=",U1," ; Invalid RxNorm code passed.
;
N ORZPT,PSODFN S (ORZPT,PSODFN)=DFN ;"" ;POINTER TO PATIENT FILE (#2)
N PNTSTAT S PNTSTAT=20 ; NON-VA ;RX PATIENT STATUS FILE (#53)
N PROV S PROV=$$NP^C0XPT0() ;NEW PERSON FILE (#200)
N PSODRUG S PSODRUG=94558 ;POINTER TO DRUG FILE (#50) ; TODO: HARDCODED; RXN
I $$ISBRAND^C0CRXNLK(RXN) S RXN=$$BR2GEN^C0CRXNLK(RXN) ; Get Generic Drug for Brand
N LOCALDRUG S LOCALDRUG=+$$RXN2MEDS^C0CRXNLK(RXN)
I 'LOCALDRUG S LOCALDRUG=$$ADDDRUG(RXN)
W "(debug) Local Drug IEN: "_LOCALDRUG,!
N PSODRUG S PSODRUG=LOCALDRUG ;POINTER TO DRUG FILE (#50) ; TODO: HARDCODED; RXN
S PSODRUG("DEA")=$P($G(^PSDRUG(PSODRUG,0)),U,3)
N QTY S QTY=FILQTY ; NUMBER ;0;7 NUMBER (Required)
N DAYSUPLY S DAYSUPLY=FILDAYS ;NUMBER ; 0;8 NUMBER (Required);
@ -108,7 +123,6 @@ PREP(DFN,RXN,INST,FILDT,FILQTY,FILDAYS,FILLS) ;
N LDISPDT S LDISPDT=FILLDT ; 3;1 DATE
N REASON S REASON="E" ;Activity log ; SET ([E]dit)
N INIT S INIT=.5 ;NEW PERSON FILE (#200)
N COM S COM="Oupatient medication order." ;TEXT
N SIG S SIG=INST ;#51,.01
;
CREATE ; fall through
@ -119,7 +133,7 @@ CREATE ; fall through
N RXNUM S RXNUM=PSONEW("RX #") ; Rx Number, again...
;
L +^PSRX(0):0 ; Lock zero node while we get the record.
N PSOIEN S PSOIEN=$P($G(^PSRX(0)),"^",3)+1 ; Next available IEN
N PSOIEN S PSOIEN=$O(^PSRX(" "),-1)+1 ; Next available IEN
I $D(^PSRX(PSOIEN)) S $EC=",U1," ; Next number not available. File issue.
S $P(^PSRX(0),U,3)=PSOIEN ; Reset next available number.
S $P(^PSRX(PSOIEN,0),"^",1)=RXNUM ; 0;1 FREE TEXT (Required)
@ -159,7 +173,7 @@ CREATE ; fall through
. S $P(^PSRX(PSOIEN,"A",C0XREFCT+1,0),"^",2)="N" ;SET ; Dispensed using external interface
. S $P(^PSRX(PSOIEN,"A",C0XREFCT+1,0),"^",3)=INIT ;NEW PERSON FILE (#200)
. S $P(^PSRX(PSOIEN,"A",C0XREFCT+1,0),"^",4)=0 ;NUMBER - RX REFERENCE
. S $P(^PSRX(PSOIEN,"A",C0XREFCT+1,0),"^",5)="Imported from Smart" ;TEXT
. S $P(^PSRX(PSOIEN,"A",C0XREFCT+1,0),"^",5)="Imported from Smart"
. ;
. Q:C0XFILL=FILDT ; Don't add refill data for first fill!
. ;
@ -219,3 +233,92 @@ F525 ;UPDATE SUSPENSE FILE
S DIC="^PS(52.5,",DIC(0)="L",DLAYGO=52.5,DIC("DR")=".02///"_FDT_";.03////"_$P(^PSRX(PSOIEN,0),"^",2)_";.04////"_TYPE_";.05///0;.06////"_DIV_";2///0" K DD,D0 D FILE^DICN K DD,D0
Q
;
ADDDRUG(RXN,NDC,BARCODE) ; Public Proc; Add Drug to Drug File
; Input: RXN - RxNorm Semantic Clinical Drug CUI by Value. Required.
; Input: NDC - Drug NDC by Value. Optional. Pass in 11 digit format without dashes.
; Input: BARCODE - Wand Barcode. Optional. Pass exactly as wand reads minus control characters.
; Output: None.
;
; Prelim Checks
I '$G(RXN) S $EC=",U1," ; Required
I $L($G(NDC)),$L(NDC)'=11 S $EC=",U1,"
;
N PSSZ S PSSZ=1 ; Needed for the drug file to let me in!
;
; If RXN refers to a brand drug, get the generic instead.
I $$ISBRAND^C0CRXNLK(RXN) S RXN=$$BR2GEN^C0CRXNLK(RXN)
W !,"(debug) RxNorm is "_RXN,!
;
; Get first VUID for this RxNorm drug
N VUID S VUID=+$$RXN2VUI^C0CRXNLK(RXN)
Q:'VUID
W "(debug) VUID for RxNorm CUI "_RXN_" is "_VUID,!
;
; IEN in 50.68
N C0XVUID ; For Searching Compound Index
S C0XVUID(1)=VUID
S C0XVUID(2)=1
N F5068IEN S F5068IEN=$$FIND1^DIC(50.68,"","XQ",.C0XVUID,"AMASTERVUID")
Q:'F5068IEN
W "F 50.68 IEN (debug): "_F5068IEN,!
;
; FDA Array
N C0XFDA
;
; Name, shortened
S C0XFDA(50,"+1,",.01)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,40)
;
; File BarCode as a Synonym for BCMA
I $L($G(BARCODE)) D
. S C0XFDA(50.1,"+2,+1,",.01)=BARCODE
. S C0XFDA(50.1,"+2,+1,",1)="Q"
;
; Brand Names
N BNS S BNS=$$RXN2BNS^C0CRXNLK(RXN) ; Brands
I $L(BNS) N I F I=1:1:$L(BNS,U) D
. N IENS S IENS=I+2
. S C0XFDA(50.1,"+"_IENS_",+1,",.01)=$$UP^XLFSTR($E($P(BNS,U,I),1,40))
. S C0XFDA(50.1,"+"_IENS_",+1,",1)="T"
;
; NDC (string)
I $G(NDC) S C0XFDA(50,"+1,",31)=$E(NDC,1,5)_"-"_$E(NDC,6,9)_"-"_$E(NDC,10,11)
;
; Dispense Unit (string)
S C0XFDA(50,"+1,",14.5)=$$GET1^DIQ(50.68,F5068IEN,"VA DISPENSE UNIT")
;
; National Drug File Entry (pointer to 50.6)
S C0XFDA(50,"+1,",20)="`"_$$GET1^DIQ(50.68,F5068IEN,"VA GENERIC NAME","I")
;
; VA Product Name (string)
S C0XFDA(50,"+1,",21)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,70)
;
; PSNDF VA PRODUCT NAME ENTRY (pointer to 50.68)
S C0XFDA(50,"+1,",22)="`"_F5068IEN
;
; DEA, SPECIAL HDLG (string)
D ; From ^PSNMRG
. N CS S CS=$$GET1^DIQ(50.68,F5068IEN,"CS FEDERAL SCHEDULE","I")
. S CS=$S(CS?1(1"2n",1"3n"):+CS_"C",+CS=2!(+CS=3)&(CS'["C"):+CS_"A",1:CS)
. S C0XFDA(50,"+1,",3)=CS
;
; NATIONAL DRUG CLASS (pointer to 50.605) (triggers VA Classification field)
S C0XFDA(50,"+1,",25)="`"_$$GET1^DIQ(50.68,F5068IEN,"PRIMARY VA DRUG CLASS","I")
;
; Right Now, I don't file the following which ^PSNMRG does (cuz I don't need them)
; - Package Size (derived from NDC/UPN file)
; - Package Type (ditto)
; - CMOP ID (from $$PROD2^PSNAPIS)
; - National Formulary Indicator (from 50.68)
;
; Next Step is to kill Old OI if Dosage Form doesn't match
; Won't do that here as it's assumed any drugs that's added is new.
; This happens at ^PSNPSS
;
; Next Step: Kill off old doses and add new ones. We need to to that.
; TODO: Add doses. Happens at EN1^PSSUTIL.
N C0XERR,C0XIEN
D UPDATE^DIE("E","C0XFDA","C0XIEN","C0XERR")
;
S:$D(C0XERR) $EC=",U1,"
;
QUIT C0XIEN(1)