Class AdmissionService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
public class AdmissionService : IAdmissionService, IApiRequestService
- Inheritance
-
AdmissionService
- Implements
- Inherited Members
- Extension Methods
Constructors
AdmissionService(ILogger<AdmissionService>, ISubscribersService, IAdmissionRepository, IClientMessageService, IUnitService, IPatientService, IPointOfCareService, IDisplayService, IDischargeService, IPatientArchiveRepository, IHttpContextAccessor, ILocalAuditService, IMasterListServiceFactory)
public AdmissionService(ILogger<AdmissionService> logger, ISubscribersService subscribersService, IAdmissionRepository admissionRepository, IClientMessageService clientMessageService, IUnitService unitService, IPatientService patientService, IPointOfCareService pointOfCareService, IDisplayService displayService, IDischargeService dischargeService, IPatientArchiveRepository patientArchiveRepository, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, IMasterListServiceFactory masterListServiceFactory)
Parameters
loggerILogger<AdmissionService>subscribersServiceISubscribersServiceadmissionRepositoryIAdmissionRepositoryclientMessageServiceIClientMessageServiceunitServiceIUnitServicepatientServiceIPatientServicepointOfCareServiceIPointOfCareServicedisplayServiceIDisplayServicedischargeServiceIDischargeServicepatientArchiveRepositoryIPatientArchiveRepositoryhttpContextAccessorIHttpContextAccessorauditServiceILocalAuditServicemasterListServiceFactoryIMasterListServiceFactory
Methods
AdmitPatient(Admission, bool)
Admits a patient based on the provided Admission, creating a new Patient assigned to the specified point of care, marking the point of care as in use, and updating related master lists (insulation, allergies, diagnosis, origin, language barrier, passive sitting) when present. If the point of care id, unit, or point of care cannot be resolved, the operation is skipped after logging an error. When isNew is false, the originating admission record is deleted after the patient is inserted.
public Task AdmitPatient(Admission admission, bool isNew = false)
Parameters
admissionAdmissionThe admission data used to create the patient and populate location, diagnosis, allergies, and other attributes.
isNewboolWhen
false, the admission record is deleted after a successful patient insertion; whentrue, the admission is retained.
Returns
CountAdmissionsByUnitId(ObjectId)
Asynchronously counts the number of admissions associated with the specified unit identifier by delegating to the admission repository. Returns 0 and logs the error if the repository operation fails, ensuring the method does not propagate exceptions to the caller.
public Task<long> CountAdmissionsByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe identifier of the unit whose admissions should be counted.
Returns
- Task<long>
A task that represents the asynchronous operation. The task result contains the number of admissions for the given unit, or 0 if an error occurs.
DeleteAdmissionAsync(Admission)
Deletes the specified admission by delegating to the delete operation using the admission's identifier.
public Task DeleteAdmissionAsync(Admission admission)
Parameters
Returns
DeleteAdmissionByIdAsync(ObjectId)
Deletes an admission identified by the given id. If the admission is not found, the operation is skipped and logged; otherwise the admission is removed, any associated point of care is detached (clearing its AdmissionId and Admission) and set to Available when not currently Locked or InUse, a delete broadcast is sent, and an audit log entry is created.
public Task DeleteAdmissionByIdAsync(ObjectId admissionId)
Parameters
admissionIdObjectIdThe identifier of the admission to delete.
Returns
DeleteAdmissionsByUnitId(ObjectId)
Asynchronously deletes all admissions associated with the specified unit identifier by delegating the operation to the admission repository.
public Task DeleteAdmissionsByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe unique identifier of the unit whose admissions should be removed.
Returns
DeletePatientMasterListItem(OptionList, IEnumerable<Unit>, string)
Deletes a master list option from patient admissions associated with the specified units and type, records an audit log entry for each affected admission, and broadcasts the admission update when the updated admission is found.
public Task DeletePatientMasterListItem(OptionList opt, IEnumerable<Unit> unitList, string typeName)
Parameters
optOptionListThe master list option to remove from the admissions.
unitListIEnumerable<Unit>The collection of units whose admissions will be processed for the deletion.
typeNamestringThe name of the option type being deleted.
Returns
GetAdmissionByIdAsync(ObjectId)
Retrieves an admission by its identifier and, when a point of care is associated, enriches the result with the patient's location (unit, bed, and room) obtained from the point of care service. Returns null if the admission cannot be found.
public Task<Admission?> GetAdmissionByIdAsync(ObjectId admissionId)
Parameters
admissionIdObjectIdThe unique identifier of the admission to retrieve.
Returns
- Task<Admission>
The matching Admission with its PatientLocation populated when applicable, or null if no admission is found.
GetAdmissionByLocation(PatientLocation)
Retrieves a list of admissions for the specified patient location. If an error occurs during retrieval, the error is logged and an empty list is returned.
public Task<List<Admission>> GetAdmissionByLocation(PatientLocation location)
Parameters
locationPatientLocationThe patient location used to filter admissions.
Returns
- Task<List<Admission>>
A task that represents the asynchronous operation. The task result contains a list of admissions matching the specified location, or an empty list if an error occurs.
GetAdmissionByPatientNumber(string)
Retrieves the admission record associated with the specified patient clinical record number (NHC) from the admission repository.
public Task<Admission?> GetAdmissionByPatientNumber(string patientNumber)
Parameters
patientNumberstringThe patient's clinical record number (NHC) used to look up the admission.
Returns
- Task<Admission>
A task that resolves to the matching Admission if found, or
nullwhen no admission exists for the given patient number.
GetAdmissionByPointOfCareId(ObjectId)
Retrieves a list of admissions associated with the specified point of care identifier, enriching each admission with its patient location information when available.
public Task<List<Admission>> GetAdmissionByPointOfCareId(ObjectId pocId)
Parameters
pocIdObjectIdThe identifier of the point of care whose admissions should be retrieved.
Returns
- Task<List<Admission>>
A task representing the asynchronous operation, containing the list of admissions for the given point of care, or an empty list if an error occurs.
GetAdmissionByPointOfCareIdAndLocale(ObjectId, LocaleEnum)
Retrieves all admissions associated with the specified point of care and applies translations according to the given locale in parallel.
public Task<List<Admission>> GetAdmissionByPointOfCareIdAndLocale(ObjectId pocId, LocaleEnum locale)
Parameters
pocIdObjectIdThe identifier of the point of care whose admissions will be retrieved.
localeLocaleEnumThe locale used to translate the admission fields.
Returns
- Task<List<Admission>>
A task that represents the asynchronous operation, containing a list of admissions with their fields translated to the specified locale.
GetAdmissionByUnitIdWithOutPoC(ObjectId)
Retrieves admissions associated with the specified unit, excluding those linked to a Point of Care (PoC). If an error occurs during retrieval, the exception is logged and an empty list is returned as a fallback.
public Task<List<Admission>> GetAdmissionByUnitIdWithOutPoC(ObjectId unitId)
Parameters
unitIdObjectIdThe identifier of the unit whose admissions (without PoC) are being requested.
Returns
- Task<List<Admission>>
A task that returns a list of Admission objects for the given unit, or an empty list if an error occurs.
GetAdmissionsAsync()
Asynchronously retrieves all admissions and enriches each one with its associated point of care information (unit, bed, and room) when available.
public Task<IEnumerable<Admission>> GetAdmissionsAsync()
Returns
- Task<IEnumerable<Admission>>
A task that represents the asynchronous operation. The task result contains a collection of Admission objects with patient location details populated for those linked to a point of care.
Exceptions
- NotFoundException
Thrown when the admission repository returns no results.
InsertAdmission(Admission)
Inserts a new admission, preventing duplicates by NHC and optionally linking it to a Point of Care. When a Point of Care is assigned, its information is used to populate the patient location and, if free, it is reserved and associated with the newly created admission.
public Task<Admission?> InsertAdmission(Admission admission)
Parameters
admissionAdmissionThe admission to insert, optionally including a PointOfCareId to associate with a care location.
Returns
Exceptions
- ConflictException
Thrown when an admission with the same NHC already exists, or when the insertion fails to return a result.
- NotFoundException
Thrown when the specified Point of Care does not exist.
ReturnPatientToAdmissions(ObjectId)
Returns a patient to the admissions workflow by creating a new admission record, removing any existing discharge, and archiving the patient. Validates that the patient and its associated unit exist before proceeding, and only builds the admission when a point of care is assigned.
public Task ReturnPatientToAdmissions(ObjectId patientId)
Parameters
patientIdObjectIdThe identifier of the patient to be returned to admissions.
Returns
ReturnPatientToAdmissions(ObjectId, Admission)
Returns a patient to the admissions flow by creating a new admission record from the patient's existing data, removing any prior discharge, and archiving the patient.
public Task ReturnPatientToAdmissions(ObjectId patientId, Admission adm)
Parameters
patientIdObjectIdThe unique identifier of the patient to be returned to admissions.
admAdmissionThe admission context used to resolve the unit and point of care for the new admission record.
Returns
SaveRequest(ApiRequest)
Processes an admission API request by performing the appropriate action based on the request type: inserts a new admission, updates an existing one, or deletes it. Required fields (Nhc, Origin, and Diagnosis) are validated before insert and update operations, and the method exits early when the admission or any required value is missing.
public Task SaveRequest(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request containing the admission payload and the operation type to execute.
Returns
SaveRequestAsync(ApiRequest)
Asynchronously saves the specified API request by scheduling the underlying save operation on a background task.
public Task SaveRequestAsync(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request to persist.
Returns
- Task
A task that represents the asynchronous save operation.
SearchByPatientNumberAndDistinctUnit(string, ObjectId)
Searches for a patient by patient number, enriching the current patient record with its point of care and unit name when available, and combines it with archived patient and admission lookups scoped to the specified unit.
public Task<PatientSearch?> SearchByPatientNumberAndDistinctUnit(string patientNumber, ObjectId unitId)
Parameters
patientNumberstringThe unique patient number used as the primary search key.
unitIdObjectIdThe identifier of the unit used to filter the archived patient and admission searches.
Returns
- Task<PatientSearch>
A PatientSearch aggregating the current patient, archived patient, and admission data, including flags indicating whether the patient exists only in the archive and whether any of the three sources returned a result.
UpdateAdmissionAsync(Admission)
Updates an existing admission record, enriching its patient location details from the linked point of care on both the prior and incoming states, and records the change via audit log and broadcast.
If the admission is not found, the method returns without making changes; point of care lookups are only applied when a PointOfCareId is present and yields a result.
public Task UpdateAdmissionAsync(Admission admission)
Parameters
admissionAdmissionThe admission entity containing the updated information to persist.
Returns
UpdatePatientMasterListItemChange(UpdateOptionMasterListDto, IEnumerable<Unit>, string)
Updates the master list option for admissions associated with the specified units, records an audit log entry for each modified admission, and broadcasts the updates.
public Task UpdatePatientMasterListItemChange(UpdateOptionMasterListDto opt, IEnumerable<Unit> unitList, string typeName)
Parameters
optUpdateOptionMasterListDtoThe master list update options to apply to the matching admissions.
unitListIEnumerable<Unit>The collection of units whose admissions are affected by the update.
typeNamestringThe name of the master list type being modified.