Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: RORHDTUT

RORHDTUT.m

Go to the documentation of this file.
  1. RORHDTUT ;HCIOFO/SG - HISTORICAL DATA EXTRACTION UTILITIES ; 1/23/06 8:16am
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. Q
  1. ;
  1. ;***** RETURNS THE DATA EXTRACTION TIME FRAME(S)
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ;
  1. ; .DXDTF Reference to a local array where the time frame(s)
  1. ; will be returned to.
  1. ;
  1. ; DXTDF( A single time frame if no specific parameters are
  1. ; defined for the data area(s)
  1. ; ^01: Start Date
  1. ; ^02: End Date
  1. ; DataArea) Time frame for the data area:
  1. ; ^01: Start Date
  1. ; ^02: End Date
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. DXDTF(HDEIEN,DXDTF) ;
  1. N BUF,DAC,ENDT,IENS,RORBUF,RORMSG,STDT,TMP
  1. K DXDTF
  1. ;--- Load the time frame(s) from the data extract definition
  1. S IENS=(+HDEIEN)_","
  1. D GETS^DIQ(799.6,IENS,".03;.04;1*","I","RORBUF","RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.6,IENS)
  1. ;--- Get the main time frame (if defined)
  1. S STDT=$G(RORBUF(799.6,IENS,.03,"I"))\1 ; Start Date
  1. S ENDT=$G(RORBUF(799.6,IENS,.04,"I"))\1 ; End Date
  1. ;--- Check for data area time frames
  1. S IENS=""
  1. F S IENS=$O(RORBUF(799.61,IENS)) Q:IENS="" D
  1. . S DAC=+$G(RORBUF(799.61,IENS,.01,"I")) Q:DAC'>0
  1. . S BUF=""
  1. . ;--- Start Date
  1. . S TMP=$G(RORBUF(799.61,IENS,.02,"I"))\1
  1. . I TMP'>0 S TMP=STDT Q:TMP'>0
  1. . S $P(BUF,U,1)=TMP
  1. . ;--- End Date
  1. . S TMP=$G(RORBUF(799.61,IENS,.03,"I"))\1
  1. . I TMP'>0 S TMP=ENDT Q:TMP'>0
  1. . S $P(BUF,U,2)=TMP
  1. . ;--- Store the time frame
  1. . S DXDTF(DAC)=BUF
  1. ;--- Otherwise, return the main time frame
  1. S:$D(DXDTF)<10 DXDTF=STDT_U_ENDT
  1. ;--- Success
  1. Q 0
  1. ;
  1. ;***** GENERATES A NEW UNUSED FILE NAME FOR THE TASK
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ; TASKIEN Task IEN
  1. ; [.FILE] New name is returned via this parameter
  1. ; [GNONLY] Only generate a new name but do not store it into
  1. ; task record
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. NEWFILE(HDEIEN,TASKIEN,FILE,GNONLY) ;
  1. N BASE,EXT,FN,IENS,NAME,OUTDIR,RC,RORBUF,RORLST,RORMSG,TMP
  1. S RC=$$TASKFILE(HDEIEN,TASKIEN,.OUTDIR,.FILE) Q:RC<0 RC
  1. S BASE=$P($P(FILE,"."),"-",1,3),EXT=$P($P(FILE,".",2),";")
  1. ;--- Get a list of files in the output directory
  1. S RORBUF(BASE_"*."_EXT)=""
  1. Q:'$$LIST^%ZISH(OUTDIR,"RORBUF","RORLST") 0
  1. Q:$D(RORLST)<10 0
  1. K RORBUF
  1. ;--- Generate a new name
  1. S NAME="",FN=0
  1. F S NAME=$O(RORLST(NAME)) Q:NAME="" D
  1. . S TMP=+$P(NAME,"-",4) S:TMP>FN FN=TMP
  1. S FILE=BASE,$P(FILE,"-",4)=$TR($J(FN+1,2)," ","0")
  1. S FILE=FILE_"."_EXT
  1. Q:$G(GNONLY) 0
  1. K RORLST
  1. ;--- Store it to the task record
  1. S IENS=(+TASKIEN)_","_(+HDEIEN)_","
  1. S RORBUF(799.64,IENS,.05)=FILE
  1. D FILE^DIE(,"RORBUF","RORMSG")
  1. Q $$DBS^RORERR("RORMSG",-9,,,799.64,IENS)
  1. ;
  1. ;***** PAUSES THE OUTPUT AT PAGE END
  1. ;
  1. ; Return values:
  1. ; -2 Timeout
  1. ; -1 User entered a '^'
  1. ; 0 Continue
  1. ;
  1. PAGE() ;
  1. I $G(IOST)'["C-" S $Y=0 Q:$QUIT 0 Q
  1. N DA,DIR,DIROUT,DIRUT,DTOUT,DUOUT,X,Y
  1. S DIR(0)="E" D ^DIR S $Y=0
  1. Q:$QUIT $S($D(DUOUT):-1,$D(DTOUT):-2,1:0)
  1. Q
  1. ;
  1. ;***** SELECTS/ADDS A HISTORICAL DATA EXTRACTION DEFINITION
  1. ;
  1. ; [FLAGS] Flags that control the processing
  1. ; "A" Allow addition of new entries
  1. ;
  1. ; [.NAME] Data extract name is returned via this parameter
  1. ;
  1. ; [.NATIONAL] This parameter is set to 1 if a national data
  1. ; extraction is selected
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; "" "^" has been entered or timeout
  1. ; 0 Nothing has been selected
  1. ; >0 IEN of the selected definition (file #799.6)
  1. ;
  1. SELHDE(FLAGS,NAME,NATIONAL) ;
  1. N DA,DIC,DLAYGO,DTOUT,DUOUT,X,Y
  1. S NAME="",NATIONAL=0,FLAGS=$G(FLAGS)
  1. S DIC=799.6,DIC(0)="AENQZ"
  1. I FLAGS["A" D S DIC(0)=DIC(0)_"L",DLAYGO=DIC
  1. . S DIC("DR")="[RORHDT EDIT EXTRACTION]"
  1. S DIC("A")="Select a Data Extraction: "
  1. S DIC("S")="I $P($G(^(0)),U,2)=2" ; Only "Manual" type
  1. W ! D ^DIC Q:$D(DTOUT)!$D(DUOUT) ""
  1. I Y>0 S NAME=Y(0,0),NATIONAL=+$P(Y(0),U,9) Q +Y
  1. Q 0
  1. ;
  1. ;***** SELECTS A DATA EXTRACTION TASK
  1. ;
  1. ; RORHDIEN Data Extraction Definition IEN
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; "" "^" has been entered or timeout
  1. ; 0 Nothing has been selected
  1. ; >0 IEN of the selected task (multiple #4 of file #799.6)
  1. ;
  1. SELTASK(RORHDIEN) ;
  1. N DA,DIR,DTOUT,DUOUT,IENS,RC,ROROOT,X,Y
  1. ;--- Display status of the data extraction
  1. S RC=$$STATUS^RORHDT01(RORHDIEN) Q:RC<0 RC
  1. ;--- Select a task
  1. S ROROOT=$$ROOT^DILFD(799.64,","_RORHDIEN_",",1)
  1. S TMP=+$O(@ROROOT@(" "),-1)
  1. S DIR(0)="NO^1:"_TMP_":0^K:'$D(@ROROOT@(X,0)) X"
  1. S DIR("A")="Task ID"
  1. S DIR("?")="^I $$TASKLIST^RORHDTUT(RORHDIEN)"
  1. W ! D ^DIR
  1. Q $S($D(DTOUT)!$D(DUOUT):"",Y>0:+Y,1:0)
  1. ;
  1. ;***** GETS THE NAME OF THE TASK OUTPUT FILE
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ; TASKIEN Task IEN
  1. ; .OUTDIR Output directory is returned via this parameter
  1. ; .FILE File name is returned via the parameter
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. TASKFILE(HDEIEN,TASKIEN,OUTDIR,FILE) ;
  1. N IENS,RC,RORMSG
  1. S (OUTDIR,FILE)=""
  1. ;--- Get the output directory
  1. S IENS=(+HDEIEN)_","
  1. S OUTDIR=$$GET1^DIQ(799.6,IENS,2,,,"RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.6,IENS)
  1. ;--- Get the file name
  1. S IENS=(+TASKIEN)_","_(+HDEIEN)_","
  1. S FILE=$$GET1^DIQ(799.64,IENS,.05,,,"RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.6,IENS)
  1. ;--- Success
  1. Q 0
  1. ;
  1. ;***** DISPLAYS THE TASK LIST
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. TASKLIST(HDEIEN) ;
  1. N IENS,IT,RC,RORBUF,RORMNL,RORMSG,TASKIEN,TS
  1. ;--- Get the list of tasks
  1. S IENS=","_(+HDEIEN)_",",TMP="@;.01;.02;.05"
  1. D LIST^DIC(799.64,IENS,TMP,"Q",,,,"B",,,"RORBUF","RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.64,IENS)
  1. I $G(RORBUF("DILIST",0))<1 D Q 0
  1. . W !,?10,"No tasks have been defined"
  1. ;--- Get status of the tasks
  1. S IT=""
  1. F S IT=$O(RORBUF("DILIST","ID",IT)) Q:IT="" D
  1. . S TASKIEN=+RORBUF("DILIST",2,IT)
  1. . S TS=$$TASKSTAT(HDEIEN,TASKIEN)
  1. . S RORBUF("DILIST","ID",IT,.03)=$P(TS,U,2)
  1. ;--- Display the task table
  1. S RORMNL=$S($G(IOSL)>3:IOSL-3,1:20),$Y=0
  1. D TASKLP() W !
  1. S IT="",RC=0
  1. F S IT=$O(RORBUF("DILIST","ID",IT)) Q:IT="" D Q:RC
  1. . D TASKLP(IT) S:$Y'<RORMNL RC=$$PAGE()
  1. ;--- Success
  1. Q 0
  1. ;
  1. ;***** DISPLAYS A LINE OF THE TASK TABLE
  1. ;
  1. ; RORBUF Field values from the record of the file #798.5
  1. ; returned by LIST^DIC
  1. ;
  1. ; IT Index in the table
  1. ;
  1. TASKLP(IT) ;
  1. ;;!?2^ID^$J($G(RORBUF("DILIST",2,IT)),2)
  1. ;;?6^File Name^$G(RORBUF("DILIST","ID",IT,.05))
  1. ;;?39^Task^$G(RORBUF("DILIST","ID",IT,.02))
  1. ;;?49^Status^$G(RORBUF("DILIST","ID",IT,.03))
  1. ;
  1. N I,TMP
  1. ;--- Display the headers
  1. I '$G(IT) D Q
  1. . F I=1:1 S TMP=$P($T(TASKLP+I),";;",2,999) Q:TMP="" D
  1. . . W @$TR($P(TMP,"^")," "),$P(TMP,"^",2)
  1. ;--- Display the values
  1. F I=1:1 S TMP=$P($T(TASKLP+I),";;",2,999) Q:TMP="" D
  1. . W @$TR($P(TMP,"^")," "),@$P(TMP,"^",3)
  1. Q
  1. ;
  1. ;***** RETURNS THE TASK NUMBER
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ; TASKIEN Task IEN
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 No task defined
  1. ; >0 Task Number
  1. ;
  1. TASKNUM(HDEIEN,TASKIEN) ;
  1. N IENS,RORMSG,TASK
  1. S IENS=(+TASKIEN)_","_(+HDEIEN)_","
  1. S TASK=+$$GET1^DIQ(799.64,IENS,.02,"I",,"RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.64,IENS)
  1. Q TASK
  1. ;
  1. ;***** RETURNS STATUS OF THE TASK
  1. ;
  1. ; HDEIEN Data Extract IEN
  1. ; TASKIEN Task IEN
  1. ; [LTO] LOCK timeout
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Unknown Status
  1. ; >0 Status (Code^Description)
  1. ;
  1. ; 1 Active: Pending
  1. ; 2 Active: Running
  1. ; 3 Inactive: Finished
  1. ; 4 Inactive: Available
  1. ; 5 Inactive: Interrupted
  1. ;
  1. ; 100 Inactive: Crashed
  1. ; 101 Inactive: Errors
  1. ; 102 Active: Suspended
  1. ; 103 Active: Stopping
  1. ;
  1. TASKSTAT(HDEIEN,TASKIEN,LTO) ;
  1. N IENS,RORBUF,RORFDA,RORMSG,STATUS,TASK,TMP
  1. S IENS=(+TASKIEN)_","_(+HDEIEN)_","
  1. ;--- Get the task number and its last known status
  1. D GETS^DIQ(799.64,IENS,".02;.03","EI","RORBUF","RORMSG")
  1. Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.64,IENS)
  1. S TASK=$G(RORBUF(799.64,IENS,.02,"I"))
  1. Q:TASK="" 0
  1. ;--- Try to get status of the task
  1. S STATUS=$$STATUS^RORTSK02(TASK,$G(LTO))
  1. Q:STATUS<0 STATUS
  1. ;--- If the task record exists, then update the task STATUS
  1. ;--- field if necessary and return the current task status
  1. I STATUS>0 D:+STATUS'=$G(RORBUF(799.64,IENS,.03,"I")) Q STATUS
  1. . S RORFDA(799.64,IENS,.03)=+STATUS
  1. . D FILE^DIE(,"RORFDA","RORMSG")
  1. . D:$G(DIERR) DBS^RORERR("RORMSG",-9,,,799.64,IENS)
  1. ;--- Otherwise, return the last known status
  1. S STATUS=+$G(RORBUF(799.64,IENS,.03,"I"))
  1. Q:STATUS'>0 0
  1. S TMP=$TR($G(RORBUF(799.64,IENS,.03,"E")),">",":")
  1. Q STATUS_U_TMP