source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLOPROC.m@ 623

Last change on this file since 623 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 4.9 KB
Line 
1HLOPROC ;ALB/CJM- Generic HL7 Process - 10/4/94 1pm ;03/26/2007
2 ;;1.6;HEALTH LEVEL SEVEN;**126,134**;Oct 13, 1995;Build 30
3 ;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5PROCESS ;queued entry point
6 ;
7 ;insure just one process manager
8 I PROCNAME="PROCESS MANAGER" N RUNNING L +^HLTMP(PROCNAME):1 S RUNNING='$T D Q:RUNNING
9 .I 'RUNNING D
10 ..D SETNM^%ZOSV($E("HLOmgr:"_$J,1,17))
11 .E D
12 ..L +HL7("COUNTING PROCESSES"):20
13 ..K:$D(ZTSK) ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
14 ..S ^HLC("HL7 PROCESS COUNTS","RUNNING","PROCESS MANAGER")=1
15 ..S ^HLC("HL7 PROCESS COUNTS","QUEUED","PROCESS MANAGER")=0
16 ..L -HL7("COUNTING PROCESSES")
17 ..S ZTREQ="@"
18 ;
19 ;invoke the framework process
20 D HL7PROC(PROCNAME)
21 ;
22 I PROCNAME="PROCESS MANAGER" L -^HLTMP(PROCNAME)
23 S ZTREQ="@"
24 Q
25 ;
26HL7PROC(PROCNAME) ;
27 ;This is the generic HL7 process used by all processes started under the HL7 Process Manager
28 ;Input:
29 ; PROCNAME - the name of a process found in the HL7 Process Registry
30 ; OUTPUT - none
31 ;
32 N PROCESS,HL7STOP,WORK
33 ;
34 S ^HL7TMP("HL7 PROCESS NAME",$J)=PROCNAME
35 ;
36 L +HL7("COUNTING PROCESSES"):20
37 I $D(ZTQUEUED) D
38 .K:$D(ZTSK) ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
39 .I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)))
40 L +^HLTMP("HL7 RUNNING PROCESSES",$J):0
41 I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)))
42 S ^HLTMP("HL7 RUNNING PROCESSES",$J)=$H_"^"_$G(ZTSK)_"^"_PROCNAME
43 L -HL7("COUNTING PROCESSES")
44 ;
45 ;
46 I $$GETPROC(PROCNAME,.PROCESS),'$$CHK4STOP(.PROCESS) D
47 .S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
48 .;
49 .;should this task be made persistent?
50 .I PROCESS("PERSISTENT"),$G(ZTQUEUED),$$PSET^%ZTLOAD(ZTQUEUED)
51 .;
52 .S HL7STOP=0
53 .F D Q:HL7STOP
54 ..N $ETRAP,$ESTACK S $ETRAP="G ERROR^HLOPROC"
55 ..N HL7TRIES,GOTWORK
56 ..F HL7TRIES=1:1 D Q:GOTWORK Q:$G(HL7STOP)
57 ...S GOTWORK=$$GETWORK(.PROCESS,.WORK)
58 ...Q:GOTWORK
59 ...;since there is no work, don't want another process starting
60 ...S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
61 ...H PROCESS("HANG")
62 ...S HL7STOP=$$CHK4STOP(.PROCESS,HL7TRIES)
63 ..Q:$G(HL7STOP)
64 ..I GOTWORK D DOWORK(.PROCESS,.WORK) S HL7TRIES=0
65 ..S:'$G(HL7STOP) HL7STOP=$$CHK4STOP(.PROCESS,.HL7TRIES)
66 ;
67 S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
68 ;
69END ;
70 S HL7STOP=1
71 K ^HL7TMP("HL7 PROCESS NAME",$J)
72 L +HL7("COUNTING PROCESSES"):20
73 K ^HLTMP("HL7 RUNNING PROCESSES",$J)
74 I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),1)
75 L -^HLTMP("HL7 RUNNING PROCESSES",$J)
76 L -HL7("COUNTING PROCESSES")
77 K ^TMP("HL7 ERRORS",$J)
78 ;
79 Q
80 ;
81ERROR ;error trap
82 ;
83 S $ETRAP="Q:$QUIT """" Q"
84 ;
85 ;while debugging always quit on error
86 I $G(^HLTMP("LOG ALL ERRORS"))!($ECODE["TOOMANYFILES")!($ECODE["EDITED") D Q:$QUIT "" Q
87 .D ^%ZTER
88 .S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
89 .D END
90 ;
91 ;a lot of errors of the same type may indicate an endless loop, so quit
92 ;to be on the safe side. Decrement the process count.
93 N HOUR
94 S HOUR=$E($$NOW^XLFDT,1,10)
95 I $G(^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2)))>30 D Q:$QUIT "" Q
96 .;D ^%ZTER
97 .S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
98 .D END
99 ;
100 ;can continue processing after logging the error
101 S ^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2))=$G(^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2)))+1
102 D ^%ZTER
103 D UNWIND^%ZTER
104 Q
105 ;
106GETPROC(PROCNAME,PROCESS) ;
107 ;using PROCNAME to find the entry in the HL7 Process Registry, returns the entry as a subscripted array in .PROCESS
108 ;
109 ;Output: Function returns 0 on failure, 1 on success
110 ;
111 N IEN,NODE
112 S IEN=$O(^HLD(779.3,"B",PROCNAME,0))
113 Q:'IEN 0
114 S PROCESS("NAME")=PROCNAME
115 S PROCESS("IEN")=IEN
116 S NODE=$G(^HLD(779.3,IEN,0))
117 S PROCESS("MINIMUM")=+$P(NODE,"^",3)
118 S PROCESS("MAXIMUM")=+$P(NODE,"^",4)
119 S PROCESS("HANG")=+$P(NODE,"^",7)
120 I 'PROCESS("HANG") S PROCESS("HANG")=1
121 S PROCESS("GET WORK")=$P(NODE,"^",8,9)
122 S PROCESS("DO WORK")=$P(NODE,"^",10,11)
123 S PROCESS("MAX TRIES")=$P(NODE,"^",12)
124 I 'PROCESS("MAX TRIES") S PROCESS("MAX TRIES")=999
125 S PROCESS("PERSISTENT")=+$P(NODE,"^",13)
126 S PROCESS("LINK")=$P(NODE,"^",14)
127 Q 1
128 ;
129GETWORK(PROCESS,WORK) ;
130 N RETURN,XECUTE
131 I PROCESS("LINK")]"" S WORK("LINK")=PROCESS("LINK")
132 S XECUTE="S RETURN=$$"_PROCESS("GET WORK")_"(.WORK)"
133 D
134 .N PROCESS
135 .X XECUTE
136 Q RETURN
137 ;
138DOWORK(PROCESS,WORK) ;
139 N XECUTE
140 M PARMS=WORK
141 S XECUTE="D "_PROCESS("DO WORK")_"(.WORK)"
142 D
143 .N PROCESS,HL7TRIES,PARMS,PROCNAME
144 .X XECUTE
145 M WORK=PARMS
146 Q
147 ;
148CHK4STOP(PROCESS,HL7TRIES) ;
149 ;Determines if the process should stop, returns 1 if yes, 0 if no
150 ;
151 Q:$$CHKSTOP 1
152 Q:'$P($G(^HLD(779.3,PROCESS("IEN"),0)),"^",2) 1
153 I $G(HL7TRIES)>(PROCESS("MAX TRIES")-1),PROCESS("MINIMUM")<$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME"))) Q 1
154 Q:$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME")))>PROCESS("MAXIMUM") 1
155 Q 0
156 ;
157CHKSTOP() ;has HL7 been requested to stop?
158 Q '$P($G(^HLD(779.1,1,0)),"^",9)
Note: See TracBrowser for help on using the repository browser.