1 | GPLRIMA ; CCDCCR/GPL - RIM REPORT ROUTINES; 6/6/08
|
---|
2 | ;;0.1;CCDCCR;nopatch;noreleasedate
|
---|
3 | ;Copyright 2008 WorldVistA. 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 | ;
|
---|
20 | ; THESE ROUTINES EXAMINE ONE OR MORE, UP TO ALL, OF THE PATIENTS ON THE
|
---|
21 | ; SYSTEM TO DETERMINE HOW COMPLETE THE RESULTING CCR OR CCD WOULD BE FOR
|
---|
22 | ; THESE PATIENTS. IT BEGINS TO MEASURE "HL7 RIM COHERENCE" WHICH IS HOW USEFUL
|
---|
23 | ; THE VARIABLES WILL BE TO A RIM-MODELED APPLICATION AFTER THEY ARE
|
---|
24 | ; CONVEYED VIA THE CCR OR CCD.
|
---|
25 | ; FACTORS THAT AFFECT RIM COHERENCE INCLUDE:
|
---|
26 | ; 1. THE PRESENSE OF CLINICAL DATA IN A SECTION
|
---|
27 | ; 2. ARE THE DATA ELEMENTS TIME-BOUND
|
---|
28 | ; 3. ARE THE DATA ELEMENTS CODED WITH SNOMED OR LOINC ETC
|
---|
29 | ; 4. ARE SOURCE ACTORS ASSOCIATED WITH THE DATA ELEMENTS
|
---|
30 | ; 5. ARE ACTORS IDENTIFIED REGARDING THEIR ROLE
|
---|
31 | ; .. AND OTHER FACTORS YET TO BE DETERMINED
|
---|
32 | ;
|
---|
33 | ; SINCE THESE MEASUREMENTS ARE DONE AT THE VARIABLE LEVEL, THEY
|
---|
34 | ; REFLECT ON RIM COHERENCE WHETHER THE CCR OR THE CCD IS USED FOR
|
---|
35 | ; CONVEYANCE TO THE RIM APPLICATION.
|
---|
36 | ;
|
---|
37 | ;
|
---|
38 | ANALYZE(BEGDFN,DFNCNT) ; RIM COHERANCE ANALYSIS ROUTINE
|
---|
39 | ; BEGINS AT BEGDFN AND GOES FOR DFNCNT PATIENTS
|
---|
40 | ; TO RESUME AT NEXT PATIENT, USE BEGDFN=""
|
---|
41 | ; USE RESET^GPLRIMA TO RESET TO TOP OF PATIENT LIST
|
---|
42 | ;
|
---|
43 | N RIMARY,RIMTMP,RIMI,RIMDFN,RATTR
|
---|
44 | N CCRGLO
|
---|
45 | D ASETUP ; SET UP VARIABLES AND GLOBALS
|
---|
46 | D AINIT ; INITIALIZE ATTRIBUTE VALUE TABLE
|
---|
47 | I '$D(@RIMBASE@("RESUME")) S @RIMBASE@("RESUME")=$O(^DPT(0)) ; FIRST TIME
|
---|
48 | S RESUME=@RIMBASE@("RESUME") ; WHERE WE LEFT OFF LAST RUN
|
---|
49 | S RIMDFN=BEGDFN ; BEGIN WITH THE BEGDFN PATIENT
|
---|
50 | I RIMDFN="" S RIMDFN=RESUME
|
---|
51 | I +RIMDFN=0 D Q ; AT THE END OF THE PATIENTS
|
---|
52 | . W "END OF PATIENT LIST, CALL RESET^GPLRIMA",!
|
---|
53 | F RIMI=1:1:DFNCNT D Q:+RIMDFN=0 ; FOR DFNCNT NUMBER OF PATIENTS OR END
|
---|
54 | . D CCRRPC^GPLCCR(.CCRGLO,RIMDFN,"CCR","","","") ;PROCESS THE CCR
|
---|
55 | . W RIMDFN,!
|
---|
56 | . K @RIMBASE@("VARS",RIMDFN) ; CLEAR OUT OLD VARS
|
---|
57 | . ;
|
---|
58 | . ; COPY ALL THE VARIABLES TO THE RIM MAP AREA INDEXED BY PATIENT
|
---|
59 | . ;
|
---|
60 | . I $D(^TMP("GPLCCR",$J,"PROBVALS",1)) D ; PROBLEM VARS EXISTS
|
---|
61 | . . M @RIMBASE@("VARS",RIMDFN,"PROBLEMS")=^TMP("GPLCCR",$J,"PROBVALS")
|
---|
62 | . I $D(^TMP("GPLCCR",$J,"VITALS",1)) D ; VITALS VARS EXISTS
|
---|
63 | . . M @RIMBASE@("VARS",RIMDFN,"VITALS")=^TMP("GPLCCR",$J,"VITALS")
|
---|
64 | . I $D(^TMP("GPLCCR",$J,"MEDICATIONS",1)) D ; MEDS VARS EXISTS
|
---|
65 | . . M @RIMBASE@("VARS",RIMDFN,"MEDS")=^TMP("GPLCCR",$J,"MEDICATIONS")
|
---|
66 | . K ^TMP("GPLCCR",$J) ; KILL WORK AREA FOR CCR BUILDING
|
---|
67 | . ;
|
---|
68 | . ; EVALUATE THE VARIABLES AND CREATE AN ATTRIBUTE MAP
|
---|
69 | . ;
|
---|
70 | . S RATTR=$$SETATTR(RIMDFN) ; SET THE ATTRIBUTE STRING BASED ON THE VARS
|
---|
71 | . S @RIMBASE@("ATTR",RIMDFN)=RATTR ; SAVE THE ATRIBUTES FOR THIS PAT
|
---|
72 | . ;
|
---|
73 | . ; INCREMENT THE COUNT OF PATIENTS WITH THESE ATTRIBUTES IN ATTRTBL
|
---|
74 | . ;
|
---|
75 | . ; I '$D(@RIMBASE@("ATTRTBL",RATTR)) D ; IF FIRST PAT WITH THESE ATTRS
|
---|
76 | . ; . S @RIMBASE@("ATTRTBL",RATTR)=0 ; DEFAULT VALUE TO BE INCREMENTED
|
---|
77 | . ; S @RIMBASE@("ATTRTBL",RATTR)=@RIMBASE@("ATTRTBL",RATTR)+1 ; INCREMENT
|
---|
78 | . ;
|
---|
79 | . N CATNAME,CATTBL
|
---|
80 | . ; S CATBASE=$NA(@RIMBASE@("ANALYSIS"))
|
---|
81 | . S CATNAME=""
|
---|
82 | . D CPUSH(.CATNAME,RIMBASE,"RIMTBL",RIMDFN,RATTR) ; ADD TO CATEGORY
|
---|
83 | . W "CATEGORY NAME: ",CATNAME,!
|
---|
84 | . ;
|
---|
85 | . S RIMDFN=$O(^DPT(RIMDFN)) ; NEXT PATIENT
|
---|
86 | S @RIMBASE@("RESUME")=RIMDFN ; WHERE WE ARE LEAVING OFF THIS RUN
|
---|
87 | ; D PARY^GPLXPATH(@RIMBASE@("ATTRTBL"))
|
---|
88 | Q
|
---|
89 | ;
|
---|
90 | SETATTR(SDFN) ; SET ATTRIBUTES BASED ON VARS
|
---|
91 | N SBASE,SATTR
|
---|
92 | S SBASE=$NA(@RIMBASE@("VARS",SDFN))
|
---|
93 | D APOST("SATTR","RIMTBL","HEADER")
|
---|
94 | I $D(@SBASE@("PROBLEMS",1)) D ;
|
---|
95 | . D APOST("SATTR","RIMTBL","PROBLEMS")
|
---|
96 | . W "POSTING PROBLEMS",!
|
---|
97 | I $D(@SBASE@("VITALS",1)) D APOST("SATTR","RIMTBL","VITALS")
|
---|
98 | I $D(@SBASE@("MEDS",1)) D APOST("SATTR","RIMTBL","MEDS")
|
---|
99 | D APOST("SATTR","RIMTBL","NOTEXTRACTED") ; OUTPUT NOT YET PRODUCED
|
---|
100 | W "ATTRIBUTES: ",SATTR,!
|
---|
101 | Q SATTR
|
---|
102 | ;
|
---|
103 | RESET ; KILL RESUME INDICATOR TO START OVER. ALSO KILL RIM TMP VALUES
|
---|
104 | K ^TMP("GPLRIM","RESUME")
|
---|
105 | K ^TMP("GPLRIM")
|
---|
106 | Q
|
---|
107 | ;
|
---|
108 | CLIST ; LIST THE CATEGORIES
|
---|
109 | ;
|
---|
110 | I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
|
---|
111 | N CLBASE,CLNUM,ZI,CLIDX
|
---|
112 | S CLBASE=$NA(@RIMBASE@("RIMTBL","CATS"))
|
---|
113 | S CLNUM=@CLBASE@(0)
|
---|
114 | F ZI=1:1:CLNUM D ; LOOP THROUGH THE CATEGORIES
|
---|
115 | . S CLIDX=@CLBASE@(ZI)
|
---|
116 | . W "(",$P(@CLBASE@(CLIDX),"^",1)
|
---|
117 | . W ":",$P(@CLBASE@(CLIDX),"^",2),") "
|
---|
118 | . W CLIDX,!
|
---|
119 | ; D PARY^GPLXPATH(CLBASE)
|
---|
120 | Q
|
---|
121 | ;
|
---|
122 | CPUSH(CATRTN,CBASE,CTBL,CDFN,CATTR) ; ADD PATIENTS TO CATEGORIES
|
---|
123 | ; AND PASS BACK THE NAME OF THE CATEGORY TO WHICH THE PATIENT
|
---|
124 | ; WAS ADDED IN CATRTN, WHICH IS PASSED BY REFERENCE
|
---|
125 | ; CBASE IS WHERE TO PUT THE CATEGORIES PASSED BY NAME
|
---|
126 | ; CTBL IS THE NAME OF THE TABLE USED TO CREATE THE ATTRIBUTES,
|
---|
127 | ; PASSED BY NAME AND USED TO CREATE CATEGORY NAMES IE "@CTBL_X"
|
---|
128 | ; WHERE X IS THE CATEGORY NUMBER. CTBL(0) IS THE NUMBER OF CATEGORIES
|
---|
129 | ; CATBL(X)=CATTR STORES THE ATTRIBUTE IN THE CATEGORY
|
---|
130 | ; CDFN IS THE PATIENT DFN, CATTR IS THE ATTRIBUTE STRING
|
---|
131 | ; THE LIST OF PATIENTS IN A CATEGORY IS STORED INDEXED BY CATEGORY
|
---|
132 | ; NUMBER IE CTBL_X(CDFN)=""
|
---|
133 | ;
|
---|
134 | ; N CCTBL,CENTRY,CNUM,CCOUNT,CPATLIST
|
---|
135 | S CCTBL=$NA(@CBASE@(CTBL,"CATS"))
|
---|
136 | W "CBASE: ",CCTBL,!
|
---|
137 | ;
|
---|
138 | I '$D(@CCTBL@(CATTR)) D ; FIRST PATIENT IN THIS CATEGORY
|
---|
139 | . D PUSH^GPLXPATH(CCTBL,CATTR) ; ADD THE CATEGORY TO THE ARRAY
|
---|
140 | . S CNUM=@CCTBL@(0) ; ARRAY ENTRY NUMBER FOR THIS CATEGORY
|
---|
141 | . S CENTRY=CTBL_"_"_CNUM_U_0 ; TABLE ENTRY DEFAULT
|
---|
142 | . S @CCTBL@(CATTR)=CENTRY ; DEFAULT NON INCREMENTED TABLE ENTRY
|
---|
143 | . ; NOTE THAT P1 IS THE CATEGORY NAME MADE UP OF THE TABLE NAME
|
---|
144 | . ; AND CATGORY ARRAY NUMBER. P2 IS THE COUNT WHICH IS INITIALLY 0
|
---|
145 | ;
|
---|
146 | S CCOUNT=$P(@CCTBL@(CATTR),U,2) ; COUNT OF PATIENTS IN THIS CATEGORY
|
---|
147 | S CCOUNT=CCOUNT+1 ; INCREMENT THE COUNT
|
---|
148 | S $P(@CCTBL@(CATTR),U,2)=CCOUNT ; PUT IT BACK
|
---|
149 | ;
|
---|
150 | S CATRTN=$P(@CCTBL@(CATTR),U,1) ; THE CATEGORY NAME WHICH IS RETURNED
|
---|
151 | ;
|
---|
152 | S CPATLIST=$NA(@CBASE@(CTBL,"PATS",CATRTN)) ; BASE OF PAT LIST FOR THIS CAT
|
---|
153 | W "PATS BASE: ",CPATLIST,!
|
---|
154 | S @CPATLIST@(CDFN)="" ; ADD THIS PATIENT TO THE CAT PAT LIST
|
---|
155 | ;
|
---|
156 | Q
|
---|
157 | ;
|
---|
158 | CCOUNT ; RECOUNT THE CATEGORIES.. USE IN CASE OF RESTART OF ANALYZE
|
---|
159 | ;
|
---|
160 | I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
|
---|
161 | N ZI,ZJ,ZCNT,ZIDX,ZCAT,ZATR,ZTOT
|
---|
162 | S ZCBASE=$NA(@RIMBASE@("RIMTBL","CATS")) ; BASE OF CATEGORIES
|
---|
163 | S ZPBASE=$NA(@RIMBASE@("RIMTBL","PATS")) ; BASE OF PATIENTS
|
---|
164 | S ZTOT=0 ; INITIALIZE OVERALL TOTAL
|
---|
165 | F ZI=1:1:@ZCBASE@(0) D ; FOR ALL CATS
|
---|
166 | . S ZCNT=0
|
---|
167 | . S ZATR=@ZCBASE@(ZI) ; THE ATTRIBUTE OF THE CATEGORY
|
---|
168 | . S ZCAT=$P(@ZCBASE@(ZATR),"^",1) ; USE IT TO LOOK UP THE CATEGORY NAME
|
---|
169 | . ; S ZIDX=$O(@ZPBASE@(ZCAT,"")) ; FIRST PATIENT IN LIST
|
---|
170 | . ; F ZJ=0:0 D Q:$O(@ZPBASE@(ZCAT,ZIDX))="" ; ALL PATIENTS IN THE LISTS
|
---|
171 | . ; . S ZCNT=ZCNT+1 ; INCREMENT THE COUNT
|
---|
172 | . ; . W ZCAT," DFN:",ZIDX," COUNT:",ZCNT,!
|
---|
173 | . ; . S ZIDX=$O(@ZPBASE@(ZCAT,ZIDX))
|
---|
174 | . S ZCNT=$$CNTLST($NA(@ZPBASE@(ZCAT)))
|
---|
175 | . S $P(@ZCBASE@(ZATR),"^",2)=ZCNT ; UPDATE THE COUNT IN THE CAT RECORD
|
---|
176 | . S ZTOT=ZTOT+ZCNT
|
---|
177 | W "TOTAL: ",ZTOT,!
|
---|
178 | Q
|
---|
179 | ;
|
---|
180 | CNTLST(INLST) ; RETURNS THE NUMBER OF ELEMENTS IN THE LIST
|
---|
181 | ; INLST IS PASSED BY NAME
|
---|
182 | N ZI,ZDX,ZCOUNT
|
---|
183 | W INLST,!
|
---|
184 | S ZCOUNT=0
|
---|
185 | S ZDX=""
|
---|
186 | F ZI=$O(@INLST@(ZDX)):0 D Q:$O(@INLST@(ZDX))="" ; LOOP UNTIL THE END
|
---|
187 | . S ZCOUNT=ZCOUNT+1
|
---|
188 | . S ZDX=$O(@INLST@(ZDX))
|
---|
189 | . W "ZDX:",ZDX," ZCNT:",ZCOUNT,!
|
---|
190 | Q ZCOUNT
|
---|
191 | ;
|
---|
192 | XCPAT(CPATCAT) ; EXPORT TO FILE ALL PATIENTS IN CATEGORY CPATCAT
|
---|
193 | ;
|
---|
194 | I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
|
---|
195 | N ZI,ZJ,ZC,ZPATBASE
|
---|
196 | S ZPATBASE=$NA(@RIMBASE@("RIMTBL","PATS",CPATCAT))
|
---|
197 | S ZI=""
|
---|
198 | F ZJ=0:0 D Q:$O(@ZPATBASE@(ZI))="" ; TIL END
|
---|
199 | . S ZI=$O(@ZPATBASE@(ZI))
|
---|
200 | . D XPAT^GPLCCR(ZI,"","") ; EXPORT THE PATIENT TO A FILE
|
---|
201 | Q
|
---|
202 | ;
|
---|
203 | CPAT(CPATCAT) ; SHOW PATIENT DFNS FOR A CATEGORY CPATCAT
|
---|
204 | ;
|
---|
205 | I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
|
---|
206 | N ZI,ZJ,ZC,ZPATBASE
|
---|
207 | S ZC=0 ; COUNT FOR SPACING THE PRINTOUT
|
---|
208 | S ZPATBASE=$NA(@RIMBASE@("RIMTBL","PATS",CPATCAT))
|
---|
209 | S ZI=""
|
---|
210 | F ZJ=0:0 D Q:$O(@ZPATBASE@(ZI))="" ; TIL END
|
---|
211 | . S ZI=$O(@ZPATBASE@(ZI))
|
---|
212 | . S ZC=ZC+1 ; INCREMENT OUTPUT PER LINE COUNT
|
---|
213 | . W ZI," "
|
---|
214 | . I ZC=10 D ; NEW LINE
|
---|
215 | . . S ZC=0
|
---|
216 | . . W !
|
---|
217 | Q
|
---|
218 | ;
|
---|
219 | APUSH(AMAP,AVAL) ; ADD AVAL TO ATTRIBUTE MAP AMAP (AMAP PASSED BY NAME)
|
---|
220 | ; AMAP IS FORMED FOR ARRAY ACCESS: AMAP(0) IS THE COUNT
|
---|
221 | ; AND AMAP(N)=AVAL IS THE NTH AVAL
|
---|
222 | ; ALSO HASH ACCESS AMAP(AVAL)=N WHERE N IS THE ASSIGNED ORDER OF THE
|
---|
223 | ; MAP VALUE. INSTANCES OF THE MAP WILL USE $P(X,U,N)=AVAL TO PLACE
|
---|
224 | ; THE ATTRIBUTE IN ITS RIGHT PLACE. THE ATTRIBUTE VALUE IS STORED
|
---|
225 | ; SO THAT DIFFERENT MAPS CAN BE AUTOMATICALLY CROSSWALKED
|
---|
226 | ;
|
---|
227 | I '$D(@AMAP) D ; IF THE MAP DOES NOT EXIST
|
---|
228 | . S @AMAP@(0)=0 ; HAS ZERO ELEMENTS
|
---|
229 | S @AMAP@(0)=@AMAP@(0)+1 ;INCREMENT ELEMENT COUNT
|
---|
230 | S @AMAP@(@AMAP@(0))=AVAL ; ADD THE VALUE TO THE ARRAY
|
---|
231 | S @AMAP@(AVAL)=@AMAP@(0) ; ADD THE VALUE TO THE HASH WITH ARRAY REF
|
---|
232 | Q
|
---|
233 | ;
|
---|
234 | ASETUP ; SET UP GLOBALS AND VARS RIMBASE AND RIMTBL
|
---|
235 | I '$D(RIMBASE) S RIMBASE=$NA(^TMP("GPLRIM"))
|
---|
236 | I '$D(@RIMBASE) S @RIMBASE=""
|
---|
237 | I '$D(RIMTBL) S RIMTBL=$NA(^TMP("GPLRIM","RIMTBL","TABLE")) ; ATTR TABLE
|
---|
238 | S ^TMP("GPLRIM","TABLES","RIMTBL")=RIMTBL ; TABLE OF TABLES
|
---|
239 | Q
|
---|
240 | ;
|
---|
241 | AINIT ; INITIALIZE ATTRIBUTE TABLE
|
---|
242 | I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
|
---|
243 | K @RIMTBL
|
---|
244 | D APUSH(RIMTBL,"EXTRACTED")
|
---|
245 | D APUSH(RIMTBL,"NOTEXTRACTED")
|
---|
246 | D APUSH(RIMTBL,"HEADER")
|
---|
247 | D APUSH(RIMTBL,"NOPCP")
|
---|
248 | D APUSH(RIMTBL,"PCP")
|
---|
249 | D APUSH(RIMTBL,"PROBLEMS")
|
---|
250 | D APUSH(RIMTBL,"PROBCODE")
|
---|
251 | D APUSH(RIMTBL,"PROBNOCODE")
|
---|
252 | D APUSH(RIMTBL,"PROBDATE")
|
---|
253 | D APUSH(RIMTBL,"PROBNODATE")
|
---|
254 | D APUSH(RIMTBL,"VITALS")
|
---|
255 | D APUSH(RIMTBL,"VITALSCODE")
|
---|
256 | D APUSH(RIMTBL,"VITALSNOCODE")
|
---|
257 | D APUSH(RIMTBL,"VITALSDATE")
|
---|
258 | D APUSH(RIMTBL,"VITALSNODATE")
|
---|
259 | D APUSH(RIMTBL,"MEDS")
|
---|
260 | D APUSH(RIMTBL,"MEDSCODE")
|
---|
261 | D APUSH(RIMTBL,"MEDSNOCODE")
|
---|
262 | D APUSH(RIMTBL,"MEDSDATE")
|
---|
263 | D APUSH(RIMTBL,"MEDSNODATE")
|
---|
264 | Q
|
---|
265 | ;
|
---|
266 | APOST(PRSLT,PTBL,PVAL) ; POST AN ATTRIBUTE PVAL TO PRSLT USING PTBL
|
---|
267 | ; PSRLT AND PTBL ARE PASSED BY NAME. PVAL IS A STRING
|
---|
268 | ; PTBL IS THE NAME OF A TABLE IN @RIMBASE@("TABLES") - "RIMTBL"=ALL VALUES
|
---|
269 | ; PVAL WILL BE PLACED IN THE STRING PRSLT AT $P(X,U,@PTBL@(PVAL))
|
---|
270 | I '$D(RIMBASE) D ASETUP ; FOR COMMANDLINE PROCESSING
|
---|
271 | N USETBL
|
---|
272 | I '$D(@RIMBASE@("TABLES",PTBL)) D Q ; NO TABLE
|
---|
273 | . W "ERROR NO SUCH TABLE",!
|
---|
274 | S USETBL=@RIMBASE@("TABLES",PTBL)
|
---|
275 | S $P(@PRSLT,U,@USETBL@(PVAL))=PVAL
|
---|
276 | Q |
---|