290 lines
11 KiB
C#
290 lines
11 KiB
C#
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;
|
|
|
|
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.
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 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;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|