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

SDESCLINDAILYSCH.m

Go to the documentation of this file.
SDESCLINDAILYSCH ;ALB/BLB - SDES GET CLINIC DAILY SCHEDULE ;Jan 9, 2023@18:47
 ;;5.3;Scheduling;**836,860**;Aug 13, 1993;Build 12
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
GETSCHEDULE(JSONRETURN,CLINICIEN,DATE) ;
 N ERRORS,RETURN,SCHEDULE,DOW,SUB
 ;
 ; validate
 D VALIDATEDATE(.ERRORS,.DATE,$G(CLINICIEN))
 D VALIDATECLINIC(.ERRORS,$G(CLINICIEN))
 I $D(ERRORS) M RETURN=ERRORS D BUILDJSON(.JSONRETURN,.RETURN) Q
 ;
 S DOW=$$UP^XLFSTR($$DOW^XLFDT(DATE))
 S SUB=$$SUB(.SUB,DOW)
 S DAYSCHEDULE=$$GETDAYSCHEDULE(CLINICIEN,SUB,DATE)
 I $D(ERRORS) M RETURN=ERRORS D BUILDJSON(.JSONRETURN,.RETURN) Q
 ;
 ; build slots
 D BUILD(.SCHEDULE,DAYSCHEDULE,CLINICIEN,SUB,DATE)
 I '$D(SCHEDULE) S SCHEDULE("ClinicSlot",1)=""
 M RETURN=SCHEDULE
 D BUILDJSON(.JSONRETURN,.RETURN)
 Q
 ;
