Index: ccr/trunk/p/C0CRXN.m
===================================================================
--- ccr/trunk/p/C0CRXN.m	(revision 303)
+++ ccr/trunk/p/C0CRXN.m	(revision 304)
@@ -31,24 +31,53 @@
  ; "DIFFERENT TEXT" FIELD TO "Y" IF THERE ARE DIFFERENCES
  ; USES SUPPORT ROUTINES FROM C0CRNF.m
- N C0CFDA,C0CA,C0CB,C0CZX ;FDA WORK ARRAY, RNF ARRAYS, AND IEN ITERATOR
- N C0CFVA,C0CFRXN ; CLOSED ROOTS FOR SOURCE FILES
- N C0CF ; CLOSED ROOT FOR DESTINATION FILE
+ ;N C0CFDA,C0CA,C0CB,C0CC,C0CZX ;FDA WORK ARRAY, RNF ARRAYS, AND IEN ITERATOR
+ ;N C0CFVA,C0CFRXN ; CLOSED ROOTS FOR SOURCE FILES
+ ;N C0CF ; CLOSED ROOT FOR DESTINATION FILE
  S C0CVA=$$FILEREF^C0CRNF(176.111) ; C0C PHARMACY VA RXNORM MAPPING FILE
- ;S C0CFRXN=$$FILEREF^C0CRNF(176.001) ; CLOSED ROOT FOR RXNORM CONCEPT FILE
- ;S C0CF=$$FILEREF^C0CRNF(176.112) ; C0C RXNORM VUID MAPPING EXPANSION FILE
- ;W C0CVA,C0CFRXN,C0CF,!
+ S C0CFRXN=$$FILEREF^C0CRNF(176.001) ; CLOSED ROOT FOR RXNORM CONCEPT FILE
+ S C0CF=$$FILEREF^C0CRNF(176.112) ; C0C RXNORM VUID MAPPING EXPANSION FILE
+ W C0CVA,C0CFRXN,C0CF,!
  S C0CZX=0
- S (HASRXN,NORXN,NOVUID)=0 ; INITIALIZE COUNTERS
+ S (HASRXN,NORXN,NOVUID,RXFOUND,RXMATCH,TXTMATCH)=0 ; INITIALIZE COUNTERS
  F  S C0CZX=$O(^C0CCODES(176.111,C0CZX)) Q:+C0CZX=0  D  ; FOR EVERY RECORD
- . D GETN^C0CRNF("C0CA",176.111,C0CZX,"ALL") ;GET THE FIELDS
+ . K C0CA,C0CB,C0CC ; CLEAR ARRAYS
+ . D FIELDS^C0CRNF("C0CC",176.112) ;GET FIELD NAMES FOR OUTPUT FILE
+ . D GETN2^C0CRNF("C0CA",176.111,C0CZX,"","ALL") ;GET THE FIELDS
  . I $$ZVALUE("MEDIATION CODE")="" D
  . . S NORXN=NORXN+1 ;
- . E  S HASRXN=HASRXN+1
+ . E  D  ; PROCESS MEDIATION CODE
+ . . S HASRXN=HASRXN+1
+ . . D SETFDA("MEDIATION CODE",$$ZVALUE("MEDIATION CODE")) ;
  . I $$ZVALUE("VUID")="" D  ; BAD RECORD
  . . S NOVUID=NOVUID+1
- . . ZWR C0CA
+ . . ;D SETFDA("VUID",$$ZVALUE("VUID"))
+ . E  D SETFDA("VUID TEXT",$$ZVALUE("VUID TEXT"))
+ . . ;ZWR C0CA
+ . D GETN2^C0CRNF("C0CB",176.001,$$ZVALUE("VUID"),"VUID","ALL")
+ . I $$ZVALUE("RXCUI","C0CB")'="" D  ; RXNORM FOUND
+ . . S RXFOUND=RXFOUND+1
+ . . I $$ZVALUE("MEDIATION CODE")="" D  ; THIS IS A NEW CODE
+ . . . D SETFDA("MEDIATION CODE",$$ZVALUE("RXCUI","C0CB"))
+ . . . D SETFDA("NEW","Y") ;FLAG RECORD HAS HAVING NEW RXNORM
+ . . W "RXNORM=",$$ZVALUE("RXCUI","C0CB")," ",$$ZVALUE("STR","C0CB"),!
+ . . W "VUID TEXT: ",$$ZVALUE("VUID TEXT"),!
+ . . I $$ZVALUE("VUID TEXT")=$$ZVALUE("STR","C0CB") S TXTMATCH=TXTMATCH+1
+ . . E  D  ;
+ . . . D PUSH^GPLXPATH("NOMATCH",$$ZVALUE("VUID TEXT")_"^"_$$ZVALUE("STR","C0CB"))
+ . . . D SETFDA("RXNORM TEXT",$$ZVALUE("STR","C0CB")) ;
+ . . . D SETFDA("DIFFERENT TEXT","Y") ;FLAG RECORD FOR DIFFERENT TEXT
+ . I $$ZVALUE("MEDIATION CODE")=$$ZVALUE("RXCUI","C0CB") D  ;
+ . . S RXMATCH=RXMATCH+1
+ . . W "VUID=",$$ZVALUE("VUID")," MATCH RXNORM=",$$ZVALUE("MEDIATION CODE"),!
+ . D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
+ . S C0CFDA(176.112,"+"_C0CZX_",",.01)=$$ZVALUE("VUID") ; NEW VUID RECORD
+ . D UPDATE^DIE("","C0CFDA")
+ . I $D(^TMP("DIERR",$J)) U $P BREAK
  W "HAS RXN=",HASRXN,!
  W "NO RXN=",NORXN,!
  W "NO VUID=",NOVUID,!
+ W "RXNORM FOUND=",RXFOUND,!
+ W "RXNORM MATCHES:",RXMATCH,!
+ W "TEXT MATCHES:",TXTMATCH,!
  Q
  ;
@@ -59,7 +88,7 @@
  ;
  N C0CSI,C0CSJ
- S C0CSI=$$ZFILE(C0CSN,"C0CA") ; FILE NUMBER
- S C0CSJ=$$ZFIELD(C0CSN,"C0CA") ; FIELD NUMBER
- S C0CFDA(C0CZX,C0CSI,C0CZX_",",C0CSJ)=C0CSV
+ S C0CSI=$$ZFILE(C0CSN,"C0CC") ; FILE NUMBER
+ S C0CSJ=$$ZFIELD(C0CSN,"C0CC") ; FIELD NUMBER
+ S C0CFDA(C0CSI,"+"_C0CZX_",",C0CSJ)=C0CSV
  Q
 ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
@@ -67,14 +96,24 @@
  ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
  I '$D(ZTAB) S ZTAB="C0CA"
- Q $P(@ZTAB@(ZFN),"^",1)
+ N ZR
+ I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",1)
+ E  S ZR=""
+ Q ZR
 ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
  ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
  ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
  I '$D(ZTAB) S ZTAB="C0CA"
- Q $P(@ZTAB@(ZFN),"^",2)
+ N ZR
+ I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",2)
+ E  S ZR=""
+ Q ZR
+ ;
 ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
  ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
  ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
  I '$D(ZTAB) S ZTAB="C0CA"
- Q $P(@ZTAB@(ZFN),"^",3)
+ N ZR
+ I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",3)
+ E  S ZR=""
+ Q ZR
  ;
