Index: qrda/C0Q/trunk/p/C0QKIDS.m
===================================================================
--- qrda/C0Q/trunk/p/C0QKIDS.m	(revision 1484)
+++ qrda/C0Q/trunk/p/C0QKIDS.m	(revision 1501)
@@ -1,23 +1,46 @@
-C0QKIDS	; VEN/SMH - Kids Utilities for transporting C0Q data ; 7/13/12 11:49am
-	;;1.0;C0Q;;May 21, 2012;Build 47
+C0QKIDS	; VEN/SMH - Kids Utilities for transporting C0Q data ; 7/31/12 3:01pm
+	;;1.0;C0Q;;May 21, 2012;Build 63
 	; Licensed under package license. See Documentation.
 	;
-	; PEPs: PRE, TRAN, POST
-	;
-PRE ; Unified Pre; PEP
-	QUIT
+	; PEPs: TRAN, POST, PRE
+	;
 TRAN	; Unified Transport; PEP
 	; D TRAN301  ; looks like I won't send that file over
-	D TRAN201
+	D TRAN201 ; C0Q MEASUREMENT
+	D TRAN101 ; C0Q QUALITY MEASURE
 	QUIT
 POST	; Unified Post; PEP
 	; D POST301  ; looks like I won't send that file over
-	D POST101
-	D POST201
+	; D POST101 ; C0Q QUALITY MEASURE ; As of T11, I won't do that anymore. -->
+	; I discovered that it will do it on destination systems that are set-up.
+	; So bad bad bad idea for me to do it in a post-init.
+	; ... I wrote TRAN101 to do the function of POST101.
+	D POST201 ; C0Q MEASUREMENT
+	QUIT
+	;
+PRE	; Unified Pre; PEP
+	D PRE101
 	QUIT
 	;
 	; << >>
 	;
+TRAN101	; Remove Untransportable pointers in C0Q QUALITY MEASURE; Private EP
+	; NB: I am reaching into KIDS's data here. This may not work for future versions
+	; of KIDS. However, I am exporting this only; once exported, it should work in
+	; any version of KIDS.
+	N XPDIEN S XPDIEN=$QS(XPDGREF,2) ; Get IEN of KIDS Transport Global
+	N X S X=$NA(^XTMP("XPDT",XPDIEN,"DATA",1130580001.101)) ; KIDS transports our data here
+	N IEN S IEN=0 ; Looper
+	F  S IEN=$O(@X@(IEN)) Q:'IEN  D  ; For each IEN, remove the following:
+	. S $P(@X@(IEN,0),U,2)="" ; Numerator Patient List
+	. S $P(@X@(IEN,0),U,3)="" ; Denominator Patient List
+	. S $P(@X@(IEN,7),U,4)="" ; Negative Numerator List
+	. S $P(@X@(IEN,7),U,2)="" ; Alternate Numerator List
+	. S $P(@X@(IEN,7),U,3)="" ; Alternate Denominator List
+	. S $P(@X@(IEN,7),U,5)="" ; Alternate Negative Numerator List
+	QUIT
+	;
 TRAN301	; Grab FDA for entire file C0Q PATIENT LIST and store in Transport Global; Private EP
+	; Not used. Dead code.
 	N C0QIEN S C0QIEN=0 ; IEN walker
 	N C0QREF1 S C0QREF1=$NAME(^TMP("C0QOLD",$J)) ; Temporary Global Reference
@@ -56,6 +79,32 @@
 	;
 POST201	; File FDA for 201; Private EP
+	; 
+	; Clean-up data if it already exists!
+	; ZWRITE ^C0Q(201,:,5,:,0)        
+	; ^C0Q(201,1,5,599,0)=50
+	; ^C0Q(201,1,5,600,0)=4
+	; ^C0Q(201,1,5,601,0)=39
+	; ^C0Q(201,1,5,602,0)=6
+	; ^C0Q(201,1,5,603,0)=7
+	; ^C0Q(201,1,5,604,0)=48
+	; ^C0Q(201,1,5,605,0)=46
+	;
 	IF $O(^C0Q(201,0)) DO  QUIT  ; Quit if data is already there.
 	. D MES^XPDUTL("Data exists in file C0Q MEASUREMENTS... Not adding new data")
