source: ccr/trunk/p/KBAICSNA.m@ 765

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

updated alert coding analysis

File size: 8.7 KB
Line 
1KBAICSNA ; CCDCCR/GPL - SNOMED CT ANALYSIS ROUTINES; 10/14/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 ANALYZE THE POTENTIAL RETRIEVAL OF SNOMED CT CODES
21 ; FOR PATIENT DRUG ALLERGIES FOR INCLUSION IN THE CCR OR CCD
22 ; USING THE VISTA LEXICON ^LEX
23 ;
24ANALYZE(BEGIEN,IENCNT) ; SNOMED RETRIEVAL ANALYSIS ROUTINE
25 ; BEGINS AT BEGIEN AND GOES FOR IENCNT DRUGS IN GMRD
26 ; TO RESUME AT NEXT DRUG, USE BEGIEN=""
27 ; USE RESET^KBAICSNA TO RESET TO TOP OF DRUG LIST
28 ;
29 N SNOARY,SNOTMP,SNOI,SNOIEN,RATTR
30 N CCRGLO
31 D ASETUP ; SET UP VARIABLES AND GLOBALS
32 D AINIT ; INITIALIZE ATTRIBUTE VALUE TABLE
33 I '$D(@SNOBASE@("RESUME")) S @SNOBASE@("RESUME")=$O(@GMRBASE@(1)) ;1ST TME
34 S RESUME=@SNOBASE@("RESUME") ; WHERE WE LEFT OFF LAST RUN
35 S SNOIEN=BEGIEN ; BEGIN WITH THE BEGIEN RECORD
36 I SNOIEN="" S SNOIEN=RESUME
37 I +SNOIEN=0 D Q ; AT THE END OF THE ALLERGY LIST
38 . W "END OF DRUG LIST, CALL RESET^KBAICSNA",!
39 F SNOI=1:1:IENCNT D Q:+SNOIEN=0 ; FOR IENCNT NUMBER OF PATIENTS OR END
40 . ;D CCRRPC^GPLCCR(.CCRGLO,SNOIEN,"CCR","","","") ;PROCESS THE CCR
41 . W SNOIEN,@GMRBASE@(SNOIEN,0),!
42 . N SNORTN,TTERM ; RETURN ARRAY
43 . S TTERM=$P(@GMRBASE@(SNOIEN,0),"^",1)_" ALLERGY"
44 . D TEXTRPC(.SNORTN,TTERM)
45 . I $D(SNORTN) D ;
46 . . S TVUID=$$GET1^DIQ(120.82,SNOIEN,"VUID")
47 . . W "VUID:",TVUID,!
48 . . K @SNOBASE@("VARS",SNOIEN) ; CLEAR OUT OLD VARS
49 . . I $P(TTMP,"^",1)=1 S @SNOBASE@("VARS",SNOIEN)=TTERM_"^"_TTMP_"^"_SNORTN(0)_"^"_TVUID_"^"_SNORTN("F")
50 . . ;
51 . . ; EVALUATE THE VARIABLES AND CREATE AN ATTRIBUTE MAP
52 . . ;
53 . . S RATTR=$$SETATTR(SNOIEN) ; SET THE ATTRIBUTE STRING BASED ON THE VARS
54 . . S @SNOBASE@("ATTR",SNOIEN)=RATTR ; SAVE THE ATRIBUTES FOR THIS DRUG
55 . . ;
56 . . N CATNAME,CATTBL
57 . . S CATNAME=""
58 . . D CPUSH(.CATNAME,SNOBASE,"SNOTBL",SNOIEN,RATTR) ; ADD TO CATEGORY
59 . . ; W "CATEGORY NAME: ",CATNAME,!
60 . . ;
61 . S SNOIEN=$O(@GMRBASE@(SNOIEN)) ; NEXT RECORD
62 . S @SNOBASE@("RESUME")=SNOIEN ; WHERE WE ARE LEAVING OFF THIS RUN
63 ; D PARY^GPLXPATH(@SNOBASE@("ATTRTBL"))
64 Q
65 ;
66TEXTRPC(ORTN,ITEXT) ; CALL THE LEXICON WITH ITEXT AND RETURN RESULTS IN ORTN
67 ;
68 ;N TTMP
69 W ITEXT,!
70 S TTMP=$$TEXT^LEXTRAN(ITEXT,"","","SCT","ORTN")
71 Q
72 ;
73ASETUP ; SET UP GLOBALS AND VARS SNOBASE AND SNOTBL
74 I '$D(SNOBASE) S SNOBASE=$NA(^TMP("GPLSNO"))
75 I '$D(@SNOBASE) S @SNOBASE=""
76 I '$D(GMRBASE) S GMRBASE=$NA(^GMRD(120.82))
77 I '$D(SNOTBL) S SNOTBL=$NA(^TMP("GPLSNO","SNOTBL","TABLE")) ; ATTR TABLE
78 S ^TMP("GPLSNO","TABLES","SNOTBL")=SNOTBL ; TABLE OF TABLES
79 Q
80 ;
81AINIT ; INITIALIZE ATTRIBUTE TABLE
82 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
83 K @SNOTBL
84 D APUSH^GPLRIMA(SNOTBL,"CODE")
85 D APUSH^GPLRIMA(SNOTBL,"NOCODE")
86 D APUSH^GPLRIMA(SNOTBL,"MULTICODE")
87 D APUSH^GPLRIMA(SNOTBL,"SUBMULTI")
88 D APUSH^GPLRIMA(SNOTBL,"DONE")
89 Q
90APOST(PRSLT,PTBL,PVAL) ; POST AN ATTRIBUTE PVAL TO PRSLT USING PTBL
91 ; PSRLT AND PTBL ARE PASSED BY NAME. PVAL IS A STRING
92 ; PTBL IS THE NAME OF A TABLE IN @SNOBASE@("TABLES") - "SNOTBL"=ALL VALUES
93 ; PVAL WILL BE PLACED IN THE STRING PRSLT AT $P(X,U,@PTBL@(PVAL))
94 I '$D(SNOBASE) D ASETUP ; FOR COMMANDLINE PROCESSING
95 N USETBL
96 I '$D(@SNOBASE@("TABLES",PTBL)) D Q ; NO TABLE
97 . W "ERROR NO SUCH TABLE",!
98 S USETBL=@SNOBASE@("TABLES",PTBL)
99 S $P(@PRSLT,U,@USETBL@(PVAL))=PVAL
100 Q
101SETATTR(SDFN) ; SET ATTRIBUTES BASED ON VARS
102 N SBASE,SATTR
103 S SBASE=$NA(@SNOBASE@("VARS",SDFN))
104 D APOST("SATTR","SNOTBL","DONE")
105 I $P(TTMP,"^",1)=1 D APOST("SATTR","SNOTBL","CODE")
106 I $P(TTMP,"^",1)=-1 D APOST("SATTR","SNOTBL","NOCODE")
107 Q SATTR ; GPL
108 I $D(@SBASE@("PROBLEMS",1)) D ;
109 . D APOST("SATTR","SNOTBL","PROBLEMS")
110 . ; W "POSTING PROBLEMS",!
111 I $D(@SBASE@("VITALS",1)) D APOST("SATTR","SNOTBL","VITALS")
112 I $D(@SBASE@("MEDS",1)) D ; IF THE PATIENT HAS MEDS VARIABLES
113 . D APOST("SATTR","SNOTBL","MEDS")
114 . N ZR,ZI
115 . D GETPA^GPLRIMA(.ZR,SDFN,"MEDS","MEDPRODUCTNAMECODEVALUE") ;CHECK FOR MED CODES
116 . I ZR(0)>0 D ; VAR LOOKUP WAS GOOD, CHECK FOR NON=NULL RETURN
117 . . F ZI=1:1:ZR(0) D ; LOOP THROUGH RETURNED VAR^VALUE PAIRS
118 . . . I $P(ZR(ZI),"^",2)'="" D APOST("SATTR","SNOTBL","MEDSCODE") ;CODES
119 . ; D PATD^KBAICSNA(2,"MEDS","MEDPRODUCTNAMECODEVALUE") CHECK FOR MED CODES
120 D APOST("SATTR","SNOTBL","NOTEXTRACTED") ; OUTPUT NOT YET PRODUCED
121 ; W "ATTRIBUTES: ",SATTR,!
122 Q SATTR
123 ;
124RESET ; KILL RESUME INDICATOR TO START OVER. ALSO KILL SNO TMP VALUES
125 K ^TMP("GPLSNO","RESUME")
126 K ^TMP("GPLSNO")
127 Q
128 ;
129CLIST ; LIST THE CATEGORIES
130 ;
131 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
132 N CLBASE,CLNUM,ZI,CLIDX
133 S CLBASE=$NA(@SNOBASE@("SNOTBL","CATS"))
134 S CLNUM=@CLBASE@(0)
135 F ZI=1:1:CLNUM D ; LOOP THROUGH THE CATEGORIES
136 . S CLIDX=@CLBASE@(ZI)
137 . W "(",$P(@CLBASE@(CLIDX),"^",1)
138 . W ":",$P(@CLBASE@(CLIDX),"^",2),") "
139 . W CLIDX,!
140 ; D PARY^GPLXPATH(CLBASE)
141 Q
142 ;
143CPUSH(CATRTN,CBASE,CTBL,CDFN,CATTR) ; ADD PATIENTS TO CATEGORIES
144 ; AND PASS BACK THE NAME OF THE CATEGORY TO WHICH THE PATIENT
145 ; WAS ADDED IN CATRTN, WHICH IS PASSED BY REFERENCE
146 ; CBASE IS WHERE TO PUT THE CATEGORIES PASSED BY NAME
147 ; CTBL IS THE NAME OF THE TABLE USED TO CREATE THE ATTRIBUTES,
148 ; PASSED BY NAME AND USED TO CREATE CATEGORY NAMES IE "@CTBL_X"
149 ; WHERE X IS THE CATEGORY NUMBER. CTBL(0) IS THE NUMBER OF CATEGORIES
150 ; CATBL(X)=CATTR STORES THE ATTRIBUTE IN THE CATEGORY
151 ; CDFN IS THE PATIENT DFN, CATTR IS THE ATTRIBUTE STRING
152 ; THE LIST OF PATIENTS IN A CATEGORY IS STORED INDEXED BY CATEGORY
153 ; NUMBER IE CTBL_X(CDFN)=""
154 ;
155 ; N CCTBL,CENTRY,CNUM,CCOUNT,CPATLIST
156 S CCTBL=$NA(@CBASE@(CTBL,"CATS"))
157 ; W "CBASE: ",CCTBL,!
158 ;
159 I '$D(@CCTBL@(CATTR)) D ; FIRST PATIENT IN THIS CATEGORY
160 . D PUSH^GPLXPATH(CCTBL,CATTR) ; ADD THE CATEGORY TO THE ARRAY
161 . S CNUM=@CCTBL@(0) ; ARRAY ENTRY NUMBER FOR THIS CATEGORY
162 . S CENTRY=CTBL_"_"_CNUM_U_0 ; TABLE ENTRY DEFAULT
163 . S @CCTBL@(CATTR)=CENTRY ; DEFAULT NON INCREMENTED TABLE ENTRY
164 . ; NOTE THAT P1 IS THE CATEGORY NAME MADE UP OF THE TABLE NAME
165 . ; AND CATGORY ARRAY NUMBER. P2 IS THE COUNT WHICH IS INITIALLY 0
166 ;
167 S CCOUNT=$P(@CCTBL@(CATTR),U,2) ; COUNT OF PATIENTS IN THIS CATEGORY
168 S CCOUNT=CCOUNT+1 ; INCREMENT THE COUNT
169 S $P(@CCTBL@(CATTR),U,2)=CCOUNT ; PUT IT BACK
170 ;
171 S CATRTN=$P(@CCTBL@(CATTR),U,1) ; THE CATEGORY NAME WHICH IS RETURNED
172 ;
173 S CPATLIST=$NA(@CBASE@(CTBL,"IENS",CATRTN)) ; BASE OF PAT LIST FOR THIS CAT
174 ; W "IENS BASE: ",CPATLIST,!
175 S @CPATLIST@(CDFN)="" ; ADD THIS PATIENT TO THE CAT PAT LIST
176 ;
177 Q
178 ;
179REUSE ; GET SAVED VALUES FROM ^TMP("GPLSAV") AND PUT THEM IN A DATABASE
180 ;
181 D ASETUP
182 D AINIT
183 N SNOI,SNOJ,SNOK,SNOSNO,SNOSEC,SNOIEN,SNOOLD,SNOSRCH
184 D DO^KBAICX1 ; INITIALIZE GPLSAV VARIABLES
185 ;S SAVBASE=$NA(^TMP("GPLSAV","VARS"))
186 S SAVBASE=$NA(@SNOBASE@("VARS"))
187 S CSVARY=$NA(^TMP("GPLSNO","CSV"))
188 K @CSVARY
189 D PUSH^GPLXPATH(CSVARY,"VUID|VUIDText|MediationCode|MediationText") ; header for CSV file
190 S SNOI=""
191 F D Q:$O(@SAVBASE@(SNOI))="" ;THE WHOLE LIST
192 . S SNOI=$O(@SAVBASE@(SNOI))
193 . S SNOJ=@SAVBASE@(SNOI)
194 . S SNOK=$P($P(SNOJ,"^",1)," ALLERGY",1)
195 . S SNOSRCH=$P(SNOJ,"^",1) ;SEARCH TERM USED TO OBTAIN SNOMED CODE
196 . S SNOIEN=$P(SNOJ,"^",3) ; IEN OF ELEMENT IN LEXICON
197 . S SNOSNO=$P(SNOJ,"^",4) ; SNOMED CODE
198 . S SNOSEC=$P(SNOJ,"^",5) ; SECTION OF SNOMED FOR THIS CODE
199 . S SNOOLD=$P(SNOJ,"^",7) ; OLD NUMBER FOR THIS CODE
200 . S SNOVUID=$P(SNOJ,"^",9) ; VUID FOR THIS RECORD
201 . S SNOTXT=$P(SNOJ,"^",10) ; NOMED TEXT FOR CODE
202 . D PUSH^GPLXPATH(CSVARY,SNOVUID_"|"_$P(SNOSRCH," ALLERGY",1)_"|"_SNOSNO_"|"_SNOTXT)
203 . W "SEARCH:",SNOSRCH," IEN:",SNOIEN," CODE:",SNOSNO," SEC:",SNOSEC," OLD:",SNOOLD,!
204 . W SNOK,!
205 . W SNOJ,!
206 S OARY=$NA(@CSVARY@(1)) ; SETUP FOR OUTPUT ROUTINE
207 D PARY^GPLXPATH(CSVARY)
208 S OFILE="GMR_ALLERGY_MAPPING_TABLE.csv"
209 S ODIR="/home/vademo2/"
210 S ZY=$$OUTPUT^GPLXPATH(OARY,OFILE,ODIR)
211 I ZY W "WROTE ",OFILE," to ",ODIR,!
212 Q
213 ;
Note: See TracBrowser for help on using the repository browser.