HLOPROC ;ALB/CJM- Generic HL7 Process - 10/4/94 1pm ;03/26/2012
;;1.6;HEALTH LEVEL SEVEN;**126,134,146,147,158**;Oct 13, 1995;Build 14
;Per VHA Directive 2004-038, this routine should not be modified.
;
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:$G(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:$G(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="Q:$QUIT """" Q"
;
;quit back to the Taskman error trap on these errors
I ($ECODE["TOOMANYFILES")!($ECODE["EDITED") D Q:$QUIT "" Q
.S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
.D END
.D UNWIND^%ZTER
;
;don't log READ/WRITE errors unless logging is turned on, but do resume
;execution
I '$G(^HLTMP("LOG ALL ERRORS")),($ECODE["READ")!($ECODE["NOTOPEN")!($ECODE["DEVNOTOPN")!($ECODE["WRITE")!($ECODE["OPENERR") D Q:$QUIT "" Q
.S $ECODE=""
;
;add to the process's count for the type of error
N HOUR
S HOUR=$E($$NOW^XLFDT,1,10)
S ^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2))=$G(^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2)))+1
;
;a lot of errors of the same type may indicate an endless loop, so quit
;to Taskman error trap to be on the safe side.
I $G(^TMP("HL7 ERRORS",$J,HOUR,$P($ECODE,",",2)))>30 D Q:$QUIT "" Q
.S:'$D(PROCNAME) PROCNAME=$G(^HL7TMP("HL7 PROCESS NAME",$J))
.D END
.D UNWIND^%ZTER
;
;can log error and continue processing
D ^%ZTER
S $ECODE=""
Q:$QUIT "" 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?
N RET
;** P146 START CJM
;Q '$P($G(^HLD(779.1,1,0)),"^",9)
S RET='$P($G(^HLD(779.1,1,0)),"^",9)
ZB25 ;
Q RET
;**P146 END CJM
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLOPROC 5578 printed Nov 22, 2024@17:09:04 Page 2
HLOPROC ;ALB/CJM- Generic HL7 Process - 10/4/94 1pm ;03/26/2012
+1 ;;1.6;HEALTH LEVEL SEVEN;**126,134,146,147,158**;Oct 13, 1995;Build 14
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
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 $GET(HL7STOP)
QUIT
+37 if $GET(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="Q:$QUIT """" Q"
+3 ;
+4 ;quit back to the Taskman error trap on these errors
+5 IF ($ECODE["TOOMANYFILES")!($ECODE["EDITED")
Begin DoDot:1
+6 if '$DATA(PROCNAME)
SET PROCNAME=$GET(^HL7TMP("HL7 PROCESS NAME",$JOB))
+7 DO END
+8 DO UNWIND^%ZTER
End DoDot:1
if $QUIT
QUIT ""
QUIT
+9 ;
+10 ;don't log READ/WRITE errors unless logging is turned on, but do resume
+11 ;execution
+12 IF '$GET(^HLTMP("LOG ALL ERRORS"))
IF ($ECODE["READ")!($ECODE["NOTOPEN")!($ECODE["DEVNOTOPN")!($ECODE["WRITE")!($ECODE["OPENERR")
Begin DoDot:1
+13 SET $ECODE=""
End DoDot:1
if $QUIT
QUIT ""
QUIT
+14 ;
+15 ;add to the process's count for the type of error
+16 NEW HOUR
+17 SET HOUR=$EXTRACT($$NOW^XLFDT,1,10)
+18 SET ^TMP("HL7 ERRORS",$JOB,HOUR,$PIECE($ECODE,",",2))=$GET(^TMP("HL7 ERRORS",$JOB,HOUR,$PIECE($ECODE,",",2)))+1
+19 ;
+20 ;a lot of errors of the same type may indicate an endless loop, so quit
+21 ;to Taskman error trap to be on the safe side.
+22 IF $GET(^TMP("HL7 ERRORS",$JOB,HOUR,$PIECE($ECODE,",",2)))>30
Begin DoDot:1
+23 if '$DATA(PROCNAME)
SET PROCNAME=$GET(^HL7TMP("HL7 PROCESS NAME",$JOB))
+24 DO END
+25 DO UNWIND^%ZTER
End DoDot:1
if $QUIT
QUIT ""
QUIT
+26 ;
+27 ;can log error and continue processing
+28 DO ^%ZTER
+29 SET $ECODE=""
+30 if $QUIT
QUIT ""
QUIT
+31 ;
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 NEW RET
+2 ;** P146 START CJM
+3 ;Q '$P($G(^HLD(779.1,1,0)),"^",9)
+4 SET RET='$PIECE($GET(^HLD(779.1,1,0)),"^",9)
ZB25 ;
+1 QUIT RET
+2 ;**P146 END CJM