Files
2021-01-04 18:09:35 +00:00

359 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sarand.Core.Base;
using Sarand.Core.Bus;
using Sarand.PatientMgr.Core.App;
namespace Sarand.PatientMgr.Core.Bus
{
//=======================================================================
public abstract class SpmFacility : SacsHierarchyItem
{
//-------------------------------------------------------------------
// Columns.
public enum Column
{
Pos,
Id,
DepartmentId,
Type,
Type_Desc,
Name,
SortCode,
Desc,
TemplateMapType,
ScheduleFreezeType,
FreezeTime,
FreezeData,
ApplicFrom,
ApplicTo,
// Common properties.
Notes,
Flag,
Status,
Status_Ind,
Status_Desc,
CreateOn_Date,
UpdateOn_Date,
}
//-------------------------------------------------------------------
/// <summary>Properties other than common.</summary>
public class DataProperties
{
public SysId DepartmentId { get; set; }
public Spm.FacilityType FacilityType { get; set; }
public String Name { get; set; }
public String SortCode { get; set; }
public String Desc { get; set; }
public Spm.FacilityTemplateMapType TemplateMapType { get; set; }
public Spm.ScheduleFreezeType ScheduleFreezeType { get; set; }
public DateTime ScheduleFreezeAtTime { get; set; }
public String ScheduleFreezeData { get; set; }
public DateTime ApplicationFrom { get; set; }
public DateTime ApplicationTo { get; set; }
}
//-------------------------------------------------------------------
// Data.
public new class Data : SacsHierarchyItem.Data
{
// Data members.
private readonly DataProperties data = new DataProperties();
// Construction.
public Data ()
{
Status = DefaultStatus;
}
// Properties.
public SysId DepartmentId
{
get { return data.DepartmentId; }
set { CheckChanged(data.DepartmentId, value); data.DepartmentId = value; }
}
public Spm.FacilityType FacilityType
{
get { return data.FacilityType; }
set { CheckChanged((int)data.FacilityType, (int)value); data.FacilityType = value; }
}
public String Name
{
get { return data.Name; }
set { CheckChanged(data.Name, value); data.Name = value; }
}
public String SortCode
{
get { return data.SortCode; }
set { CheckChanged(data.SortCode, value); data.SortCode = value; }
}
public String Desc
{
get { return data.Desc; }
set { CheckChanged(data.Desc, value); data.Desc = value; }
}
public Spm.FacilityTemplateMapType TemplateMapType
{
get { return data.TemplateMapType; }
set { CheckChanged((int)data.TemplateMapType, (int)value); data.TemplateMapType = value; }
}
public Spm.ScheduleFreezeType ScheduleFreezeType
{
get { return data.ScheduleFreezeType; }
set { CheckChanged((int)data.ScheduleFreezeType, (int)value); data.ScheduleFreezeType = value; }
}
public DateTime ScheduleFreezeAtTime
{
get { return data.ScheduleFreezeAtTime; }
set { CheckChanged(data.ScheduleFreezeAtTime, value); data.ScheduleFreezeAtTime = value; }
}
public String ScheduleFreezeData
{
get { return data.ScheduleFreezeData; }
set { CheckChanged(data.ScheduleFreezeData, value); data.ScheduleFreezeData = value; }
}
public DateTime ApplicationFrom
{
get { return data.ApplicationFrom; }
set { CheckChanged(data.ApplicationFrom, value); data.ApplicationFrom = value; }
}
public DateTime ApplicationTo
{
get { return data.ApplicationTo; }
set { CheckChanged(data.ApplicationTo, value); data.ApplicationTo = value; }
}
//-------------------------------------------------------------------
// Flags.
public bool IsBookingToFacility
{
get { return GetFlag(Flag_BookingToFacility); }
set { SetFlag(Flag_BookingToFacility, value); }
}
// Population.
internal void PopulateFrom (Data data)
{
DepartmentId = data.DepartmentId;
FacilityType = data.FacilityType;
Name = data.Name;
SortCode = data.SortCode;
Desc = data.Desc;
TemplateMapType = data.TemplateMapType;
ScheduleFreezeType = data.ScheduleFreezeType;
ScheduleFreezeAtTime = data.ScheduleFreezeAtTime;
ScheduleFreezeData = data.ScheduleFreezeData;
ApplicationFrom = data.ApplicationFrom;
ApplicationTo = data.ApplicationTo;
base.PopulateFrom(data);
}
public Data Clone ()
{
Data data = new Data();
data.PopulateFrom(this);
return data;
}
}
//-------------------------------------------------------------------
// Error field - identify properties with validation error.
public new class ErrField : SacsHierarchyItem.ErrField
{
public ValidValue DepartmentId { get; set; } = ValidValue.Valid;
public ValidValue FacilityType { get; set; } = ValidValue.Valid;
public ValidValue Name { get; set; } = ValidValue.Valid;
public ValidValue SortCode { get; set; } = ValidValue.Valid;
public ValidValue Desc { get; set; } = ValidValue.Valid;
public ValidValue TemplateMapType { get; set; } = ValidValue.Valid;
public ValidValue ScheduleFreezeType { get; set; } = ValidValue.Valid;
public ValidValue ScheduleFreezeAtTime { get; set; } = ValidValue.Valid;
public ValidValue ScheduleFreezeData { get; set; } = ValidValue.Valid;
public ValidValue ApplicationFrom { get; set; } = ValidValue.Valid;
public ValidValue ApplicationTo { get; set; } = ValidValue.Valid;
}
//-------------------------------------------------------------------
// Data members.
private readonly Data data = new Data();
public static readonly Byte Flag_BookingToFacility = 0x01;
//-------------------------------------------------------------------
// Construction.
protected SpmFacility (SysId facilityId, SysId departmentId, Spm.FacilityType facilityType) : base()
{
departmentId = DepartmentId;
facilityType = FacilityType;
Status = DefaultStatus;
base.SetData(data);
}
//-------------------------------------------------------------------
// Status.
private static readonly List<SaStatus> facilityStatuses = new List<SaStatus>()
{
SaStatus.Current,
};
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
public static List<SaStatus> FacilityStatuses { get { return new List<SaStatus>(facilityStatuses); } }
public static DataValue.TriStateType GetStatusTriState (SaStatus status)
{
facilityStatuses.Add(SaStatus.Current);
switch (status)
{
case SaStatus.Current:
return DataValue.TriStateType.Green;
}
return DataValue.TriStateType.Unknown;
}
//-------------------------------------------------------------------
// Utilities.
public Spm.WardAdmissionMode GetBookingMode ()
{
// Based on 'Booking to Facility' flag etc.
if (FacilityType == Spm.FacilityType.Ward && IsBookingToFacility)
return Spm.WardAdmissionMode.ByWard;
return Spm.WardAdmissionMode.ByResource;
}
public bool IsTemplateRequiredForBooking ()
{
if (GetBookingMode() == Spm.WardAdmissionMode.ByWard)
return false;
return true;
}
//-------------------------------------------------------------------
// Properties.
public Data GetData () { return data.Clone(); }
public void SetData (Data data)
{
String fn = GetType().Name + ".SetData";
// Properties that cannot be changed if previously specified.
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
throw new NotSupportedException(fn + " Id cannot be changed");
this.data.PopulateFrom(data);
}
//-------------------------------------------------------------------
// Attributes.
public SysId DepartmentId
{
get { return data.DepartmentId; }
set { data.DepartmentId = value; }
}
public Spm.FacilityType FacilityType
{
get { return data.FacilityType; }
set { data.FacilityType = value; }
}
public String Name
{
get { return data.Name; }
set { data.Name = value; }
}
public String SortCode
{
get { return data.SortCode; }
set { data.SortCode = value; }
}
public String Desc
{
get { return data.Desc; }
set { data.Desc = value; }
}
public Spm.FacilityTemplateMapType TemplateMapType
{
get { return data.TemplateMapType; }
set { data.TemplateMapType = value; }
}
public Spm.ScheduleFreezeType ScheduleFreezeType
{
get { return data.ScheduleFreezeType; }
set { data.ScheduleFreezeType = value; }
}
public DateTime ScheduleFreezeAtTime
{
get { return data.ScheduleFreezeAtTime; }
set { data.ScheduleFreezeAtTime = value; }
}
public String ScheduleFreezeData
{
get { return data.ScheduleFreezeData; }
set { data.ScheduleFreezeData = value; }
}
public DateTime ApplicationFrom
{
get { return data.ApplicationFrom; }
set { data.ApplicationFrom = value; }
}
public DateTime ApplicationTo
{
get { return data.ApplicationTo; }
set { data.ApplicationTo = value; }
}
//-------------------------------------------------------------------
// Flags.
public bool IsBookingToFacility
{
get { return GetFlag(Flag_BookingToFacility); }
set { SetFlag(Flag_BookingToFacility, value); }
}
//-------------------------------------------------------------------
// A s s o c i a t e d D a t a E l e m e n t s
//-------------------------------------------------------------------
public abstract bool HasTemplates (); // eg. Slots.
public abstract bool HasSessions ();
public abstract bool HasSessionsBefore (DateTime target, ref DateTime? earliest, ref DateTime? latest);
public abstract bool HasSessionsAfter (DateTime target, ref DateTime? earliest, ref DateTime? latest);
public abstract bool HasSessions (DateTime before, DateTime after, ref DateTime? earliest, ref DateTime? latest);
public abstract bool HasAdmissions (Spm.AdmissionCancelType admissionCancelType);
public abstract bool HasAdmissionsBefore (DateTime target, Spm.AdmissionCancelType admissionCancelType, ref DateTime? earliest, ref DateTime? latest);
public abstract bool HasAdmissionsAfter (DateTime target, Spm.AdmissionCancelType admissionCancelType, ref DateTime? earliest, ref DateTime? latest);
public abstract bool HasAdmissions (DateTime before, DateTime after, Spm.AdmissionCancelType admissionCancelType, ref DateTime? earliest, ref DateTime? latest);
//-------------------------------------------------------------------
// P a r a m s
//-------------------------------------------------------------------
/// <summary>Parameters - used to define the filters that should be applied to a List of Addresses</summary>
// List parameters.
public enum StatusCat
{
Any,
}
/// <summary> Item list parameters. </summary>
public new class Params : SacsHierarchyItem.Params
{
// List filtering.
public List<SysId> IncludedIds { get; } = new List<SysId>();
public List<SysId> ExcludedIds { get; } = new List<SysId>();
// Facility.
public SysId DepartmentId { get; set; }
public Spm.FacilityType FacilityType { get; set; }
public String NamePartial { get; set; }
public int WeekOfMonth { get; set; }
public int WorkingDayOfWeek { get; set; }
public DateTime ApplicationFrom { get; set; }
public DateTime ApplicationTo { get; set; }
public DateTime Application { get; set; }
public DateTime TemplatesApplicationFrom { get; set; }
public StatusCat StatusCat { get; set; } = StatusCat.Any;
}
//-------------------------------------------------------------------
}
//=======================================================================
// Facility D a t a L i s t
//=======================================================================
public static class SpmFacilityList
{
}
//=======================================================================
}