Index: ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.m
===================================================================
--- ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.m	(revision 1617)
+++ ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.m	(revision 1630)
@@ -1,4 +1,4 @@
-C0CRXNLK	; VEN/SMH - RxNorm Lookup Utilities ;2013-04-10  7:01 PM
-	;;1.0;RX NORM;;Apr 25, 2012;Build 99
+C0CRXNLK	; VEN/SMH - RxNorm Lookup Utilities ;2013-11-14  2:43 PM
+	;;2.2;RXNORM FOR VISTA;;Nov 14, 2013;Build 8
 	;(c) Sam Habiel 2013
 	; See accompanying license. Don't use otherwise.
@@ -10,5 +10,5 @@
 	QUIT
 	;
-EXIST(RXN) ; $$ Public - Does this RxNorm CUI exist?
+EXIST(RXN)	; $$ Public - Does this RxNorm CUI exist?
 	; Input: RxNorm CUI by value
 	; Output: Extrinsic
@@ -22,5 +22,6 @@
 	Q ^(IEN)
 	;
-GCN2RXNT ; @TEST - Test Get RxNorm CUI using GCN
+GCN2RXNT	; @TEST - Test Get RxNorm CUI using GCN
+	Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
 	N L F L=1:1 N LN S LN=$T(GCN2RXND+L) Q:LN["<<END>>"  Q:LN=""  D
 	. N GCN S GCN=$P(LN,";",3)
@@ -29,5 +30,5 @@
 	QUIT
 	;
-GCN2RXND ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
+GCN2RXND	; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
 	;;16033;991632
 	;;8208;310429
@@ -35,4 +36,32 @@
 	;;18;197604
 	;;346;884173
+	;;<<END>>
+	;
+	;
+	;
+RXN2GCN(RXNCUI)	; $$ Public - Get GCN(s) given an RxNorm Number
+	; Input: RXNCUI by Value
+	; Output: Caret delimited Extrinsic
+	N GCNS S GCNS=""
+	N I S I=""
+	F  S I=$O(^C0CRXN(176.001,"STX","NDDF","CDC",RXNCUI,I)) Q:I=""  S GCNS=GCNS_+^(I)_U ; + b/c we want the GCN w/o leading zeros
+	S GCNS=$E(GCNS,1,$L(GCNS)-1) ; remove trailing ^
+	Q GCNS
+	;
+RXN2GCNT	; @TEST - Test Get GCN from RXNCUI
+	Q:'$D(^C0CRXN(176.001,"STX","NDDF"))
+	N L F L=1:1 N LN S LN=$T(RXN2GCND+L) Q:LN["<<END>>"  Q:LN=""  D
+	. N RXN S RXN=$P(LN,";",3)
+	. N GCN S GCN=$P(LN,";",4)
+	. D CHKEQ^XTMUNIT($$RXN2GCN(RXN),GCN,"Translation from RXCUI to GCN failed")
+	QUIT
+	;
+	;
+RXN2GCND	; @DATA - Data for Tests ;;RXNORM CUI;Expected GCN; Human Readable Drug name for dear reader
+	;;998689;5145;Acetabulol 200mg tab
+	;;745679;5037;Albuterol Inhaler
+	;;197320;2536;Allopurinol 300mg tab
+	;;993691;3948^46236;Bupropion 75mg tab
+	;;197591;3768;Diazepam 5mg tab
 	;;<<END>>
 	;
@@ -50,5 +79,5 @@
 	Q C0PVUID
 	;
-RXN2VUIT ; @TEST - Get VUIDs given RxNorm values
+RXN2VUIT	; @TEST - Get VUIDs given RxNorm values
 	N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>"  Q:LN=""  D
 	. N RXN S RXN=$P(LN,";",3)
@@ -57,5 +86,5 @@
 	QUIT
 	;
-RXN2VUID ; @DATA - Data items for previous test
+RXN2VUID	; @DATA - Data items for previous test
 	;;991632;4006455
 	;;310429;4002369^4013941
@@ -76,5 +105,5 @@
 	Q O
 	;
-VUI2VAPT ; @TEST - Get VA Product IEN from VUID
+VUI2VAPT	; @TEST - Get VA Product IEN from VUID
 	N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>"  Q:LN=""  D
 	. N VUID S VUID=$P(LN,";",3)
@@ -83,5 +112,5 @@
 	QUIT
 	;
-VUI2VAPD ; @DATA - Data for above test
+VUI2VAPD	; @DATA - Data for above test
 	;;4006455;5932
 	;;4002369;1784
@@ -112,5 +141,5 @@
 	;
 	;
-RXN2MEDS(RXNCUI) ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
+RXN2MEDS(RXNCUI)	; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
 	; Input: SCD RXNCUI
 	; Output; Caret delimited extrinsic
@@ -123,5 +152,5 @@
 	. N VUID S VUID=$P(VUIDS,U,I)
 	. N VAPRODS S VAPRODS=$$VUI2VAP(VUID) ; Get VA Product from VUID (multiple products per VUID)
-	. I '$L(VAPRODS) S ^SAM(RXNCUI)="TELL SAM",DONE=1 QUIT  ; MUST EXIST. Every VUID must have a product to go with it.
+	. I '$L(VAPRODS) S $ECODE=",U-NO-VA-PRODUCT-CORRUPT-NDF,"  ; MUST EXIST. Every VUID must have a product to go with it.
 	. N J F J=1:1:$L(VAPRODS,U) D  Q:DONE
 	. . N VAPROD S VAPROD=$P(VAPRODS,U,J)
@@ -138,4 +167,5 @@
 	;
 FDI2RXNT	; @TEST - Test Get RxNorm CUI for FDB Ingredient/Base
+	Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
 	D CHKEQ^XTMUNIT($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
 	QUIT
@@ -162,5 +192,5 @@
 	Q C0PIEN_"^"_C0P01
 	;
-VIN2VAGT ; @TEST - Test Get VA Generic for VUID Ingredient
+VIN2VAGT	; @TEST - Test Get VA Generic for VUID Ingredient
 	D CHKEQ^XTMUNIT(+$$VIN2VAG(4023636),2832,"$$VIN2VAG failed")
 	QUIT
@@ -202,5 +232,15 @@
 	QUIT RXNS
 	;
-MED2RXN(DA) ; $$ Public - Get RxNorm CUI for Drug
+VUI2GCN(VUID)	; $$ Public - Get GCNs for a given VUID (any VUID type)
+	; Input: VUID by Value
+	; Output: GCNs delimited by ^
+	; TODO: Unit Test
+	N RXNS S RXNS=$$VUI2RXN(VUID)
+	N GCNS S GCNS=""
+	N I F I=1:1:$L(RXNS,U) S GCNS=GCNS_$$RXN2GCN($P(RXNS,U,I))_U
+	S GCNS=$E(GCNS,1,$L(GCNS)-1)
+	QUIT GCNS
+	;
+MED2RXN(DA)	; $$ Public - Get RxNorm CUI for Drug
 	; Input: DA - Medication IEN
 	; Output: RXNCUIs delimited by ^
@@ -212,5 +252,5 @@
 	Q $$VUI2RXN(VUID)
 	;
-MED2SCDN(DA) ; $$ Public - Medication to Semantic Clinical Drug Name
+MED2SCDN(DA)	; $$ Public - Medication to Semantic Clinical Drug Name
 	; Input: DA - Medication IEN
 	; Output: The Canonical Semantic Clinical Drug name
@@ -239,5 +279,5 @@
 	; ---
 	;
-NDC2RXN(NDC) ; $$ Public - Get RxCUI given the NDC
+NDC2RXN(NDC)	; $$ Public - Get RxCUI given the NDC
 	; NB: Will only work if passed NDC is in 5-4-2 format.
 	; Input: NDC By Value in 5-4-2 Format
@@ -246,5 +286,5 @@
 	N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
 	;
-NDC2RXNT ; @TEST - Test Get RxCUI given the NDC
+NDC2RXNT	; @TEST - Test Get RxCUI given the NDC
 	D CHKEQ^XTMUNIT($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
 	QUIT
@@ -252,9 +292,9 @@
 	; ---
 	;
-ISBRAND(RXN) ; $$ Public - Is this RxCUI for a brand drug?
+ISBRAND(RXN)	; $$ Public - Is this RxCUI for a brand drug?
 	; Input: RxCUI
 	; Output: 0 or 1
 	Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
-ISBRANDT ; @TEST - Test Is this RxCUI for a brand drug?
+ISBRANDT	; @TEST - Test Is this RxCUI for a brand drug?
 	D CHKEQ^XTMUNIT($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
 	D CHKEQ^XTMUNIT($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
@@ -263,9 +303,9 @@
 	; ---
 	;
-BR2GEN(RXN) ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
+BR2GEN(RXN)	; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
 	; Input: RxCUI of Brand
 	; Output: RxCUI of Generic
 	Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
-BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
+BR2GENT	; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
 	D CHKEQ^XTMUNIT($$BR2GEN(205535),310384,"$$BR2GEN failed")
 	QUIT
@@ -273,5 +313,5 @@
 	; ---
 	;
-GEN2BR(RXN) ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
+GEN2BR(RXN)	; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
 	N RTN S RTN="" ; Return
 	N I S I="" F  S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I  S RTN=RTN_I_U
@@ -279,5 +319,5 @@
 	Q RTN
 	;
-GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
+GEN2BRT	; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
 	D CHKTF^XTMUNIT($$GEN2BR(310384)[205535,"$$GEN2BR failed")
 	QUIT
@@ -285,5 +325,5 @@
 	; ---
 	;
-RXN2BNS(RXN) ; $$ Public - Get all Brand Names associated with an RXN
+RXN2BNS(RXN)	; $$ Public - Get all Brand Names associated with an RXN
 	N BNS S BNS=""
 	I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
@@ -297,5 +337,16 @@
 	. S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
 	QUIT $E(BNS,1,$L(BNS)-1)
-RXN2BNST ; @TEST - Test Get all Brand Names associated with an RXN
+RXN2BNST	; @TEST - Test Get all Brand Names associated with an RXN
 	D CHKTF^XTMUNIT($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
 	QUIT
+	;
+	; ---
+	;
+RXN2NDC(RXN)	; Get NDC codes for RxNorm code
+	N NDCS S NDCS=""
+	N I F I=0:0 S I=$O(^C0CRXN(176.002,"ASAR","RXNORM","NDC",RXN,I)) Q:'I  S NDCS=NDCS_^(I)_"^"
+	S $E(NDCS,$L(NDCS))=""
+	QUIT NDCS
+RXN2NDCT	; @TEST - Test Get NDC codes for RxNorm code
+	D CHKTF^XTMUNIT($$RXN2NDC(197379)["^"_16714003309,"$$RXN2NDC failed")
+	QUIT
