Class AdminPanelService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
public class AdminPanelService : IAdminPanelService
- Inheritance
-
AdminPanelService
- Implements
- Inherited Members
- Extension Methods
Constructors
AdminPanelService(IOptions<ApiSettings>, IPatientService, IConfigObservationService, IMedicineService, IPointOfCareService, IUnitService, ILogger<AdminPanelService>, IAdmissionService, IAuthService, IDischargeService, IDisplayService)
public AdminPanelService(IOptions<ApiSettings> apiSettings, IPatientService patientService, IConfigObservationService configObservationService, IMedicineService medicineService, IPointOfCareService pocService, IUnitService unitService, ILogger<AdminPanelService> logger, IAdmissionService admissionService, IAuthService authService, IDischargeService dischargeService, IDisplayService displayService)
Parameters
apiSettingsIOptions<ApiSettings>patientServiceIPatientServiceconfigObservationServiceIConfigObservationServicemedicineServiceIMedicineServicepocServiceIPointOfCareServiceunitServiceIUnitServiceloggerILogger<AdminPanelService>admissionServiceIAdmissionServiceauthServiceIAuthServicedischargeServiceIDischargeServicedisplayServiceIDisplayService
Methods
ArchivePatient(Patient)
Archives the specified patient via the patient service and logs the operation. Returns true on success; any exception thrown by the underlying service is written to the console and rethrown.
public Task<bool> ArchivePatient(Patient patient)
Parameters
patientPatientThe patient to archive.
Returns
Exceptions
- Exception
Rethrows any exception thrown by the underlying patient service after logging it to the console.
CreateConfig(ConfigObservation)
Creates a new configuration based on the provided observation data. Throws a conflict exception when the underlying creation operation fails (returns null), otherwise returns true.
public Task<bool> CreateConfig(ConfigObservation configObservation)
Parameters
configObservationConfigObservationThe configuration observation containing the data to persist.
Returns
Exceptions
- ConflictException
Thrown when the configuration creation fails, indicated by a null result from the service call.
CreatePatient(AdmPanelRequest)
Creates a new patient from an ADMPanel request, generating a new identifier and persisting it through the patient service.
public Task<Patient?> CreatePatient(AdmPanelRequest admRequest)
Parameters
admRequestAdmPanelRequestThe ADMPanel request containing the data used to populate the new patient.
Returns
DeleteConfigObservationItem(ObjectId)
Deletes a config observation item by its identifier. Throws a conflict exception if the underlying removal service returns a null result, indicating the delete could not be completed.
public Task<bool> DeleteConfigObservationItem(ObjectId id)
Parameters
idObjectIdThe unique identifier of the config observation item to delete.
Returns
Exceptions
- ConflictException
Thrown when the removal operation returns a null result, signaling a conflict with the delete request.
DeleteMedicineById(string)
Deletes a medicine record by its identifier, validating the identifier format and confirming successful removal.
public Task<bool> DeleteMedicineById(string medicineId)
Parameters
medicineIdstringThe string representation of the medicine's ObjectId to delete.
Returns
Exceptions
- BadRequestException
Thrown when
medicineIdis not a valid ObjectId format.- ConflictException
Thrown when the medicine still exists after the delete operation, indicating the deletion failed.
DeleteUnitById(ObjectId)
Deletes a unit identified by its identifier, cascading the removal to all associated resources (admissions, discharges, authorizations, displays, and points of care). Throws a NotFoundException if the unit does not exist, and a ConflictException if the unit still has patients assigned to it.
public Task<bool> DeleteUnitById(ObjectId unitId)
Parameters
unitIdObjectIdThe identifier of the unit to delete.
Returns
- Task<bool>
trueif the unit and its related resources were successfully deleted; otherwise,falsewhen an error is caught and logged.
Exceptions
- NotFoundException
Thrown when no unit is found for the specified
unitId.- ConflictException
Thrown when the unit has patients assigned to it, preventing deletion.
FindByLocation(PatientLocation)
Retrieves a patient associated with the specified location, throwing a not-found exception if no patient is found.
public Task<Patient?> FindByLocation(PatientLocation location)
Parameters
locationPatientLocationThe location used to look up the patient.
Returns
Exceptions
- NotFoundException
Thrown when no patient is found for the given location.
FindPatient(AdmPanelRequest)
Asynchronously retrieves a Patient based on the provided admission panel request, using location-aware lookup when the location is not fully empty. When a location is present, the search is performed including location criteria; otherwise the location parameter is ignored.
public Task<Patient?> FindPatient(AdmPanelRequest request)
Parameters
requestAdmPanelRequestThe admission panel request containing the patient identification data and optional location used to locate the patient.
Returns
Exceptions
- NotFoundException
Thrown when no patient matches the provided request criteria.
FindPatientById(ObjectId)
Retrieves a patient by their unique identifier from the patient service. Throws a not-found exception when no matching patient exists for the specified identifier.
public Task<Patient?> FindPatientById(ObjectId id)
Parameters
idObjectIdThe unique identifier of the patient to look up.
Returns
Exceptions
- NotFoundException
Thrown when no patient is found for the specified identifier.
FindPatientByLocation(PatientLocation)
Finds a patient at the specified location by delegating to the patient service. Returns null when no patient is found at the given location.
public Task<Patient?> FindPatientByLocation(PatientLocation location)
Parameters
locationPatientLocationThe location to search for a patient at.
Returns
FindPatientByPatientNumber(string)
Retrieves a patient by their unique patient number by delegating to the patient service.
Returns null when no matching patient is found.
public Task<Patient?> FindPatientByPatientNumber(string patientNumber)
Parameters
patientNumberstringThe unique patient number used to look up the patient.
Returns
GetMedicineById(ObjectId)
Retrieves a medicine by its unique identifier, or throws an exception if the medicine cannot be found.
public Task<Medicine?> GetMedicineById(ObjectId medicineId)
Parameters
medicineIdObjectIdThe unique identifier of the medicine to retrieve.
Returns
Exceptions
- NotFoundException
Thrown when no medicine is found with the specified identifier.
GetUnitDependencyDto(Unit)
Asynchronously creates a UnitInfoDto for the specified unit, populated with counts of related entities such as admissions, discharges, displays, patients, points of care, and virtual points of care. Returns null if any of the underlying count operations fail, logging the error.
public Task<UnitInfoDto?> GetUnitDependencyDto(Unit unit)
Parameters
unitUnitThe unit for which to build the dependency information DTO.
Returns
- Task<UnitInfoDto>
A task that resolves to a UnitInfoDto containing the unit's dependency counts, or
nullif an error occurs while retrieving the counts.
InsertUnit(Unit)
Inserts a new unit and automatically creates the default Points of Care associated with it, one for each value of the VirtualPointOfCare enum. Each created Point of Care is set to Available status, using the enum value name for both Room and Bed, and its identifier is added to the unit's PointOfCareIds before updating the unit. Returns null if the initial unit insertion fails.
public Task<Unit?> InsertUnit(Unit unit)
Parameters
unitUnitThe unit to be inserted.
Returns
- Task<Unit>
The inserted unit with its associated Point of Care identifiers, or null if the unit could not be inserted.
PostMedicine(Medicine)
Creates a new medicine by forwarding the request to the medicine service. Throws a conflict exception if the service is unable to create the medicine.
public Task<Medicine?> PostMedicine(Medicine medicine)
Parameters
medicineMedicineThe medicine to be created.
Returns
Exceptions
- ConflictException
Thrown when the medicine service fails to create the medicine.
UpdateConfig(ConfigObservation)
Updates a configuration observation by delegating to the configuration service. If the service returns a null result, indicating a failure to update, a conflict exception is thrown.
public Task<bool> UpdateConfig(ConfigObservation configObservation)
Parameters
configObservationConfigObservationThe configuration observation to update.
Returns
Exceptions
- ConflictException
Thrown when the underlying update operation fails, as indicated by a null result from the service.
UpdateMedicine(Medicine)
Updates an existing Medicine by delegating to the medicine service. Throws a ConflictException when the service returns a null result, indicating the update could not be applied.
public Task<Medicine?> UpdateMedicine(Medicine medicine)
Parameters
medicineMedicineThe medicine entity containing the updated information to persist.
Returns
Exceptions
- ConflictException
Thrown when the update operation fails and the service returns a null result.
UpdatePatientData(AdmPanelRequest, Patient)
Updates the patient information based on the provided administrative panel request, persisting only the patient-related fields and detecting whether the patient number has changed.
public Task<bool> UpdatePatientData(AdmPanelRequest request, Patient oldPatient)
Parameters
requestAdmPanelRequestThe administrative panel request containing the new patient number and the updated patient data to apply.
oldPatientPatientThe existing patient record currently stored in the database that will be updated.
Returns
Exceptions
- ConflictException
Thrown when the request is missing the patient number, the patient payload is null, or the patient payload is empty.
UpdatePatientLocation(AdmPanelRequest)
Updates the patient location based on the provided admission panel request.
public Task<bool> UpdatePatientLocation(AdmPanelRequest request)
Parameters
requestAdmPanelRequestThe admission panel request containing the patient location details to update.