source: qrda/C0Q/trunk/p/C0QQRDA.m@ 1518

Last change on this file since 1518 was 1518, checked in by Sam Habiel, 12 years ago

latest iteration

File size: 8.2 KB
Line 
1C0QQRDA ; GPL - Quality Reporting QRDA Processing ; 8/2/12 12:42am
2 ;;1.0;QUALITY MEASURES;**4**;May 21, 2012;Build 28
3 ;Copyright 2012 George Lilly. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20EN ; Private to this Package; Main Entry Point for this routine
21 ; This EP is interactive or silent depending on params
22 ;
23 ; Check for config errors first
24 N % S %=$$CHECKERR()
25 I % D EN^DDIOL($P(%,U,2)) QUIT
26 ;
27 ; Print Intro
28 N %
29 S %(1)="This program collects patients from the denominators of the measures"
30 S %(2)="STK, VTE, and ED and outputs modified CCR files to the kernel default"
31 S %(3)="directory (probably /tmp/)."
32 S %(4)=""
33 S %(5)="This will take some time to execute."
34 S %(6)=""
35 S %(6,"F")="!!!"
36 ;
37 D EN^DDIOL(.%)
38 ;
39 ; Ask user which measure set to run
40 N DIR,DTOUT,DUOUT,X,Y,DIRUT,DIROUT,DA ; DIR variables
41 S DIR(0)="SB^V:VTE;S:STK;E:ED"
42 S DIR("A")="Measure to calculate"
43 S DIR("A",1)="Which measure set would you like to produce QRDA documents for?"
44 S DIR("A",2)="Choose to Run [V]TE Measure Set, [S]TK Measure Set, or "
45 S DIR("A",3)="[E]D Measure Set"
46 D ^DIR
47 ;
48 I $G(DTOUT)!$G(DUOUT) QUIT ; Did user hit '^' or time out?
49 ;
50 ; Get the Measure Set IEN which the user has seleted.
51 ; NB: field names start with VTE, STK, or ED; so I can use the output
52 ; of DIR directly.
53 ;
54 N FLD S FLD=Y(0)
55 N C0QMSIEN S C0QMSIEN=$$GET1^DIQ(1130580001.401,$$INPPARM(),FLD,"I")
56 ;
57 S:'C0QMSIEN $EC=",U1," ; Debug.Assert that MSIEN is numeric.
58 ;
59 ; Do the work
60 N REF S REF=$NAME(^TMP("C0QQRDA",$J)) ; Global for data collection
61 K @REF ; Clear global
62 D WORK(REF,C0QMSIEN) ; Process Measure Set, collect data in global
63 D PRINTXML(REF,FLD) ; Generate XML; output to File.
64 K @REF ; Clear global
65 QUIT
66 ;
67 ;SILENTEN(RETURN) ; For future RPC calls...; needs to be reworked.
68 ; N % S %=$$CHECKERR()
69 ; I % S RETURN(0)=% Q
70 ;
71 ; N DIQUIET S DIQUIET=1
72 ; D EN
73 ; S RETURN(0)=0
74 ; QUIT
75 ;
76CHECKERR() ; Private Proc; Check if environment is okay.
77 ; Output: 0 -> Okay; +ve^message for error
78 N INPPARM S INPPARM=$$INPPARM() ; Inpatient Parameters IEN
79 I 'INPPARM Q 1_U_"No Inpatient Parameters found"
80 ;
81 ; Pointer fields to Measurement Set file, we grab the IENs
82 N C0QED S C0QED=$$GET1^DIQ(1130580001.401,INPPARM,"ED","I")
83 N C0QSTK S C0QSTK=$$GET1^DIQ(1130580001.401,INPPARM,"STK","I")
84 N C0QVTE S C0QVTE=$$GET1^DIQ(1130580001.401,INPPARM,"VTE","I")
85 ;
86 N TXT S TXT="" ; Error text
87 I 'C0QED S TXT=TXT_"ED,"
88 I 'C0QSTK S TXT=TXT_"STK,"
89 I 'C0QVTE S TXT=TXT_"VTE"
90 I $E(TXT,$L(TXT)=",") S TXT=$E(TXT,1,$L(TXT)-1)
91 I $L(TXT) Q 2_U_"Measure Sets missing from parameters: "_TXT
92 ;
93 QUIT 0 ; All okay
94 ;
95WORK(C0QREF,C0QMSIEN) ; Private Proc; Process Measure Sets; Collect the data.
96 ; Input/Output: C0QREF -> Global for Output passed by Name
97 ; C0QMSIEN -> (Input): Measurement Set IEN to calculate
98 ;
99 ; Print
100 D EN^DDIOL(C0QMSIEN_": "_^C0Q(201,C0QMSIEN,0))
101 D EN^DDIOL("")
102 ;
103 ; Calculate totals and move patients over from individual measures
104 D UPDATE^C0QUPDT(.A,C0QMSIEN) ; FYI: A isn't used.
105 ;
106 ; Get QRDA code for Measure Set.
107 N C0QMSQRDA S C0QMSQRDA=$$GET1^DIQ($$C0QMFN^C0QUPDT(),C0QMSIEN_",","QRDA TEMPLATE ROOT")
108 ;
109 N C0QI S C0QI=0 ; Fileman IEN looper
110 F S C0QI=$O(^C0Q(201,C0QMSIEN,5,C0QI)) Q:'C0QI D ; For each measure in Measure Set
111 . ;
112 . ; Get QRDA code using relational jump
113 . N C0QMEASUREQRDA S C0QMEASUREQRDA=$$GET1^DIQ($$C0QMMFN^C0QUPDT(),C0QI_","_C0QMSIEN_",",".01:QRDA TEMPLATE ROOT")
114 . ;
115 . ; Then collect patients in the denominator, and store in output global
116 . N C0QP S C0QP=0
117 . F S C0QP=$O(^C0Q(201,C0QMSIEN,5,C0QI,3,C0QP)) Q:'C0QP D ; For each patient in denominator
118 . . N C0QDFN S C0QDFN=+^(C0QP,0)
119 . . S @C0QREF@(C0QDFN,C0QMSQRDA,C0QMEASUREQRDA)=""
120 QUIT
121 ;
122INPPARM() ; $$ Private; Get Inpatient Parameters IEN
123 ; Output: IEN of Inpatient Parameter in C0Q PARAMETER file
124 ;
125 ; Browse this tree of xrefs to get the IEN of INP type (last line here).
126 ; ^C0Q(401,"B","INPATIENT",2)=""
127 ; ^C0Q(401,"B","OUTPATIENT",1)=""
128 ; ^C0Q(401,"MU","MU12",1)=""
129 ; ^C0Q(401,"MU","MU12",2)=""
130 ; ^C0Q(401,"MUTYP","MU12","EP",1)=""
131 ; ^C0Q(401,"MUTYP","MU12","INP",2)=""
132 ;
133 N MUID S MUID="" ; Looper for MU Year ID
134 N FOUND S FOUND=0 ; Found flag to get out of loop
135 N IEN ; Output variable
136 F S MUID=$O(^C0Q(401,"MUTYP",MUID),-1) Q:MUID="" Q:FOUND D ; Loop backwards
137 . N TYP S TYP="" ; Type ("EP" or "INP")
138 . F S TYP=$O(^C0Q(401,"MUTYP",MUID,TYP)) Q:TYP="" Q:FOUND D
139 . . I TYP="INP" S IEN=$O(^(TYP,"")),FOUND=1 Q ; If found, get IEN, quit out of loops
140 QUIT +$G(IEN)
141 ;
142PRINTXML(C0QREF,C0QMNM) ; Print the XML; Private Proc
143 ; Input: C0QREF -> Global By Name
144 ; C0QMNM -> Measure Name -> Either VTE, STK, ED. For use in filenames.
145 ; Output: modified CCRs are saved in /tmp/
146 N C0QDFN,C0QMS,C0QM S (C0QDFN,C0QMS,C0QM)="" ; DFN, Measure Set, Measure loopers
147 F S C0QDFN=$O(@C0QREF@(C0QDFN)) Q:C0QDFN="" D ; For each patient
148 . ;
149 . N GREEN S GREEN=$C(27)_"[1;37;42m"
150 . N RESET S RESET=$C(27)_"[0m"
151 . D EN^DDIOL(GREEN_"Prosessing DFN "_C0QDFN_RESET,"","!!!")
152 . D EN^DDIOL("","","!")
153 . ;
154 . ; CCR Generatation is next; protected against crashes.
155 . ; ET set to new value then restored.
156 . N C0QCCRXML ; CCR XML
157 . N OLDTRAP S OLDTRAP=$ET
158 . ; ET: Rollback to this level, write the error in red , clear it, then quit
159 . N ETTEXT S ETTEXT=$C(27)_"[1;37;41m"_$$EC^%ZOSV_$C(27)_RESET
160 . N $ES,$ET
161 . S $ET="W ETTEXT D ^%ZTER G ROLLDOWN^C0QQRDA"
162 . D CCRRPC^C0CCCR(.C0QCCRXML,C0QDFN) ; Run CCR RPC.
163 . S $ET=OLDTRAP
164 . ;
165 . ;
166 . ; Quality XML Section generated by hand next...
167 . N C0QXML ; Generated Quality XML
168 . D XMLSTORE(.C0QXML,$$OT("QUALITY")) ; Open Tag
169 . F S C0QMS=$O(@C0QREF@(C0QDFN,C0QMS)) Q:C0QMS="" D ; For each measure set
170 . . D XMLSTORE(.C0QXML,$$OT("MEASURE_SET")) ; Open tag
171 . . D XMLSTORE(.C0QXML,$$TAG("ID",C0QMS)) ; Write out set QRDA code
172 . . D XMLSTORE(.C0QXML,$$OT("MEASURES")) ; Open tag
173 . . F S C0QM=$O(@C0QREF@(C0QDFN,C0QMS,C0QM)) Q:C0QM="" D ; for each measure
174 . . . D XMLSTORE(.C0QXML,$$TAG("MEASURE",C0QM)) ; Write <measure> and qrda code
175 . . D XMLSTORE(.C0QXML,$$CT("MEASURES")) ; Close tag
176 . . D XMLSTORE(.C0QXML,$$CT("MEASURE_SET")) ; Close tag
177 . D XMLSTORE(.C0QXML,$$CT("QUALITY")) ; Close tag
178 . ;
179 . ;
180 . ; Insert Quality XML under the root of the CCR document
181 . D INSERT^C0CXPATH($NA(C0QCCRXML),$NA(C0QXML),"//ContinuityOfCareRecord")
182 . ;
183 . ;
184 . ; Get Kernel Default Directory
185 . N DEFDIR S DEFDIR=$$DEFDIR^%ZISH()
186 . ;
187 . ;
188 . ; Write out to a file.
189 . N FN S FN=C0QMNM_"_QRDA_CCR_DFN"_$$RJ^XLFSTR(C0QDFN,10,"0")_".XML" ; File Name
190 . K C0QCCRXML(0) ; remove zero node; API doesn't support it.
191 . D EN^DDIOL($$OUTPUT^C0CXPATH($NA(C0QCCRXML(1)),FN,DEFDIR))
192 QUIT
193 ;
194 ; Quick XML stuff ; All Private
195OT(STR) Q "<"_STR_">" ; $$ Open Tag
196CT(STR) Q "</"_STR_">" ; $$ Close Tag
197TAG(NM,CONTENT) Q "<"_NM_">"_CONTENT_"</"_NM_">" ; $$ Whole tag
198 ;
199XMLSTORE(REF,STR) ; Priv Proc - Store XML
200 ; REF -> Save Array. Pass by Reference.
201 ; STR -> What to store. Pass by Value.
202 ; Use like this: D XMLSTORE(.STORE,"<tag>")
203 ; Output: STORE(1)="<tag>"
204 N L ; Number Subscript to use
205 S L=$O(REF(" "),-1) S L=L+1 ; Get last number and increment
206 S REF(L)=STR,REF(0)=L ; Store string in numbered sub, store last number in 0 node (not used here)
207 QUIT
208 ;
209 ; Following is for formatting printed XML. L passed in Symbol Table and starts at 0.
210L1 D WS S L=L+1 Q ; Write space and increment
211L2 S L=L-1 D WS Q ; Decrement and Write space
212WS X "F I=1:1:L W "" """ Q ; Write Space
213 ; This is for rolling down the stack to the $ES level
214ROLLDOWN S $ET="Q:$ES S $EC=""""",$EC=",U99," QUIT
Note: See TracBrowser for help on using the repository browser.