Index: qrda/C0Q/trunk/p/C0QUPDT.m
===================================================================
--- qrda/C0Q/trunk/p/C0QUPDT.m	(revision 1445)
+++ qrda/C0Q/trunk/p/C0QUPDT.m	(revision 1572)
@@ -1,4 +1,4 @@
-C0QUPDT	; GPL - Quality Reporting List Update Routines ; 5/30/12 3:47pm
-	;;1.0;C0Q;;May 21, 2012;Build 44
+C0QUPDT	; GPL - Quality Reporting List Update Routines ; 10/10/12 11:36am
+	;;1.0;C0Q;**1**;May 21, 2012;Build 32
 	;Copyright 2009 George Lilly.  Licensed under the terms of the GNU
 	;General Public License See attached copy of the License.
@@ -48,8 +48,8 @@
 	. ; 
 	. ; Special processing for eRx measure.
-	. I $P(C0QM(ZII),U,2)="MU EP ERX" D ERXCOUNT(MSET,ZII) QUIT
+	. I $$GET1^DIQ(1130580001.101,+C0QM(ZII)_",",4,"I")="E" D ERXCOUNT(MSET,ZII) Q
 	. ;
 	. ; Otherwise, we go on
-	. N C0QNL,C0QDL,C0QFLTN,C0QFLTD
+	. N C0QNL,C0QDL,C0QFLTN,C0QFLTD,C0QNALT ; VEN/SMH - line changed in *5 
 	. S C0QFLTN=$P(C0QM(ZII),U,3) ;IEN OF NUMERATOR FILTER LIST
 	. S C0QFLTD=$P(C0QM(ZII),U,4) ; IEN OF DENOMINATOR FILTER LIST
@@ -204,5 +204,5 @@
 	K ZERR
 	D CLEAN^DILF
-	N % S %=$NA(C0QFDA) F  S %=$Q(@%) Q:%=""  W %_"="_@%,! ; smh instead of zwrite
+	D ZWRITE^C0QUTIL("C0QFDA")
 	D UPDATE^DIE("","C0QFDA","","ZERR")
 	I $D(ZERR) S ZZERR=ZZERR ; ZZERR DOESN'T EXIST, INVOKE THE ERROR TRAP IF TASKED
@@ -213,66 +213,71 @@
 	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
+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
+	; 
+	; Optional Symtab input: C0QDEBUG to print out debug messages to STDOUT.
+	; ZEXCEPT: C0QDEBUG ; For Dr. Ivey's parser.
+	;
+	; No check is done to see if the caller is sending bad data. Measurement must be
+	; in a subfile under Measurement Set.
+	;
+	W:$G(C0QDEBUG) "Processing E-Prescribing Counts",!
+	; 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
