249 lines
8.2 KiB
C#
249 lines
8.2 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 SpmDepartment : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
InstitutionId,
|
|
Name,
|
|
ApplicableFrom,
|
|
ApplicableTo,
|
|
// Common properties.
|
|
Notes,
|
|
Flag,
|
|
Status,
|
|
Status_Ind,
|
|
Status_Desc,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
public Data ()
|
|
{
|
|
Status = SpmDepartment.DefaultStatus;
|
|
}
|
|
public SysId InstitutionId { get; set; }
|
|
public String Name { get; set; }
|
|
public uint FacilityTypes { get; set; } = 0;
|
|
public bool HasFacilityType (Spm.FacilityType facilityType)
|
|
{
|
|
return SpmDepartment.HasFacilityType(FacilityTypes, facilityType);
|
|
}
|
|
public uint AllowAnyFacilities { get; set; } = 0;
|
|
public bool AllowAnyFacility (Spm.FacilityType facilityType)
|
|
{
|
|
return SpmDepartment.AllowAnyFacility(AllowAnyFacilities, facilityType);
|
|
}
|
|
public ushort GetCancelReBookLimit (Spm.FacilityType facilityType)
|
|
{
|
|
return SpmDepartment.GetCancelReBookLimit("", facilityType);
|
|
}
|
|
public DateTime ApplicableFrom { get; set; }
|
|
public DateTime ApplicableTo { get; set; }
|
|
internal void PopulateFrom (Data data)
|
|
{
|
|
InstitutionId = data.InstitutionId;
|
|
Name = data.Name;
|
|
ApplicableFrom = data.ApplicableFrom;
|
|
ApplicableTo = data.ApplicableTo;
|
|
base.PopulateFrom(data);
|
|
}
|
|
public Data Clone ()
|
|
{
|
|
Data data = new Data();
|
|
data.PopulateFrom(this);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// ErrField.
|
|
public new class ErrField : SacsHierarchyItem.ErrField
|
|
{
|
|
public ValidValue InstitutionId { get; set; } = ValidValue.Valid;
|
|
public ValidValue Name { get; set; } = ValidValue.Valid;
|
|
public ValidValue ApplicableFrom { get; set; } = ValidValue.Valid;
|
|
public ValidValue ApplicableTo { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SpmDepartment (SysId id, SysId institutionId) : base(id)
|
|
{
|
|
InstitutionId = institutionId;
|
|
Status = DefaultStatus;
|
|
base.SetData(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> departmentStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Current,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(departmentStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState (SaStatus status)
|
|
{
|
|
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");
|
|
if (SysId.IsValid(InstitutionId) && SysId.ToInt(InstitutionId) != SysId.ToInt(data.InstitutionId))
|
|
throw new NotSupportedException(fn + " Institution Id cannot be changed");
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public SysId InstitutionId
|
|
{
|
|
get { return data.InstitutionId; }
|
|
protected set { CheckChanged(data.InstitutionId, value); data.InstitutionId = value; }
|
|
}
|
|
public String Name
|
|
{
|
|
get { return data.Name; }
|
|
set { CheckChanged(data.Name, value); data.Name = value; }
|
|
}
|
|
// Facility types.
|
|
public uint FacilityTypes { get { return data.FacilityTypes; } set { data.FacilityTypes = value; } }
|
|
public static 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 static bool HasFacilityType (uint facilityTypes, Spm.FacilityType facilityType)
|
|
{
|
|
int facilityTypeBit = GetFacilityTypeBit (facilityType);
|
|
if (facilityTypeBit >= 0 && facilityTypeBit < 32)
|
|
return (facilityTypes & (((uint)1) << facilityTypeBit)) > 0;
|
|
return false;
|
|
}
|
|
public bool HasFacilityType (Spm.FacilityType facilityType)
|
|
{
|
|
return HasFacilityType(data.FacilityTypes, facilityType);
|
|
}
|
|
// Allow any facility.
|
|
public uint AllowAnyFacilities { get { return data.AllowAnyFacilities; } set { data.AllowAnyFacilities = value; } }
|
|
public static bool AllowAnyFacility (uint allowAnyFacilities, Spm.FacilityType facilityType)
|
|
{
|
|
int facilityTypeBit = GetFacilityTypeBit(facilityType);
|
|
if (facilityTypeBit >= 0 && facilityTypeBit < 32)
|
|
return (allowAnyFacilities & (((uint)1) << facilityTypeBit)) > 0;
|
|
return false;
|
|
}
|
|
public bool AllowAnyFacility (Spm.FacilityType facilityType)
|
|
{
|
|
return AllowAnyFacility(data.AllowAnyFacilities, facilityType);
|
|
}
|
|
// Cancel re-book limit.
|
|
public static ushort GetCancelReBookLimit (String cancelReBookLimit, Spm.FacilityType facilityType)
|
|
{
|
|
if (facilityType == Spm.FacilityType.Theatre) return 28;
|
|
return 0;
|
|
}
|
|
public ushort GetCancelReBookLimit (Spm.FacilityType facilityType)
|
|
{
|
|
return GetCancelReBookLimit("", facilityType);
|
|
}
|
|
public DateTime ApplicableFrom
|
|
{
|
|
get { return data.ApplicableFrom; }
|
|
set { CheckChanged(data.ApplicableFrom, value); data.ApplicableFrom = value; }
|
|
}
|
|
public DateTime ApplicableTo
|
|
{
|
|
get { return data.ApplicableTo; }
|
|
set { CheckChanged(data.ApplicableTo, value); data.ApplicableTo = 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
|
|
//-------------------------------------------------------------------
|
|
/// <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>();
|
|
|
|
// Department.
|
|
public String Name { get; set; }
|
|
public String NamePartial { get; set; }
|
|
public DateTime ApplicableFrom { get; set; }
|
|
public DateTime ApplicableTo { 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
|
|
{
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|