Index: /qrda/C0Q/trunk/p/C0QQRDA.m
===================================================================
--- /qrda/C0Q/trunk/p/C0QQRDA.m	(revision 1516)
+++ /qrda/C0Q/trunk/p/C0QQRDA.m	(revision 1517)
@@ -1,4 +1,4 @@
-C0QQRDA ; GPL - Quality Reporting QRDA Processing ; 8/1/12 7:34am
-	;;1.0;C0Q;**4**;May 21, 2012;Build 28
+C0QQRDA ; GPL - Quality Reporting QRDA Processing ; 8/1/12 4:24pm
+	;;1.0;QUALITY MEASURES;**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.
@@ -22,5 +22,4 @@
 	K @REF
 	D WORK(REF)
-	D ZWRITE^C0QUTIL(REF)
 	D PRINTXML(REF)
 	QUIT
@@ -51,24 +50,65 @@
 	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")
+PRINTXML(C0QREF) ; Print the XML; Private EP
+	N C0QDFN,C0QMS,C0QM S (C0QDFN,C0QMS,C0QM)="" ; DFN, Measure Set, Measure loopers
+	F  S C0QDFN=$O(@C0QREF@(C0QDFN)) Q:C0QDFN=""  D  ; For each patient
+	. W !!,$C(27),"[1;37;42m","Prosessing DFN ",C0QDFN,$C(27),"[0m",!  ; Print in Green.
+	. ;
+	. ;
+	. ; CCR Generatation is next; protected against crashes.
+	. ; ET set to new value then restored.
+	. N C0QCCRXML ; CCR XML
+	. N OLDTRAP S OLDTRAP=$ET
+	. ; ET: Rollback to this level, write the error in red , clear it, then quit
+	. N $ES,$ET
+	. S $ET="Q:($ES)  W $C(27),""[1;37;41m"",$ZS,$C(27),""[0m"",! S $EC="""""
+	. D CCRRPC^C0CCCR(.C0QCCRXML,C0QDFN) ; Run CCR RPC.
+	. S $ET=OLDTRAP
+	. ;
+	. ;
+	. ; Quality XML Section generated by hand next...
+	. N C0QXML ; Generated Quality XML
+	. D XMLSTORE(.C0QXML,$$OT("QUALITY")) ; Open Tag
+	. F  S C0QMS=$O(@C0QREF@(C0QDFN,C0QMS)) Q:C0QMS=""  D  ; For each measure set
+	. . D XMLSTORE(.C0QXML,$$OT("MEASURE_SET")) ; Open tag
+	. . D XMLSTORE(.C0QXML,$$TAG("ID",C0QMS)) ; Write out set QRDA code
+	. . D XMLSTORE(.C0QXML,$$OT("MEASURES")) ; Open tag
+	. . F  S C0QM=$O(@C0QREF@(C0QDFN,C0QMS,C0QM)) Q:C0QM=""  D  ; for each measure
+	. . . D XMLSTORE(.C0QXML,$$TAG("MEASURE",C0QM)) ; Write <measure> and qrda code
+	. . D XMLSTORE(.C0QXML,$$CT("MEASURES")) ; Close tag
+	. . D XMLSTORE(.C0QXML,$$CT("MEASURE_SET")) ; Close tag
+	. D XMLSTORE(.C0QXML,$$CT("QUALITY")) ; Close tag
+	. ;
+	. ;
+	. ; Insert XML under the root of the document XPATH
+	. D INSERT^C0CXPATH($NA(C0QCCRXML),$NA(C0QXML),"//ContinuityOfCareRecord")
+	. ;
+	. ; 
+	. ; Get Kernel Default Directory
+	. N DEFDIR S DEFDIR=$$DEFDIR^%ZISH()
+	. ;
+	. ; 
+	. ; Write out to a file.
+	. N FN S FN="QRDA_CCR_DFN"_$$RJ^XLFSTR(C0QDFN,10,"0")_".XML" ; File Name
+	. K C0QCCRXML(0) ; remove zero node
+	. D EN^DDIOL($$OUTPUT^C0CXPATH($NA(C0QCCRXML(1)),FN,DEFDIR))
 	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
+	; Quick XML stuff ; All Private
+OT(STR) Q "<"_STR_">"  ; $$ Open Tag
+CT(STR) Q "</"_STR_">"  ; $$ Close Tag
+TAG(NM,CONTENT) Q "<"_NM_">"_CONTENT_"</"_NM_">"  ; $$ Whole tag
+	;
+XMLSTORE(REF,STR) ; Priv Proc - Store XML
+	; REF -> Save Array. Pass by Reference.
+	; STR -> What to store. Pass by Value.
+	; Use like this: D XMLSTORE(.STORE,"<tag>")
+	; Output: STORE(1)="<tag>"
+	N L ; Number Subscript to use
+	S L=$O(REF(" "),-1) S L=L+1 ; Get last number and increment
+	S REF(L)=STR,REF(0)=L ; Store string in numbered sub, store last number in 0 node (not used here)
+	QUIT
+ ;
+ ; Following is for formatting printed XML. L passed in Symbol Table and starts at 0.
 L1 D WS S L=L+1 Q  ; Write space and increment
 L2 S L=L-1 D WS Q  ; Decrement and Write space
