SDES2CRTCLNAVAIL ;ALB/BLB - SDES2 SET CLINIC AVAILABILITY Aug, 14 2024@12:09
;;5.3;Scheduling;**890**;Aug 13, 1993;Build 5
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
CREATE(JSON,SDCONTEXT,AVAILABILITY) ;
N ERRORS,RETURNAVAIL,CLINICIEN,CLINICSTARTHOUR,NUMBEROFENTRIES,INPUTS,INDEFINITEUNTIL,SDDISPPERHR,SDCLINSTARTHR,SLOTSTOCANCEL
;
M INPUTS=AVAILABILITY
D VALIDATE(.ERRORS,.AVAILABILITY,.CLINICIEN,.CLINICSTARTHOUR,.NUMBEROFENTRIES)
I $D(ERRORS) S ERRORS("ClinicAvailability")="" D BUILDJSON^SDES2JSON(.JSON,.ERRORS) Q
;
D CREATEAVAIL(.AVAILABILITY,.SDCONTEXT,.SLOTSTOCANCEL,CLINICIEN,CLINICSTARTHOUR,$$GET1^DIQ(44,CLINICIEN,1917,"I"),$$GET1^DIQ(44,CLINICIEN,1914,"I"),NUMBEROFENTRIES,.INPUTS,.INDEFINITEUNTIL,.RETURNAVAIL,.ERRORS)
;
I $L($G(SLOTSTOCANCEL("CancelledSlots",1,"BeginTime"))) D
.D RECANCELSLOTS(.SLOTSTOCANCEL,CLINICIEN,.SDCONTEXT) K SLOTSTOCANCEL
;
D BUILDJSON^SDES2JSON(.JSON,.RETURNAVAIL)
Q
;
CREATEAVAIL(AVAILABILITY,SDCONTEXT,SLOTSTOCANCEL,CLINICIEN,CLINICSTARTHOUR,SDDISPPERHR,SDCLINSTARTHR,NUMBEROFENTRIES,INPUTS,INDEFINITEUNTIL,RETURNAVAIL,ERRORS) ;
N COUNT,ENDDATE,DATES,TIMES,SCHEDULEDDAYS,DATENEXTTIMESLOT,CANSLOTSENDDATE,DONE,SDRETURN
;
S COUNT=0,DONE=0
F D Q:COUNT=NUMBEROFENTRIES!(DONE=1)
.S COUNT=COUNT+1
.I $G(SCHEDULEDDAYS)[$P($G(INPUTS("START DATE TIME",COUNT)),"T") Q
.;
.D CREATEDATESTIMES(.DATES,.TIMES,.INPUTS,$P($G(INPUTS("START DATE TIME",COUNT)),"T"),NUMBEROFENTRIES,.SLOTSTOCANCEL)
.I $D(SLOTSTOCANCEL("Error")) M RETURNAVAIL=SLOTSTOCANCEL S DONE=1 Q
.D CREATE^SDES2UTIL1(CLINICIEN,CLINICSTARTHOUR,$$GET1^DIQ(44,CLINICIEN,1912,"I"),$$DOW^XLFDT($P($G(AVAILABILITY("START DATE TIME",COUNT)),"."),1),.INDEFINITEUNTIL,.DATES,.TIMES,SDDISPPERHR,.SDRETURN,.ERRORS) K DATES,TIMES
.;
.S RETURNAVAIL("ClinicAvailability",COUNT,"Pattern")="Pattern Filed"
.I $G(INDEFINITEUNTIL) D
..S RETURNAVAIL("ClinicAvailability",COUNT,"DateIndefiniteScheduleEnds")=INDEFINITEUNTIL K INDEFINITEUNTIL
.S SCHEDULEDDAYS=$G(SCHEDULEDDAYS)_$P($G(INPUTS("START DATE TIME",COUNT)),"T")_U
.;
Q
;
CREATEDATESTIMES(DATES,TIMES,INPUTS,AVAILABILITYDATE,NUMBEROFENTRIES,SLOTSTOCANCEL) ;
N COUNT,SUBSCRIPT,STARTDATE,STARTTIME,ENDTIME,SLOTS,LASTTIMESLOTDATE,DONE
;
S COUNT=0
F D Q:COUNT=NUMBEROFENTRIES
.S COUNT=COUNT+1
.I $P($G(INPUTS("START DATE TIME",COUNT)),"T")'=AVAILABILITYDATE Q
.;
.I $G(INPUTS("NUMBER OF SLOTS",COUNT))="@" D Q
..S DATES=$G(INPUTS("START DATE TIME",COUNT))="",DATES($$ISOTFM^SDAMUTDT(DATES))="",TIMES=""
.;
.S LASTTIMESLOTDATE=0,LASTTIMESLOTDATE=$O(DATES(LASTTIMESLOTDATE))
.I $G(LASTTIMESLOTDATE)=$$ISOTFM^SDAMUTDT($P($G(INPUTS("START DATE TIME",COUNT)),"T"))!('$G(LASTTIMESLOTDATE)) D
..S DATES=$$ISOTFM^SDAMUTDT($P($G(INPUTS("START DATE TIME",COUNT)),"T")),DATES(DATES)=""
..S TIMES=$G(TIMES)_$P($G(INPUTS("START DATE TIME",COUNT)),"T",2)_"-"_$P($G(INPUTS("END DATE TIME",COUNT)),"T",2)_";"
..S TIMES($P($G(INPUTS("START DATE TIME",COUNT)),"T",2))=$P($G(INPUTS("START DATE TIME",COUNT)),"T",2)_"-"_$P($G(INPUTS("END DATE TIME",COUNT)),"T",2)_U_$G(INPUTS("NUMBER OF SLOTS",COUNT))
.;
.I $G(INPUTS("INDEFINITE",COUNT)),'$D(DATES(9999999)) D
..S DATES=$G(DATES)_";9999999",DATES(9999999)=""
.;
.S DATENEXTTIMESLOT=$$ISOTFM^SDAMUTDT($P($G(INPUTS("START DATE TIME",COUNT)),"T"))
.S CANSLOTSENDDATE=$S($G(AVAILABILITY("INDEFINITE",COUNT)):$$FMTISO^SDAMUTDT($$GETLASTINDEFDATE(CLINICIEN,DATENEXTTIMESLOT,$$GET1^DIQ(44,CLINICIEN,2002))),1:DATENEXTTIMESLOT)
.I $G(INPUTS("INDEFINITE",COUNT)) D Q
..S DONE=0
..F D Q:DATENEXTTIMESLOT=$$ISOTFM^SDAMUTDT(CANSLOTSENDDATE)
...D GETCANSLOTS(CLINICIEN,.SLOTSTOCANCEL,$G(AVAILABILITY("INDEFINITE",COUNT)),CANSLOTSENDDATE,COUNT,$$FMTISO^SDAMUTDT(DATENEXTTIMESLOT),.INPUTS,.SDCONTEXT)
...S DATENEXTTIMESLOT=$$FMADD^XLFDT(DATENEXTTIMESLOT,7)
.;
.D GETCANSLOTS(CLINICIEN,.SLOTSTOCANCEL,$G(AVAILABILITY("INDEFINITE",COUNT)),CANSLOTSENDDATE,COUNT,$$FMTISO^SDAMUTDT(DATENEXTTIMESLOT),.INPUTS,.SDCONTEXT)
;
S TIMES=$E($G(TIMES),1,$L($G(TIMES))-1)
Q
;
GETLASTINDEFDATE(CLINICIEN,DATE,MAXBOOKINGDAYS) ;
N FOUND,OSTDATE
;
S OSTDATE=DATE,FOUND=0
F D Q:FOUND!(OSTDATE>$$FMADD^XLFDT(DT,MAXBOOKINGDAYS))
.S OSTDATE=$$FMADD^XLFDT(OSTDATE,7)
.I $D(^SC(CLINICIEN,"OST",OSTDATE)) S FOUND=1
Q $G(OSTDATE)
;
RECANCELSLOTS(SLOTSTOCANCEL,CLINICIEN,SDCONTEXT) ;
N COUNT,CANCEL,CANCELRETURN
;
S COUNT=0
F S COUNT=$O(SLOTSTOCANCEL("CancelledSlots",COUNT)) Q:'COUNT D
.S CANCEL("CLINIC IEN")=CLINICIEN
.S CANCEL("FULL PARTIAL FLAG")=$S($G(SLOTSTOCANCEL("CancelledSlots",COUNT,"BeginTime"))["T":"P",1:"F")
.S CANCEL("START DATE TIME")=$G(SLOTSTOCANCEL("CancelledSlots",COUNT,"BeginTime"))
.S CANCEL("END DATE TIME")=$G(SLOTSTOCANCEL("CancelledSlots",COUNT,"EndTime"))
.D CANCEL^SDES2CANCLNAVAIL(.CANCELRETURN,.SDCONTEXT,.CANCEL)
Q
;
GETCANSLOTS(CLINICIEN,SLOTSTOCANCEL,INDEFINITE,ENDDATE,COUNT,SCHEDULEDATE,INPUTS,SDCONTEXT) ;
N CANSLOTS,JSON,SLOTS,NUM,SLOTNUM
;
I $$GET1^DIQ(44.005,$$ISOTFM^SDAMUTDT(SCHEDULEDATE)_","_CLINICIEN_",",1,"I")["CANCELLED" D Q
.S SLOTSTOCANCEL("CancelledSlots",1,"BeginTime")=SCHEDULEDATE
.S SLOTSTOCANCEL("CancelledSlots",1,"EndTime")=SCHEDULEDATE
;
S CANSLOTS("CLINICIEN")=CLINICIEN
S CANSLOTS("SDESSTART")=SCHEDULEDATE_"T"_"0001"_$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT(SCHEDULEDATE),CLINICIEN)
S CANSLOTS("SDESENDDATE")=SCHEDULEDATE_"T"_2359_$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT(SCHEDULEDATE),CLINICIEN)
D GETCANCSLOTS^SDES2GETCANSLOTS(.JSON,.SDCONTEXT,.CANSLOTS) K CANSLOTS
D DECODE^XLFJSON("JSON","SLOTS")
;
I $D(SLOTSTOCANCEL("CancelledSlots",1,"BeginTime")),$L($G(SLOTS("CancelledSlots",1,"BeginTime"))) D Q
.S NUM="",NUM=$O(SLOTSTOCANCEL("CancelledSlots",NUM),-1)
.S SLOTNUM=0
.F S SLOTNUM=$O(SLOTS("CancelledSlots",SLOTNUM)) Q:'SLOTNUM D
..S NUM=NUM+1
..S SLOTSTOCANCEL("CancelledSlots",NUM,"BeginTime")=$G(SLOTS("CancelledSlots",SLOTNUM,"BeginTime"))
..S SLOTSTOCANCEL("CancelledSlots",NUM,"EndTime")=$G(SLOTS("CancelledSlots",SLOTNUM,"EndTime"))
;
I $D(SLOTS("CancelledSlots",1,"BeginTime")) D
.M SLOTSTOCANCEL=SLOTS
;
S SCHEDULEDATE=$$FMADD^XLFDT(SCHEDULEDATE,7) K SLOTS
Q
;
VALIDATE(ERRORS,AVAILABILITY,CLINICIEN,CLINICSTARTHOUR,NUMBEROFENTRIES) ;
N FDATA,VAL
;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
D VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,$G(AVAILABILITY("CLINIC IEN")),1,,18,19)
I $D(ERRORS) Q
;
S CLINICIEN=$G(AVAILABILITY("CLINIC IEN"))
S CLINICSTARTHOUR=$$GET1^DIQ(44,CLINICIEN,1914,"I")
;
S NUMBEROFENTRIES=$O(AVAILABILITY("NUMBER OF SLOTS",""),-1)
I $O(AVAILABILITY("START DATE TIME",""),-1)'=NUMBEROFENTRIES!($O(AVAILABILITY("END DATE TIME",""),-1)'=NUMBEROFENTRIES) D ERRLOG^SDES2JSON(.ERRORS,580)
;
D VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,CLINICIEN,1,,18,19)
D VALAPPTLENGTH(.ERRORS,$$GET1^DIQ(44,CLINICIEN,1912,"I"),CLINICIEN)
D VALSTARTHOUR^SDES2VAL44(.ERRORS,.CLINICSTARTHOUR)
D VALIDATESLOTS(.ERRORS,.AVAILABILITY)
D VALIDATEDATETIME(.ERRORS,CLINICIEN,.AVAILABILITY,NUMBEROFENTRIES)
D VALIDATEINDEF(.ERRORS,.AVAILABILITY)
Q
;
VALIDATEINDEF(ERRORS,AVAILABILITY) ;
S COUNT=0
F S COUNT=$O(AVAILABILITY("INDEFINITE",COUNT)) Q:'COUNT!($D(ERRORS)) D
.I $G(AVAILABILITY("INDEFINITE",COUNT))="" D ERRLOG^SDES2JSON(.ERRORS,592) Q
.I $G(AVAILABILITY("INDEFINITE",COUNT))'=1,$G(AVAILABILITY("INDEFINITE",COUNT))'=0 D ERRLOG^SDES2JSON(.ERRORS,591) Q
Q
;
VALAPPTLENGTH(ERRORS,LENGTH,CLINICIEN) ;
I LENGTH="" D ERRLOG^SDES2JSON(.ERRORS,115) Q
I ((LENGTH<10)!(LENGTH>240)) D ERRLOG^SDES2JSON(.ERRORS,116) Q
I (LENGTH#10'=0),(LENGTH#15'=0) D ERRLOG^SDES2JSON(.ERRORS,116) Q
Q
;
VALIDATESLOTS(ERRORS,AVAILABILITY) ;
N COUNT
;
S COUNT=0
F S COUNT=$O(AVAILABILITY("NUMBER OF SLOTS",COUNT)) Q:'COUNT D
.I $G(AVAILABILITY("NUMBER OF SLOTS",COUNT))="@" Q
.I $G(AVAILABILITY("NUMBER OF SLOTS",COUNT))<1!($G(AVAILABILITY("NUMBER OF SLOTS",COUNT))>26) D ERRLOG^SDES2JSON(.ERRORS,125)
Q
;
VALIDATEDATETIME(ERRORS,CLINICIEN,AVAILABILITY,NUMBEROFENTRIES) ;
N COUNT,TIMEZONEOFFSET,TIME
;
F COUNT=1:1:NUMBEROFENTRIES D Q:$D(ERRORS)
.I $G(AVAILABILITY("NUMBER OF SLOTS",COUNT))="@" Q
.;
.I $L($P($P($G(AVAILABILITY("START DATE TIME",COUNT)),"T",2),"-",2))!($L($P($P($G(AVAILABILITY("END DATE TIME",COUNT)),"T",2),"-",2))) D ERRLOG^SDES2JSON(.ERRORS,590)
.S TIMEZONEOFFSET=$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT($P($G(AVAILABILITY("START DATE TIME",COUNT)),"T")),CLINICIEN)
.S AVAILABILITY("START DATE TIME",COUNT)=$G(AVAILABILITY("START DATE TIME",COUNT))_TIMEZONEOFFSET
.S AVAILABILITY("END DATE TIME",COUNT)=$G(AVAILABILITY("END DATE TIME",COUNT))_TIMEZONEOFFSET
.;
.D VALISODATERANGE^SDES2VALISODTTM(.ERRORS,$G(AVAILABILITY("START DATE TIME",COUNT)),$G(AVAILABILITY("END DATE TIME",COUNT)),1,CLINICIEN)
.S AVAILABILITY("START DATE TIME",COUNT)=$$ISOTFM^SDAMUTDT($G(AVAILABILITY("START DATE TIME",COUNT)),CLINICIEN)
.S AVAILABILITY("END DATE TIME",COUNT)=$$ISOTFM^SDAMUTDT($G(AVAILABILITY("END DATE TIME",COUNT)),CLINICIEN)
.I $G(AVAILABILITY("START DATE TIME",COUNT))<DT D ERRLOG^SDES2JSON(.ERRORS,71)
.;
.I $$GET1^DIQ(44,CLINICIEN,1914,"I")*100>+$E($P($G(AVAILABILITY("START DATE TIME",COUNT)),".",2)_"0000",1,4) D ERRLOG^SDES2JSON(.ERRORS,581)
.I '$$CHECKDURATION^SDES2UTIL1($G(AVAILABILITY("START DATE TIME",COUNT)),$G(AVAILABILITY("END DATE TIME",COUNT)),$$GET1^DIQ(44,CLINICIEN,1912,"I")) D ERRLOG^SDES2JSON(.ERRORS,582)
.I $$INACTIVE^SDESUTIL(CLINICIEN,$P($G(AVAILABILITY("START DATE TIME",COUNT)),".")) D ERRLOG^SDES2JSON(.ERRORS,583)
.I $$GET1^DIQ(44,CLINICIEN,1918.5,"I")'="Y",$D(^HOLIDAY($P($G(AVAILABILITY("START DATE TIME",COUNT)),"."),0)) D ERRLOG^SDES2JSON(.ERRORS,465)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2CRTCLNAVAIL 9781 printed Dec 13, 2024@02:53:38 Page 2
SDES2CRTCLNAVAIL ;ALB/BLB - SDES2 SET CLINIC AVAILABILITY Aug, 14 2024@12:09
+1 ;;5.3;Scheduling;**890**;Aug 13, 1993;Build 5
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
CREATE(JSON,SDCONTEXT,AVAILABILITY) ;
+1 NEW ERRORS,RETURNAVAIL,CLINICIEN,CLINICSTARTHOUR,NUMBEROFENTRIES,INPUTS,INDEFINITEUNTIL,SDDISPPERHR,SDCLINSTARTHR,SLOTSTOCANCEL
+2 ;
+3 MERGE INPUTS=AVAILABILITY
+4 DO VALIDATE(.ERRORS,.AVAILABILITY,.CLINICIEN,.CLINICSTARTHOUR,.NUMBEROFENTRIES)
+5 IF $DATA(ERRORS)
SET ERRORS("ClinicAvailability")=""
DO BUILDJSON^SDES2JSON(.JSON,.ERRORS)
QUIT
+6 ;
+7 DO CREATEAVAIL(.AVAILABILITY,.SDCONTEXT,.SLOTSTOCANCEL,CLINICIEN,CLINICSTARTHOUR,$$GET1^DIQ(44,CLINICIEN,1917,"I"),$$GET1^DIQ(44,CLINICIEN,1914,"I"),NUMBEROFENTRIES,.INPUTS,.INDEFINITEUNTIL,.RETURNAVAIL,.ERRORS)
+8 ;
+9 IF $LENGTH($GET(SLOTSTOCANCEL("CancelledSlots",1,"BeginTime")))
Begin DoDot:1
+10 DO RECANCELSLOTS(.SLOTSTOCANCEL,CLINICIEN,.SDCONTEXT)
KILL SLOTSTOCANCEL
End DoDot:1
+11 ;
+12 DO BUILDJSON^SDES2JSON(.JSON,.RETURNAVAIL)
+13 QUIT
+14 ;
CREATEAVAIL(AVAILABILITY,SDCONTEXT,SLOTSTOCANCEL,CLINICIEN,CLINICSTARTHOUR,SDDISPPERHR,SDCLINSTARTHR,NUMBEROFENTRIES,INPUTS,INDEFINITEUNTIL,RETURNAVAIL,ERRORS) ;
+1 NEW COUNT,ENDDATE,DATES,TIMES,SCHEDULEDDAYS,DATENEXTTIMESLOT,CANSLOTSENDDATE,DONE,SDRETURN
+2 ;
+3 SET COUNT=0
SET DONE=0
+4 FOR
Begin DoDot:1
+5 SET COUNT=COUNT+1
+6 IF $GET(SCHEDULEDDAYS)[$PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T")
QUIT
+7 ;
+8 DO CREATEDATESTIMES(.DATES,.TIMES,.INPUTS,$PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T"),NUMBEROFENTRIES,.SLOTSTOCANCEL)
+9 IF $DATA(SLOTSTOCANCEL("Error"))
MERGE RETURNAVAIL=SLOTSTOCANCEL
SET DONE=1
QUIT
+10 DO CREATE^SDES2UTIL1(CLINICIEN,CLINICSTARTHOUR,$$GET1^DIQ(44,CLINICIEN,1912,"I"),$$DOW^XLFDT($PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),"."),1),.INDEFINITEUNTIL,.DATES,.TIMES,SDDISPPERHR,.SDRETURN,.ERRORS)
KILL DATES,TIMES
+11 ;
+12 SET RETURNAVAIL("ClinicAvailability",COUNT,"Pattern")="Pattern Filed"
+13 IF $GET(INDEFINITEUNTIL)
Begin DoDot:2
+14 SET RETURNAVAIL("ClinicAvailability",COUNT,"DateIndefiniteScheduleEnds")=INDEFINITEUNTIL
KILL INDEFINITEUNTIL
End DoDot:2
+15 SET SCHEDULEDDAYS=$GET(SCHEDULEDDAYS)_$PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T")_U
+16 ;
End DoDot:1
if COUNT=NUMBEROFENTRIES!(DONE=1)
QUIT
+17 QUIT
+18 ;
CREATEDATESTIMES(DATES,TIMES,INPUTS,AVAILABILITYDATE,NUMBEROFENTRIES,SLOTSTOCANCEL) ;
+1 NEW COUNT,SUBSCRIPT,STARTDATE,STARTTIME,ENDTIME,SLOTS,LASTTIMESLOTDATE,DONE
+2 ;
+3 SET COUNT=0
+4 FOR
Begin DoDot:1
+5 SET COUNT=COUNT+1
+6 IF $PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T")'=AVAILABILITYDATE
QUIT
+7 ;
+8 IF $GET(INPUTS("NUMBER OF SLOTS",COUNT))="@"
Begin DoDot:2
+9 SET DATES=$GET(INPUTS("START DATE TIME",COUNT))=""
SET DATES($$ISOTFM^SDAMUTDT(DATES))=""
SET TIMES=""
End DoDot:2
QUIT
+10 ;
+11 SET LASTTIMESLOTDATE=0
SET LASTTIMESLOTDATE=$ORDER(DATES(LASTTIMESLOTDATE))
+12 IF $GET(LASTTIMESLOTDATE)=$$ISOTFM^SDAMUTDT($PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T"))!('$GET(LASTTIMESLOTDATE))
Begin DoDot:2
+13 SET DATES=$$ISOTFM^SDAMUTDT($PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T"))
SET DATES(DATES)=""
+14 SET TIMES=$GET(TIMES)_$PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T",2)_"-"_$PIECE($GET(INPUTS("END DATE TIME",COUNT)),"T",2)_";"
+15 SET TIMES($PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T",2))=$PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T",2)_"-"_$PIECE($GET(INPUTS("END DATE TIME",COUNT)),"T",2)_U_$GET(INPUTS("NUMBER OF SLOTS",COUNT))
End DoDot:2
+16 ;
+17 IF $GET(INPUTS("INDEFINITE",COUNT))
IF '$DATA(DATES(9999999))
Begin DoDot:2
+18 SET DATES=$GET(DATES)_";9999999"
SET DATES(9999999)=""
End DoDot:2
+19 ;
+20 SET DATENEXTTIMESLOT=$$ISOTFM^SDAMUTDT($PIECE($GET(INPUTS("START DATE TIME",COUNT)),"T"))
+21 SET CANSLOTSENDDATE=$SELECT($GET(AVAILABILITY("INDEFINITE",COUNT)):$$FMTISO^SDAMUTDT($$GETLASTINDEFDATE(CLINICIEN,DATENEXTTIMESLOT,$$GET1^DIQ(44,CLINICIEN,2002))),1:DATENEXTTIMESLOT)
+22 IF $GET(INPUTS("INDEFINITE",COUNT))
Begin DoDot:2
+23 SET DONE=0
+24 FOR
Begin DoDot:3
+25 DO GETCANSLOTS(CLINICIEN,.SLOTSTOCANCEL,$GET(AVAILABILITY("INDEFINITE",COUNT)),CANSLOTSENDDATE,COUNT,$$FMTISO^SDAMUTDT(DATENEXTTIMESLOT),.INPUTS,.SDCONTEXT)
+26 SET DATENEXTTIMESLOT=$$FMADD^XLFDT(DATENEXTTIMESLOT,7)
End DoDot:3
if DATENEXTTIMESLOT=$$ISOTFM^SDAMUTDT(CANSLOTSENDDATE)
QUIT
End DoDot:2
QUIT
+27 ;
+28 DO GETCANSLOTS(CLINICIEN,.SLOTSTOCANCEL,$GET(AVAILABILITY("INDEFINITE",COUNT)),CANSLOTSENDDATE,COUNT,$$FMTISO^SDAMUTDT(DATENEXTTIMESLOT),.INPUTS,.SDCONTEXT)
End DoDot:1
if COUNT=NUMBEROFENTRIES
QUIT
+29 ;
+30 SET TIMES=$EXTRACT($GET(TIMES),1,$LENGTH($GET(TIMES))-1)
+31 QUIT
+32 ;
GETLASTINDEFDATE(CLINICIEN,DATE,MAXBOOKINGDAYS) ;
+1 NEW FOUND,OSTDATE
+2 ;
+3 SET OSTDATE=DATE
SET FOUND=0
+4 FOR
Begin DoDot:1
+5 SET OSTDATE=$$FMADD^XLFDT(OSTDATE,7)
+6 IF $DATA(^SC(CLINICIEN,"OST",OSTDATE))
SET FOUND=1
End DoDot:1
if FOUND!(OSTDATE>$$FMADD^XLFDT(DT,MAXBOOKINGDAYS))
QUIT
+7 QUIT $GET(OSTDATE)
+8 ;
RECANCELSLOTS(SLOTSTOCANCEL,CLINICIEN,SDCONTEXT) ;
+1 NEW COUNT,CANCEL,CANCELRETURN
+2 ;
+3 SET COUNT=0
+4 FOR
SET COUNT=$ORDER(SLOTSTOCANCEL("CancelledSlots",COUNT))
if 'COUNT
QUIT
Begin DoDot:1
+5 SET CANCEL("CLINIC IEN")=CLINICIEN
+6 SET CANCEL("FULL PARTIAL FLAG")=$SELECT($GET(SLOTSTOCANCEL("CancelledSlots",COUNT,"BeginTime"))["T":"P",1:"F")
+7 SET CANCEL("START DATE TIME")=$GET(SLOTSTOCANCEL("CancelledSlots",COUNT,"BeginTime"))
+8 SET CANCEL("END DATE TIME")=$GET(SLOTSTOCANCEL("CancelledSlots",COUNT,"EndTime"))
+9 DO CANCEL^SDES2CANCLNAVAIL(.CANCELRETURN,.SDCONTEXT,.CANCEL)
End DoDot:1
+10 QUIT
+11 ;
GETCANSLOTS(CLINICIEN,SLOTSTOCANCEL,INDEFINITE,ENDDATE,COUNT,SCHEDULEDATE,INPUTS,SDCONTEXT) ;
+1 NEW CANSLOTS,JSON,SLOTS,NUM,SLOTNUM
+2 ;
+3 IF $$GET1^DIQ(44.005,$$ISOTFM^SDAMUTDT(SCHEDULEDATE)_","_CLINICIEN_",",1,"I")["CANCELLED"
Begin DoDot:1
+4 SET SLOTSTOCANCEL("CancelledSlots",1,"BeginTime")=SCHEDULEDATE
+5 SET SLOTSTOCANCEL("CancelledSlots",1,"EndTime")=SCHEDULEDATE
End DoDot:1
QUIT
+6 ;
+7 SET CANSLOTS("CLINICIEN")=CLINICIEN
+8 SET CANSLOTS("SDESSTART")=SCHEDULEDATE_"T"_"0001"_$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT(SCHEDULEDATE),CLINICIEN)
+9 SET CANSLOTS("SDESENDDATE")=SCHEDULEDATE_"T"_2359_$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT(SCHEDULEDATE),CLINICIEN)
+10 DO GETCANCSLOTS^SDES2GETCANSLOTS(.JSON,.SDCONTEXT,.CANSLOTS)
KILL CANSLOTS
+11 DO DECODE^XLFJSON("JSON","SLOTS")
+12 ;
+13 IF $DATA(SLOTSTOCANCEL("CancelledSlots",1,"BeginTime"))
IF $LENGTH($GET(SLOTS("CancelledSlots",1,"BeginTime")))
Begin DoDot:1
+14 SET NUM=""
SET NUM=$ORDER(SLOTSTOCANCEL("CancelledSlots",NUM),-1)
+15 SET SLOTNUM=0
+16 FOR
SET SLOTNUM=$ORDER(SLOTS("CancelledSlots",SLOTNUM))
if 'SLOTNUM
QUIT
Begin DoDot:2
+17 SET NUM=NUM+1
+18 SET SLOTSTOCANCEL("CancelledSlots",NUM,"BeginTime")=$GET(SLOTS("CancelledSlots",SLOTNUM,"BeginTime"))
+19 SET SLOTSTOCANCEL("CancelledSlots",NUM,"EndTime")=$GET(SLOTS("CancelledSlots",SLOTNUM,"EndTime"))
End DoDot:2
End DoDot:1
QUIT
+20 ;
+21 IF $DATA(SLOTS("CancelledSlots",1,"BeginTime"))
Begin DoDot:1
+22 MERGE SLOTSTOCANCEL=SLOTS
End DoDot:1
+23 ;
+24 SET SCHEDULEDATE=$$FMADD^XLFDT(SCHEDULEDATE,7)
KILL SLOTS
+25 QUIT
+26 ;
VALIDATE(ERRORS,AVAILABILITY,CLINICIEN,CLINICSTARTHOUR,NUMBEROFENTRIES) ;
+1 NEW FDATA,VAL
+2 ;
+3 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+4 DO VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,$GET(AVAILABILITY("CLINIC IEN")),1,,18,19)
+5 IF $DATA(ERRORS)
QUIT
+6 ;
+7 SET CLINICIEN=$GET(AVAILABILITY("CLINIC IEN"))
+8 SET CLINICSTARTHOUR=$$GET1^DIQ(44,CLINICIEN,1914,"I")
+9 ;
+10 SET NUMBEROFENTRIES=$ORDER(AVAILABILITY("NUMBER OF SLOTS",""),-1)
+11 IF $ORDER(AVAILABILITY("START DATE TIME",""),-1)'=NUMBEROFENTRIES!($ORDER(AVAILABILITY("END DATE TIME",""),-1)'=NUMBEROFENTRIES)
DO ERRLOG^SDES2JSON(.ERRORS,580)
+12 ;
+13 DO VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,CLINICIEN,1,,18,19)
+14 DO VALAPPTLENGTH(.ERRORS,$$GET1^DIQ(44,CLINICIEN,1912,"I"),CLINICIEN)
+15 DO VALSTARTHOUR^SDES2VAL44(.ERRORS,.CLINICSTARTHOUR)
+16 DO VALIDATESLOTS(.ERRORS,.AVAILABILITY)
+17 DO VALIDATEDATETIME(.ERRORS,CLINICIEN,.AVAILABILITY,NUMBEROFENTRIES)
+18 DO VALIDATEINDEF(.ERRORS,.AVAILABILITY)
+19 QUIT
+20 ;
VALIDATEINDEF(ERRORS,AVAILABILITY) ;
+1 SET COUNT=0
+2 FOR
SET COUNT=$ORDER(AVAILABILITY("INDEFINITE",COUNT))
if 'COUNT!($DATA(ERRORS))
QUIT
Begin DoDot:1
+3 IF $GET(AVAILABILITY("INDEFINITE",COUNT))=""
DO ERRLOG^SDES2JSON(.ERRORS,592)
QUIT
+4 IF $GET(AVAILABILITY("INDEFINITE",COUNT))'=1
IF $GET(AVAILABILITY("INDEFINITE",COUNT))'=0
DO ERRLOG^SDES2JSON(.ERRORS,591)
QUIT
End DoDot:1
+5 QUIT
+6 ;
VALAPPTLENGTH(ERRORS,LENGTH,CLINICIEN) ;
+1 IF LENGTH=""
DO ERRLOG^SDES2JSON(.ERRORS,115)
QUIT
+2 IF ((LENGTH<10)!(LENGTH>240))
DO ERRLOG^SDES2JSON(.ERRORS,116)
QUIT
+3 IF (LENGTH#10'=0)
IF (LENGTH#15'=0)
DO ERRLOG^SDES2JSON(.ERRORS,116)
QUIT
+4 QUIT
+5 ;
VALIDATESLOTS(ERRORS,AVAILABILITY) ;
+1 NEW COUNT
+2 ;
+3 SET COUNT=0
+4 FOR
SET COUNT=$ORDER(AVAILABILITY("NUMBER OF SLOTS",COUNT))
if 'COUNT
QUIT
Begin DoDot:1
+5 IF $GET(AVAILABILITY("NUMBER OF SLOTS",COUNT))="@"
QUIT
+6 IF $GET(AVAILABILITY("NUMBER OF SLOTS",COUNT))<1!($GET(AVAILABILITY("NUMBER OF SLOTS",COUNT))>26)
DO ERRLOG^SDES2JSON(.ERRORS,125)
End DoDot:1
+7 QUIT
+8 ;
VALIDATEDATETIME(ERRORS,CLINICIEN,AVAILABILITY,NUMBEROFENTRIES) ;
+1 NEW COUNT,TIMEZONEOFFSET,TIME
+2 ;
+3 FOR COUNT=1:1:NUMBEROFENTRIES
Begin DoDot:1
+4 IF $GET(AVAILABILITY("NUMBER OF SLOTS",COUNT))="@"
QUIT
+5 ;
+6 IF $LENGTH($PIECE($PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),"T",2),"-",2))!($LENGTH($PIECE($PIECE($GET(AVAILABILITY("END DATE TIME",COUNT)),"T",2),"-",2)))
DO ERRLOG^SDES2JSON(.ERRORS,590)
+7 SET TIMEZONEOFFSET=$$GETTZOFFSET^SDESUTIL($$ISOTFM^SDAMUTDT($PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),"T")),CLINICIEN)
+8 SET AVAILABILITY("START DATE TIME",COUNT)=$GET(AVAILABILITY("START DATE TIME",COUNT))_TIMEZONEOFFSET
+9 SET AVAILABILITY("END DATE TIME",COUNT)=$GET(AVAILABILITY("END DATE TIME",COUNT))_TIMEZONEOFFSET
+10 ;
+11 DO VALISODATERANGE^SDES2VALISODTTM(.ERRORS,$GET(AVAILABILITY("START DATE TIME",COUNT)),$GET(AVAILABILITY("END DATE TIME",COUNT)),1,CLINICIEN)
+12 SET AVAILABILITY("START DATE TIME",COUNT)=$$ISOTFM^SDAMUTDT($GET(AVAILABILITY("START DATE TIME",COUNT)),CLINICIEN)
+13 SET AVAILABILITY("END DATE TIME",COUNT)=$$ISOTFM^SDAMUTDT($GET(AVAILABILITY("END DATE TIME",COUNT)),CLINICIEN)
+14 IF $GET(AVAILABILITY("START DATE TIME",COUNT))<DT
DO ERRLOG^SDES2JSON(.ERRORS,71)
+15 ;
+16 IF $$GET1^DIQ(44,CLINICIEN,1914,"I")*100>+$EXTRACT($PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),".",2)_"0000",1,4)
DO ERRLOG^SDES2JSON(.ERRORS,581)
+17 IF '$$CHECKDURATION^SDES2UTIL1($GET(AVAILABILITY("START DATE TIME",COUNT)),$GET(AVAILABILITY("END DATE TIME",COUNT)),$$GET1^DIQ(44,CLINICIEN,1912,"I"))
DO ERRLOG^SDES2JSON(.ERRORS,582)
+18 IF $$INACTIVE^SDESUTIL(CLINICIEN,$PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),"."))
DO ERRLOG^SDES2JSON(.ERRORS,583)
+19 IF $$GET1^DIQ(44,CLINICIEN,1918.5,"I")'="Y"
IF $DATA(^HOLIDAY($PIECE($GET(AVAILABILITY("START DATE TIME",COUNT)),"."),0))
DO ERRLOG^SDES2JSON(.ERRORS,465)
End DoDot:1
if $DATA(ERRORS)
QUIT
+20 QUIT
+21 ;