+	. D MES^XPDUTL("Cleaning up broken pointers in C0Q MEASUREMENTS from deleted data in C0Q QUALITY MEASURE")
+	. ; This is very hairy code. Run through the 5 multiple in C0Q MEASUREMENT
+	. ; Grab the IEN in the .01, check if it exists; if not, kill.
+	. N DA,DIK ; DIK Variables; as well as our looper variables
+	. S (DA,DA(1))=0 ; Initial looper values
+	. F  S DA(1)=$O(^C0Q(201,DA(1))) Q:'DA(1)  D  ; Loop through entries
+	. . D MES^XPDUTL("...Processing entry "_$P(^C0Q(201,DA(1),0),U))  ; msg
+	. . S DIK="^C0Q(201,"_DA(1)_",5,"  ; deletion root for the next loop
+	. . F  S DA=$O(^C0Q(201,DA(1),5,DA)) Q:'DA  D  ; For each Measure
+	. . . N IEN S IEN=+^C0Q(201,DA(1),5,DA,0)  ; Get IEN
+	. . . I IEN,'$D(^C0Q(101,IEN)) D  ; If IEN is numeric, IEN exists in dest file
+	. . . . D MES^XPDUTL("......Deleting broken pointer "_IEN) ; msg
+	. . . . D ^DIK ; delete
+	;
+	; If new install, add data
 	;
 	D MES^XPDUTL("Adding data to C0Q MEASUREMENTS")
@@ -70,4 +119,5 @@
 	;
 POST301	; Get FDA from Transport Global and install in destination system for C0Q PATIENT LIST; Private EP
+	; Not used. Dead code.
 	N C0QFDA S C0QFDA=$NAME(@XPDGREF@("C0Q","1130580001.301")) ; FDA array name is the global reference
 	N C0QERR ; Error 
@@ -79,29 +129,86 @@
 	QUIT
 	;
