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

SDES2RSTCAVAIL.m

Go to the documentation of this file.
SDES2RSTCAVAIL ;ALB/LAB - VISTA SCHEDULING SDES2 RESTORE CLIN AVAIL ;OCT 30, 2023
 ;;5.3;Scheduling;**861,864,875**;Aug 13, 1993;Build 25
 ;;Per VHA Directive 6402, this routine should not be modified
 Q
 ;
RESTORE(RESULT,SDCONTEXT,SDRESTORE) ;
 N ERRORS,RETURN
 ;validate context array for accuracy
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Restore",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 ;
 ;set up needed variables and validate
 ;
 D ASSIGNVARS(.CLINIC,.DATETIME,.RESTORETYPE)
 D VALIDATE(.ERRORS,CLINIC,.DATETIME,RESTORETYPE)
 I $D(ERRORS) S ERRORS("Restore",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 D GETCLINICINFO(CLINIC,.INCREMENT,.STARTHOUR,DATETIME,.CANCELDATE)
 I $D(ERRORS) S ERRORS("Restore",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 ;
 ; verify that date/time has cancellation
 ;
 D VERIFYCANCEL(.ERRORS,CLINIC,DATETIME)
 I $D(ERRORS) S ERRORS("Restore",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 ;
 D:RESTORETYPE="F" FULLRESTORE(.RETURN,CLINIC,DATETIME)
 D:RESTORETYPE="P" PARTIALRESTORE(.ERRORS,.RETURN,CLINIC,DATETIME,STARTHOUR,INCREMENT)
 I $D(ERRORS) S ERRORS("Restore",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
 D BUILDJSON^SDES2JSON(.RESULT,.RETURN)
 Q
 ;
GETCLINICINFO(CLINIC,INCREMENT,STARTHOUR,DATETIME,CANCELDATE) ;assign variables needed from clinic
 S INCREMENT=+$$GET1^DIQ(44,CLINIC_",",1917,"I")
 S INCREMENT=$S(INCREMENT<3:4,INCREMENT:INCREMENT,1:4)
 S STARTHOUR=$$GET1^DIQ(44,CLINIC_",",1914,"I")
 S:STARTHOUR="" STARTHOUR=8
 S CANCELDATE=$P(DATETIME,".")
 Q
 ;
ASSIGNVARS(CLINIC,DATETIME,RESTORETYPE) ;assign variables from input array
 S CLINIC=$G(SDRESTORE("CLINIC IEN"))
 S DATETIME=$G(SDRESTORE("DATE OR DATETIME")) ;date for full datetime for partial
 S RESTORETYPE=$G(SDRESTORE("RESTORE TYPE")) ;partial or full restore
 Q
 ;
VALIDATE(ERRORS,CLINIC,DATETIME,RESTORETYPE) ; validate input array variables
 D VALFILEIEN^SDES2VALUTIL(,.ERRORS,44,CLINIC,1,"",18,19)
 Q:$D(ERRORS)
 I $$INACTIVE^SDES2UTIL(CLINIC) S ERRORS("Restore",1)="" D ERRLOG^SDES2JSON(.ERRORS,52,"Inactive clinic cannot restore availability.")
 Q:$D(ERRORS)
 I '$$CLNCK^SDUTL2(CLINIC,1) S ERRORS("Restore",1)="" D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic stop code restriction invalid. MUST be corrected before continuing.")
 Q:$D(ERRORS)
 S DATETIME=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,DATETIME,CLINIC,1,45,46) ;
 I (RESTORETYPE'="P")&(RESTORETYPE'="F") S ERRORS("Restore",1)="" D ERRLOG^SDES2JSON(.ERRORS,52,"Invalid Restore type value.") Q
 I (RESTORETYPE="F")&($P(DATETIME,".",2)'="") S ERRORS("Restore",1)="" D ERRLOG^SDES2JSON(.ERRORS,52,"No time needed for Full restore.")
 I (RESTORETYPE="P")&($P(DATETIME,".",2)="") S ERRORS("Restore",1)="" D ERRLOG^SDES2JSON(.ERRORS,52,"Start time of period to restore is required.")
 Q
 ;
VERIFYCANCEL(ERRORS,CLINIC,DATETIME) ;Verify that the clinic has cancellation for that a date or datetime
 N CURRENTSCHEDULE
 S CURRENTSCHEDULE=$$GET1^DIQ(44.005,$P(DATETIME,".")_","_CLINIC_",",1)
 I (CURRENTSCHEDULE'["CANCELLED")&(CURRENTSCHEDULE'["X") D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic has not been cancelled for that date.  Cannot restore.")
 Q
 ;
FULLRESTORE(RETURN,CLINIC,DATETIME) ;perform a full day restore for date provided
 N CURRENTSCHEDULE,RESTOREPATTERN,FDA,SDDATE
 S SDDATE=$P(DATETIME,".")
 S CURRENTSCHEDULE=$$GET1^DIQ(44.005,SDDATE_","_CLINIC_",",1)
 I (CURRENTSCHEDULE'["CANCELLED") D RETCANPERIODS(.ERRORS,CLINIC,DATETIME) Q 
 D GETRETSTOREVALUE(.RESTOREPATTERN,CLINIC,SDDATE)
 S FDA(44.005,SDDATE_","_CLINIC_",",1)=RESTOREPATTERN
 D FILE^DIE(,"FDA") K FDA
 K ^SC(CLINIC,"ST",SDDATE,"CAN")
 D UPDATETMP(CLINIC,SDDATE,,"UC","RESTORED - DAY")
 S RETURN("Restore",1)="Restore completed successfully"
 Q
 ;
PARTIALRESTORE(ERRORS,RETURN,CLINIC,DATETIME,STARTHOUR,INCREMENT) ;perform partial day restore
 N RESTORESTART,RESTOREEND,SDATE,FDA,RESTOREDSCHEDULE,CURRENTSCHEDULE,RESTOREPATTERN,ENDPOSITION,STARTPOSITION
 S RESTORESTART=$P($$GET1^DIQ(44.05,DATETIME_","_CLINIC_",",.01,"I"),".",2)
 I RESTORESTART="" D RETCANPERIODS(.ERRORS,CLINIC,DATETIME) Q
 ;restore the sent in time period
 S RESTOREEND=$$GET1^DIQ(44.05,DATETIME_","_CLINIC_",",1,"I")
 D FORMATTIME(.RESTORESTART)
 D FORMATTIME(.RESTOREEND)
 D GETPOSITION(.STARTPOSITION,RESTORESTART,STARTHOUR,INCREMENT)
 D GETPOSITION(.ENDPOSITION,RESTOREEND,STARTHOUR,INCREMENT)
 S SDDATE=$P(DATETIME,".")
 S CURRENTSCHEDULE=$$GET1^DIQ(44.005,SDDATE_","_CLINIC_",",1)
 D GETRETSTOREVALUE(.RESTOREPATTERN,CLINIC,SDDATE)
 S RESTOREDSCHEDULE=$E(CURRENTSCHEDULE,1,STARTPOSITION-1)_$E(RESTOREPATTERN,STARTPOSITION,ENDPOSITION)_$E(CURRENTSCHEDULE,ENDPOSITION+1,80)
 S FDA(44.005,SDDATE_","_CLINIC_",",1)=RESTOREDSCHEDULE
 D FILE^DIE(,"FDA") K FDA
 S FDA(44.05,DATETIME_","_CLINIC_",",.01)="@"
 D FILE^DIE(,"FDA") K FDA
 D FILE^DIE(,"FDA") K FDA
 K ^SC(CLINIC,"S",DATETIME,"MES") ;to prevent issues with roll and scroll need to kill off the entire node.
 I RESTOREDSCHEDULE'["X" K ^SC(CLINIC,"ST",SDDATE,"CAN")
 D UPDATETMP(CLINIC,RESTORESTART,RESTOREEND,"UP","RESTORED - PARTIAL DAY")
 S RETURN("Restore",1)="Restore completed successfully"
 Q
 ;
RETCANPERIODS(ERRORS,CLINIC,DATETIME) ; if sent in time is not cancelled return time periods that are cancelled
 N NEWDATE,STARTDATE,CNT,ECNT
 S STARTDATE=$P(DATETIME,"."),NEWDATE=STARTDATE
 S CNT=1
 S ECNT=2
 D ERRLOG^SDES2JSON(.ERRORS,52,"Not a cancelled period.  Must send defined cancelled period.")
 F  S NEWDATE=$O(^SC(CLINIC,"SDCAN",NEWDATE)) Q:$P(NEWDATE,".")'=STARTDATE  D 
 . N STARTTIME,ENDTIME
 . S STARTTIME=$$GET1^DIQ(44.05,NEWDATE_","_CLINIC_",",.01,"I")
 . S ENDTIME=$$GET1^DIQ(44.05,NEWDATE_","_CLINIC_",",1,"I")
 . S ENDTIME=$E(ENDTIME,1,2)_":"_$E(ENDTIME,3,4)
 . S ERRORS("Error",2,"Restore Periods",CNT)=$$FMTISO^SDAMUTDT($$GET1^DIQ(44.05,NEWDATE_","_CLINIC_",",.01,"I"),CLINIC)
 . S ERRORS("Error",2,"Restore Periods",CNT)=ERRORS("Error",2,"Restore Periods",CNT)_"  (to restore: "_$$FMTISO^SDAMUTDT(STARTTIME,CLINIC)
 . S ERRORS("Error",2,"Restore Periods",CNT)=ERRORS("Error",2,"Restore Periods",CNT)_" to "_$$FMTISO^SDAMUTDT($P(STARTTIME,".")_"."_$TR(ENDTIME,":"),CLINIC)_")"
 . S ECNT=ECNT+1
 . S CNT=CNT+1
 Q
 ;
FORMATTIME(TIME) ;add zeros to fileman time where needed
 S TIME=$E((TIME_"0000"),1,4)
 Q
 ;
GETRETSTOREVALUE(RESTOREPATTERN,CLINIC,PATTERNDATE) ;need to define pattern
 ;if ,9 node exists, there should be an OST record.  Would want to get that record for restore.
 ;if no ',9) node exists, then get T_# record and build the front end 
 N DAYOFWEEK,SUBFILE,SDPATTERNDATE
 I $$GET1^DIQ(44.005,PATTERNDATE_","_CLINIC_",",3,"I")'="" S RESTOREPATTERN=$$GET1^DIQ(44.0002,PATTERNDATE_","_CLINIC_",",1) Q
 S DAYOFWEEK=$$DOW^XLFDT(PATTERNDATE,1)
 S SUBFILE=$S(DAYOFWEEK=0:44.06,DAYOFWEEK=1:44.07,DAYOFWEEK=2:44.08,DAYOFWEEK=3:44.09,DAYOFWEEK=4:44.008,DAYOFWEEK=5:44.009,DAYOFWEEK=6:44.0001,1:1)
 I SUBFILE=1 D ERRLOG^SDES2JSON(.ERRORS,52,"Cannot find Mastern pattern for T"_DAYOFWEEK)
 S SDPATTERNDATE=$O(^SC(CLINIC,"T"_DAYOFWEEK,PATTERNDATE))
 S RESTOREPATTERN=$P("SU^MO^TU^WE^TH^FR^SA","^",DAYOFWEEK+1)_" "_$E(PATTERNDATE,6,7)_$J("",(2*INCREMENT)-6)_$$GET1^DIQ(SUBFILE,SDPATTERNDATE_","_CLINIC_",",1,"I")
 Q
 ;
GETPOSITION(POSITION,TIME,DISPSTART,INCREMENT) ;given time returns back character string position 
 NEW MINUTES
 S MINUTES=$E(TIME,3,4)
 S POSITION=TIME\100-DISPSTART*INCREMENT+(MINUTES*INCREMENT\60)*2+(2*INCREMENT)
 Q
 ;
UPDATETMP(CLINIC,STARTDATE,ENDDATE,FUNCTION,COMMENT) ;
 D EN^SDTMPHLC(CLINIC,STARTDATE,$G(ENDDATE),FUNCTION,COMMENT)
 Q
 ;