Index: /qrda/C0Q/trunk/p/C0QQRDA.m
===================================================================
--- /qrda/C0Q/trunk/p/C0QQRDA.m	(revision 1516)
+++ /qrda/C0Q/trunk/p/C0QQRDA.m	(revision 1516)
@@ -0,0 +1,75 @@
+C0QQRDA ; GPL - Quality Reporting QRDA Processing ; 8/1/12 7:34am
+	;;1.0;C0Q;**4**;May 21, 2012;Build 28
+	;Copyright 2012 George Lilly.  Licensed under the terms of the GNU
+	;General Public License See attached copy of the License.
+	;
+	;This program is free software; you can redistribute it and/or modify
+	;it under the terms of the GNU General Public License as published by
+	;the Free Software Foundation; either version 2 of the License, or
+	;(at your option) any later version.
+	;
+	;This program is distributed in the hope that it will be useful,
+	;but WITHOUT ANY WARRANTY; without even the implied warranty of
+	;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	;GNU General Public License for more details.
+	;
+	;You should have received a copy of the GNU General Public License along
+	;with this program; if not, write to the Free Software Foundation, Inc.,
+	;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+	;
+EN
+	N REF S REF=$NAME(^TMP("C0QQRDA",$J))
+	K @REF
+	D WORK(REF)
+	D ZWRITE^C0QUTIL(REF)
+	D PRINTXML(REF)
+	QUIT
+	;
+	; Get measure set iens from Measure Set file
+	; TODO: Populate from a config file.
+WORK(C0QREF)
+	N C0Q1 S C0Q1=$O(^C0Q(201,"B","ED CMS REPORTING MEASURES",""))
+	N C0Q2 S C0Q2=$O(^C0Q(201,"B","STK CMS REPORTING MEASURES",""))
+	N C0Q3 S C0Q3=$O(^C0Q(201,"B","VTE CMS REPORTING MEASURES",""))
+	;
+	; For each measure, write it, count totals and move patients over
+	N C0QX F C0QX="C0Q1","C0Q2","C0Q3" D
+	. Q:'@C0QX
+	. D EN^DDIOL(@C0QX_": "_^C0Q(201,@C0QX,0))
+	. D EN^DDIOL("")
+	. D UPDATE^C0QUPDT(.A,@C0QX)
+	. ;
+	. ; Get QRDA code for Measure Set.
+	. N C0QMSQRDA S C0QMSQRDA=$$GET1^DIQ($$C0QMFN^C0QUPDT(),@C0QX_",","QRDA TEMPLATE ROOT")
+	. N C0QI S C0QI=0 ; Fileman IEN looper
+	. F  S C0QI=$O(^C0Q(201,@C0QX,5,C0QI)) Q:'C0QI  D  ; For each measure
+	. . N C0QMEASUREQRDA S C0QMEASUREQRDA=$$GET1^DIQ($$C0QMMFN^C0QUPDT(),C0QI_","_@C0QX_",",".01:QRDA TEMPLATE ROOT")
+	. . N C0QP S C0QP=0
+	. . F  S C0QP=$O(^C0Q(201,@C0QX,5,C0QI,3,C0QP)) Q:'C0QP  D  ; For each patient in denominator
+	. . . N C0QDFN S C0QDFN=+^(C0QP,0)
+	. . . S @C0QREF@(C0QDFN,C0QMSQRDA,C0QMEASUREQRDA)=""
+	QUIT
+	;
+PRINTXML(C0QREF)
+	N C0QDFN,C0QMS,C0QM S (C0QDFN,C0QMS,C0QM)=""
+	S L=0
+	F  S C0QDFN=$O(@C0QREF@(C0QDFN)) Q:C0QDFN=""  D
+	. D OT("QUALITY")
+	. F  S C0QMS=$O(@C0QREF@(C0QDFN,C0QMS)) Q:C0QMS=""  D
+	. . D OT("MEASURE_SET")
+	. . D TAG("ID",C0QMS)
+	. . D OT("MEASURES")
+	. . F  S C0QM=$O(@C0QREF@(C0QDFN,C0QMS,C0QM)) Q:C0QM=""  D
+	. . . D TAG("MEASURE",C0QM)
+	. . D CT("MEASURES")
+	. . D CT("MEASURE_SET")
+	. D CT("QUALITY")
+	QUIT
+	;
+	; Quick XML stuff
+OT(STR) D L1 W "<"_STR_">",! Q  ; Open Tag
+CT(STR) D L2 W "</"_STR_">",! Q  ; Close Tag
+TAG(NM,CONTENT) D WS W "<"_NM_">",CONTENT,"</"_NM_">",! Q  ; Write whole tag
+L1 D WS S L=L+1 Q  ; Write space and increment
+L2 S L=L-1 D WS Q  ; Decrement and Write space
+WS X "F I=1:1:L W "" """ Q  ; Write Space
