RORUPD05 ;HCIOFO/SG - REGISTRY UPDATE (MULTITASK) ; 7/6/06 11:09am
;;1.5;CLINICAL CASE REGISTRIES;**1**;Feb 17, 2006;Build 24
;
Q
;
;***** MONITORS THE SUBTASKS
;
; Return Values:
; <0 Error code
; >=0 Combined statistics returned by the $$PROCESS^RORUPD01
; function of each subtask
;
MONITOR() ;
N CNT,ECNT,EXIT,RC,TASK,TIMEOUT,TSKCNT
S (CNT,ECNT,EXIT)=0,TIMEOUT=600 ; 10hrs = 600*60
F H 60 D Q:EXIT
. ;--- Exit if all subtasks finished
. I $D(@RORUPDPI@("T"))<10 S EXIT=1 Q
. ;--- Abort if some of the subtasks have not started during
. ;--- the predefined time frame.
. I TIMEOUT'>0 S EXIT=$$ERROR^RORERR(-78) Q
. ;--- Check for a request to stop
. I $D(ZTQUEUED),$$S^%ZTLOAD S EXIT=$$ERROR^RORERR(-42) Q
. ;--- Browse through the list of subtasks
. S (TASK,TSKCNT)=0
. F S TASK=$O(@RORUPDPI@("T",TASK)) Q:TASK="" D
. . S RC=@RORUPDPI@("T",TASK),TSKCNT=TSKCNT+1
. . ;--- Skip a subtask that was scheduled but has not started yet
. . I RC="S" S TSKCNT=TSKCNT-1 Q
. . ;--- Skip a running subtask
. . L +@RORUPDPI@("T",TASK):1 E Q
. . L -@RORUPDPI@("T",TASK)
. . ;--- The subtask has crashed
. . I RC=-60 S EXIT=$$ERROR^RORERR(-60,,,,TASK) Q
. . ;--- Fatal error in the subtask
. . I RC<0 S EXIT=+RC D Q
. . . S RC=$$ERROR^RORERR(-56,,,,+RC,"subtask #"_TASK)
. . ;--- The subtask is completed (accumulate the statistics)
. . S CNT=CNT+$P(RC,U),ECNT=ECNT+$P(RC,U,2)
. . K @RORUPDPI@("T",TASK)
. ;--- Timeout timer is ticking only if no subtasks are running
. S:TSKCNT'>0 TIMEOUT=TIMEOUT-1
Q $S(EXIT<0:EXIT,1:CNT_U_ECNT)
;
;***** PROCESSES THE DATA (SINGLE TASK OR MULTITASK MODE)
;
; [MAXNTSK] Maximum number of data processing subtasks.
; If this parameter is less than 2, all patients
; will be processed by the single main task.
; Otherwise, all patients can be distributed among
; several subtasks.
;
; If "N^M^AUTO" is passed as a value of this parameter
; and difference between the end and start dates is
; more than M days then N subtasks will be created.
;
; Return Values:
; <0 Error code
; >=0 Statistics returned by the $$MONITOR function
;
; The main task will wait for completion of the subtasks. If one
; of them fails, all other (including the main one) will fail too.
;
PROCESS(MAXNTSK) ;
N COUNTERS,NTSK,OLDPI,RC,SUBSCR,TASKTBL,TMP
;--- Calculate number of tasks and create the task table
D:$G(MAXNTSK)["AUTO"
. S TMP=$$FMDIFF^XLFDT(RORUPD("DSEND"),RORUPD("DSBEG"),1)
. S MAXNTSK=$S(TMP>$P(MAXNTSK,U,2):+MAXNTSK,1:0)
I $G(MAXNTSK)>1 D Q:NTSK<0 NTSK
. S NTSK=$$TASKTBL(MAXNTSK,.TASKTBL)
;--- Process all patients by the main task
Q:$G(NTSK)<2 $$PROCESS^RORUPD01()
;
S RORUPD("JOB")=$J,OLDPI=RORUPDPI
;--- Initialize the node in the ^XTMP global
I $G(RORPARM("SETUP")) D
. S SUBSCR="RORUPDR"_+$O(RORUPD("LM2",""))
. S RORUPDPI=$NA(^XTMP(SUBSCR)),I=0
. F S I=$O(@RORUPDPI@(I)) Q:I="" K:I'="U" @RORUPDPI@(I)
E D
. S SUBSCR="RORUPDJ"_$J
. S RORUPDPI=$NA(^XTMP(SUBSCR))
. K @RORUPDPI
D XTMPHDR^RORUTL01(SUBSCR,30,"PROCESS-RORUPD05")
M @RORUPDPI=@OLDPI
;--- Indicate that the main task is running
L +@RORUPDPI@("T",0):7
E Q $$ERROR^RORERR(-61)
;
;--- Start the subtasks
S RC=$$START(.TASKTBL)
;--- Monitor the subtasks
S COUNTERS=$S(RC'<0:$$MONITOR(),1:RC)
;
;--- Clear "running" flag of the main task
; (request all unfinished subtasks to stop)
L -@RORUPDPI@("T",0)
;--- Cleanup
I COUNTERS<0 D
. N TASK,ZTSK
. ;--- Dequeue subtasks that have not started yet
. S TASK=0
. F S TASK=$O(@RORUPDPI@("T",TASK)) Q:TASK="" D
. . S ZTSK=TASK D DQ^%ZTLOAD
. ;--- Wait for all unfinished subtasks to stop
. L +@RORUPDPI@("T"):300 L -@RORUPDPI@("T")
K @RORUPDPI@("T")
Q COUNTERS
;
;***** STARTS THE SUBTASKS
;
; .TASKTBL Reference to a local variable containing the table
; of subtask parameters. See the TASKSPLT and TASKTBL
; entry points for details.
;
; Return Values:
; <0 Error code
; 0 Ok
;
START(TASKTBL) ;
N CNT,I,ZTDESC,ZTDTH,ZTIO,ZTPRI,ZTRTN,ZTSAVE,ZTSK
K @RORUPDPI@("T")
;--- Do not allow subtasks to proceed before everything is ready
L +@RORUPDPI@("T"):7
E Q $$ERROR^RORERR(-61)
;--- Start the subtasks
S I=""
F CNT=1:1 S I=$O(TASKTBL(I)) Q:I="" D
. S ZTRTN="SUBTASK^RORUPD05",ZTIO=""
. S ZTDTH=$$FMADD^XLFDT($$NOW^XLFDT,,,,CNT*30)
. S ZTDESC="Registry Update Subtask ("_$TR(TASKTBL(I),U,"-")_")"
. S ZTSAVE("RORIENS")=TASKTBL(I)
. S ZTSAVE("RORLRC(")=""
. S ZTSAVE("RORPARM(")=""
. S ZTSAVE("RORUPD(")=""
. S ZTSAVE("RORUPDPI")=""
. D ^%ZTLOAD
. ;--- Indicate that the subtask has been scheduled
. S @RORUPDPI@("T",ZTSK)="S"
. D LOG^RORERR(-62,,,ZTSK)
;--- The subtasks may proceed now
L -@RORUPDPI@("T")
Q 0
;
;***** DATA PROCESSING SUBTASK
;
; RORIENS Diapason of IENs in the 'PATIENT' file
; ^1: Start IEN
; ^2: End IEN
; RORLRC List of Lab result codes to check
; RORPARM Application parameters
; RORUPD Registry update descriptor
; RORUPDPI Closed root of the temporary storage
;
SUBTASK ;
N RORERROR ; Error processing data
N RORLOG ; Log subsystem constants & variables
;
N RC,TASK,TMP
S TASK=ZTSK
;--- We are not in the KIDS environment anymore
K RORPARM("KIDS")
;--- Disable debug output (subtask has no device)
S:$G(RORPARM("DEBUG"))>1 RORPARM("DEBUG")=1
;--- Indicate that the subtask is running
L +@RORUPDPI@("T",TASK):180
E S RC=$$ERROR^RORERR(-61) Q
;--- Check if the main task is running
L +@RORUPDPI@("T",0):3
I D
. ;--- Cleanup if the main task is not running
. L -@RORUPDPI@("T",0)
. K @RORUPDPI@("T",TASK)
E D
. N REGIEN,REGLST
. ;--- Error code that will be in effect if the subtask crashes
. S @RORUPDPI@("T",TASK)=-60
. ;--- Initialize the variables
. D INIT^RORUTL01(),CLEAR^RORERR("SUBTASK^RORUPD05")
. S REGIEN=""
. F S REGIEN=$O(@RORUPDPI@(2,REGIEN)) Q:REGIEN="" D
. . S TMP=$P(@RORUPDPI@(2,REGIEN),U) S:TMP'="" REGLST(TMP)=REGIEN
. S TMP="REGISTRY UPDATE SUBTASK #"_TASK_" STARTED"
. S TMP=$$OPEN^RORLOG(.REGLST,1,TMP)
. ;--- Process the patients from 'Start IEN' to 'End IEN'
. S RC=$$PROCESS^RORUPD01($P(RORIENS,U),$P(RORIENS,U,2))
. ;--- Set the error code returned by the registry update process
. S @RORUPDPI@("T",TASK)=RC
. ;--- Cleanup and error processing
. S:RC=-42 ZTSTOP=1
. S TMP="REGISTRY UPDATE SUBTASK "_$S(RC<0:"ABORTED",1:"COMPLETED")
. D CLOSE^RORLOG(TMP,$S(RC'<0:RC,1:""))
;--- Clear "running" flag of the subtask
L -@RORUPDPI@("T",TASK)
S ZTREQ="@"
Q
;
;***** CALCULATES TABLE OF SUBTASKS
;
; MAXNTSK Maximum number of data processing subtasks
;
; .TASKTBL Reference to a local variable where table of
; subtask parameters is returned:
;
; TASKTBL Number of subtasks
; TASKTBL(I) Subtask parameters
; ^1: Start IEN
; ^2: End IEN
;
; Return Values:
; <0 Error code
; 0 Process all data by the main task
; >1 Number of subtasks
;
; If the PATIENT file contains more than 100,000 records, up to
; MAXNTSK data processing subtasks may be defined. Otherwise, the
; data should be processed by the main task.
;
TASKTBL(MAXNTSK,RORTBL) ;
N I,IEN,INC,LST,NR,RORTMP
K RORTBL
;--- Get number of records in the PATIENT file
S NR=$$GET1^DID(2,,,"ENTRIES",,"RORMSG")
Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9)
Q:NR'>10000 0
;--- Generate IEN intervals (no more than 300)
S RORTMP=$$ALLOC^RORTMP()
S INC=NR\300,NR=0 S:INC<1 INC=1
F IEN=0:INC S IEN=$O(^DPT(IEN)) Q:IEN'>0 D
. S NR=NR+1,@RORTMP@(NR)=IEN
;--- Generate the task table
S IEN=1,INC=NR/MAXNTSK
F RORTBL=1:1 D Q:(RORTBL'<MAXNTSK)!(IEN'>0)
. S RORTBL(RORTBL)=IEN
. S I=$J(RORTBL*INC,0,0),IEN=$G(@RORTMP@(I))
. S $P(RORTBL(RORTBL),U,2)=IEN
D FREE^RORTMP(RORTMP)
;--- Analize the result
I $G(RORTBL)<2 K RORTBL
E S $P(RORTBL(RORTBL),U,2)=$O(^DPT(" "),-1)
Q +$G(RORTBL)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORUPD05 8409 printed Nov 22, 2024@16:53:53 Page 2
RORUPD05 ;HCIOFO/SG - REGISTRY UPDATE (MULTITASK) ; 7/6/06 11:09am
+1 ;;1.5;CLINICAL CASE REGISTRIES;**1**;Feb 17, 2006;Build 24
+2 ;
+3 QUIT
+4 ;
+5 ;***** MONITORS THE SUBTASKS
+6 ;
+7 ; Return Values:
+8 ; <0 Error code
+9 ; >=0 Combined statistics returned by the $$PROCESS^RORUPD01
+10 ; function of each subtask
+11 ;
MONITOR() ;
+1 NEW CNT,ECNT,EXIT,RC,TASK,TIMEOUT,TSKCNT
+2 ; 10hrs = 600*60
SET (CNT,ECNT,EXIT)=0
SET TIMEOUT=600
+3 FOR
HANG 60
Begin DoDot:1
+4 ;--- Exit if all subtasks finished
+5 IF $DATA(@RORUPDPI@("T"))<10
SET EXIT=1
QUIT
+6 ;--- Abort if some of the subtasks have not started during
+7 ;--- the predefined time frame.
+8 IF TIMEOUT'>0
SET EXIT=$$ERROR^RORERR(-78)
QUIT
+9 ;--- Check for a request to stop
+10 IF $DATA(ZTQUEUED)
IF $$S^%ZTLOAD
SET EXIT=$$ERROR^RORERR(-42)
QUIT
+11 ;--- Browse through the list of subtasks
+12 SET (TASK,TSKCNT)=0
+13 FOR
SET TASK=$ORDER(@RORUPDPI@("T",TASK))
if TASK=""
QUIT
Begin DoDot:2
+14 SET RC=@RORUPDPI@("T",TASK)
SET TSKCNT=TSKCNT+1
+15 ;--- Skip a subtask that was scheduled but has not started yet
+16 IF RC="S"
SET TSKCNT=TSKCNT-1
QUIT
+17 ;--- Skip a running subtask
+18 LOCK +@RORUPDPI@("T",TASK):1
IF '$TEST
QUIT
+19 LOCK -@RORUPDPI@("T",TASK)
+20 ;--- The subtask has crashed
+21 IF RC=-60
SET EXIT=$$ERROR^RORERR(-60,,,,TASK)
QUIT
+22 ;--- Fatal error in the subtask
+23 IF RC<0
SET EXIT=+RC
Begin DoDot:3
+24 SET RC=$$ERROR^RORERR(-56,,,,+RC,"subtask #"_TASK)
End DoDot:3
QUIT
+25 ;--- The subtask is completed (accumulate the statistics)
+26 SET CNT=CNT+$PIECE(RC,U)
SET ECNT=ECNT+$PIECE(RC,U,2)
+27 KILL @RORUPDPI@("T",TASK)
End DoDot:2
+28 ;--- Timeout timer is ticking only if no subtasks are running
+29 if TSKCNT'>0
SET TIMEOUT=TIMEOUT-1
End DoDot:1
if EXIT
QUIT
+30 QUIT $SELECT(EXIT<0:EXIT,1:CNT_U_ECNT)
+31 ;
+32 ;***** PROCESSES THE DATA (SINGLE TASK OR MULTITASK MODE)
+33 ;
+34 ; [MAXNTSK] Maximum number of data processing subtasks.
+35 ; If this parameter is less than 2, all patients
+36 ; will be processed by the single main task.
+37 ; Otherwise, all patients can be distributed among
+38 ; several subtasks.
+39 ;
+40 ; If "N^M^AUTO" is passed as a value of this parameter
+41 ; and difference between the end and start dates is
+42 ; more than M days then N subtasks will be created.
+43 ;
+44 ; Return Values:
+45 ; <0 Error code
+46 ; >=0 Statistics returned by the $$MONITOR function
+47 ;
+48 ; The main task will wait for completion of the subtasks. If one
+49 ; of them fails, all other (including the main one) will fail too.
+50 ;
PROCESS(MAXNTSK) ;
+1 NEW COUNTERS,NTSK,OLDPI,RC,SUBSCR,TASKTBL,TMP
+2 ;--- Calculate number of tasks and create the task table
+3 if $GET(MAXNTSK)["AUTO"
Begin DoDot:1
+4 SET TMP=$$FMDIFF^XLFDT(RORUPD("DSEND"),RORUPD("DSBEG"),1)
+5 SET MAXNTSK=$SELECT(TMP>$PIECE(MAXNTSK,U,2):+MAXNTSK,1:0)
End DoDot:1
+6 IF $GET(MAXNTSK)>1
Begin DoDot:1
+7 SET NTSK=$$TASKTBL(MAXNTSK,.TASKTBL)
End DoDot:1
if NTSK<0
QUIT NTSK
+8 ;--- Process all patients by the main task
+9 if $GET(NTSK)<2
QUIT $$PROCESS^RORUPD01()
+10 ;
+11 SET RORUPD("JOB")=$JOB
SET OLDPI=RORUPDPI
+12 ;--- Initialize the node in the ^XTMP global
+13 IF $GET(RORPARM("SETUP"))
Begin DoDot:1
+14 SET SUBSCR="RORUPDR"_+$ORDER(RORUPD("LM2",""))
+15 SET RORUPDPI=$NAME(^XTMP(SUBSCR))
SET I=0
+16 FOR
SET I=$ORDER(@RORUPDPI@(I))
if I=""
QUIT
if I'="U"
KILL @RORUPDPI@(I)
End DoDot:1
+17 IF '$TEST
Begin DoDot:1
+18 SET SUBSCR="RORUPDJ"_$JOB
+19 SET RORUPDPI=$NAME(^XTMP(SUBSCR))
+20 KILL @RORUPDPI
End DoDot:1
+21 DO XTMPHDR^RORUTL01(SUBSCR,30,"PROCESS-RORUPD05")
+22 MERGE @RORUPDPI=@OLDPI
+23 ;--- Indicate that the main task is running
+24 LOCK +@RORUPDPI@("T",0):7
+25 IF '$TEST
QUIT $$ERROR^RORERR(-61)
+26 ;
+27 ;--- Start the subtasks
+28 SET RC=$$START(.TASKTBL)
+29 ;--- Monitor the subtasks
+30 SET COUNTERS=$SELECT(RC'<0:$$MONITOR(),1:RC)
+31 ;
+32 ;--- Clear "running" flag of the main task
+33 ; (request all unfinished subtasks to stop)
+34 LOCK -@RORUPDPI@("T",0)
+35 ;--- Cleanup
+36 IF COUNTERS<0
Begin DoDot:1
+37 NEW TASK,ZTSK
+38 ;--- Dequeue subtasks that have not started yet
+39 SET TASK=0
+40 FOR
SET TASK=$ORDER(@RORUPDPI@("T",TASK))
if TASK=""
QUIT
Begin DoDot:2
+41 SET ZTSK=TASK
DO DQ^%ZTLOAD
End DoDot:2
+42 ;--- Wait for all unfinished subtasks to stop
+43 LOCK +@RORUPDPI@("T"):300
LOCK -@RORUPDPI@("T")
End DoDot:1
+44 KILL @RORUPDPI@("T")
+45 QUIT COUNTERS
+46 ;
+47 ;***** STARTS THE SUBTASKS
+48 ;
+49 ; .TASKTBL Reference to a local variable containing the table
+50 ; of subtask parameters. See the TASKSPLT and TASKTBL
+51 ; entry points for details.
+52 ;
+53 ; Return Values:
+54 ; <0 Error code
+55 ; 0 Ok
+56 ;
START(TASKTBL) ;
+1 NEW CNT,I,ZTDESC,ZTDTH,ZTIO,ZTPRI,ZTRTN,ZTSAVE,ZTSK
+2 KILL @RORUPDPI@("T")
+3 ;--- Do not allow subtasks to proceed before everything is ready
+4 LOCK +@RORUPDPI@("T"):7
+5 IF '$TEST
QUIT $$ERROR^RORERR(-61)
+6 ;--- Start the subtasks
+7 SET I=""
+8 FOR CNT=1:1
SET I=$ORDER(TASKTBL(I))
if I=""
QUIT
Begin DoDot:1
+9 SET ZTRTN="SUBTASK^RORUPD05"
SET ZTIO=""
+10 SET ZTDTH=$$FMADD^XLFDT($$NOW^XLFDT,,,,CNT*30)
+11 SET ZTDESC="Registry Update Subtask ("_$TRANSLATE(TASKTBL(I),U,"-")_")"
+12 SET ZTSAVE("RORIENS")=TASKTBL(I)
+13 SET ZTSAVE("RORLRC(")=""
+14 SET ZTSAVE("RORPARM(")=""
+15 SET ZTSAVE("RORUPD(")=""
+16 SET ZTSAVE("RORUPDPI")=""
+17 DO ^%ZTLOAD
+18 ;--- Indicate that the subtask has been scheduled
+19 SET @RORUPDPI@("T",ZTSK)="S"
+20 DO LOG^RORERR(-62,,,ZTSK)
End DoDot:1
+21 ;--- The subtasks may proceed now
+22 LOCK -@RORUPDPI@("T")
+23 QUIT 0
+24 ;
+25 ;***** DATA PROCESSING SUBTASK
+26 ;
+27 ; RORIENS Diapason of IENs in the 'PATIENT' file
+28 ; ^1: Start IEN
+29 ; ^2: End IEN
+30 ; RORLRC List of Lab result codes to check
+31 ; RORPARM Application parameters
+32 ; RORUPD Registry update descriptor
+33 ; RORUPDPI Closed root of the temporary storage
+34 ;
SUBTASK ;
+1 ; Error processing data
NEW RORERROR
+2 ; Log subsystem constants & variables
NEW RORLOG
+3 ;
+4 NEW RC,TASK,TMP
+5 SET TASK=ZTSK
+6 ;--- We are not in the KIDS environment anymore
+7 KILL RORPARM("KIDS")
+8 ;--- Disable debug output (subtask has no device)
+9 if $GET(RORPARM("DEBUG"))>1
SET RORPARM("DEBUG")=1
+10 ;--- Indicate that the subtask is running
+11 LOCK +@RORUPDPI@("T",TASK):180
+12 IF '$TEST
SET RC=$$ERROR^RORERR(-61)
QUIT
+13 ;--- Check if the main task is running
+14 LOCK +@RORUPDPI@("T",0):3
+15 IF $TEST
Begin DoDot:1
+16 ;--- Cleanup if the main task is not running
+17 LOCK -@RORUPDPI@("T",0)
+18 KILL @RORUPDPI@("T",TASK)
End DoDot:1
+19 IF '$TEST
Begin DoDot:1
+20 NEW REGIEN,REGLST
+21 ;--- Error code that will be in effect if the subtask crashes
+22 SET @RORUPDPI@("T",TASK)=-60
+23 ;--- Initialize the variables
+24 DO INIT^RORUTL01()
DO CLEAR^RORERR("SUBTASK^RORUPD05")
+25 SET REGIEN=""
+26 FOR
SET REGIEN=$ORDER(@RORUPDPI@(2,REGIEN))
if REGIEN=""
QUIT
Begin DoDot:2
+27 SET TMP=$PIECE(@RORUPDPI@(2,REGIEN),U)
if TMP'=""
SET REGLST(TMP)=REGIEN
End DoDot:2
+28 SET TMP="REGISTRY UPDATE SUBTASK #"_TASK_" STARTED"
+29 SET TMP=$$OPEN^RORLOG(.REGLST,1,TMP)
+30 ;--- Process the patients from 'Start IEN' to 'End IEN'
+31 SET RC=$$PROCESS^RORUPD01($PIECE(RORIENS,U),$PIECE(RORIENS,U,2))
+32 ;--- Set the error code returned by the registry update process
+33 SET @RORUPDPI@("T",TASK)=RC
+34 ;--- Cleanup and error processing
+35 if RC=-42
SET ZTSTOP=1
+36 SET TMP="REGISTRY UPDATE SUBTASK "_$SELECT(RC<0:"ABORTED",1:"COMPLETED")
+37 DO CLOSE^RORLOG(TMP,$SELECT(RC'<0:RC,1:""))
End DoDot:1
+38 ;--- Clear "running" flag of the subtask
+39 LOCK -@RORUPDPI@("T",TASK)
+40 SET ZTREQ="@"
+41 QUIT
+42 ;
+43 ;***** CALCULATES TABLE OF SUBTASKS
+44 ;
+45 ; MAXNTSK Maximum number of data processing subtasks
+46 ;
+47 ; .TASKTBL Reference to a local variable where table of
+48 ; subtask parameters is returned:
+49 ;
+50 ; TASKTBL Number of subtasks
+51 ; TASKTBL(I) Subtask parameters
+52 ; ^1: Start IEN
+53 ; ^2: End IEN
+54 ;
+55 ; Return Values:
+56 ; <0 Error code
+57 ; 0 Process all data by the main task
+58 ; >1 Number of subtasks
+59 ;
+60 ; If the PATIENT file contains more than 100,000 records, up to
+61 ; MAXNTSK data processing subtasks may be defined. Otherwise, the
+62 ; data should be processed by the main task.
+63 ;
TASKTBL(MAXNTSK,RORTBL) ;
+1 NEW I,IEN,INC,LST,NR,RORTMP
+2 KILL RORTBL
+3 ;--- Get number of records in the PATIENT file
+4 SET NR=$$GET1^DID(2,,,"ENTRIES",,"RORMSG")
+5 if $GET(DIERR)
QUIT $$DBS^RORERR("RORMSG",-9)
+6 if NR'>10000
QUIT 0
+7 ;--- Generate IEN intervals (no more than 300)
+8 SET RORTMP=$$ALLOC^RORTMP()
+9 SET INC=NR\300
SET NR=0
if INC<1
SET INC=1
+10 FOR IEN=0:INC
SET IEN=$ORDER(^DPT(IEN))
if IEN'>0
QUIT
Begin DoDot:1
+11 SET NR=NR+1
SET @RORTMP@(NR)=IEN
End DoDot:1
+12 ;--- Generate the task table
+13 SET IEN=1
SET INC=NR/MAXNTSK
+14 FOR RORTBL=1:1
Begin DoDot:1
+15 SET RORTBL(RORTBL)=IEN
+16 SET I=$JUSTIFY(RORTBL*INC,0,0)
SET IEN=$GET(@RORTMP@(I))
+17 SET $PIECE(RORTBL(RORTBL),U,2)=IEN
End DoDot:1
if (RORTBL'<MAXNTSK)!(IEN'>0)
QUIT
+18 DO FREE^RORTMP(RORTMP)
+19 ;--- Analize the result
+20 IF $GET(RORTBL)<2
KILL RORTBL
+21 IF '$TEST
SET $PIECE(RORTBL(RORTBL),U,2)=$ORDER(^DPT(" "),-1)
+22 QUIT +$GET(RORTBL)