SB 16-May-2019
This commit is contained in:
@@ -0,0 +1,840 @@
|
||||
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 SpmAdmission : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Session, // Not populated - reserved for session heading.
|
||||
Id,
|
||||
|
||||
FacilityId,
|
||||
TemplateId,
|
||||
Seq,
|
||||
// Admission date.
|
||||
AdmissionFromDate,
|
||||
AdmissionFromTime,
|
||||
AdmissionFromDateTime,
|
||||
AdmissionToDate,
|
||||
AdmissionToTime,
|
||||
AdmissionToDateTime,
|
||||
Type,
|
||||
Type_Desc,
|
||||
// Dates.
|
||||
DecisionToReferOn,
|
||||
ReferredOn,
|
||||
BreechOn,
|
||||
DecisionToAdmitOn,
|
||||
// Admission details.
|
||||
Patient, // No & display name.
|
||||
PatientId,
|
||||
PatientNo,
|
||||
PatientName, // LAST, First
|
||||
PatientSurname,
|
||||
PatientForename,
|
||||
BirthAge,
|
||||
BirthOn,
|
||||
Age,
|
||||
AgeOn,
|
||||
FacilityIdWard,
|
||||
Ward,
|
||||
ProcedureId,
|
||||
SpecialityCode,
|
||||
Procedure,
|
||||
ComplexityCode,
|
||||
ProcedureIndication,
|
||||
DurationExp,
|
||||
DurationAct,
|
||||
Anaesthetic,
|
||||
Position,
|
||||
SpecialEquipment,
|
||||
AttendanceStatusDesc,
|
||||
ComfortScore,
|
||||
// Admission timings.
|
||||
TimeCalled,
|
||||
TimeArrived,
|
||||
TimeAnaesStart,
|
||||
TimeProcStart,
|
||||
TimeProcEnd,
|
||||
TimeInRecovery,
|
||||
TimeInformDest,
|
||||
TimeLeave,
|
||||
// Cancellations.
|
||||
CancelType,
|
||||
CancelTypeDesc,
|
||||
CancelDate,
|
||||
CancelElapsed,
|
||||
CancelReBookBy,
|
||||
CancelReBookDue,
|
||||
CancelCount,
|
||||
Notes,
|
||||
// Facility.
|
||||
Facility_Type,
|
||||
Facility_TypeDesc,
|
||||
Facility_Name,
|
||||
Facility_Desc,
|
||||
Facility_TemplateMapType,
|
||||
Facility_ApplicFrom,
|
||||
Facility_ApplicTo,
|
||||
Facility_Notes,
|
||||
// Facility Template.
|
||||
Template_WeekOfMonth,
|
||||
Template_DayOfWeek,
|
||||
Template_ConsultantId,
|
||||
Template_ConsultantCode,
|
||||
Template_SpecialityCode,
|
||||
Template_StartAt,
|
||||
Template_FinishAt,
|
||||
Template_CategoryDesc,
|
||||
Template_TypeDesc,
|
||||
Template_Name,
|
||||
Template_Desc,
|
||||
Template_Group,
|
||||
Template_ApplicFrom,
|
||||
Template_ApplicTo,
|
||||
Template_Notes,
|
||||
// Facility Session.
|
||||
Session_TemplateId,
|
||||
Session_ConsultantId,
|
||||
Session_ConsultantCode,
|
||||
Session_SpecialityCode,
|
||||
Session_StartAt,
|
||||
Session_FinishAt,
|
||||
Session_Name,
|
||||
Session_Desc,
|
||||
Session_Flags,
|
||||
Session_Notes,
|
||||
// Session definition (combined template and date-specific session info):
|
||||
SessionDfn_Summary,
|
||||
SessionDfn_Name,
|
||||
// Patient.
|
||||
Patient_PatientNo,
|
||||
Patient_Surname,
|
||||
Patient_Forename,
|
||||
Patient_BirthOn,
|
||||
Patient_Age,
|
||||
Patient_AgeOn,
|
||||
// Members of staff (Role-categories not in use are commented out).
|
||||
Role_Consultant_Operating_Code,
|
||||
Role_Consultant_Referring_Code,
|
||||
//Role_Consultant_Attending_Code,
|
||||
Role_Surgeon_Operating_Code,
|
||||
//Role_Surgeon_Referring_Code,
|
||||
//Role_Surgeon_Attending_Code,
|
||||
Role_Anaesthetist_Operating_Code,
|
||||
|
||||
// Common properties.
|
||||
//Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = AdmissionStatus;
|
||||
}
|
||||
public SysId FacilityId { get; set; }
|
||||
public SysId FacilityTemplateId { get; set; }
|
||||
public DateTime AdmissionFrom { get; set; }
|
||||
public DateTime AdmissionTo { get; set; }
|
||||
public DateTime ToComeIn { get; set; }
|
||||
public bool RequiresSeq() { return RequiresSeq(/*AdmissionType*/); }
|
||||
public ushort Seq { get; set; }
|
||||
public Spm.AdmissionType AdmissionType { get; set; }
|
||||
public Spm.AdmissionOccupancy Occupancy { get; set; }
|
||||
public DateTime DecisionToReferOn { get; set; }
|
||||
public DateTime ReferredOn { get; set; }
|
||||
public DateTime DecisionToAdmitOn { get; set; }
|
||||
public DateTime BreechOn { get; set; }
|
||||
public SysId PatientId { get; set; }
|
||||
public String PatientNo { get; set; }
|
||||
public String NhsNumber { get; set; }
|
||||
public String Title { get; set; }
|
||||
public String Forename { get; set; }
|
||||
public String Surname { get; set; }
|
||||
public Spm.Gender Gender { get; set; }
|
||||
public DateTime BirthOn { get; set; }
|
||||
public String Age { get; set; }
|
||||
public DateTime AgeOn { get; set; }
|
||||
public SysId FacilityIdWard { get; set; }
|
||||
public String Ward { get; set; }
|
||||
public SysId ProcedureId { get; set; }
|
||||
public String SpecialityCode { get; set; }
|
||||
public String ProcedureDesc { get; set; }
|
||||
public String ComplexityCode { get; set; }
|
||||
public String ProcedureIndication { get; set; }
|
||||
public String PatientHistory { get; set; }
|
||||
public String GestationPeriod { get; set; }
|
||||
public String SystemRef { get; set; }
|
||||
public ushort DurationExp { get; set; }
|
||||
public ushort DurationAct { get; set; }
|
||||
public decimal UnitsExp { get; set; }
|
||||
public decimal UnitsAct { get; set; }
|
||||
public String Anaesthetic { get; set; }
|
||||
public String Position { get; set; }
|
||||
public String SpecialEquipment { get; set; }
|
||||
public Spm.AttendanceType AttendanceType { get; set; }
|
||||
public String AttendanceStatus { get; set; }
|
||||
public String ComfortScore { get; set; }
|
||||
|
||||
// Admission times.
|
||||
public DateTime TimeCalled { get; set; }
|
||||
public DateTime TimeArrived { get; set; }
|
||||
public DateTime TimeAnaesStart { get; set; }
|
||||
public DateTime TimeProcStart { get; set; }
|
||||
public DateTime TimeProcEnd { get; set; }
|
||||
public DateTime TimeInRecovery { get; set; }
|
||||
public DateTime TimeInformDest { get; set; }
|
||||
public DateTime TimeLeave { get; set; }
|
||||
|
||||
// Cancellation.
|
||||
public static bool IsCancelled(Spm.AdmissionCancelType cancel) { return (cancel != Spm.AdmissionCancelType.None); }
|
||||
public bool IsCancelled() { return IsCancelled(/*CancelType*/); }
|
||||
public Spm.AdmissionCancelType CancelType { get; set; }
|
||||
public DateTime CancelDate { get; set; }
|
||||
public ushort CancelCount { get; set; }
|
||||
public String CancelCode { get; set; }
|
||||
public String CancelReason { get; set; }
|
||||
|
||||
// Flags.
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
FacilityId = data.FacilityId;
|
||||
FacilityTemplateId = data.FacilityTemplateId;
|
||||
AdmissionFrom = data.AdmissionFrom;
|
||||
AdmissionTo = data.AdmissionTo;
|
||||
ToComeIn = data.ToComeIn;
|
||||
Seq = data.Seq;
|
||||
AdmissionType = data.AdmissionType;
|
||||
Occupancy = data.Occupancy;
|
||||
DecisionToReferOn = data.DecisionToReferOn;
|
||||
ReferredOn = data.ReferredOn;
|
||||
DecisionToAdmitOn = data.DecisionToAdmitOn;
|
||||
BreechOn = data.BreechOn;
|
||||
PatientId = data.PatientId;
|
||||
PatientNo = data.PatientNo;
|
||||
NhsNumber = data.NhsNumber;
|
||||
Title = data.Title;
|
||||
Forename = data.Forename;
|
||||
Surname = data.Surname;
|
||||
Gender = data.Gender;
|
||||
BirthOn = data.BirthOn;
|
||||
Age = data.Age;
|
||||
AgeOn = data.AgeOn;
|
||||
FacilityIdWard = data.FacilityIdWard;
|
||||
Ward = data.Ward;
|
||||
ProcedureId = data.ProcedureId;
|
||||
SpecialityCode = data.SpecialityCode;
|
||||
ProcedureDesc = data.ProcedureDesc;
|
||||
ComplexityCode = data.ComplexityCode;
|
||||
ProcedureIndication = data.ProcedureIndication;
|
||||
PatientHistory = data.PatientHistory;
|
||||
GestationPeriod = data.GestationPeriod;
|
||||
SystemRef = data.SystemRef;
|
||||
DurationExp = data.DurationExp;
|
||||
DurationAct = data.DurationAct;
|
||||
UnitsExp = data.UnitsExp;
|
||||
UnitsAct = data.UnitsAct;
|
||||
Anaesthetic = data.Anaesthetic;
|
||||
Position = data.Position;
|
||||
SpecialEquipment = data.SpecialEquipment;
|
||||
AttendanceType = data.AttendanceType;
|
||||
AttendanceStatus = data.AttendanceStatus;
|
||||
ComfortScore = data.ComfortScore;
|
||||
TimeCalled = data.TimeCalled;
|
||||
TimeArrived = data.TimeArrived;
|
||||
TimeAnaesStart = data.TimeAnaesStart;
|
||||
TimeProcStart = data.TimeProcStart;
|
||||
TimeProcEnd = data.TimeProcEnd;
|
||||
TimeInRecovery = data.TimeInRecovery;
|
||||
TimeInformDest = data.TimeInformDest;
|
||||
TimeLeave = data.TimeLeave;
|
||||
CancelType = data.CancelType;
|
||||
CancelDate = data.CancelDate;
|
||||
CancelCount = data.CancelCount;
|
||||
CancelCode = data.CancelCode;
|
||||
CancelReason = data.CancelReason;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
public ValidValue FacilityId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue FacilityTemplateId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionFrom { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionTo { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ToComeIn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Seq { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Occupancy { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DecisionToReferOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ReferredOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DecisionToAdmitOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue BreechOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue PatientId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue PatientNo { get; set; } = ValidValue.Valid;
|
||||
public ValidValue NhsNumber { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Title { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Forename { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Surname { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Gender { get; set; } = ValidValue.Valid;
|
||||
public ValidValue BirthOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Age { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AgeOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue FacilityIdWard { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Ward { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ProcedureId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SpecialityCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ProcedureDesc { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ComplexityCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ProcedureIndication { get; set; } = ValidValue.Valid;
|
||||
public ValidValue PatientHistory { get; set; } = ValidValue.Valid;
|
||||
public ValidValue GestationPeriod { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SystemRef { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationExp { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationAct { get; set; } = ValidValue.Valid;
|
||||
public ValidValue UnitsExp { get; set; } = ValidValue.Valid;
|
||||
public ValidValue UnitsAct { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Anaesthetic { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Position { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SpecialEquipment { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AttendanceType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AttendanceStatus { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ComfortScore { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeCalled { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeArrived { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeAnaesStart { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeProcStart { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeProcEnd { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeInRecovery { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeInformDest { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TimeLeave { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CancelType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CancelDate { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CancelCount { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CancelCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CancelReason { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
public static readonly ushort Flag_HasRisk = 0x01;
|
||||
public static readonly ushort Flag_HighlightNotes = 0x02;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmAdmission(SysId facilityId, SysId facilityTemplateId) : base()
|
||||
{
|
||||
facilityId = FacilityId;
|
||||
facilityTemplateId = FacilityTemplateId;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> admissionStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> AdmissionStatuses { get { return new List<SaStatus>(admissionStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
admissionStatuses.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 FacilityId
|
||||
{
|
||||
get { return data.FacilityId; }
|
||||
set { CheckChanged(data.FacilityId, value); data.FacilityId = value; }
|
||||
}
|
||||
public SysId FacilityTemplateId
|
||||
{
|
||||
get { return data.FacilityTemplateId; }
|
||||
set { CheckChanged(data.FacilityTemplateId, value); data.FacilityTemplateId = value; }
|
||||
}
|
||||
public DateTime AdmissionFrom
|
||||
{
|
||||
get { return data.AdmissionFrom; }
|
||||
set { CheckChanged(data.AdmissionFrom, value); data.AdmissionFrom = value; }
|
||||
}
|
||||
public DateTime AdmissionTo
|
||||
{
|
||||
get { return data.AdmissionTo; }
|
||||
set { CheckChanged(data.AdmissionTo, value); data.AdmissionTo = value; }
|
||||
}
|
||||
public DateTime ToComeIn
|
||||
{
|
||||
get { return data.ToComeIn; }
|
||||
set { CheckChanged(data.ToComeIn, value); data.ToComeIn = value; }
|
||||
}
|
||||
public static bool RequiresSeq(Spm.AdmissionType admissionType)
|
||||
{
|
||||
switch (admissionType)
|
||||
{
|
||||
// Ward and clinic admission do not require a sequence.
|
||||
case Spm.AdmissionType.WardAdmission:
|
||||
case Spm.AdmissionType.WardReservation:
|
||||
case Spm.AdmissionType.ClinicBooking:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public ushort Seq
|
||||
{
|
||||
get { return data.Seq; }
|
||||
set { CheckChanged(data.Seq, value); data.Seq = value; }
|
||||
}
|
||||
public Spm.AdmissionType AdmissionType
|
||||
{
|
||||
get { return data.AdmissionType; }
|
||||
set { CheckChanged((int)data.AdmissionType, (int)value); data.AdmissionType = value; }
|
||||
}
|
||||
public Spm.AdmissionOccupancy Occupancy
|
||||
{
|
||||
get { return data.Occupancy; }
|
||||
set { CheckChanged((int)data.Occupancy, (int)value); data.Occupancy = value; }
|
||||
}
|
||||
|
||||
public bool IsTheatreAdmission()
|
||||
{
|
||||
switch (AdmissionType)
|
||||
{
|
||||
case Spm.AdmissionType.TheatreDayCase:
|
||||
case Spm.AdmissionType.TheatreInPatientElective:
|
||||
case Spm.AdmissionType.TheatreEmergency:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool IsClinicAdmission()
|
||||
{
|
||||
switch (AdmissionType)
|
||||
{
|
||||
case Spm.AdmissionType.ClinicBooking:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool IsWardAdmission()
|
||||
{
|
||||
switch (AdmissionType)
|
||||
{
|
||||
case Spm.AdmissionType.WardAdmission:
|
||||
case Spm.AdmissionType.WardReservation:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public DateTime DecisionToReferOn
|
||||
{
|
||||
get { return data.DecisionToReferOn; }
|
||||
set { CheckChanged(data.DecisionToReferOn, value); data.DecisionToReferOn = value; }
|
||||
}
|
||||
public DateTime ReferredOn
|
||||
{
|
||||
get { return data.ReferredOn; }
|
||||
set { CheckChanged(data.ReferredOn, value); data.ReferredOn = value; }
|
||||
}
|
||||
public DateTime DecisionToAdmitOn
|
||||
{
|
||||
get { return data.DecisionToAdmitOn; }
|
||||
set { CheckChanged(data.DecisionToAdmitOn, value); data.DecisionToAdmitOn = value; }
|
||||
}
|
||||
public DateTime BreechOn
|
||||
{
|
||||
get { return data.BreechOn; }
|
||||
set { CheckChanged(data.BreechOn, value); data.BreechOn = value; }
|
||||
}
|
||||
public SysId PatientId
|
||||
{
|
||||
get { return data.PatientId; }
|
||||
set { CheckChanged(data.PatientId, value); data.PatientId = value; }
|
||||
}
|
||||
public String PatientNo
|
||||
{
|
||||
get { return data.PatientNo; }
|
||||
set { CheckChanged(data.PatientNo, value); data.PatientNo = value; }
|
||||
}
|
||||
public String NhsNumber
|
||||
{
|
||||
get { return data.NhsNumber; }
|
||||
set { CheckChanged(data.NhsNumber, value); data.NhsNumber = value; }
|
||||
}
|
||||
public String Title
|
||||
{
|
||||
get { return data.Title; }
|
||||
set { CheckChanged(data.Title, value); data.Title = value; }
|
||||
}
|
||||
public String Forename
|
||||
{
|
||||
get { return data.Forename; }
|
||||
set { CheckChanged(data.Forename, value); data.Forename = value; }
|
||||
}
|
||||
public String Surname
|
||||
{
|
||||
get { return data.Surname; }
|
||||
set { CheckChanged(data.Surname, value); data.Surname = value; }
|
||||
}
|
||||
public static String GetDisplayName(String surname, String forename, bool upperSurname = true)
|
||||
{
|
||||
String name = surname;
|
||||
if (upperSurname)
|
||||
name.ToUpper();
|
||||
if (!StringUtil.IsEmpty(surname) && !StringUtil.IsEmpty(forename))
|
||||
name += ", ";
|
||||
name += forename;
|
||||
return name;
|
||||
}
|
||||
public String GetDisplayName(bool upperSurname = true)
|
||||
{
|
||||
return GetDisplayName(Surname, Forename, upperSurname);
|
||||
}
|
||||
public Spm.Gender Gender
|
||||
{
|
||||
get { return data.Gender; }
|
||||
set { CheckChanged((int)data.Gender, (int)value); data.Gender = value; }
|
||||
}
|
||||
public DateTime BirthOn
|
||||
{
|
||||
get { return data.BirthOn; }
|
||||
set { CheckChanged(data.BirthOn, value); data.BirthOn = value; }
|
||||
}
|
||||
public String Age
|
||||
{
|
||||
get { return data.Age; }
|
||||
set { CheckChanged(data.Age, value); data.Age = value; }
|
||||
}
|
||||
public DateTime AgeOn
|
||||
{
|
||||
get { return data.AgeOn; }
|
||||
set { CheckChanged(data.AgeOn, value); data.AgeOn = value; }
|
||||
}
|
||||
public String GetPatientAge(DateTime dob, DateTime ageOn)
|
||||
{
|
||||
String patientAge = "";
|
||||
if (DateUtil.IsValid(dob) && DateUtil.IsValid(ageOn) && dob < ageOn)
|
||||
{
|
||||
/*ushort age = Date::CalculateAge(dob, ageOn);
|
||||
ushort ageMonths = Date::CalculateAgeMonths(dob, ageOn);
|
||||
if (age >= 2) patientAge = age.ToString();
|
||||
else if (ageMonths > 0) patientAge = ageMonths.ToString() + "M";*/
|
||||
}
|
||||
return patientAge;
|
||||
}
|
||||
public SysId FacilityIdWard
|
||||
{
|
||||
get { return data.FacilityIdWard; }
|
||||
set { CheckChanged(data.FacilityIdWard, value); data.FacilityIdWard = value; }
|
||||
}
|
||||
public String Ward
|
||||
{
|
||||
get { return data.Ward; }
|
||||
set { CheckChanged(data.Ward, value); data.Ward = value; }
|
||||
}
|
||||
public SysId ProcedureId
|
||||
{
|
||||
get { return data.ProcedureId; }
|
||||
set { CheckChanged(data.ProcedureId, value); data.ProcedureId = value; }
|
||||
}
|
||||
public String SpecialityCode
|
||||
{
|
||||
get { return data.SpecialityCode; }
|
||||
set { CheckChanged(data.SpecialityCode, value); data.SpecialityCode = value; }
|
||||
}
|
||||
public String ProcedureDesc
|
||||
{
|
||||
get { return data.ProcedureDesc; }
|
||||
set { CheckChanged(data.ProcedureDesc, value); data.ProcedureDesc = value; }
|
||||
}
|
||||
public String ComplexityCode
|
||||
{
|
||||
get { return data.ComplexityCode; }
|
||||
set { CheckChanged(data.ComplexityCode, value); data.ComplexityCode = value; }
|
||||
}
|
||||
public String ProcedureIndication
|
||||
{
|
||||
get { return data.ProcedureIndication; }
|
||||
set { CheckChanged(data.ProcedureIndication, value); data.ProcedureIndication = value; }
|
||||
}
|
||||
public String PatientHistory
|
||||
{
|
||||
get { return data.PatientHistory; }
|
||||
set { CheckChanged(data.PatientHistory, value); data.PatientHistory = value; }
|
||||
}
|
||||
public String GestationPeriod
|
||||
{
|
||||
get { return data.GestationPeriod; }
|
||||
set { CheckChanged(data.GestationPeriod, value); data.GestationPeriod = value; }
|
||||
}
|
||||
public String SystemRef
|
||||
{
|
||||
get { return data.SystemRef; }
|
||||
set { CheckChanged(data.SystemRef, value); data.SystemRef = value; }
|
||||
}
|
||||
public ushort DurationExp
|
||||
{
|
||||
get { return data.DurationExp; }
|
||||
set { CheckChanged(data.DurationExp, value); data.DurationExp = value; }
|
||||
}
|
||||
public ushort DurationAct
|
||||
{
|
||||
get { return data.DurationAct; }
|
||||
set { CheckChanged(data.DurationAct, value); data.DurationAct = value; }
|
||||
}
|
||||
public decimal UnitsExp
|
||||
{
|
||||
get { return data.UnitsExp; }
|
||||
set { CheckChanged(data.UnitsExp, value); data.UnitsExp = value; }
|
||||
}
|
||||
public decimal UnitsAct
|
||||
{
|
||||
get { return data.UnitsAct; }
|
||||
set { CheckChanged(data.UnitsAct, value); data.UnitsAct = value; }
|
||||
}
|
||||
public String Anaesthetic
|
||||
{
|
||||
get { return data.Anaesthetic; }
|
||||
set { CheckChanged(data.Anaesthetic, value); data.Anaesthetic = value; }
|
||||
}
|
||||
public String Position
|
||||
{
|
||||
get { return data.Position; }
|
||||
set { CheckChanged(data.Position, value); data.Position = value; }
|
||||
}
|
||||
public String SpecialEquipment
|
||||
{
|
||||
get { return data.SpecialEquipment; }
|
||||
set { CheckChanged(data.SpecialEquipment, value); data.SpecialEquipment = value; }
|
||||
}
|
||||
public Spm.AttendanceType AttendanceType
|
||||
{
|
||||
get { return data.AttendanceType; }
|
||||
set { CheckChanged((int)data.AttendanceType, (int)value); data.AttendanceType = value; }
|
||||
}
|
||||
public String AttendanceStatus
|
||||
{
|
||||
get { return data.AttendanceStatus; }
|
||||
set { CheckChanged(data.AttendanceStatus, value); data.AttendanceStatus = value; }
|
||||
}
|
||||
public String ComfortScore
|
||||
{
|
||||
get { return data.ComfortScore; }
|
||||
set { CheckChanged(data.ComfortScore, value); data.ComfortScore = value; }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Admission time.
|
||||
public DateTime TimeCalled
|
||||
{
|
||||
get { return data.TimeCalled; }
|
||||
set { CheckChanged(data.TimeCalled, value); data.TimeCalled = value; }
|
||||
}
|
||||
public DateTime TimeArrived
|
||||
{
|
||||
get { return data.TimeArrived; }
|
||||
set { CheckChanged(data.TimeArrived, value); data.TimeArrived = value; }
|
||||
}
|
||||
public DateTime TimeAnaesStart
|
||||
{
|
||||
get { return data.TimeAnaesStart; }
|
||||
set { CheckChanged(data.TimeAnaesStart, value); data.TimeAnaesStart = value; }
|
||||
}
|
||||
public DateTime TimeProcStart
|
||||
{
|
||||
get { return data.TimeProcStart; }
|
||||
set { CheckChanged(data.TimeProcStart, value); data.TimeProcStart = value; }
|
||||
}
|
||||
public DateTime TimeProcEnd
|
||||
{
|
||||
get { return data.TimeProcEnd; }
|
||||
set { CheckChanged(data.TimeProcEnd, value); data.TimeProcEnd = value; }
|
||||
}
|
||||
public DateTime TimeInRecovery
|
||||
{
|
||||
get { return data.TimeInRecovery; }
|
||||
set { CheckChanged(data.TimeInRecovery, value); data.TimeInRecovery = value; }
|
||||
}
|
||||
public DateTime TimeInformDest
|
||||
{
|
||||
get { return data.TimeInformDest; }
|
||||
set { CheckChanged(data.TimeInformDest, value); data.TimeInformDest = value; }
|
||||
}
|
||||
public DateTime TimeLeave
|
||||
{
|
||||
get { return data.TimeLeave; }
|
||||
set { CheckChanged(data.TimeLeave, value); data.TimeLeave = value; }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Cancellation.
|
||||
public Spm.AdmissionCancelType CancelType
|
||||
{
|
||||
get { return data.CancelType; }
|
||||
set { CheckChanged((int)data.CancelType, (int)value); data.CancelType = value; }
|
||||
}
|
||||
public DateTime CancelDate
|
||||
{
|
||||
get { return data.CancelDate; }
|
||||
set { CheckChanged(data.CancelDate, value); data.CancelDate = value; }
|
||||
}
|
||||
public ushort CancelCount
|
||||
{
|
||||
get { return data.CancelCount; }
|
||||
set { CheckChanged(data.CancelCount, value); data.CancelCount = value; }
|
||||
}
|
||||
public String CancelCode
|
||||
{
|
||||
get { return data.CancelCode; }
|
||||
set { CheckChanged(data.CancelCode, value); data.CancelCode = value; }
|
||||
}
|
||||
public String CancelReason
|
||||
{
|
||||
get { return data.CancelReason; }
|
||||
set { CheckChanged(data.CancelReason, value); data.CancelReason = value; }
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Flags.
|
||||
public bool HasRisk
|
||||
{
|
||||
get { return GetFlag(Flag_HasRisk); }
|
||||
set { SetFlag(Flag_HasRisk, value); }
|
||||
}
|
||||
public bool HighlightNotes
|
||||
{
|
||||
get { return GetFlag(Flag_HighlightNotes); }
|
||||
set { SetFlag(Flag_HighlightNotes, value); }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A s s o c i a t e d D a t a E l e m e n t s
|
||||
//-------------------------------------------------------------------
|
||||
// Admission Roles
|
||||
public bool HasRoles() { return HasRole(Spm.EmployeeRole.Unknown, ""); }
|
||||
public abstract bool HasRole(Spm.EmployeeRole admissionRole); // Any admission.
|
||||
public abstract bool HasRole(Spm.EmployeeRole admissionRole, String admissionCode); // Specific emloyee.
|
||||
public abstract List<SpmAdmissionRole> GetRoles();
|
||||
public abstract bool SetRoles(List<SpmAdmissionRole> admissionRoles); // Without commiting the changes.
|
||||
public abstract bool CommitRoles();
|
||||
|
||||
// Admission Action.
|
||||
public bool HasActions() { return HasAction(Spm.AdmissionActionType.Unknown); }
|
||||
public abstract bool HasAction(Spm.AdmissionActionType admissionActionType); // Any admission.
|
||||
public abstract bool GetActions();
|
||||
public abstract bool SetActions(); // Without commiting the changes.
|
||||
public abstract bool CommitActions();
|
||||
|
||||
|
||||
// Admission Data.
|
||||
public bool HasDatas() { return HasData(Spm.AdmissionDataType.Unknown); }
|
||||
public abstract bool HasData(Spm.AdmissionDataType admissionDataType); // Any admission.
|
||||
public abstract bool GetDatas();
|
||||
public abstract bool SetDatas(); // Without commiting the changes.
|
||||
public abstract bool CommitDatas();
|
||||
|
||||
public abstract List<String> GetProcedureKits();
|
||||
public abstract List<String> GetAllergies();
|
||||
public abstract List<String> GetRiskFactors();
|
||||
public abstract bool SetProcedureKits(List<String> procedures);
|
||||
public abstract bool SetAllergies(List<String> allergies);
|
||||
public abstract bool SetRiskFactors(List<String> riskFactors);
|
||||
|
||||
public abstract bool ClearAssociatedData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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.
|
||||
public DateTime Admission { get; set; }
|
||||
public DateTime AdmissionFrom { get; set; }
|
||||
public DateTime AdmissionTo { get; set; }
|
||||
public SysId DepartmentId { get; set; }
|
||||
public SysId FacilityId { get; set; }
|
||||
public SysId FacilityTemplateId { get; set; }
|
||||
public Spm.FacilityType FacilityType { get; set; }
|
||||
public int MaxSeq { get; set; }
|
||||
public int MinSeq { get; set; }
|
||||
public Spm.AdmissionCancelType CancelType { get; set; }
|
||||
public String PatientNoFull { get; set; }
|
||||
public String PatientNoPartial { get; set; }
|
||||
public String PatientSurname { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// A d m i s s i o n D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmAdmissionList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
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 SpmAdmissionAction : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
AdmissionId,
|
||||
Type,
|
||||
Type_Desc,
|
||||
// Admission details.
|
||||
Admission_FacilityId,
|
||||
Admission_TemplateId,
|
||||
AdmissionFrom,
|
||||
AdmissionFromDateTime,
|
||||
AdmissionFromDate,
|
||||
AdmissionFromTime,
|
||||
AdmissionTo,
|
||||
AdmissionToDate,
|
||||
AdmissionToTime,
|
||||
AdmissionType,
|
||||
AdmissionTypeDesc,
|
||||
AdmissionNotes,
|
||||
AdmissionFlags,
|
||||
AdmissionStatus,
|
||||
AdmissionStatusInd,
|
||||
// Admission patient details.
|
||||
Patient, // No & display name.
|
||||
PatientId,
|
||||
PatientNo,
|
||||
PatientSurname,
|
||||
PatientForename,
|
||||
// Facility:
|
||||
Facility_Name,
|
||||
Facility_Desc,
|
||||
Facility_Notes,
|
||||
// Facility Template.
|
||||
Template_Name,
|
||||
Template_Desc,
|
||||
Template_Notes,
|
||||
// Session definition (combined template and date-specific session info).
|
||||
SessionDfn_Summary,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = AdmissionActionStatus;
|
||||
}
|
||||
public SysId AdmissionId { get; set; }
|
||||
public Spm.AdmissionActionType AdmissionActionType { get; set; }
|
||||
public DateTime Raised { get; set; }
|
||||
public SysId EmployeeIdRaised { get; set; }
|
||||
public DateTime Completed { get; set; }
|
||||
public SysId EmployeeIdCompleted { get; set; }
|
||||
public String ActionData { get; set; }
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
AdmissionId = data.AdmissionId;
|
||||
AdmissionActionType = data.AdmissionActionType;
|
||||
Raised = data.Raised;
|
||||
EmployeeIdRaised = data.EmployeeIdRaised;
|
||||
Completed = data.Completed;
|
||||
EmployeeIdCompleted = data.EmployeeIdCompleted;
|
||||
ActionData = data.ActionData;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
public ValidValue AdmissionId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionActionType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Raised { get; set; } = ValidValue.Valid;
|
||||
public ValidValue EmployeeIdRaised { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Completed { get; set; } = ValidValue.Valid;
|
||||
public ValidValue EmployeeIdCompleted { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ActionData { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmAdmissionAction(SysId id, SysId admissionId, Spm.AdmissionActionType admissionActionType) : base(id)
|
||||
{
|
||||
id = Id;
|
||||
admissionId = AdmissionId;
|
||||
admissionActionType = AdmissionActionType;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> admissionActionStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> AdmissionActionStatuses { get { return new List<SaStatus>(admissionActionStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
admissionActionStatuses.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 { CheckChanged(data.AdmissionId, value); data.AdmissionId = value; }
|
||||
}
|
||||
public Spm.AdmissionActionType AdmissionActionType
|
||||
{
|
||||
get { return data.AdmissionActionType; }
|
||||
set { CheckChanged((int)data.AdmissionActionType, (int)value); data.AdmissionActionType = value; }
|
||||
}
|
||||
public DateTime Raised
|
||||
{
|
||||
get { return data.Raised; }
|
||||
set { CheckChanged(data.Raised, value); data.Raised = value; }
|
||||
}
|
||||
public SysId EmployeeIdRaised
|
||||
{
|
||||
get { return data.EmployeeIdRaised; }
|
||||
set { CheckChanged(data.EmployeeIdRaised, value); data.EmployeeIdRaised = value; }
|
||||
}
|
||||
public DateTime Completed
|
||||
{
|
||||
get { return data.Completed; }
|
||||
set { CheckChanged(data.Completed, value); data.Completed = value; }
|
||||
}
|
||||
public SysId EmployeeIdCompleted
|
||||
{
|
||||
get { return data.EmployeeIdCompleted; }
|
||||
set { CheckChanged(data.EmployeeIdCompleted, value); data.EmployeeIdCompleted = value; }
|
||||
}
|
||||
public String ActionData
|
||||
{
|
||||
get { return data.ActionData; }
|
||||
set { CheckChanged(data.ActionData, value); data.ActionData = value; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Flags.
|
||||
|
||||
|
||||
|
||||
public int Compare(SpmAdmissionAction action)
|
||||
{
|
||||
SaStatus status1 = new SaStatus();
|
||||
SaStatus status2 = action.Status;
|
||||
// 'Required' actions always occur earlier in the list.
|
||||
if (status1 == SaStatus.Required && status2 != SaStatus.Required) return -1;
|
||||
if (status1 != SaStatus.Required && status2 == SaStatus.Required) return 1;
|
||||
// Followed by 'Completed' actions.
|
||||
if (status1 == SaStatus.Completed && status2 != SaStatus.Completed) return -1;
|
||||
if (status1 != SaStatus.Completed && status2 == SaStatus.Completed) return 1;
|
||||
// Sort by 'Raised' date.
|
||||
int iCompareRaised = Raised.CompareTo(action.Raised);
|
||||
if (iCompareRaised != 0) return iCompareRaised;
|
||||
// Sort by type.
|
||||
if (AdmissionActionType < action.AdmissionActionType) return -1;
|
||||
if (AdmissionActionType > action.AdmissionActionType) return 1;
|
||||
return -1; // To retain previous sequence.
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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 Action.
|
||||
public SysId Id { get; set; }
|
||||
public SysId AdmissionId { get; set; }
|
||||
public SysId DepartmentId { get; set; }
|
||||
public SysId FacilityId { get; set; }
|
||||
public Spm.AdmissionActionType AdmissionActionType { get; set; }
|
||||
public DateTime Raised { get; set; }
|
||||
public SysId EmployeeIdRaised { get; set; }
|
||||
public DateTime Completed { get; set; }
|
||||
public SysId EmployeeIdCompleted { get; set; }
|
||||
public String ActionData { get; set; }
|
||||
public bool RequiredOnly { get; set; } = true;
|
||||
public bool ExcludeCancelled { get; set; } = true;
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// AdmissionAction D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmAdmissionActionList
|
||||
{
|
||||
public static int CompareByNameSeq(SpmAdmissionAction action1, SpmAdmissionAction action2)
|
||||
{
|
||||
if (action1 == null || action2 == null) return 0;
|
||||
return action1.Compare(action2);
|
||||
}
|
||||
public enum SortMode { SortActionRequiredRaised, };
|
||||
|
||||
public static void Sort(this List<SpmAdmissionAction> values, SortMode sortActionRequiredRaised, bool ascending = true)
|
||||
{
|
||||
if (sortActionRequiredRaised == SortMode.SortActionRequiredRaised)
|
||||
values.Sort
|
||||
(
|
||||
delegate (SpmAdmissionAction action1, SpmAdmissionAction action2)
|
||||
{
|
||||
return CompareByNameSeq(action1, action2);
|
||||
}
|
||||
);
|
||||
}
|
||||
public static bool SetIdentity(this List<SpmAdmissionAction> values, SpmAdmission admission)
|
||||
{
|
||||
foreach (SpmAdmissionAction admissionAction in values)
|
||||
admissionAction.AdmissionId = admission.Id;
|
||||
return true;
|
||||
}
|
||||
|
||||
// HasAction
|
||||
|
||||
// HasRequiredAction
|
||||
|
||||
public static bool Find(this List<SpmAdmissionAction> values, SpmAdmissionAction admissionAction)
|
||||
{
|
||||
if (admissionAction == null) return false;
|
||||
return (values.Find(item => item == admissionAction) != null);
|
||||
}
|
||||
public static bool FindById(this List<SpmAdmissionAction> values, SysId admissionActionId)
|
||||
{
|
||||
if (!SysId.IsValid(admissionActionId)) return false;
|
||||
return values.Exists(item => item.Id.Equals(admissionActionId));
|
||||
}
|
||||
public static bool FindByType(this List<SpmAdmissionAction> values, String admissionActionType)
|
||||
{
|
||||
if (StringUtil.IsEmpty(admissionActionType)) return false;
|
||||
return values.Exists(item => item.AdmissionActionType.ToString().EqualsCI(admissionActionType));
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
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 SpmAdmissionData : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
AdmissionId,
|
||||
Type,
|
||||
Type_Desc,
|
||||
AdmissionData,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flag,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = AdmissionDataStatus;
|
||||
}
|
||||
public SysId AdmissionId { get; set; }
|
||||
public Spm.AdmissionDataType AdmissionDataType { get; set; }
|
||||
public String AdmissionData { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
AdmissionId = data.AdmissionId;
|
||||
AdmissionDataType = data.AdmissionDataType;
|
||||
AdmissionData = data.AdmissionData;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
public ValidValue AdmissionId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionDataType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AdmissionData { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmAdmissionData(SysId admissionId, Spm.AdmissionDataType admissionDataType) : base()
|
||||
{
|
||||
admissionId = AdmissionId;
|
||||
admissionDataType = AdmissionDataType;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> admissionDataStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> AdmissionDataStatuses { get { return new List<SaStatus>(admissionDataStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
admissionDataStatuses.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 { CheckChanged(data.AdmissionId, value); data.AdmissionId = value; }
|
||||
}
|
||||
public Spm.AdmissionDataType AdmissionDataType
|
||||
{
|
||||
get { return data.AdmissionDataType; }
|
||||
set { CheckChanged((int)data.AdmissionDataType, (int)value); data.AdmissionDataType = value; }
|
||||
}
|
||||
public String AdmissionData
|
||||
{
|
||||
get { return data.AdmissionData; }
|
||||
set { CheckChanged(data.AdmissionData, value); data.AdmissionData = 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 Data.
|
||||
public SysId AdmissionId { get; set; }
|
||||
public Spm.AdmissionDataType AdmissionDataType { get; set; }
|
||||
public String AdmissionData { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// AdmissionData D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmAdmissionDataList
|
||||
{
|
||||
/// <summary>Check whether admission data exists/locate in list with specified Id.</summary>
|
||||
public static bool SetIdentity(this List<SpmAdmissionData> values, SpmAdmission admission)
|
||||
{
|
||||
foreach (SpmAdmissionData admissionData in values)
|
||||
admissionData.AdmissionId = admission.Id;
|
||||
return true;
|
||||
}
|
||||
public static bool Find(this List<SpmAdmissionData> values, SpmAdmissionData admissionData)
|
||||
{
|
||||
if (admissionData == null) return false;
|
||||
return (values.Find(item => item == admissionData) != null);
|
||||
}
|
||||
public static bool FindByType(this List<SpmAdmissionData> values, String admissionDataType)
|
||||
{
|
||||
if (StringUtil.IsEmpty(admissionDataType)) return false;
|
||||
return values.Exists(item => item.AdmissionDataType.ToString().EqualsCI(admissionDataType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
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,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = AdmissionRoleStatus;
|
||||
}
|
||||
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; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
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 { 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; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
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<SaStatus> departmentStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> DepartmentStatuses { get { return new List<SaStatus>(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; }
|
||||
}
|
||||
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
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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 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
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SpmEmployee : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
InstitutionId,
|
||||
EmployeeNo,
|
||||
Code,
|
||||
Initials,
|
||||
Title,
|
||||
Forename,
|
||||
Surname,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flag,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = EmployeeStatus;
|
||||
}
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String EmployeeNo { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String Initials { get; set; }
|
||||
public String Title { get; set; }
|
||||
public String Forename { get; set; }
|
||||
public String Surname { get; set; }
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
InstitutionId = data.InstitutionId;
|
||||
EmployeeNo = data.EmployeeNo;
|
||||
Code = data.Code;
|
||||
Initials = data.Initials;
|
||||
Title = data.Title;
|
||||
Forename = data.Forename;
|
||||
Surname = data.Surname;
|
||||
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 EmployeeNo { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Code { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Initials { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Title { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Forename { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Surname { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmEmployee(SysId id, SysId institutionId) : base()
|
||||
{
|
||||
institutionId = InstitutionId;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> employeeStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> EmployeeStatuses { get { return new List<SaStatus>(employeeStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
employeeStatuses.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 InstitutionId
|
||||
{
|
||||
get { return data.InstitutionId; }
|
||||
set { CheckChanged(data.InstitutionId, value); data.InstitutionId = value; }
|
||||
}
|
||||
public String EmployeeNo
|
||||
{
|
||||
get { return data.EmployeeNo; }
|
||||
set { CheckChanged(data.EmployeeNo, value); data.EmployeeNo = value; }
|
||||
}
|
||||
public String Code
|
||||
{
|
||||
get { return data.Code; }
|
||||
set { CheckChanged(data.Code, value); data.Code = value; }
|
||||
}
|
||||
public String Initials
|
||||
{
|
||||
get { return data.Initials; }
|
||||
set { CheckChanged(data.Initials, value); data.Initials = value; }
|
||||
}
|
||||
public String Title
|
||||
{
|
||||
get { return data.Title; }
|
||||
set { CheckChanged(data.Title, value); data.Title = value; }
|
||||
}
|
||||
public String Forename
|
||||
{
|
||||
get { return data.Forename; }
|
||||
set { CheckChanged(data.Forename, value); data.Forename = value; }
|
||||
}
|
||||
public String Surname
|
||||
{
|
||||
get { return data.Surname; }
|
||||
set { CheckChanged(data.Surname, value); data.Surname = value; }
|
||||
}
|
||||
public static String GetDisplayName(String surname, String forename, bool upperSurname = true)
|
||||
{
|
||||
String name = surname;
|
||||
if (upperSurname)
|
||||
name.ToUpper();
|
||||
if (!StringUtil.IsEmpty(surname) && !StringUtil.IsEmpty(forename))
|
||||
name += ", ";
|
||||
name += forename;
|
||||
return name;
|
||||
}
|
||||
public String GetDisplayName(bool upperSurname = true)
|
||||
{
|
||||
return GetDisplayName(Surname, Forename, upperSurname);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
// Employee.
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String EmployeeNo { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String Surname { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Employee D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmEmployeeList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
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 SpmEmployeeRole : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
DepartmentId,
|
||||
EmployeeId,
|
||||
Role,
|
||||
ApplicationFrom,
|
||||
ApplicationTo,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flag,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = EmployeeRoleStatus;
|
||||
}
|
||||
public SysId DepartmentId { get; set; }
|
||||
public SysId EmployeeId { get; set; }
|
||||
public Spm.EmployeeRole EmployeeRole { get; set; }
|
||||
public DateTime ApplicationFrom { get; set; }
|
||||
public DateTime ApplicationTo { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
DepartmentId = data.DepartmentId;
|
||||
EmployeeId = data.EmployeeId;
|
||||
EmployeeRole = data.EmployeeRole;
|
||||
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 DepartmentId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue EmployeeId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue EmployeeRole { 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();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmEmployeeRole(SysId departmentId, SysId employeeId, Spm.EmployeeRole employeeRole) : base()
|
||||
{
|
||||
departmentId = DepartmentId;
|
||||
employeeId = EmployeeId;
|
||||
employeeRole = EmployeeRole;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> employeeRoleStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> EmployeeRoleStatuses { get { return new List<SaStatus>(employeeRoleStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
employeeRoleStatuses.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 DepartmentId
|
||||
{
|
||||
get { return data.DepartmentId; }
|
||||
set { CheckChanged(data.DepartmentId, value); data.DepartmentId = value; }
|
||||
}
|
||||
public SysId EmployeeId
|
||||
{
|
||||
get { return data.EmployeeId; }
|
||||
set { CheckChanged(data.EmployeeId, value); data.EmployeeId = value; }
|
||||
}
|
||||
public Spm.EmployeeRole EmployeeRole
|
||||
{
|
||||
get { return data.EmployeeRole; }
|
||||
set { CheckChanged((int)data.EmployeeRole, (int)value); data.EmployeeRole = 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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
// EmployeeRole.
|
||||
public SysId DepartmentId { get; set; }
|
||||
public SysId EmployeeId { get; set; }
|
||||
public Spm.EmployeeRole EmployeeRole { get; set; }
|
||||
public String Surname { get; set; }
|
||||
public String Initials { get; set; }
|
||||
public DateTime ApplicationFrom { get; set; }
|
||||
public DateTime ApplicationTo { get; set; }
|
||||
public DateTime Application { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// EmployeeRole D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmEmployeeRoleList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
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,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = FacilityStatus;
|
||||
}
|
||||
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; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
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 ushort 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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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 { 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 BookingToFacility
|
||||
{
|
||||
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
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
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 SpmFacilitySession : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
// Facility columns.
|
||||
Facility_TypeDesc,
|
||||
Facility_Name,
|
||||
Facility_SortCode,
|
||||
Facility_Desc,
|
||||
Facility_TemplateMapTypeDesc,
|
||||
Facility_ApplicFrom,
|
||||
Facility_ApplicTo,
|
||||
Facility_Notes,
|
||||
// Template columns.
|
||||
Template_Id,
|
||||
Template_FacilityId,
|
||||
Template_WeekOfMonth,
|
||||
Template_DayOfWeek,
|
||||
Template_TypeDesc,
|
||||
Template_Name,
|
||||
Template_Desc,
|
||||
Template_ConsultantCode,
|
||||
Template_SpecialityCode,
|
||||
Template_ConsSpec,
|
||||
Template_StartTime,
|
||||
Template_FinishTime,
|
||||
Template_DurationTotal,
|
||||
Template_DurationInterval,
|
||||
Template_DurationMin,
|
||||
Template_DurationMax,
|
||||
Template_DurationBreaks,
|
||||
Template_UnitsExp,
|
||||
Template_ApplicFrom,
|
||||
Template_ApplicTo,
|
||||
Template_Notes,
|
||||
// Session columns.
|
||||
Session_Date,
|
||||
Session_Name,
|
||||
Session_Desc,
|
||||
Session_ConsultantCode,
|
||||
Session_SpecialityCode,
|
||||
Session_ConsSpec,
|
||||
Session_StartTime,
|
||||
Session_FinishTime,
|
||||
Session_DurationTotal, // Total duration specifically for the session.
|
||||
Session_DurationInterval,
|
||||
Session_DurationMin,
|
||||
Session_DurationMax,
|
||||
Session_DurationBreaks,
|
||||
Session_UnitsExp,
|
||||
Session_Overrides,
|
||||
Session_Flags,
|
||||
Session_Unavailable,
|
||||
Session_Notes,
|
||||
// Derived session columns - template value if session not present.
|
||||
Session_Duration_Total, // Total duration for template or session if specified.
|
||||
Session_Duration_Breaks,
|
||||
Session_Duration_Session, // Total session time - breaks.
|
||||
Session_Admissions_Duration_Total, // Booked mins - discharge time - admission time.
|
||||
Session_Admissions_Duration_BlankPatientNo,
|
||||
Session_Admissions_DurationExp,
|
||||
Session_Admissions_DurationAct,
|
||||
Session_Admissions_Duration_Util,
|
||||
Session_Admissions_UnitsExp_Total,
|
||||
Session_Admissions_UnitsExp_Util,
|
||||
Session_Available_Mins,
|
||||
Session_Admissions_LateCancelled, // Includes bookings cancelled, deleted and moved sicne previous day.
|
||||
Session_Booked_Percent_Total,
|
||||
Session_Booked_Percent_Util,
|
||||
Session_Slots_Capacity_Min,
|
||||
Session_Slots_Capacity_Int,
|
||||
Session_Slots_Capacity_Maj,
|
||||
Session_Slots_Booked_Total,
|
||||
Session_Slots_Booked_Min,
|
||||
Session_Slots_Booked_Int,
|
||||
Session_Slots_Booked_Maj,
|
||||
Session_Slots_Booked_Other,
|
||||
Session_Slots_Booked_Percent,
|
||||
Session_Slots_Avail_Total,
|
||||
Session_Slots_Avail_Min,
|
||||
Session_Slots_Avail_Int,
|
||||
Session_Slots_Avail_Maj,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = FacilitySessionStatus;
|
||||
}
|
||||
public SysId FacilityId{ get; set; }
|
||||
public SysId FacilityTemplateId{ get; set; }
|
||||
public DateTime SessionDate{ get; set; }
|
||||
public Spm.TemplateType TemplateType { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String Desc { get; set; }
|
||||
public String SessionCode{ get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime FinishTime { get; set; }
|
||||
// Ward resources & Clinic sessions.
|
||||
public Spm.ResourceCapacityType ResourceCapacityType { get; set; }
|
||||
public short CapacityMin { get; set; }
|
||||
public short CapacityMax { get; set; }
|
||||
public decimal UnitsExp { get; set; }
|
||||
public short DurationInterval { get; set; }
|
||||
public short DurationMin { get; set; }
|
||||
public short DurationMax { get; set; }
|
||||
public short DurationBreaks { get; set; }
|
||||
// Theatre & Clinic sessions.
|
||||
public SysId ConsultantId{ get; set; }
|
||||
public String ConsultantCode{ get; set; }
|
||||
public String SpecialityCode{ get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
FacilityId = data.FacilityId;
|
||||
FacilityTemplateId = data.FacilityTemplateId;
|
||||
SessionDate = data.SessionDate;
|
||||
TemplateType = data.TemplateType;
|
||||
Name = data.Name;
|
||||
Desc = data.Desc;
|
||||
SessionCode = data.SessionCode;
|
||||
StartTime = data.StartTime;
|
||||
FinishTime = data.FinishTime;
|
||||
ResourceCapacityType = data.ResourceCapacityType;
|
||||
CapacityMin = data.CapacityMin;
|
||||
CapacityMax = data.CapacityMax;
|
||||
UnitsExp = data.UnitsExp;
|
||||
DurationInterval = data.DurationInterval;
|
||||
DurationMin = data.DurationMin;
|
||||
DurationMax = data.DurationMax;
|
||||
DurationBreaks = data.DurationBreaks;
|
||||
ConsultantId = data.ConsultantId;
|
||||
ConsultantCode = data.ConsultantCode;
|
||||
SpecialityCode = data.SpecialityCode;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
public ValidValue FacilityId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue FacilityTemplateId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SessionDate { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TemplateType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Name { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Desc { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SessionCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue StartTime { get; set; } = ValidValue.Valid;
|
||||
public ValidValue FinishTime { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ResourceCapacityType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CapacityMin { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CapacityMax { get; set; } = ValidValue.Valid;
|
||||
public ValidValue UnitsExp { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationInterval { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationMin { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationMax { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationBreaks { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ConsultantId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ConsultantCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SpecialityCode { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
public static readonly ushort Flag_NotAvailable = 0x01;
|
||||
public static readonly ushort Flag_HideTemplateNotes = 0x02;
|
||||
public static readonly ushort Flag_HighlightSessionNotes = 0x03;
|
||||
public static readonly ushort Flag_Finalised = 0x04;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmFacilitySession(SysId facilityId, SysId facilityTemplateId, DateTime sessionDate) : base()
|
||||
{
|
||||
facilityId = FacilityId;
|
||||
facilityTemplateId = FacilityTemplateId;
|
||||
sessionDate = SessionDate;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> facilitySessionStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> FacilitySessionStatuses { get { return new List<SaStatus>(facilitySessionStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
facilitySessionStatuses.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 FacilityId
|
||||
{
|
||||
get { return data.FacilityId; }
|
||||
set { CheckChanged(data.FacilityId, value); data.FacilityId = value; }
|
||||
}
|
||||
public SysId FacilityTemplateId
|
||||
{
|
||||
get { return data.FacilityTemplateId; }
|
||||
set { CheckChanged(data.FacilityTemplateId, value); data.FacilityTemplateId = value; }
|
||||
}
|
||||
public DateTime SessionDate
|
||||
{
|
||||
get { return data.SessionDate; }
|
||||
set { CheckChanged(data.SessionDate, value); data.SessionDate = value; }
|
||||
}
|
||||
public Spm.TemplateType TemplateType
|
||||
{
|
||||
get { return data.TemplateType; }
|
||||
set { CheckChanged((int)data.TemplateType, (int)value); data.TemplateType = value; }
|
||||
}
|
||||
public String Name
|
||||
{
|
||||
get { return data.Name; }
|
||||
set { CheckChanged(data.Name, value); data.Name = value; }
|
||||
}
|
||||
public String Description
|
||||
{
|
||||
get { return data.Desc; }
|
||||
set { CheckChanged(data.Desc, value); data.Desc = value; }
|
||||
}
|
||||
public String SessionCode
|
||||
{
|
||||
get { return data.SessionCode; }
|
||||
set { CheckChanged(data.SessionCode, value); data.SessionCode = value; }
|
||||
}
|
||||
public DateTime StartTime
|
||||
{
|
||||
get { return data.StartTime; }
|
||||
set { CheckChanged(data.StartTime, value); data.StartTime = value; }
|
||||
}
|
||||
public DateTime FinishTime
|
||||
{
|
||||
get { return data.FinishTime; }
|
||||
set { CheckChanged(data.FinishTime, value); data.FinishTime = value; }
|
||||
}
|
||||
public Spm.ResourceCapacityType ResourceCapacityType
|
||||
{
|
||||
get { return data.ResourceCapacityType; }
|
||||
set { CheckChanged((int)data.ResourceCapacityType, (int)value); data.ResourceCapacityType = value; }
|
||||
}
|
||||
public short CapacityMin
|
||||
{
|
||||
get { return data.CapacityMin; }
|
||||
set { CheckChanged(data.CapacityMin, value); data.CapacityMin = value; }
|
||||
}
|
||||
public short CapacityMax
|
||||
{
|
||||
get { return data.CapacityMax; }
|
||||
set { CheckChanged(data.CapacityMax, value); data.CapacityMax = value; }
|
||||
}
|
||||
public decimal UnitsExp
|
||||
{
|
||||
get { return data.UnitsExp; }
|
||||
set { CheckChanged(data.UnitsExp, value); data.UnitsExp = value; }
|
||||
}
|
||||
public static ushort GetDurationIntervalDefault()
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
public short DurationInterval
|
||||
{
|
||||
get { return data.DurationInterval; }
|
||||
set { CheckChanged(data.DurationInterval, value); data.DurationInterval = value; }
|
||||
}
|
||||
public short DurationMin
|
||||
{
|
||||
get { return data.DurationMin; }
|
||||
set { CheckChanged(data.DurationMin, value); data.DurationMin = value; }
|
||||
}
|
||||
public short DurationMax
|
||||
{
|
||||
get { return data.DurationMax; }
|
||||
set { CheckChanged(data.DurationMax, value); data.DurationMax = value; }
|
||||
}
|
||||
public short DurationBreaks
|
||||
{
|
||||
get { return data.DurationBreaks; }
|
||||
set { CheckChanged(data.DurationBreaks, value); data.DurationBreaks = value; }
|
||||
}
|
||||
public SysId ConsultantId
|
||||
{
|
||||
get { return data.ConsultantId; }
|
||||
set { CheckChanged(data.ConsultantId, value); data.ConsultantId = value; }
|
||||
}
|
||||
public String ConsultantCode
|
||||
{
|
||||
get { return data.ConsultantCode; }
|
||||
set { CheckChanged(data.ConsultantCode, value); data.ConsultantCode = value; }
|
||||
}
|
||||
public String SpecialityCode
|
||||
{
|
||||
get { return data.SpecialityCode; }
|
||||
set { CheckChanged(data.SpecialityCode, value); data.SpecialityCode = value; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Flags.
|
||||
public bool NotAvailable
|
||||
{
|
||||
get { return GetFlag(Flag_NotAvailable); }
|
||||
set { SetFlag(Flag_NotAvailable, value); }
|
||||
}
|
||||
public bool HideTemplateNotes
|
||||
{
|
||||
get { return GetFlag(Flag_HideTemplateNotes); }
|
||||
set { SetFlag(Flag_HideTemplateNotes, value); }
|
||||
}
|
||||
public bool HighlightSessionNotes
|
||||
{
|
||||
get { return GetFlag(Flag_HighlightSessionNotes); }
|
||||
set { SetFlag(Flag_HighlightSessionNotes, value); }
|
||||
}
|
||||
public bool Finalised
|
||||
{
|
||||
get { return GetFlag(Flag_Finalised); }
|
||||
set { SetFlag(Flag_Finalised, value); }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
// FacilitySession.
|
||||
public SysId FacilityId { get; set; }
|
||||
public SysId FacilityTemplateId { get; set; }
|
||||
public DateTime SessionFrom { get; set; }
|
||||
public DateTime SessionTo { get; set; }
|
||||
|
||||
public DateTime Admission { get; set; }
|
||||
/*public DateTime AdmissionFrom { get; set; }
|
||||
public DateTime AdmissionTo { get; set; }
|
||||
public SysId DepartmentId { get; set; }
|
||||
public SysId FacilityId { get; set; }
|
||||
public SysId FacilityTemplate { get; set; }
|
||||
public Spm.FacilityType FacilityType { get; set; }
|
||||
int iMaxSeq, iMinSeq{ get; set; }
|
||||
eSwmAdmissionCancelType eCancelType{ get; set; }
|
||||
String sPatientNoFull, sPatientNoPartial, sPatientSurname{ get; set; }*/
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// FacilitySession D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmFacilitySessionList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
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 SpmFacilityTemplate : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
Category,
|
||||
Type,
|
||||
Sort,
|
||||
Group,
|
||||
Name,
|
||||
Desc,
|
||||
CapacityType,
|
||||
WeekOfMonth,
|
||||
DayOfWeek,
|
||||
Consultant,
|
||||
Speciality,
|
||||
UnitsExp,
|
||||
DurationInterval,
|
||||
DurationMin,
|
||||
DurationMax,
|
||||
DurationBreaks,
|
||||
SlotsMin,
|
||||
SlotsInt,
|
||||
SlotsMaj,
|
||||
Start,
|
||||
Finish,
|
||||
Notes,
|
||||
ApplicFrom,
|
||||
ApplicTo,
|
||||
|
||||
// Common properties.
|
||||
//Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = FacilityTemplateStatus;
|
||||
}
|
||||
public SysId FacilityId { get; set; }
|
||||
public Spm.ResourceCategory ResourceCategory { get; set; }
|
||||
public Spm.TemplateType TemplateType { get; set; }
|
||||
public String Name { get; set; }
|
||||
public String SortCode { get; set; }
|
||||
public String Desc { get; set; }
|
||||
public String SessionCode { get; set; }
|
||||
public String Group { get; set; }
|
||||
// Ward resources & Clinic sessions.
|
||||
public Spm.ResourceCapacityType ResourceCapacityType { get; set; }
|
||||
public ushort CapacityMin { get; set; }
|
||||
public ushort CapacityMax { get; set; }
|
||||
public decimal UnitsExp { get; set; }
|
||||
public ushort DurationInterval { get; set; }
|
||||
public ushort DurationMin { get; set; }
|
||||
public ushort DurationMax { get; set; }
|
||||
public ushort DurationBreaks { get; set; }
|
||||
// Theatre & Clinic sessions.
|
||||
public ushort WeekOfMonth { get; set; }
|
||||
public ushort DayOfWeek { get; set; }
|
||||
public SysId ConsultantId { get; set; } // Employee role.
|
||||
public String ConsultantCode { get; set; }
|
||||
public String SpecialityCode { get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime FinishTime { get; set; }
|
||||
public DateTime ApplicationFrom { get; set; }
|
||||
public DateTime ApplicationTo { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
FacilityId = data.FacilityId;
|
||||
ResourceCategory = data.ResourceCategory;
|
||||
TemplateType = data.TemplateType;
|
||||
Name = data.Name;
|
||||
SortCode = data.SortCode;
|
||||
Desc = data.Desc;
|
||||
SessionCode = data.SessionCode;
|
||||
Group = data.Group;
|
||||
ResourceCapacityType = data.ResourceCapacityType;
|
||||
CapacityMin = data.CapacityMin;
|
||||
CapacityMax = data.CapacityMax;
|
||||
UnitsExp = data.UnitsExp;
|
||||
DurationInterval = data.DurationInterval;
|
||||
DurationMin = data.DurationMin;
|
||||
DurationMax = data.DurationMax;
|
||||
DurationBreaks = data.DurationBreaks;
|
||||
WeekOfMonth = data.WeekOfMonth;
|
||||
DayOfWeek = data.DayOfWeek;
|
||||
ConsultantId = data.ConsultantId;
|
||||
ConsultantCode = data.ConsultantCode;
|
||||
SpecialityCode = data.SpecialityCode;
|
||||
StartTime = data.StartTime;
|
||||
FinishTime = data.FinishTime;
|
||||
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 FacilityId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ResourceCategory { get; set; } = ValidValue.Valid;
|
||||
public ValidValue TemplateType { 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 SessionCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Group { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ResourceCapacityType { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CapacityMin { get; set; } = ValidValue.Valid;
|
||||
public ValidValue CapacityMax { get; set; } = ValidValue.Valid;
|
||||
public ValidValue UnitsExp { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationInterval { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationMin { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationMax { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationBreaks { get; set; } = ValidValue.Valid;
|
||||
public ValidValue WeekOfMonth { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DayOfWeek { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ConsultantId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ConsultantCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SpecialityCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue StartTime { get; set; } = ValidValue.Valid;
|
||||
public ValidValue FinishTime { 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();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmFacilityTemplate(SysId facilityId, Spm.ResourceCategory resourceCategory) : base()
|
||||
{
|
||||
facilityId = FacilityId;
|
||||
resourceCategory = ResourceCategory;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> facilityTemplateStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> FacilityTemplateStatuses { get { return new List<SaStatus>(facilityTemplateStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
facilityTemplateStatuses.Add(SaStatus.Current);
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case SaStatus.Current:
|
||||
return DataValue.TriStateType.Green;
|
||||
}
|
||||
return DataValue.TriStateType.Unknown;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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 FacilityId
|
||||
{
|
||||
get { return data.FacilityId; }
|
||||
set { CheckChanged(data.FacilityId, value); data.FacilityId = value; }
|
||||
}
|
||||
public Spm.ResourceCategory ResourceCategory
|
||||
{
|
||||
get { return data.ResourceCategory; }
|
||||
set { CheckChanged((int)data.ResourceCategory, (int)value); data.ResourceCategory = value; }
|
||||
}
|
||||
public Spm.TemplateType TemplateType
|
||||
{
|
||||
get { return data.TemplateType; }
|
||||
set { CheckChanged((int)data.TemplateType, (int)value); data.TemplateType = 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 String SessionCode
|
||||
{
|
||||
get { return data.SessionCode; }
|
||||
set { CheckChanged(data.SessionCode, value); data.SessionCode = value; }
|
||||
}
|
||||
public String Group
|
||||
{
|
||||
get { return data.Group; }
|
||||
set { CheckChanged(data.Group, value); data.Group = value; }
|
||||
}
|
||||
// Ward resources & Clinic sessions.
|
||||
public Spm.ResourceCapacityType ResourceCapacityType
|
||||
{
|
||||
get { return data.ResourceCapacityType; }
|
||||
set { CheckChanged((int)data.ResourceCapacityType, (int)value); data.ResourceCapacityType = value; }
|
||||
}
|
||||
public ushort CapacityMin
|
||||
{
|
||||
get { return data.CapacityMin; }
|
||||
set { CheckChanged(data.CapacityMin, value); data.CapacityMin = value; }
|
||||
}
|
||||
public ushort CapacityMax
|
||||
{
|
||||
get { return data.CapacityMax; }
|
||||
set { CheckChanged(data.CapacityMax, value); data.CapacityMax = value; }
|
||||
}
|
||||
public decimal UnitsExp
|
||||
{
|
||||
get { return data.UnitsExp; }
|
||||
set { CheckChanged(data.UnitsExp, value); data.UnitsExp = value; }
|
||||
}
|
||||
public static ushort GetDurationIntervalDefault()
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
public ushort DurationInterval
|
||||
{
|
||||
get { return data.DurationInterval; }
|
||||
set { CheckChanged(data.DurationInterval, value); data.DurationInterval = value; }
|
||||
}
|
||||
public ushort DurationMin
|
||||
{
|
||||
get { return data.DurationMin; }
|
||||
set { CheckChanged(data.DurationMin, value); data.DurationMin = value; }
|
||||
}
|
||||
public ushort DurationMax
|
||||
{
|
||||
get { return data.DurationMax; }
|
||||
set { CheckChanged(data.DurationMax, value); data.DurationMax = value; }
|
||||
}
|
||||
public ushort DurationBreaks
|
||||
{
|
||||
get { return data.DurationBreaks; }
|
||||
set { CheckChanged(data.DurationBreaks, value); data.DurationBreaks = value; }
|
||||
}
|
||||
// Theatre & Clinic sessions.
|
||||
public ushort WeekOfMonth
|
||||
{
|
||||
get { return data.WeekOfMonth; }
|
||||
set { CheckChanged(data.WeekOfMonth, value); data.WeekOfMonth = value; }
|
||||
}
|
||||
public ushort DayOfWeek
|
||||
{
|
||||
get { return data.DayOfWeek; }
|
||||
set { CheckChanged(data.DayOfWeek, value); data.DayOfWeek = value; }
|
||||
}
|
||||
public SysId ConsultantId
|
||||
{
|
||||
get { return data.ConsultantId; }
|
||||
set { CheckChanged(data.ConsultantId, value); data.ConsultantId = value; }
|
||||
}
|
||||
public String ConsultantCode
|
||||
{
|
||||
get { return data.ConsultantCode; }
|
||||
set { CheckChanged(data.ConsultantCode, value); data.ConsultantCode = value; }
|
||||
}
|
||||
public String SpecialityCode
|
||||
{
|
||||
get { return data.SpecialityCode; }
|
||||
set { CheckChanged(data.SpecialityCode, value); data.SpecialityCode = value; }
|
||||
}
|
||||
public DateTime StartTime
|
||||
{
|
||||
get { return data.StartTime; }
|
||||
set { CheckChanged(data.StartTime, value); data.StartTime = value; }
|
||||
}
|
||||
public DateTime FinishTime
|
||||
{
|
||||
get { return data.FinishTime; }
|
||||
set { CheckChanged(data.FinishTime, value); data.FinishTime = 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.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
//FacilityTemplate.
|
||||
public DateTime ApplicationFrom { get; set; }
|
||||
public DateTime ApplicationTo { get; set; }
|
||||
public DateTime Application { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// FacilityTemplate D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmFacilityTemplateList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SpmInstitution : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
Name,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = InstitutionStatus;
|
||||
}
|
||||
public String Name { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
Name = data.Name;
|
||||
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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmInstitution(SysId id) : base(id)
|
||||
{
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> institutionStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> InstitutionStatuses { get { return new List<SaStatus>(institutionStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
institutionStatuses.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; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
// Institution.
|
||||
public String Name { get; set; }
|
||||
public String NamePartial { get; set; }
|
||||
public String NotesPartial { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Institution D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmInstitutionList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SpmOperation : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
InstitutionId,
|
||||
Code,
|
||||
Description,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = OperationStatus;
|
||||
}
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String Description { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
InstitutionId = data.InstitutionId;
|
||||
Code = data.Code;
|
||||
Description = data.Description;
|
||||
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 Code { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Description { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmOperation(SysId departmentId, SysId institionId) : base()
|
||||
{
|
||||
institionId = InstitutionId;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> operationStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> OperationStatuses { get { return new List<SaStatus>(operationStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
operationStatuses.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 InstitutionId
|
||||
{
|
||||
get { return data.InstitutionId; }
|
||||
set { CheckChanged(data.InstitutionId, value); data.InstitutionId = value; }
|
||||
}
|
||||
public String Code
|
||||
{
|
||||
get { return data.Code; }
|
||||
set { CheckChanged(data.Code, value); data.Code = value; }
|
||||
}
|
||||
public String Description
|
||||
{
|
||||
get { return data.Description; }
|
||||
set { CheckChanged(data.Description, value); data.Description = 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>();
|
||||
// Operation.
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String Code { get; set; }
|
||||
public String CodePartial { get; set; }
|
||||
public String Description { get; set; }
|
||||
public String DescriptionPartial { get; set; }
|
||||
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Operation D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmOperationList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
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 SpmPatient : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
InstitutionId,
|
||||
PatientNo,
|
||||
NhsNumber,
|
||||
Title,
|
||||
Forename,
|
||||
Surname,
|
||||
BirthOn,
|
||||
Age,
|
||||
AgeOn,
|
||||
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = PatientStatus;
|
||||
}
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String PatientNo { get; set; }
|
||||
public String NhsNumber { get; set; }
|
||||
public String Title { get; set; }
|
||||
public String Forename { get; set; }
|
||||
public String Surname { get; set; }
|
||||
public Spm.Gender Gender { get; set; }
|
||||
public DateTime BirthOn { get; set; }
|
||||
public String Age { get; set; }
|
||||
public DateTime AgeOn { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
InstitutionId = data.InstitutionId;
|
||||
PatientNo = data.PatientNo;
|
||||
NhsNumber = data.NhsNumber;
|
||||
Title = data.Title;
|
||||
Forename = data.Forename;
|
||||
Surname = data.Surname;
|
||||
Gender = data.Gender;
|
||||
BirthOn = data.BirthOn;
|
||||
Age = data.Age;
|
||||
AgeOn = data.AgeOn;
|
||||
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 PatientNo { get; set; } = ValidValue.Valid;
|
||||
public ValidValue NhsNumber { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Title { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Forename { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Surname { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Gender { get; set; } = ValidValue.Valid;
|
||||
public ValidValue BirthOn { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Age { get; set; } = ValidValue.Valid;
|
||||
public ValidValue AgeOn { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmPatient(SysId id, SysId institutionId) : base(id)
|
||||
{
|
||||
institutionId = InstitutionId;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> patientStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> PatientStatuses { get { return new List<SaStatus>(patientStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
patientStatuses.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 InstitutionId
|
||||
{
|
||||
get { return data.InstitutionId; }
|
||||
set { CheckChanged(data.InstitutionId, value); data.InstitutionId = value; }
|
||||
}
|
||||
public String PatientNo
|
||||
{
|
||||
get { return data.PatientNo; }
|
||||
set { CheckChanged(data.PatientNo, value); data.PatientNo = value; }
|
||||
}
|
||||
public String NhsNumber
|
||||
{
|
||||
get { return data.NhsNumber; }
|
||||
set { CheckChanged(data.NhsNumber, value); data.NhsNumber = value; }
|
||||
}
|
||||
public String Title
|
||||
{
|
||||
get { return data.Title; }
|
||||
set { CheckChanged(data.Title, value); data.Title = value; }
|
||||
}
|
||||
public String Forename
|
||||
{
|
||||
get { return data.Forename; }
|
||||
set { CheckChanged(data.Forename, value); data.Forename = value; }
|
||||
}
|
||||
public String Surname
|
||||
{
|
||||
get { return data.Surname; }
|
||||
set { CheckChanged(data.Surname, value); data.Surname = value; }
|
||||
}
|
||||
public static String GetDisplayName(String surname, String forename, bool upperSurname = true)
|
||||
{
|
||||
String name = surname;
|
||||
if (upperSurname)
|
||||
name.ToUpper();
|
||||
if (!StringUtil.IsEmpty(surname) && !StringUtil.IsEmpty(forename))
|
||||
name += ", ";
|
||||
name += forename;
|
||||
return name;
|
||||
}
|
||||
public String GetDisplayName(bool upperSurname = true)
|
||||
{
|
||||
return GetDisplayName(Surname, Forename, upperSurname);
|
||||
}
|
||||
public Spm.Gender Gender
|
||||
{
|
||||
get { return data.Gender; }
|
||||
set { CheckChanged((int)data.Gender, (int)value); data.Gender = value; }
|
||||
}
|
||||
public DateTime BirthOn
|
||||
{
|
||||
get { return data.BirthOn; }
|
||||
set { CheckChanged(data.BirthOn, value); data.BirthOn = value; }
|
||||
}
|
||||
public String Age
|
||||
{
|
||||
get { return data.Age; }
|
||||
set { CheckChanged(data.Age, value); data.Age = value; }
|
||||
}
|
||||
public DateTime AgeOn
|
||||
{
|
||||
get { return data.AgeOn; }
|
||||
set { CheckChanged(data.AgeOn, value); data.AgeOn = 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>();
|
||||
|
||||
// Patient.
|
||||
public SysId InstitutionId { get; set; }
|
||||
public String PatientNo { get; set; }
|
||||
public String Surname { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Patient D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmPatientList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SpmProcedure : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
Pos,
|
||||
Id,
|
||||
DepartmentId,
|
||||
OperationId,
|
||||
Description,
|
||||
SpecialityCode,
|
||||
ComplexityCode,
|
||||
Duration,
|
||||
Duration_Training,
|
||||
Units,
|
||||
Units_Training,
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = ProcedureStatus;
|
||||
}
|
||||
public SysId DepartmentId { get; set; } // Department.
|
||||
public SysId OperationId { get; set; } // Operation Id.
|
||||
public String OperationCode { get; set; } // Operation code.
|
||||
public String Description { get; set; }
|
||||
public String SpecialityCode { get; set; }
|
||||
public String ComplexityCode { get; set; }
|
||||
public short Duration { get; set; } // Minutes.
|
||||
public short DurationTraining { get; set; } // Minutes.
|
||||
public decimal Units { get; set; }
|
||||
public decimal UnitsTraining { get; set; }
|
||||
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
DepartmentId = data.DepartmentId;
|
||||
OperationId = data.OperationId;
|
||||
OperationCode = data.OperationCode;
|
||||
Description = data.Description;
|
||||
SpecialityCode = data.SpecialityCode;
|
||||
ComplexityCode = data.ComplexityCode;
|
||||
Duration = data.Duration;
|
||||
DurationTraining = data.DurationTraining;
|
||||
Units = data.Units;
|
||||
UnitsTraining = data.UnitsTraining;
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
public ValidValue DepartmentId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue OperationId { get; set; } = ValidValue.Valid;
|
||||
public ValidValue OperationCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Description { get; set; } = ValidValue.Valid;
|
||||
public ValidValue SpecialityCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue ComplexityCode { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Duration { get; set; } = ValidValue.Valid;
|
||||
public ValidValue DurationTraining { get; set; } = ValidValue.Valid;
|
||||
public ValidValue Units { get; set; } = ValidValue.Valid;
|
||||
public ValidValue UnitsTraining { get; set; } = ValidValue.Valid;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmProcedure(SysId procedureId, SysId departmentId) : base()
|
||||
{
|
||||
departmentId = DepartmentId;
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> procedureStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> ProcedureStatuses { get { return new List<SaStatus>(procedureStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
procedureStatuses.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 DepartmentId
|
||||
{
|
||||
get { return data.DepartmentId; }
|
||||
set { CheckChanged(data.DepartmentId, value); data.DepartmentId = value; }
|
||||
}
|
||||
public SysId OperationId
|
||||
{
|
||||
get { return data.OperationId; }
|
||||
set { CheckChanged(data.OperationId, value); data.OperationId = value; }
|
||||
}
|
||||
public String OperationCode
|
||||
{
|
||||
get { return data.OperationCode; }
|
||||
set { CheckChanged(data.OperationCode, value); data.OperationCode = value; }
|
||||
}
|
||||
public String Description
|
||||
{
|
||||
get { return data.Description; }
|
||||
set { CheckChanged(data.Description, value); data.Description = value; }
|
||||
}
|
||||
public String SpecialityCode
|
||||
{
|
||||
get { return data.SpecialityCode; }
|
||||
set { CheckChanged(data.SpecialityCode, value); data.SpecialityCode = value; }
|
||||
}
|
||||
public String ComplexityCode
|
||||
{
|
||||
get { return data.ComplexityCode; }
|
||||
set { CheckChanged(data.ComplexityCode, value); data.ComplexityCode = value; }
|
||||
}
|
||||
public short Duration
|
||||
{
|
||||
get { return data.Duration; }
|
||||
set { CheckChanged(data.Duration, value); data.Duration = value; }
|
||||
}
|
||||
public short DurationTraining
|
||||
{
|
||||
get { return data.DurationTraining; }
|
||||
set { CheckChanged(data.DurationTraining, value); data.DurationTraining = value; }
|
||||
}
|
||||
public decimal Units
|
||||
{
|
||||
get { return data.Units; }
|
||||
set { CheckChanged(data.Units, value); data.Units = value; }
|
||||
}
|
||||
public decimal UnitsTraining
|
||||
{
|
||||
get { return data.UnitsTraining; }
|
||||
set { CheckChanged(data.UnitsTraining, value); data.UnitsTraining = 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>();
|
||||
// Procedure.
|
||||
public SysId OperationId { get; set; }
|
||||
public String OperationCode { get; set; }
|
||||
public String Description { get; set; }
|
||||
public String SpecialityCode { get; set; }
|
||||
public String ComplexityCode { get; set; }
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// Procedure D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmProcedureList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SpmTemplateData : SacsHierarchyItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public enum Column
|
||||
{
|
||||
// Common properties.
|
||||
Notes,
|
||||
Flags,
|
||||
Status,
|
||||
Status_Ind,
|
||||
Status_Desc,
|
||||
CreateOn_Date,
|
||||
UpdateOn_Date,
|
||||
}
|
||||
|
||||
// Data.
|
||||
public new class Data : SacsHierarchyItem.Data
|
||||
{
|
||||
public Data()
|
||||
{
|
||||
//Status = TemplateDataStatus;
|
||||
}
|
||||
internal void PopulateFrom(Data data)
|
||||
{
|
||||
base.PopulateFrom(data);
|
||||
}
|
||||
public Data Clone()
|
||||
{
|
||||
Data data = new Data();
|
||||
data.PopulateFrom(this);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// ErrField.
|
||||
public new class ErrField : SacsHierarchyItem.ErrField
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly Data data = new Data();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SpmTemplateData(SysId id) : base(id)
|
||||
{
|
||||
Status = DefaultStatus;
|
||||
base.SetData(data);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Status.
|
||||
private static readonly List<SaStatus> templateDataStatuses = new List<SaStatus>()
|
||||
{
|
||||
SaStatus.Current,
|
||||
};
|
||||
public static SaStatus DefaultStatus { get { return SaStatus.Current; } }
|
||||
public static List<SaStatus> TemplateDataStatuses { get { return new List<SaStatus>(templateDataStatuses); } }
|
||||
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
||||
{
|
||||
templateDataStatuses.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.
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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>();
|
||||
// ###.
|
||||
|
||||
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
// TemplateData D a t a L i s t
|
||||
//=======================================================================
|
||||
public static class SpmTemplateDataList
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual admission.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist admission.
|
||||
public abstract bool AdmissionExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get admission.
|
||||
public abstract SpmAdmission GetAdmission(SpmAdmission.Params prm);
|
||||
public abstract SpmAdmission GetAdmissionById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create admission.
|
||||
public abstract SpmAdmission CreateAdmission(SysId facilityId, SysId facilityTemplateId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate admission data.
|
||||
public bool IsValidAdmission(SpmAdmission admission)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (admission == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidAdmissionData(admission.GetData(), new SpmAdmission.ErrField());
|
||||
}
|
||||
public virtual bool IsValidAdmissionData(SpmAdmission.Data data, SpmAdmission.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Admission properties.
|
||||
if (errField.FacilityId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.FacilityId))
|
||||
{
|
||||
errField.FacilityId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid facility Id");
|
||||
}
|
||||
if (errField.AdmissionFrom != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.AdmissionFrom))
|
||||
{
|
||||
errField.AdmissionFrom = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("'From' date not specified");
|
||||
}
|
||||
if (errField.AdmissionTo != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.AdmissionTo))
|
||||
{
|
||||
errField.AdmissionTo = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("'To' date not specified");
|
||||
}
|
||||
if (errField.ToComeIn != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.ToComeIn))
|
||||
{
|
||||
if (data.ToComeIn > data.AdmissionFrom) return SetErrorState("'TCI' cannot be after the admission date/time");
|
||||
errField.ToComeIn = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.AdmissionType != SacsHierarchyItem.ValidValue.Ignore && (short)data.AdmissionType < 1)
|
||||
{
|
||||
if ((int)data.AdmissionType < 1)
|
||||
{
|
||||
errField.AdmissionType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Admission type must be supplied");
|
||||
}
|
||||
}
|
||||
|
||||
bool patientEntered = !StringUtil.IsEmpty(data.PatientNo) || !StringUtil.IsEmpty(data.Surname) || !StringUtil.IsEmpty(data.Forename) || !StringUtil.IsEmpty(data.Age);
|
||||
|
||||
if (errField.PatientNo != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.PatientNo, "PatientNo", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_PatientNo), true))
|
||||
{
|
||||
errField.PatientNo = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.NhsNumber != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.NhsNumber, "NhsNumber", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_NhsNumber), true))
|
||||
{
|
||||
errField.NhsNumber = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Title != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Title, "Title", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Title), true))
|
||||
{
|
||||
errField.Title = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Forename != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Forename, "Forename", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Forename), true))
|
||||
{
|
||||
errField.Forename = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Surname != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Surname, "Surname", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Surname), patientEntered))
|
||||
{
|
||||
errField.Surname = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Age != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Age, "Age", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Age), true))
|
||||
{
|
||||
errField.Age = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Ward != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Ward, "Ward", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Ward), true))
|
||||
{
|
||||
errField.Ward = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SpecialityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SpecialityCode, "SpecialityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_SpecialityCode), true))
|
||||
{
|
||||
errField.SpecialityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ProcedureDesc != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ProcedureDesc, "ProcedureDesc", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_ProcedureDesc), true))
|
||||
{
|
||||
errField.ProcedureDesc = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ComplexityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ComplexityCode, "ComplexityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_ComplexityCode), true))
|
||||
{
|
||||
errField.ComplexityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ProcedureIndication != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ProcedureIndication, "ProcedureIndication", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_ProcedureIndication), true))
|
||||
{
|
||||
errField.ProcedureIndication = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.GestationPeriod != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.GestationPeriod, "GestationPeriod", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_GestationPeriod), true))
|
||||
{
|
||||
errField.GestationPeriod = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SystemRef != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SystemRef, "SystemRef", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_SystemRef), true))
|
||||
{
|
||||
errField.SystemRef = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Anaesthetic != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Anaesthetic, "Anaesthetic", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Anaesthetic), true))
|
||||
{
|
||||
errField.Anaesthetic = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Position != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Position, "Position", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Position), true))
|
||||
{
|
||||
errField.Position = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SpecialEquipment != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SpecialEquipment, "SpecialEquipment", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_SpecialEquipment), true))
|
||||
{
|
||||
errField.SpecialEquipment = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.AttendanceStatus != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.AttendanceStatus, "AttendanceStatus", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_AttendanceStatus), true))
|
||||
{
|
||||
errField.AttendanceStatus = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ComfortScore != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ComfortScore, "ComfortScore", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_ComfortScore), true))
|
||||
{
|
||||
errField.ComfortScore = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.CancelCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CancelCode, "CancelCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_CancelCode), true))
|
||||
{
|
||||
errField.CancelCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.CancelReason != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CancelReason, "CancelReason", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_CancelReason), true))
|
||||
{
|
||||
errField.CancelReason = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmission_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmAdmission.AdmissionStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Admission database interface.
|
||||
public abstract bool InsertAdmission(SpmAdmission admission, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateAdmission(SpmAdmission admission, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool AdmissionCanBeDeleted(SpmAdmission admission)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteAdmission(SpmAdmission admission, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Admission list.
|
||||
public abstract ColumnDfn GetAdmissionColumnDfn(SpmAdmission.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetAdmissionQueryFilter(SpmAdmission.Params prm);
|
||||
public abstract long GetAdmissionCount(SpmAdmission.Params prm);
|
||||
public abstract List<SpmAdmission> GetAdmissionList(SpmAdmission.Params prm);
|
||||
public abstract DbResultSet ExecuteAdmissionQuery(List<ColumnDfn> columns, SpmAdmission.Params prm);
|
||||
public abstract DataValue GetAdmissionDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n A c t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual admissionAction.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist admissionAction.
|
||||
public abstract bool AdmissionActionExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get admissionAction.
|
||||
public abstract SpmAdmissionAction GetAdmissionAction(SpmAdmissionAction.Params prm);
|
||||
public abstract SpmAdmissionAction GetAdmissionActionById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create admissionAction.
|
||||
public abstract SpmAdmissionAction CreateAdmissionAction(SysId admissionId, Spm.AdmissionActionType admissionActionType);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate admissionAction data.
|
||||
public bool IsValidAdmissionAction(SpmAdmissionAction admissionAction)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (admissionAction == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidAdmissionActionData(admissionAction.GetData(), new SpmAdmissionAction.ErrField());
|
||||
}
|
||||
public virtual bool IsValidAdmissionActionData(SpmAdmissionAction.Data data, SpmAdmissionAction.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// AdmissionAction properties.
|
||||
if (errField.AdmissionId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.AdmissionId))
|
||||
{
|
||||
errField.AdmissionId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid admission Id");
|
||||
}
|
||||
if (errField.AdmissionActionType != SacsHierarchyItem.ValidValue.Ignore && (short)data.AdmissionActionType < 1)
|
||||
{
|
||||
if ((int)data.AdmissionActionType < 1)
|
||||
{
|
||||
errField.AdmissionActionType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Association type must be supplied");
|
||||
}
|
||||
}
|
||||
if (errField.Raised != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.Raised))
|
||||
{
|
||||
errField.Raised = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmAdmissionAction.AdmissionActionStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction database interface.
|
||||
public abstract bool InsertAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool AdmissionActionCanBeDeleted(SpmAdmissionAction admissionAction)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction list.
|
||||
public abstract ColumnDfn GetAdmissionActionColumnDfn(SpmAdmissionAction.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetAdmissionActionQueryFilter(SpmAdmissionAction.Params prm);
|
||||
public abstract long GetAdmissionActionCount(SpmAdmissionAction.Params prm);
|
||||
public abstract List<SpmAdmissionAction> GetAdmissionActionList(SpmAdmissionAction.Params prm);
|
||||
public abstract DbResultSet ExecuteAdmissionActionQuery(List<ColumnDfn> columns, SpmAdmissionAction.Params prm);
|
||||
public abstract DataValue GetAdmissionActionDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n D a t a
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual admissionData.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist admissionData.
|
||||
public abstract bool AdmissionDataExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get admissionData.
|
||||
public abstract SpmAdmissionData GetAdmissionData(SpmAdmissionData.Params prm);
|
||||
public abstract SpmAdmissionData GetAdmissionDataById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create admissionData.
|
||||
public abstract SpmAdmissionData CreateAdmissionData(SysId admissionId, Spm.AdmissionDataType admissionDataType);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate admissionData data.
|
||||
public bool IsValidAdmissionData(SpmAdmissionData admissionData)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (admissionData == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidAdmissionDataData(admissionData.GetData(), new SpmAdmissionData.ErrField());
|
||||
}
|
||||
public virtual bool IsValidAdmissionDataData(SpmAdmissionData.Data data, SpmAdmissionData.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// AdmissionData properties.
|
||||
if (errField.AdmissionId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.AdmissionId))
|
||||
{
|
||||
errField.AdmissionId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid admission Id");
|
||||
}
|
||||
if (errField.AdmissionDataType != SacsHierarchyItem.ValidValue.Ignore && (short)data.AdmissionDataType < 1)
|
||||
{
|
||||
if ((int)data.AdmissionDataType < 1)
|
||||
{
|
||||
errField.AdmissionDataType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Admission Data Type must be supplied");
|
||||
}
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionData_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionData_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmAdmissionData.AdmissionDataStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData database interface.
|
||||
public abstract bool InsertAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool AdmissionDataCanBeDeleted(SpmAdmissionData admissionData)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData list.
|
||||
public abstract ColumnDfn GetAdmissionDataColumnDfn(SpmAdmissionData.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetAdmissionDataQueryFilter(SpmAdmissionData.Params prm);
|
||||
public abstract long GetAdmissionDataCount(SpmAdmissionData.Params prm);
|
||||
public abstract List<SpmAdmissionData> GetAdmissionDataList(SpmAdmissionData.Params prm);
|
||||
public abstract DbResultSet ExecuteAdmissionDataQuery(List<ColumnDfn> columns, SpmAdmissionData.Params prm);
|
||||
public abstract DataValue GetAdmissionDataDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n R o l e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual admissionRole.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist admissionRole.
|
||||
public abstract bool AdmissionRoleExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get admissionRole.
|
||||
public abstract SpmAdmissionRole GetAdmissionRole(SpmAdmissionRole.Params prm);
|
||||
public abstract SpmAdmissionRole GetAdmissionRoleById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create admissionRole.
|
||||
public abstract SpmAdmissionRole CreateAdmissionRole(SysId admissionId, Spm.EmployeeRole employeeRole, Spm.EmployeeRoleCategory employeeRoleCategory);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate admissionRole data.
|
||||
public bool IsValidAdmissionRole(SpmAdmissionRole admissionRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (admissionRole == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidAdmissionRoleData(admissionRole.GetData(), new SpmAdmissionRole.ErrField());
|
||||
}
|
||||
public virtual bool IsValidAdmissionRoleData(SpmAdmissionRole.Data data, SpmAdmissionRole.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// AdmissionRole properties.
|
||||
if (errField.AdmissionId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.AdmissionId))
|
||||
{
|
||||
errField.AdmissionId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid admission Id");
|
||||
}
|
||||
if (errField.Seq != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Seq.ToString(), "seq", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Seq), true))
|
||||
{
|
||||
errField.Seq = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.EmployeeRole != SacsHierarchyItem.ValidValue.Ignore && (short)data.EmployeeRole < 1)
|
||||
{
|
||||
if ((int)data.EmployeeRole < 1)
|
||||
{
|
||||
errField.EmployeeRole = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Employee role must be supplied");
|
||||
}
|
||||
}
|
||||
if (errField.EmployeeRoleId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.EmployeeRoleId))
|
||||
{
|
||||
errField.EmployeeRoleId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid employeeRoleId");
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmAdmissionRole.AdmissionRoleStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole database interface.
|
||||
public abstract bool InsertAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool AdmissionRoleCanBeDeleted(SpmAdmissionRole admissionRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole list.
|
||||
public abstract ColumnDfn GetAdmissionRoleColumnDfn(SpmAdmissionRole.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetAdmissionRoleQueryFilter(SpmAdmissionRole.Params prm);
|
||||
public abstract long GetAdmissionRoleCount(SpmAdmissionRole.Params prm);
|
||||
public abstract List<SpmAdmissionRole> GetAdmissionRoleList(SpmAdmissionRole.Params prm);
|
||||
public abstract DbResultSet ExecuteAdmissionRoleQuery(List<ColumnDfn> columns, SpmAdmissionRole.Params prm);
|
||||
public abstract DataValue GetAdmissionRoleDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -10,9 +10,9 @@ namespace Sarand.PatientMgr.Core.Mgr
|
||||
// Department
|
||||
// Employee Role
|
||||
// Facility
|
||||
// Facility Session
|
||||
// Facility Template
|
||||
// Template Data
|
||||
// Facility Session
|
||||
// Procedure
|
||||
//=======================================================================
|
||||
public abstract partial class SpmDepartmentMgr : SpmItemMgr
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// D e p a r t m e n t
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual department.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist department.
|
||||
public abstract bool DepartmentExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get department.
|
||||
public abstract SpmDepartment GetDepartment(SpmDepartment.Params prm);
|
||||
public abstract SpmDepartment GetDepartmentById(SysId id);
|
||||
public abstract SpmDepartment GetDepartmentByName(String name);
|
||||
public abstract SpmDepartment GetDepartmentByFacilityId(SysId facilityId);
|
||||
public abstract SpmDepartment GetDepartmentByFacilityTemplateId(SysId facilityId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create department.
|
||||
public abstract SpmDepartment CreateDepartment();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate department data.
|
||||
public bool IsValidDepartment(SpmDepartment department)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (department == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidDepartmentData(department.GetData(), new SpmDepartment.ErrField());
|
||||
}
|
||||
public virtual bool IsValidDepartmentData(SpmDepartment.Data data, SpmDepartment.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Department properties.
|
||||
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "name", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmDepartment_Name), true))
|
||||
{
|
||||
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ApplicationFrom != SacsHierarchyItem.ValidValue.Ignore && errField.ApplicationTo != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.ApplicationFrom) && DateUtil.IsValid(data.ApplicationTo))
|
||||
{
|
||||
if (data.ApplicationFrom.CompareTo(data.ApplicationTo) > 0)
|
||||
{
|
||||
errField.ApplicationFrom = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Invalid application date range");
|
||||
}
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmDepartment_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmDepartment_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmDepartment.DepartmentStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department database interface.
|
||||
public abstract bool InsertDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool DepartmentCanBeDeleted(SpmDepartment department)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department list.
|
||||
public abstract ColumnDfn GetDepartmentColumnDfn(SpmDepartment.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetDepartmentQueryFilter(SpmDepartment.Params prm);
|
||||
public abstract long GetDepartmentCount(SpmDepartment.Params prm);
|
||||
public abstract List<SpmDepartment> GetDepartmentList(SpmDepartment.Params prm);
|
||||
public abstract DbResultSet ExecuteDepartmentQuery(List<ColumnDfn> columns, SpmDepartment.Params prm);
|
||||
public abstract DataValue GetDepartmentDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// E m p l o y e e R o l e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual employeeRole.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist employeeRole.
|
||||
public abstract bool EmployeeRoleExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get employeeRole.
|
||||
public abstract SpmEmployeeRole GetEmployeeRole(SpmEmployeeRole.Params prm);
|
||||
public abstract SpmEmployeeRole GetEmployeeRoleById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create employeeRole.
|
||||
public abstract SpmEmployeeRole CreateEmployeeRole(SysId deparmentId, SysId employeeId, Spm.EmployeeRole employeeRole);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate employeeRole data.
|
||||
public bool IsValidEmployeeRole(SpmEmployeeRole employeeRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (employeeRole == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidEmployeeRoleData(employeeRole.GetData(), new SpmEmployeeRole.ErrField());
|
||||
}
|
||||
public virtual bool IsValidEmployeeRoleData(SpmEmployeeRole.Data data, SpmEmployeeRole.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// EmployeeRole properties.
|
||||
if (errField.DepartmentId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.DepartmentId))
|
||||
{
|
||||
errField.DepartmentId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid DepartmentId");
|
||||
}
|
||||
if (errField.EmployeeId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.EmployeeId))
|
||||
{
|
||||
errField.EmployeeId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid EmployeeId");
|
||||
}
|
||||
if (errField.EmployeeRole != SacsHierarchyItem.ValidValue.Ignore && (short)data.EmployeeRole < 1)
|
||||
{
|
||||
if ((int)data.EmployeeRole < 1)
|
||||
{
|
||||
errField.EmployeeRole = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Employee role must be supplied");
|
||||
}
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmEmployeeRole.EmployeeRoleStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole database interface.
|
||||
public abstract bool InsertEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool EmployeeRoleCanBeDeleted(SpmEmployeeRole employeeRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole list.
|
||||
public abstract ColumnDfn GetEmployeeRoleColumnDfn(SpmEmployeeRole.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetEmployeeRoleQueryFilter(SpmEmployeeRole.Params prm);
|
||||
public abstract long GetEmployeeRoleCount(SpmEmployeeRole.Params prm);
|
||||
public abstract List<SpmEmployeeRole> GetEmployeeRoleList(SpmEmployeeRole.Params prm);
|
||||
public abstract DbResultSet ExecuteEmployeeRoleQuery(List<ColumnDfn> columns, SpmEmployeeRole.Params prm);
|
||||
public abstract DataValue GetEmployeeRoleDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// F a c i l i t y
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual facility.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist facility.
|
||||
public abstract bool FacilityExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get facility.
|
||||
public abstract SpmFacility GetFacility(SpmFacility.Params prm);
|
||||
public abstract SpmFacility GetFacilityById(SysId id);
|
||||
public abstract SpmFacility GetFacilityByName(String name);
|
||||
public abstract SpmFacility GetFacilityByTemplateId(SysId facilityTemplateId);
|
||||
//-------------------------------------------------------------------
|
||||
// Create facility.
|
||||
public abstract SpmFacility CreateFacility(SysId facilityId, SysId departmentId, Spm.FacilityType facilityType);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate facility data.
|
||||
public bool IsValidFacility(SpmFacility facility)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (facility == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidFacilityData(facility.GetData(), new SpmFacility.ErrField());
|
||||
}
|
||||
public virtual bool IsValidFacilityData(SpmFacility.Data data, SpmFacility.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Facility properties.
|
||||
if (errField.DepartmentId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.DepartmentId))
|
||||
{
|
||||
errField.DepartmentId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid department Id");
|
||||
}
|
||||
if (errField.FacilityType != SacsHierarchyItem.ValidValue.Ignore && (short)data.FacilityType < 1)
|
||||
{
|
||||
if ((int)data.FacilityType < 1)
|
||||
{
|
||||
errField.FacilityType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("FacilityType must be supplied");
|
||||
}
|
||||
}
|
||||
if (errField.TemplateMapType != SacsHierarchyItem.ValidValue.Ignore && (short)data.TemplateMapType < 1)
|
||||
{
|
||||
if ((int)data.TemplateMapType < 1)
|
||||
{
|
||||
errField.FacilityType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("TemplateMapType must be supplied");
|
||||
}
|
||||
}
|
||||
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "Name", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_Name), true))
|
||||
{
|
||||
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SortCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SortCode, "SortCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_SortCode), true))
|
||||
{
|
||||
errField.SortCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Desc != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Desc, "Desc", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_Description), true))
|
||||
{
|
||||
errField.Desc = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ScheduleFreezeType != SacsHierarchyItem.ValidValue.Ignore && (short)data.ScheduleFreezeType < 1)
|
||||
{
|
||||
if ((int)data.ScheduleFreezeType < 1)
|
||||
{
|
||||
errField.FacilityType = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("ScheduleFreezeType must be supplied");
|
||||
}
|
||||
}
|
||||
if (errField.ScheduleFreezeData != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ScheduleFreezeData, "ScheduleFreezeData", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_ScheduleFreezeData), true))
|
||||
{
|
||||
errField.ScheduleFreezeData = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ApplicationFrom != SacsHierarchyItem.ValidValue.Ignore && errField.ApplicationTo != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.ApplicationFrom) && DateUtil.IsValid(data.ApplicationTo))
|
||||
{
|
||||
if (data.ApplicationFrom.CompareTo(data.ApplicationTo) > 0)
|
||||
{
|
||||
errField.ApplicationFrom = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Invalid application date range");
|
||||
}
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacility_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmFacility.FacilityStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility database interface.
|
||||
public abstract bool InsertFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool FacilityCanBeDeleted(SpmFacility facility)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility list.
|
||||
public abstract ColumnDfn GetFacilityColumnDfn(SpmFacility.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetFacilityQueryFilter(SpmFacility.Params prm);
|
||||
public abstract long GetFacilityCount(SpmFacility.Params prm);
|
||||
public abstract List<SpmFacility> GetFacilityList(SpmFacility.Params prm);
|
||||
public abstract DbResultSet ExecuteFacilityQuery(List<ColumnDfn> columns, SpmFacility.Params prm);
|
||||
public abstract DataValue GetFacilityDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// F a c i l i t y S e s s i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual facilitySession.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist facilitySession.
|
||||
public abstract bool FacilitySessionExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get facilitySession.
|
||||
public abstract SpmFacilitySession GetFacilitySession(SpmFacilitySession.Params prm);
|
||||
public abstract SpmFacilitySession GetFacilitySessionById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create facilitySession.
|
||||
public abstract SpmFacilitySession CreateFacilitySession(SysId facilityId, SysId facilityTemplateId, DateTime sessionDate);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate facilitySession data.
|
||||
public bool IsValidFacilitySession(SpmFacilitySession facilitySession)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (facilitySession == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidFacilitySessionData(facilitySession.GetData(), new SpmFacilitySession.ErrField());
|
||||
}
|
||||
public virtual bool IsValidFacilitySessionData(SpmFacilitySession.Data data, SpmFacilitySession.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// FacilitySession properties.
|
||||
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "Name", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_Name), true))
|
||||
{
|
||||
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Desc != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Desc, "Description", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_Description), true))
|
||||
{
|
||||
errField.Desc = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SessionCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SessionCode, "SessionCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_SessionCode), true))
|
||||
{
|
||||
errField.SessionCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ConsultantCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ConsultantCode, "ConsultantCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_ConsultantCode), true))
|
||||
{
|
||||
errField.ConsultantCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SpecialityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SpecialityCode, "SpecialityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_SpecialityCode), true))
|
||||
{
|
||||
errField.SpecialityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmFacilitySession.FacilitySessionStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilitySession database interface.
|
||||
public abstract bool InsertFacilitySession(SpmFacilitySession facilitySession, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateFacilitySession(SpmFacilitySession facilitySession, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool FacilitySessionCanBeDeleted(SpmFacilitySession facilitySession)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteFacilitySession(SpmFacilitySession facilitySession, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilitySession list.
|
||||
public abstract ColumnDfn GetFacilitySessionColumnDfn(SpmFacilitySession.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetFacilitySessionQueryFilter(SpmFacilitySession.Params prm);
|
||||
public abstract long GetFacilitySessionCount(SpmFacilitySession.Params prm);
|
||||
public abstract List<SpmFacilitySession> GetFacilitySessionList(SpmFacilitySession.Params prm);
|
||||
public abstract DbResultSet ExecuteFacilitySessionQuery(List<ColumnDfn> columns, SpmFacilitySession.Params prm);
|
||||
public abstract DataValue GetFacilitySessionDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// F a c i l i t y T e m p l a t e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual facilityTemplate.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist facilityTemplate.
|
||||
public abstract bool FacilityTemplateExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get facilityTemplate.
|
||||
public abstract SpmFacilityTemplate GetFacilityTemplate(SpmFacilityTemplate.Params prm);
|
||||
public abstract SpmFacilityTemplate GetFacilityTemplateById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create facilityTemplate.
|
||||
public abstract SpmFacilityTemplate CreateFacilityTemplate(SysId facilityId, Spm.ResourceCategory resourceCategory);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate facilityTemplate data.
|
||||
public bool IsValidFacilityTemplate(SpmFacilityTemplate facilityTemplate)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (facilityTemplate == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidFacilityTemplateData(facilityTemplate.GetData(), new SpmFacilityTemplate.ErrField());
|
||||
}
|
||||
public virtual bool IsValidFacilityTemplateData(SpmFacilityTemplate.Data data, SpmFacilityTemplate.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// FacilityTemplate properties.
|
||||
if (errField.Group != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Group, "Group", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Group), true))
|
||||
{
|
||||
errField.Group = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "Name", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Name), true))
|
||||
{
|
||||
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SortCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SortCode, "SortCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_SortCode), true))
|
||||
{
|
||||
errField.SortCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Desc != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Desc, "Desc", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Description), true))
|
||||
{
|
||||
errField.Desc = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SessionCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SessionCode, "SessionCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_SessionCode), true))
|
||||
{
|
||||
errField.SessionCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ToDo FacilityType&TemplateMapType need to have connection between Facility and FacilityTemplate like FacTmpl.WeekOfMonth etc.
|
||||
/*if (Type != Spm.FacilityType.Ward)
|
||||
{
|
||||
// Validate week of month against the template map type.
|
||||
if (TemplateMapType == Spm.FacilityTemplateMapType.RollingWeek && data.WeekOfMonth != 0) return SetErrorState("week of month must be '0'");
|
||||
if (TemplateMapType != Spm.FacilityTemplateMapType.RollingWeek && (data.WeekOfMonth < 1 || data.WeekOfMonth > 5)) return SetErrorState("week of month must be between 1 and 5");
|
||||
|
||||
// Validate the day of the week.
|
||||
if (data.DayOfWeek() < 1 || data.DayOfWeek() > 7) return SetErrorState("invalid day of week");
|
||||
}*/
|
||||
|
||||
if (errField.CapacityMin != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CapacityMin.ToString(), "CapacityMin", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_CapacityMin), true))
|
||||
{
|
||||
errField.CapacityMin = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid CapacityMin");
|
||||
}
|
||||
if (errField.CapacityMax != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CapacityMax.ToString(), "CapacityMax", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_CapacityMax), true))
|
||||
{
|
||||
errField.CapacityMax = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid CapacityMax");
|
||||
}
|
||||
if (errField.DurationInterval != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DurationInterval.ToString(), "DurationInterval", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_DurationInterval), true))
|
||||
{
|
||||
errField.DurationInterval = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid DurationInterval");
|
||||
}
|
||||
if (errField.DurationMin != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DurationMin.ToString(), "DurationMin", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_DurationMin), true))
|
||||
{
|
||||
errField.DurationMin = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid DurationMin");
|
||||
}
|
||||
if (errField.DurationMax != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DurationMax.ToString(), "DurationMax", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_DurationMax), true))
|
||||
{
|
||||
errField.DurationMax = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid DurationMax");
|
||||
}
|
||||
if (errField.DurationBreaks != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.DurationBreaks.ToString(), "DurationBreaks", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_DurationBreaks), true))
|
||||
{
|
||||
errField.DurationBreaks = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid DurationBreaks");
|
||||
}
|
||||
|
||||
if (errField.ConsultantCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ConsultantCode, "ConsultantCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_ConsultantCode), true))
|
||||
{
|
||||
errField.ConsultantCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SpecialityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SpecialityCode, "SpecialityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilitySession_SpecialityCode), true))
|
||||
{
|
||||
errField.SpecialityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ToDo need to get FacilityType.WARD for StartTime & FinishTime with ApplicationFrom & ApplicationTo.
|
||||
/*if (Type == Spm.FacilityType.Ward)
|
||||
{
|
||||
// Wards - start and finish times should be '00:00'.
|
||||
if (data.GetStartTime != Time("00:00:00")) return SetErrorState("invalid start time");
|
||||
if (data.GetFinishTime != Time("00:00:00")) return SetErrorState("invalid finish time");
|
||||
}
|
||||
else
|
||||
if (data.StartTime >= data.FinishTime) return SetErrorState("invalid start/finish times");*/
|
||||
|
||||
if (errField.ApplicationFrom != SacsHierarchyItem.ValidValue.Ignore && errField.ApplicationTo != SacsHierarchyItem.ValidValue.Ignore && DateUtil.IsValid(data.ApplicationFrom) && DateUtil.IsValid(data.ApplicationTo))
|
||||
{
|
||||
if (data.ApplicationFrom.CompareTo(data.ApplicationTo) > 0)
|
||||
{
|
||||
errField.ApplicationFrom = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("Invalid application date range");
|
||||
}
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmFacilityTemplate.FacilityTemplateStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate database interface.
|
||||
public abstract bool InsertFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool FacilityTemplateCanBeDeleted(SpmFacilityTemplate facilityTemplate)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate list.
|
||||
public abstract ColumnDfn GetFacilityTemplateColumnDfn(SpmFacilityTemplate.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetFacilityTemplateQueryFilter(SpmFacilityTemplate.Params prm);
|
||||
public abstract long GetFacilityTemplateCount(SpmFacilityTemplate.Params prm);
|
||||
public abstract List<SpmFacilityTemplate> GetFacilityTemplateList(SpmFacilityTemplate.Params prm);
|
||||
public abstract DbResultSet ExecuteFacilityTemplateQuery(List<ColumnDfn> columns, SpmFacilityTemplate.Params prm);
|
||||
public abstract DataValue GetFacilityTemplateDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// P r o c e d u r e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual procedure.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist procedure.
|
||||
public abstract bool ProcedureExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get procedure.
|
||||
public abstract SpmProcedure GetProcedure(SpmProcedure.Params prm);
|
||||
public abstract SpmProcedure GetProcedureById(SysId id);
|
||||
public abstract SpmProcedure GetProcedureByCode(String operationCode);
|
||||
public abstract SpmProcedure GetProcedureByOperationId(SysId operationId);
|
||||
//-------------------------------------------------------------------
|
||||
// Create procedure.
|
||||
public abstract SpmProcedure CreateProcedure(SysId procedureId, SysId departmentId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate procedure data.
|
||||
public bool IsValidProcedure(SpmProcedure procedure)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (procedure == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidProcedureData(procedure.GetData(), new SpmProcedure.ErrField());
|
||||
}
|
||||
public virtual bool IsValidProcedureData(SpmProcedure.Data data, SpmProcedure.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Procedure properties.
|
||||
if (errField.DepartmentId != SacsHierarchyItem.ValidValue.Ignore && !SysId.IsValid(data.DepartmentId))
|
||||
{
|
||||
errField.DepartmentId = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState("invalid department Id");
|
||||
}
|
||||
if (errField.OperationCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.OperationCode, "OperationCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_OpnCode), true))
|
||||
{
|
||||
errField.OperationCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Description != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Description, "Description", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_Description), true))
|
||||
{
|
||||
errField.Description = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.SpecialityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.SpecialityCode, "SpecialityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_SpecialityCode), true))
|
||||
{
|
||||
errField.SpecialityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.ComplexityCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.ComplexityCode, "ComplexityCode", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_ComplexityCode), true))
|
||||
{
|
||||
errField.ComplexityCode = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmProcedure_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmProcedure.ProcedureStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure database interface.
|
||||
public abstract bool InsertProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool ProcedureCanBeDeleted(SpmProcedure procedure)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure list.
|
||||
public abstract ColumnDfn GetProcedureColumnDfn(SpmProcedure.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetProcedureQueryFilter(SpmProcedure.Params prm);
|
||||
public abstract long GetProcedureCount(SpmProcedure.Params prm);
|
||||
public abstract List<SpmProcedure> GetProcedureList(SpmProcedure.Params prm);
|
||||
public abstract DbResultSet ExecuteProcedureQuery(List<ColumnDfn> columns, SpmProcedure.Params prm);
|
||||
public abstract DataValue GetProcedureDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// T e m p l a t e D a t a
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual templateData.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist templateData.
|
||||
public abstract bool TemplateDataExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get templateData.
|
||||
public abstract SpmTemplateData GetTemplateData(SpmTemplateData.Params prm);
|
||||
public abstract SpmTemplateData GetTemplateDataById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create templateData.
|
||||
public abstract SpmTemplateData CreateTemplateData();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate templateData data.
|
||||
public bool IsValidTemplateData(SpmTemplateData templateData)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (templateData == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidTemplateDataData(templateData.GetData(), new SpmTemplateData.ErrField());
|
||||
}
|
||||
public virtual bool IsValidTemplateDataData(SpmTemplateData.Data data, SpmTemplateData.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// TemplateData properties.
|
||||
|
||||
|
||||
// Common properties.
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmTemplateData_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmTemplateData.TemplateDataStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData database interface.
|
||||
public abstract bool InsertTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool TemplateDataCanBeDeleted(SpmTemplateData templateData)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData list.
|
||||
public abstract ColumnDfn GetTemplateDataColumnDfn(SpmTemplateData.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetTemplateDataQueryFilter(SpmTemplateData.Params prm);
|
||||
public abstract long GetTemplateDataCount(SpmTemplateData.Params prm);
|
||||
public abstract List<SpmTemplateData> GetTemplateDataList(SpmTemplateData.Params prm);
|
||||
public abstract DbResultSet ExecuteTemplateDataQuery(List<ColumnDfn> columns, SpmTemplateData.Params prm);
|
||||
public abstract DataValue GetTemplateDataDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// E m p l o y e e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual employee.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist employee.
|
||||
public abstract bool EmployeeExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get employee.
|
||||
public abstract SpmEmployee GetEmployee(SpmEmployee.Params prm);
|
||||
public abstract SpmEmployee GetEmployeeById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create employee.
|
||||
public abstract SpmEmployee CreateEmployee(SysId id, SysId institutionId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate employee data.
|
||||
public bool IsValidEmployee(SpmEmployee employee)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (employee == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidEmployeeData(employee.GetData(), new SpmEmployee.ErrField());
|
||||
}
|
||||
public virtual bool IsValidEmployeeData(SpmEmployee.Data data, SpmEmployee.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Employee properties.
|
||||
if (errField.EmployeeNo != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.EmployeeNo, "EmployeeNo", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_EmployeeNo), true))
|
||||
{
|
||||
errField.EmployeeNo = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Code != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Code, "Code", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Code), true))
|
||||
{
|
||||
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Title != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Title, "Title", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Title), true))
|
||||
{
|
||||
errField.Title = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Initials != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Initials, "Initials", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Initials), true))
|
||||
{
|
||||
errField.Initials = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Forename != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Forename, "Forename", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Forename), true))
|
||||
{
|
||||
errField.Forename = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Surname != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Surname, "Surname", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Surname), true))
|
||||
{
|
||||
errField.Surname = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmEmployee_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmEmployee.EmployeeStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee database interface.
|
||||
public abstract bool InsertEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool EmployeeCanBeDeleted(SpmEmployee employee)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee list.
|
||||
public abstract ColumnDfn GetEmployeeColumnDfn(SpmEmployee.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetEmployeeQueryFilter(SpmEmployee.Params prm);
|
||||
public abstract long GetEmployeeCount(SpmEmployee.Params prm);
|
||||
public abstract List<SpmEmployee> GetEmployeeList(SpmEmployee.Params prm);
|
||||
public abstract DbResultSet ExecuteEmployeeQuery(List<ColumnDfn> columns, SpmEmployee.Params prm);
|
||||
public abstract DataValue GetEmployeeDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// I n s t i t u t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual institution.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist institution.
|
||||
public abstract bool InstitutionExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get institution.
|
||||
public abstract SpmInstitution GetInstitution(SpmInstitution.Params prm);
|
||||
public abstract SpmInstitution GetInstitutionById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create institution.
|
||||
public abstract SpmInstitution CreateInstitution(SysId institutionId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate institution data.
|
||||
public bool IsValidInstitution(SpmInstitution institution)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (institution == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidInstitutionData(institution.GetData(), new SpmInstitution.ErrField());
|
||||
}
|
||||
public virtual bool IsValidInstitutionData(SpmInstitution.Data data, SpmInstitution.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Institution properties.
|
||||
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "Name", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmInstitution_Name), true))
|
||||
{
|
||||
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmInstitution_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmInstitution_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmInstitution.InstitutionStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution database interface.
|
||||
public abstract bool InsertInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool InstitutionCanBeDeleted(SpmInstitution institution)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution list.
|
||||
public abstract ColumnDfn GetInstitutionColumnDfn(SpmInstitution.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetInstitutionQueryFilter(SpmInstitution.Params prm);
|
||||
public abstract long GetInstitutionCount(SpmInstitution.Params prm);
|
||||
public abstract List<SpmInstitution> GetInstitutionList(SpmInstitution.Params prm);
|
||||
public abstract DbResultSet ExecuteInstitutionQuery(List<ColumnDfn> columns, SpmInstitution.Params prm);
|
||||
public abstract DataValue GetInstitutionDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// O p e r a t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual operation.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist operation.
|
||||
public abstract bool OperationExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get operation.
|
||||
public abstract SpmOperation GetOperation(SpmOperation.Params prm);
|
||||
public abstract SpmOperation GetOperationById(SysId id);
|
||||
public abstract SpmOperation GetOperationByCode(String code);
|
||||
//-------------------------------------------------------------------
|
||||
// Create operation.
|
||||
public abstract SpmOperation CreateOperation(SysId departmentId, SysId institutionId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate operation data.
|
||||
public bool IsValidOperation(SpmOperation operation)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (operation == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidOperationData(operation.GetData(), new SpmOperation.ErrField());
|
||||
}
|
||||
public virtual bool IsValidOperationData(SpmOperation.Data data, SpmOperation.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Operation properties.
|
||||
if (errField.Code != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Code, "Code", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmOperation_Code), true))
|
||||
{
|
||||
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Description != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Description, "Description", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmOperation_Description), true))
|
||||
{
|
||||
errField.Description = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmOperation_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmOperation_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmOperation.OperationStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation database interface.
|
||||
public abstract bool InsertOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdateOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool OperationCanBeDeleted(SpmOperation operation)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeleteOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation list.
|
||||
public abstract ColumnDfn GetOperationColumnDfn(SpmOperation.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetOperationQueryFilter(SpmOperation.Params prm);
|
||||
public abstract long GetOperationCount(SpmOperation.Params prm);
|
||||
public abstract List<SpmOperation> GetOperationList(SpmOperation.Params prm);
|
||||
public abstract DbResultSet ExecuteOperationQuery(List<ColumnDfn> columns, SpmOperation.Params prm);
|
||||
public abstract DataValue GetOperationDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
|
||||
namespace Sarand.PatientMgr.Core.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
partial class SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// P a t i e n t
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve individual patient.
|
||||
//-------------------------------------------------------------------
|
||||
// Exist patient.
|
||||
public abstract bool PatientExistsById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Get patient.
|
||||
public abstract SpmPatient GetPatient(SpmPatient.Params prm);
|
||||
public abstract SpmPatient GetPatientById(SysId id);
|
||||
//-------------------------------------------------------------------
|
||||
// Create patient.
|
||||
public abstract SpmPatient CreatePatient(SysId id, SysId institutionId);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate patient data.
|
||||
public bool IsValidPatient(SpmPatient patient)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (patient == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
||||
return IsValidPatientData(patient.GetData(), new SpmPatient.ErrField());
|
||||
}
|
||||
public virtual bool IsValidPatientData(SpmPatient.Data data, SpmPatient.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Patient properties.
|
||||
if (errField.PatientNo != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.PatientNo, "PatientNo", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_PatientNo), true))
|
||||
{
|
||||
errField.PatientNo = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.NhsNumber != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.NhsNumber, "NhsNumber", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_NhsNumber), true))
|
||||
{
|
||||
errField.NhsNumber = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Title != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Title, "Title", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Title), true))
|
||||
{
|
||||
errField.Title = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Forename != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Forename, "Forename", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Forename), true))
|
||||
{
|
||||
errField.Forename = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Surname != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Surname, "Surname", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Surname), true))
|
||||
{
|
||||
errField.Surname = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Age != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Age, "Age", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Age), true))
|
||||
{
|
||||
errField.Age = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common properties.
|
||||
if (!IsValidValue(data.Notes, "notes", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Notes)))
|
||||
{
|
||||
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
||||
{
|
||||
if (!IsValidValue(SacsSystem.GetStatusCode(data.Status), "status", (long)SpmDbDfn.GetColTextLen(SpmDbDfn.ColumnIdx.SwmPatient_Status), true, true))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return false;
|
||||
}
|
||||
if (!SpmPatient.PatientStatuses.Contains(data.Status))
|
||||
{
|
||||
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
||||
return SetErrorState(ErrorMessage.InvalidStatus);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient database interface.
|
||||
public abstract bool InsertPatient(SpmPatient patient, DbUpdateInfo dbUpdateInfo);
|
||||
public abstract bool UpdatePatient(SpmPatient patient, DbUpdateInfo dbUpdateInfo);
|
||||
public virtual bool PatientCanBeDeleted(SpmPatient patient)
|
||||
{
|
||||
ClearErrorState();
|
||||
return true;
|
||||
}
|
||||
public abstract bool DeletePatient(SpmPatient patient, DbUpdateInfo dbUpdateInfo);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient list.
|
||||
public abstract ColumnDfn GetPatientColumnDfn(SpmPatient.Column columnId, String caption = "", int width = 0);
|
||||
public abstract List<String> GetPatientQueryFilter(SpmPatient.Params prm);
|
||||
public abstract long GetPatientCount(SpmPatient.Params prm);
|
||||
public abstract List<SpmPatient> GetPatientList(SpmPatient.Params prm);
|
||||
public abstract DbResultSet ExecutePatientQuery(List<ColumnDfn> columns, SpmPatient.Params prm);
|
||||
public abstract DataValue GetPatientDataValue(ColumnDfn column, NamedValue.Map values);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Core\Bus\" />
|
||||
<Folder Include="Core\Consoles\" />
|
||||
<Folder Include="Core\Data\" />
|
||||
<Folder Include="Core\UpdateLog\" />
|
||||
|
||||
@@ -42,6 +42,21 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Win\Dbas\App\SpmSystem_WinDbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmPatient_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmOperation_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmInstitution_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmProcedure_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmTemplateData_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmFacilitySession_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmFacilityTemplate_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmFacility_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmEmployeeRole_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmEmployee_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmDepartment_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmAdmissionRole_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmAdmissionData_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmAdmissionAction_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Bus\SpmAdmission_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Consoles\SpmCodeTypeConsole_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Consoles\SpmItemOptionConsole_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Consoles\SpmSecurityConsole_Dbas.cs" />
|
||||
@@ -65,6 +80,23 @@
|
||||
<Compile Include="Win\Dbas\Internal\SwmPatient_Db.cs" />
|
||||
<Compile Include="Win\Dbas\Internal\SwmProcedure_Db.cs" />
|
||||
<Compile Include="Win\Dbas\Internal\SwmTemplateData_Db.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmAdmissionMgr_Dbas-AdmissionData.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmAdmissionMgr_Dbas-AdmissionRole.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmAdmissionMgr_Dbas-AdmissionAction.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmAdmissionMgr_Dbas-Admission.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-EmployeeRole.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-Facility.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-FacilitySession.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-FacilityTemplate.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-Procedure.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-TemplateData.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas-Department.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmInstitutionMgr_Dbas-Employee.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmInstitutionMgr_Dbas-Operation.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmInstitutionMgr_Dbas-Patient.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmInstitutionMgr_Dbas-Institution.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmInstitutionMgr_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmDepartmentMgr_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Mgr\SpmAdmissionMgr_Dbas.cs" />
|
||||
<Compile Include="Win\Dbas\Utils\SpmDbDfnGenerator.cs" />
|
||||
<Compile Include="Win\Dbas\Utils\SpmFileUtil.cs" />
|
||||
@@ -88,7 +120,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Win\Dbas\Base\" />
|
||||
<Folder Include="Win\Dbas\Bus\" />
|
||||
<Folder Include="Win\Dbas\UpdateLog\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmAdmissionAction_Dbas : SpmAdmissionAction
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmAdmissionAction_Dbas(SpmUserContext userContext, SysId id, SysId admissionId, Spm.AdmissionActionType admissionActionType, ushort flags) :
|
||||
base(id, admissionId, admissionActionType)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmAdmissionData_Dbas : SpmAdmissionData
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmAdmissionData_Dbas(SpmUserContext userContext, SysId admissionId, Spm.AdmissionDataType admissionDataType, ushort flags) :
|
||||
base(admissionId, admissionDataType)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmAdmissionRole_Dbas : SpmAdmissionRole
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmAdmissionRole_Dbas(SpmUserContext userContext, SysId admissionId, Spm.EmployeeRole employeeRole, Spm.EmployeeRoleCategory employeeRoleCategory, ushort flags) :
|
||||
base(admissionId, employeeRole, employeeRoleCategory)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmAdmission_Dbas : SpmAdmission
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
private SpmAdmissionMgr admissionMgr = null;
|
||||
private List<SpmAdmissionRole> admissionRolesCache;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmAdmission_Dbas(SpmUserContext userContext, SysId facilityId, SysId facilityTemplateId, ushort flags) :
|
||||
base(facilityId, facilityTemplateId)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (admissionMgr != null) admissionMgr.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
private SpmAdmissionMgr AdmissionMgr { get { if (admissionMgr == null) admissionMgr = SpmGlobals.System.CreateAdmissionMgr(userContext); return admissionMgr; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
// Admission Roles
|
||||
public override bool HasRole(Spm.EmployeeRole employeeRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||
if ((int)employeeRole < 1) return SetErrorState("role must be supplied");
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db == null)
|
||||
{
|
||||
// Filter to identify matching Roles:
|
||||
// AdmissionRole.AdmissionId = This item's Id.
|
||||
// AdmissionRole.Role = supplied value.
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId) + "=" + Id.ToString());
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Role) + "=" + ((int)employeeRole).ToString());
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole), filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasRole(Spm.EmployeeRole employeeRole, String employeeCode)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||
if ((int)employeeRole < 1) return SetErrorState("role must be supplied");
|
||||
if (StringUtil.IsEmpty(employeeCode)) return SetErrorState("employee code must be supplied");
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db == null)
|
||||
{
|
||||
// Dummy query to set DBMS - for correct formatting of strings and dates etc.
|
||||
DbQuery queryDummy = new DbQuery(db != null ? db.DbmsType : DbmsType.General);
|
||||
|
||||
// Filter to identify matching Roles:
|
||||
// AdmissionRole.AdmissionId = This item's Id.
|
||||
// AdmissionRole.Role = supplied value.
|
||||
// AdmissionRole.EmployeeCode = supplied value.
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId) + "=" + Id.ToString());
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Role) + "=" + ((int)employeeRole).ToString());
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeCode) + "=" + DbQuery.FormatForCondition(employeeCode) + "'");
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole), filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override List<SpmAdmissionRole> GetRoles()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (admissionRolesCache == null)
|
||||
{
|
||||
SpmAdmissionRole.Params prmAdmissionRole = new SpmAdmissionRole.Params();
|
||||
prmAdmissionRole.AdmissionId = Id;
|
||||
prmAdmissionRole.StatusCat = SpmAdmissionRole.StatusCat.Any;
|
||||
admissionRolesCache = AdmissionMgr.GetAdmissionRoleList(prmAdmissionRole);
|
||||
admissionRolesCache.Sort();
|
||||
}
|
||||
return new List<SpmAdmissionRole>(admissionRolesCache);
|
||||
}
|
||||
public override bool SetRoles(List<SpmAdmissionRole> admissionRolesNew)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Clear the existing list.
|
||||
if (admissionRolesCache != null) admissionRolesCache.Clear();
|
||||
// Copy all items from the specified list.
|
||||
admissionRolesCache = new List<SpmAdmissionRole>(admissionRolesNew);
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool CommitRoles()
|
||||
{
|
||||
ClearErrorState();
|
||||
// Make a copy of the list so that we can keep track of the items that have been updated.
|
||||
List<SpmAdmissionRole> admissionRolesCopy = new List<SpmAdmissionRole>(admissionRolesCache);
|
||||
// Do not attempt any updates unless the list has been populated.
|
||||
if (SysId.IsValid(Id))
|
||||
{
|
||||
|
||||
admissionRolesCopy.SetSequence();
|
||||
admissionRolesCopy.SetIdentity(this);
|
||||
|
||||
// Retrieve all roles for this admission.
|
||||
SpmAdmissionRole.Params prmAdmissionRole = new SpmAdmissionRole.Params();
|
||||
prmAdmissionRole.AdmissionId = Id;
|
||||
prmAdmissionRole.StatusCat = SpmAdmissionRole.StatusCat.Any;
|
||||
foreach (SpmAdmissionRole admissionRole in admissionRolesCopy = AdmissionMgr.GetAdmissionRoleList(prmAdmissionRole))
|
||||
{
|
||||
// Does an entry for this Admission Role still exist in the list.
|
||||
if (admissionRolesCopy.FindByRoleCatSeq((Spm.EmployeeRole)prmAdmissionRole.EmployeeRole, (Spm.EmployeeRoleCategory)prmAdmissionRole.EmployeeRoleCategory, prmAdmissionRole.Seq))
|
||||
{
|
||||
if (admissionRole.Changed)
|
||||
{
|
||||
prmAdmissionRole.EmployeeRoleCategory = admissionRole.EmployeeRoleCategory;
|
||||
CopyFrom(admissionRole, admissionRole.Seq, admissionRole.EmployeeRoleId, admissionRole.EmployeeCode, admissionRole.Notes, admissionRole.Status);
|
||||
/*if (!role.Update)*/ SetErrorState("failed to update admission role");
|
||||
}
|
||||
// Remove this item from ths list.
|
||||
if (!HasErrorState()) admissionRolesCopy.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Admission Role no longer in the list - remove the record.
|
||||
if (admissionRole.HasErrorState()) SetErrorState("failed to remove admission role");
|
||||
}
|
||||
}
|
||||
// Any items remaining in the list must be new.
|
||||
foreach(SpmAdmissionRole admissionRoleNew in admissionRolesCopy)
|
||||
{
|
||||
if (admissionRoleNew == null) continue;
|
||||
prmAdmissionRole.AdmissionId = Id;
|
||||
prmAdmissionRole.EmployeeRole = admissionRoleNew.EmployeeRole;
|
||||
prmAdmissionRole.EmployeeRoleCategory = admissionRoleNew.EmployeeRoleCategory;
|
||||
// ToDo CopyFrom for AdmissionRole.
|
||||
CopyFrom(admissionRoleNew, admissionRoleNew.Seq, admissionRoleNew.EmployeeRoleId, admissionRoleNew.EmployeeCode, admissionRoleNew.Notes, admissionRoleNew.Status);
|
||||
/*if (!role.Update)*/ SetErrorState("failed to update admission role");
|
||||
}
|
||||
admissionRolesCopy.Clear();
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
public void CopyFrom(SpmAdmissionRole role, ushort seq, SysId employeeRoleId, String employeeCode, String notes, SaStatus status)
|
||||
{
|
||||
role.Seq = seq;
|
||||
role.EmployeeRoleId = employeeRoleId;
|
||||
role.EmployeeCode = employeeCode;
|
||||
role.Notes = notes;
|
||||
role.Status = status;
|
||||
}
|
||||
// Admission Action.
|
||||
public override bool HasAction(Spm.AdmissionActionType admissionActionType)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||
if ((int)admissionActionType < 1) return SetErrorState("action type must be supplied");
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db == null)
|
||||
{
|
||||
// Filter to identify matching Actions:
|
||||
// AdmissionAction.AdmissionId = This item's Id.
|
||||
// AdmissionAction.Type = supplied value.
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionAction_AdmissionId) + "=" + Id.ToString());
|
||||
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type) + "=" + ((int)admissionActionType).ToString());
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmission), filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool GetActions()
|
||||
{
|
||||
ClearErrorState();
|
||||
List<SpmAdmissionAction> admissionActionsCopy = new List<SpmAdmissionAction>();
|
||||
if (/*!*/admissionActionsCopy.Count < 1)
|
||||
{
|
||||
SpmAdmissionAction.Params prmAdmissionAction = new SpmAdmissionAction.Params();
|
||||
prmAdmissionAction.AdmissionId = Id;
|
||||
prmAdmissionAction.StatusCat = SpmAdmissionAction.StatusCat.Any;
|
||||
foreach (SpmAdmissionAction admissionAction in admissionActionsCopy = AdmissionMgr.GetAdmissionActionList(prmAdmissionAction))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public override bool SetActions()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
return false;
|
||||
}
|
||||
public override bool CommitActions()
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Admission Data.
|
||||
public override bool HasData(Spm.AdmissionDataType admissionDataType)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||
if ((int)admissionDataType < 1) return SetErrorState("data type must be supplied");
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
return false;
|
||||
}
|
||||
public override bool GetDatas()
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
return false;
|
||||
}
|
||||
public override bool SetDatas()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
return false;
|
||||
}
|
||||
public override bool CommitDatas()
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override List<String> GetProcedureKits()
|
||||
{
|
||||
List<String> procedureKits = new List<String>();
|
||||
return procedureKits;
|
||||
}
|
||||
public override List<String> GetAllergies()
|
||||
{
|
||||
List<String> allergies = new List<String>();
|
||||
return allergies;
|
||||
}
|
||||
public override List<String> GetRiskFactors()
|
||||
{
|
||||
List<String> riskfactors = new List<String>();
|
||||
return riskfactors;
|
||||
}
|
||||
public override bool SetProcedureKits(List<String> procedures)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public override bool SetAllergies(List<String> allergies)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public override bool SetRiskFactors(List<String> riskFactors)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool ClearAssociatedData()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmDepartment_Dbas : SpmDepartment
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmDepartment_Dbas(SpmUserContext userContext, SysId id, ushort flags) :
|
||||
base(id)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmEmployeeRole_Dbas : SpmEmployeeRole
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmEmployeeRole_Dbas(SpmUserContext userContext, SysId departmentId, SysId employeeId, Spm.EmployeeRole employeeRole, ushort flags) :
|
||||
base(departmentId, employeeId, employeeRole)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmEmployee_Dbas : SpmEmployee
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmEmployee_Dbas(SpmUserContext userContext, SysId id, SysId institutionId, ushort flags) :
|
||||
base(id, institutionId)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmFacilitySession_Dbas : SpmFacilitySession
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmFacilitySession_Dbas(SpmUserContext userContext, SysId facilityId, SysId facilityTemplateId, DateTime sessionDate, ushort flags) :
|
||||
base(facilityId, facilityTemplateId, sessionDate)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmFacilityTemplate_Dbas : SpmFacilityTemplate
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmFacilityTemplate_Dbas(SpmUserContext userContext, SysId facilityId, Spm.ResourceCategory resourceCategory, ushort flags) :
|
||||
base(facilityId, resourceCategory)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmFacility_Dbas : SpmFacility
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmFacility_Dbas(SpmUserContext userContext, SysId facilityId, SysId departmentId, Spm.FacilityType facilityType, ushort flags) :
|
||||
base(facilityId, departmentId, facilityType)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmInstitution_Dbas : SpmInstitution
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmInstitution_Dbas(SpmUserContext userContext, SysId id, ushort flags) : base(id)
|
||||
{
|
||||
id = Id;
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmOperation_Dbas : SpmOperation
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmOperation_Dbas(SpmUserContext userContext, SysId departmentId, SysId institutionId, ushort flags) :
|
||||
base(departmentId, institutionId)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmPatient_Dbas : SpmPatient
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmPatient_Dbas(SpmUserContext userContext, SysId id, SysId institutionId, ushort flags) :
|
||||
base(id, institutionId)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmProcedure_Dbas : SpmProcedure
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmProcedure_Dbas(SpmUserContext userContext, SysId id, SysId departmentId, ushort flags) :
|
||||
base(id, departmentId)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.Core.Interfaces;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SpmTemplateData_Dbas : SpmTemplateData
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SpmUserContext userContext;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmTemplateData_Dbas(SpmUserContext userContext, SysId id, ushort flags) :
|
||||
base(id)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Associated data.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,715 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmAdmissionMgr_Dbas : SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n A c t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction exists.
|
||||
public override bool AdmissionActionExistsById(SysId admissionActionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionActionId)) return false;
|
||||
SpmAdmissionAction.Params prmAdmissionAction = new SpmAdmissionAction.Params();
|
||||
prmAdmissionAction.IncludedIds.Add(admissionActionId);
|
||||
prmAdmissionAction.StatusCat = SpmAdmissionAction.StatusCat.Any;
|
||||
return GetAdmissionActionCount(prmAdmissionAction) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get AdmissionAction.
|
||||
public override SpmAdmissionAction GetAdmissionAction(SpmAdmissionAction.Params prm)
|
||||
{
|
||||
return GetAdmissionAction(GetAdmissionActionQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmAdmissionAction GetAdmissionAction(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetAdmissionActionCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple AdmissionActiones found");
|
||||
return null;
|
||||
}
|
||||
SpmAdmissionAction admissionAction = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionAction_Db dbAdmissionAction = new SwmAdmissionAction_Db(DbInfo);
|
||||
dbAdmissionAction.PopulateFrom(dbCommand, aliasAdmissionAction, filter);
|
||||
admissionAction = CreateAdmissionAction(dbAdmissionAction);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionAction\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return admissionAction;
|
||||
}
|
||||
public override SpmAdmissionAction GetAdmissionActionById(SysId admissionActionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionActionId)) return null;
|
||||
SpmAdmissionAction.Params prmAdmissionAction = new SpmAdmissionAction.Params();
|
||||
prmAdmissionAction.IncludedIds.Add(admissionActionId);
|
||||
prmAdmissionAction.StatusCat = SpmAdmissionAction.StatusCat.Any;
|
||||
return GetAdmissionAction(prmAdmissionAction);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create AdmissionAction.
|
||||
public override SpmAdmissionAction CreateAdmissionAction(SysId admissionId, Spm.AdmissionActionType admissionActionType)
|
||||
{
|
||||
return new SpmAdmissionAction_Dbas(UserContext, null, admissionId, admissionActionType, 0);
|
||||
}
|
||||
private SpmAdmissionAction_Dbas CreateAdmissionAction(SwmAdmissionAction_Db dbAdmissionAction)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmAdmissionAction_Dbas admissionAction = new SpmAdmissionAction_Dbas(UserContext, new SysId(dbAdmissionAction._Id), new SysId(dbAdmissionAction._AdmissionId), (Spm.AdmissionActionType)dbAdmissionAction._Type, (ushort)dbAdmissionAction._Flags);
|
||||
PopulateFrom(dbAdmissionAction, admissionAction);
|
||||
return admissionAction;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate AdmissionAction.
|
||||
public override bool IsValidAdmissionActionData(SpmAdmissionAction.Data data, SpmAdmissionAction.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidAdmissionActionData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert AdmissionAction.
|
||||
public override bool InsertAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionAction(admissionAction)) return false;
|
||||
if (SysId.IsValid(admissionAction.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionAction_Db dbAdmissionAction = new SwmAdmissionAction_Db(DbInfo);
|
||||
PopulateTo(dbAdmissionAction, admissionAction, dbUpdateInfo);
|
||||
if (SwmAdmissionAction_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbAdmissionAction._Id = SysId.ToInt(db.GetNextId("AdmissionAction", dbUpdateInfo));
|
||||
}
|
||||
dbAdmissionAction.ExecuteInsertCommand(dbCommand);
|
||||
admissionAction.Id = new SysId(dbAdmissionAction._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update AdmissionAction.
|
||||
public override bool UpdateAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionAction(admissionAction)) return false;
|
||||
if (!SysId.IsValid(admissionAction.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionAction.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionAction_Db dbAdmissionAction = new SwmAdmissionAction_Db(DbInfo);
|
||||
dbAdmissionAction.PopulateFrom(dbCommand, aliasAdmissionAction, "Id=" + SysId.ToString(admissionAction.Id));
|
||||
//SpmUpdateLogItemMonitor_AdmissionAction updateLogMonitor = new SpmUpdateLogItemMonitor_AdmissionAction(UserContext, CreateAdmissionAction(dbAdmissionAction));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbAdmissionAction, admissionAction, dbUpdateInfo);
|
||||
dbAdmissionAction.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(admissionAction);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete AdmissionAction.
|
||||
public override bool AdmissionActionCanBeDeleted(SpmAdmissionAction admissionAction)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.AdmissionActionCanBeDeleted(admissionAction)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteAdmissionAction(SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!AdmissionActionCanBeDeleted(admissionAction)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionAction.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionAction_Db dbAdmissionAction = new SwmAdmissionAction_Db(DbInfo);
|
||||
dbAdmissionAction.PopulateFrom(dbCommand, aliasAdmissionAction, "Id=" + admissionAction.Id.ToString());
|
||||
// Delete AdmissionAction.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionAction) + " WHERE Id=" + SysId.ToString(admissionAction.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmAdmissionAction_Db dbAdmissionAction, SpmAdmissionAction admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbAdmissionAction._Id = admissionAction.Id.ToInt();
|
||||
dbAdmissionAction._AdmissionId = admissionAction.AdmissionId.ToInt();
|
||||
dbAdmissionAction._Type = (short)admissionAction.AdmissionActionType;
|
||||
dbAdmissionAction._Raised = admissionAction.Raised;
|
||||
dbAdmissionAction._EmployeeIdRaised = admissionAction.EmployeeIdRaised.ToInt();
|
||||
dbAdmissionAction._Completed = admissionAction.Completed;
|
||||
dbAdmissionAction._EmployeeIdCompleted = admissionAction.EmployeeIdCompleted.ToInt();
|
||||
dbAdmissionAction._ActionData = admissionAction.ActionData;
|
||||
|
||||
dbAdmissionAction._Notes = admissionAction.Notes;
|
||||
dbAdmissionAction._Status = SacsSystem.GetStatusCode(admissionAction.Status);
|
||||
dbAdmissionAction._Flags = (short)admissionAction.Flags;
|
||||
if (!SysId.IsValid(admissionAction.Id))
|
||||
{
|
||||
dbAdmissionAction._CreateOn = DateTime.UtcNow;
|
||||
dbAdmissionAction._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionAction._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbAdmissionAction._UpdateOn = DateTime.UtcNow;
|
||||
dbAdmissionAction._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionAction._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmAdmissionAction_Db dbAdmissionAction, SpmAdmissionAction admissionAction)
|
||||
{
|
||||
admissionAction.Id = new SysId(dbAdmissionAction._Id);
|
||||
admissionAction.AdmissionId = new SysId(dbAdmissionAction._AdmissionId);
|
||||
admissionAction.AdmissionActionType = (Spm.AdmissionActionType)dbAdmissionAction._Type;
|
||||
admissionAction.Raised = dbAdmissionAction._Raised;
|
||||
admissionAction.EmployeeIdRaised = new SysId(dbAdmissionAction._EmployeeIdRaised);
|
||||
admissionAction.Completed = dbAdmissionAction._Completed;
|
||||
admissionAction.EmployeeIdCompleted = new SysId(dbAdmissionAction._EmployeeIdCompleted);
|
||||
admissionAction.ActionData = dbAdmissionAction._ActionData;
|
||||
|
||||
admissionAction.Notes = dbAdmissionAction._Notes;
|
||||
admissionAction.Status = SacsSystem.GetStatusForCode(dbAdmissionAction._Status);
|
||||
admissionAction.SetCreateStamp(dbAdmissionAction._CreateOn, new SysId(dbAdmissionAction._CreateBy), dbAdmissionAction._CreateHost);
|
||||
admissionAction.SetUpdateStamp(dbAdmissionAction._UpdateOn, new SysId(dbAdmissionAction._UpdateBy), dbAdmissionAction._UpdateHost);
|
||||
admissionAction.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction column definitions.
|
||||
private static readonly String aliasAdmissionAction = "aAdmAct";
|
||||
private void SetAdmissionActionColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmAdmissionAction)
|
||||
alias = aliasAdmissionAction;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmAdmissionAction column definition.
|
||||
public override ColumnDfn GetAdmissionActionColumnDfn(SpmAdmissionAction.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmAdmissionAction.Column.Pos:
|
||||
SetAdmissionActionColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Id:
|
||||
SetAdmissionActionColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// AdmissionAction Properties.
|
||||
case SpmAdmissionAction.Column.AdmissionId:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmId", 55, SpmDbDfn.ColumnIdx.SwmAdmissionAction_AdmissionId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Type:
|
||||
SetAdmissionActionColDfn(columnDfn, "Type", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Type_Desc:
|
||||
SetAdmissionActionColDfn(columnDfn, "Type", 100, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type);
|
||||
break;
|
||||
|
||||
|
||||
case SpmAdmissionAction.Column.Notes:
|
||||
SetAdmissionActionColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Notes);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Flags:
|
||||
SetAdmissionActionColDfn(columnDfn, "Flags", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Flags);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Status:
|
||||
SetAdmissionActionColDfn(columnDfn, "Status", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Status_Desc:
|
||||
SetAdmissionActionColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Status_Ind:
|
||||
SetAdmissionActionColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
break;
|
||||
|
||||
// Admission details.
|
||||
case SpmAdmissionAction.Column.Admission_FacilityId:
|
||||
SetAdmissionActionColDfn(columnDfn, "FacId", 45, SpmDbDfn.ColumnIdx.SwmAdmission_FacilityId, ColumnAlignment.Right, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Admission_TemplateId:
|
||||
SetAdmissionActionColDfn(columnDfn, "FacId", 45, SpmDbDfn.ColumnIdx.SwmAdmission_FacilityTemplateId, ColumnAlignment.Right, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionFrom:
|
||||
SetAdmissionActionColDfn(columnDfn, "From", 100, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionFrom, ColumnAlignment.Center, DataValue.DataType.DateTime, aliasAdmission, prefixAdmission);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
columnDfn.TimeFormat = "HH:mm";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionFromDateTime:
|
||||
SetAdmissionActionColDfn(columnDfn, "From", 120, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionFrom, ColumnAlignment.Center, DataValue.DataType.DateTime, aliasAdmission, prefixAdmission);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
columnDfn.TimeFormat = "HH:mm";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionFromDate:
|
||||
SetAdmissionActionColDfn(columnDfn, "From", 80, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionFrom, ColumnAlignment.Center, DataValue.DataType.Date, aliasAdmission, prefixAdmission);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionFromTime:
|
||||
SetAdmissionActionColDfn(columnDfn, "From", 40, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionFrom, ColumnAlignment.Center, DataValue.DataType.Time, aliasAdmission, prefixAdmission);
|
||||
columnDfn.TimeFormat = "HH:mm";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionTo:
|
||||
SetAdmissionActionColDfn(columnDfn, "To", 100, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionTo, ColumnAlignment.Center, DataValue.DataType.DateTime, aliasAdmission, prefixAdmission);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
columnDfn.TimeFormat = "HH:mm";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionToDate:
|
||||
SetAdmissionActionColDfn(columnDfn, "To", 80, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionTo, ColumnAlignment.Center, DataValue.DataType.Date, aliasAdmission, prefixAdmission);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionToTime:
|
||||
SetAdmissionActionColDfn(columnDfn, "To", 40, SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionTo, ColumnAlignment.Center, DataValue.DataType.Time, aliasAdmission, prefixAdmission);
|
||||
columnDfn.TimeFormat = "HH:mm";
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionType:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmType", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, ColumnAlignment.Center, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionTypeDesc:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmType", 90, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionNotes:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmNotes", 200, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Notes, ColumnAlignment.Center, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionFlags:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmFlags", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Flags, ColumnAlignment.Center, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionStatus:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmStatus", 40, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, ColumnAlignment.Center, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.AdmissionStatusInd:
|
||||
SetAdmissionActionColDfn(columnDfn, "AdmStatus", 50, SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, ColumnAlignment.Center, DataValue.DataType.TriState, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
|
||||
// Patient.
|
||||
case SpmAdmissionAction.Column.Patient:
|
||||
SetAdmissionActionColDfn(columnDfn, "Patient", 200, SpmDbDfn.ColumnIdx.SwmAdmission_PatientNo, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.PatientId:
|
||||
SetAdmissionActionColDfn(columnDfn, "Patient Id", 80, SpmDbDfn.ColumnIdx.SwmAdmission_PatientId, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.PatientNo:
|
||||
SetAdmissionActionColDfn(columnDfn, "Patient No", 80, SpmDbDfn.ColumnIdx.SwmAdmission_PatientNo, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.PatientSurname:
|
||||
SetAdmissionActionColDfn(columnDfn, "Surname", 90, SpmDbDfn.ColumnIdx.SwmAdmission_Surname, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.PatientForename:
|
||||
SetAdmissionActionColDfn(columnDfn, "Forename", 90, SpmDbDfn.ColumnIdx.SwmAdmission_Forename, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission, prefixAdmission);
|
||||
break;
|
||||
|
||||
// Facility.
|
||||
case SpmAdmissionAction.Column.Facility_Name:
|
||||
SetAdmissionActionColDfn(columnDfn, "Facility Name", 100, SpmDbDfn.ColumnIdx.SwmFacility_Name, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission_Facility, prefixAdmission_Facility);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Facility_Desc:
|
||||
SetAdmissionActionColDfn(columnDfn, "Facility Desc", 120, SpmDbDfn.ColumnIdx.SwmFacility_Description, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission_Facility, prefixAdmission_Facility);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Facility_Notes:
|
||||
SetAdmissionActionColDfn(columnDfn, "Facility Notes", 200, SpmDbDfn.ColumnIdx.SwmFacility_Notes, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission_Facility, prefixAdmission_Facility);
|
||||
break;
|
||||
|
||||
// Facility Template.
|
||||
case SpmAdmissionAction.Column.Template_Name:
|
||||
SetAdmissionActionColDfn(columnDfn, "Template Name", 100, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Name, ColumnAlignment.Center, DataValue.DataType.String, aliasAdmission_Template, prefixAdmission_Template);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Template_Desc:
|
||||
SetAdmissionActionColDfn(columnDfn, "Template Desc", 160, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Description, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission_Template, prefixAdmission_Template);
|
||||
break;
|
||||
case SpmAdmissionAction.Column.Template_Notes:
|
||||
SetAdmissionActionColDfn(columnDfn, "Tmpl Notes", 200, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Notes, ColumnAlignment.Default, DataValue.DataType.String, aliasAdmission_Template, prefixAdmission_Template);
|
||||
break;
|
||||
|
||||
// Session definition (combined template and date-specific session info).
|
||||
case SpmAdmissionAction.Column.SessionDfn_Summary:
|
||||
SetAdmissionActionColDfn(columnDfn, "Session", 160, SpmDbDfn.ColumnIdx.Unknown);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmAdmissionAction.Column.CreateOn_Date:
|
||||
SetAdmissionActionColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmAdmissionAction_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmAdmissionAction.Column.UpdateOn_Date:
|
||||
SetAdmissionActionColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmAdmissionAction_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction query filter.
|
||||
public override List<string> GetAdmissionActionQueryFilter(SpmAdmissionAction.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// AdmissionAction Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Id, aliasAdmissionAction) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Id, aliasAdmissionAction) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Department Id - join via Facility table.
|
||||
List<String> filtersDepartIdFacilityId = new List<String>();
|
||||
if (SysId.IsValid(prm.DepartmentId))
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_DepartmentId, aliasAdmission_Facility) + "=" + prm.DepartmentId.ToString());
|
||||
else
|
||||
{
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(new StringPair(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), aliasAdmission_Facility));
|
||||
qry.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Id));
|
||||
qry.Filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_DepartmentId) + "=" + prm.DepartmentId.ToString());
|
||||
filtersDepartIdFacilityId.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityId, aliasAdmission) + " IN (" + qry.BuildQuery() + ")");
|
||||
}
|
||||
|
||||
// Facility Id.
|
||||
if (SysId.IsValid(prm.FacilityId))
|
||||
filtersDepartIdFacilityId.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityId, aliasAdmission) + "=" + prm.FacilityId.ToString());
|
||||
else
|
||||
{
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(new StringPair(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmission), aliasAdmission));
|
||||
qry.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_Id, aliasAdmission));
|
||||
qry.Filters.AddRange(filtersDepartIdFacilityId);
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_AdmissionId, aliasAdmissionAction) + " IN (" + qry.BuildQuery() + ")");
|
||||
}
|
||||
|
||||
// Action type.
|
||||
if (prm.AdmissionActionType > 0)
|
||||
{
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, aliasAdmissionAction) + "=" + ((int)prm.AdmissionActionType).ToString());
|
||||
}
|
||||
|
||||
// Action status.
|
||||
if (prm.RequiredOnly)
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, aliasAdmissionAction) + "='" + SacsSystem.GetStatusCode(SaStatus.Required) + "'");
|
||||
else if (prm.ExcludeCancelled)
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, aliasAdmissionAction) + "!='" + SacsSystem.GetStatusCode(SaStatus.Cancelled) + "'");
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction sort columns.
|
||||
public List<String> GetAdmissionActionSortColumns(SpmAdmissionAction.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for AdmissionAction columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmAdmissionAction)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasAdmissionAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, aliasAdmissionAction) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction count.
|
||||
private long GetAdmissionActionCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionAction) + " As " + aliasAdmissionAction, filter);
|
||||
}
|
||||
public override long GetAdmissionActionCount(SpmAdmissionAction.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetAdmissionActionCount(GetAdmissionActionQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction list.
|
||||
public override List<SpmAdmissionAction> GetAdmissionActionList(SpmAdmissionAction.Params prm)
|
||||
{
|
||||
List<SpmAdmissionAction> AdmissionActiones = new List<SpmAdmissionAction>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionAction), aliasAdmissionAction);
|
||||
qry.Columns.AddRange(SwmAdmissionAction_Db.Fields);
|
||||
qry.Filters.AddRange(GetAdmissionActionQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmAdmissionAction_Db dbAdmissionAction = new SwmAdmissionAction_Db(DbInfo);
|
||||
dbAdmissionAction.PopulateFrom(dbDataReader);
|
||||
AdmissionActiones.Add(CreateAdmissionAction(dbAdmissionAction));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionActionList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return AdmissionActiones;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionAction query execution.
|
||||
public override DbResultSet ExecuteAdmissionActionQuery(List<ColumnDfn> columns, SpmAdmissionAction.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionAction), aliasAdmissionAction);
|
||||
|
||||
// AdmissionAction Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Id, aliasAdmissionAction));
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.AdmissionId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_AdmissionId, aliasAdmissionAction));
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.Type) || columns.HasId((int)SpmAdmissionAction.Column.Type_Desc))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Type, aliasAdmissionAction));
|
||||
|
||||
// Join to Admission table.
|
||||
DbQueryJoin joinAdm = new DbQueryJoin(DbJoinType.Inner);
|
||||
joinAdm.Table = new StringPair(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmission), aliasAdmission);
|
||||
joinAdm.Filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_Id, aliasAdmission) + "=" + SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_AdmissionId));
|
||||
query.Joins.Add(joinAdm);
|
||||
|
||||
// Add the Admission columns.
|
||||
List<SpmDbDfn.ColumnIdx> admissionCols = new List<SpmDbDfn.ColumnIdx>();
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Id);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityId);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityTemplateId);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionFrom);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_AdmissionTo);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Seq);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Type);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_PatientId);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_PatientNo);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Surname);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Forename);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Notes);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Flags);
|
||||
admissionCols.Add(SpmDbDfn.ColumnIdx.SwmAdmission_Status);
|
||||
foreach (SpmDbDfn.ColumnIdx dbColumn in admissionCols)
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(dbColumn, aliasAdmission), prefixAdmission + SpmDbDfn.GetColumnName(dbColumn, false));
|
||||
|
||||
// Facility.
|
||||
bool hasFacilityCols = false;
|
||||
if (!hasFacilityCols) hasFacilityCols = columns.HasId((int)SpmAdmissionAction.Column.Facility_Name);
|
||||
if (!hasFacilityCols) hasFacilityCols = columns.HasId((int)SpmAdmissionAction.Column.Facility_Desc);
|
||||
if (!hasFacilityCols) hasFacilityCols = columns.HasId((int)SpmAdmissionAction.Column.Facility_Notes);
|
||||
if (hasFacilityCols)
|
||||
{
|
||||
// Join to the Facility.
|
||||
DbQueryJoin joinFacility = new DbQueryJoin(DbJoinType.LeftOuter);;
|
||||
joinFacility.Table = new StringPair(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), aliasAdmission_Facility);
|
||||
joinFacility.Filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Id, aliasAdmission_Facility) + "=" + SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityId, aliasAdmission));
|
||||
query.Joins.Add(joinFacility);
|
||||
|
||||
// Add the Facility columns.
|
||||
List<SpmDbDfn.ColumnIdx> facilityCols = new List<SpmDbDfn.ColumnIdx>();
|
||||
facilityCols.Add(SpmDbDfn.ColumnIdx.SwmFacility_Type);
|
||||
facilityCols.Add(SpmDbDfn.ColumnIdx.SwmFacility_Name);
|
||||
facilityCols.Add(SpmDbDfn.ColumnIdx.SwmFacility_Description);
|
||||
facilityCols.Add(SpmDbDfn.ColumnIdx.SwmFacility_Notes);
|
||||
foreach (SpmDbDfn.ColumnIdx dbColumn in facilityCols)
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(dbColumn, aliasAdmission_Facility), prefixAdmission_Facility + SpmDbDfn.GetColumnName(dbColumn, false));
|
||||
}
|
||||
|
||||
// Template.
|
||||
bool hasTemplateCols = false;
|
||||
if (!hasTemplateCols) hasTemplateCols = columns.HasId((int)SpmAdmissionAction.Column.Template_Name);
|
||||
if (!hasTemplateCols) hasTemplateCols = columns.HasId((int)SpmAdmissionAction.Column.Template_Desc);
|
||||
if (!hasTemplateCols) hasTemplateCols = columns.HasId((int)SpmAdmissionAction.Column.Template_Notes);
|
||||
if (!hasTemplateCols) hasTemplateCols = columns.HasId((int)SpmAdmissionAction.Column.SessionDfn_Summary);
|
||||
if (hasTemplateCols)
|
||||
{
|
||||
// Join to the Template table.
|
||||
DbQueryJoin joinTmpl = new DbQueryJoin(DbJoinType.LeftOuter);;
|
||||
joinTmpl.Table = new StringPair(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate), aliasAdmission_Template);
|
||||
joinTmpl.Filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id, aliasAdmission_Template) + "=" + SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmission_FacilityTemplateId, aliasAdmission));
|
||||
query.Joins.Add(joinTmpl);
|
||||
|
||||
// Add the template columns.
|
||||
List<SpmDbDfn.ColumnIdx> templateCols = new List<SpmDbDfn.ColumnIdx>();
|
||||
templateCols.Add(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Name);
|
||||
templateCols.Add(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Description);
|
||||
templateCols.Add(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Notes);
|
||||
foreach (SpmDbDfn.ColumnIdx dbColumn in templateCols)
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(dbColumn, aliasAdmission_Template), prefixAdmission_Template + SpmDbDfn.GetColumnName(dbColumn, false));
|
||||
}
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Notes, aliasAdmissionAction));
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.Status) || columns.HasId((int)SpmAdmissionAction.Column.Status_Desc) || columns.HasId((int)SpmAdmissionAction.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_Status, aliasAdmissionAction));
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_CreateOn, aliasAdmissionAction));
|
||||
if (columns.HasId((int)SpmAdmissionAction.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionAction_UpdateOn, aliasAdmissionAction));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetAdmissionActionQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetAdmissionActionSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetAdmissionActionDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmAdmissionAction.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmAdmissionAction.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmAdmissionAction.Column.Status_Desc:
|
||||
case SpmAdmissionAction.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmAdmissionAction.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmAdmissionAction.Column.Status_Ind)
|
||||
value = new DataValue(SpmAdmissionAction.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmAdmissionMgr_Dbas : SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n D a t a
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData exists.
|
||||
public override bool AdmissionDataExistsById(SysId admissionDataId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionDataId)) return false;
|
||||
SpmAdmissionData.Params prmAdmissionData = new SpmAdmissionData.Params();
|
||||
prmAdmissionData.IncludedIds.Add(admissionDataId);
|
||||
prmAdmissionData.StatusCat = SpmAdmissionData.StatusCat.Any;
|
||||
return GetAdmissionDataCount(prmAdmissionData) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get AdmissionData.
|
||||
public override SpmAdmissionData GetAdmissionData(SpmAdmissionData.Params prm)
|
||||
{
|
||||
return GetAdmissionData(GetAdmissionDataQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmAdmissionData GetAdmissionData(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetAdmissionDataCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple AdmissionDataes found");
|
||||
return null;
|
||||
}
|
||||
SpmAdmissionData admissionData = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionData_Db dbAdmissionData = new SwmAdmissionData_Db(DbInfo);
|
||||
dbAdmissionData.PopulateFrom(dbCommand, aliasAdmissionData, filter);
|
||||
admissionData = CreateAdmissionData(dbAdmissionData);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionData\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return admissionData;
|
||||
}
|
||||
public override SpmAdmissionData GetAdmissionDataById(SysId admissionDataId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionDataId)) return null;
|
||||
SpmAdmissionData.Params prmAdmissionData = new SpmAdmissionData.Params();
|
||||
prmAdmissionData.IncludedIds.Add(admissionDataId);
|
||||
prmAdmissionData.StatusCat = SpmAdmissionData.StatusCat.Any;
|
||||
return GetAdmissionData(prmAdmissionData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create AdmissionData.
|
||||
public override SpmAdmissionData CreateAdmissionData(SysId admissionId, Spm.AdmissionDataType admissionDataType)
|
||||
{
|
||||
return new SpmAdmissionData_Dbas(UserContext, admissionId, admissionDataType, 0);
|
||||
}
|
||||
private SpmAdmissionData_Dbas CreateAdmissionData(SwmAdmissionData_Db dbAdmissionData)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmAdmissionData_Dbas admissionData = new SpmAdmissionData_Dbas(UserContext, new SysId(dbAdmissionData._AdmissionId), (Spm.AdmissionDataType)dbAdmissionData._Type, (ushort)dbAdmissionData._Flags);
|
||||
PopulateFrom(dbAdmissionData, admissionData);
|
||||
return admissionData;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate AdmissionData.
|
||||
public override bool IsValidAdmissionDataData(SpmAdmissionData.Data data, SpmAdmissionData.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidAdmissionDataData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert AdmissionData.
|
||||
public override bool InsertAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionData(admissionData)) return false;
|
||||
if (SysId.IsValid(admissionData.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionData_Db dbAdmissionData = new SwmAdmissionData_Db(DbInfo);
|
||||
PopulateTo(dbAdmissionData, admissionData, dbUpdateInfo);
|
||||
if (SwmAdmissionData_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
//dbAdmissionData._Id = SysId.ToInt(db.GetNextId("AdmissionData", dbUpdateInfo));
|
||||
}
|
||||
dbAdmissionData.ExecuteInsertCommand(dbCommand);
|
||||
//admissionData.Id = new SysId(dbAdmissionData._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update AdmissionData.
|
||||
public override bool UpdateAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionData(admissionData)) return false;
|
||||
if (!SysId.IsValid(admissionData.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionData.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionData_Db dbAdmissionData = new SwmAdmissionData_Db(DbInfo);
|
||||
dbAdmissionData.PopulateFrom(dbCommand, aliasAdmissionData, "Id=" + SysId.ToString(admissionData.Id));
|
||||
//SpmUpdateLogItemMonitor_AdmissionData updateLogMonitor = new SpmUpdateLogItemMonitor_AdmissionData(UserContext, CreateAdmissionData(dbAdmissionData));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbAdmissionData, admissionData, dbUpdateInfo);
|
||||
dbAdmissionData.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(admissionData);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete AdmissionData.
|
||||
public override bool AdmissionDataCanBeDeleted(SpmAdmissionData admissionData)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.AdmissionDataCanBeDeleted(admissionData)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteAdmissionData(SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!AdmissionDataCanBeDeleted(admissionData)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionData.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionData_Db dbAdmissionData = new SwmAdmissionData_Db(DbInfo);
|
||||
dbAdmissionData.PopulateFrom(dbCommand, aliasAdmissionData, "Id=" + admissionData.Id.ToString());
|
||||
// Delete AdmissionData.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionData) + " WHERE Id=" + SysId.ToString(admissionData.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmAdmissionData_Db dbAdmissionData, SpmAdmissionData admissionData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbAdmissionData._AdmissionId = admissionData.AdmissionId.ToInt();
|
||||
dbAdmissionData._Type = (short)admissionData.AdmissionDataType;
|
||||
dbAdmissionData._Data = admissionData.AdmissionData;
|
||||
|
||||
dbAdmissionData._Notes = admissionData.Notes;
|
||||
dbAdmissionData._Status = SacsSystem.GetStatusCode(admissionData.Status);
|
||||
dbAdmissionData._Flags = (short)admissionData.Flags;
|
||||
if (!SysId.IsValid(admissionData.Id))
|
||||
{
|
||||
dbAdmissionData._CreateOn = DateTime.UtcNow;
|
||||
dbAdmissionData._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionData._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbAdmissionData._UpdateOn = DateTime.UtcNow;
|
||||
dbAdmissionData._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionData._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmAdmissionData_Db dbAdmissionData, SpmAdmissionData admissionData)
|
||||
{
|
||||
admissionData.AdmissionId = new SysId(dbAdmissionData._AdmissionId);
|
||||
admissionData.AdmissionDataType = (Spm.AdmissionDataType)dbAdmissionData._Type;
|
||||
admissionData.AdmissionData = dbAdmissionData._Data;
|
||||
|
||||
admissionData.Notes = dbAdmissionData._Notes;
|
||||
admissionData.Status = SacsSystem.GetStatusForCode(dbAdmissionData._Status);
|
||||
admissionData.SetCreateStamp(dbAdmissionData._CreateOn, new SysId(dbAdmissionData._CreateBy), dbAdmissionData._CreateHost);
|
||||
admissionData.SetUpdateStamp(dbAdmissionData._UpdateOn, new SysId(dbAdmissionData._UpdateBy), dbAdmissionData._UpdateHost);
|
||||
admissionData.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData column definitions.
|
||||
private static readonly String aliasAdmissionData = "aAdmData";
|
||||
private void SetAdmissionDataColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmAdmissionData)
|
||||
alias = aliasAdmissionData;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmAdmissionData column definition.
|
||||
public override ColumnDfn GetAdmissionDataColumnDfn(SpmAdmissionData.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmAdmissionData.Column.Pos:
|
||||
SetAdmissionDataColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
|
||||
// AdmissionData Properties.
|
||||
case SpmAdmissionData.Column.AdmissionId:
|
||||
SetAdmissionDataColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmAdmissionData_AdmissionId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmAdmissionData.Column.Type:
|
||||
SetAdmissionDataColDfn(columnDfn, "Type", 40, SpmDbDfn.ColumnIdx.SwmAdmissionData_Type, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionData.Column.Type_Desc:
|
||||
SetAdmissionDataColDfn(columnDfn, "Type", 100, SpmDbDfn.ColumnIdx.SwmAdmissionData_Type);
|
||||
break;
|
||||
case SpmAdmissionData.Column.AdmissionData:
|
||||
SetAdmissionDataColDfn(columnDfn, "Admission Data", 90, SpmDbDfn.ColumnIdx.SwmAdmissionData_Data);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmAdmissionData.Column.Notes:
|
||||
SetAdmissionDataColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmAdmissionData_Notes);
|
||||
break;
|
||||
case SpmAdmissionData.Column.Status:
|
||||
SetAdmissionDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionData_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionData.Column.Status_Desc:
|
||||
SetAdmissionDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionData_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionData.Column.Status_Ind:
|
||||
SetAdmissionDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionData_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmAdmissionData.Column.CreateOn_Date:
|
||||
SetAdmissionDataColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmAdmissionData_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmAdmissionData.Column.UpdateOn_Date:
|
||||
SetAdmissionDataColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmAdmissionData_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData query filter.
|
||||
public override List<string> GetAdmissionDataQueryFilter(SpmAdmissionData.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// AdmissionData Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_AdmissionId, aliasAdmissionData) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_AdmissionId, aliasAdmissionData) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Admission Id.
|
||||
String colAdmisssionData_AdmissionId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_AdmissionId, aliasAdmissionData);
|
||||
if (SysId.IsValid(prm.AdmissionId))
|
||||
filters.Add(colAdmisssionData_AdmissionId + "=" + prm.AdmissionId.ToString());
|
||||
|
||||
String colType = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Type, aliasAdmissionData);
|
||||
if (prm.AdmissionDataType > 0)
|
||||
filters.Add(colType + "=" + ((int)prm.AdmissionDataType).ToString());
|
||||
|
||||
|
||||
// AdmissionData.
|
||||
String colAdmissionData = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Data, aliasAdmissionData);
|
||||
if (StringUtil.IsEmpty(prm.AdmissionData))
|
||||
filters.Add(colAdmissionData + "=" + DbQuery.FormatForCondition(prm.AdmissionData));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData sort columns.
|
||||
public List<String> GetAdmissionDataSortColumns(SpmAdmissionData.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for AdmissionData columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmAdmissionData)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasAdmissionData);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Type, aliasAdmissionData) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData count.
|
||||
private long GetAdmissionDataCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionData) + " As " + aliasAdmissionData, filter);
|
||||
}
|
||||
public override long GetAdmissionDataCount(SpmAdmissionData.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetAdmissionDataCount(GetAdmissionDataQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData list.
|
||||
public override List<SpmAdmissionData> GetAdmissionDataList(SpmAdmissionData.Params prm)
|
||||
{
|
||||
List<SpmAdmissionData> AdmissionDataes = new List<SpmAdmissionData>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionData), aliasAdmissionData);
|
||||
qry.Columns.AddRange(SwmAdmissionData_Db.Fields);
|
||||
qry.Filters.AddRange(GetAdmissionDataQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmAdmissionData_Db dbAdmissionData = new SwmAdmissionData_Db(DbInfo);
|
||||
dbAdmissionData.PopulateFrom(dbDataReader);
|
||||
AdmissionDataes.Add(CreateAdmissionData(dbAdmissionData));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionDataList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return AdmissionDataes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionData query execution.
|
||||
public override DbResultSet ExecuteAdmissionDataQuery(List<ColumnDfn> columns, SpmAdmissionData.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionData), aliasAdmissionData);
|
||||
|
||||
// AdmissionData Properties - add columns as defined in query list.
|
||||
/*if (columns.HasId((int)SpmAdmissionData.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_, aliasAdmissionData));*/
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.AdmissionId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_AdmissionId, aliasAdmissionData));
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.Type) || columns.HasId((int)SpmAdmissionData.Column.Type_Desc))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Type, aliasAdmissionData));
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.AdmissionData))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Data, aliasAdmissionData));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Notes, aliasAdmissionData));
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.Status) || columns.HasId((int)SpmAdmissionData.Column.Status_Desc) || columns.HasId((int)SpmAdmissionData.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_Status, aliasAdmissionData));
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_CreateOn, aliasAdmissionData));
|
||||
if (columns.HasId((int)SpmAdmissionData.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionData_UpdateOn, aliasAdmissionData));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetAdmissionDataQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetAdmissionDataSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetAdmissionDataDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmAdmissionData.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmAdmissionData.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmAdmissionData.Column.Status_Desc:
|
||||
case SpmAdmissionData.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmAdmissionData.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmAdmissionData.Column.Status_Ind)
|
||||
value = new DataValue(SpmAdmissionData.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,554 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmAdmissionMgr_Dbas : SpmAdmissionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n R o l e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole exists.
|
||||
public override bool AdmissionRoleExistsById(SysId admissionRoleId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionRoleId)) return false;
|
||||
SpmAdmissionRole.Params prmAdmissionRole = new SpmAdmissionRole.Params();
|
||||
prmAdmissionRole.IncludedIds.Add(admissionRoleId);
|
||||
prmAdmissionRole.StatusCat = SpmAdmissionRole.StatusCat.Any;
|
||||
return GetAdmissionRoleCount(prmAdmissionRole) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get AdmissionRole.
|
||||
public override SpmAdmissionRole GetAdmissionRole(SpmAdmissionRole.Params prm)
|
||||
{
|
||||
return GetAdmissionRole(GetAdmissionRoleQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmAdmissionRole GetAdmissionRole(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetAdmissionRoleCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple AdmissionRolees found");
|
||||
return null;
|
||||
}
|
||||
SpmAdmissionRole admissionRole = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionRole_Db dbAdmissionRole = new SwmAdmissionRole_Db(DbInfo);
|
||||
dbAdmissionRole.PopulateFrom(dbCommand, aliasAdmissionRole, filter);
|
||||
admissionRole = CreateAdmissionRole(dbAdmissionRole);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionRole\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return admissionRole;
|
||||
}
|
||||
public override SpmAdmissionRole GetAdmissionRoleById(SysId admissionRoleId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionRoleId)) return null;
|
||||
SpmAdmissionRole.Params prmAdmissionRole = new SpmAdmissionRole.Params();
|
||||
prmAdmissionRole.IncludedIds.Add(admissionRoleId);
|
||||
prmAdmissionRole.StatusCat = SpmAdmissionRole.StatusCat.Any;
|
||||
return GetAdmissionRole(prmAdmissionRole);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create AdmissionRole.
|
||||
public override SpmAdmissionRole CreateAdmissionRole(SysId admissionId, Spm.EmployeeRole employeeRole, Spm.EmployeeRoleCategory employeeRoleCategory)
|
||||
{
|
||||
return new SpmAdmissionRole_Dbas(UserContext, admissionId, employeeRole, employeeRoleCategory, 0);
|
||||
}
|
||||
private SpmAdmissionRole_Dbas CreateAdmissionRole(SwmAdmissionRole_Db dbAdmissionRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmAdmissionRole_Dbas admissionRole = new SpmAdmissionRole_Dbas(UserContext, new SysId(dbAdmissionRole._AdmissionId), (Spm.EmployeeRole)dbAdmissionRole._Role, (Spm.EmployeeRoleCategory)dbAdmissionRole._Category, (ushort)dbAdmissionRole._Flags);
|
||||
PopulateFrom(dbAdmissionRole, admissionRole);
|
||||
return admissionRole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate AdmissionRole.
|
||||
public override bool IsValidAdmissionRoleData(SpmAdmissionRole.Data data, SpmAdmissionRole.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidAdmissionRoleData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert AdmissionRole.
|
||||
public override bool InsertAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionRole(admissionRole)) return false;
|
||||
if (SysId.IsValid(admissionRole.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmAdmissionRole_Db dbAdmissionRole = new SwmAdmissionRole_Db(DbInfo);
|
||||
PopulateTo(dbAdmissionRole, admissionRole, dbUpdateInfo);
|
||||
if (SwmAdmissionRole_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbAdmissionRole._AdmissionId = SysId.ToInt(db.GetNextId("AdmissionRole", dbUpdateInfo));
|
||||
}
|
||||
dbAdmissionRole.ExecuteInsertCommand(dbCommand);
|
||||
admissionRole.Id = new SysId(dbAdmissionRole._AdmissionId);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update AdmissionRole.
|
||||
public override bool UpdateAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidAdmissionRole(admissionRole)) return false;
|
||||
if (!SysId.IsValid(admissionRole.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionRole.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionRole_Db dbAdmissionRole = new SwmAdmissionRole_Db(DbInfo);
|
||||
dbAdmissionRole.PopulateFrom(dbCommand, aliasAdmissionRole, "Id=" + SysId.ToString(admissionRole.Id));
|
||||
//SpmUpdateLogItemMonitor_AdmissionRole updateLogMonitor = new SpmUpdateLogItemMonitor_AdmissionRole(UserContext, CreateAdmissionRole(dbAdmissionRole));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbAdmissionRole, admissionRole, dbUpdateInfo);
|
||||
dbAdmissionRole.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(admissionRole);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete AdmissionRole.
|
||||
public override bool AdmissionRoleCanBeDeleted(SpmAdmissionRole admissionRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.AdmissionRoleCanBeDeleted(admissionRole)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteAdmissionRole(SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!AdmissionRoleCanBeDeleted(admissionRole)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve AdmissionRole.
|
||||
dbConnection.Open();
|
||||
SwmAdmissionRole_Db dbAdmissionRole = new SwmAdmissionRole_Db(DbInfo);
|
||||
dbAdmissionRole.PopulateFrom(dbCommand, aliasAdmissionRole, "Id=" + admissionRole.Id.ToString());
|
||||
// Delete AdmissionRole.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole) + " WHERE Id=" + SysId.ToString(admissionRole.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmAdmissionRole_Db dbAdmissionRole, SpmAdmissionRole admissionRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbAdmissionRole._AdmissionId = admissionRole.AdmissionId.ToInt();
|
||||
dbAdmissionRole._Role = (short)admissionRole.EmployeeRole;
|
||||
dbAdmissionRole._Category = (short)admissionRole.EmployeeRoleCategory;
|
||||
dbAdmissionRole._Seq = (byte)admissionRole.Seq;
|
||||
dbAdmissionRole._EmployeeRoleId = admissionRole.EmployeeRoleId.ToInt();
|
||||
dbAdmissionRole._EmployeeCode = admissionRole.EmployeeCode;
|
||||
|
||||
dbAdmissionRole._Notes = admissionRole.Notes;
|
||||
dbAdmissionRole._Status = SacsSystem.GetStatusCode(admissionRole.Status);
|
||||
dbAdmissionRole._Flags = (short)admissionRole.Flags;
|
||||
if (!SysId.IsValid(admissionRole.Id))
|
||||
{
|
||||
dbAdmissionRole._CreateOn = DateTime.UtcNow;
|
||||
dbAdmissionRole._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionRole._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbAdmissionRole._UpdateOn = DateTime.UtcNow;
|
||||
dbAdmissionRole._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbAdmissionRole._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmAdmissionRole_Db dbAdmissionRole, SpmAdmissionRole admissionRole)
|
||||
{
|
||||
admissionRole.AdmissionId = new SysId(dbAdmissionRole._AdmissionId);
|
||||
admissionRole.EmployeeRole = (Spm.EmployeeRole)dbAdmissionRole._Role;
|
||||
admissionRole.EmployeeRoleCategory = (Spm.EmployeeRoleCategory)dbAdmissionRole._Category;
|
||||
admissionRole.Seq = (ushort)dbAdmissionRole._Seq;
|
||||
admissionRole.EmployeeRoleId = new SysId(dbAdmissionRole._EmployeeRoleId);
|
||||
admissionRole.EmployeeCode = dbAdmissionRole._EmployeeCode;
|
||||
|
||||
|
||||
|
||||
// Category - replacing zero/null values with 'Operating'.
|
||||
admissionRole.EmployeeRoleCategory = (Spm.EmployeeRoleCategory)dbAdmissionRole._Category;
|
||||
if (admissionRole.EmployeeRoleCategory < Spm.EmployeeRoleCategory.Operating)
|
||||
admissionRole.EmployeeRoleCategory = Spm.EmployeeRoleCategory.Operating;
|
||||
|
||||
|
||||
|
||||
admissionRole.Notes = dbAdmissionRole._Notes;
|
||||
admissionRole.Status = SacsSystem.GetStatusForCode(dbAdmissionRole._Status);
|
||||
admissionRole.SetCreateStamp(dbAdmissionRole._CreateOn, new SysId(dbAdmissionRole._CreateBy), dbAdmissionRole._CreateHost);
|
||||
admissionRole.SetUpdateStamp(dbAdmissionRole._UpdateOn, new SysId(dbAdmissionRole._UpdateBy), dbAdmissionRole._UpdateHost);
|
||||
admissionRole.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole column definitions.
|
||||
private static readonly String aliasAdmissionRole = "aAdmRle";
|
||||
private void SetAdmissionRoleColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmAdmissionRole)
|
||||
alias = aliasAdmissionRole;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmAdmissionRole column definition.
|
||||
public override ColumnDfn GetAdmissionRoleColumnDfn(SpmAdmissionRole.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmAdmissionRole.Column.Pos:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Id:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// AdmissionRole Properties.
|
||||
case SpmAdmissionRole.Column.AdmissionId:
|
||||
SetAdmissionRoleColDfn(columnDfn, "AdmissionId", 40, SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Role:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Role", 40, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Role, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Category:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Category", 40, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Category, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Seq:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Seq", 45, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Seq, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.EmployeeRoleId:
|
||||
SetAdmissionRoleColDfn(columnDfn, "EmployeeRole Id", 80, SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeRoleId);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.EmployeeCode:
|
||||
SetAdmissionRoleColDfn(columnDfn, "EmployeeCode", 90, SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeCode);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmAdmissionRole.Column.Notes:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Notes);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Status:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Status_Desc:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmAdmissionRole.Column.Status_Ind:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmAdmissionRole_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmAdmissionRole.Column.CreateOn_Date:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmAdmissionRole_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmAdmissionRole.Column.UpdateOn_Date:
|
||||
SetAdmissionRoleColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmAdmissionRole_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole query filter.
|
||||
public override List<string> GetAdmissionRoleQueryFilter(SpmAdmissionRole.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// AdmissionRole Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId, aliasAdmissionRole) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId, aliasAdmissionRole) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Admission Id.
|
||||
String colAdmisssionRole_AdmissionId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId, aliasAdmissionRole);
|
||||
if (SysId.IsValid(prm.AdmissionId))
|
||||
filters.Add(colAdmisssionRole_AdmissionId + "=" + prm.AdmissionId.ToString());
|
||||
|
||||
// Employee Role & Category.
|
||||
String colRole = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Role, aliasAdmissionRole);
|
||||
if (prm.EmployeeRole > 0)
|
||||
filters.Add(colRole + "=" + ((int)prm.EmployeeRole).ToString());
|
||||
String colCategory = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Category, aliasAdmissionRole);
|
||||
if (prm.EmployeeRoleCategory > 0)
|
||||
filters.Add(colCategory + "=" + ((int)prm.EmployeeRoleCategory).ToString());
|
||||
|
||||
// Seq.
|
||||
String colSeq = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Seq, aliasAdmissionRole);
|
||||
if (prm.Seq > 0)
|
||||
filters.Add(colSeq + "=" + ((int)prm.Seq).ToString());
|
||||
|
||||
// Employee Role Id.
|
||||
String colAdmisssionRole_EmployeeRoleId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeRoleId, aliasAdmissionRole);
|
||||
if (SysId.IsValid(prm.EmployeeRoleId))
|
||||
filters.Add(colAdmisssionRole_EmployeeRoleId + "=" + prm.EmployeeRoleId.ToString());
|
||||
|
||||
|
||||
// EmployeeCode.
|
||||
String colEmployeeCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeCode, aliasAdmissionRole);
|
||||
if (StringUtil.IsEmpty(prm.EmployeeCode))
|
||||
filters.Add(colEmployeeCode + "=" + DbQuery.FormatForCondition(prm.EmployeeCode));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole sort columns.
|
||||
public List<String> GetAdmissionRoleSortColumns(SpmAdmissionRole.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for AdmissionRole columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmAdmissionRole)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasAdmissionRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Type, aliasAdmissionRole) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole count.
|
||||
private long GetAdmissionRoleCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole) + " As " + aliasAdmissionRole, filter);
|
||||
}
|
||||
public override long GetAdmissionRoleCount(SpmAdmissionRole.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetAdmissionRoleCount(GetAdmissionRoleQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole list.
|
||||
public override List<SpmAdmissionRole> GetAdmissionRoleList(SpmAdmissionRole.Params prm)
|
||||
{
|
||||
List<SpmAdmissionRole> AdmissionRolees = new List<SpmAdmissionRole>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole), aliasAdmissionRole);
|
||||
qry.Columns.AddRange(SwmAdmissionRole_Db.Fields);
|
||||
qry.Filters.AddRange(GetAdmissionRoleQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmAdmissionRole_Db dbAdmissionRole = new SwmAdmissionRole_Db(DbInfo);
|
||||
dbAdmissionRole.PopulateFrom(dbDataReader);
|
||||
AdmissionRolees.Add(CreateAdmissionRole(dbAdmissionRole));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetAdmissionRoleList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return AdmissionRolees;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// AdmissionRole query execution.
|
||||
public override DbResultSet ExecuteAdmissionRoleQuery(List<ColumnDfn> columns, SpmAdmissionRole.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmissionRole), aliasAdmissionRole);
|
||||
|
||||
// AdmissionRole Properties - add columns as defined in query list.
|
||||
/*if (columns.HasId((int)SpmAdmissionRole.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_, aliasAdmissionRole));*/
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.AdmissionId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_AdmissionId, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.Role))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Role, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.Category))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Category, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.Seq))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Seq, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.EmployeeRoleId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeRoleId, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.EmployeeCode))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_EmployeeCode, aliasAdmissionRole));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Notes, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.Status) || columns.HasId((int)SpmAdmissionRole.Column.Status_Desc) || columns.HasId((int)SpmAdmissionRole.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_Status, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_CreateOn, aliasAdmissionRole));
|
||||
if (columns.HasId((int)SpmAdmissionRole.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmAdmissionRole_UpdateOn, aliasAdmissionRole));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetAdmissionRoleQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetAdmissionRoleSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetAdmissionRoleDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmAdmissionRole.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmAdmissionRole.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmAdmissionRole.Column.Status_Desc:
|
||||
case SpmAdmissionRole.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmAdmissionRole.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmAdmissionRole.Column.Status_Ind)
|
||||
value = new DataValue(SpmAdmissionRole.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Data;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -11,6 +14,8 @@ namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SacsDatabase db = null;
|
||||
private readonly SpmDbDataItem.DatabaseInfo dbInfo;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
@@ -21,6 +26,8 @@ namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected ISacsDatabase Database { get { return db; } }
|
||||
protected SpmDbDataItem.DatabaseInfo DbInfo { get { return dbInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
@@ -0,0 +1,567 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// D e p a r t m e n t
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department exists.
|
||||
public override bool DepartmentExistsById(SysId departmentId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(departmentId)) return false;
|
||||
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
||||
prmDepartment.IncludedIds.Add(departmentId);
|
||||
prmDepartment.StatusCat = SpmDepartment.StatusCat.Any;
|
||||
return GetDepartmentCount(prmDepartment) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Department.
|
||||
public override SpmDepartment GetDepartment(SpmDepartment.Params prm)
|
||||
{
|
||||
return GetDepartment(GetDepartmentQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmDepartment GetDepartment(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetDepartmentCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Departmentes found");
|
||||
return null;
|
||||
}
|
||||
SpmDepartment department = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmDepartment_Db dbDepartment = new SwmDepartment_Db(DbInfo);
|
||||
dbDepartment.PopulateFrom(dbCommand, aliasDepartment, filter);
|
||||
department = CreateDepartment(dbDepartment);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetDepartment\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return department;
|
||||
}
|
||||
public override SpmDepartment GetDepartmentById(SysId departmentId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(departmentId)) return null;
|
||||
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
||||
prmDepartment.IncludedIds.Add(departmentId);
|
||||
prmDepartment.StatusCat = SpmDepartment.StatusCat.Any;
|
||||
return GetDepartment(prmDepartment);
|
||||
}
|
||||
public override SpmDepartment GetDepartmentByName(String name)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!StringUtil.IsEmpty(name)) return null;
|
||||
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
||||
prmDepartment.Name = name;
|
||||
prmDepartment.StatusCat = SpmDepartment.StatusCat.Any;
|
||||
return GetDepartment(prmDepartment);
|
||||
}
|
||||
public override SpmDepartment GetDepartmentByFacilityId(SysId facilityId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityId)) return null;
|
||||
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
||||
prmDepartment.IncludedIds.Add(facilityId);
|
||||
prmDepartment.StatusCat = SpmDepartment.StatusCat.Any;
|
||||
return GetDepartment(prmDepartment);
|
||||
}
|
||||
public override SpmDepartment GetDepartmentByFacilityTemplateId(SysId facilityTemplateId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityTemplateId)) return null;
|
||||
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
||||
prmDepartment.IncludedIds.Add(facilityTemplateId);
|
||||
prmDepartment.StatusCat = SpmDepartment.StatusCat.Any;
|
||||
return GetDepartment(prmDepartment);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Department.
|
||||
public override SpmDepartment CreateDepartment()
|
||||
{
|
||||
return new SpmDepartment_Dbas(UserContext, null, 0);
|
||||
}
|
||||
private SpmDepartment_Dbas CreateDepartment(SwmDepartment_Db dbDepartment)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmDepartment_Dbas department = new SpmDepartment_Dbas(UserContext, new SysId(dbDepartment._Id), (ushort)dbDepartment._Flags);
|
||||
PopulateFrom(dbDepartment, department);
|
||||
return department;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Department.
|
||||
public override bool IsValidDepartmentData(SpmDepartment.Data data, SpmDepartment.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidDepartmentData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Department.
|
||||
public override bool InsertDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidDepartment(department)) return false;
|
||||
if (SysId.IsValid(department.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmDepartment_Db dbDepartment = new SwmDepartment_Db(DbInfo);
|
||||
PopulateTo(dbDepartment, department, dbUpdateInfo);
|
||||
if (SwmDepartment_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbDepartment._Id = SysId.ToInt(db.GetNextId("Department", dbUpdateInfo));
|
||||
}
|
||||
dbDepartment.ExecuteInsertCommand(dbCommand);
|
||||
department.Id = new SysId(dbDepartment._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Department.
|
||||
public override bool UpdateDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidDepartment(department)) return false;
|
||||
if (!SysId.IsValid(department.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Department.
|
||||
dbConnection.Open();
|
||||
SwmDepartment_Db dbDepartment = new SwmDepartment_Db(DbInfo);
|
||||
dbDepartment.PopulateFrom(dbCommand, aliasDepartment, "Id=" + SysId.ToString(department.Id));
|
||||
//SpmUpdateLogItemMonitor_Department updateLogMonitor = new SpmUpdateLogItemMonitor_Department(UserContext, CreateDepartment(dbDepartment));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbDepartment, department, dbUpdateInfo);
|
||||
dbDepartment.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(department);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Department.
|
||||
public override bool DepartmentCanBeDeleted(SpmDepartment department)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.DepartmentCanBeDeleted(department)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteDepartment(SpmDepartment department, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!DepartmentCanBeDeleted(department)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Department.
|
||||
dbConnection.Open();
|
||||
SwmDepartment_Db dbDepartment = new SwmDepartment_Db(DbInfo);
|
||||
dbDepartment.PopulateFrom(dbCommand, aliasDepartment, "Id=" + department.Id.ToString());
|
||||
// Delete Department.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmDepartment) + " WHERE Id=" + SysId.ToString(department.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmDepartment_Db dbDepartment, SpmDepartment department, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbDepartment._Id = department.Id.ToInt();
|
||||
dbDepartment._Name = department.Name;
|
||||
dbDepartment._FacilityTypes = (int)department.GetFacilityTypes();
|
||||
dbDepartment._AllowAnyFacility = (int)department.GetAllowAnyFacilities();
|
||||
dbDepartment._ApplicFrom = department.ApplicationFrom;
|
||||
dbDepartment._ApplicTo = department.ApplicationTo;
|
||||
|
||||
dbDepartment._Notes = department.Notes;
|
||||
dbDepartment._Status = SacsSystem.GetStatusCode(department.Status);
|
||||
dbDepartment._Flags = (short)department.Flags;
|
||||
if (!SysId.IsValid(department.Id))
|
||||
{
|
||||
dbDepartment._CreateOn = DateTime.UtcNow;
|
||||
dbDepartment._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbDepartment._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbDepartment._UpdateOn = DateTime.UtcNow;
|
||||
dbDepartment._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbDepartment._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmDepartment_Db dbDepartment, SpmDepartment department)
|
||||
{
|
||||
department.Id = new SysId(dbDepartment._Id);
|
||||
department.Name = dbDepartment._Name;
|
||||
department.ApplicationFrom = dbDepartment._ApplicFrom;
|
||||
department.ApplicationTo = dbDepartment._ApplicTo;
|
||||
|
||||
department.Notes = dbDepartment._Notes;
|
||||
department.Status = SacsSystem.GetStatusForCode(dbDepartment._Status);
|
||||
department.SetCreateStamp(dbDepartment._CreateOn, new SysId(dbDepartment._CreateBy), dbDepartment._CreateHost);
|
||||
department.SetUpdateStamp(dbDepartment._UpdateOn, new SysId(dbDepartment._UpdateBy), dbDepartment._UpdateHost);
|
||||
department.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department column definitions.
|
||||
private static readonly String aliasDepartment = "aDept";
|
||||
private void SetDepartmentColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmDepartment)
|
||||
alias = aliasDepartment;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmDepartment column definition.
|
||||
public override ColumnDfn GetDepartmentColumnDfn(SpmDepartment.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmDepartment.Column.Pos:
|
||||
SetDepartmentColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmDepartment.Column.Id:
|
||||
SetDepartmentColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmDepartment_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Department Properties.
|
||||
case SpmDepartment.Column.Name:
|
||||
SetDepartmentColDfn(columnDfn, "Name", 60, SpmDbDfn.ColumnIdx.SwmDepartment_Name, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmDepartment.Column.ApplicatonFrom:
|
||||
SetDepartmentColDfn(columnDfn, "ApplicationFrom", 70, SpmDbDfn.ColumnIdx.SwmDepartment_ApplicFrom, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmDepartment.Column.ApplicationTo:
|
||||
SetDepartmentColDfn(columnDfn, "ApplicationTo", 70, SpmDbDfn.ColumnIdx.SwmDepartment_ApplicTo, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmDepartment.Column.Notes:
|
||||
SetDepartmentColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmDepartment_Notes);
|
||||
break;
|
||||
case SpmDepartment.Column.Status:
|
||||
SetDepartmentColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmDepartment_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmDepartment.Column.Status_Desc:
|
||||
SetDepartmentColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmDepartment_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmDepartment.Column.Status_Ind:
|
||||
SetDepartmentColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmDepartment_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmDepartment.Column.CreateOn_Date:
|
||||
SetDepartmentColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmDepartment_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmDepartment.Column.UpdateOn_Date:
|
||||
SetDepartmentColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmDepartment_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department query filter.
|
||||
public override List<string> GetDepartmentQueryFilter(SpmDepartment.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Department Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Id, aliasDepartment) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Id, aliasDepartment) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Partial name.
|
||||
String namePartial = DbQuery.FormatForCondition(prm.NamePartial);
|
||||
String colName = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Name, aliasDepartment);
|
||||
if (!StringUtil.IsEmpty(namePartial))
|
||||
filters.Add(DbQuery.FormatFn_Left(colName, namePartial.Length) + "='" + namePartial + "'");
|
||||
|
||||
// Applicable dates.
|
||||
DateTime nullDate = new DateTime(1970, 1, 1);
|
||||
String colApplicFrom = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_ApplicFrom, aliasDepartment);
|
||||
String colApplicTo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_ApplicTo, aliasDepartment);
|
||||
if (DateUtil.IsValid(prm.Application))
|
||||
{
|
||||
// Looking for roles that are applicable on the specified date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.Application, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.Application) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom) || DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Looking for roles that overlap with the specified date range.
|
||||
if (DateUtil.IsValid(prm.ApplicationFrom) && DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Both from and to dates specified.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom))
|
||||
{
|
||||
// Only 'from' date specified - Matches with ApplicTo not specified or after 'from' date.
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Only 'to' date specified - Matches with ApplicFrom not specified or before 'to' date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department sort columns.
|
||||
public List<String> GetDepartmentSortColumns(SpmDepartment.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Department columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmDepartment)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasDepartment);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Type, aliasDepartment) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department count.
|
||||
private long GetDepartmentCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmDepartment) + " As " + aliasDepartment, filter);
|
||||
}
|
||||
public override long GetDepartmentCount(SpmDepartment.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetDepartmentCount(GetDepartmentQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department list.
|
||||
public override List<SpmDepartment> GetDepartmentList(SpmDepartment.Params prm)
|
||||
{
|
||||
List<SpmDepartment> Departmentes = new List<SpmDepartment>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmDepartment), aliasDepartment);
|
||||
qry.Columns.AddRange(SwmDepartment_Db.Fields);
|
||||
qry.Filters.AddRange(GetDepartmentQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmDepartment_Db dbDepartment = new SwmDepartment_Db(DbInfo);
|
||||
dbDepartment.PopulateFrom(dbDataReader);
|
||||
Departmentes.Add(CreateDepartment(dbDepartment));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetDepartmentList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Departmentes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Department query execution.
|
||||
public override DbResultSet ExecuteDepartmentQuery(List<ColumnDfn> columns, SpmDepartment.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmDepartment), aliasDepartment);
|
||||
|
||||
// Department Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmDepartment.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Id, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.Name))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Name, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.ApplicatonFrom))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_ApplicFrom, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.ApplicationTo))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_ApplicTo, aliasDepartment));
|
||||
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmDepartment.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Notes, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.Status) || columns.HasId((int)SpmDepartment.Column.Status_Desc) || columns.HasId((int)SpmDepartment.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_Status, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_CreateOn, aliasDepartment));
|
||||
if (columns.HasId((int)SpmDepartment.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmDepartment_UpdateOn, aliasDepartment));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetDepartmentQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetDepartmentSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetDepartmentDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmDepartment.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmDepartment.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmDepartment.Column.Status_Desc:
|
||||
case SpmDepartment.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmDepartment.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmDepartment.Column.Status_Ind)
|
||||
value = new DataValue(SpmDepartment.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,564 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// E m p l o y e e R o l e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole exists.
|
||||
public override bool EmployeeRoleExistsById(SysId employeeRoleId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(employeeRoleId)) return false;
|
||||
SpmEmployeeRole.Params prmEmployeeRole = new SpmEmployeeRole.Params();
|
||||
prmEmployeeRole.IncludedIds.Add(employeeRoleId);
|
||||
prmEmployeeRole.StatusCat = SpmEmployeeRole.StatusCat.Any;
|
||||
return GetEmployeeRoleCount(prmEmployeeRole) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get EmployeeRole.
|
||||
public override SpmEmployeeRole GetEmployeeRole(SpmEmployeeRole.Params prm)
|
||||
{
|
||||
return GetEmployeeRole(GetEmployeeRoleQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmEmployeeRole GetEmployeeRole(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetEmployeeRoleCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple EmployeeRolees found");
|
||||
return null;
|
||||
}
|
||||
SpmEmployeeRole employeeRole = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmEmployeeRole_Db dbEmployeeRole = new SwmEmployeeRole_Db(DbInfo);
|
||||
dbEmployeeRole.PopulateFrom(dbCommand, aliasEmployeeRole, filter);
|
||||
employeeRole = CreateEmployeeRole(dbEmployeeRole);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetEmployeeRole\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return employeeRole;
|
||||
}
|
||||
public override SpmEmployeeRole GetEmployeeRoleById(SysId employeeRoleId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(employeeRoleId)) return null;
|
||||
SpmEmployeeRole.Params prmEmployeeRole = new SpmEmployeeRole.Params();
|
||||
prmEmployeeRole.IncludedIds.Add(employeeRoleId);
|
||||
prmEmployeeRole.StatusCat = SpmEmployeeRole.StatusCat.Any;
|
||||
return GetEmployeeRole(prmEmployeeRole);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create EmployeeRole.
|
||||
public override SpmEmployeeRole CreateEmployeeRole(SysId deparmentId, SysId employeeId, Spm.EmployeeRole employeeRole)
|
||||
{
|
||||
return new SpmEmployeeRole_Dbas(UserContext, deparmentId, employeeId, employeeRole, 0);
|
||||
}
|
||||
private SpmEmployeeRole_Dbas CreateEmployeeRole(SwmEmployeeRole_Db dbEmployeeRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmEmployeeRole_Dbas employeeRole = new SpmEmployeeRole_Dbas(UserContext, new SysId(dbEmployeeRole._DepartmentId), new SysId(dbEmployeeRole._EmployeeId), (Spm.EmployeeRole)dbEmployeeRole._Role, (ushort)dbEmployeeRole._Flags);
|
||||
PopulateFrom(dbEmployeeRole, employeeRole);
|
||||
return employeeRole;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate EmployeeRole.
|
||||
public override bool IsValidEmployeeRoleData(SpmEmployeeRole.Data data, SpmEmployeeRole.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidEmployeeRoleData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert EmployeeRole.
|
||||
public override bool InsertEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidEmployeeRole(employeeRole)) return false;
|
||||
if (SysId.IsValid(employeeRole.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmEmployeeRole_Db dbEmployeeRole = new SwmEmployeeRole_Db(DbInfo);
|
||||
PopulateTo(dbEmployeeRole, employeeRole, dbUpdateInfo);
|
||||
if (SwmEmployeeRole_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbEmployeeRole._Id = SysId.ToInt(db.GetNextId("EmployeeRole", dbUpdateInfo));
|
||||
}
|
||||
dbEmployeeRole.ExecuteInsertCommand(dbCommand);
|
||||
employeeRole.Id = new SysId(dbEmployeeRole._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update EmployeeRole.
|
||||
public override bool UpdateEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidEmployeeRole(employeeRole)) return false;
|
||||
if (!SysId.IsValid(employeeRole.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve EmployeeRole.
|
||||
dbConnection.Open();
|
||||
SwmEmployeeRole_Db dbEmployeeRole = new SwmEmployeeRole_Db(DbInfo);
|
||||
dbEmployeeRole.PopulateFrom(dbCommand, aliasEmployeeRole, "Id=" + SysId.ToString(employeeRole.Id));
|
||||
//SpmUpdateLogItemMonitor_EmployeeRole updateLogMonitor = new SpmUpdateLogItemMonitor_EmployeeRole(UserContext, CreateEmployeeRole(dbEmployeeRole));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbEmployeeRole, employeeRole, dbUpdateInfo);
|
||||
dbEmployeeRole.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(employeeRole);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete EmployeeRole.
|
||||
public override bool EmployeeRoleCanBeDeleted(SpmEmployeeRole employeeRole)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.EmployeeRoleCanBeDeleted(employeeRole)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteEmployeeRole(SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!EmployeeRoleCanBeDeleted(employeeRole)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve EmployeeRole.
|
||||
dbConnection.Open();
|
||||
SwmEmployeeRole_Db dbEmployeeRole = new SwmEmployeeRole_Db(DbInfo);
|
||||
dbEmployeeRole.PopulateFrom(dbCommand, aliasEmployeeRole, "Id=" + employeeRole.Id.ToString());
|
||||
// Delete EmployeeRole.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployeeRole) + " WHERE Id=" + SysId.ToString(employeeRole.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmEmployeeRole_Db dbEmployeeRole, SpmEmployeeRole employeeRole, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbEmployeeRole._Id = employeeRole.Id.ToInt();
|
||||
dbEmployeeRole._ApplicFrom = employeeRole.ApplicationFrom;
|
||||
dbEmployeeRole._ApplicTo = employeeRole.ApplicationTo;
|
||||
|
||||
dbEmployeeRole._Notes = employeeRole.Notes;
|
||||
dbEmployeeRole._Status = SacsSystem.GetStatusCode(employeeRole.Status);
|
||||
dbEmployeeRole._Flags = (short)employeeRole.Flags;
|
||||
if (!SysId.IsValid(employeeRole.Id))
|
||||
{
|
||||
dbEmployeeRole._CreateOn = DateTime.UtcNow;
|
||||
dbEmployeeRole._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbEmployeeRole._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbEmployeeRole._UpdateOn = DateTime.UtcNow;
|
||||
dbEmployeeRole._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbEmployeeRole._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmEmployeeRole_Db dbEmployeeRole, SpmEmployeeRole employeeRole)
|
||||
{
|
||||
employeeRole.Id = new SysId(dbEmployeeRole._Id);
|
||||
employeeRole.ApplicationFrom = dbEmployeeRole._ApplicFrom;
|
||||
employeeRole.ApplicationTo = dbEmployeeRole._ApplicTo;
|
||||
|
||||
employeeRole.Notes = dbEmployeeRole._Notes;
|
||||
employeeRole.Status = SacsSystem.GetStatusForCode(dbEmployeeRole._Status);
|
||||
employeeRole.SetCreateStamp(dbEmployeeRole._CreateOn, new SysId(dbEmployeeRole._CreateBy), dbEmployeeRole._CreateHost);
|
||||
employeeRole.SetUpdateStamp(dbEmployeeRole._UpdateOn, new SysId(dbEmployeeRole._UpdateBy), dbEmployeeRole._UpdateHost);
|
||||
employeeRole.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole column definitions.
|
||||
private static readonly String aliasEmployeeRole = "aEmpRole";
|
||||
private void SetEmployeeRoleColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmEmployeeRole)
|
||||
alias = aliasEmployeeRole;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmEmployeeRole column definition.
|
||||
public override ColumnDfn GetEmployeeRoleColumnDfn(SpmEmployeeRole.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmEmployeeRole.Column.Pos:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmEmployeeRole.Column.Id:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// EmployeeRole Properties.
|
||||
case SpmEmployeeRole.Column.DepartmentId:
|
||||
SetEmployeeRoleColDfn(columnDfn, "DepartmentId", 45, SpmDbDfn.ColumnIdx.SwmEmployeeRole_DepartmentId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.EmployeeId:
|
||||
SetEmployeeRoleColDfn(columnDfn, "EmployeeId", 45, SpmDbDfn.ColumnIdx.SwmEmployeeRole_EmployeeId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.Role:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Role", 40, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Role, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.ApplicationFrom:
|
||||
SetEmployeeRoleColDfn(columnDfn, "ApplicationFrom", 70, SpmDbDfn.ColumnIdx.SwmEmployeeRole_ApplicFrom, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmEmployeeRole.Column.ApplicationTo:
|
||||
SetEmployeeRoleColDfn(columnDfn, "ApplicationTo", 70, SpmDbDfn.ColumnIdx.SwmEmployeeRole_ApplicTo, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmEmployeeRole.Column.Notes:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Notes);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.Status:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.Status_Desc:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmEmployeeRole.Column.Status_Ind:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployeeRole_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmEmployeeRole.Column.CreateOn_Date:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmEmployeeRole_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmEmployeeRole.Column.UpdateOn_Date:
|
||||
SetEmployeeRoleColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmEmployeeRole_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole query filter.
|
||||
public override List<string> GetEmployeeRoleQueryFilter(SpmEmployeeRole.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// EmployeeRole Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Id, aliasEmployeeRole) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Id, aliasEmployeeRole) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Employee:
|
||||
if (SysId.IsValid(prm.EmployeeId))
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_EmployeeId, aliasEmployeeRole) + "=" + prm.EmployeeId.ToString());
|
||||
// Role:
|
||||
if ((int)prm.EmployeeRole > 0)
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Role, aliasEmployeeRole) + "=" + ((int)prm.EmployeeRole).ToString());
|
||||
|
||||
// Employee name.
|
||||
String initials = DbQuery.FormatForCondition(prm.Initials);
|
||||
String surname = DbQuery.FormatForCondition(prm.Surname);
|
||||
if (!StringUtil.IsEmpty(initials) || !StringUtil.IsEmpty(surname))
|
||||
{
|
||||
// Common database definitions.
|
||||
String aliasEmployee = "aEmp";
|
||||
String colEmployeeId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Id, aliasEmployee);
|
||||
String colInitials = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Initials, aliasEmployee);
|
||||
String colSurname = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Surname, aliasEmployee);
|
||||
|
||||
// Build sub query on employee.
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployee), aliasEmployee);
|
||||
qry.Columns.Add(colEmployeeId);
|
||||
|
||||
// Employee must match role.
|
||||
qry.Filters.Add(colEmployeeId + "=" + SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_EmployeeId, aliasEmployeeRole));
|
||||
if (!initials.IsEmpty())
|
||||
qry.Filters.Add(DbQuery.FormatFn_Left(colInitials, prm.Initials.Length) + "='" + initials + "'");
|
||||
if (!surname.IsEmpty())
|
||||
qry.Filters.Add(DbQuery.FormatFn_Left(colSurname, prm.Surname.Length) + "='" + surname + "'");
|
||||
filters.Add("EXISTS(" + qry.BuildQuery() + ")");
|
||||
}
|
||||
|
||||
// Applicable dates.
|
||||
DateTime nullDate = new DateTime(1970, 1, 1);
|
||||
String colApplicFrom = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_ApplicFrom, aliasEmployeeRole);
|
||||
String colApplicTo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_ApplicTo, aliasEmployeeRole);
|
||||
if (DateUtil.IsValid(prm.Application))
|
||||
{
|
||||
// Looking for roles that are applicable on the specified date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.Application, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.Application) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom) || DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Looking for roles that overlap with the specified date range.
|
||||
if (DateUtil.IsValid(prm.ApplicationFrom) && DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Both from and to dates specified.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom))
|
||||
{
|
||||
// Only 'from' date specified - Matches with ApplicTo not specified or after 'from' date.
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Only 'to' date specified - Matches with ApplicFrom not specified or before 'to' date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole sort columns.
|
||||
public List<String> GetEmployeeRoleSortColumns(SpmEmployeeRole.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for EmployeeRole columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmEmployeeRole)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasEmployeeRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Type, aliasEmployeeRole) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole count.
|
||||
private long GetEmployeeRoleCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployeeRole) + " As " + aliasEmployeeRole, filter);
|
||||
}
|
||||
public override long GetEmployeeRoleCount(SpmEmployeeRole.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetEmployeeRoleCount(GetEmployeeRoleQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole list.
|
||||
public override List<SpmEmployeeRole> GetEmployeeRoleList(SpmEmployeeRole.Params prm)
|
||||
{
|
||||
List<SpmEmployeeRole> EmployeeRolees = new List<SpmEmployeeRole>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployeeRole), aliasEmployeeRole);
|
||||
qry.Columns.AddRange(SwmEmployeeRole_Db.Fields);
|
||||
qry.Filters.AddRange(GetEmployeeRoleQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmEmployeeRole_Db dbEmployeeRole = new SwmEmployeeRole_Db(DbInfo);
|
||||
dbEmployeeRole.PopulateFrom(dbDataReader);
|
||||
EmployeeRolees.Add(CreateEmployeeRole(dbEmployeeRole));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetEmployeeRoleList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return EmployeeRolees;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// EmployeeRole query execution.
|
||||
public override DbResultSet ExecuteEmployeeRoleQuery(List<ColumnDfn> columns, SpmEmployeeRole.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployeeRole), aliasEmployeeRole);
|
||||
|
||||
// EmployeeRole Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmEmployeeRole.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Id, aliasEmployeeRole));
|
||||
if (columns.HasId((int)SpmFacility.Column.ApplicFrom))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_ApplicFrom, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.ApplicTo))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_ApplicTo, aliasFacility));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmEmployeeRole.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Notes, aliasEmployeeRole));
|
||||
if (columns.HasId((int)SpmEmployeeRole.Column.Status) || columns.HasId((int)SpmEmployeeRole.Column.Status_Desc) || columns.HasId((int)SpmEmployeeRole.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_Status, aliasEmployeeRole));
|
||||
if (columns.HasId((int)SpmEmployeeRole.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_CreateOn, aliasEmployeeRole));
|
||||
if (columns.HasId((int)SpmEmployeeRole.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployeeRole_UpdateOn, aliasEmployeeRole));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetEmployeeRoleQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetEmployeeRoleSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetEmployeeRoleDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmEmployeeRole.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmEmployeeRole.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmEmployeeRole.Column.Status_Desc:
|
||||
case SpmEmployeeRole.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmEmployeeRole.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmEmployeeRole.Column.Status_Ind)
|
||||
value = new DataValue(SpmEmployeeRole.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// F a c i l i t y
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility exists.
|
||||
public override bool FacilityExistsById(SysId facilityId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityId)) return false;
|
||||
SpmFacility.Params prmFacility = new SpmFacility.Params();
|
||||
prmFacility.IncludedIds.Add(facilityId);
|
||||
prmFacility.StatusCat = SpmFacility.StatusCat.Any;
|
||||
return GetFacilityCount(prmFacility) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Facility.
|
||||
public override SpmFacility GetFacility(SpmFacility.Params prm)
|
||||
{
|
||||
return GetFacility(GetFacilityQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmFacility GetFacility(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetFacilityCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Facilityes found");
|
||||
return null;
|
||||
}
|
||||
SpmFacility facility = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmFacility_Db dbFacility = new SwmFacility_Db(DbInfo);
|
||||
dbFacility.PopulateFrom(dbCommand, aliasFacility, filter);
|
||||
facility = CreateFacility(dbFacility);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetFacility\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return facility;
|
||||
}
|
||||
public override SpmFacility GetFacilityById(SysId facilityId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityId)) return null;
|
||||
SpmFacility.Params prmFacility = new SpmFacility.Params();
|
||||
prmFacility.IncludedIds.Add(facilityId);
|
||||
prmFacility.StatusCat = SpmFacility.StatusCat.Any;
|
||||
return GetFacility(prmFacility);
|
||||
}
|
||||
public override SpmFacility GetFacilityByName(String name)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!StringUtil.IsEmpty(name)) return null;
|
||||
SpmFacility.Params prmFacility = new SpmFacility.Params();
|
||||
prmFacility.NamePartial = name;
|
||||
prmFacility.StatusCat = SpmFacility.StatusCat.Any;
|
||||
return GetFacility(prmFacility);
|
||||
}
|
||||
public override SpmFacility GetFacilityByTemplateId(SysId facilityTemplateId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityTemplateId)) return null;
|
||||
SpmFacility.Params prmFacility = new SpmFacility.Params();
|
||||
prmFacility.IncludedIds.Add(facilityTemplateId);
|
||||
prmFacility.StatusCat = SpmFacility.StatusCat.Any;
|
||||
return GetFacility(prmFacility);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Facility.
|
||||
public override SpmFacility CreateFacility(SysId facilityId, SysId departmentId, Spm.FacilityType facilityType)
|
||||
{
|
||||
return new SpmFacility_Dbas(UserContext, facilityId, departmentId, facilityType, 0);
|
||||
}
|
||||
private SpmFacility_Dbas CreateFacility(SwmFacility_Db dbFacility)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmFacility_Dbas facility = new SpmFacility_Dbas(UserContext, new SysId(dbFacility._Id), new SysId(dbFacility._DepartmentId), (Spm.FacilityType)dbFacility._Type, (ushort)dbFacility._Flags);
|
||||
PopulateFrom(dbFacility, facility);
|
||||
return facility;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Facility.
|
||||
public override bool IsValidFacilityData(SpmFacility.Data data, SpmFacility.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidFacilityData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Facility.
|
||||
public override bool InsertFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidFacility(facility)) return false;
|
||||
if (SysId.IsValid(facility.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmFacility_Db dbFacility = new SwmFacility_Db(DbInfo);
|
||||
PopulateTo(dbFacility, facility, dbUpdateInfo);
|
||||
if (SwmFacility_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbFacility._Id = SysId.ToInt(db.GetNextId("Facility", dbUpdateInfo));
|
||||
}
|
||||
dbFacility.ExecuteInsertCommand(dbCommand);
|
||||
facility.Id = new SysId(dbFacility._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Facility.
|
||||
public override bool UpdateFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidFacility(facility)) return false;
|
||||
if (!SysId.IsValid(facility.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Facility.
|
||||
dbConnection.Open();
|
||||
SwmFacility_Db dbFacility = new SwmFacility_Db(DbInfo);
|
||||
dbFacility.PopulateFrom(dbCommand, aliasFacility, "Id=" + SysId.ToString(facility.Id));
|
||||
//SpmUpdateLogItemMonitor_Facility updateLogMonitor = new SpmUpdateLogItemMonitor_Facility(UserContext, CreateFacility(dbFacility));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbFacility, facility, dbUpdateInfo);
|
||||
dbFacility.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(facility);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Facility.
|
||||
public override bool FacilityCanBeDeleted(SpmFacility facility)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.FacilityCanBeDeleted(facility)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteFacility(SpmFacility facility, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!FacilityCanBeDeleted(facility)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Facility.
|
||||
dbConnection.Open();
|
||||
SwmFacility_Db dbFacility = new SwmFacility_Db(DbInfo);
|
||||
dbFacility.PopulateFrom(dbCommand, aliasFacility, "Id=" + facility.Id.ToString());
|
||||
// Delete Facility.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility) + " WHERE Id=" + SysId.ToString(facility.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmFacility_Db dbFacility, SpmFacility facility, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbFacility._Id = facility.Id.ToInt();
|
||||
dbFacility._Name = facility.Name;
|
||||
dbFacility._SortCode = facility.SortCode;
|
||||
dbFacility._Description = facility.Desc;
|
||||
dbFacility._TemplateMapType = (short)facility.TemplateMapType;
|
||||
dbFacility._ScheduleFreezeType = (short)facility.ScheduleFreezeType;
|
||||
dbFacility._ScheduleFreezeData = facility.ScheduleFreezeData;
|
||||
dbFacility._ApplicFrom = facility.ApplicationFrom;
|
||||
dbFacility._ApplicTo = facility.ApplicationTo;
|
||||
|
||||
dbFacility._Notes = facility.Notes;
|
||||
dbFacility._Status = SacsSystem.GetStatusCode(facility.Status);
|
||||
dbFacility._Flags = (short)facility.Flags;
|
||||
if (!SysId.IsValid(facility.Id))
|
||||
{
|
||||
dbFacility._CreateOn = DateTime.UtcNow;
|
||||
dbFacility._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbFacility._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbFacility._UpdateOn = DateTime.UtcNow;
|
||||
dbFacility._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbFacility._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmFacility_Db dbFacility, SpmFacility facility)
|
||||
{
|
||||
facility.Id = new SysId(dbFacility._Id);
|
||||
facility.Name = dbFacility._Name;
|
||||
facility.SortCode = dbFacility._SortCode;
|
||||
facility.Desc = dbFacility._Description;
|
||||
facility.TemplateMapType = (Spm.FacilityTemplateMapType)dbFacility._TemplateMapType;
|
||||
facility.ScheduleFreezeType = (Spm.ScheduleFreezeType)dbFacility._ScheduleFreezeType;
|
||||
facility.ScheduleFreezeData = dbFacility._ScheduleFreezeData;
|
||||
facility.ApplicationFrom = dbFacility._ApplicFrom;
|
||||
facility.ApplicationTo = dbFacility._ApplicTo;
|
||||
|
||||
facility.Notes = dbFacility._Notes;
|
||||
facility.Status = SacsSystem.GetStatusForCode(dbFacility._Status);
|
||||
facility.SetCreateStamp(dbFacility._CreateOn, new SysId(dbFacility._CreateBy), dbFacility._CreateHost);
|
||||
facility.SetUpdateStamp(dbFacility._UpdateOn, new SysId(dbFacility._UpdateBy), dbFacility._UpdateHost);
|
||||
facility.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility column definitions.
|
||||
private static readonly String aliasFacility = "aFac";
|
||||
private void SetFacilityColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmFacility)
|
||||
alias = aliasFacility;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmFacility column definition.
|
||||
public override ColumnDfn GetFacilityColumnDfn(SpmFacility.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmFacility.Column.Pos:
|
||||
SetFacilityColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmFacility.Column.Id:
|
||||
SetFacilityColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmFacility_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Facility Properties.
|
||||
case SpmFacility.Column.DepartmentId:
|
||||
SetFacilityColDfn(columnDfn, "DepartmentId", 45, SpmDbDfn.ColumnIdx.SwmFacility_DepartmentId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmFacility.Column.Type:
|
||||
SetFacilityColDfn(columnDfn, "Type", 40, SpmDbDfn.ColumnIdx.SwmFacility_Type, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.Type_Desc:
|
||||
SetFacilityColDfn(columnDfn, "Type", 90, SpmDbDfn.ColumnIdx.SwmFacility_Type, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.Name:
|
||||
SetFacilityColDfn(columnDfn, "Name", 60, SpmDbDfn.ColumnIdx.SwmFacility_Name, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmFacility.Column.SortCode:
|
||||
SetFacilityColDfn(columnDfn, "SortCode", 60, SpmDbDfn.ColumnIdx.SwmFacility_SortCode, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmFacility.Column.Desc:
|
||||
SetFacilityColDfn(columnDfn, "Desc", 60, SpmDbDfn.ColumnIdx.SwmFacility_Description, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmFacility.Column.TemplateMapType:
|
||||
SetFacilityColDfn(columnDfn, "TemplateMapType", 40, SpmDbDfn.ColumnIdx.SwmFacility_Type, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.ScheduleFreezeType:
|
||||
SetFacilityColDfn(columnDfn, "ScheduleFreezeType", 40, SpmDbDfn.ColumnIdx.SwmFacility_ScheduleFreezeType, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.FreezeTime:
|
||||
SetFacilityColDfn(columnDfn, "ApplicationTo", 70, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmFacility.Column.FreezeData:
|
||||
SetFacilityColDfn(columnDfn, "ScheduleFreezeData", 60, SpmDbDfn.ColumnIdx.SwmFacility_ScheduleFreezeData, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmFacility.Column.ApplicFrom:
|
||||
SetFacilityColDfn(columnDfn, "ApplicationFrom", 70, SpmDbDfn.ColumnIdx.SwmFacility_ApplicFrom, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
case SpmFacility.Column.ApplicTo:
|
||||
SetFacilityColDfn(columnDfn, "ApplicationTo", 70, SpmDbDfn.ColumnIdx.SwmFacility_ApplicTo, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmFacility.Column.Notes:
|
||||
SetFacilityColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmFacility_Notes);
|
||||
break;
|
||||
case SpmFacility.Column.Status:
|
||||
SetFacilityColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacility_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.Status_Desc:
|
||||
SetFacilityColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacility_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacility.Column.Status_Ind:
|
||||
SetFacilityColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacility_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmFacility.Column.CreateOn_Date:
|
||||
SetFacilityColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmFacility_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmFacility.Column.UpdateOn_Date:
|
||||
SetFacilityColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmFacility_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility query filter.
|
||||
public override List<string> GetFacilityQueryFilter(SpmFacility.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Facility Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Id, aliasFacility) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Id, aliasFacility) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Applicable dates.
|
||||
DateTime nullDate = new DateTime(1970, 1, 1);
|
||||
String colApplicFrom = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_ApplicFrom, aliasFacility);
|
||||
String colApplicTo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_ApplicTo, aliasFacility);
|
||||
if (DateUtil.IsValid(prm.Application))
|
||||
{
|
||||
// Looking for roles that are applicable on the specified date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.Application, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.Application) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom) || DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Looking for roles that overlap with the specified date range.
|
||||
if (DateUtil.IsValid(prm.ApplicationFrom) && DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Both from and to dates specified.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom))
|
||||
{
|
||||
// Only 'from' date specified - Matches with ApplicTo not specified or after 'from' date.
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Only 'to' date specified - Matches with ApplicFrom not specified or before 'to' date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility sort columns.
|
||||
public List<String> GetFacilitySortColumns(SpmFacility.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Facility columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmFacility)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasFacility);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Type, aliasFacility) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility count.
|
||||
private long GetFacilityCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility) + " As " + aliasFacility, filter);
|
||||
}
|
||||
public override long GetFacilityCount(SpmFacility.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetFacilityCount(GetFacilityQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility list.
|
||||
public override List<SpmFacility> GetFacilityList(SpmFacility.Params prm)
|
||||
{
|
||||
List<SpmFacility> Facilityes = new List<SpmFacility>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), aliasFacility);
|
||||
qry.Columns.AddRange(SwmFacility_Db.Fields);
|
||||
qry.Filters.AddRange(GetFacilityQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmFacility_Db dbFacility = new SwmFacility_Db(DbInfo);
|
||||
dbFacility.PopulateFrom(dbDataReader);
|
||||
Facilityes.Add(CreateFacility(dbFacility));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetFacilityList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Facilityes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Facility query execution.
|
||||
public override DbResultSet ExecuteFacilityQuery(List<ColumnDfn> columns, SpmFacility.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), aliasFacility);
|
||||
|
||||
// Facility Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmFacility.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Id, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.DepartmentId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_DepartmentId, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.Type) || columns.HasId((int)SpmFacility.Column.Type_Desc))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Type, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.Name))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Name, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.SortCode))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_SortCode, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.Type))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Type, aliasFacility));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmFacility.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Notes, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.Status) || columns.HasId((int)SpmFacility.Column.Status_Desc) || columns.HasId((int)SpmFacility.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_Status, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_CreateOn, aliasFacility));
|
||||
if (columns.HasId((int)SpmFacility.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacility_UpdateOn, aliasFacility));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetFacilityQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetFacilitySortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetFacilityDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmFacility.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmFacility.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmFacility.Column.Status_Desc:
|
||||
case SpmFacility.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmFacility.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmFacility.Column.Status_Ind)
|
||||
value = new DataValue(SpmFacility.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,509 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// F a c i l i t y T e m p l a t e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate exists.
|
||||
public override bool FacilityTemplateExistsById(SysId facilityTemplateId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityTemplateId)) return false;
|
||||
SpmFacilityTemplate.Params prmFacilityTemplate = new SpmFacilityTemplate.Params();
|
||||
prmFacilityTemplate.IncludedIds.Add(facilityTemplateId);
|
||||
prmFacilityTemplate.StatusCat = SpmFacilityTemplate.StatusCat.Any;
|
||||
return GetFacilityTemplateCount(prmFacilityTemplate) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get FacilityTemplate.
|
||||
public override SpmFacilityTemplate GetFacilityTemplate(SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
return GetFacilityTemplate(GetFacilityTemplateQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmFacilityTemplate GetFacilityTemplate(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetFacilityTemplateCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple FacilityTemplatees found");
|
||||
return null;
|
||||
}
|
||||
SpmFacilityTemplate facilityTemplate = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmFacilityTemplate_Db dbFacilityTemplate = new SwmFacilityTemplate_Db(DbInfo);
|
||||
dbFacilityTemplate.PopulateFrom(dbCommand, aliasFacilityTemplate, filter);
|
||||
facilityTemplate = CreateFacilityTemplate(dbFacilityTemplate);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetFacilityTemplate\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return facilityTemplate;
|
||||
}
|
||||
public override SpmFacilityTemplate GetFacilityTemplateById(SysId facilityTemplateId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(facilityTemplateId)) return null;
|
||||
SpmFacilityTemplate.Params prmFacilityTemplate = new SpmFacilityTemplate.Params();
|
||||
prmFacilityTemplate.IncludedIds.Add(facilityTemplateId);
|
||||
prmFacilityTemplate.StatusCat = SpmFacilityTemplate.StatusCat.Any;
|
||||
return GetFacilityTemplate(prmFacilityTemplate);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create FacilityTemplate.
|
||||
public override SpmFacilityTemplate CreateFacilityTemplate(SysId facilityId, Spm.ResourceCategory resourceCategory)
|
||||
{
|
||||
return new SpmFacilityTemplate_Dbas(UserContext, facilityId, resourceCategory, 0);
|
||||
}
|
||||
private SpmFacilityTemplate_Dbas CreateFacilityTemplate(SwmFacilityTemplate_Db dbFacilityTemplate)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmFacilityTemplate_Dbas facilityTemplate = new SpmFacilityTemplate_Dbas(UserContext, new SysId(dbFacilityTemplate._FacilityId), (Spm.ResourceCategory)dbFacilityTemplate._Category, (ushort)dbFacilityTemplate._Flags);
|
||||
PopulateFrom(dbFacilityTemplate, facilityTemplate);
|
||||
return facilityTemplate;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate FacilityTemplate.
|
||||
public override bool IsValidFacilityTemplateData(SpmFacilityTemplate.Data data, SpmFacilityTemplate.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidFacilityTemplateData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert FacilityTemplate.
|
||||
public override bool InsertFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidFacilityTemplate(facilityTemplate)) return false;
|
||||
if (SysId.IsValid(facilityTemplate.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmFacilityTemplate_Db dbFacilityTemplate = new SwmFacilityTemplate_Db(DbInfo);
|
||||
PopulateTo(dbFacilityTemplate, facilityTemplate, dbUpdateInfo);
|
||||
if (SwmFacilityTemplate_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbFacilityTemplate._Id = SysId.ToInt(db.GetNextId("FacilityTemplate", dbUpdateInfo));
|
||||
}
|
||||
dbFacilityTemplate.ExecuteInsertCommand(dbCommand);
|
||||
facilityTemplate.Id = new SysId(dbFacilityTemplate._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update FacilityTemplate.
|
||||
public override bool UpdateFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidFacilityTemplate(facilityTemplate)) return false;
|
||||
if (!SysId.IsValid(facilityTemplate.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve FacilityTemplate.
|
||||
dbConnection.Open();
|
||||
SwmFacilityTemplate_Db dbFacilityTemplate = new SwmFacilityTemplate_Db(DbInfo);
|
||||
dbFacilityTemplate.PopulateFrom(dbCommand, aliasFacilityTemplate, "Id=" + SysId.ToString(facilityTemplate.Id));
|
||||
//SpmUpdateLogItemMonitor_FacilityTemplate updateLogMonitor = new SpmUpdateLogItemMonitor_FacilityTemplate(UserContext, CreateFacilityTemplate(dbFacilityTemplate));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbFacilityTemplate, facilityTemplate, dbUpdateInfo);
|
||||
dbFacilityTemplate.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(facilityTemplate);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete FacilityTemplate.
|
||||
public override bool FacilityTemplateCanBeDeleted(SpmFacilityTemplate facilityTemplate)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.FacilityTemplateCanBeDeleted(facilityTemplate)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteFacilityTemplate(SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!FacilityTemplateCanBeDeleted(facilityTemplate)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve FacilityTemplate.
|
||||
dbConnection.Open();
|
||||
SwmFacilityTemplate_Db dbFacilityTemplate = new SwmFacilityTemplate_Db(DbInfo);
|
||||
dbFacilityTemplate.PopulateFrom(dbCommand, aliasFacilityTemplate, "Id=" + facilityTemplate.Id.ToString());
|
||||
// Delete FacilityTemplate.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate) + " WHERE Id=" + SysId.ToString(facilityTemplate.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmFacilityTemplate_Db dbFacilityTemplate, SpmFacilityTemplate facilityTemplate, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbFacilityTemplate._Id = facilityTemplate.Id.ToInt();
|
||||
|
||||
dbFacilityTemplate._Notes = facilityTemplate.Notes;
|
||||
dbFacilityTemplate._Status = SacsSystem.GetStatusCode(facilityTemplate.Status);
|
||||
dbFacilityTemplate._Flags = (short)facilityTemplate.Flags;
|
||||
if (!SysId.IsValid(facilityTemplate.Id))
|
||||
{
|
||||
dbFacilityTemplate._CreateOn = DateTime.UtcNow;
|
||||
dbFacilityTemplate._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbFacilityTemplate._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbFacilityTemplate._UpdateOn = DateTime.UtcNow;
|
||||
dbFacilityTemplate._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbFacilityTemplate._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmFacilityTemplate_Db dbFacilityTemplate, SpmFacilityTemplate facilityTemplate)
|
||||
{
|
||||
//facilityTemplate.Id = new SysId(dbFacilityTemplate._Id);
|
||||
facilityTemplate.Notes = dbFacilityTemplate._Notes;
|
||||
facilityTemplate.Status = SacsSystem.GetStatusForCode(dbFacilityTemplate._Status);
|
||||
facilityTemplate.SetCreateStamp(dbFacilityTemplate._CreateOn, new SysId(dbFacilityTemplate._CreateBy), dbFacilityTemplate._CreateHost);
|
||||
facilityTemplate.SetUpdateStamp(dbFacilityTemplate._UpdateOn, new SysId(dbFacilityTemplate._UpdateBy), dbFacilityTemplate._UpdateHost);
|
||||
facilityTemplate.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate column definitions.
|
||||
private static readonly String aliasFacilityTemplate = "aFacTemp";
|
||||
private void SetFacilityTemplateColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmFacilityTemplate)
|
||||
alias = aliasFacilityTemplate;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmFacilityTemplate column definition.
|
||||
public override ColumnDfn GetFacilityTemplateColumnDfn(SpmFacilityTemplate.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmFacilityTemplate.Column.Pos:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.Id:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// FacilityTemplate Properties.
|
||||
|
||||
// Derived properties.
|
||||
|
||||
// Common properties.
|
||||
case SpmFacilityTemplate.Column.Notes:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Notes);
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.Status:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.Status_Desc:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.Status_Ind:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.CreateOn_Date:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmFacilityTemplate.Column.UpdateOn_Date:
|
||||
SetFacilityTemplateColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmFacilityTemplate_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate query filter.
|
||||
public override List<string> GetFacilityTemplateQueryFilter(SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// FacilityTemplate Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id, aliasFacilityTemplate) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id, aliasFacilityTemplate) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Applicable dates.
|
||||
DateTime nullDate = new DateTime(1970, 1, 1);
|
||||
String colApplicFrom = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_ApplicFrom, aliasFacilityTemplate);
|
||||
String colApplicTo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_ApplicTo, aliasFacilityTemplate);
|
||||
if (DateUtil.IsValid(prm.Application))
|
||||
{
|
||||
// Looking for roles that are applicable on the specified date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.Application, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.Application) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom) || DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Looking for roles that overlap with the specified date range.
|
||||
if (DateUtil.IsValid(prm.ApplicationFrom) && DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Both from and to dates specified.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationFrom))
|
||||
{
|
||||
// Only 'from' date specified - Matches with ApplicTo not specified or after 'from' date.
|
||||
filters.Add("(" + colApplicTo + " IS NULL OR " + colApplicTo + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicTo + ">=" + DbQuery.FormatDateForCondition(prm.ApplicationFrom) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
else if (DateUtil.IsValid(prm.ApplicationTo))
|
||||
{
|
||||
// Only 'to' date specified - Matches with ApplicFrom not specified or before 'to' date.
|
||||
filters.Add("(" + colApplicFrom + " IS NULL OR " + colApplicFrom + "=" + DbQuery.FormatDateForCondition(nullDate) + " OR " + colApplicFrom + "<" + DbQuery.FormatDateForCondition(DateUtil.IncrementDate(prm.ApplicationTo, 1)) + ")");
|
||||
String filter = filters[0];
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate sort columns.
|
||||
public List<String> GetFacilityTemplateSortColumns(SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for FacilityTemplate columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmFacilityTemplate)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasFacilityTemplate);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Type, aliasFacilityTemplate) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate count.
|
||||
private long GetFacilityTemplateCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate) + " As " + aliasFacilityTemplate, filter);
|
||||
}
|
||||
public override long GetFacilityTemplateCount(SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetFacilityTemplateCount(GetFacilityTemplateQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate list.
|
||||
public override List<SpmFacilityTemplate> GetFacilityTemplateList(SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
List<SpmFacilityTemplate> FacilityTemplatees = new List<SpmFacilityTemplate>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate), aliasFacilityTemplate);
|
||||
qry.Columns.AddRange(SwmFacilityTemplate_Db.Fields);
|
||||
qry.Filters.AddRange(GetFacilityTemplateQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmFacilityTemplate_Db dbFacilityTemplate = new SwmFacilityTemplate_Db(DbInfo);
|
||||
dbFacilityTemplate.PopulateFrom(dbDataReader);
|
||||
FacilityTemplatees.Add(CreateFacilityTemplate(dbFacilityTemplate));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetFacilityTemplateList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return FacilityTemplatees;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// FacilityTemplate query execution.
|
||||
public override DbResultSet ExecuteFacilityTemplateQuery(List<ColumnDfn> columns, SpmFacilityTemplate.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate), aliasFacilityTemplate);
|
||||
|
||||
// FacilityTemplate Properties - add columns as defined in query list.
|
||||
/*if (columns.HasId((int)SpmFacilityTemplate.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id, aliasFacilityTemplate));*/
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmFacilityTemplate.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Notes, aliasFacilityTemplate));
|
||||
if (columns.HasId((int)SpmFacilityTemplate.Column.Status) || columns.HasId((int)SpmFacilityTemplate.Column.Status_Desc) || columns.HasId((int)SpmFacilityTemplate.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Status, aliasFacilityTemplate));
|
||||
if (columns.HasId((int)SpmFacilityTemplate.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_CreateOn, aliasFacilityTemplate));
|
||||
if (columns.HasId((int)SpmFacilityTemplate.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_UpdateOn, aliasFacilityTemplate));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetFacilityTemplateQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetFacilityTemplateSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetFacilityTemplateDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmFacilityTemplate.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmFacilityTemplate.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmFacilityTemplate.Column.Status_Desc:
|
||||
case SpmFacilityTemplate.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmFacilityTemplate.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmFacilityTemplate.Column.Status_Ind)
|
||||
value = new DataValue(SpmFacilityTemplate.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n A c t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure exists.
|
||||
public override bool ProcedureExistsById(SysId procedureId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(procedureId)) return false;
|
||||
SpmProcedure.Params prmProcedure = new SpmProcedure.Params();
|
||||
prmProcedure.IncludedIds.Add(procedureId);
|
||||
prmProcedure.StatusCat = SpmProcedure.StatusCat.Any;
|
||||
return GetProcedureCount(prmProcedure) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Procedure.
|
||||
public override SpmProcedure GetProcedure(SpmProcedure.Params prm)
|
||||
{
|
||||
return GetProcedure(GetProcedureQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmProcedure GetProcedure(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetProcedureCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Procedurees found");
|
||||
return null;
|
||||
}
|
||||
SpmProcedure procedure = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmProcedure_Db dbProcedure = new SwmProcedure_Db(DbInfo);
|
||||
dbProcedure.PopulateFrom(dbCommand, aliasProcedure, filter);
|
||||
procedure = CreateProcedure(dbProcedure);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetProcedure\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return procedure;
|
||||
}
|
||||
public override SpmProcedure GetProcedureById(SysId procedureId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(procedureId)) return null;
|
||||
SpmProcedure.Params prmProcedure = new SpmProcedure.Params();
|
||||
prmProcedure.IncludedIds.Add(procedureId);
|
||||
prmProcedure.StatusCat = SpmProcedure.StatusCat.Any;
|
||||
return GetProcedure(prmProcedure);
|
||||
}
|
||||
public override SpmProcedure GetProcedureByCode(String operationCode)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!StringUtil.IsEmpty(operationCode)) return null;
|
||||
SpmProcedure.Params prmProcedure = new SpmProcedure.Params();
|
||||
prmProcedure.OperationCode = operationCode;
|
||||
prmProcedure.StatusCat = SpmProcedure.StatusCat.Any;
|
||||
return GetProcedure(prmProcedure);
|
||||
}
|
||||
public override SpmProcedure GetProcedureByOperationId(SysId operationId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(operationId)) return null;
|
||||
SpmProcedure.Params prmProcedure = new SpmProcedure.Params();
|
||||
prmProcedure.IncludedIds.Add(operationId);
|
||||
prmProcedure.OperationId = operationId;
|
||||
prmProcedure.StatusCat = SpmProcedure.StatusCat.Any;
|
||||
return GetProcedure(prmProcedure);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Procedure.
|
||||
public override SpmProcedure CreateProcedure(SysId procedureId, SysId departmentId)
|
||||
{
|
||||
return new SpmProcedure_Dbas(UserContext, procedureId, departmentId, 0);
|
||||
}
|
||||
private SpmProcedure_Dbas CreateProcedure(SwmProcedure_Db dbProcedure)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmProcedure_Dbas procedure = new SpmProcedure_Dbas(UserContext, new SysId(dbProcedure._Id), new SysId(dbProcedure._DepartmentId), (ushort)dbProcedure._Flags);
|
||||
PopulateFrom(dbProcedure, procedure);
|
||||
return procedure;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Procedure.
|
||||
public override bool IsValidProcedureData(SpmProcedure.Data data, SpmProcedure.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidProcedureData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Procedure.
|
||||
public override bool InsertProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidProcedure(procedure)) return false;
|
||||
if (SysId.IsValid(procedure.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmProcedure_Db dbProcedure = new SwmProcedure_Db(DbInfo);
|
||||
PopulateTo(dbProcedure, procedure, dbUpdateInfo);
|
||||
if (SwmProcedure_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbProcedure._Id = SysId.ToInt(db.GetNextId("Procedure", dbUpdateInfo));
|
||||
}
|
||||
dbProcedure.ExecuteInsertCommand(dbCommand);
|
||||
procedure.Id = new SysId(dbProcedure._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Procedure.
|
||||
public override bool UpdateProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidProcedure(procedure)) return false;
|
||||
if (!SysId.IsValid(procedure.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Procedure.
|
||||
dbConnection.Open();
|
||||
SwmProcedure_Db dbProcedure = new SwmProcedure_Db(DbInfo);
|
||||
dbProcedure.PopulateFrom(dbCommand, aliasProcedure, "Id=" + SysId.ToString(procedure.Id));
|
||||
//SpmUpdateLogItemMonitor_Procedure updateLogMonitor = new SpmUpdateLogItemMonitor_Procedure(UserContext, CreateProcedure(dbProcedure));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbProcedure, procedure, dbUpdateInfo);
|
||||
dbProcedure.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(procedure);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Procedure.
|
||||
public override bool ProcedureCanBeDeleted(SpmProcedure procedure)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.ProcedureCanBeDeleted(procedure)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteProcedure(SpmProcedure procedure, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!ProcedureCanBeDeleted(procedure)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Procedure.
|
||||
dbConnection.Open();
|
||||
SwmProcedure_Db dbProcedure = new SwmProcedure_Db(DbInfo);
|
||||
dbProcedure.PopulateFrom(dbCommand, aliasProcedure, "Id=" + procedure.Id.ToString());
|
||||
// Delete Procedure.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmProcedure) + " WHERE Id=" + SysId.ToString(procedure.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmProcedure_Db dbProcedure, SpmProcedure procedure, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbProcedure._Id = procedure.Id.ToInt();
|
||||
dbProcedure._OperationId = procedure.OperationId.ToInt();
|
||||
dbProcedure._OpnCode = procedure.OperationCode;
|
||||
dbProcedure._Description = procedure.Description;
|
||||
dbProcedure._ComplexityCode = procedure.ComplexityCode;
|
||||
dbProcedure._SpecialityCode = procedure.SpecialityCode;
|
||||
dbProcedure._Duration = procedure.Duration;
|
||||
dbProcedure._Duration_Training = procedure.DurationTraining;
|
||||
dbProcedure._Units = (float)procedure.Units;
|
||||
dbProcedure._Units_Training = (float)procedure.UnitsTraining;
|
||||
|
||||
dbProcedure._Notes = procedure.Notes;
|
||||
dbProcedure._Status = SacsSystem.GetStatusCode(procedure.Status);
|
||||
dbProcedure._Flags = (short)procedure.Flags;
|
||||
if (!SysId.IsValid(procedure.Id))
|
||||
{
|
||||
dbProcedure._CreateOn = DateTime.UtcNow;
|
||||
dbProcedure._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbProcedure._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbProcedure._UpdateOn = DateTime.UtcNow;
|
||||
dbProcedure._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbProcedure._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmProcedure_Db dbProcedure, SpmProcedure procedure)
|
||||
{
|
||||
procedure.Id = new SysId(dbProcedure._Id);
|
||||
procedure.OperationId = new SysId(dbProcedure._OperationId);
|
||||
procedure.OperationCode = dbProcedure._OpnCode;
|
||||
procedure.Description = dbProcedure._Description;
|
||||
procedure.ComplexityCode = dbProcedure._ComplexityCode;
|
||||
procedure.SpecialityCode = dbProcedure._SpecialityCode;
|
||||
procedure.Duration = dbProcedure._Duration;
|
||||
procedure.DurationTraining = dbProcedure._Duration_Training;
|
||||
procedure.Units = (decimal)dbProcedure._Units;
|
||||
procedure.UnitsTraining = (decimal)dbProcedure._Units_Training;
|
||||
|
||||
procedure.Notes = dbProcedure._Notes;
|
||||
procedure.Status = SacsSystem.GetStatusForCode(dbProcedure._Status);
|
||||
procedure.SetCreateStamp(dbProcedure._CreateOn, new SysId(dbProcedure._CreateBy), dbProcedure._CreateHost);
|
||||
procedure.SetUpdateStamp(dbProcedure._UpdateOn, new SysId(dbProcedure._UpdateBy), dbProcedure._UpdateHost);
|
||||
procedure.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure column definitions.
|
||||
private static readonly String aliasProcedure = "aProc";
|
||||
private void SetProcedureColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmProcedure)
|
||||
alias = aliasProcedure;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmProcedure column definition.
|
||||
public override ColumnDfn GetProcedureColumnDfn(SpmProcedure.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmProcedure.Column.Pos:
|
||||
SetProcedureColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmProcedure.Column.Id:
|
||||
SetProcedureColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmProcedure_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Procedure Properties.
|
||||
case SpmProcedure.Column.DepartmentId:
|
||||
SetFacilityColDfn(columnDfn, "DepartmentId", 45, SpmDbDfn.ColumnIdx.SwmProcedure_DepartmentId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmProcedure.Column.OperationId:
|
||||
SetProcedureColDfn(columnDfn, "OperationId", 45, SpmDbDfn.ColumnIdx.SwmProcedure_OperationId, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmProcedure.Column.Description:
|
||||
SetProcedureColDfn(columnDfn, "Description", 60, SpmDbDfn.ColumnIdx.SwmProcedure_Description, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmProcedure.Column.SpecialityCode:
|
||||
SetProcedureColDfn(columnDfn, "SpecialityCode", 60, SpmDbDfn.ColumnIdx.SwmProcedure_SpecialityCode, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmProcedure.Column.ComplexityCode:
|
||||
SetProcedureColDfn(columnDfn, "ComplexityCode", 60, SpmDbDfn.ColumnIdx.SwmProcedure_ComplexityCode, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmProcedure.Column.Duration:
|
||||
SetProcedureColDfn(columnDfn, "Duration", 45, SpmDbDfn.ColumnIdx.SwmProcedure_Duration, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmProcedure.Column.Duration_Training:
|
||||
SetProcedureColDfn(columnDfn, "DurationTraining", 45, SpmDbDfn.ColumnIdx.SwmProcedure_Duration_Training, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmProcedure.Column.Units:
|
||||
SetProcedureColDfn(columnDfn, "Units", 45, SpmDbDfn.ColumnIdx.SwmProcedure_Units, ColumnAlignment.Right);
|
||||
break;
|
||||
case SpmProcedure.Column.Units_Training:
|
||||
SetProcedureColDfn(columnDfn, "UnitsTraining", 45, SpmDbDfn.ColumnIdx.SwmProcedure_Units_Training, ColumnAlignment.Right);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmProcedure.Column.Notes:
|
||||
SetProcedureColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmProcedure_Notes);
|
||||
break;
|
||||
case SpmProcedure.Column.Status:
|
||||
SetProcedureColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmProcedure_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmProcedure.Column.Status_Desc:
|
||||
SetProcedureColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmProcedure_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmProcedure.Column.Status_Ind:
|
||||
SetProcedureColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmProcedure_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmProcedure.Column.CreateOn_Date:
|
||||
SetProcedureColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmProcedure_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmProcedure.Column.UpdateOn_Date:
|
||||
SetProcedureColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmProcedure_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure query filter.
|
||||
public override List<string> GetProcedureQueryFilter(SpmProcedure.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Procedure Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Id, aliasProcedure) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Id, aliasProcedure) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Operation Id.
|
||||
if (SysId.IsValid(prm.OperationId))
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_OperationId, aliasProcedure) + "=" + prm.OperationId.ToString());
|
||||
|
||||
// Operation Code.
|
||||
String operationCode = DbQuery.FormatForCondition(prm.OperationCode);
|
||||
if (!StringUtil.IsEmpty(operationCode))
|
||||
{
|
||||
String colOperationCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_OpnCode, aliasProcedure);
|
||||
filters.Add(DbQuery.FormatFn_Left(colOperationCode, prm.OperationCode.Length) + "='" + operationCode + "'");
|
||||
}
|
||||
|
||||
// Description.
|
||||
String description = DbQuery.FormatForCondition(prm.Description);
|
||||
if (!StringUtil.IsEmpty(description))
|
||||
{
|
||||
String colDescription = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Description, aliasProcedure);
|
||||
// Build filter condition on description.
|
||||
List<String> filtersDesc = new List<String>();
|
||||
filtersDesc.Add(DbQuery.FormatFn_Left(colDescription, prm.Description.Length) + "='" + description + "'");
|
||||
|
||||
// Split description into space delimited words (to allow any combination within the description).
|
||||
List<String> descWord = description.Split(' ').ToList();
|
||||
filtersDesc.Add("(" + descWord.Concat(" AND ", colDescription + " LIKE '%", "%'") + ")");
|
||||
filters.Add(filtersDesc.Concat(" OR "));
|
||||
}
|
||||
|
||||
// Speciality code.
|
||||
String colSpecialityCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_SpecialityCode, aliasProcedure);
|
||||
if (!StringUtil.IsEmpty(prm.SpecialityCode))
|
||||
filters.Add(colSpecialityCode + "='" + prm.SpecialityCode + "'");
|
||||
|
||||
// Complexity code.
|
||||
String colComplexityCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_ComplexityCode, aliasProcedure);
|
||||
if (!StringUtil.IsEmpty(prm.ComplexityCode))
|
||||
filters.Add(colComplexityCode + "='" + prm.ComplexityCode + "'");
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure sort columns.
|
||||
public List<String> GetProcedureSortColumns(SpmProcedure.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Procedure columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmProcedure)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasProcedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Type, aliasProcedure) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure count.
|
||||
private long GetProcedureCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmProcedure) + " As " + aliasProcedure, filter);
|
||||
}
|
||||
public override long GetProcedureCount(SpmProcedure.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetProcedureCount(GetProcedureQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure list.
|
||||
public override List<SpmProcedure> GetProcedureList(SpmProcedure.Params prm)
|
||||
{
|
||||
List<SpmProcedure> Procedurees = new List<SpmProcedure>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmProcedure), aliasProcedure);
|
||||
qry.Columns.AddRange(SwmProcedure_Db.Fields);
|
||||
qry.Filters.AddRange(GetProcedureQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmProcedure_Db dbProcedure = new SwmProcedure_Db(DbInfo);
|
||||
dbProcedure.PopulateFrom(dbDataReader);
|
||||
Procedurees.Add(CreateProcedure(dbProcedure));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetProcedureList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Procedurees;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Procedure query execution.
|
||||
public override DbResultSet ExecuteProcedureQuery(List<ColumnDfn> columns, SpmProcedure.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmProcedure), aliasProcedure);
|
||||
|
||||
// Procedure Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmProcedure.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Id, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.DepartmentId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_DepartmentId, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.OperationId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_OperationId, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Description))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Description, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.SpecialityCode))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_SpecialityCode, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.ComplexityCode))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_ComplexityCode, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Duration))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Duration, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Duration_Training))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Duration_Training, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Units))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Units, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Units_Training))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Units_Training, aliasProcedure));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmProcedure.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Notes, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.Status) || columns.HasId((int)SpmProcedure.Column.Status_Desc) || columns.HasId((int)SpmProcedure.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_Status, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_CreateOn, aliasProcedure));
|
||||
if (columns.HasId((int)SpmProcedure.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmProcedure_UpdateOn, aliasProcedure));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetProcedureQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetProcedureSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetProcedureDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmProcedure.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmProcedure.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmProcedure.Column.Status_Desc:
|
||||
case SpmProcedure.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmProcedure.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmProcedure.Column.Status_Ind)
|
||||
value = new DataValue(SpmProcedure.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// A d m i s s i o n A c t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData exists.
|
||||
public override bool TemplateDataExistsById(SysId templateDataId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(templateDataId)) return false;
|
||||
SpmTemplateData.Params prmTemplateData = new SpmTemplateData.Params();
|
||||
prmTemplateData.IncludedIds.Add(templateDataId);
|
||||
prmTemplateData.StatusCat = SpmTemplateData.StatusCat.Any;
|
||||
return GetTemplateDataCount(prmTemplateData) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get TemplateData.
|
||||
public override SpmTemplateData GetTemplateData(SpmTemplateData.Params prm)
|
||||
{
|
||||
return GetTemplateData(GetTemplateDataQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmTemplateData GetTemplateData(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetTemplateDataCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple TemplateDataes found");
|
||||
return null;
|
||||
}
|
||||
SpmTemplateData templateData = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmTemplateData_Db dbTemplateData = new SwmTemplateData_Db(DbInfo);
|
||||
dbTemplateData.PopulateFrom(dbCommand, aliasTemplateData, filter);
|
||||
templateData = CreateTemplateData(dbTemplateData);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetTemplateData\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return templateData;
|
||||
}
|
||||
public override SpmTemplateData GetTemplateDataById(SysId templateDataId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(templateDataId)) return null;
|
||||
SpmTemplateData.Params prmTemplateData = new SpmTemplateData.Params();
|
||||
prmTemplateData.IncludedIds.Add(templateDataId);
|
||||
prmTemplateData.StatusCat = SpmTemplateData.StatusCat.Any;
|
||||
return GetTemplateData(prmTemplateData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create TemplateData.
|
||||
public override SpmTemplateData CreateTemplateData()
|
||||
{
|
||||
return new SpmTemplateData_Dbas(UserContext, null, 0);
|
||||
}
|
||||
private SpmTemplateData_Dbas CreateTemplateData(SwmTemplateData_Db dbTemplateData)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmTemplateData_Dbas templateData = new SpmTemplateData_Dbas(UserContext, new SysId(0), (ushort)dbTemplateData._Flags);
|
||||
PopulateFrom(dbTemplateData, templateData);
|
||||
return templateData;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate TemplateData.
|
||||
public override bool IsValidTemplateDataData(SpmTemplateData.Data data, SpmTemplateData.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidTemplateDataData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert TemplateData.
|
||||
public override bool InsertTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidTemplateData(templateData)) return false;
|
||||
if (SysId.IsValid(templateData.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmTemplateData_Db dbTemplateData = new SwmTemplateData_Db(DbInfo);
|
||||
PopulateTo(dbTemplateData, templateData, dbUpdateInfo);
|
||||
if (SwmTemplateData_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
//dbTemplateData._Id = SysId.ToInt(db.GetNextId("TemplateData", dbUpdateInfo));
|
||||
}
|
||||
dbTemplateData.ExecuteInsertCommand(dbCommand);
|
||||
//templateData.Id = new SysId(dbTemplateData._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update TemplateData.
|
||||
public override bool UpdateTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidTemplateData(templateData)) return false;
|
||||
if (!SysId.IsValid(templateData.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve TemplateData.
|
||||
dbConnection.Open();
|
||||
SwmTemplateData_Db dbTemplateData = new SwmTemplateData_Db(DbInfo);
|
||||
dbTemplateData.PopulateFrom(dbCommand, aliasTemplateData, "Id=" + SysId.ToString(templateData.Id));
|
||||
//SpmUpdateLogItemMonitor_TemplateData updateLogMonitor = new SpmUpdateLogItemMonitor_TemplateData(UserContext, CreateTemplateData(dbTemplateData));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbTemplateData, templateData, dbUpdateInfo);
|
||||
dbTemplateData.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(templateData);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete TemplateData.
|
||||
public override bool TemplateDataCanBeDeleted(SpmTemplateData templateData)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.TemplateDataCanBeDeleted(templateData)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteTemplateData(SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!TemplateDataCanBeDeleted(templateData)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve TemplateData.
|
||||
dbConnection.Open();
|
||||
SwmTemplateData_Db dbTemplateData = new SwmTemplateData_Db(DbInfo);
|
||||
dbTemplateData.PopulateFrom(dbCommand, aliasTemplateData, "Id=" + templateData.Id.ToString());
|
||||
// Delete TemplateData.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmTemplateData) + " WHERE Id=" + SysId.ToString(templateData.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmTemplateData_Db dbTemplateData, SpmTemplateData templateData, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
//dbTemplateData._Id = templateData.Id.ToInt();
|
||||
|
||||
dbTemplateData._Notes = templateData.Notes;
|
||||
dbTemplateData._Status = SacsSystem.GetStatusCode(templateData.Status);
|
||||
dbTemplateData._Flags = (short)templateData.Flags;
|
||||
if (!SysId.IsValid(templateData.Id))
|
||||
{
|
||||
dbTemplateData._CreateOn = DateTime.UtcNow;
|
||||
dbTemplateData._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbTemplateData._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbTemplateData._UpdateOn = DateTime.UtcNow;
|
||||
dbTemplateData._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbTemplateData._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmTemplateData_Db dbTemplateData, SpmTemplateData templateData)
|
||||
{
|
||||
//templateData.Id = new SysId(dbTemplateData._Id);
|
||||
templateData.Notes = dbTemplateData._Notes;
|
||||
templateData.Status = SacsSystem.GetStatusForCode(dbTemplateData._Status);
|
||||
templateData.SetCreateStamp(dbTemplateData._CreateOn, new SysId(dbTemplateData._CreateBy), dbTemplateData._CreateHost);
|
||||
templateData.SetUpdateStamp(dbTemplateData._UpdateOn, new SysId(dbTemplateData._UpdateBy), dbTemplateData._UpdateHost);
|
||||
templateData.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData column definitions.
|
||||
private static readonly String aliasTemplateData = "aAdmAct";
|
||||
private void SetTemplateDataColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmTemplateData)
|
||||
alias = aliasTemplateData;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmTemplateData column definition.
|
||||
public override ColumnDfn GetTemplateDataColumnDfn(SpmTemplateData.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
/*case SpmTemplateData.Column.Pos:
|
||||
SetTemplateDataColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmTemplateData.Column.Id:
|
||||
SetTemplateDataColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmTemplateData_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;*/
|
||||
|
||||
// TemplateData Properties.
|
||||
|
||||
// Derived properties.
|
||||
|
||||
// Common properties.
|
||||
case SpmTemplateData.Column.Notes:
|
||||
SetTemplateDataColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmTemplateData_Notes);
|
||||
break;
|
||||
case SpmTemplateData.Column.Status:
|
||||
SetTemplateDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmTemplateData_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmTemplateData.Column.Status_Desc:
|
||||
SetTemplateDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmTemplateData_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmTemplateData.Column.Status_Ind:
|
||||
SetTemplateDataColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmTemplateData_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmTemplateData.Column.CreateOn_Date:
|
||||
SetTemplateDataColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmTemplateData_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmTemplateData.Column.UpdateOn_Date:
|
||||
SetTemplateDataColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmTemplateData_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData query filter.
|
||||
public override List<string> GetTemplateDataQueryFilter(SpmTemplateData.Params prm)
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
|
||||
// TemplateData Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
/*if (!includedIds.IsEmpty())
|
||||
filter.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Id, aliasTemplateData) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filter.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Id, aliasTemplateData) + " NOT IN (" + excludedIds + ")");*/
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Common Properties.
|
||||
|
||||
if (filter.Count < 1) filter.Add("1=1");
|
||||
return filter;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData sort columns.
|
||||
public List<String> GetTemplateDataSortColumns(SpmTemplateData.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for TemplateData columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmTemplateData)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasTemplateData);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Type, aliasTemplateData) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData count.
|
||||
private long GetTemplateDataCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmTemplateData) + " As " + aliasTemplateData, filter);
|
||||
}
|
||||
public override long GetTemplateDataCount(SpmTemplateData.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetTemplateDataCount(GetTemplateDataQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData list.
|
||||
public override List<SpmTemplateData> GetTemplateDataList(SpmTemplateData.Params prm)
|
||||
{
|
||||
List<SpmTemplateData> TemplateDataes = new List<SpmTemplateData>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmTemplateData), aliasTemplateData);
|
||||
qry.Columns.AddRange(SwmTemplateData_Db.Fields);
|
||||
qry.Filters.AddRange(GetTemplateDataQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmTemplateData_Db dbTemplateData = new SwmTemplateData_Db(DbInfo);
|
||||
dbTemplateData.PopulateFrom(dbDataReader);
|
||||
TemplateDataes.Add(CreateTemplateData(dbTemplateData));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetTemplateDataList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return TemplateDataes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// TemplateData query execution.
|
||||
public override DbResultSet ExecuteTemplateDataQuery(List<ColumnDfn> columns, SpmTemplateData.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmTemplateData), aliasTemplateData);
|
||||
|
||||
// TemplateData Properties - add columns as defined in query list.
|
||||
/*if (columns.HasId((int)SpmTemplateData.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Id, aliasTemplateData));*/
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmTemplateData.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Notes, aliasTemplateData));
|
||||
if (columns.HasId((int)SpmTemplateData.Column.Status) || columns.HasId((int)SpmTemplateData.Column.Status_Desc) || columns.HasId((int)SpmTemplateData.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_Status, aliasTemplateData));
|
||||
if (columns.HasId((int)SpmTemplateData.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_CreateOn, aliasTemplateData));
|
||||
if (columns.HasId((int)SpmTemplateData.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmTemplateData_UpdateOn, aliasTemplateData));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetTemplateDataQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetTemplateDataSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetTemplateDataDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmTemplateData.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmTemplateData.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmTemplateData.Column.Status_Desc:
|
||||
case SpmTemplateData.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmTemplateData.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmTemplateData.Column.Status_Ind)
|
||||
value = new DataValue(SpmTemplateData.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Data;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmDepartmentMgr_Dbas : SpmDepartmentMgr
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SacsDatabase db = null;
|
||||
private readonly SpmDbDataItem.DatabaseInfo dbInfo;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmDepartmentMgr_Dbas (SpmUserContext userContext) :
|
||||
base(userContext)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected ISacsDatabase Database { get { return db; } }
|
||||
protected SpmDbDataItem.DatabaseInfo DbInfo { get { return dbInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmInstitutionMgr_Dbas : SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// E m p l o y e e
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee exists.
|
||||
public override bool EmployeeExistsById(SysId employeeId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(employeeId)) return false;
|
||||
SpmEmployee.Params prmEmployee = new SpmEmployee.Params();
|
||||
prmEmployee.IncludedIds.Add(employeeId);
|
||||
prmEmployee.StatusCat = SpmEmployee.StatusCat.Any;
|
||||
return GetEmployeeCount(prmEmployee) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Employee.
|
||||
public override SpmEmployee GetEmployee(SpmEmployee.Params prm)
|
||||
{
|
||||
return GetEmployee(GetEmployeeQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmEmployee GetEmployee(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetEmployeeCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Employeees found");
|
||||
return null;
|
||||
}
|
||||
SpmEmployee employee = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmEmployee_Db dbEmployee = new SwmEmployee_Db(DbInfo);
|
||||
dbEmployee.PopulateFrom(dbCommand, aliasEmployee, filter);
|
||||
employee = CreateEmployee(dbEmployee);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetEmployee\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
public override SpmEmployee GetEmployeeById(SysId employeeId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(employeeId)) return null;
|
||||
SpmEmployee.Params prmEmployee = new SpmEmployee.Params();
|
||||
prmEmployee.IncludedIds.Add(employeeId);
|
||||
prmEmployee.StatusCat = SpmEmployee.StatusCat.Any;
|
||||
return GetEmployee(prmEmployee);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Employee.
|
||||
public override SpmEmployee CreateEmployee(SysId id, SysId institutionId)
|
||||
{
|
||||
return new SpmEmployee_Dbas(UserContext, id, institutionId, 0);
|
||||
}
|
||||
private SpmEmployee_Dbas CreateEmployee(SwmEmployee_Db dbEmployee)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmEmployee_Dbas employee = new SpmEmployee_Dbas(UserContext, new SysId(dbEmployee._Id), new SysId(dbEmployee._InstitutionId), (ushort)dbEmployee._Flags);
|
||||
PopulateFrom(dbEmployee, employee);
|
||||
return employee;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Employee.
|
||||
public override bool IsValidEmployeeData(SpmEmployee.Data data, SpmEmployee.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidEmployeeData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Employee.
|
||||
public override bool InsertEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidEmployee(employee)) return false;
|
||||
if (SysId.IsValid(employee.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmEmployee_Db dbEmployee = new SwmEmployee_Db(DbInfo);
|
||||
PopulateTo(dbEmployee, employee, dbUpdateInfo);
|
||||
if (SwmEmployee_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbEmployee._Id = SysId.ToInt(db.GetNextId("Employee", dbUpdateInfo));
|
||||
}
|
||||
dbEmployee.ExecuteInsertCommand(dbCommand);
|
||||
employee.Id = new SysId(dbEmployee._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Employee.
|
||||
public override bool UpdateEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidEmployee(employee)) return false;
|
||||
if (!SysId.IsValid(employee.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Employee.
|
||||
dbConnection.Open();
|
||||
SwmEmployee_Db dbEmployee = new SwmEmployee_Db(DbInfo);
|
||||
dbEmployee.PopulateFrom(dbCommand, aliasEmployee, "Id=" + SysId.ToString(employee.Id));
|
||||
//SpmUpdateLogItemMonitor_Employee updateLogMonitor = new SpmUpdateLogItemMonitor_Employee(UserContext, CreateEmployee(dbEmployee));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbEmployee, employee, dbUpdateInfo);
|
||||
dbEmployee.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(employee);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Employee.
|
||||
public override bool EmployeeCanBeDeleted(SpmEmployee employee)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.EmployeeCanBeDeleted(employee)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteEmployee(SpmEmployee employee, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!EmployeeCanBeDeleted(employee)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Employee.
|
||||
dbConnection.Open();
|
||||
SwmEmployee_Db dbEmployee = new SwmEmployee_Db(DbInfo);
|
||||
dbEmployee.PopulateFrom(dbCommand, aliasEmployee, "Id=" + employee.Id.ToString());
|
||||
// Delete Employee.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployee) + " WHERE Id=" + SysId.ToString(employee.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmEmployee_Db dbEmployee, SpmEmployee employee, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbEmployee._Id = employee.Id.ToInt();
|
||||
dbEmployee._EmployeeNo = employee.EmployeeNo;
|
||||
dbEmployee._Code = employee.Code;
|
||||
dbEmployee._Initials = employee.Initials;
|
||||
dbEmployee._Title = employee.Title;
|
||||
dbEmployee._Surname = employee.Surname;
|
||||
dbEmployee._Forename = employee.Forename;
|
||||
|
||||
dbEmployee._Notes = employee.Notes;
|
||||
dbEmployee._Status = SacsSystem.GetStatusCode(employee.Status);
|
||||
dbEmployee._Flags = (short)employee.Flags;
|
||||
if (!SysId.IsValid(employee.Id))
|
||||
{
|
||||
dbEmployee._CreateOn = DateTime.UtcNow;
|
||||
dbEmployee._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbEmployee._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbEmployee._UpdateOn = DateTime.UtcNow;
|
||||
dbEmployee._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbEmployee._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmEmployee_Db dbEmployee, SpmEmployee employee)
|
||||
{
|
||||
employee.Id = new SysId(dbEmployee._Id);
|
||||
employee.EmployeeNo = dbEmployee._EmployeeNo;
|
||||
employee.Code = dbEmployee._Code;
|
||||
employee.Initials = dbEmployee._Initials;
|
||||
employee.Title = dbEmployee._Title;
|
||||
employee.Surname = dbEmployee._Surname;
|
||||
employee.Forename = dbEmployee._Forename;
|
||||
|
||||
employee.Notes = dbEmployee._Notes;
|
||||
employee.Status = SacsSystem.GetStatusForCode(dbEmployee._Status);
|
||||
employee.SetCreateStamp(dbEmployee._CreateOn, new SysId(dbEmployee._CreateBy), dbEmployee._CreateHost);
|
||||
employee.SetUpdateStamp(dbEmployee._UpdateOn, new SysId(dbEmployee._UpdateBy), dbEmployee._UpdateHost);
|
||||
employee.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee column definitions.
|
||||
private static readonly String aliasEmployee = "aAdmAct";
|
||||
private void SetEmployeeColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmEmployee)
|
||||
alias = aliasEmployee;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmEmployee column definition.
|
||||
public override ColumnDfn GetEmployeeColumnDfn(SpmEmployee.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmEmployee.Column.Pos:
|
||||
SetEmployeeColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmEmployee.Column.Id:
|
||||
SetEmployeeColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmEmployee_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Employee Properties.
|
||||
case SpmEmployee.Column.InstitutionId:
|
||||
SetEmployeeColDfn(columnDfn, "InstitutionId", 40, SpmDbDfn.ColumnIdx.SwmEmployee_InstitutionId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmEmployee.Column.EmployeeNo:
|
||||
SetEmployeeColDfn(columnDfn, "EmployeeNo", 60, SpmDbDfn.ColumnIdx.SwmEmployee_EmployeeNo, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmEmployee.Column.Code:
|
||||
SetEmployeeColDfn(columnDfn, "Code", 60, SpmDbDfn.ColumnIdx.SwmEmployee_Code, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmEmployee.Column.Initials:
|
||||
SetEmployeeColDfn(columnDfn, "Initials", 90, SpmDbDfn.ColumnIdx.SwmEmployee_Initials);
|
||||
break;
|
||||
case SpmEmployee.Column.Title:
|
||||
SetEmployeeColDfn(columnDfn, "Title", 90, SpmDbDfn.ColumnIdx.SwmEmployee_Title);
|
||||
break;
|
||||
case SpmEmployee.Column.Surname:
|
||||
SetEmployeeColDfn(columnDfn, "Surname", 90, SpmDbDfn.ColumnIdx.SwmEmployee_Surname);
|
||||
break;
|
||||
case SpmEmployee.Column.Forename:
|
||||
SetEmployeeColDfn(columnDfn, "Forename", 90, SpmDbDfn.ColumnIdx.SwmEmployee_Forename);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmEmployee.Column.Notes:
|
||||
SetEmployeeColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmEmployee_Notes);
|
||||
break;
|
||||
case SpmEmployee.Column.Status:
|
||||
SetEmployeeColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployee_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmEmployee.Column.Status_Desc:
|
||||
SetEmployeeColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployee_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmEmployee.Column.Status_Ind:
|
||||
SetEmployeeColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmEmployee_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmEmployee.Column.CreateOn_Date:
|
||||
SetEmployeeColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmEmployee_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmEmployee.Column.UpdateOn_Date:
|
||||
SetEmployeeColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmEmployee_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee query filter.
|
||||
public override List<string> GetEmployeeQueryFilter(SpmEmployee.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Employee Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Id, aliasEmployee) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Id, aliasEmployee) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Institution Id.
|
||||
String colInstitutionId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_InstitutionId, aliasOperation);
|
||||
if (SysId.IsValid(prm.InstitutionId))
|
||||
filters.Add(colInstitutionId + "=" + prm.InstitutionId.ToString());
|
||||
|
||||
// Employee Number.
|
||||
String employeeNo = DbQuery.FormatForCondition(prm.EmployeeNo);
|
||||
String colEmployeeNo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_EmployeeNo, aliasEmployee);
|
||||
if (!StringUtil.IsEmpty(employeeNo))
|
||||
filters.Add(DbQuery.FormatFn_Left(colEmployeeNo, employeeNo.Length) + "='" + employeeNo + "'");
|
||||
|
||||
// Code.
|
||||
String code = DbQuery.FormatForCondition(prm.Code);
|
||||
String sColCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Code, aliasEmployee);
|
||||
if (!StringUtil.IsEmpty(code))
|
||||
filters.Add(DbQuery.FormatFn_Left(sColCode, code.Length) + "='" + code + "'");
|
||||
|
||||
// Partial name.
|
||||
String surname = DbQuery.FormatForCondition(prm.Surname);
|
||||
String sColName = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Surname, aliasEmployee);
|
||||
if (!StringUtil.IsEmpty(surname))
|
||||
filters.Add(DbQuery.FormatFn_Left(sColName, surname.Length) + "='" + surname + "'");
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee sort columns.
|
||||
public List<String> GetEmployeeSortColumns(SpmEmployee.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Employee columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmEmployee)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasEmployee);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Type, aliasEmployee) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee count.
|
||||
private long GetEmployeeCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployee) + " As " + aliasEmployee, filter);
|
||||
}
|
||||
public override long GetEmployeeCount(SpmEmployee.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetEmployeeCount(GetEmployeeQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee list.
|
||||
public override List<SpmEmployee> GetEmployeeList(SpmEmployee.Params prm)
|
||||
{
|
||||
List<SpmEmployee> Employeees = new List<SpmEmployee>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployee), aliasEmployee);
|
||||
qry.Columns.AddRange(SwmEmployee_Db.Fields);
|
||||
qry.Filters.AddRange(GetEmployeeQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmEmployee_Db dbEmployee = new SwmEmployee_Db(DbInfo);
|
||||
dbEmployee.PopulateFrom(dbDataReader);
|
||||
Employeees.Add(CreateEmployee(dbEmployee));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetEmployeeList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Employeees;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Employee query execution.
|
||||
public override DbResultSet ExecuteEmployeeQuery(List<ColumnDfn> columns, SpmEmployee.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmEmployee), aliasEmployee);
|
||||
|
||||
// Employee Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmEmployee.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Id, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.EmployeeNo))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_EmployeeNo, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Code))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Code, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Initials))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Initials, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Title))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Title, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Forename))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Forename, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Surname))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Surname, aliasEmployee));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmEmployee.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Notes, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.Status) || columns.HasId((int)SpmEmployee.Column.Status_Desc) || columns.HasId((int)SpmEmployee.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_Status, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_CreateOn, aliasEmployee));
|
||||
if (columns.HasId((int)SpmEmployee.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmEmployee_UpdateOn, aliasEmployee));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetEmployeeQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetEmployeeSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetEmployeeDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmEmployee.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmEmployee.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmEmployee.Column.Status_Desc:
|
||||
case SpmEmployee.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmEmployee.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmEmployee.Column.Status_Ind)
|
||||
value = new DataValue(SpmEmployee.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmInstitutionMgr_Dbas : SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// I n s t i t u t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution exists.
|
||||
public override bool InstitutionExistsById(SysId institutionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(institutionId)) return false;
|
||||
SpmInstitution.Params prmInstitution = new SpmInstitution.Params();
|
||||
prmInstitution.IncludedIds.Add(institutionId);
|
||||
prmInstitution.StatusCat = SpmInstitution.StatusCat.Any;
|
||||
return GetInstitutionCount(prmInstitution) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Institution.
|
||||
public override SpmInstitution GetInstitution(SpmInstitution.Params prm)
|
||||
{
|
||||
return GetInstitution(GetInstitutionQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmInstitution GetInstitution(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetInstitutionCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Institutiones found");
|
||||
return null;
|
||||
}
|
||||
SpmInstitution institution = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmInstitution_Db dbInstitution = new SwmInstitution_Db(DbInfo);
|
||||
dbInstitution.PopulateFrom(dbCommand, aliasInstitution, filter);
|
||||
institution = CreateInstitution(dbInstitution);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetInstitution\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return institution;
|
||||
}
|
||||
public override SpmInstitution GetInstitutionById(SysId institutionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(institutionId)) return null;
|
||||
SpmInstitution.Params prmInstitution = new SpmInstitution.Params();
|
||||
prmInstitution.IncludedIds.Add(institutionId);
|
||||
prmInstitution.StatusCat = SpmInstitution.StatusCat.Any;
|
||||
return GetInstitution(prmInstitution);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Institution.
|
||||
public override SpmInstitution CreateInstitution(SysId institutionId)
|
||||
{
|
||||
return new SpmInstitution_Dbas(UserContext, null, 0);
|
||||
}
|
||||
private SpmInstitution_Dbas CreateInstitution(SwmInstitution_Db dbInstitution)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmInstitution_Dbas institution = new SpmInstitution_Dbas(UserContext, new SysId(dbInstitution._Id), (ushort)dbInstitution._Flags);
|
||||
PopulateFrom(dbInstitution, institution);
|
||||
return institution;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Institution.
|
||||
public override bool IsValidInstitutionData(SpmInstitution.Data data, SpmInstitution.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidInstitutionData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Institution.
|
||||
public override bool InsertInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidInstitution(institution)) return false;
|
||||
if (SysId.IsValid(institution.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmInstitution_Db dbInstitution = new SwmInstitution_Db(DbInfo);
|
||||
PopulateTo(dbInstitution, institution, dbUpdateInfo);
|
||||
if (SwmInstitution_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbInstitution._Id = SysId.ToInt(db.GetNextId("Institution", dbUpdateInfo));
|
||||
}
|
||||
dbInstitution.ExecuteInsertCommand(dbCommand);
|
||||
institution.Id = new SysId(dbInstitution._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Institution.
|
||||
public override bool UpdateInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidInstitution(institution)) return false;
|
||||
if (!SysId.IsValid(institution.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Institution.
|
||||
dbConnection.Open();
|
||||
SwmInstitution_Db dbInstitution = new SwmInstitution_Db(DbInfo);
|
||||
dbInstitution.PopulateFrom(dbCommand, aliasInstitution, "Id=" + SysId.ToString(institution.Id));
|
||||
//SpmUpdateLogItemMonitor_Institution updateLogMonitor = new SpmUpdateLogItemMonitor_Institution(UserContext, CreateInstitution(dbInstitution));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbInstitution, institution, dbUpdateInfo);
|
||||
dbInstitution.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(institution);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Institution.
|
||||
public override bool InstitutionCanBeDeleted(SpmInstitution institution)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.InstitutionCanBeDeleted(institution)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteInstitution(SpmInstitution institution, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!InstitutionCanBeDeleted(institution)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Institution.
|
||||
dbConnection.Open();
|
||||
SwmInstitution_Db dbInstitution = new SwmInstitution_Db(DbInfo);
|
||||
dbInstitution.PopulateFrom(dbCommand, aliasInstitution, "Id=" + institution.Id.ToString());
|
||||
// Delete Institution.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmInstitution) + " WHERE Id=" + SysId.ToString(institution.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmInstitution_Db dbInstitution, SpmInstitution institution, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbInstitution._Id = institution.Id.ToInt();
|
||||
dbInstitution._Name = institution.Name;
|
||||
|
||||
dbInstitution._Notes = institution.Notes;
|
||||
dbInstitution._Status = SacsSystem.GetStatusCode(institution.Status);
|
||||
dbInstitution._Flags = (short)institution.Flags;
|
||||
if (!SysId.IsValid(institution.Id))
|
||||
{
|
||||
dbInstitution._CreateOn = DateTime.UtcNow;
|
||||
dbInstitution._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbInstitution._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbInstitution._UpdateOn = DateTime.UtcNow;
|
||||
dbInstitution._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbInstitution._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmInstitution_Db dbInstitution, SpmInstitution institution)
|
||||
{
|
||||
institution.Id = new SysId(dbInstitution._Id);
|
||||
institution.Name = dbInstitution._Name;
|
||||
|
||||
institution.Notes = dbInstitution._Notes;
|
||||
institution.Status = SacsSystem.GetStatusForCode(dbInstitution._Status);
|
||||
institution.SetCreateStamp(dbInstitution._CreateOn, new SysId(dbInstitution._CreateBy), dbInstitution._CreateHost);
|
||||
institution.SetUpdateStamp(dbInstitution._UpdateOn, new SysId(dbInstitution._UpdateBy), dbInstitution._UpdateHost);
|
||||
institution.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution column definitions.
|
||||
private static readonly String aliasInstitution = "aInst";
|
||||
private void SetInstitutionColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmInstitution)
|
||||
alias = aliasInstitution;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmInstitution column definition.
|
||||
public override ColumnDfn GetInstitutionColumnDfn(SpmInstitution.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmInstitution.Column.Pos:
|
||||
SetInstitutionColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmInstitution.Column.Id:
|
||||
SetInstitutionColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmInstitution_Id, ColumnAlignment.Right, DataValue.DataType.Long, aliasInstitution);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Institution Properties.
|
||||
case SpmInstitution.Column.Name:
|
||||
SetInstitutionColDfn(columnDfn, "Name", 60, SpmDbDfn.ColumnIdx.SwmInstitution_Name, ColumnAlignment.Default, DataValue.DataType.String, aliasInstitution);
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmInstitution.Column.Notes:
|
||||
SetInstitutionColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmInstitution_Notes);
|
||||
break;
|
||||
case SpmInstitution.Column.Status:
|
||||
SetInstitutionColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmInstitution_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmInstitution.Column.Status_Desc:
|
||||
SetInstitutionColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmInstitution_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmInstitution.Column.Status_Ind:
|
||||
SetInstitutionColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmInstitution_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmInstitution.Column.CreateOn_Date:
|
||||
SetInstitutionColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmInstitution_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmInstitution.Column.UpdateOn_Date:
|
||||
SetInstitutionColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmInstitution_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution query filter.
|
||||
public override List<string> GetInstitutionQueryFilter(SpmInstitution.Params prm)
|
||||
{
|
||||
List<String> filter = new List<String>();
|
||||
|
||||
// Institution Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filter.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Id, aliasInstitution) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filter.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Id, aliasInstitution) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Name.
|
||||
String colInstitution_Name = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Name, aliasInstitution);
|
||||
if (!StringUtil.IsEmpty(prm.Name))
|
||||
filter.Add(colInstitution_Name + "='" + DbQuery.FormatForCondition(prm.Name) + "'");
|
||||
if (!StringUtil.IsEmpty(prm.NamePartial))
|
||||
filter.Add(colInstitution_Name + " LIKE '%" + DbQuery.FormatForLike(prm.NamePartial) + "%'");
|
||||
|
||||
// Notes.
|
||||
String colInstitution_Notes = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Notes, aliasInstitution);
|
||||
if (!StringUtil.IsEmpty(prm.NotesPartial))
|
||||
filter.Add(colInstitution_Notes + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'");
|
||||
|
||||
// Status.
|
||||
if (prm.StatusCat == SpmInstitution.StatusCat.Any)
|
||||
filter.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Status, aliasInstitution) + " = '" + SacsSystem.GetStatusCode(SaStatus.Any) + "'");
|
||||
|
||||
|
||||
if (filter.Count < 1) filter.Add("1=1");
|
||||
return filter;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution sort columns.
|
||||
public List<String> GetInstitutionSortColumns(SpmInstitution.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Institution columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmInstitution)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasInstitution);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Type, aliasInstitution) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution count.
|
||||
private long GetInstitutionCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmInstitution) + " As " + aliasInstitution, filter);
|
||||
}
|
||||
public override long GetInstitutionCount(SpmInstitution.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetInstitutionCount(GetInstitutionQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution list.
|
||||
public override List<SpmInstitution> GetInstitutionList(SpmInstitution.Params prm)
|
||||
{
|
||||
List<SpmInstitution> Institutiones = new List<SpmInstitution>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmInstitution), aliasInstitution);
|
||||
qry.Columns.AddRange(SwmInstitution_Db.Fields);
|
||||
qry.Filters.AddRange(GetInstitutionQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmInstitution_Db dbInstitution = new SwmInstitution_Db(DbInfo);
|
||||
dbInstitution.PopulateFrom(dbDataReader);
|
||||
Institutiones.Add(CreateInstitution(dbInstitution));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetInstitutionList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Institutiones;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Institution query execution.
|
||||
public override DbResultSet ExecuteInstitutionQuery(List<ColumnDfn> columns, SpmInstitution.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmInstitution), aliasInstitution);
|
||||
|
||||
// Institution Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmInstitution.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Id, aliasInstitution));
|
||||
if (columns.HasId((int)SpmInstitution.Column.Name))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Name, aliasInstitution));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmInstitution.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Notes, aliasInstitution));
|
||||
if (columns.HasId((int)SpmInstitution.Column.Status) || columns.HasId((int)SpmInstitution.Column.Status_Desc) || columns.HasId((int)SpmInstitution.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_Status, aliasInstitution));
|
||||
if (columns.HasId((int)SpmInstitution.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_CreateOn, aliasInstitution));
|
||||
if (columns.HasId((int)SpmInstitution.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmInstitution_UpdateOn, aliasInstitution));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetInstitutionQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetInstitutionSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetInstitutionDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmInstitution.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmInstitution.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmInstitution.Column.Status_Desc:
|
||||
case SpmInstitution.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmInstitution.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmInstitution.Column.Status_Ind)
|
||||
value = new DataValue(SpmInstitution.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmInstitutionMgr_Dbas : SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// O p e r a t i o n
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation exists.
|
||||
public override bool OperationExistsById(SysId operationId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(operationId)) return false;
|
||||
SpmOperation.Params prmOperation = new SpmOperation.Params();
|
||||
prmOperation.IncludedIds.Add(operationId);
|
||||
prmOperation.StatusCat = SpmOperation.StatusCat.Any;
|
||||
return GetOperationCount(prmOperation) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Operation.
|
||||
public override SpmOperation GetOperation(SpmOperation.Params prm)
|
||||
{
|
||||
return GetOperation(GetOperationQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmOperation GetOperation(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetOperationCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Operationes found");
|
||||
return null;
|
||||
}
|
||||
SpmOperation operation = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmOperation_Db dbOperation = new SwmOperation_Db(DbInfo);
|
||||
dbOperation.PopulateFrom(dbCommand, aliasOperation, filter);
|
||||
operation = CreateOperation(dbOperation);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetOperation\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
public override SpmOperation GetOperationById(SysId operationId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(operationId)) return null;
|
||||
SpmOperation.Params prmOperation = new SpmOperation.Params();
|
||||
prmOperation.IncludedIds.Add(operationId);
|
||||
prmOperation.StatusCat = SpmOperation.StatusCat.Any;
|
||||
return GetOperation(prmOperation);
|
||||
}
|
||||
public override SpmOperation GetOperationByCode(String code)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!StringUtil.IsEmpty(code)) return null;
|
||||
SpmOperation.Params prmOperation = new SpmOperation.Params();
|
||||
prmOperation.CodePartial = code;
|
||||
prmOperation.StatusCat = SpmOperation.StatusCat.Any;
|
||||
return GetOperation(prmOperation);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Operation.
|
||||
public override SpmOperation CreateOperation(SysId departmentId, SysId institutionId)
|
||||
{
|
||||
return new SpmOperation_Dbas(UserContext, departmentId, institutionId, 0);
|
||||
}
|
||||
private SpmOperation_Dbas CreateOperation(SwmOperation_Db dbOperation)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmOperation_Dbas operation = new SpmOperation_Dbas(UserContext, new SysId(0), new SysId(dbOperation._InstitutionId), (ushort)dbOperation._Flags);
|
||||
PopulateFrom(dbOperation, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Operation.
|
||||
public override bool IsValidOperationData(SpmOperation.Data data, SpmOperation.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidOperationData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Operation.
|
||||
public override bool InsertOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidOperation(operation)) return false;
|
||||
if (SysId.IsValid(operation.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmOperation_Db dbOperation = new SwmOperation_Db(DbInfo);
|
||||
PopulateTo(dbOperation, operation, dbUpdateInfo);
|
||||
if (SwmOperation_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbOperation._Id = SysId.ToInt(db.GetNextId("Operation", dbUpdateInfo));
|
||||
}
|
||||
dbOperation.ExecuteInsertCommand(dbCommand);
|
||||
operation.Id = new SysId(dbOperation._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Operation.
|
||||
public override bool UpdateOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidOperation(operation)) return false;
|
||||
if (!SysId.IsValid(operation.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Operation.
|
||||
dbConnection.Open();
|
||||
SwmOperation_Db dbOperation = new SwmOperation_Db(DbInfo);
|
||||
dbOperation.PopulateFrom(dbCommand, aliasOperation, "Id=" + SysId.ToString(operation.Id));
|
||||
//SpmUpdateLogItemMonitor_Operation updateLogMonitor = new SpmUpdateLogItemMonitor_Operation(UserContext, CreateOperation(dbOperation));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbOperation, operation, dbUpdateInfo);
|
||||
dbOperation.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(operation);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Operation.
|
||||
public override bool OperationCanBeDeleted(SpmOperation operation)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.OperationCanBeDeleted(operation)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeleteOperation(SpmOperation operation, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!OperationCanBeDeleted(operation)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Operation.
|
||||
dbConnection.Open();
|
||||
SwmOperation_Db dbOperation = new SwmOperation_Db(DbInfo);
|
||||
dbOperation.PopulateFrom(dbCommand, aliasOperation, "Id=" + operation.Id.ToString());
|
||||
// Delete Operation.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmOperation) + " WHERE Id=" + SysId.ToString(operation.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmOperation_Db dbOperation, SpmOperation operation, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbOperation._Id = operation.Id.ToInt();
|
||||
dbOperation._Code = operation.Code;
|
||||
dbOperation._Description = operation.Description;
|
||||
|
||||
dbOperation._Notes = operation.Notes;
|
||||
dbOperation._Status = SacsSystem.GetStatusCode(operation.Status);
|
||||
dbOperation._Flags = (short)operation.Flags;
|
||||
if (!SysId.IsValid(operation.Id))
|
||||
{
|
||||
dbOperation._CreateOn = DateTime.UtcNow;
|
||||
dbOperation._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbOperation._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbOperation._UpdateOn = DateTime.UtcNow;
|
||||
dbOperation._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbOperation._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmOperation_Db dbOperation, SpmOperation operation)
|
||||
{
|
||||
operation.Id = new SysId(dbOperation._Id);
|
||||
operation.Code = dbOperation._Code;
|
||||
operation.Description = dbOperation._Description;
|
||||
|
||||
operation.Notes = dbOperation._Notes;
|
||||
operation.Status = SacsSystem.GetStatusForCode(dbOperation._Status);
|
||||
operation.SetCreateStamp(dbOperation._CreateOn, new SysId(dbOperation._CreateBy), dbOperation._CreateHost);
|
||||
operation.SetUpdateStamp(dbOperation._UpdateOn, new SysId(dbOperation._UpdateBy), dbOperation._UpdateHost);
|
||||
operation.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation column definitions.
|
||||
private static readonly String aliasOperation = "aOper";
|
||||
private void SetOperationColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmOperation)
|
||||
alias = aliasOperation;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmOperation column definition.
|
||||
public override ColumnDfn GetOperationColumnDfn(SpmOperation.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmOperation.Column.Pos:
|
||||
SetOperationColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmOperation.Column.Id:
|
||||
SetOperationColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmOperation_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Operation Properties.
|
||||
case SpmOperation.Column.InstitutionId:
|
||||
SetOperationColDfn(columnDfn, "InstitutionId", 40, SpmDbDfn.ColumnIdx.SwmOperation_InstitutionId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmOperation.Column.Code:
|
||||
SetOperationColDfn(columnDfn, "Code", 60, SpmDbDfn.ColumnIdx.SwmOperation_Code, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
case SpmOperation.Column.Description:
|
||||
SetOperationColDfn(columnDfn, "Description", 60, SpmDbDfn.ColumnIdx.SwmOperation_Description, ColumnAlignment.Center, DataValue.DataType.String);
|
||||
break;
|
||||
|
||||
// Derived properties.
|
||||
|
||||
// Common properties.
|
||||
case SpmOperation.Column.Notes:
|
||||
SetOperationColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmOperation_Notes);
|
||||
break;
|
||||
case SpmOperation.Column.Status:
|
||||
SetOperationColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmOperation_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmOperation.Column.Status_Desc:
|
||||
SetOperationColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmOperation_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmOperation.Column.Status_Ind:
|
||||
SetOperationColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmOperation_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmOperation.Column.CreateOn_Date:
|
||||
SetOperationColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmOperation_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmOperation.Column.UpdateOn_Date:
|
||||
SetOperationColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmOperation_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation query filter.
|
||||
public override List<string> GetOperationQueryFilter(SpmOperation.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Operation Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Id, aliasOperation) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Id, aliasOperation) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Institution Id.
|
||||
String colInstitutionId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_InstitutionId, aliasOperation);
|
||||
if (SysId.IsValid(prm.InstitutionId))
|
||||
filters.Add(colInstitutionId + "=" + prm.InstitutionId.ToString());
|
||||
|
||||
// Code Partial.
|
||||
String colCode = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Code, aliasOperation);
|
||||
String codePartial = DbQuery.FormatForCondition(prm.CodePartial);
|
||||
if (!StringUtil.IsEmpty(codePartial))
|
||||
filters.Add(DbQuery.FormatFn_Left(colCode, codePartial.Length) + "='" + codePartial + "'");
|
||||
|
||||
// Description Partial.
|
||||
String colDesc = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Description, aliasOperation);
|
||||
String descPartial = DbQuery.FormatForCondition(prm.DescriptionPartial);
|
||||
if (!StringUtil.IsEmpty(descPartial))
|
||||
filters.Add(DbQuery.FormatFn_Left(colDesc, descPartial.Length) + "='" + descPartial + "'");
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation sort columns.
|
||||
public List<String> GetOperationSortColumns(SpmOperation.Params prm)
|
||||
{
|
||||
// Sort sequence:
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Operation columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmOperation)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasOperation);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Type, aliasOperation) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation count.
|
||||
private long GetOperationCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmOperation) + " As " + aliasOperation, filter);
|
||||
}
|
||||
public override long GetOperationCount(SpmOperation.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetOperationCount(GetOperationQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation list.
|
||||
public override List<SpmOperation> GetOperationList(SpmOperation.Params prm)
|
||||
{
|
||||
List<SpmOperation> Operationes = new List<SpmOperation>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmOperation), aliasOperation);
|
||||
qry.Columns.AddRange(SwmOperation_Db.Fields);
|
||||
qry.Filters.AddRange(GetOperationQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmOperation_Db dbOperation = new SwmOperation_Db(DbInfo);
|
||||
dbOperation.PopulateFrom(dbDataReader);
|
||||
Operationes.Add(CreateOperation(dbOperation));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetOperationList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Operationes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Operation query execution.
|
||||
public override DbResultSet ExecuteOperationQuery(List<ColumnDfn> columns, SpmOperation.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmOperation), aliasOperation);
|
||||
|
||||
// Operation Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmOperation.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Id, aliasOperation));
|
||||
if (columns.HasId((int)SpmOperation.Column.Code))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Code, aliasOperation));
|
||||
if (columns.HasId((int)SpmOperation.Column.Description))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Description, aliasOperation));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmOperation.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Notes, aliasOperation));
|
||||
if (columns.HasId((int)SpmOperation.Column.Status) || columns.HasId((int)SpmOperation.Column.Status_Desc) || columns.HasId((int)SpmOperation.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_Status, aliasOperation));
|
||||
if (columns.HasId((int)SpmOperation.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_CreateOn, aliasOperation));
|
||||
if (columns.HasId((int)SpmOperation.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmOperation_UpdateOn, aliasOperation));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetOperationQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetOperationSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetOperationDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmOperation.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmOperation.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmOperation.Column.Status_Desc:
|
||||
case SpmOperation.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmOperation.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmOperation.Column.Status_Ind)
|
||||
value = new DataValue(SpmOperation.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,549 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sarand.Core.App;
|
||||
using Sarand.Core.Base;
|
||||
using Sarand.Core.Bus;
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Bus;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Bus;
|
||||
using Sarand.PatientMgr.Win.Dbas.Internal;
|
||||
//using Sarand.PatientMgr.Win.Dbas.UpdateLog;
|
||||
using Sarand.Win.Dbas.Data;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmInstitutionMgr_Dbas : SpmInstitutionMgr
|
||||
{
|
||||
//*******************************************************************
|
||||
// P a t i e n t
|
||||
//*******************************************************************
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient exists.
|
||||
public override bool PatientExistsById(SysId admissionActionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionActionId)) return false;
|
||||
SpmPatient.Params prmPatient = new SpmPatient.Params();
|
||||
prmPatient.IncludedIds.Add(admissionActionId);
|
||||
prmPatient.StatusCat = SpmPatient.StatusCat.Any;
|
||||
return GetPatientCount(prmPatient) == 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get Patient.
|
||||
public override SpmPatient GetPatient(SpmPatient.Params prm)
|
||||
{
|
||||
return GetPatient(GetPatientQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
private SpmPatient GetPatient(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
long count = GetPatientCount(filter);
|
||||
if (count == 0) return null;
|
||||
if (count != 1)
|
||||
{
|
||||
SetErrorState("Multiple Patientes found");
|
||||
return null;
|
||||
}
|
||||
SpmPatient admissionAction = null;
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmPatient_Db dbPatient = new SwmPatient_Db(DbInfo);
|
||||
dbPatient.PopulateFrom(dbCommand, aliasPatient, filter);
|
||||
admissionAction = CreatePatient(dbPatient);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState("Database query exception");
|
||||
Logger.Warn(GetType().Name + ".GetPatient\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return admissionAction;
|
||||
}
|
||||
public override SpmPatient GetPatientById(SysId admissionActionId)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(admissionActionId)) return null;
|
||||
SpmPatient.Params prmPatient = new SpmPatient.Params();
|
||||
prmPatient.IncludedIds.Add(admissionActionId);
|
||||
prmPatient.StatusCat = SpmPatient.StatusCat.Any;
|
||||
return GetPatient(prmPatient);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create Patient.
|
||||
public override SpmPatient CreatePatient(SysId id, SysId institutionId)
|
||||
{
|
||||
return new SpmPatient_Dbas(UserContext, id, institutionId, 0);
|
||||
}
|
||||
private SpmPatient_Dbas CreatePatient(SwmPatient_Db dbPatient)
|
||||
{
|
||||
ClearErrorState();
|
||||
SpmPatient_Dbas admissionAction = new SpmPatient_Dbas(UserContext, new SysId(dbPatient._Id), new SysId(dbPatient._InstitutionId), (ushort)dbPatient._Flags);
|
||||
PopulateFrom(dbPatient, admissionAction);
|
||||
return admissionAction;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Validate Patient.
|
||||
public override bool IsValidPatientData(SpmPatient.Data data, SpmPatient.ErrField errField)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.IsValidPatientData(data, errField)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Insert Patient.
|
||||
public override bool InsertPatient(SpmPatient admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidPatient(admissionAction)) return false;
|
||||
if (SysId.IsValid(admissionAction.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
SwmPatient_Db dbPatient = new SwmPatient_Db(DbInfo);
|
||||
PopulateTo(dbPatient, admissionAction, dbUpdateInfo);
|
||||
if (SwmPatient_Db.FieldsNonId.Contains("Id"))
|
||||
{
|
||||
// Generate next Id.
|
||||
dbPatient._Id = SysId.ToInt(db.GetNextId("Patient", dbUpdateInfo));
|
||||
}
|
||||
dbPatient.ExecuteInsertCommand(dbCommand);
|
||||
admissionAction.Id = new SysId(dbPatient._Id);
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Update Patient.
|
||||
public override bool UpdatePatient(SpmPatient admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!IsValidPatient(admissionAction)) return false;
|
||||
if (!SysId.IsValid(admissionAction.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Patient.
|
||||
dbConnection.Open();
|
||||
SwmPatient_Db dbPatient = new SwmPatient_Db(DbInfo);
|
||||
dbPatient.PopulateFrom(dbCommand, aliasPatient, "Id=" + SysId.ToString(admissionAction.Id));
|
||||
//SpmUpdateLogItemMonitor_Patient updateLogMonitor = new SpmUpdateLogItemMonitor_Patient(UserContext, CreatePatient(dbPatient));
|
||||
|
||||
// Update properties.
|
||||
PopulateTo(dbPatient, admissionAction, dbUpdateInfo);
|
||||
dbPatient.ExecuteUpdateCommand(dbCommand);
|
||||
|
||||
/* Record updates.
|
||||
updateLogMonitor.RecordUpdatedValues(admissionAction);
|
||||
updateLogMonitor.LogUpdates();*/
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Delete Patient.
|
||||
public override bool PatientCanBeDeleted(SpmPatient admissionAction)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!base.PatientCanBeDeleted(admissionAction)) return false;
|
||||
return true;
|
||||
}
|
||||
public override bool DeletePatient(SpmPatient admissionAction, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!PatientCanBeDeleted(admissionAction)) return false;
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve Patient.
|
||||
dbConnection.Open();
|
||||
SwmPatient_Db dbPatient = new SwmPatient_Db(DbInfo);
|
||||
dbPatient.PopulateFrom(dbCommand, aliasPatient, "Id=" + admissionAction.Id.ToString());
|
||||
// Delete Patient.
|
||||
dbCommand.CommandType = System.Data.CommandType.Text;
|
||||
dbCommand.CommandText = "DELETE FROM " + SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmPatient) + " WHERE Id=" + SysId.ToString(admissionAction.Id) + ";";
|
||||
dbCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception exc) { SetErrorState(exc.Message); }
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Copy data properties to and from database.
|
||||
private void PopulateTo(SwmPatient_Db dbPatient, SpmPatient patient, DbUpdateInfo dbUpdateInfo)
|
||||
{
|
||||
dbPatient._Id = patient.Id.ToInt();
|
||||
dbPatient._PatientNo = patient.PatientNo;
|
||||
dbPatient._NhsNumber = patient.NhsNumber;
|
||||
dbPatient._Title = patient.Title;
|
||||
dbPatient._Forename = patient.Forename;
|
||||
dbPatient._Surname = patient.Surname;
|
||||
dbPatient._Gender = (short)patient.Gender;
|
||||
dbPatient._Age = patient.Age;
|
||||
dbPatient._AgeOn = patient.AgeOn;
|
||||
dbPatient._BirthOn = patient.BirthOn.DateToInt32();
|
||||
|
||||
dbPatient._Notes = patient.Notes;
|
||||
dbPatient._Status = SacsSystem.GetStatusCode(patient.Status);
|
||||
dbPatient._Flags = (short)patient.Flags;
|
||||
if (!SysId.IsValid(patient.Id))
|
||||
{
|
||||
dbPatient._CreateOn = DateTime.UtcNow;
|
||||
dbPatient._CreateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbPatient._CreateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
dbPatient._UpdateOn = DateTime.UtcNow;
|
||||
dbPatient._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
||||
dbPatient._UpdateHost = dbUpdateInfo.Host;
|
||||
}
|
||||
private void PopulateFrom(SwmPatient_Db dbPatient, SpmPatient patient)
|
||||
{
|
||||
patient.Id = new SysId(dbPatient._Id);
|
||||
patient.PatientNo = dbPatient._PatientNo;
|
||||
patient.NhsNumber = dbPatient._NhsNumber;
|
||||
patient.Title = dbPatient._Title;
|
||||
patient.Forename = dbPatient._Forename;
|
||||
patient.Surname = dbPatient._Surname;
|
||||
patient.Gender = (Spm.Gender)dbPatient._Gender;
|
||||
patient.Age = dbPatient._Age;
|
||||
patient.AgeOn = dbPatient._AgeOn;
|
||||
patient.BirthOn = new DateTime(dbPatient._BirthOn);
|
||||
|
||||
patient.Notes = dbPatient._Notes;
|
||||
patient.Status = SacsSystem.GetStatusForCode(dbPatient._Status);
|
||||
patient.SetCreateStamp(dbPatient._CreateOn, new SysId(dbPatient._CreateBy), dbPatient._CreateHost);
|
||||
patient.SetUpdateStamp(dbPatient._UpdateOn, new SysId(dbPatient._UpdateBy), dbPatient._UpdateHost);
|
||||
patient.AcceptChanges();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient column definitions.
|
||||
private static readonly String aliasPatient = "aAdmAct";
|
||||
private void SetPatientColDfn
|
||||
(ColumnDfn col, String caption, int width, SpmDbDfn.ColumnIdx dbCol,
|
||||
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
||||
String alias = "", String prefix = "")
|
||||
{
|
||||
if (String.IsNullOrEmpty(alias) && SpmDbDfn.GetTableForColumn(dbCol) == SpmDbDfn.TableIdx.SwmPatient)
|
||||
alias = aliasPatient;
|
||||
col.Set(caption, width, (int)dbCol, prefix + SpmDbDfn.GetColumnName(dbCol, false), SpmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
||||
if (dataType == DataValue.DataType.String && dbCol != SpmDbDfn.ColumnIdx.Unknown)
|
||||
col.MaxLength = (int)SpmDbDfn.GetColTextLen(dbCol);
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Getting prmPatient column definition.
|
||||
public override ColumnDfn GetPatientColumnDfn(SpmPatient.Column columnId, string caption = "", int width = 0)
|
||||
{
|
||||
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
||||
switch (columnId)
|
||||
{
|
||||
case SpmPatient.Column.Pos:
|
||||
SetPatientColDfn(columnDfn, "Pos", 42, SpmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
||||
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
||||
columnDfn.ReadOnly = true;
|
||||
columnDfn.Resizable = false;
|
||||
break;
|
||||
case SpmPatient.Column.Id:
|
||||
SetPatientColDfn(columnDfn, "Id", 40, SpmDbDfn.ColumnIdx.SwmPatient_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
|
||||
// Patient Properties.
|
||||
case SpmPatient.Column.InstitutionId:
|
||||
SetPatientColDfn(columnDfn, "InstitutionId", 40, SpmDbDfn.ColumnIdx.SwmPatient_InstitutionId, ColumnAlignment.Right, DataValue.DataType.Long);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmPatient.Column.Title:
|
||||
SetPatientColDfn(columnDfn, "Title", 90, SpmDbDfn.ColumnIdx.SwmPatient_Title);
|
||||
break;
|
||||
case SpmPatient.Column.Surname:
|
||||
SetPatientColDfn(columnDfn, "Surname", 90, SpmDbDfn.ColumnIdx.SwmPatient_Surname);
|
||||
break;
|
||||
case SpmPatient.Column.Forename:
|
||||
SetPatientColDfn(columnDfn, "Forename", 90, SpmDbDfn.ColumnIdx.SwmPatient_Forename);
|
||||
break;
|
||||
case SpmPatient.Column.BirthOn:
|
||||
SetPatientColDfn(columnDfn, "DOB", 75, SpmDbDfn.ColumnIdx.SwmPatient_BirthOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "dd-MMM-yyyy";
|
||||
break;
|
||||
case SpmPatient.Column.Age:
|
||||
SetPatientColDfn(columnDfn, "Age", 40, SpmDbDfn.ColumnIdx.SwmPatient_Age, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmPatient.Column.AgeOn:
|
||||
SetPatientColDfn(columnDfn, "AgeOn", 75, SpmDbDfn.ColumnIdx.SwmPatient_AgeOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.DateFormat = "d-MMM-yy";
|
||||
break;
|
||||
|
||||
// Common properties.
|
||||
case SpmPatient.Column.Notes:
|
||||
SetPatientColDfn(columnDfn, "Notes", 200, SpmDbDfn.ColumnIdx.SwmPatient_Notes);
|
||||
break;
|
||||
case SpmPatient.Column.Status:
|
||||
SetPatientColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmPatient_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmPatient.Column.Status_Desc:
|
||||
SetPatientColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmPatient_Status, ColumnAlignment.Center);
|
||||
break;
|
||||
case SpmPatient.Column.Status_Ind:
|
||||
SetPatientColDfn(columnDfn, "Status", 50, SpmDbDfn.ColumnIdx.SwmPatient_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
||||
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
||||
break;
|
||||
case SpmPatient.Column.CreateOn_Date:
|
||||
SetPatientColDfn(columnDfn, "Created", 65, SpmDbDfn.ColumnIdx.SwmPatient_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
case SpmPatient.Column.UpdateOn_Date:
|
||||
SetPatientColDfn(columnDfn, "Updated", 65, SpmDbDfn.ColumnIdx.SwmPatient_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
||||
columnDfn.ReadOnly = true;
|
||||
break;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(caption))
|
||||
columnDfn.Caption = caption;
|
||||
if (width > 0)
|
||||
columnDfn.Width = width;
|
||||
return columnDfn;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient query filter.
|
||||
public override List<string> GetPatientQueryFilter(SpmPatient.Params prm)
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
|
||||
// Patient Id.
|
||||
String includedIds = prm.IncludedIds.Concat(",");
|
||||
if (!includedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Id, aliasPatient) + " IN (" + includedIds + ")");
|
||||
String excludedIds = prm.ExcludedIds.Concat(",");
|
||||
if (!excludedIds.IsEmpty())
|
||||
filters.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Id, aliasPatient) + " NOT IN (" + excludedIds + ")");
|
||||
|
||||
// Institution Id.
|
||||
String colInstitutionId = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_InstitutionId, aliasPatient);
|
||||
if (SysId.IsValid(prm.InstitutionId))
|
||||
filters.Add(colInstitutionId + "=" + prm.InstitutionId.ToString());
|
||||
|
||||
// Partial No.
|
||||
String patientNo = DbQuery.FormatForCondition(prm.PatientNo);
|
||||
String colPatientNo = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_PatientNo, aliasPatient);
|
||||
if (!StringUtil.IsEmpty(patientNo))
|
||||
filters.Add(DbQuery.FormatFn_Left(colPatientNo, prm.PatientNo.Length) + "='" + patientNo + "'");
|
||||
|
||||
// Partial Surname.
|
||||
String surname = DbQuery.FormatForCondition(prm.Surname);
|
||||
String colSurname = SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Surname, aliasPatient);
|
||||
if (!StringUtil.IsEmpty(surname))
|
||||
filters.Add(DbQuery.FormatFn_Left(colSurname, prm.Surname.Length) + "='" + surname + "'");
|
||||
|
||||
if (filters.Count < 1) filters.Add("1=1");
|
||||
return filters;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient sort columns.
|
||||
public List<String> GetPatientSortColumns(SpmPatient.Params prm)
|
||||
{
|
||||
// Sort sequence.
|
||||
List<String> sortColumnNames = new List<String>();
|
||||
foreach (var columnDfn in prm.SortColumns)
|
||||
{
|
||||
// Need to ensure correct alias used for Patient columns in case of conflict.
|
||||
String sortCol = String.Empty;
|
||||
if (SpmDbDfn.GetTableForColumn((SpmDbDfn.ColumnIdx)columnDfn.DbColumn) == SpmDbDfn.TableIdx.SwmPatient)
|
||||
{
|
||||
sortCol = SpmDbDfn.GetColumnNameQual((SpmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasPatient);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortCol = columnDfn.DataName;
|
||||
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
||||
sortCol = columnDfn.SortDataName;
|
||||
}
|
||||
if (!sortCol.IsEmpty())
|
||||
{
|
||||
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
||||
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
||||
}
|
||||
}
|
||||
sortColumnNames.RemoveBlanks();
|
||||
if (sortColumnNames.IsEmpty())
|
||||
{
|
||||
// Default sort columns:
|
||||
//sortColumnNames.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Type, aliasPatient) + " ASC");
|
||||
}
|
||||
return sortColumnNames;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient count.
|
||||
private long GetPatientCount(String filter)
|
||||
{
|
||||
ClearErrorState();
|
||||
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmPatient) + " As " + aliasPatient, filter);
|
||||
}
|
||||
public override long GetPatientCount(SpmPatient.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
return GetPatientCount(GetPatientQueryFilter(prm).Concat(" AND ", "(", ")"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient list.
|
||||
public override List<SpmPatient> GetPatientList(SpmPatient.Params prm)
|
||||
{
|
||||
List<SpmPatient> Patientes = new List<SpmPatient>();
|
||||
DbQuery qry = new DbQuery(db.DbmsType);
|
||||
qry.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmPatient), aliasPatient);
|
||||
qry.Columns.AddRange(SwmPatient_Db.Fields);
|
||||
qry.Filters.AddRange(GetPatientQueryFilter(prm));
|
||||
// Query data.
|
||||
using (var dbConnection = db.CreateConnection())
|
||||
using (var dbCommand = dbConnection.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbConnection.Open();
|
||||
dbCommand.CommandText = qry.BuildQuery();
|
||||
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
||||
{
|
||||
while (dbDataReader.Read())
|
||||
{
|
||||
SwmPatient_Db dbPatient = new SwmPatient_Db(DbInfo);
|
||||
dbPatient.PopulateFrom(dbDataReader);
|
||||
Patientes.Add(CreatePatient(dbPatient));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Logger.Warn(GetType().Name + ".GetPatientList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
||||
}
|
||||
}
|
||||
return Patientes;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Patient query execution.
|
||||
public override DbResultSet ExecutePatientQuery(List<ColumnDfn> columns, SpmPatient.Params prm)
|
||||
{
|
||||
ClearErrorState();
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Construct query.
|
||||
DbQuery query = new DbQuery(db.DbmsType);
|
||||
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmPatient), aliasPatient);
|
||||
|
||||
// Patient Properties - add columns as defined in query list.
|
||||
if (columns.HasId((int)SpmPatient.Column.Id))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Id, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.InstitutionId))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_InstitutionId, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.PatientNo))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_PatientNo, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.NhsNumber))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_NhsNumber, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.Title))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Title, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.Forename))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Forename, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.Surname))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Surname, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.BirthOn))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_BirthOn, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.Age))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Age, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.AgeOn))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_AgeOn, aliasPatient));
|
||||
|
||||
// Common Properties
|
||||
if (columns.HasId((int)SpmPatient.Column.Notes))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Notes, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.Status) || columns.HasId((int)SpmPatient.Column.Status_Desc) || columns.HasId((int)SpmPatient.Column.Status_Ind))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_Status, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.CreateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_CreateOn, aliasPatient));
|
||||
if (columns.HasId((int)SpmPatient.Column.UpdateOn_Date))
|
||||
query.Columns.Add(SpmDbDfn.GetColumnNameQual(SpmDbDfn.ColumnIdx.SwmPatient_UpdateOn, aliasPatient));
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Populate filter.
|
||||
query.Filters.AddRange(GetPatientQueryFilter(prm));
|
||||
|
||||
if (prm.IncludedIds.Count != 1)
|
||||
{
|
||||
// Configure sort sequence.
|
||||
foreach (String sortColumn in GetPatientSortColumns(prm))
|
||||
query.OrderBy.Add(sortColumn);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
||||
return new Sarand.Win.Dbas.Data.DbResultSet_DataReader(db, query.BuildQuery());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public override DataValue GetPatientDataValue(ColumnDfn column, NamedValue.Map values)
|
||||
{
|
||||
DataValue value = new DataValue();
|
||||
switch ((SpmPatient.Column)column.Id)
|
||||
{
|
||||
// Notes.
|
||||
case SpmPatient.Column.Notes:
|
||||
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
||||
break;
|
||||
|
||||
// Status.
|
||||
case SpmPatient.Column.Status_Desc:
|
||||
case SpmPatient.Column.Status_Ind:
|
||||
{
|
||||
String statusCode = values.GetValue(column.DataName).ToString();
|
||||
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
||||
if (column.Id == (int)SpmPatient.Column.Status_Desc)
|
||||
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
||||
else if (column.Id == (int)SpmPatient.Column.Status_Ind)
|
||||
value = new DataValue(SpmPatient.GetStatusTriState(status));
|
||||
}
|
||||
break;
|
||||
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Sarand.Core.Dbas.Base;
|
||||
using Sarand.PatientMgr.Core.App;
|
||||
using Sarand.PatientMgr.Core.Mgr;
|
||||
using Sarand.PatientMgr.Win.Dbas.Data;
|
||||
using Sarand.Win.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.PatientMgr.Win.Dbas.Mgr
|
||||
{
|
||||
//=======================================================================
|
||||
internal partial class SpmInstitutionMgr_Dbas : SpmInstitutionMgr
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SacsDatabase db = null;
|
||||
private readonly SpmDbDataItem.DatabaseInfo dbInfo;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SpmInstitutionMgr_Dbas (SpmUserContext userContext) :
|
||||
base(userContext)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected ISacsDatabase Database { get { return db; } }
|
||||
protected SpmDbDataItem.DatabaseInfo DbInfo { get { return dbInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user