[1730] | 1 | C0CRXNAD ; VEN/SMH - Add a drug to VISTA from RxNorm;2013-04-19 5:39 PM
|
---|
| 2 | ;;2.5;RXNORM FOR VISTA;;Apr 27, 2016;Build 17
|
---|
[1770] | 3 | ; (C) 2016 Sam Habiel
|
---|
[1730] | 4 | ;
|
---|
[1770] | 5 | N X
|
---|
| 6 | R "Enter GCNSEQNO (with leading zeros): ",X:DTIME,!
|
---|
| 7 | E QUIT
|
---|
| 8 | I X="" QUIT
|
---|
| 9 | I X="^" QUIT
|
---|
| 10 | N URL S URL="https://rxnav.nlm.nih.gov/REST/rxcui.json?idtype=GCN_SEQNO&id="_X
|
---|
| 11 | K ^TMP("C0CJSON",$J),^TMP("C0CARR1",$J)
|
---|
| 12 | N STATUS S STATUS=$$GETURL^XTHC10(URL,1,$NA(^TMP("C0CJSON",$J)))
|
---|
| 13 | I +STATUS'=200 W "ERROR",! QUIT
|
---|
| 14 | D DECODE^VPRJSON($NA(^TMP("C0CJSON",$J)),$NA(^TMP("C0CARR1",$J)))
|
---|
| 15 | N I F I=0:0 S I=$O(^TMP("C0CARR1",$J,"idGroup","rxnormId",I)) Q:'I D
|
---|
| 16 | . N RXN S RXN=^TMP("C0CARR1",$J,"idGroup","rxnormId",I)
|
---|
| 17 | . S URL="https://rxnav.nlm.nih.gov/REST/rxcui/{RXN}/property.json?propName=VUID"
|
---|
| 18 | . N % S %("{RXN}")=RXN
|
---|
| 19 | . S URL=$$REPLACE^XLFSTR(URL,.%)
|
---|
| 20 | . K ^TMP("C0CJSON",$J),^TMP("C0CARR2",$J)
|
---|
| 21 | . N STATUS S STATUS=$$GETURL^XTHC10(URL,1,$NA(^TMP("C0CJSON",$J)))
|
---|
| 22 | . D DECODE^VPRJSON($NA(^TMP("C0CJSON",$J)),$NA(^TMP("C0CARR2",$J)))
|
---|
| 23 | . N DONE S DONE=0
|
---|
| 24 | . N J F J=0:0 S J=$O(^TMP("C0CARR2",$J,"propConceptGroup","propConcept",J)) Q:'J D Q:DONE
|
---|
| 25 | .. N VAPRDVUID S VAPRDVUID=^TMP("C0CARR2",$J,"propConceptGroup","propConcept",J,"propValue")
|
---|
| 26 | .. S DONE=$$ADDDRUG2(RXN,VAPRDVUID)
|
---|
| 27 | QUIT
|
---|
| 28 | ;
|
---|
[1730] | 29 | ADDDRUG(RXN,NDC,BARCODE) ; Public Proc; Add Drug to Drug File
|
---|
| 30 | ; Input: RXN - RxNorm Semantic Clinical Drug CUI by Value. Required.
|
---|
| 31 | ; Input: NDC - Drug NDC by Value. Optional. Pass in 11 digit format without dashes.
|
---|
| 32 | ; Input: BARCODE - Wand Barcode. Optional. Pass exactly as wand reads minus control characters.
|
---|
| 33 | ; Output: Internal Entry Number
|
---|
| 34 | ;
|
---|
| 35 | ; Prelim Checks
|
---|
| 36 | I '$G(RXN) S $EC=",U1," ; Required
|
---|
| 37 | I $L($G(NDC)),$L(NDC)'=11 S $EC=",U1,"
|
---|
| 38 | ;
|
---|
| 39 | ; If RXN refers to a brand drug, get the generic instead.
|
---|
| 40 | I $$ISBRAND^C0CRXNLK(RXN) S RXN=$$BR2GEN^C0CRXNLK(RXN)
|
---|
| 41 | W !,"(debug) RxNorm is "_RXN,!
|
---|
| 42 | ;
|
---|
| 43 | ; Get first VUID for this RxNorm drug
|
---|
| 44 | N VUID S VUID=+$$RXN2VUI^C0CRXNLK(RXN)
|
---|
| 45 | Q:'VUID
|
---|
[1770] | 46 | G NEXT
|
---|
| 47 | ADDDRUG2(RXN,VUID) ;
|
---|
| 48 | NEXT ;
|
---|
| 49 | N PSSZ S PSSZ=1 ; Needed for the drug file to let me in!
|
---|
| 50 | ;
|
---|
[1730] | 51 | W "(debug) VUID for RxNorm CUI "_RXN_" is "_VUID,!
|
---|
| 52 | ;
|
---|
| 53 | ; IEN in 50.68
|
---|
| 54 | N C0XVUID ; For Searching Compound Index
|
---|
| 55 | S C0XVUID(1)=VUID
|
---|
| 56 | S C0XVUID(2)=1
|
---|
| 57 | N F5068IEN S F5068IEN=$$FIND1^DIC(50.68,"","XQ",.C0XVUID,"AMASTERVUID")
|
---|
| 58 | Q:'F5068IEN
|
---|
| 59 | W "F 50.68 IEN (debug): "_F5068IEN,!
|
---|
| 60 | ;
|
---|
| 61 | ; FDA Array
|
---|
| 62 | N C0XFDA
|
---|
| 63 | ;
|
---|
| 64 | ; Name, shortened
|
---|
| 65 | S C0XFDA(50,"+1,",.01)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,40)
|
---|
| 66 | ;
|
---|
| 67 | ; File BarCode as a Synonym for BCMA
|
---|
| 68 | I $L($G(BARCODE)) D
|
---|
| 69 | . S C0XFDA(50.1,"+2,+1,",.01)=BARCODE
|
---|
| 70 | . S C0XFDA(50.1,"+2,+1,",1)="Q"
|
---|
| 71 | ;
|
---|
| 72 | ; Brand Names
|
---|
[1770] | 73 | N BNS S BNS="" ; S BNS=$$RXN2BNS^C0CRXNLK(RXN) ; Brands
|
---|
[1730] | 74 | I $L(BNS) N I F I=1:1:$L(BNS,U) D
|
---|
| 75 | . N IENS S IENS=I+2
|
---|
| 76 | . S C0XFDA(50.1,"+"_IENS_",+1,",.01)=$$UP^XLFSTR($E($P(BNS,U,I),1,40))
|
---|
| 77 | . S C0XFDA(50.1,"+"_IENS_",+1,",1)="T"
|
---|
| 78 | ;
|
---|
| 79 | ; NDC (string)
|
---|
| 80 | I $G(NDC) S C0XFDA(50,"+1,",31)=$E(NDC,1,5)_"-"_$E(NDC,6,9)_"-"_$E(NDC,10,11)
|
---|
| 81 | ;
|
---|
| 82 | ; Dispense Unit (string)
|
---|
| 83 | S C0XFDA(50,"+1,",14.5)=$$GET1^DIQ(50.68,F5068IEN,"VA DISPENSE UNIT")
|
---|
| 84 | ;
|
---|
| 85 | ; National Drug File Entry (pointer to 50.6)
|
---|
| 86 | S C0XFDA(50,"+1,",20)="`"_$$GET1^DIQ(50.68,F5068IEN,"VA GENERIC NAME","I")
|
---|
| 87 | ;
|
---|
| 88 | ; VA Product Name (string)
|
---|
| 89 | S C0XFDA(50,"+1,",21)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,70)
|
---|
| 90 | ;
|
---|
| 91 | ; PSNDF VA PRODUCT NAME ENTRY (pointer to 50.68)
|
---|
| 92 | S C0XFDA(50,"+1,",22)="`"_F5068IEN
|
---|
| 93 | ;
|
---|
| 94 | ; DEA, SPECIAL HDLG (string)
|
---|
| 95 | D ; From ^PSNMRG
|
---|
| 96 | . N CS S CS=$$GET1^DIQ(50.68,F5068IEN,"CS FEDERAL SCHEDULE","I")
|
---|
| 97 | . S CS=$S(CS?1(1"2n",1"3n"):+CS_"C",+CS=2!(+CS=3)&(CS'["C"):+CS_"A",1:CS)
|
---|
| 98 | . S C0XFDA(50,"+1,",3)=CS
|
---|
| 99 | ;
|
---|
| 100 | ; NATIONAL DRUG CLASS (pointer to 50.605) (triggers VA Classification field)
|
---|
| 101 | S C0XFDA(50,"+1,",25)="`"_$$GET1^DIQ(50.68,F5068IEN,"PRIMARY VA DRUG CLASS","I")
|
---|
| 102 | ;
|
---|
| 103 | ; Right Now, I don't file the following which ^PSNMRG does (cuz I don't need them)
|
---|
| 104 | ; - Package Size (derived from NDC/UPN file)
|
---|
| 105 | ; - Package Type (ditto)
|
---|
| 106 | ; - CMOP ID (from $$PROD2^PSNAPIS)
|
---|
| 107 | ; - National Formulary Indicator (from 50.68)
|
---|
| 108 | ;
|
---|
| 109 | ; Next Step is to kill Old OI if Dosage Form doesn't match
|
---|
| 110 | ; Won't do that here as it's assumed any drugs that's added is new.
|
---|
| 111 | ; This happens at ^PSNPSS
|
---|
| 112 | ;
|
---|
| 113 | ; Now add drug to drug file, as we need the IEN for the dosages call.
|
---|
| 114 | N C0XERR,C0XIEN
|
---|
| 115 | D UPDATE^DIE("E","C0XFDA","C0XIEN","C0XERR")
|
---|
| 116 | S:$D(C0XERR) $EC=",U1,"
|
---|
| 117 | ;
|
---|
| 118 | ; Next Step: Kill off old doses and add new ones.
|
---|
| 119 | D EN2^PSSUTIL(C0XIEN(1))
|
---|
| 120 | ;
|
---|
| 121 | ; Mark uses for the Drug; use the undocumented Silent call in PSSGIU
|
---|
| 122 | N PSIUDA,PSIUX ; Expected Input variables
|
---|
| 123 | S PSIUDA=C0XIEN(1),PSIUX="O^Outpatient Pharmacy" D ENS^PSSGIU
|
---|
| 124 | S PSIUDA=C0XIEN(1),PSIUX="U^Unit Dose" D ENS^PSSGIU
|
---|
| 125 | S PSIUDA=C0XIEN(1),PSIUX="X^Non-VA Med" D ENS^PSSGIU
|
---|
| 126 | ;
|
---|
| 127 | ; Get VA Generic text and VA Product pointer for Orderable Item creation plus dosage form information
|
---|
| 128 | N VAGENP S VAGENP=$P(^PSDRUG(C0XIEN(1),"ND"),U) ; VA Generic Pointer
|
---|
| 129 | N VAGEN S VAGEN=$$VAGN^PSNAPIS(VAGENP) ; VA Generic Full name
|
---|
| 130 | N VAPRODP S VAPRODP=$P(^PSDRUG(C0XIEN(1),"ND"),U,3) ; VA Product Pointer
|
---|
| 131 | N DOSAGE S DOSAGE=$$PSJDF^PSNAPIS(0,VAPRODP) ; IEN of dose form in 50.606 ^ Text
|
---|
| 132 | N DOSEPTR S DOSEPTR=$P(DOSAGE,U) ; ditto
|
---|
| 133 | N DOSEFORM S DOSEFORM=$P(DOSAGE,U,2) ;ditto
|
---|
| 134 | ;
|
---|
| 135 | ; Get the (possibly new) Orderable Item Text
|
---|
| 136 | N VAG40 S VAG40=$E(VAGEN,1,40) ; Max length of .01 field
|
---|
| 137 | ;
|
---|
| 138 | ; See if there is an existing orderable item already. If so, populate the Pharmacy Orderable item on drug file.
|
---|
| 139 | N OI S OI=$O(^PS(50.7,"ADF",VAG40,DOSEPTR,""))
|
---|
| 140 | ;
|
---|
| 141 | ; Otherwise, add a new one. (See MCHAN+12^PSSPOIMN)
|
---|
| 142 | I 'OI D
|
---|
| 143 | . N C0XFDA,C0XERR
|
---|
| 144 | . S C0XFDA(50.7,"+1,",.01)=VAG40
|
---|
| 145 | . S C0XFDA(50.7,"+1,",.02)=DOSEPTR
|
---|
| 146 | . D UPDATE^DIE("",$NA(C0XFDA),$NA(OI),$NA(C0XERR))
|
---|
| 147 | . I $D(C0XERR) S $EC=",U1,"
|
---|
| 148 | . S OI=OI(1) ; For ease of use...
|
---|
| 149 | . ; Next two statements: See FIN^PSSPOIM1 and MF^PSSDEE.
|
---|
| 150 | . D EN^PSSPOIDT(OI) ; Update Indexes; activations, etc.
|
---|
| 151 | . D EN2^PSSHL1(OI,"MUP") ; Send HL7 message to CPRS
|
---|
| 152 | ;
|
---|
| 153 | ; Finally, add the orderable Item to the drug file.
|
---|
| 154 | N C0XFDA,C0XERR S C0XFDA(50,C0XIEN(1)_",",2.1)=OI ; Orderable Item
|
---|
| 155 | D FILE^DIE("",$NA(C0XFDA),$NA(C0XERR))
|
---|
| 156 | S:$D(C0XERR) $EC=",U1,"
|
---|
| 157 | ;
|
---|
| 158 | EX QUIT C0XIEN(1)
|
---|