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

SDES2CRTCLNAVAIL.m

Go to the documentation of this file.
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
 ;