300 lines
9.5 KiB
C#
300 lines
9.5 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 SpmAdmissionRole : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos,
|
|
Id,
|
|
AdmissionId,
|
|
Role,
|
|
Category,
|
|
Seq,
|
|
EmployeeRoleId,
|
|
EmployeeCode,
|
|
|
|
// Common properties.
|
|
Notes,
|
|
Flag,
|
|
Status,
|
|
Status_Ind,
|
|
Status_Desc,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId AdmissionId { get; set; }
|
|
public Spm.EmployeeRole EmployeeRole { get; set; }
|
|
public Spm.EmployeeRoleCategory EmployeeRoleCategory { get; set; }
|
|
public ushort Seq { get; set; }
|
|
public SysId EmployeeRoleId { get; set; }
|
|
public String EmployeeCode { 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 AdmissionId
|
|
{
|
|
get { return data.AdmissionId; }
|
|
set { CheckChanged(data.AdmissionId, value); data.AdmissionId = value; }
|
|
}
|
|
public Spm.EmployeeRole EmployeeRole
|
|
{
|
|
get { return data.EmployeeRole; }
|
|
set { CheckChanged((int)data.EmployeeRole, (int)value); data.EmployeeRole = value; }
|
|
}
|
|
public Spm.EmployeeRoleCategory EmployeeRoleCategory
|
|
{
|
|
get { return data.EmployeeRoleCategory; }
|
|
set { CheckChanged((int)data.EmployeeRoleCategory, (int)value); data.EmployeeRoleCategory = value; }
|
|
}
|
|
public ushort Seq
|
|
{
|
|
get { return data.Seq; }
|
|
set { CheckChanged(data.Seq, value); data.Seq = value; }
|
|
}
|
|
public SysId EmployeeRoleId
|
|
{
|
|
get { return data.EmployeeRoleId; }
|
|
set { CheckChanged(data.EmployeeRoleId, value); data.EmployeeRoleId = value; }
|
|
}
|
|
public String EmployeeCode
|
|
{
|
|
get { return data.EmployeeCode; }
|
|
set { CheckChanged(data.EmployeeCode, value); data.EmployeeCode = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom (Data data)
|
|
{
|
|
AdmissionId = data.AdmissionId;
|
|
EmployeeRole = data.EmployeeRole;
|
|
EmployeeRoleCategory = data.EmployeeRoleCategory;
|
|
Seq = data.Seq;
|
|
EmployeeRoleId = data.EmployeeRoleId;
|
|
EmployeeCode = data.EmployeeCode;
|
|
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 AdmissionId { get; set; } = ValidValue.Valid;
|
|
public ValidValue EmployeeRole { get; set; } = ValidValue.Valid;
|
|
public ValidValue EmployeeRoleCategory { get; set; } = ValidValue.Valid;
|
|
public ValidValue Seq { get; set; } = ValidValue.Valid;
|
|
public ValidValue EmployeeRoleId { get; set; } = ValidValue.Valid;
|
|
public ValidValue EmployeeCode { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SpmAdmissionRole (SysId admissionId, Spm.EmployeeRole employeeRole, Spm.EmployeeRoleCategory employeeRoleCategory) : base()
|
|
{
|
|
admissionId = AdmissionId;
|
|
employeeRole = EmployeeRole;
|
|
employeeRoleCategory = EmployeeRoleCategory;
|
|
Status = DefaultStatus;
|
|
base.SetData(data);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status.
|
|
private static readonly List<SaStatus> admissionRoleStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Current,
|
|
};
|
|
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
|
public static List<SaStatus> AdmissionRoleStatuses { get { return new List<SaStatus>(admissionRoleStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState (SaStatus status)
|
|
{
|
|
admissionRoleStatuses.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 SysId AdmissionId
|
|
{
|
|
get { return data.AdmissionId; }
|
|
set { data.AdmissionId = value; }
|
|
}
|
|
public Spm.EmployeeRole EmployeeRole
|
|
{
|
|
get { return data.EmployeeRole; }
|
|
set { data.EmployeeRole = value; }
|
|
}
|
|
public Spm.EmployeeRoleCategory EmployeeRoleCategory
|
|
{
|
|
get { return data.EmployeeRoleCategory; }
|
|
set { data.EmployeeRoleCategory = value; }
|
|
}
|
|
public ushort Seq
|
|
{
|
|
get { return data.Seq; }
|
|
set { data.Seq = value; }
|
|
}
|
|
public SysId EmployeeRoleId
|
|
{
|
|
get { return data.EmployeeRoleId; }
|
|
set { data.EmployeeRoleId = value; }
|
|
}
|
|
public String EmployeeCode
|
|
{
|
|
get { return data.EmployeeCode; }
|
|
set { data.EmployeeCode = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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>();
|
|
// Admission Role.
|
|
public SysId AdmissionId { get; set; }
|
|
public Spm.EmployeeRole EmployeeRole { get; set; } = Spm.EmployeeRole.Unknown;
|
|
public Spm.EmployeeRoleCategory EmployeeRoleCategory { get; set; } = Spm.EmployeeRoleCategory.Unknown;
|
|
public ushort Seq { get; set; }
|
|
public SysId EmployeeRoleId { get; set; }
|
|
public String EmployeeCode { get; set; }
|
|
|
|
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
// AdmissionRole D a t a L i s t
|
|
//=======================================================================
|
|
public static class SpmAdmissionRoleList
|
|
{
|
|
public static int CompareByRoleSeq (SpmAdmissionRole p1, SpmAdmissionRole p2)
|
|
{
|
|
Spm.EmployeeRole role1 = (p1 != null ? p1.EmployeeRole : Spm.EmployeeRole.Unknown);
|
|
Spm.EmployeeRole role2 = (p2 != null ? p2.EmployeeRole : Spm.EmployeeRole.Unknown);
|
|
ushort seq1 = (p1 != null ? p1.Seq : (ushort)0);
|
|
ushort seq2 = (p2 != null ? p2.Seq : (ushort)0);
|
|
if (role1 == role2 && seq1 == seq2) return 0;
|
|
if (role1 > role2) return 1;
|
|
if (role1 == role2 && seq1 > seq2) return 1;
|
|
return -1;
|
|
}
|
|
|
|
public enum SortMode { SortRoleSeq, };
|
|
|
|
public static void Sort (this List<SpmAdmissionRole> values, SortMode admissionRoleSort, bool ascending = true)
|
|
{
|
|
if (admissionRoleSort == SortMode.SortRoleSeq)
|
|
values.Sort
|
|
(
|
|
delegate (SpmAdmissionRole admissionRole1, SpmAdmissionRole admissionRole2)
|
|
{
|
|
return CompareByRoleSeq(admissionRole1, admissionRole2);
|
|
}
|
|
);
|
|
}
|
|
|
|
public static void SetSequence (this List<SpmAdmissionRole> values)
|
|
{
|
|
if (values != null || values.Count == 0) return;
|
|
for (int itemIdx = 0; itemIdx < values.Count; itemIdx++)
|
|
values[itemIdx].Seq = (ushort)(itemIdx + 1);
|
|
}
|
|
|
|
public static bool SetIdentity (this List<SpmAdmissionRole> values, SpmAdmission admission)
|
|
{
|
|
foreach (SpmAdmissionRole admissionRole in values)
|
|
admissionRole.AdmissionId = admission.Id;
|
|
return true;
|
|
}
|
|
|
|
public static bool Find (this List<SpmAdmissionRole> values, SpmAdmissionRole admissionRole)
|
|
{
|
|
if (admissionRole == null) return false;
|
|
return (values.Find(item => item == admissionRole) != null);
|
|
}
|
|
|
|
public static bool FindByRoleCatSeq (this List<SpmAdmissionRole> values, Spm.EmployeeRole role, Spm.EmployeeRoleCategory category, ushort seq)
|
|
{
|
|
if ((int)role > 0 && (int)category > 0) return false;
|
|
return values.Exists(item => item.EmployeeRole.Equals(role) && item.EmployeeRoleCategory.Equals(category) && item.Seq.Equals(seq));
|
|
}
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|