Index: qrda/C0Q/trunk/p/C0QMU12.m
===================================================================
--- qrda/C0Q/trunk/p/C0QMU12.m	(revision 1444)
+++ qrda/C0Q/trunk/p/C0QMU12.m	(revision 1445)
@@ -1,4 +1,4 @@
-C0QMU12	;JJOH/ZAG/GPL - Patient Reminder List ; 5/23/12 5:43pm
-	;;1.0;C0Q;;May 21, 2012;Build 43
+C0QMU12	;JJOH/ZAG/GPL - Patient Reminder List ; 5/30/12 11:28am
+	;;1.0;C0Q;;May 21, 2012;Build 44
 	;
 	;2011 Zach Gonzales<zach@linux.com> - Licensed under the terms of the GNU
@@ -812,4 +812,12 @@
 	. D VITALS
 	D FILE ; FILE THE PATIENT LISTS
+	; 
+	; Now process eRx MU measures for these patients
+	; Check for eRx template and code first; if they exist, run the code
+	; I $D(^C0PX("B","GETMEDS6")),$L($T(SOAP^C0PWS2)) DO  ; smh -cmm for now
+	. N C0QDEBUG S C0QDEBUG=1 ; This causes the code to print out data;
+	. D EN^C0QMUERX($$PATLN^C0QMU12(ZYR_"HasERX")) ; Pass the eRx patient list
+	. K C0QDEBUG ; remove debug variable
+	;
 	N C0QCIEN
 	S ZI=""
Index: qrda/C0Q/trunk/p/C0QMUERX.m
===================================================================
--- qrda/C0Q/trunk/p/C0QMUERX.m	(revision 1444)
+++ qrda/C0Q/trunk/p/C0QMUERX.m	(revision 1445)
@@ -1,3 +1,3 @@
-C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/30/12 9:35am
+C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/30/12 12:40pm
  ;;1.0;C0Q;;May 21, 2012;Build 44
  QUIT  ; No Entry from the top
@@ -280,5 +280,5 @@
  ; Output: (as string) NUMERATOR/DENOMINATOR
  ; 
- I $QS(C0QLIST,0)'="^C0Q" W:$G(C0QDEBUG) "Counting for files other than C0Q(301, not supported ",! QUIT
+ I $QS(C0QLIST,0)'="^C0Q" W:$G(C0QDEBUG) "Counting for files other than C0Q(301, not supported ",! QUIT "0/0"
  ; MEASURE -----------
  ; IEN -----------   |
Index: qrda/C0Q/trunk/p/C0QUPDT.m
===================================================================
--- qrda/C0Q/trunk/p/C0QUPDT.m	(revision 1444)
+++ qrda/C0Q/trunk/p/C0QUPDT.m	(revision 1445)
@@ -1,4 +1,4 @@
-C0QUPDT	; GPL - Quality Reporting List Update Routines ; 5/23/12 5:46pm
-	;;1.0;C0Q;;May 21, 2012;Build 43
+C0QUPDT	; GPL - Quality Reporting List Update Routines ; 5/30/12 3:47pm
+	;;1.0;C0Q;;May 21, 2012;Build 44
 	;Copyright 2009 George Lilly.  Licensed under the terms of the GNU
 	;General Public License See attached copy of the License.
@@ -46,16 +46,27 @@
 	N ZII S ZII=""
 	F  S ZII=$O(C0QM(ZII)) Q:ZII=""  D  ; FOR EACH MEASURE
+	. ; 
+	. ; Special processing for eRx measure.
+	. I $P(C0QM(ZII),U,2)="MU EP ERX" D ERXCOUNT(MSET,ZII) QUIT
+	. ;
+	. ; Otherwise, we go on
 	. N C0QNL,C0QDL,C0QFLTN,C0QFLTD
 	. S C0QFLTN=$P(C0QM(ZII),U,3) ;IEN OF NUMERATOR FILTER LIST
 	. S C0QFLTD=$P(C0QM(ZII),U,4) ; IEN OF DENOMINATOR FILTER LIST
 	. S ZI=$P(C0QM(ZII),U,1) ; IEN OF THE MEASURE IN THE C0Q QUALITY MEAS FILE
+	. ;
+	. ; Numerator
 	. S C0QNL=$$GET1^DIQ($$C0QQFN,ZI_",",1,"I") ; NUMERATOR POINTER
 	. I C0QNL="" D  ; CHECK ALTERNATE LIST
 	. . S C0QNL=$$GET1^DIQ($$C0QQFN,ZI_",",1.1,"I") ; NUMERATOR POINTER
 	. . I C0QNL'="" S C0QNALT=1
+	. I C0QNL="" QUIT  ; No Numerator. Can't perform calculation.--smh
+	. ;
+	. ; Denominator
 	. S C0QDL=$$GET1^DIQ($$C0QQFN,ZI_",",2,"I") ; DENOMINATOR POINTER
 	. I C0QDL="" D  ; CHECK ALTERNATE LIST
 	. . S C0QDL=$$GET1^DIQ($$C0QQFN,ZI_",",2.1,"I") ; DENOMINATOR POINTER
 	. . I C0QDL'="" S C0QDALT=1
+	. I C0QDL="" QUIT  ; No Denominator. Can't perform calcuation.--smh
 	. ;
 	. ; FIRST PROCESS THE NUMERATOR
