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 SpmDepartment : SacsHierarchyItem { //------------------------------------------------------------------- // Columns. public enum Column { Pos, Id, Name, ApplicatonFrom, ApplicationTo, // Common properties. Notes, Flag, Status, Status_Ind, Status_Desc, CreateOn_Date, UpdateOn_Date, } // Data. public new class Data : SacsHierarchyItem.Data { public Data() { //Status = DepartmentStatus; } public String Name { get; set; } public DateTime ApplicationFrom { get; set; } public DateTime ApplicationTo { get; set; } internal void PopulateFrom(Data data) { Name = data.Name; ApplicationFrom = data.ApplicationFrom; ApplicationTo = data.ApplicationTo; base.PopulateFrom(data); } public Data Clone() { Data data = new Data(); data.PopulateFrom(this); return data; } } // ErrField. public new class ErrField : SacsHierarchyItem.ErrField { public ValidValue Name { 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(); private long facilityTypes; private long allowAnyFacility; //------------------------------------------------------------------- // Construction. protected SpmDepartment(SysId id) : base(id) { Status = DefaultStatus; base.SetData(data); } //------------------------------------------------------------------- // Status. private static readonly List departmentStatuses = new List() { SaStatus.Current, }; public static SaStatus DefaultStatus { get { return SaStatus.Current; } } public static List DepartmentStatuses { get { return new List(departmentStatuses); } } public static DataValue.TriStateType GetStatusTriState(SaStatus status) { departmentStatuses.Add(SaStatus.Current); switch (status) { case SaStatus.Current: return DataValue.TriStateType.Green; } return DataValue.TriStateType.Unknown; } //------------------------------------------------------------------- // Utilities. //------------------------------------------------------------------- // 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 String Name { get { return data.Name; } set { CheckChanged(data.Name, value); data.Name = value; } } public int GetFacilityTypeBit(Spm.FacilityType facilityType) { // Map facility types to their position in the bit mapped value: if (facilityType == Spm.FacilityType.Theatre) return 0; if (facilityType == Spm.FacilityType.Clinic) return 1; if (facilityType == Spm.FacilityType.Ward) return 2; if (facilityType == Spm.FacilityType.Apparatus) return 3; return -1; } public bool HasFacilityType(Spm.FacilityType facilityType) { int facilityTypeBit = GetFacilityTypeBit(facilityType); if (facilityTypeBit >= 0 && facilityTypeBit < 32) return ((facilityTypes & (((long)1) << facilityTypeBit)) > 0); return false; } public bool AllowAnyFacility(Spm.FacilityType facilityType) { int iFacilityTypeBit = GetFacilityTypeBit(facilityType); if (iFacilityTypeBit >= 0 && iFacilityTypeBit < 32) return ((allowAnyFacility & (((long)1) << iFacilityTypeBit)) > 0); return false; } public long GetFacilityTypes() { return facilityTypes; } public long GetAllowAnyFacilities() { return allowAnyFacility; } public ushort GetCancelReBookLimit(Spm.FacilityType facility) { if (facility == Spm.FacilityType.Theatre) return 28; return 0; } public DateTime ApplicationFrom { get { return data.ApplicationFrom; } set { CheckChanged(data.ApplicationFrom, value); data.ApplicationFrom = value; }dd } public DateTime ApplicationTo { get { return data.ApplicationTo; } set { CheckChanged(data.ApplicationTo, value); data.ApplicationTo = value; } } //------------------------------------------------------------------- // Flags. //------------------------------------------------------------------- // A s s o c i a t e d D a t a E l e m e n t s //------------------------------------------------------------------- public abstract int GetFacilityCount(Spm.FacilityType type); public abstract bool HasFacilities(Spm.FacilityType type); public abstract bool HasProcedures(); //------------------------------------------------------------------- // P a r a m s //------------------------------------------------------------------- /// Parameters - used to define the filters that should be applied to a List of Addresses // List parameters. public enum StatusCat { Any, } /// Item list parameters. public new class Params : SacsHierarchyItem.Params { // List filtering. public List IncludedIds { get; } = new List(); public List ExcludedIds { get; } = new List(); // Department. public String Name { get; set; } public String NamePartial { get; set; } public DateTime ApplicationFrom { get; set; } public DateTime ApplicationTo { get; set; } public DateTime Application { get; set; } public StatusCat StatusCat { get; set; } = StatusCat.Any; } //------------------------------------------------------------------- } //======================================================================= // Department D a t a L i s t //======================================================================= public static class SpmDepartmentList { } //======================================================================= }