source: ccr/trunk/p/C0CSNOA.m@ 1742

Last change on this file since 1742 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CSNOA.m1290
    /ccr/branches/ohum/p/C0CSNOA.m1291-1543
    /ccr/branches/ohum/p/p/C0CSNOA.m1287-1289
File size: 7.3 KB
RevLine 
[1544]1C0CSNOA ; CCDCCR/GPL - SNOMED CT ANALYSIS ROUTINES; 10/14/08
[1586]2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
[1544]3 ;Copyright 2008,2009 George Lilly, University of Minnesota.
4 ;
[1586]5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU Affero General Public License as
7 ; published by the Free Software Foundation, either version 3 of the
8 ; License, or (at your option) any later version.
[1544]9 ;
[1586]10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU Affero General Public License for more details.
[1544]14 ;
[1586]15 ; You should have received a copy of the GNU Affero General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
[1544]17 ;
[1586]18ANALYZE(BEGIEN,IENCNT) ; SNOMED RETRIEVAL ANALYSIS ROUTINE
19 ; BEGINS AT BEGIEN AND GOES FOR IENCNT DRUGS IN GMRD
20 ; TO RESUME AT NEXT DRUG, USE BEGIEN=""
21 ; USE RESET^C0CSNOA TO RESET TO TOP OF DRUG LIST
[1544]22 ;
[1586]23 N SNOARY,SNOTMP,SNOI,SNOIEN,RATTR
24 N CCRGLO
25 D ASETUP ; SET UP VARIABLES AND GLOBALS
26 D AINIT ; INITIALIZE ATTRIBUTE VALUE TABLE
27 I '$D(@SNOBASE@("RESUME")) S @SNOBASE@("RESUME")=$O(@GMRBASE@(1)) ;1ST TME
28 S RESUME=@SNOBASE@("RESUME") ; WHERE WE LEFT OFF LAST RUN
29 S SNOIEN=BEGIEN ; BEGIN WITH THE BEGIEN RECORD
30 I SNOIEN="" S SNOIEN=RESUME
31 I +SNOIEN=0 D Q ; AT THE END OF THE ALLERGY LIST
32 . W "END OF DRUG LIST, CALL RESET^C0CSNOA",!
33 F SNOI=1:1:IENCNT D Q:+SNOIEN=0 ; FOR IENCNT NUMBER OF PATIENTS OR END
34 . ;D CCRRPC^C0CCCR(.CCRGLO,SNOIEN,"CCR","","","") ;PROCESS THE CCR
35 . W SNOIEN,@GMRBASE@(SNOIEN,0),!
36 . N SNORTN,TTERM ; RETURN ARRAY
37 . S TTERM=$P(@GMRBASE@(SNOIEN,0),"^",1)_" ALLERGY"
38 . D TEXTRPC(.SNORTN,TTERM)
39 . ; I $D(SNORTN) ZWR SNORTN
40 . K @SNOBASE@("VARS",SNOIEN) ; CLEAR OUT OLD VARS
41 . I $P(TTMP,"^",1)=1 S @SNOBASE@("VARS",SNOIEN)=TTERM_"^"_TTMP_"^"_SNORTN(0)
42 . ;
43 . ; EVALUATE THE VARIABLES AND CREATE AN ATTRIBUTE MAP
44 . ;
45 . S RATTR=$$SETATTR(SNOIEN) ; SET THE ATTRIBUTE STRING BASED ON THE VARS
46 . S @SNOBASE@("ATTR",SNOIEN)=RATTR ; SAVE THE ATRIBUTES FOR THIS DRUG
47 . ;
48 . N CATNAME,CATTBL
49 . S CATNAME=""
50 . D CPUSH(.CATNAME,SNOBASE,"SNOTBL",SNOIEN,RATTR) ; ADD TO CATEGORY
51 . ; W "CATEGORY NAME: ",CATNAME,!
52 . ;
53 . S SNOIEN=$O(@GMRBASE@(SNOIEN)) ; NEXT RECORD
54 . S @SNOBASE@("RESUME")=SNOIEN ; WHERE WE ARE LEAVING OFF THIS RUN
55 ; D PARY^C0CXPATH(@SNOBASE@("ATTRTBL"))
56 Q
57 ;
[1544]58TEXTRPC(ORTN,ITEXT) ; CALL THE LEXICON WITH ITEXT AND RETURN RESULTS IN ORTN
59 ;
60 ;N TTMP
61 W ITEXT,!
62 S TTMP=$$TEXT^LEXTRAN(ITEXT,"","","SCT","ORTN")
63 Q
64 ;
65ASETUP ; SET UP GLOBALS AND VARS SNOBASE AND SNOTBL
[1586]66 I '$D(SNOBASE) S SNOBASE=$NA(^TMP("C0CSNO"))
67 I '$D(@SNOBASE) S @SNOBASE=""
68 I '$D(GMRBASE) S GMRBASE=$NA(^GMRD(120.82))
69 I '$D(SNOTBL) S SNOTBL=$NA(^TMP("C0CSNO","SNOTBL","TABLE")) ; ATTR TABLE
70 S ^TMP("C0CSNO","TABLES","SNOTBL")=SNOTBL ; TABLE OF TABLES
71 Q
72 ;
[1544]73AINIT ; INITIALIZE ATTRIBUTE TABLE
[1586]74 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
75 K @SNOTBL
76 D APUSH^C0CRIMA(SNOTBL,"CODE")
77 D APUSH^C0CRIMA(SNOTBL,"NOCODE")
78 D APUSH^C0CRIMA(SNOTBL,"MULTICODE")
79 D APUSH^C0CRIMA(SNOTBL,"SUBMULTI")
80 D APUSH^C0CRIMA(SNOTBL,"DONE")
81 Q
[1544]82APOST(PRSLT,PTBL,PVAL) ; POST AN ATTRIBUTE PVAL TO PRSLT USING PTBL
[1586]83 ; PSRLT AND PTBL ARE PASSED BY NAME. PVAL IS A STRING
84 ; PTBL IS THE NAME OF A TABLE IN @SNOBASE@("TABLES") - "SNOTBL"=ALL VALUES
85 ; PVAL WILL BE PLACED IN THE STRING PRSLT AT $P(X,U,@PTBL@(PVAL))
86 I '$D(SNOBASE) D ASETUP ; FOR COMMANDLINE PROCESSING
87 N USETBL
88 I '$D(@SNOBASE@("TABLES",PTBL)) D Q ; NO TABLE
89 . W "ERROR NO SUCH TABLE",!
90 S USETBL=@SNOBASE@("TABLES",PTBL)
91 S $P(@PRSLT,U,@USETBL@(PVAL))=PVAL
92 Q
[1544]93SETATTR(SDFN) ; SET ATTRIBUTES BASED ON VARS
[1586]94 N SBASE,SATTR
95 S SBASE=$NA(@SNOBASE@("VARS",SDFN))
96 D APOST("SATTR","SNOTBL","DONE")
97 I $P(TTMP,"^",1)=1 D APOST("SATTR","SNOTBL","CODE")
98 I $P(TTMP,"^",1)=-1 D APOST("SATTR","SNOTBL","NOCODE")
99 Q SATTR ; C0C
100 I $D(@SBASE@("PROBLEMS",1)) D ;
101 . D APOST("SATTR","SNOTBL","PROBLEMS")
102 . ; W "POSTING PROBLEMS",!
103 I $D(@SBASE@("VITALS",1)) D APOST("SATTR","SNOTBL","VITALS")
104 I $D(@SBASE@("MEDS",1)) D ; IF THE PATIENT HAS MEDS VARIABLES
105 . D APOST("SATTR","SNOTBL","MEDS")
106 . N ZR,ZI
107 . D GETPA^C0CRIMA(.ZR,SDFN,"MEDS","MEDPRODUCTNAMECODEVALUE") ;CHECK FOR MED CODES
108 . I ZR(0)>0 D ; VAR LOOKUP WAS GOOD, CHECK FOR NON=NULL RETURN
109 . . F ZI=1:1:ZR(0) D ; LOOP THROUGH RETURNED VAR^VALUE PAIRS
110 . . . I $P(ZR(ZI),"^",2)'="" D APOST("SATTR","SNOTBL","MEDSCODE") ;CODES
111 . ; D PATD^C0CSNOA(2,"MEDS","MEDPRODUCTNAMECODEVALUE") CHECK FOR MED CODES
112 D APOST("SATTR","SNOTBL","NOTEXTRACTED") ; OUTPUT NOT YET PRODUCED
113 ; W "ATTRIBUTES: ",SATTR,!
114 Q SATTR
115 ;
[1544]116RESET ; KILL RESUME INDICATOR TO START OVER. ALSO KILL SNO TMP VALUES
[1586]117 K ^TMP("C0CSNO","RESUME")
118 K ^TMP("C0CSNO")
119 Q
120 ;
[1544]121CLIST ; LIST THE CATEGORIES
[1586]122 ;
123 I '$D(SNOBASE) D ASETUP ; FOR COMMAND LINE CALLS
124 N CLBASE,CLNUM,ZI,CLIDX
125 S CLBASE=$NA(@SNOBASE@("SNOTBL","CATS"))
126 S CLNUM=@CLBASE@(0)
127 F ZI=1:1:CLNUM D ; LOOP THROUGH THE CATEGORIES
128 . S CLIDX=@CLBASE@(ZI)
129 . W "(",$P(@CLBASE@(CLIDX),"^",1)
130 . W ":",$P(@CLBASE@(CLIDX),"^",2),") "
131 . W CLIDX,!
132 ; D PARY^C0CXPATH(CLBASE)
133 Q
134 ;
[1544]135CPUSH(CATRTN,CBASE,CTBL,CDFN,CATTR) ; ADD PATIENTS TO CATEGORIES
[1586]136 ; AND PASS BACK THE NAME OF THE CATEGORY TO WHICH THE PATIENT
137 ; WAS ADDED IN CATRTN, WHICH IS PASSED BY REFERENCE
138 ; CBASE IS WHERE TO PUT THE CATEGORIES PASSED BY NAME
139 ; CTBL IS THE NAME OF THE TABLE USED TO CREATE THE ATTRIBUTES,
140 ; PASSED BY NAME AND USED TO CREATE CATEGORY NAMES IE "@CTBL_X"
141 ; WHERE X IS THE CATEGORY NUMBER. CTBL(0) IS THE NUMBER OF CATEGORIES
142 ; CATBL(X)=CATTR STORES THE ATTRIBUTE IN THE CATEGORY
143 ; CDFN IS THE PATIENT DFN, CATTR IS THE ATTRIBUTE STRING
144 ; THE LIST OF PATIENTS IN A CATEGORY IS STORED INDEXED BY CATEGORY
145 ; NUMBER IE CTBL_X(CDFN)=""
146 ;
147 ; N CCTBL,CENTRY,CNUM,CCOUNT,CPATLIST
148 S CCTBL=$NA(@CBASE@(CTBL,"CATS"))
149 ; W "CBASE: ",CCTBL,!
150 ;
151 I '$D(@CCTBL@(CATTR)) D ; FIRST PATIENT IN THIS CATEGORY
152 . D PUSH^C0CXPATH(CCTBL,CATTR) ; ADD THE CATEGORY TO THE ARRAY
153 . S CNUM=@CCTBL@(0) ; ARRAY ENTRY NUMBER FOR THIS CATEGORY
154 . S CENTRY=CTBL_"_"_CNUM_U_0 ; TABLE ENTRY DEFAULT
155 . S @CCTBL@(CATTR)=CENTRY ; DEFAULT NON INCREMENTED TABLE ENTRY
156 . ; NOTE THAT P1 IS THE CATEGORY NAME MADE UP OF THE TABLE NAME
157 . ; AND CATGORY ARRAY NUMBER. P2 IS THE COUNT WHICH IS INITIALLY 0
158 ;
159 S CCOUNT=$P(@CCTBL@(CATTR),U,2) ; COUNT OF PATIENTS IN THIS CATEGORY
160 S CCOUNT=CCOUNT+1 ; INCREMENT THE COUNT
161 S $P(@CCTBL@(CATTR),U,2)=CCOUNT ; PUT IT BACK
162 ;
163 S CATRTN=$P(@CCTBL@(CATTR),U,1) ; THE CATEGORY NAME WHICH IS RETURNED
164 ;
165 S CPATLIST=$NA(@CBASE@(CTBL,"IENS",CATRTN)) ; BASE OF PAT LIST FOR THIS CAT
166 ; W "IENS BASE: ",CPATLIST,!
167 S @CPATLIST@(CDFN)="" ; ADD THIS PATIENT TO THE CAT PAT LIST
168 ;
169 Q
170 ;
[1544]171REUSE ; GET SAVED VALUES FROM ^TMP("C0CSAV") AND PUT THEM IN A DATABASE
172 ;
173 D ASETUP
174 D AINIT
175 N SNOI,SNOJ,SNOK,SNOSNO,SNOSEC,SNOIEN,SNOOLD,SNOSRCH
176 S SAVBASE=$NA(^TMP("C0CSAV","VARS"))
177 S SNOI=""
[1586]178 F D Q:$O(@SAVBASE@(SNOI))="" ;THE WHOLE LIST
[1544]179 . S SNOI=$O(@SAVBASE@(SNOI))
180 . S SNOJ=@SAVBASE@(SNOI)
181 . S SNOK=$P($P(SNOJ,"^",1)," ALLERGY",1)
182 . S SNOSRCH=$P(SNOJ,"^",1) ;SEARCH TERM USED TO OBTAIN SNOMED CODE
183 . S SNOIEN=$P(SNOJ,"^",3) ; IEN OF ELEMENT IN LEXICON
184 . S SNOSNO=$P(SNOJ,"^",4) ; SNOMED CODE
185 . S SNOSEC=$P(SNOJ,"^",5) ; SECTION OF SNOMED FOR THIS CODE
186 . S SNOOLD=$P(SNOJ,"^",7) ; OLD NUMBER FOR THIS CODE
187 . W "SEARCH:",SNOSRCH," IEN:",SNOIEN," CODE:",SNOSNO," SEC:",SNOSEC," OLD:",SNOOLD,!
188 . W SNOK,!
189 . W SNOJ,!
190 Q
191 ;
Note: See TracBrowser for help on using the repository browser.