Index: qrda/C0Q/trunk/p/C0QMUERX.m
===================================================================
--- qrda/C0Q/trunk/p/C0QMUERX.m	(revision 1443)
+++ qrda/C0Q/trunk/p/C0QMUERX.m	(revision 1444)
@@ -1,3 +1,3 @@
-C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/30/12 1:48am
+C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/30/12 9:35am
  ;;1.0;C0Q;;May 21, 2012;Build 44
  QUIT  ; No Entry from the top
@@ -26,4 +26,5 @@
  N C0QDEBUG S C0QDEBUG=1
  D EN($$PATLN^C0QMU12("MU12-EP-HasERX"))
+ W $$COUNT($$PATLN^C0QMU12("MU12-EP-HasERX"))
  QUIT
 EN(C0QLIST) ; PEP - Analyze ERx Data and store
@@ -207,6 +208,31 @@
  Q +$G(HASERX)
  ;
-SAVE(C0QLIST,C0QDFN,TYPE,COUNT) ; Proc - Private; Save Count
- ; TODO: Documentation
+SAVE(C0QLIST,C0QDFN,TYPE,COUNT) ; Proc - Private; Save Count in C0Q(301, file
+ ; Layman's Explanation: Save the denominator or numerator for ePrescribing for
+ ; each of the patients in the Subfile for that patient in ^C0Q(301,
+ ; Still hard to understand though! Here's a demo:
+ ; ^C0Q(301,IEN has a subfile under node 1 which stores the patients. E.g.
+ ; ^C0Q(301,48,1,15,0)=91$
+ ; ^C0Q(301,48,1,16,0)=93$
+ ; ^C0Q(301,48,1,17,0)=173$
+ ; 
+ ; I store the numerator and denominator under each of the patients. The numerator
+ ; stands for the number of prescriptions that were electronically transmitted;
+ ; the denominator stands for the numbers of prescriptions that COULD HAVE BEEN
+ ; electronically transmitted. End result for Patient 173 is as follows:
+ ; ^C0Q(301,48,1,17,0)=173
+ ; ^C0Q(301,48,1,17,1,0)="^1130580001.3111^2^2"
+ ; ^C0Q(301,48,1,17,1,1,0)="ERXDEN^0"
+ ; ^C0Q(301,48,1,17,1,2,0)="ERXNUM^0"
+ ; ^C0Q(301,48,1,17,1,"B","ERXDEN",1)=""
+ ; ^C0Q(301,48,1,17,1,"B","ERXNUM",2)=""
+ ;
+ ; Subroutine COUNT (below) goes and counts the data
+ ; 
+ ; Params:
+ ; C0QLIST (by val): "B" x-ref where patients are located. Only supports ^C0Q(301, file.
+ ; C0QDFN (by val): Patient DFN for whom to file data.
+ ; TYPE (by val): Either ERXDEN or ERXNUM for eRx Denominator or eRx Numerator
+ ; COUNT (by val): The number to save
  ;
  ; First, QUIT if this isn't a Quality Measures List?
@@ -246,5 +272,56 @@
  I $D(C0QERR) DO
  . W "Error in filing data",!
- . S %=$NAME(C0QERR) F  S %=$Q(@%) Q:%=""  W %_": "_@%,!
+ . N % S %=$NAME(C0QERR) F  S %=$Q(@%) Q:%=""  W %_": "_@%,!
  ;
  QUIT
+ ;
+COUNT(C0QLIST) ; $$ - Private; Count Numerator and Denominator for a Patient List
+ ; Input: C0QLIST - Pass by Value - Patient Listing B index (only C0Q(301,IEN,1,"B", listing is supported)
+ ; Output: (as string) NUMERATOR/DENOMINATOR
+ ; 
+ I $QS(C0QLIST,0)'="^C0Q" W:$G(C0QDEBUG) "Counting for files other than C0Q(301, not supported ",! QUIT
+ ; MEASURE -----------
+ ; IEN -----------   |
+ ; L1 ------|    |   |
+ ;          V    V   V
+ ; ^C0Q(301,48,1,2,1,1,0)="ERXDEN^0"
+ ; ^C0Q(301,48,1,2,1,2,0)="ERXNUM^0"
+ ; ^C0Q(301,48,1,2,1,"B","ERXDEN",1)=""
+ ; ^C0Q(301,48,1,2,1,"B","ERXNUM",2)=""
+ ; ^C0Q(301,48,1,2,1,"B"
+ W:$G(C0QDEBUG) "DFN",?20,"Denominator",?40,"Numerator",!
+ ;
+ N L1 S L1=$QS(C0QLIST,2) ; Top Level IEN
+ ;
+ N DENTOT,NUMTOT S (DENTOT,NUMTOT)=0 ; Denominator Total, Numerator Total
+ ;
+ N C0QDFN S C0QDFN=0 ; Walker through B index
+ F  S C0QDFN=$O(^C0Q(301,L1,1,"B",C0QDFN)) Q:C0QDFN=""  DO
+ . N IEN S IEN=$O(^(C0QDFN,"")) ; naked naked - get IEN from B index
+ . W:$G(C0QDEBUG) C0QDFN
+ . ;
+ . ; Denom Processing
+ . N DENIEN S DENIEN=$O(^C0Q(301,L1,1,IEN,1,"B","ERXDEN","")) ; Denom IEN
+ . N DEN S DEN=$S(DENIEN:$P(^C0Q(301,L1,1,IEN,1,DENIEN,0),U,2),1:"N/A") ; Denominator
+ . W:$G(C0QDEBUG) ?20,DEN
+ . S DENTOT=DENTOT+DEN ; Total it up (N/A becomes zero)
+ . ;
+ . N NUMIEN S NUMIEN=$O(^C0Q(301,L1,1,IEN,1,"B","ERXNUM","")) ; Numerator IEN
+ . N NUM S NUM=$S(NUMIEN:$P(^C0Q(301,L1,1,IEN,1,NUMIEN,0),U,2),1:"N/A") ; Numerator
+ . W:$G(C0QDEBUG) ?40,NUM
+ . S NUMTOT=NUMTOT+NUM ; Total it up (N/A becomes zero)
+ . ;
+ . w:$G(C0QDEBUG) !
+ ;
+ ; Write the totals
+ D:$G(C0QDEBUG)
+ . W ?20,"==="
+ . W ?40,"==="
+ . W !
+ . ;
+ . W ?20,DENTOT
+ . W ?40,NUMTOT
+ . W !
+ ;
+ ; Quit with Numeartor/Denominator
+ QUIT NUMTOT_"/"_DENTOT