@@ -161,9 +172,11 @@
 	. . S ZC=ZC+1
 	. I $D(C0QFDA) D UPDIE ; PROCESS
+	. ;
+	. ; File Percentage
 	. N C0QPCT ; PERCENT
 	. D  ;
-	       . . I C0QDCNT>0 D  ;
+	. . I C0QDCNT>0 D  ;
 	. . . S C0QPCT=$J(100*C0QNCNT/C0QDCNT,0,0)
-	       . . E  S C0QPCT=0
+	. . E  S C0QPCT=0
 	. . K C0QFDA
 	. . S C0QFDA($$C0QMMFN(),ZII_","_MSET_",",3)=C0QPCT ; PERCENT
@@ -191,5 +204,5 @@
 	K ZERR
 	D CLEAN^DILF
-	ZWRITE C0QFDA
+	N % S %=$NA(C0QFDA) F  S %=$Q(@%) Q:%=""  W %_"="_@%,! ; smh instead of zwrite
 	D UPDATE^DIE("","C0QFDA","","ZERR")
 	I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST, INVOKE THE ERROR TRAP IF TASKED
@@ -200,2 +213,66 @@
 	Q
 	;
+ERXCOUNT(MSETIEN,MIEN) ; Private Proc; Get eRx and file as Numerator, Denominator, and %
+ ; Inputs:
+ ; MSETIEN - Measurement Set IEN - By Value
+ ; MIEN - Measurement IEN inside the Measurement Set - By Value
+ ; No check is done to see if the caller is sending bad data. Measurement must be
+ ; in a subfile under Measurement Set.
+ ;
+ ; Example of Data we go through in the C0Q Parameter File, so the code below
+ ; will make sense.
+ ; ^C0Q(401,"AMMS",2,1)=""
+ ; ^C0Q(401,"AMMS",2,2)=""
+ ; ^C0Q(401,"AQMS",6,2)=""
+ ; ^C0Q(401,"B","INPATIENT",2)=""
+ ; ^C0Q(401,"B","OUTPATIENT",1)=""
+ ; ^C0Q(401,"MU","MU12",1)=""
+ ; ^C0Q(401,"MU","MU12",2)=""
+ ; ^C0Q(401,"MUTYP","MU12","EP",1)=""
+ ; ^C0Q(401,"MUTYP","MU12","INP",2)=""
+ ;
+ ; Get Parameter year from the Parameters file.
+ ; 1. Get parameter associated with this measurement set from AMMS x-ref (new in C0Q*1*1).
+ N C0QPARAM
+ N % S %="" F  S %=$O(^C0Q(401,"AMMS",MSETIEN,%)) Q:%=""  S C0QPARAM(%)=""
+ ;
+ ; 2. Find the year for each of those--store as value of node; IEN still subscript.
+ N % S %="" F  S %=$O(C0QPARAM(%)) Q:%=""  S C0QPARAM(%)=$$GET1^DIQ(1130580001.401,%_",",.02)
+ ;
+ ; 3. Now make sure that this parameter that point to an Outpatient Parameters
+ ; WARNING: CONFUSING CODE WRITTEN BY ME AHEAD
+ ; The % loop will stop with a valid value if found; % is used in the lines immediately below
+ N % S %="" F  S %=$O(C0QPARAM(%)) Q:%=""  Q:$D(^C0Q(401,"MUTYP",C0QPARAM(%),"EP",%))
+ ;
+ ; 4. If % has a valid IEN (there can be multiple, we take the first), then off we go.
+ ; Otherwise, if it is back to "", we quit.
+ N MUYEAR
+ IF '% W "No suitable parameter found. Cannot determine Measurement Year.",! QUIT
+ ELSE  S MUYEAR=C0QPARAM(%)
+ ; 
+ ; Now, based on the MU year, construct the patient list name that has the eRx data.
+ N LISTNAME S LISTNAME=MUYEAR_"-"_"EP"_"-"_"HasERX"
+ ;
+ ; Call the API in C0QMUERX to get the counts already calculated
+ ; Data is returned NUM/DEN
+ N COUNTS S COUNTS=$$COUNT^C0QMUERX($$PATLN^C0QMU12(LISTNAME))
+ ;
+ ; File the count
+ N NUM S NUM=$P(COUNTS,"/") ; Numerator
+ N DEN S DEN=$P(COUNTS,"/",2) ; Denominator
+ ;
+ ; Prepare FDA
+ N C0QFDA,C0QERR
+ S C0QFDA($$C0QMMFN(),MIEN_","_MSETIEN_",",1.1)=NUM ; Numerator
+ S C0QFDA($$C0QMMFN(),MIEN_","_MSETIEN_",",2.1)=DEN ; Denominator
+ S C0QFDA($$C0QMMFN(),MIEN_","_MSETIEN_",",3)=$S(DEN=0:0,1:$J(100*NUM/DEN,0,0)) ; Percentage; avoid dividing by zero!
+ ;
+ ; File FDA using Filer not updater (editing existing entry only)
+ D FILE^DIE("ET",$NAME(C0QFDA),$NAME(C0QERR)) ; Flags: External, Transaction
+ ;
+ ; If error, print it out
+ I $D(C0QERR) DO
+ . W "Error filing data",!
+ . N % S %=$NAME(C0QERR) F  S %=$Q(@%) Q:%=""  W %_": "_@%,!
+ ;
+ QUIT
