126 lines
5.8 KiB
C#
126 lines
5.8 KiB
C#
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;
|
|
using Sarand.Core.Base;
|
|
using Sarand.Win.Dbas.Data;
|
|
using Sarand.Win.Dbas.Base;
|
|
|
|
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.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
public override bool HasTemplates()
|
|
{
|
|
ClearErrorState();
|
|
if (SysId.IsValid(Id)) return false;
|
|
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
|
if (db == null) SetErrorState("database unavailable");
|
|
List<String> filters = new List<String>();
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_FacilityId) + "=" + Id.ToString());
|
|
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate), filters.Concat(" AND ", "(", ")")) > 0;
|
|
}
|
|
public override bool HasSessions()
|
|
{
|
|
DateTime? earliest = null, latest = null;
|
|
return HasSessions(DateTime.MinValue, DateTime.MinValue, ref earliest, ref latest);
|
|
}
|
|
public override bool HasSessionsBefore(DateTime target, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
return HasSessions(DateTime.MinValue, DateTime.MinValue, ref earliest, ref latest);
|
|
}
|
|
public override bool HasSessionsAfter(DateTime target, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
return HasSessions(DateTime.MinValue, DateTime.MinValue, ref earliest, ref latest);
|
|
}
|
|
public override bool HasSessions(DateTime before, DateTime after, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
ClearErrorState();
|
|
if (SysId.IsValid(Id)) return false;
|
|
SacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext) as SacsDatabase;
|
|
if (db == null) SetErrorState("database unavailable");
|
|
long countSession = 0;
|
|
|
|
// Filter to identify matching Sessions:
|
|
// FacilitySession.FacilityTemplateId = Template belonging to this facility (via sub query).
|
|
// FacilitySession.Session > Before date if specified.
|
|
// FacilitySession.Session > After date if specified.
|
|
List<String> filters = new List<String>();
|
|
DbQuery query = new DbQuery(db != null ? db.DbmsType : DbmsType.General);
|
|
query.Tables.Add(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilityTemplate));
|
|
query.Columns.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_Id));
|
|
query.Filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilityTemplate_FacilityId) + "=" + Id.ToString());
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilitySession_FacilityTemplateId) + " IN (" + query.BuildQuery() + ")");
|
|
if (DateUtil.IsValid(before))
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilitySession_Session) + "<" + DbQuery.FormatDateForCondition(before));
|
|
if (DateUtil.IsValid(after))
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacilitySession_Session) + ">" + DbQuery.FormatDateForCondition(after));
|
|
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacilitySession), filters.Concat(" AND ", "(", ")")) > 0;
|
|
}
|
|
public override bool HasAdmissions(Spm.AdmissionCancelType cancelType)
|
|
{
|
|
DateTime? earliest = null, latest = null;
|
|
return HasAdmissions(DateTime.MinValue, DateTime.MinValue, cancelType, ref earliest, ref latest);
|
|
}
|
|
public override bool HasAdmissionsBefore(DateTime target, Spm.AdmissionCancelType cancelType, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
return HasAdmissions(DateTime.MinValue, DateTime.MinValue, cancelType, ref earliest, ref latest);
|
|
}
|
|
public override bool HasAdmissionsAfter(DateTime target, Spm.AdmissionCancelType cancelType, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
return HasAdmissions(DateTime.MinValue, DateTime.MinValue, cancelType, ref earliest, ref latest);
|
|
}
|
|
public override bool HasAdmissions(DateTime before, DateTime after, Spm.AdmissionCancelType cancelType, ref DateTime? earliest, ref DateTime? latest)
|
|
{
|
|
ClearErrorState();
|
|
if (SysId.IsValid(Id)) return false;
|
|
SacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext) as SacsDatabase;
|
|
if (db == null) SetErrorState("database unavailable");
|
|
DbQuery query = new DbQuery(db.DbmsType);
|
|
|
|
// Filter to identify matching Admissions.
|
|
SpmAdmission.Params prmAdm = new SpmAdmission.Params();
|
|
prmAdm.FacilityTemplateId = Id;
|
|
prmAdm.AdmissionFrom = after.AddDays(1);
|
|
prmAdm.AdmissionTo = before.AddDays(-1);
|
|
SpmAdmissionMgr admissionMgr = SpmGlobals.System.CreateAdmissionMgr(userContext);
|
|
List<String> filters = new List<String>(admissionMgr.GetAdmissionQueryFilter(prmAdm));
|
|
return db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmAdmission), filters.Concat(" AND ", "(", ")")) > 0;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|