source: ccr/trunk/p/GPLRIMA.m@ 102

Last change on this file since 102 was 102, checked in by George Lilly, 16 years ago

added functions to RIM reporting

File size: 10.3 KB
Line 
1GPLRIMA ; 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 ;
38ANALYZE(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 . ;
67 . ; EVALUATE THE VARIABLES AND CREATE AN ATTRIBUTE MAP
68 . ;
69 . S RATTR=$$SETATTR(RIMDFN) ; SET THE ATTRIBUTE STRING BASED ON THE VARS
70 . S @RIMBASE@("ATTR",RIMDFN)=RATTR ; SAVE THE ATRIBUTES FOR THIS PAT
71 . ;
72 . ; INCREMENT THE COUNT OF PATIENTS WITH THESE ATTRIBUTES IN ATTRTBL
73 . ;
74 . ; I '$D(@RIMBASE@("ATTRTBL",RATTR)) D ; IF FIRST PAT WITH THESE ATTRS
75 . ; . S @RIMBASE@("ATTRTBL",RATTR)=0 ; DEFAULT VALUE TO BE INCREMENTED
76 . ; S @RIMBASE@("ATTRTBL",RATTR)=@RIMBASE@("ATTRTBL",RATTR)+1 ; INCREMENT
77 . ;
78 . N CATNAME,CATTBL
79 . ; S CATBASE=$NA(@RIMBASE@("ANALYSIS"))
80 . S CATNAME=""
81 . D CPUSH(.CATNAME,RIMBASE,"RIMTBL",RIMDFN,RATTR) ; ADD TO CATEGORY
82 . W "CATEGORY NAME: ",CATNAME,!
83 . ;
84 . S RIMDFN=$O(^DPT(RIMDFN)) ; NEXT PATIENT
85 S @RIMBASE@("RESUME")=RIMDFN ; WHERE WE ARE LEAVING OFF THIS RUN
86 ; D PARY^GPLXPATH(@RIMBASE@("ATTRTBL"))
87 Q
88 ;
89SETATTR(SDFN) ; SET ATTRIBUTES BASED ON VARS
90 N SBASE,SATTR
91 S SBASE=$NA(@RIMBASE@("VARS",SDFN))
92 D APOST("SATTR","RIMTBL","HEADER")
93 I $D(@SBASE@("PROBLEMS",1)) D ;
94 . D APOST("SATTR","RIMTBL","PROBLEMS")
95 . W "POSTING PROBLEMS",!
96 I $D(@SBASE@("VITALS",1)) D APOST("SATTR","RIMTBL","VITALS")
97 I $D(@SBASE@("MEDS",1)) D APOST("SATTR","RIMTBL","MEDS")
98 D APOST("SATTR","RIMTBL","NOTEXTRACTED") ; OUTPUT NOT YET PRODUCED
99 W "ATTRIBUTES: ",SATTR,!
100 Q SATTR
101 ;
102RESET ; KILL RESUME INDICATOR TO START OVER. ALSO KILL RIM TMP VALUES
103 K ^TMP("GPLRIM","RESUME")
104 K ^TMP("GPLRIM")
105 Q
106 ;
107CLIST ; LIST THE CATEGORIES
108 ;
109 I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
110 N CLBASE,CLNUM,ZI,CLIDX
111 S CLBASE=$NA(@RIMBASE@("RIMTBL","CATS"))
112 S CLNUM=@CLBASE@(0)
113 F ZI=1:1:CLNUM D ; LOOP THROUGH THE CATEGORIES
114 . S CLIDX=@CLBASE@(ZI)
115 . W "(",$P(@CLBASE@(CLIDX),"^",1)
116 . W ":",$P(@CLBASE@(CLIDX),"^",2),") "
117 . W CLIDX,!
118 ; D PARY^GPLXPATH(CLBASE)
119 Q
120 ;
121CPUSH(CATRTN,CBASE,CTBL,CDFN,CATTR) ; ADD PATIENTS TO CATEGORIES
122 ; AND PASS BACK THE NAME OF THE CATEGORY TO WHICH THE PATIENT
123 ; WAS ADDED IN CATRTN, WHICH IS PASSED BY REFERENCE
124 ; CBASE IS WHERE TO PUT THE CATEGORIES PASSED BY NAME
125 ; CTBL IS THE NAME OF THE TABLE USED TO CREATE THE ATTRIBUTES,
126 ; PASSED BY NAME AND USED TO CREATE CATEGORY NAMES IE "@CTBL_X"
127 ; WHERE X IS THE CATEGORY NUMBER. CTBL(0) IS THE NUMBER OF CATEGORIES
128 ; CATBL(X)=CATTR STORES THE ATTRIBUTE IN THE CATEGORY
129 ; CDFN IS THE PATIENT DFN, CATTR IS THE ATTRIBUTE STRING
130 ; THE LIST OF PATIENTS IN A CATEGORY IS STORED INDEXED BY CATEGORY
131 ; NUMBER IE CTBL_X(CDFN)=""
132 ;
133 ; N CCTBL,CENTRY,CNUM,CCOUNT,CPATLIST
134 S CCTBL=$NA(@CBASE@(CTBL,"CATS"))
135 W "CBASE: ",CCTBL,!
136 ;
137 I '$D(@CCTBL@(CATTR)) D ; FIRST PATIENT IN THIS CATEGORY
138 . D PUSH^GPLXPATH(CCTBL,CATTR) ; ADD THE CATEGORY TO THE ARRAY
139 . S CNUM=@CCTBL@(0) ; ARRAY ENTRY NUMBER FOR THIS CATEGORY
140 . S CENTRY=CTBL_"_"_CNUM_U_0 ; TABLE ENTRY DEFAULT
141 . S @CCTBL@(CATTR)=CENTRY ; DEFAULT NON INCREMENTED TABLE ENTRY
142 . ; NOTE THAT P1 IS THE CATEGORY NAME MADE UP OF THE TABLE NAME
143 . ; AND CATGORY ARRAY NUMBER. P2 IS THE COUNT WHICH IS INITIALLY 0
144 ;
145 S CCOUNT=$P(@CCTBL@(CATTR),U,2) ; COUNT OF PATIENTS IN THIS CATEGORY
146 S CCOUNT=CCOUNT+1 ; INCREMENT THE COUNT
147 S $P(@CCTBL@(CATTR),U,2)=CCOUNT ; PUT IT BACK
148 ;
149 S CATRTN=$P(@CCTBL@(CATTR),U,1) ; THE CATEGORY NAME WHICH IS RETURNED
150 ;
151 S CPATLIST=$NA(@CBASE@(CTBL,"PATS",CATRTN)) ; BASE OF PAT LIST FOR THIS CAT
152 W "PATS BASE: ",CPATLIST,!
153 S @CPATLIST@(CDFN)="" ; ADD THIS PATIENT TO THE CAT PAT LIST
154 ;
155 Q
156 ;
157CCOUNT ; RECOUNT THE CATEGORIES.. USE IN CASE OF RESTART OF ANALYZE
158 ;
159 I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
160 N ZI,ZJ,ZCNT,ZIDX,ZCAT,ZATR,ZTOT
161 S ZCBASE=$NA(@RIMBASE@("RIMTBL","CATS")) ; BASE OF CATEGORIES
162 S ZPBASE=$NA(@RIMBASE@("RIMTBL","PATS")) ; BASE OF PATIENTS
163 S ZTOT=0 ; INITIALIZE OVERALL TOTAL
164 F ZI=1:1:@ZCBASE@(0) D ; FOR ALL CATS
165 . S ZCNT=0
166 . S ZATR=@ZCBASE@(ZI) ; THE ATTRIBUTE OF THE CATEGORY
167 . S ZCAT=$P(@ZCBASE@(ZATR),"^",1) ; USE IT TO LOOK UP THE CATEGORY NAME
168 . ; S ZIDX=$O(@ZPBASE@(ZCAT,"")) ; FIRST PATIENT IN LIST
169 . ; F ZJ=0:0 D Q:$O(@ZPBASE@(ZCAT,ZIDX))="" ; ALL PATIENTS IN THE LISTS
170 . ; . S ZCNT=ZCNT+1 ; INCREMENT THE COUNT
171 . ; . W ZCAT," DFN:",ZIDX," COUNT:",ZCNT,!
172 . ; . S ZIDX=$O(@ZPBASE@(ZCAT,ZIDX))
173 . S ZCNT=$$CNTLST($NA(@ZPBASE@(ZCAT)))
174 . S $P(@ZCBASE@(ZATR),"^",2)=ZCNT ; UPDATE THE COUNT IN THE CAT RECORD
175 . S ZTOT=ZTOT+ZCNT
176 W "TOTAL: ",ZTOT,!
177 Q
178 ;
179CNTLST(INLST) ; RETURNS THE NUMBER OF ELEMENTS IN THE LIST
180 ; INLST IS PASSED BY NAME
181 N ZI,ZDX,ZCOUNT
182 W INLST,!
183 S ZCOUNT=0
184 S ZDX=""
185 F ZI=$O(@INLST@(ZDX)):0 D Q:$O(@INLST@(ZDX))="" ; LOOP UNTIL THE END
186 . S ZCOUNT=ZCOUNT+1
187 . S ZDX=$O(@INLST@(ZDX))
188 . W "ZDX:",ZDX," ZCNT:",ZCOUNT,!
189 Q ZCOUNT
190 ;
191APUSH(AMAP,AVAL) ; ADD AVAL TO ATTRIBUTE MAP AMAP (AMAP PASSED BY NAME)
192 ; AMAP IS FORMED FOR ARRAY ACCESS: AMAP(0) IS THE COUNT
193 ; AND AMAP(N)=AVAL IS THE NTH AVAL
194 ; ALSO HASH ACCESS AMAP(AVAL)=N WHERE N IS THE ASSIGNED ORDER OF THE
195 ; MAP VALUE. INSTANCES OF THE MAP WILL USE $P(X,U,N)=AVAL TO PLACE
196 ; THE ATTRIBUTE IN ITS RIGHT PLACE. THE ATTRIBUTE VALUE IS STORED
197 ; SO THAT DIFFERENT MAPS CAN BE AUTOMATICALLY CROSSWALKED
198 ;
199 I '$D(@AMAP) D ; IF THE MAP DOES NOT EXIST
200 . S @AMAP@(0)=0 ; HAS ZERO ELEMENTS
201 S @AMAP@(0)=@AMAP@(0)+1 ;INCREMENT ELEMENT COUNT
202 S @AMAP@(@AMAP@(0))=AVAL ; ADD THE VALUE TO THE ARRAY
203 S @AMAP@(AVAL)=@AMAP@(0) ; ADD THE VALUE TO THE HASH WITH ARRAY REF
204 Q
205 ;
206ASETUP ; SET UP GLOBALS AND VARS RIMBASE AND RIMTBL
207 I '$D(RIMBASE) S RIMBASE=$NA(^TMP("GPLRIM"))
208 I '$D(@RIMBASE) S @RIMBASE=""
209 I '$D(RIMTBL) S RIMTBL=$NA(^TMP("GPLRIM","RIMTBL","TABLE")) ; ATTR TABLE
210 S ^TMP("GPLRIM","TABLES","RIMTBL")=RIMTBL ; TABLE OF TABLES
211 Q
212 ;
213AINIT ; INITIALIZE ATTRIBUTE TABLE
214 I '$D(RIMBASE) D ASETUP ; FOR COMMAND LINE CALLS
215 K @RIMTBL
216 D APUSH(RIMTBL,"EXTRACTED")
217 D APUSH(RIMTBL,"NOTEXTRACTED")
218 D APUSH(RIMTBL,"HEADER")
219 D APUSH(RIMTBL,"NOPCP")
220 D APUSH(RIMTBL,"PCP")
221 D APUSH(RIMTBL,"PROBLEMS")
222 D APUSH(RIMTBL,"PROBCODE")
223 D APUSH(RIMTBL,"PROBNOCODE")
224 D APUSH(RIMTBL,"PROBDATE")
225 D APUSH(RIMTBL,"PROBNODATE")
226 D APUSH(RIMTBL,"VITALS")
227 D APUSH(RIMTBL,"VITALSCODE")
228 D APUSH(RIMTBL,"VITALSNOCODE")
229 D APUSH(RIMTBL,"VITALSDATE")
230 D APUSH(RIMTBL,"VITALSNODATE")
231 D APUSH(RIMTBL,"MEDS")
232 D APUSH(RIMTBL,"MEDSCODE")
233 D APUSH(RIMTBL,"MEDSNOCODE")
234 D APUSH(RIMTBL,"MEDSDATE")
235 D APUSH(RIMTBL,"MEDSNODATE")
236 Q
237 ;
238APOST(PRSLT,PTBL,PVAL) ; POST AN ATTRIBUTE PVAL TO PRSLT USING PTBL
239 ; PSRLT AND PTBL ARE PASSED BY NAME. PVAL IS A STRING
240 ; PTBL IS THE NAME OF A TABLE IN @RIMBASE@("TABLES") - "RIMTBL"=ALL VALUES
241 ; PVAL WILL BE PLACED IN THE STRING PRSLT AT $P(X,U,@PTBL@(PVAL))
242 I '$D(RIMBASE) D ASETUP ; FOR COMMANDLINE PROCESSING
243 N USETBL
244 I '$D(@RIMBASE@("TABLES",PTBL)) D Q ; NO TABLE
245 . W "ERROR NO SUCH TABLE",!
246 S USETBL=@RIMBASE@("TABLES",PTBL)
247 S $P(@PRSLT,U,@USETBL@(PVAL))=PVAL
248 Q
Note: See TracBrowser for help on using the repository browser.