source: fmts/trunk/p/C0XMULTI.m@ 1805

Last change on this file since 1805 was 1601, checked in by George Lilly, 12 years ago

update to multi tasking

File size: 8.7 KB
Line 
1C0XMULTI ;GPL - Multi tasking with the triplestore ;3/22/12 17:05
2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
3 ;Copyright 2011 George Lilly. 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 Q
21 ;
22INIT ; initialize control queues
23 ;
24 K ^TMP("RXMISSINGTOTAL")
25 K ^TMP("RXFOUNDTOTAL")
26 K ^TMP("C0X","LOADPV")
27 ;
28 N C0XPATDM
29 D subjects^C0XGET1(.C0XPATDM,"sage:patientLegacyAccountNumber") ; all patient subjects
30 K ^TMP("C0X","LOADPV")
31 M ^TMP("C0X","LOADPV","HOLD")=C0XPATDM
32 S ^TMP("C0X","LOADPV","COUNT","HOLD")=$$COUNT^JJOHMMUT(.C0XPATDM)
33 S ^TMP("C0X","LOADPV","THROTTLE")=1000
34 Q
35 ;
36MINUS(PLACE)
37 ;
38 ;L +$NA(@PLACE),1
39 I $G(@PLACE)'<1 D ;
40 . S @PLACE=@PLACE-1
41 ;L -$NA(@PLACE)
42 Q
43 ;
44PLUS(PLACE)
45 ;
46 ;L +$NA(@PLACE),1
47 S @PLACE=$G(@PLACE)+1
48 ;L -$NA(@PLACE)
49 Q
50 ;
51H2Q(NUM) ; PUT A BATCH OF ITEMS FROM HOLD TO QUEUE
52 N ZI,ZJ
53 F ZI=1:1:NUM D ;
54 . S ZJ=$O(^TMP("C0X","LOADPV","HOLD",""))
55 . I ZJ="" Q ; NO MORE
56 . K ^TMP("C0X","LOADPV","HOLD",ZJ) ; REMOVE FROM HOLD
57 . S ^TMP("C0X","LOADPV","QUEUE",ZJ)="" ; ADD TO QUEUE
58 . N GN
59 . S GN=$NA(^TMP("C0X","LOADPV","COUNT","HOLD"))
60 . D MINUS(GN)
61 . S GN=$NA(^TMP("C0X","LOADPV","COUNT","QUEUE"))
62 . D PLUS(GN)
63 Q
64 ;
65Q2R() ; return a patient to run
66 ;
67 N ZZ,ZP
68 S ZZ=$O(^TMP("C0X","LOADPV","QUEUE",""))
69 I ZZ="" Q "" ; no more
70 K ^TMP("C0X","LOADPV","QUEUE",ZZ) ; remove from queue queue
71 S ZP=$NA(^TMP("C0X","LOADPV","COUNT","QUEUE"))
72 D MINUS(ZP) ; DECREMENT QUEUE COUNT
73 S ^TMP("C0X","LOADPV","RUN",ZZ)="" ;add to run queue
74 S ZP=$NA(^TMP("C0X","LOADPV","COUNT","RUN"))
75 D PLUS(ZP) ; increment Run count
76 Q ZZ
77 ;
78R2D(ZWHAT) ; MOVE ZWHAT FROM RUN QUEUE TO DONE QUEUE
79 K ^TMP("C0X","LOADPV","RUN",ZWHAT)
80 S ^TMP("C0X","LOADPV","DONE",ZWHAT)=""
81 S GN=$NA(^TMP("C0X","LOADPV","COUNT","DONE"))
82 D PLUS(GN)
83 S GN=$NA(^TMP("C0X","LOADPV","COUNT","RUN"))
84 D MINUS(GN)
85 Q
86 ;
87ZTLOAD ; take items out of hold and start up taskman jobs to process
88 ; use throttle to know how many
89 N ZMAX
90 S ZMAX=$G(^TMP("C0X","LOADPV","THROTTLE"))
91 I +ZMAX=0 D ;
92 . S ^TMP("C0X","LOADPV","THROTTLE")=100
93 . S ZMAX=100
94 N COUNTS
95 M COUNTS=^TMP("C0X","LOADPV","COUNT")
96 I COUNTS("HOLD")=0 Q ;
97 N ZADDS
98 S ZADDS=ZMAX-$G(COUNTS("QUEUE"))-$G(COUNTS("RUN"))
99 W !,"ZADDS=",ZADDS
100 I ZADDS>0 D ;
101 . D H2Q(ZADDS) ; move some new items from hold to queue
102 . D LAUNCH(ZADDS)
103 Q
104 ;
105LAUNCH(ZADDS) ; launch ZADDS number of workers in taskman
106 N ZJ
107 F ZJ=1:1:ZADDS D ;
108 . N C0XST
109 . S C0XST("ZTDTH")=$H ; force it to start now
110 . W !,$$NODEV^XUTMDEVQ("EN^JJOHMMP5","LOADPV",,.C0XST,1) ;
111 . ; add a bunch of new taskman tasks
112 Q
113 ;
114SHOW ;
115 ZWR ^TMP("C0X","LOADPV","THROTTLE")
116 ZWR ^TMP("C0X","LOADPV","COUNT",*)
117 Q
118 ;
119EN ; load patient viewer from batch job.. one at a time
120 ;
121 S C0XPVFN=172.901 ; file number for patient viewer file
122 S C0XALFN=172.9011 ; allergy subfile number
123 S C0XPRFN=172.9012 ; problem subfile number
124 S C0XMDFN=172.9013 ; medication subfile number
125 S C0XIMFN=172.9014 ; immunization subfile number
126 S C0XNTFN=172.9016 ; notes subfile number
127 S C0XLBFN=172.9018 ; lab subfile number
128 S C0XVTFN=172.9019 ; vitals subfile number
129 S C0XIDFN=172.9015 ; identifier subfile number
130 S C0XDEFN=172.9017 ; demographics subfile number
131 N C0XPATDM ; array of patient demographics pointers
132 S C0XPATDM=$NA(^TMP("C0X","LOADPV"))
133 N C0XPAT ; current patient
134 S C0XPAT=$$Q2R ; POP A PATIENT OFF THE QUEUE TO RUN
135 I C0XPAT="" Q ; no more to process
136 ;
137 ; create the processing control table
138 S C0XTYPE("personal")="D PTALGY^JJOHMMP4" ; allergy type
139 S C0XTYPE("patprob")="D PTPROB^JJOHMMP4" ; problem type
140 S C0XTYPE("patrx")="D PTMED^JJOHMMP4" ; medications type
141 S C0XTYPE("catalog")="D PTNOTES^JJOHMMP4" ; notes type
142 S C0XTYPE("vitalsigns")="D PTVITAL^JJOHMMP4" ; vitals type
143 S C0XTYPE("vacination")="D PTIMMUN^JJOHMMP4" ; immunizations type
144 ;
145 ;I '$D(C0XPATDM) B ;
146 ;N ZI S ZI=""
147 ;F S ZI=$O(C0XPATDM(ZI)) Q:ZI="" D ;
148 S ZI=C0XPAT
149 D ; process one patient
150 . N C0XDEMOS
151 . D triples^C0XGET1(.C0XDEMOS,ZI,,,,"raw") ; get patient demographics
152 . N C0XNAME
153 . S C0XNAME=$$PTNAME^JJOHMMP4(.C0XDEMOS,ZI)
154 . S C0XPAT=$G(C0XDEMOS(ZI,"sage:patientLegacyAccountNumber"))
155 . I C0XPAT="" D Q ;
156 . . W !,"Error finding Patient Pointer",ZI
157 . N C0XINDX ; index of patient clinical subrecords
158 . D subjects^C0XGET1(.C0XINDX,,C0XPAT)
159 . N DOYN S DOYN=0 ; default is don't process this patient
160 . N C0XPROC ; clinical records to process
161 . N ZJ S ZJ=""
162 . F S ZJ=$O(C0XINDX(ZJ)) Q:ZJ="" D ;
163 . . N ZTYPE
164 . . S ZTYPE=$$object^C0XGET1(ZJ,"rdf:type")
165 . . I '$D(C0XTYPE(ZTYPE)) D Q ; type not supported
166 . . . W !,"SKIPPING: ",ZTYPE
167 . . S C0XPROC(ZJ,ZTYPE)=""
168 . . W !,"FOUND: ",ZTYPE," ",ZJ,!
169 . . S DOYN=1
170 . Q:DOYN=0 ; didn't find any clinical data to add
171 . K C0XFDA
172 . S C0XFDA(C0XPVFN,"?+1,",.01)=C0XNAME
173 . D UPDIE^JJOHMMP4 ; create the patient record in the Patient Viewer if not there
174 . N C0XIEN
175 . S C0XIEN=$O(^C0XVPV(172.901,"B",C0XNAME,""))
176 . I C0XIEN="" D Q ;
177 . . W !,"PROBLEM WITH THE B CROSS REFERENCE.. TOO SMALL"
178 . . B
179 . D PATIENT^JJOHMMP4 ; process demographics
180 . ; COMMENT OUT THE NEXT TWO LINES TO DO A FULL LOAD
181 . ; THIS WILL ONLY LOAD THE DEMOGRAPHICS
182 . D R2D(ZI) ;
183 . Q
184 . ; END DEMO ONLY FIX
185 . S ZJ=""
186 . F S ZJ=$O(C0XPROC(ZJ)) Q:ZJ="" D ;
187 . . N C0XARY
188 . . d triples^C0XGET1(.C0XARY,ZJ,,,,"raw")
189 . . I '$D(C0XARY) B ;
190 . . S ZSUB=ZJ
191 . . X C0XTYPE($O(C0XPROC(ZJ,"")))
192 D R2D(ZI) ; mark this patient as done
193 Q
194 ;
195INDEX(ZIEN,ZN,ZG,ZS,ZP,ZO) ; HARD SET THE INDEX FOR ONE ENTRY
196 S C0X(101,"B",ZN,ZIEN)="" ; the B index
197 S C0X(101,"G",ZG,ZIEN)="" ; the G for Graph index
198 S C0X(101,"SPO",ZS,ZP,ZO,ZIEN)=""
199 S C0X(101,"SOP",ZS,ZO,ZP,ZIEN)=""
200 S C0X(101,"OPS",ZO,ZP,ZS,ZIEN)=""
201 S C0X(101,"OSP",ZO,ZS,ZP,ZIEN)=""
202 S C0X(101,"PSO",ZP,ZS,ZO,ZIEN)=""
203 S C0X(101,"POS",ZP,ZO,ZS,ZIEN)=""
204 ;S ^C0X(101,"GOPS",ZG,ZO,ZP,ZS,ZIEN)=""
205 ;S ^C0X(101,"GOSP",ZG,ZO,ZS,ZP,ZIEN)=""
206 ;S ^C0X(101,"GPSO",ZG,ZP,ZS,ZO,ZIEN)=""
207 ;S ^C0X(101,"GPOS",ZG,ZP,ZO,ZS,ZIEN)=""
208 ;S ^C0X(101,"GSPO",ZG,ZS,ZP,ZO,ZIEN)=""
209 ;S ^C0X(101,"GSOP",ZG,ZS,ZO,ZP,ZIEN)=""
210 Q
211 ;
212REINDX ; reindex pa
213 Q
214 ;
215NOTES ; user the browser instead of listman
216 N PAT
217 S DIC=172.901,DIC(0)="AEMQ" D ^DIC
218 I Y<1 Q ;
219 S PAT=$P(Y,U,1)
220 D LIST^DIC(172.9016,","_PAT_",","1;2;3;") ; get title, date and file names
221 N ZI S ZI=0
222 N GN,ZARY,ZN
223 S ZN=0
224 S DIR(0)="SO^"
225 S GN=$NA(^TMP("DILIST",$J,"ID"))
226 F S ZI=$O(@GN@(ZI)) Q:ZI="" D ;
227 . S ZN=ZN+1
228 . S ZARY(ZN)=@GN@(ZI,3)
229 . S DIR(0)=DIR(0)_ZI_":"_@GN@(ZI,3)_";"
230 . S DIR("L",ZN)=ZN_" "_@GN@(ZI,1)_" SAGE "_@GN@(ZI,2)_" "_@GN@(ZI,3)
231 S DIR("L")=""
232 I ZN=0 Q ;
233 D ^DIR
234 I +Y<1 Q ;
235 N ZNOTE,ZTMP,ZSIZE
236 S ZNOTE=$NA(^TMP("C0XPV",$J))
237 K @ZNOTE
238 D IMPORT^JJOHMMUT(ZARY(Y),"ZTMP")
239 N ZN S ZN=0
240 S ZI=""
241 F S ZI=$O(ZTMP(ZI)) Q:ZI="" D ;
242 . S ZN=ZN+1
243 . S @ZNOTE@(ZN,0)=ZTMP(ZI)
244 . S ZSIZE=ZN
245 ;S ZSIZE=$O(@ZNOTE@(""),-1)
246 S $P(@ZNOTE@(0),U,4)=ZSIZE
247 D WP^VALM(ZNOTE,ZARY(Y))
248 Q
249 ;
250NOTES2 ;
251 N PAT
252 S DIC=172.901,DIC(0)="AEMQ" D ^DIC
253 I Y<1 Q ;
254 S PAT=$P(Y,U,1)
255 D LIST^DIC(172.9016,","_PAT_",","1;2;3;") ; get title, date and file names
256 N ZI S ZI=""
257 N GN,ZARY,ZN
258 S ZN=0
259 S DIR(0)="SO^"
260 S GN=$NA(^TMP("DILIST",$J,"ID"))
261 F S ZI=$O(@GN@(ZI)) Q:ZI="" D ;
262 . S ZN=ZN+1
263 . S ZARY(ZN)=@GN@(ZI,3)
264 . S DIR(0)=DIR(0)_ZI_":"_@GN@(ZI,3)_";"
265 . S DIR("L",ZN)=ZN_" "_@GN@(ZI,1)_" SAGE "_@GN@(ZI,2)_" "_@GN@(ZI,3)
266 I ZN=0 D Q ;
267 . W !,"NO NOTES FOR THIS PATIENT"
268 S DIR("L")=""
269 D ^DIR
270 I Y<1 Q ;
271 N ZNOTE,ZTMP,ZSIZE
272 S ZNOTE=$NA(^TMP("C0XPV",$J))
273 K @ZNOTE
274 D IMPORT^JJOHMMUT(ZARY(Y),"ZTMP")
275 S ZSIZE=$O(ZTMP(""),-1)
276 ;S $P(@ZNOTE@(0),U,4)=ZSIZE
277 N ZJ S ZJ=""
278 N ZN S ZN=0
279 F S ZJ=$O(ZTMP(ZJ)) Q:ZJ="" D ;
280 . S ZN=ZN+1
281 . S @ZNOTE@(ZN)=$$CLEAN(ZTMP(ZJ))
282 D BROWSE^DDBR(ZNOTE,"N",ZARY(Y))
283 Q
284 ;
285BROWSE ;
286 N I,ZNOTE
287 S ZNOTE=$NA(^TMP("C0XPV",$J))
288 F I=1:1:300 S @ZNOTE@(I)="THIS IS LINE "_I
289 D BROWSE^DDBR(ZNOTE,"N","GPLTEST")
290 Q
291 ;
292CLEAN(ZX) ; extrinsic cleans one line of text
293 N X,Y
294 S X=ZX
295 I $E(X,1,5)="bodyg" D ;
296 . S $E(X,1,6)="" ; get rid of bodygx at the beginning of the line
297 . N XX S XX=$E(X,1,1)
298 . I ($A(XX)>47)&($A(XX)<58) S $E(X,1,1)=""
299 I $E(X,1,4)="body" S $E(X,1,4)=""
300 I $E(X,1,5)="ebody" S $E(X,1,5)=""
301 N ZI F ZI=1:1:$L(X) D ;
302 . I $A($E(X,ZI,ZI))<32 S $E(X,ZI,ZI)="*"
303 . I $A($E(X,ZI,ZI))>126 S $E(X,ZI,ZI)="*"
304 Q X
305 ;
Note: See TracBrowser for help on using the repository browser.