1 | C0QMUERX ; VEN - Analyze ERx Data for Patients ; 5/30/12 10:21am
|
---|
2 | ;;1.0;C0Q;;May 21, 2012;Build 44
|
---|
3 | QUIT ; No Entry from the top
|
---|
4 | ;
|
---|
5 | UT ; 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("")
|
---|
21 | UT2 ; Units Tests 2
|
---|
22 | N C0QDEBUG S C0QDEBUG=1
|
---|
23 | D EN("^C0Q(301,4,1,""B"")")
|
---|
24 | QUIT
|
---|
25 | EN(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 | . Q:$G(^TMP($J,C0QDFN,1,"RowCount"))=0 ; WS says no data
|
---|
83 | . M ^TMP($J,C0QDFN)=C0POUT
|
---|
84 | ;
|
---|
85 | ; From the New Crop Meaningful Use documentation:
|
---|
86 | ; Appendix G: Meaningful Use Certification FAQ Question 10
|
---|
87 | ;
|
---|
88 | ; DENOMINATOR NUMERATOR
|
---|
89 | ; DeaClassCode = 0, 9 DeaClassCode = 0, 9
|
---|
90 | ; PharmacyType = 1 PharmacyType = 1
|
---|
91 | ; PharmacyDetailType = 1, 2 PharmacyDetailType = 1, 2
|
---|
92 | ; FinalDestinationType = 1, 2, 3, 4 FinalDestinationType = 3, 4
|
---|
93 | ; FinalStatusType = 1, 4, 5 FinalStatusType = 1, 5
|
---|
94 | ;
|
---|
95 | ; DeMorgan's Law
|
---|
96 | ; NOT(A or B) = NOT(A) and NOT(B)
|
---|
97 | ; So to collect prescriptions for which DeaClassCode is 0 or 9
|
---|
98 | ; We exclude all those who are not 0 AND not 9.
|
---|
99 | ; See: http://en.wikipedia.org/wiki/De_Morgan%27s_laws#Negation_of_a_disjunction
|
---|
100 | ;
|
---|
101 | ; The algorithms below use an Onion Peeling method. Any prescription which
|
---|
102 | ; fails makes you jump to the next prescription.
|
---|
103 | ; The "Onion levels" are:
|
---|
104 | ; DeaClassCode, PharamcyType, PharmacyDetailType, FinalDestinationType, FinalStatusType
|
---|
105 | ;
|
---|
106 | ; Now walk through collected DFNs and accumulate MU stats
|
---|
107 | ;
|
---|
108 | ; WARNING: Naked References below
|
---|
109 | ;
|
---|
110 | N C0QDFN,C0QRXNO S (C0QDFN,C0QRXNO)=0
|
---|
111 | N C0QD S C0QD=0 ; Denominator
|
---|
112 | ;
|
---|
113 | ; Calculate Denominator below
|
---|
114 | F S C0QDFN=$O(^TMP($J,C0QDFN)) Q:C0QDFN="" DO
|
---|
115 | . F S C0QRXNO=$O(^TMP($J,C0QDFN,C0QRXNO)) Q:C0QRXNO="" DO
|
---|
116 | .. W:$G(C0QDEBUG) "Patient "_C0QDFN_" Rx "_C0QRXNO,!
|
---|
117 | .. ;
|
---|
118 | .. I ^(C0QRXNO,"DeaClassCode") ; Change $REFERENCE
|
---|
119 | .. ;
|
---|
120 | .. N DEA S DEA=^("DeaClassCode")
|
---|
121 | .. W:$G(C0QDEBUG) "DeaClassCode: "_DEA,!
|
---|
122 | .. Q:((DEA'=0)&(DEA'=9))
|
---|
123 | .. ;
|
---|
124 | .. N PT S PT=^("PharmacyType")
|
---|
125 | .. W:$G(C0QDEBUG) "PharmacyType: "_PT,!
|
---|
126 | .. Q:(PT'=1)
|
---|
127 | .. ;
|
---|
128 | .. N PDT S PDT=^("PharmacyDetailType")
|
---|
129 | .. W:$G(C0QDEBUG) "PharmacyDetailType: "_PDT,!
|
---|
130 | .. Q:((PDT'=1)&(PDT'=2))
|
---|
131 | .. ;
|
---|
132 | .. N FDT S FDT=^("FinalDestinationType")
|
---|
133 | .. W:$G(C0QDEBUG) "FinalDestinationType: "_FDT,!
|
---|
134 | .. Q:((FDT'=1)&(FDT'=2)&(FDT'=3)&(FDT'=4))
|
---|
135 | .. ;
|
---|
136 | .. N FST S FST=^("FinalStatusType")
|
---|
137 | .. W:$G(C0QDEBUG) "FinalStatusType: "_FST,!
|
---|
138 | .. Q:((FST'=1)&(FST'=4)&(FST'=5))
|
---|
139 | .. ;
|
---|
140 | .. W:$G(C0QDEBUG) "Adding to Denominator",!
|
---|
141 | .. S C0QD=C0QD+1
|
---|
142 | ;
|
---|
143 | ; Calculate Numerator below
|
---|
144 | N C0QDFN,C0QRXNO S (C0QDFN,C0QRXNO)=0
|
---|
145 | N C0QN S C0QN=0 ; Numerator
|
---|
146 | F S C0QDFN=$O(^TMP($J,C0QDFN)) Q:C0QDFN="" DO
|
---|
147 | . F S C0QRXNO=$O(^TMP($J,C0QDFN,C0QRXNO)) Q:C0QRXNO="" DO
|
---|
148 | .. W:$G(C0QDEBUG) "Patient "_C0QDFN_" Rx "_C0QRXNO,!
|
---|
149 | .. ;
|
---|
150 | .. I ^(C0QRXNO,"DeaClassCode") ; Change $REFERENCE
|
---|
151 | .. ;
|
---|
152 | .. N DEA S DEA=^("DeaClassCode")
|
---|
153 | .. W:$G(C0QDEBUG) "DeaClassCode: "_DEA,!
|
---|
154 | .. Q:((DEA'=0)&(DEA'=9))
|
---|
155 | .. ;
|
---|
156 | .. N PT S PT=^("PharmacyType")
|
---|
157 | .. W:$G(C0QDEBUG) "PharmacyType: "_PT,!
|
---|
158 | .. Q:(PT'=1)
|
---|
159 | .. ;
|
---|
160 | .. N PDT S PDT=^("PharmacyDetailType")
|
---|
161 | .. W:$G(C0QDEBUG) "PharmacyDetailType: "_PDT,!
|
---|
162 | .. Q:((PDT'=1)&(PDT'=2))
|
---|
163 | .. ;
|
---|
164 | .. N FDT S FDT=^("FinalDestinationType")
|
---|
165 | .. W:$G(C0QDEBUG) "FinalDestinationType: "_FDT,!
|
---|
166 | .. Q:((FDT'=3)&(FDT'=4))
|
---|
167 | .. ;
|
---|
168 | .. N FST S FST=^("FinalStatusType")
|
---|
169 | .. W:$G(C0QDEBUG) "FinalStatusType: "_FST,!
|
---|
170 | .. Q:((FST'=1)&(FST'=5))
|
---|
171 | .. ;
|
---|
172 | .. W:$G(C0QDEBUG) "Adding to Numerator",!
|
---|
173 | .. S C0QN=C0QN+1
|
---|
174 | ;
|
---|
175 | S ^TMP($J)=C0QN_U_C0QD
|
---|
176 | ;
|
---|
177 | ; TODO: Over here, do something with the numerator and denominator..
|
---|
178 | ; Probably store them somewhere.
|
---|
179 | ;
|
---|
180 | I '$G(C0QDEBUG) K ^TMP($J) ; Empty out in production not testing
|
---|
181 | QUIT
|
---|
182 | ;
|
---|
183 | HASERX(DFN) ; $$ - Private; Has E-Prescriptions?
|
---|
184 | ; Parameters
|
---|
185 | ; - DFN by Value
|
---|
186 | ; Output
|
---|
187 | ; 0 or 1 (false or true)
|
---|
188 | N ZI S ZI=""
|
---|
189 | N ZERX S ZERX=$NA(^PS(55,DFN,"NVA"))
|
---|
190 | N DONE,HASERX
|
---|
191 | F S ZI=$O(@ZERX@(ZI)) Q:ZI="" Q:$G(DONE) D
|
---|
192 | . I $G(@ZERX@(ZI,1,1,0))["E-Rx Web" S (DONE,HASERX)=1
|
---|
193 | Q +$G(HASERX)
|
---|