# Class AdminPanelService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

    public class AdminPanelService : IAdminPanelService

Inheritance
  object
  AdminPanelService

Implements
  IAdminPanelService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## 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

`apiSettings` IOptions<ApiSettings>
`patientService` IPatientService
`configObservationService` IConfigObservationService
`medicineService` IMedicineService
`pocService` IPointOfCareService
`unitService` IUnitService
`logger` ILogger<AdminPanelService>
`admissionService` IAdmissionService
`authService` IAuthService
`dischargeService` IDischargeService
`displayService` IDisplayService

## 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

`patient` Patient

  The patient to archive.

#### Returns

Task<bool>

  `true` if the patient was archived successfully.

#### 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

`configObservation` ConfigObservation

  The configuration observation containing the data to persist.

#### Returns

Task<bool>

  A task that resolves to `true` when the configuration is created successfully.

#### 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

`admRequest` AdmPanelRequest

  The ADMPanel request containing the data used to populate the new patient.

#### Returns

Task<Patient>

  The newly created Patient with its generated identifier.

### 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

`id` ObjectId

  The unique identifier of the config observation item to delete.

#### Returns

Task<bool>

  `true` when the config observation item is successfully removed.

#### 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

`medicineId` string

  The string representation of the medicine's ObjectId to delete.

#### Returns

Task<bool>

  A task that resolves to `true` when the medicine has been successfully deleted.

#### Exceptions

BadRequestException

  Thrown when `medicineId` is 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

`unitId` ObjectId

  The identifier of the unit to delete.

#### Returns

Task<bool>

  `true` if the unit and its related resources were successfully deleted; otherwise, `false` when 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

`location` PatientLocation

  The location used to look up the patient.

#### Returns

Task<Patient>

  The patient found at the specified location.

#### 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

`request` AdmPanelRequest

  The admission panel request containing the patient identification data and optional location used to locate the patient.

#### Returns

Task<Patient>

  The matching Patient if found.

#### 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

`id` ObjectId

  The unique identifier of the patient to look up.

#### Returns

Task<Patient>

  The patient matching the provided identifier.

#### 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

`location` PatientLocation

  The location to search for a patient at.

#### Returns

Task<Patient>

  A Patient if one is found at the specified location; otherwise, `null`.

### 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

`patientNumber` string

  The unique patient number used to look up the patient.

#### Returns

Task<Patient>

  A Patient if a match is found; otherwise, `null`.

### 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

`medicineId` ObjectId

  The unique identifier of the medicine to retrieve.

#### Returns

Task<Medicine>

  The medicine matching the specified identifier.

#### 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

`unit` Unit

  The 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 `null` if 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

`unit` Unit

  The 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

`medicine` Medicine

  The medicine to be created.

#### Returns

Task<Medicine>

  The created Medicine.

#### 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

`configObservation` ConfigObservation

  The configuration observation to update.

#### Returns

Task<bool>

  A task that resolves to `true` when the configuration is successfully updated.

#### 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

`medicine` Medicine

  The medicine entity containing the updated information to persist.

#### Returns

Task<Medicine>

  The updated Medicine returned by the service.

#### 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

`request` AdmPanelRequest

  The administrative panel request containing the new patient number and the updated patient data to apply.

`oldPatient` Patient

  The existing patient record currently stored in the database that will be updated.

#### Returns

Task<bool>

  A task that resolves to `true` when the patient data is successfully updated.

#### 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

`request` AdmPanelRequest

  The admission panel request containing the patient location details to update.

#### Returns

Task<bool>

  A task that represents the asynchronous operation. The task result is `true` if the update was successful; otherwise, `false`.