78 lines
2.9 KiB
C#
78 lines
2.9 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 SpmDepartment_Dbas : SpmDepartment
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SpmUserContext userContext;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SpmDepartment_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.
|
|
|
|
//-------------------------------------------------------------------
|
|
// A s s o c i a t e d D a t a E l e m e n t s
|
|
//-------------------------------------------------------------------
|
|
public override int GetFacilityCount (Spm.FacilityType facilityType)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(Id)) { SetErrorState("invalid department"); return 0; }
|
|
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
|
if (db == null) { SetErrorState("database unavailable"); return 0; }
|
|
|
|
// Build query filter.
|
|
List<String> filters = new List<String>();
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacility_DepartmentId) + "=" + Id.ToString());
|
|
if (facilityType > 0) filters.Add(" AND " + SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmFacility_Type) + "=" + ((int)facilityType).ToString());
|
|
// Count the number of matching rows.
|
|
return (int)db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), filters.Concat(" AND ", "(", ")"));
|
|
}
|
|
|
|
public override bool HasFacilities (Spm.FacilityType facilityType)
|
|
{
|
|
ClearErrorState();
|
|
return (GetFacilityCount(facilityType) > 0);
|
|
}
|
|
|
|
public override bool HasProcedures ()
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(Id)) return SetErrorState("invalid department");
|
|
ISacsDatabase db = SpmGlobals.Application.GetDatabase(userContext.SessionContext);
|
|
if (db == null) return SetErrorState("database unavailable");
|
|
List<String> filters = new List<String>();
|
|
filters.Add(SpmDbDfn.GetColumnName(SpmDbDfn.ColumnIdx.SwmProcedure_DepartmentId) + "=" + Id.ToString());
|
|
return (int)db.GetRowCount(SpmDbDfn.GetTableName(SpmDbDfn.TableIdx.SwmFacility), filters.Concat(" AND ", "(", ")")) > 0;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|