source: qrda/C0Q/trunk/p/C0QMUERX.m@ 1440

Last change on this file since 1440 was 1440, checked in by George Lilly, 12 years ago

eRx measure

File size: 5.9 KB
Line 
1C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/29/12 4:29pm
2 ;;
3 QUIT ; No Entry from the top
4 ;
5UT ; Unit Tests
6 N C0QDEBUG S C0QDEBUG=1
7 W "Testing ^DPT B Index",!
8 D EN("^DPT(""B"")")
9 W !,"Testing B Index on a C0Q Patient List",!
10 D EN("^C0Q(301,4,1,""B"")")
11 W !,"Testing ^AUPNPAT B Index",!
12 D EN("^AUPNPAT(""B"")")
13 W !,"Testing Reminder Patient List B Index",!
14 D EN("^PXRMXP(810.5,80,30,""B"")")
15 W !,"Testing upright file ^DPT",!
16 D EN("^DPT")
17 W !,"Testing a file with no data",!
18 D EN("^ALKJSDF")
19 W !,"Testing a no valid parameters",!
20 D EN("")
21UT2 ; Units Tests 2
22 N C0QDEBUG S C0QDEBUG=1
23 D EN("^C0Q(301,4,1,""B"")")
24 QUIT
25EN(C0QLIST) ; PEP - Analyze ERx Data and store
26 ; Parameters:
27 ; C0QLIST - Pass by Name. Global or Local Reference.
28 ; Can be: ^DPT("B") for all patients or ^C0Q(301,2,1,"B") for a specific patient list
29 ; Future: Can be a search template on file 2 or 9000001
30 ;
31 ; Check if XML Soap Message is installed
32 I '$D(^C0PX("B","GETMEDS6")) WRITE "GETMEDS6 Soap Message not installed",! QUIT
33 ;
34 ; Check if SOAP^C0PWS2 exists
35 I '$L($T(SOAP^C0PWS2)) WRITE "C0PWS2 Doesn't exist",! QUIT
36 ;
37 ; Check C0QLIST for sanity. Must be a single node.
38 IF '($DATA(C0QLIST)#2)!(C0QLIST="") WRITE "You didn't pass the list",! QUIT
39 ;
40 ; Contents must be a Reference with Data
41 IF '$DATA(@C0QLIST) WRITE "Destination doesn't contain any data",! QUIT
42 ;
43 ; Is this a B index?
44 NEW C0QB
45 IF $QSUBSCRIPT(C0QLIST,$QLENGTH(C0QLIST))="B" DO
46 . SET C0QB=1
47 . ; DEBUG
48 . W:$G(C0QDEBUG) "B index passed",!
49 . ; DEBUG
50 ELSE SET C0QB=0
51 ;
52 ; Make sure our TMP is empty
53 K ^TMP($J)
54 ;
55 ; Walk the global
56 N C0QWALK S C0QWALK=$SELECT(C0QB:"",'C0QB:0) ; Walker
57 N C0QDONE S C0QDONE=0 ; Finish Flag
58 FOR SET C0QWALK=$O(@C0QLIST@(C0QWALK)) QUIT:C0QDONE DO
59 . ; Are we done?
60 . I C0QB,C0QWALK="" S C0QDONE=1 QUIT ; If in index and we are out, done
61 . I 'C0QB,'+C0QWALK S C0QDONE=1 QUIT ; If not in index and we are not numeric, done
62 . ;
63 . N C0QDFN ; DFN of Patient
64 . ; If Walking B Index and Index not numeric, grab DFN (assuming ^DPT or ^AUPNPAT)
65 . ; TODO: Should I check that the global is ^DPT or ^AUPNPAT?
66 . I C0QB,'+C0QWALK S C0QDFN=$O(@C0QLIST@(C0QWALK,""))
67 . ; Otherwise, we will assume the contents of the index are the DFNs
68 . E S C0QDFN=C0QWALK
69 . I $G(C0QDEBUG) W C0QDFN," "
70 . ;
71 . ; Now, check to see if the patient has e-Rx's
72 . I $$HASERX(C0QDFN) S ^TMP($J,C0QDFN)=""
73 ;
74 W:$G(C0QDEBUG) ! ;
75 ;
76 ; Loop through collected DFNs, send to WS, and get data back, store in ^TMP($J,DFN)
77 N C0QDFN S C0QDFN=0
78 F S C0QDFN=$O(^TMP($J,C0QDFN)) Q:C0QDFN="" DO
79 . N C0POUT
80 . W:$G(C0QDEBUG) "Calling GETMEDS6 SOAP Web Service Call for "_C0QDFN,!
81 . D SOAP^C0PWS2("C0POUT","GETMEDS6",DUZ,C0QDFN)
82 . M ^TMP($J,C0QDFN)=C0POUT
83 ;
84 ; From the New Crop Meaningful Use documentation:
85 ; Appendix G: Meaningful Use Certification FAQ Question 10
86 ;
87 ; DENOMINATOR NUMERATOR
88 ; DeaClassCode = 0, 9 DeaClassCode = 0, 9
89 ; PharmacyType = 1 PharmacyType = 1
90 ; PharmacyDetailType = 1, 2 PharmacyDetailType = 1, 2
91 ; FinalDestinationType = 1, 2, 3, 4 FinalDestinationType = 3, 4
92 ; FinalStatusType = 1, 4, 5 FinalStatusType = 1, 5
93 ;
94 ; DeMorgan's Law
95 ; NOT(A or B) = NOT(A) and NOT(B)
96 ; So to collect prescriptions for which DeaClassCode is 0 or 9
97 ; We exclude all those who are not 0 AND not 9.
98 ; See: http://en.wikipedia.org/wiki/De_Morgan%27s_laws#Negation_of_a_disjunction
99 ;
100 ; The algorithms below use an Onion Peeling method. Any prescription which
101 ; fails makes you jump to the next prescription.
102 ; The "Onion levels" are:
103 ; DeaClassCode, PharamcyType, PharmacyDetailType, FinalDestinationType, FinalStatusType
104 ;
105 ; Now walk through collected DFNs and accumulate MU stats
106 ;
107 ; WARNING: Naked References below
108 ;
109 N C0QDFN,C0QRXNO S (C0QDFN,C0QRXNO)=0
110 N C0QD S C0QD=0 ; Denominator
111 ;
112 ; Calculate Denominator below
113 F S C0QDFN=$O(^TMP($J,C0QDFN)) Q:C0QDFN="" DO
114 . F S C0QRXNO=$O(^TMP($J,C0QDFN,C0QRXNO)) Q:C0QRXNO="" DO
115 .. W:$G(C0QDEBUG) "Patient "_C0QDFN_" Rx "_C0QRXNO,!
116 .. ;
117 .. I ^(C0QRXNO,"DeaClassCode") ; Change $REFERENCE
118 .. ;
119 .. N DEA S DEA=^("DeaClassCode")
120 .. W:$G(C0QDEBUG) "DeaClassCode: "_DEA,!
121 .. Q:((DEA'=0)&(DEA'=9))
122 .. ;
123 .. N PT S PT=^("PharmacyType")
124 .. W:$G(C0QDEBUG) "PharmacyType: "_PT,!
125 .. Q:(PT'=1)
126 .. ;
127 .. N PDT S PDT=^("PharmacyDetailType")
128 .. W:$G(C0QDEBUG) "PharmacyDetailType: "_PDT,!
129 .. Q:((PDT'=1)&(PDT'=2))
130 .. ;
131 .. N FDT S FDT=^("FinalDestinationType")
132 .. W:$G(C0QDEBUG) "FinalDestinationType: "_FDT,!
133 .. Q:((FDT'=1)&(FDT'=2)&(FDT'=3)&(FDT'=4))
134 .. ;
135 .. N FST S FST=^("FinalStatusType")
136 .. W:$G(C0QDEBUG) "FinalStatusType: "_FST,!
137 .. Q:((FST'=1)&(FST'=4)&(FST'=5))
138 .. ;
139 .. W:$G(C0QDEBUG) "Adding to Denominator",!
140 .. S C0QD=C0QD+1
141 ;
142 ; Calculate Numerator below
143 N C0QDFN,C0QRXNO S (C0QDFN,C0QRXNO)=0
144 N C0QN S C0QN=0 ; Numerator
145 F S C0QDFN=$O(^TMP($J,C0QDFN)) Q:C0QDFN="" DO
146 . F S C0QRXNO=$O(^TMP($J,C0QDFN,C0QRXNO)) Q:C0QRXNO="" DO
147 .. W:$G(C0QDEBUG) "Patient "_C0QDFN_" Rx "_C0QRXNO,!
148 .. ;
149 .. I ^(C0QRXNO,"DeaClassCode") ; Change $REFERENCE
150 .. ;
151 .. N DEA S DEA=^("DeaClassCode")
152 .. W:$G(C0QDEBUG) "DeaClassCode: "_DEA,!
153 .. Q:((DEA'=0)&(DEA'=9))
154 .. ;
155 .. N PT S PT=^("PharmacyType")
156 .. W:$G(C0QDEBUG) "PharmacyType: "_PT,!
157 .. Q:(PT'=1)
158 .. ;
159 .. N PDT S PDT=^("PharmacyDetailType")
160 .. W:$G(C0QDEBUG) "PharmacyDetailType: "_PDT,!
161 .. Q:((PDT'=1)&(PDT'=2))
162 .. ;
163 .. N FDT S FDT=^("FinalDestinationType")
164 .. W:$G(C0QDEBUG) "FinalDestinationType: "_FDT,!
165 .. Q:((FDT'=3)&(FDT'=4))
166 .. ;
167 .. N FST S FST=^("FinalStatusType")
168 .. W:$G(C0QDEBUG) "FinalStatusType: "_FST,!
169 .. Q:((FST'=1)&(FST'=5))
170 .. ;
171 .. W:$G(C0QDEBUG) "Adding to Numerator",!
172 .. S C0QN=C0QN+1
173 ;
174 S ^TMP($J)=C0QN_U_C0QD
175 I '$G(C0QDEBUG) K ^TMP($J) ; Empty out in production not testing
176 QUIT
177
178HASERX(DFN) ; $$ - Private; Has E-Prescriptions?
179 ; Parameters
180 ; - DFN by Value
181 ; Output
182 ; 0 or 1 (false or true)
183 N ZI S ZI=""
184 N ZERX S ZERX=$NA(^PS(55,DFN,"NVA"))
185 N DONE,HASERX
186 F S ZI=$O(@ZERX@(ZI)) Q:ZI="" Q:$G(DONE) D
187 . I $G(@ZERX@(ZI,1,1,0))["E-Rx Web" S (DONE,HASERX)=1
188 Q +$G(HASERX)
Note: See TracBrowser for help on using the repository browser.