-POST101	; Clean transported data from broken pointers in C0Q QUALITY MEASURE in destination systems; Private EP
-	D MES^XPDUTL("Cleaning C0Q QUALITY MEASURE data")
-	N C0QIEN S C0QIEN=0 ; Ien looper
-	N C0QFDA ; Fileman Data Array
-	F  S C0QIEN=$O(^C0Q(101,C0QIEN)) Q:'+C0QIEN  DO  ; For each record, delete these fields
-	. S C0QFDA(1130580001.101,C0QIEN_",",1)="@" ; NUMERATOR PATIENT LIST
-	. S C0QFDA(1130580001.101,C0QIEN_",",1.5)="@" ; NEGATIVE NUMERATOR LIST
-	. S C0QFDA(1130580001.101,C0QIEN_",",2)="@" ; DENOMINATOR PATIENT LIST
-	. ; ---
-	. ; I wasn't planning on emptying these out, but the IENs in desintation systems may be different
-	. ; so it is best to remove them for now. It's a pointer field, so IENs are important.
-	. ; Desination file is populated automatically, but only at the site, and only after config.
-	. ; So we can't really ship the pointers as part of the install.
-	. ; ---
-	. S C0QFDA(1130580001.101,C0QIEN_",",1.1)="@" ; ALTERNATIVE NUMERATOR LIST
-	. S C0QFDA(1130580001.101,C0QIEN_",",1.51)="@" ; ALTERNATE NEGATIVE NUM LIST
-	. S C0QFDA(1130580001.101,C0QIEN_",",2.1)="@" ; ALTERNATIVE DENOMINATOR LIST
-	N C0QERR ; Errors
-	D FILE^DIE("","C0QFDA","C0QERR") ; Do it!
-	I $D(C0QERR) D  ; if there's an error, print it out
-	. D MES^XPDUTL("Couldn't fix data into C0Q QUALITY MEASURE file")
-	. S C0QERR=$Q(C0QERR)
-	. F  S C0QERR=$Q(@C0QERR) Q:C0QERR=""  D MES^XPDUTL(C0QERR_": "_@C0QERR)
-	QUIT
-	;
-	; Code below taken from PXRMP15I
-	;===============================================================
+PRE101	; Clean existing data (from an earlier installation) from measures that are now merged to other measures
+	; in C0Q QUALITY MEASURE in destination systems; Private EP
+	;
+	; Quit if C0Q Quality Measures isn't on the system.
+	Q:'$D(^C0Q(101))
+	; 
+	D MES^XPDUTL("Removing subsumed entries in C0Q QUALITY MEASURE")
+	;
+	; .01 field values to for records to remove
+	N C0QLIST
+	S C0QLIST("TEST M0028A")=""
+	S C0QLIST("MU EP 0028B")=""
+	S C0QLIST("M0013")=""
+	S C0QLIST("M0024")=""
+	S C0QLIST("M1")=""
+	S C0QLIST("M3")=""
+	S C0QLIST("M2")=""
+	S C0QLIST("M0028")=""
+	S C0QLIST("M111")=""
+	S C0QLIST("M112")=""
+	S C0QLIST("M113")=""
+	S C0QLIST("M128")=""
+	S C0QLIST("M5")=""
+	S C0QLIST("M7")=""
+	S C0QLIST("M0022")=""
+	S C0QLIST("12")=""
+	S C0QLIST("M0038")=""
+	S C0QLIST("M110")=""
+	S C0QLIST("MU EP NQF 0070")=""
+	;
+	; Root for ^DIK
+	N DIK S DIK="^C0Q(101,"
+	;
+	; Loop through list, find IEN for each one, kill off
+	N C0QITEM S C0QITEM=""                             ; Item
+	F  S C0QITEM=$O(C0QLIST(C0QITEM)) Q:C0QITEM=""  D  ; Loop
+	. Q:'$DATA(^C0Q(101,"B",C0QITEM))                  ; Quit if not present.
+	. N DA S DA=$O(^C0Q(101,"B",C0QITEM,""))           ; IEN
+	. ; The original software has MU EP NQF 0070 incorrectly. If the 1 node
+	. ; has Pneumonia, we want to remove that entry.
+	. I C0QITEM="MU EP NQF 0070",^C0Q(101,DA,1)'["Pneumonia" QUIT
+	. D MES^XPDUTL("...Removing "_C0QITEM)                ; Message to user
+	. D ^DIK                                           ; Delete
+	;
+REN	; Rename a bunch of entries
+	; ("OLD NAME")="NEW NAME"
+	D MES^XPDUTL("Renaming Old entries in C0Q QUALITY MEASURE")
+	;
+	N C0QLIST
+	S C0QLIST("NQF0038 NUM1 DPT")="MU EP NQF 0038 NUM1 DPT"
+	S C0QLIST("NQF0038 NUM10")="MU EP NQF 0038 NUM10 FLU"
+	S C0QLIST("NQF0038 NUM11 COMBO5")="MU EP NQF 0038 NUM11 COMBO5"
+	S C0QLIST("NQF0038 NUM12 COMBO6")="MU EP NQF 0038 NUM12 COMBO6"
+	S C0QLIST("NQF0038 NUM2 IPV")="MU EP NQF 0038 NUM2 IPV"
+	S C0QLIST("NQF0038 NUM3 MMR")="MU EP NQF 0038 NUM3 MMR"
+	S C0QLIST("NQF0038 NUM4 HiB")="MU EP NQF 0038 NUM4 HiB"
+	S C0QLIST("NQF0038 NUM5 HEP B")="MU EP NQF 0038 NUM5 HEP B"
+	S C0QLIST("NQF0038 NUM6 VZV")="MU EP NQF 0038 NUM6 VZV"
+	S C0QLIST("NQF0038 NUM7 PCV")="MU EP NQF 0038 NUM7 PCV"
+	S C0QLIST("NQF0038 NUM8 HEP A")="MU EP NQF 0038 NUM8 HEP A"
+	S C0QLIST("NQF0038 NUM9")="MU EP NQF 0038 NUM9 RV"
+	S C0QLIST("M124")="PQRI MEASURE 124"
+	S C0QLIST("M173")="PQRI MEASURE 173"
+	S C0QLIST("M39")="PQRI MEASURE 39"
+	S C0QLIST("M47")="PQRI MEASURE 47"
+	S C0QLIST("M48")="PQRI MEASURE 48"
+	;
+	N C0QITEM S C0QITEM=""                              ; Item
+	N C0QFDA                                            ; FDA
+	F  S C0QITEM=$O(C0QLIST(C0QITEM))  Q:C0QITEM=""  D  ; Loop through
+	. N IEN S IEN=$O(^C0Q(101,"B",C0QITEM,""))          ; Get IEN from File using old name
+	. I IEN S C0QFDA(1130580001.101,IEN_",",.01)=C0QLIST(C0QITEM)  ; If found, put new name in FDA for this IEN
+	. I IEN D MES^XPDUTL("...Renaming "_C0QITEM_" to "_C0QLIST(C0QITEM)) ; Print message to user
+	;
+	N C0QERR                                            ; Error for FILE^DIE
+	I $D(C0QFDA) D FILE^DIE("E",$NA(C0QFDA),$NA(C0QERR))  ; File if FDA has contents
+	E  D MES^XPDUTL("No entries to rename")             ; If nothing, tell user so
+	; 
+	D:$D(C0QERR)                                        ; If Error, print it
+	. D MES^XPDUTL("Error Filing Data. FILE^DIE reported:")
+	. N REF S REF=$NA(C0QERR)                           ; $Q Reference
+	. F  S REF=$Q(@REF) Q:REF=""  D MES^XPDUTL(REF_"="_@REF) ; Loop and Print
+	;
+	QUIT
