HLOPROC ;ALB/CJM- Generic HL7 Process - 10/4/94 1pm
;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
;
PROCESS ;queued entry point
;
;insure just one process manager
I PROCNAME="PROCESS MANAGER" N RUNNING L +^HLTMP(PROCNAME):1 S RUNNING='$T D Q:RUNNING
.I 'RUNNING D
..D SETNM^%ZOSV($E("HLOmgr:"_$J,1,17))
.E D
..L +HL7("COUNTING PROCESSES"):20
..K:$D(ZTSK) ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
..S ^HLC("HL7 PROCESS COUNTS","RUNNING","PROCESS MANAGER")=1
..S ^HLC("HL7 PROCESS COUNTS","QUEUED","PROCESS MANAGER")=0
..L -HL7("COUNTING PROCESSES")
..S ZTREQ="@"
;
;invoke the framework process
D HL7PROC(PROCNAME)
;
I PROCNAME="PROCESS MANAGER" L -^HLTMP(PROCNAME)
S ZTREQ="@"
Q
;
HL7PROC(PROCNAME) ;
;This is the generic HL7 process used by all processes started under the HL7 Process Manager
;Input:
; PROCNAME - the name of a process found in the HL7 Process Registry
; OUTPUT - none
;
N PROCESS,HL7STOP,WORK
;
S ^HL7TMP("HL7 PROCESS NAME",$J)=PROCNAME
;
L +HL7("COUNTING PROCESSES"):20
I $D(ZTQUEUED) D
.K:$D(ZTSK) ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
.I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)))
L +^HLTMP("HL7 RUNNING PROCESSES",$J):0
I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)))
S ^HLTMP("HL7 RUNNING PROCESSES",$J)=$H_"^"_$G(ZTSK)_"^"_PROCNAME
L -HL7("COUNTING PROCESSES")
;
;
I $$GETPROC(PROCNAME,.PROCESS),'$$CHK4STOP(.PROCESS) D
.S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
.;
.;should this task be made persistent?
.I PROCESS("PERSISTENT"),$G(ZTQUEUED),$$PSET^%ZTLOAD(ZTQUEUED)
.;
.S HL7STOP=0
.F D Q:HL7STOP
..N $ETRAP,$ESTACK S $ETRAP="G ERROR^HLOPROC"
..N HL7TRIES,GOTWORK
..F HL7TRIES=1:1 D Q:GOTWORK Q:HL7STOP
...S GOTWORK=$$GETWORK(.PROCESS,.WORK)
...Q:GOTWORK
...;since there is no work, don't want another process starting
...S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
...H PROCESS("HANG")
...S HL7STOP=$$CHK4STOP(.PROCESS,HL7TRIES)
..Q:HL7STOP
..I GOTWORK D DOWORK(.PROCESS,.WORK) S HL7TRIES=0
..S:'$G(HL7STOP) HL7STOP=$$CHK4STOP(.PROCESS,.HL7TRIES)
;
S $P(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
;
END ;
S HL7STOP=1
K ^HL7TMP("HL7 PROCESS NAME",$J)
L +HL7("COUNTING PROCESSES"):20
K ^HLTMP("HL7 RUNNING PROCESSES",$J)
I $$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),-1)<0,$$INC^HLOSITE($NA(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),1)
L -^HLTMP("HL7 RUNNING PROCESSES",$J)
L -HL7("COUNTING PROCESSES")
K ^TMP("HL7 ERRORS",$J)
;
Q
;
ERROR ;error trap
;
S $ETRAP="D UNWIND^%ZTER"
;
;while debugging always quit on error
I $G(^HLTMP("LOG ALL ERRORS")) D QUIT
.D ^%ZTER
.S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
.D END
;
;a lot of errors of the same type may indicate an endless loop, so quit
;to be on the safe side. Decrement the process count.
S $ECODE=$P($ECODE,",",1,2)
S ^TMP("HL7 ERRORS",$J,$ECODE)=$G(^TMP("HL7 ERRORS",$J,$ECODE))+1
I $G(^TMP("HL7 ERRORS",$J,$ECODE))>100 D QUIT
.D ^%ZTER
.S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
.D END
;
D ^%ZTER
D UNWIND^%ZTER
Q
;
GETPROC(PROCNAME,PROCESS) ;
;using PROCNAME to find the entry in the HL7 Process Registry, returns the entry as a subscripted array in .PROCESS
;
;Output: Function returns 0 on failure, 1 on success
;
N IEN,NODE
S IEN=$O(^HLD(779.3,"B",PROCNAME,0))
Q:'IEN 0
S PROCESS("NAME")=PROCNAME
S PROCESS("IEN")=IEN
S NODE=$G(^HLD(779.3,IEN,0))
S PROCESS("MINIMUM")=+$P(NODE,"^",3)
S PROCESS("MAXIMUM")=+$P(NODE,"^",4)
S PROCESS("HANG")=+$P(NODE,"^",7)
I 'PROCESS("HANG") S PROCESS("HANG")=1
S PROCESS("GET WORK")=$P(NODE,"^",8,9)
S PROCESS("DO WORK")=$P(NODE,"^",10,11)
S PROCESS("MAX TRIES")=$P(NODE,"^",12)
I 'PROCESS("MAX TRIES") S PROCESS("MAX TRIES")=999
S PROCESS("PERSISTENT")=+$P(NODE,"^",13)
S PROCESS("LINK")=$P(NODE,"^",14)
Q 1
;
GETWORK(PROCESS,WORK) ;
N RETURN,XECUTE
I PROCESS("LINK")]"" S WORK("LINK")=PROCESS("LINK")
S XECUTE="S RETURN=$$"_PROCESS("GET WORK")_"(.WORK)"
D
.N PROCESS
.X XECUTE
Q RETURN
;
DOWORK(PROCESS,WORK) ;
N XECUTE
M PARMS=WORK
S XECUTE="D "_PROCESS("DO WORK")_"(.WORK)"
D
.N PROCESS,HL7TRIES,PARMS,PROCNAME
.X XECUTE
M WORK=PARMS
Q
;
CHK4STOP(PROCESS,HL7TRIES) ;
;Determines if the process should stop, returns 1 if yes, 0 if no
;
Q:$$CHKSTOP 1
Q:'$P($G(^HLD(779.3,PROCESS("IEN"),0)),"^",2) 1
I $G(HL7TRIES)>(PROCESS("MAX TRIES")-1),PROCESS("MINIMUM")<$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME"))) Q 1
Q:$G(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME")))>PROCESS("MAXIMUM") 1
Q 0
;
CHKSTOP() ;has HL7 been requested to stop?
Q '$P($G(^HLD(779.1,1,0)),"^",9)
HLOPROC ;ALB/CJM- Generic HL7 Process - 10/4/94 1pm
+1 ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
+2 ;
PROCESS ;queued entry point
+1 ;
+2 ;insure just one process manager
+3 IF PROCNAME="PROCESS MANAGER"
NEW RUNNING
LOCK +^HLTMP(PROCNAME):1
SET RUNNING='$TEST
Begin DoDot:1
+4 IF 'RUNNING
Begin DoDot:2
+5 DO SETNM^%ZOSV($EXTRACT("HLOmgr:"_$JOB,1,17))
End DoDot:2
+6 IF '$TEST
Begin DoDot:2
+7 LOCK +HL7("COUNTING PROCESSES"):20
+8 IF $DATA(ZTSK)
KILL ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
+9 SET ^HLC("HL7 PROCESS COUNTS","RUNNING","PROCESS MANAGER")=1
+10 SET ^HLC("HL7 PROCESS COUNTS","QUEUED","PROCESS MANAGER")=0
+11 LOCK -HL7("COUNTING PROCESSES")
+12 SET ZTREQ="@"
End DoDot:2
End DoDot:1
IF RUNNING
QUIT
+13 ;
+14 ;invoke the framework process
+15 DO HL7PROC(PROCNAME)
+16 ;
+17 IF PROCNAME="PROCESS MANAGER"
LOCK -^HLTMP(PROCNAME)
+18 SET ZTREQ="@"
+19 QUIT
+20 ;
HL7PROC(PROCNAME) ;
+1 ;This is the generic HL7 process used by all processes started under the HL7 Process Manager
+2 ;Input:
+3 ; PROCNAME - the name of a process found in the HL7 Process Registry
+4 ; OUTPUT - none
+5 ;
+6 NEW PROCESS,HL7STOP,WORK
+7 ;
+8 SET ^HL7TMP("HL7 PROCESS NAME",$JOB)=PROCNAME
+9 ;
+10 LOCK +HL7("COUNTING PROCESSES"):20
+11 IF $DATA(ZTQUEUED)
Begin DoDot:1
+12 IF $DATA(ZTSK)
KILL ^HLTMP("HL7 QUEUED PROCESSES",ZTSK)
+13 IF $$INC^HLOSITE($NAME(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)),-1)<0
IF $$INC^HLOSITE($NAME(^HLC("HL7 PROCESS COUNTS","QUEUED",PROCNAME)))
End DoDot:1
+14 LOCK +^HLTMP("HL7 RUNNING PROCESSES",$JOB):0
+15 IF $$INC^HLOSITE($NAME(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)))
+16 SET ^HLTMP("HL7 RUNNING PROCESSES",$JOB)=$HOROLOG_"^"_$GET(ZTSK)_"^"_PROCNAME
+17 LOCK -HL7("COUNTING PROCESSES")
+18 ;
+19 ;
+20 IF $$GETPROC(PROCNAME,.PROCESS)
IF '$$CHK4STOP(.PROCESS)
Begin DoDot:1
+21 SET $PIECE(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
+22 ;
+23 ;should this task be made persistent?
+24 IF PROCESS("PERSISTENT")
IF $GET(ZTQUEUED)
IF $$PSET^%ZTLOAD(ZTQUEUED)
+25 ;
+26 SET HL7STOP=0
+27 FOR
Begin DoDot:2
+28 NEW $ETRAP,$ESTACK
SET $ETRAP="G ERROR^HLOPROC"
+29 NEW HL7TRIES,GOTWORK
+30 FOR HL7TRIES=1:1
Begin DoDot:3
+31 SET GOTWORK=$$GETWORK(.PROCESS,.WORK)
+32 IF GOTWORK
QUIT
+33 ;since there is no work, don't want another process starting
+34 SET $PIECE(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
+35 HANG PROCESS("HANG")
+36 SET HL7STOP=$$CHK4STOP(.PROCESS,HL7TRIES)
End DoDot:3
IF GOTWORK
QUIT
IF HL7STOP
QUIT
+37 IF HL7STOP
QUIT
+38 IF GOTWORK
DO DOWORK(.PROCESS,.WORK)
SET HL7TRIES=0
+39 IF '$GET(HL7STOP)
SET HL7STOP=$$CHK4STOP(.PROCESS,.HL7TRIES)
End DoDot:2
IF HL7STOP
QUIT
End DoDot:1
+40 ;
+41 SET $PIECE(^HLD(779.3,PROCESS("IEN"),0),"^",6)=$$NOW^XLFDT
+42 ;
END ;
+1 SET HL7STOP=1
+2 KILL ^HL7TMP("HL7 PROCESS NAME",$JOB)
+3 LOCK +HL7("COUNTING PROCESSES"):20
+4 KILL ^HLTMP("HL7 RUNNING PROCESSES",$JOB)
+5 IF $$INC^HLOSITE($NAME(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),-1)<0
IF $$INC^HLOSITE($NAME(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCNAME)),1)
+6 LOCK -^HLTMP("HL7 RUNNING PROCESSES",$JOB)
+7 LOCK -HL7("COUNTING PROCESSES")
+8 KILL ^TMP("HL7 ERRORS",$JOB)
+9 ;
+10 QUIT
+11 ;
ERROR ;error trap
+1 ;
+2 SET $ETRAP="D UNWIND^%ZTER"
+3 ;
+4 ;while debugging always quit on error
+5 IF $GET(^HLTMP("LOG ALL ERRORS"))
Begin DoDot:1
+6 DO ^%ZTER
+7 IF '$DATA(PROCNAME)
SET PROCNAME=$GET(^HL7TMP("HL7 PROCESS NAME",$JOB))
+8 DO END
End DoDot:1
QUIT
+9 ;
+10 ;a lot of errors of the same type may indicate an endless loop, so quit
+11 ;to be on the safe side. Decrement the process count.
+12 SET $ECODE=$PIECE($ECODE,",",1,2)
+13 SET ^TMP("HL7 ERRORS",$JOB,$ECODE)=$GET(^TMP("HL7 ERRORS",$JOB,$ECODE))+1
+14 IF $GET(^TMP("HL7 ERRORS",$JOB,$ECODE))>100
Begin DoDot:1
+15 DO ^%ZTER
+16 IF '$DATA(PROCNAME)
SET PROCNAME=$GET(^HL7TMP("HL7 PROCESS NAME",$JOB))
+17 DO END
End DoDot:1
QUIT
+18 ;
+19 DO ^%ZTER
+20 DO UNWIND^%ZTER
+21 QUIT
+22 ;
GETPROC(PROCNAME,PROCESS) ;
+1 ;using PROCNAME to find the entry in the HL7 Process Registry, returns the entry as a subscripted array in .PROCESS
+2 ;
+3 ;Output: Function returns 0 on failure, 1 on success
+4 ;
+5 NEW IEN,NODE
+6 SET IEN=$ORDER(^HLD(779.3,"B",PROCNAME,0))
+7 IF 'IEN
QUIT 0
+8 SET PROCESS("NAME")=PROCNAME
+9 SET PROCESS("IEN")=IEN
+10 SET NODE=$GET(^HLD(779.3,IEN,0))
+11 SET PROCESS("MINIMUM")=+$PIECE(NODE,"^",3)
+12 SET PROCESS("MAXIMUM")=+$PIECE(NODE,"^",4)
+13 SET PROCESS("HANG")=+$PIECE(NODE,"^",7)
+14 IF 'PROCESS("HANG")
SET PROCESS("HANG")=1
+15 SET PROCESS("GET WORK")=$PIECE(NODE,"^",8,9)
+16 SET PROCESS("DO WORK")=$PIECE(NODE,"^",10,11)
+17 SET PROCESS("MAX TRIES")=$PIECE(NODE,"^",12)
+18 IF 'PROCESS("MAX TRIES")
SET PROCESS("MAX TRIES")=999
+19 SET PROCESS("PERSISTENT")=+$PIECE(NODE,"^",13)
+20 SET PROCESS("LINK")=$PIECE(NODE,"^",14)
+21 QUIT 1
+22 ;
GETWORK(PROCESS,WORK) ;
+1 NEW RETURN,XECUTE
+2 IF PROCESS("LINK")]""
SET WORK("LINK")=PROCESS("LINK")
+3 SET XECUTE="S RETURN=$$"_PROCESS("GET WORK")_"(.WORK)"
+4 Begin DoDot:1
+5 NEW PROCESS
+6 XECUTE XECUTE
End DoDot:1
+7 QUIT RETURN
+8 ;
DOWORK(PROCESS,WORK) ;
+1 NEW XECUTE
+2 MERGE PARMS=WORK
+3 SET XECUTE="D "_PROCESS("DO WORK")_"(.WORK)"
+4 Begin DoDot:1
+5 NEW PROCESS,HL7TRIES,PARMS,PROCNAME
+6 XECUTE XECUTE
End DoDot:1
+7 MERGE WORK=PARMS
+8 QUIT
+9 ;
CHK4STOP(PROCESS,HL7TRIES) ;
+1 ;Determines if the process should stop, returns 1 if yes, 0 if no
+2 ;
+3 IF $$CHKSTOP
QUIT 1
+4 IF '$PIECE($GET(^HLD(779.3,PROCESS("IEN"),0)),"^",2)
QUIT 1
+5 IF $GET(HL7TRIES)>(PROCESS("MAX TRIES")-1)
IF PROCESS("MINIMUM")<$GET(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME")))
QUIT 1
+6 IF $GET(^HLC("HL7 PROCESS COUNTS","RUNNING",PROCESS("NAME")))>PROCESS("MAXIMUM")
QUIT 1
+7 QUIT 0
+8 ;
CHKSTOP() ;has HL7 been requested to stop?
+1 QUIT '$PIECE($GET(^HLD(779.1,1,0)),"^",9)