source: ccr/trunk/p/GPLSNOA.m@ 230

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

added REACTION variables to alert processing

File size: 8.0 KB
Line 
1GPLSNOA ; 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^GPLSNOA 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^GPLSNOA",!
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) ZWR SNORTN
46 . K @SNOBASE@("VARS",SNOIEN) ; CLEAR OUT OLD VARS
47 . I $P(TTMP,"^",1)=1 S @SNOBASE@("VARS",SNOIEN)=TTERM_"^"_TTMP_"^"_SNORTN(0)
48 . ;
49 . ; EVALUATE THE VARIABLES AND CREATE AN ATTRIBUTE MAP
50 . ;
51 . S RATTR=$$SETATTR(SNOIEN) ; SET THE ATTRIBUTE STRING BASED ON THE VARS
52 . S @SNOBASE@("ATTR",SNOIEN)=RATTR ; SAVE THE ATRIBUTES FOR THIS DRUG
53 . ;
54 . N CATNAME,CATTBL
55 . S CATNAME=""
56 . D CPUSH(.CATNAME,SNOBASE,"SNOTBL",SNOIEN,RATTR) ; ADD TO CATEGORY
57 . ; W "CATEGORY NAME: ",CATNAME,!
58 . ;
59 . S SNOIEN=$O(@GMRBASE@(SNOIEN)) ; NEXT RECORD
60 . S @SNOBASE@("RESUME")=SNOIEN ; WHERE WE ARE LEAVING OFF THIS RUN
61 ; D PARY^GPLXPATH(@SNOBASE@("ATTRTBL"))
62 Q
63 ;
64TEXTRPC(ORTN,ITEXT) ; CALL THE LEXICON WITH ITEXT AND RETURN RESULTS IN ORTN
65 ;
66 ;N TTMP
67 W ITEXT,!
68 S TTMP=$$TEXT^LEXTRAN(ITEXT,"","","SCT","ORTN")
69 Q
70 ;
71ASETUP ; SET UP GLOBALS AND VARS SNOBASE AND SNOTBL
72 I '$D(SNOBASE) S SNOBASE=$NA(^TMP("GPLSNO"))
73 I '$D(@SNOBASE) S @SNOBASE=""
74 I '$D(GMRBASE) S GMRBASE=$NA(^GMRD(120.82))
75 I '$D(SNOTBL) S SNOTBL=$NA(^TMP("GPLSNO","SNOTBL","TABLE")) ; ATTR TABLE
76 S ^TMP("GPLSNO","TABLES","SNOTBL")=SNOTBL ; TABLE OF TABLES
77 Q
78 ;
79AINIT ; INITIALIZE ATTRIBUTE TABLE
80 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
81 K @SNOTBL
82 D APUSH^GPLRIMA(SNOTBL,"CODE")
83 D APUSH^GPLRIMA(SNOTBL,"NOCODE")
84 D APUSH^GPLRIMA(SNOTBL,"MULTICODE")
85 D APUSH^GPLRIMA(SNOTBL,"SUBMULTI")
86 D APUSH^GPLRIMA(SNOTBL,"DONE")
87 Q
88APOST(PRSLT,PTBL,PVAL) ; POST AN ATTRIBUTE PVAL TO PRSLT USING PTBL
89 ; PSRLT AND PTBL ARE PASSED BY NAME. PVAL IS A STRING
90 ; PTBL IS THE NAME OF A TABLE IN @SNOBASE@("TABLES") - "SNOTBL"=ALL VALUES
91 ; PVAL WILL BE PLACED IN THE STRING PRSLT AT $P(X,U,@PTBL@(PVAL))
92 I '$D(SNOBASE) D ASETUP ; FOR COMMANDLINE PROCESSING
93 N USETBL
94 I '$D(@SNOBASE@("TABLES",PTBL)) D Q ; NO TABLE
95 . W "ERROR NO SUCH TABLE",!
96 S USETBL=@SNOBASE@("TABLES",PTBL)
97 S $P(@PRSLT,U,@USETBL@(PVAL))=PVAL
98 Q
99SETATTR(SDFN) ; SET ATTRIBUTES BASED ON VARS
100 N SBASE,SATTR
101 S SBASE=$NA(@SNOBASE@("VARS",SDFN))
102 D APOST("SATTR","SNOTBL","DONE")
103 I $P(TTMP,"^",1)=1 D APOST("SATTR","SNOTBL","CODE")
104 I $P(TTMP,"^",1)=-1 D APOST("SATTR","SNOTBL","NOCODE")
105 Q SATTR ; GPL
106 I $D(@SBASE@("PROBLEMS",1)) D ;
107 . D APOST("SATTR","SNOTBL","PROBLEMS")
108 . ; W "POSTING PROBLEMS",!
109 I $D(@SBASE@("VITALS",1)) D APOST("SATTR","SNOTBL","VITALS")
110 I $D(@SBASE@("MEDS",1)) D ; IF THE PATIENT HAS MEDS VARIABLES
111 . D APOST("SATTR","SNOTBL","MEDS")
112 . N ZR,ZI
113 . D GETPA^GPLRIMA(.ZR,SDFN,"MEDS","MEDPRODUCTNAMECODEVALUE") ;CHECK FOR MED CODES
114 . I ZR(0)>0 D ; VAR LOOKUP WAS GOOD, CHECK FOR NON=NULL RETURN
115 . . F ZI=1:1:ZR(0) D ; LOOP THROUGH RETURNED VAR^VALUE PAIRS
116 . . . I $P(ZR(ZI),"^",2)'="" D APOST("SATTR","SNOTBL","MEDSCODE") ;CODES
117 . ; D PATD^GPLSNOA(2,"MEDS","MEDPRODUCTNAMECODEVALUE") CHECK FOR MED CODES
118 D APOST("SATTR","SNOTBL","NOTEXTRACTED") ; OUTPUT NOT YET PRODUCED
119 ; W "ATTRIBUTES: ",SATTR,!
120 Q SATTR
121 ;
122RESET ; KILL RESUME INDICATOR TO START OVER. ALSO KILL SNO TMP VALUES
123 K ^TMP("GPLSNO","RESUME")
124 K ^TMP("GPLSNO")
125 Q
126 ;
127CLIST ; LIST THE CATEGORIES
128 ;
129 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
130 N CLBASE,CLNUM,ZI,CLIDX
131 S CLBASE=$NA(@SNOBASE@("SNOTBL","CATS"))
132 S CLNUM=@CLBASE@(0)
133 F ZI=1:1:CLNUM D ; LOOP THROUGH THE CATEGORIES
134 . S CLIDX=@CLBASE@(ZI)
135 . W "(",$P(@CLBASE@(CLIDX),"^",1)
136 . W ":",$P(@CLBASE@(CLIDX),"^",2),") "
137 . W CLIDX,!
138 ; D PARY^GPLXPATH(CLBASE)
139 Q
140 ;
141CPUSH(CATRTN,CBASE,CTBL,CDFN,CATTR) ; ADD PATIENTS TO CATEGORIES
142 ; AND PASS BACK THE NAME OF THE CATEGORY TO WHICH THE PATIENT
143 ; WAS ADDED IN CATRTN, WHICH IS PASSED BY REFERENCE
144 ; CBASE IS WHERE TO PUT THE CATEGORIES PASSED BY NAME
145 ; CTBL IS THE NAME OF THE TABLE USED TO CREATE THE ATTRIBUTES,
146 ; PASSED BY NAME AND USED TO CREATE CATEGORY NAMES IE "@CTBL_X"
147 ; WHERE X IS THE CATEGORY NUMBER. CTBL(0) IS THE NUMBER OF CATEGORIES
148 ; CATBL(X)=CATTR STORES THE ATTRIBUTE IN THE CATEGORY
149 ; CDFN IS THE PATIENT DFN, CATTR IS THE ATTRIBUTE STRING
150 ; THE LIST OF PATIENTS IN A CATEGORY IS STORED INDEXED BY CATEGORY
151 ; NUMBER IE CTBL_X(CDFN)=""
152 ;
153 ; N CCTBL,CENTRY,CNUM,CCOUNT,CPATLIST
154 S CCTBL=$NA(@CBASE@(CTBL,"CATS"))
155 ; W "CBASE: ",CCTBL,!
156 ;
157 I '$D(@CCTBL@(CATTR)) D ; FIRST PATIENT IN THIS CATEGORY
158 . D PUSH^GPLXPATH(CCTBL,CATTR) ; ADD THE CATEGORY TO THE ARRAY
159 . S CNUM=@CCTBL@(0) ; ARRAY ENTRY NUMBER FOR THIS CATEGORY
160 . S CENTRY=CTBL_"_"_CNUM_U_0 ; TABLE ENTRY DEFAULT
161 . S @CCTBL@(CATTR)=CENTRY ; DEFAULT NON INCREMENTED TABLE ENTRY
162 . ; NOTE THAT P1 IS THE CATEGORY NAME MADE UP OF THE TABLE NAME
163 . ; AND CATGORY ARRAY NUMBER. P2 IS THE COUNT WHICH IS INITIALLY 0
164 ;
165 S CCOUNT=$P(@CCTBL@(CATTR),U,2) ; COUNT OF PATIENTS IN THIS CATEGORY
166 S CCOUNT=CCOUNT+1 ; INCREMENT THE COUNT
167 S $P(@CCTBL@(CATTR),U,2)=CCOUNT ; PUT IT BACK
168 ;
169 S CATRTN=$P(@CCTBL@(CATTR),U,1) ; THE CATEGORY NAME WHICH IS RETURNED
170 ;
171 S CPATLIST=$NA(@CBASE@(CTBL,"IENS",CATRTN)) ; BASE OF PAT LIST FOR THIS CAT
172 ; W "IENS BASE: ",CPATLIST,!
173 S @CPATLIST@(CDFN)="" ; ADD THIS PATIENT TO THE CAT PAT LIST
174 ;
175 Q
176 ;
177REUSE ; GET SAVED VALUES FROM ^TMP("GPLSAV") AND PUT THEM IN A DATABASE
178 ;
179 D ASETUP
180 D AINIT
181 N SNOI,SNOJ,SNOK,SNOSNO,SNOSEC,SNOIEN,SNOOLD,SNOSRCH
182 S SAVBASE=$NA(^TMP("GPLSAV","VARS"))
183 S SNOI=""
184 F D Q:$O(@SAVBASE@(SNOI))="" ;THE WHOLE LIST
185 . S SNOI=$O(@SAVBASE@(SNOI))
186 . S SNOJ=@SAVBASE@(SNOI)
187 . S SNOK=$P($P(SNOJ,"^",1)," ALLERGY",1)
188 . S SNOSRCH=$P(SNOJ,"^",1) ;SEARCH TERM USED TO OBTAIN SNOMED CODE
189 . S SNOIEN=$P(SNOJ,"^",3) ; IEN OF ELEMENT IN LEXICON
190 . S SNOSNO=$P(SNOJ,"^",4) ; SNOMED CODE
191 . S SNOSEC=$P(SNOJ,"^",5) ; SECTION OF SNOMED FOR THIS CODE
192 . S SNOOLD=$P(SNOJ,"^",7) ; OLD NUMBER FOR THIS CODE
193 . W "SEARCH:",SNOSRCH," IEN:",SNOIEN," CODE:",SNOSNO," SEC:",SNOSEC," OLD:",SNOOLD,!
194 . W SNOK,!
195 . W SNOJ,!
196 Q
197 ;
Note: See TracBrowser for help on using the repository browser.