BUILD(SCHEDULE,DAYSCHEDULE,CLINICIEN,SUB,DATE) ;
 N SLOTIEN,CLINICSTART,APPTLENGTH,INCREMENT,SLOTS,STARTTIME,COUNT,NEWSLOTS,TIME,STRING
 ;
 S STRING="123456789jklmnopqrstuvwxyz"
 S CLINICSTART=$$GET1^DIQ(44,CLINICIEN,1914,"I")
 S APPTLENGTH=$$GET1^DIQ(44,CLINICIEN,1912,"I")
 S INCREMENT=$$GET1^DIQ(44,CLINICIEN,1917,"I")
 ;
 I '$D(^SC(CLINICIEN,"ST",DATE,1)) D
 .D ASSEMBLE(.ERRORS,CLINICIEN,DATE,INCREMENT,CLINICSTART)
 ;
 D ARRAY^SDECUTL2(.SLOTS,DAYSCHEDULE,DATE,APPTLENGTH,CLINICSTART,INCREMENT)
 D NEWSLOTS(.NEWSLOTS,DATE,.SLOTS)
 ;
 S STARTTIME="",COUNT=0
 F  S STARTTIME=$O(NEWSLOTS(DATE,STARTTIME)) Q:STARTTIME=""  D
 .S COUNT=COUNT+1
 .S TIME=STARTTIME
 .;
 .I $$GET1^DIQ(44,CLINICIEN,1912,"I")#60'=0 D
 ..I $L($G(TIME))=3 S TIME="0"_TIME
 ..I $L($G(TIME))=2 S TIME="00"_TIME
 ..I $L($G(TIME))=1 S TIME="000"_TIME
 .;
 .I $$GET1^DIQ(44,CLINICIEN,1912,"I")#60=0 D
 ..I $L(TIME)=1 D
 ...S TIME="0"_TIME_"00"
 ..;
 ..I $L(TIME)=2 D
 ...S TIME=TIME_"00"
 .;
 .S SCHEDULE("ClinicSlot",COUNT,"Date")=$$FMTISO^SDAMUTDT(DATE)
 .S SCHEDULE("ClinicSlot",COUNT,"StartTime")=TIME
 .I $G(NEWSLOTS(DATE,STARTTIME))'?.A,+$G(NEWSLOTS(DATE,STARTTIME))=0 S SCHEDULE("ClinicSlot",COUNT,"OpenSlots")=0 Q
 .S SCHEDULE("ClinicSlot",COUNT,"OpenSlots")=$S($G(NEWSLOTS(DATE,STARTTIME))'?.N:$F(STRING,$G(NEWSLOTS(DATE,STARTTIME)))-1,1:+$G(NEWSLOTS(DATE,STARTTIME)))
 Q
 ;
NEWSLOTS(NEWSLOT,CDATE,SLOTS) ;
 N SLOT,VALUE,NEWTIMESLOT
 S SLOT="" F  S SLOT=$O(SLOTS(CDATE,SLOT)) Q:SLOT=""  D
 .S NEWTIMESLOT=+SLOT Q:SLOT="" 
 .S VALUE=$G(SLOTS(CDATE,SLOT))
 .S NEWSLOT(CDATE,NEWTIMESLOT)=VALUE
 Q
 ;
ASSEMBLE(ERRORS,CLINICIEN,DATE,INCREMENT,CLINSTART) ;
 N DOW,MASTERPATTERN,MPATTERNSLOTS,X,Y,FILENOFDA,FDAIEN,FERR,FILENO
 S X=DATE
 D DOW^SDM0 S DOW=Y
 S MASTERPATTERN=+$O(^SC(CLINICIEN,"T"_DOW,DATE))
 S FILENO=$SELECT(DOW=0:44.06,DOW=1:44.07,DOW=2:44.08,DOW=3:44.09,DOW=4:44.008,DOW=5:44.009,DOW=6:44.0001,1:"")
 S MPATTERNSLOTS=$$GET1^DIQ(FILENO,MASTERPATTERN_","_CLINICIEN_",",1)
 S FDA(44.005,"+1,"_CLINICIEN_",",.01)=DATE
 S FDA(44.005,"+1,"_CLINICIEN_",",1)=$P("SU^MO^TU^WE^TH^FR^SA",U,DOW+1)_" "_$E(DATE,6,7)_$J("",INCREMENT+INCREMENT-6)_MPATTERNSLOTS
 S FDAIEN(1)=DATE
 D UPDATE^DIE(,"FDA","FDAIEN","FERR") K FDA,FDAIEN
 Q
 ;
GETDAYSCHEDULE(CLINICIEN,SUB,DATE) ;
 S DAYSCHEDULE=$G(^SC(CLINICIEN,SUB,9999999,1))
 I DAYSCHEDULE["CANCELLED" D ERRLOG^SDESJSON(.ERRORS,248) Q ""
 ;
 I $D(^SC(CLINICIEN,"OST",DATE,1)) D
 .S DAYSCHEDULE=$E($G(^SC(CLINICIEN,"OST",DATE,1)),8,$L($G(^SC(CLINICIEN,"OST",DATE,1))))
 ;
 I DAYSCHEDULE'["[" D ERRLOG^SDESJSON(.ERRORS,249) Q "" ; doesnt meet today
 Q DAYSCHEDULE
 ;
VALIDATEDATE(ERRORS,DATE,CLINICIEN) ;
 I $G(DATE)="" D ERRLOG^SDESJSON(.ERRORS,45) Q
 S DATE=$$ISOTFM^SDAMUTDT(DATE,CLINICIEN)
 I $G(DATE)=-1 D ERRLOG^SDESJSON(.ERRORS,46) Q
 I $G(DATE)&(DATE<DT) D ERRLOG^SDESJSON(.ERRORS,71)
 Q DATE
 ;
VALIDATECLINIC(ERRORS,CLINICIEN) ;
 I CLINICIEN="" D ERRLOG^SDESJSON(.ERRORS,18) Q
 I CLINICIEN'="",'$D(^SC(CLINICIEN,0)) D ERRLOG^SDESJSON(.ERRORS,19)
 Q
 ;
SUB(SUB,DOW) ;
 S SUB="T"_$S(DOW="SUNDAY":0,DOW="MONDAY":1,DOW="TUESDAY":2,DOW="WEDNESDAY":3,DOW="THURSDAY":4,DOW="FRIDAY":5,DOW="SATURDAY":6,1:"")
 Q SUB
 ;
BUILDJSON(JSONRETURN,RETURN) ;
 N JSONERROR
 D ENCODE^XLFJSON("RETURN","JSONRETURN","JSONERROR")
 Q
 ;