=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===
This commit is contained in:
@@ -44,6 +44,7 @@ public class AdmissionService(
|
||||
/// Deletes the specified admission by delegating to the delete operation using the admission's identifier.
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission entity to delete, identified by its <see cref="Admission.Id"/>.</param>
|
||||
/// <!-- aidoc:v1 sig=bc9e848 body=3ba8fcf -->
|
||||
public async Task DeleteAdmissionAsync(Admission admission)
|
||||
{
|
||||
await DeleteAdmissionByIdAsync(admission.Id);
|
||||
@@ -53,6 +54,7 @@ public class AdmissionService(
|
||||
/// 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 <c>AdmissionId</c> and <c>Admission</c>) and set to <c>Available</c> when not currently <c>Locked</c> or <c>InUse</c>, a delete broadcast is sent, and an audit log entry is created.
|
||||
/// </summary>
|
||||
/// <param name="admissionId">The identifier of the admission to delete.</param>
|
||||
/// <!-- aidoc:v1 sig=504429d body=50c3daa -->
|
||||
public async Task DeleteAdmissionByIdAsync(ObjectId admissionId)
|
||||
{
|
||||
var admissionAux = await admissionRepository.FindById(admissionId);
|
||||
@@ -90,6 +92,7 @@ public class AdmissionService(
|
||||
/// Asynchronously deletes all admissions associated with the specified unit identifier by delegating the operation to the admission repository.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The unique identifier of the unit whose admissions should be removed.</param>
|
||||
/// <!-- aidoc:v1 sig=6db1fa4 body=5f644a1 -->
|
||||
public async Task DeleteAdmissionsByUnitId(ObjectId unitId)
|
||||
{
|
||||
_ = await admissionRepository.DeleteAdmissionsByUnitId(unitId);
|
||||
@@ -101,6 +104,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admissionId">The unique identifier of the admission to retrieve.</param>
|
||||
/// <returns>The matching <see cref="Admission"/> with its <see cref="Admission.PatientLocation"/> populated when applicable, or null if no admission is found.</returns>
|
||||
/// <!-- aidoc:v1 sig=5c1a39b body=869dd3e -->
|
||||
public async Task<Admission?> GetAdmissionByIdAsync(ObjectId admissionId)
|
||||
{
|
||||
var result = await admissionRepository.FindById(admissionId);
|
||||
@@ -118,6 +122,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of <see cref="Admission"/> objects with patient location details populated for those linked to a point of care.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when the admission repository returns no results.</exception>
|
||||
/// <!-- aidoc:v1 sig=d4fca15 body=37e0155 -->
|
||||
public async Task<IEnumerable<Admission>> GetAdmissionsAsync()
|
||||
{
|
||||
var resultList = await admissionRepository.FindAll() ??
|
||||
@@ -141,6 +146,8 @@ public class AdmissionService(
|
||||
/// <returns>The newly inserted <see cref="Admission"/>, or <c>null</c> if no result is produced.</returns>
|
||||
/// <exception cref="ConflictException">Thrown when an admission with the same NHC already exists, or when the insertion fails to return a result.</exception>
|
||||
/// <exception cref="NotFoundException">Thrown when the specified Point of Care does not exist.</exception>
|
||||
/// <!-- aidoc-review:v1 severity=medium kind=wrong_returns
|
||||
/// "The <returns> tag says 'or null if no result is produced', but the code uses `?? throw new ConflictException(...)` so the method never returns null — it throws instead. The null-return path does not exist." -->
|
||||
public async Task<Admission?> InsertAdmission(Admission admission)
|
||||
{
|
||||
var admissionAux = await admissionRepository.FindByNhc(admission.Nhc);
|
||||
@@ -183,6 +190,7 @@ public class AdmissionService(
|
||||
/// If the admission is not found, the method returns without making changes; point of care lookups are only applied when a <c>PointOfCareId</c> is present and yields a result.
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission entity containing the updated information to persist.</param>
|
||||
/// <!-- aidoc:v1 sig=ca4e183 body=25ff85a -->
|
||||
public async Task UpdateAdmissionAsync(Admission admission)
|
||||
{
|
||||
var oldAdmission = await admissionRepository.FindById(admission.Id);
|
||||
@@ -212,6 +220,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission data used to create the patient and populate location, diagnosis, allergies, and other attributes.</param>
|
||||
/// <param name="isNew">When <c>false</c>, the admission record is deleted after a successful patient insertion; when <c>true</c>, the admission is retained.</param>
|
||||
/// <!-- aidoc:v1 sig=f69ed33 body=b929523 -->
|
||||
public async Task AdmitPatient(Admission admission, bool isNew = false)
|
||||
{
|
||||
if (admission.PointOfCareId == null)
|
||||
@@ -329,6 +338,7 @@ public class AdmissionService(
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="patientId">The identifier of the patient to be returned to admissions.</param>
|
||||
/// <!-- aidoc:v1 sig=17907a9 body=0185562 -->
|
||||
public async Task ReturnPatientToAdmissions(ObjectId patientId)
|
||||
{
|
||||
var patient = await patientService.FindById(patientId);
|
||||
@@ -383,6 +393,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="patientId">The unique identifier of the patient to be returned to admissions.</param>
|
||||
/// <param name="adm">The admission context used to resolve the unit and point of care for the new admission record.</param>
|
||||
/// <!-- aidoc:v1 sig=13b57d7 body=732c8f7 -->
|
||||
public async Task ReturnPatientToAdmissions(ObjectId patientId, Admission adm)
|
||||
{
|
||||
var patient = await patientService.FindById(patientId);
|
||||
@@ -437,6 +448,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="location">The patient location used to filter admissions.</param>
|
||||
/// <returns>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.</returns>
|
||||
/// <!-- aidoc:v1 sig=4d1cb29 body=1520dd9 -->
|
||||
public async Task<List<Admission>> GetAdmissionByLocation(PatientLocation location)
|
||||
{
|
||||
try
|
||||
@@ -456,6 +468,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="pocId">The identifier of the point of care whose admissions should be retrieved.</param>
|
||||
/// <returns>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.</returns>
|
||||
/// <!-- aidoc:v1 sig=24794e8 body=d8a4124 -->
|
||||
public async Task<List<Admission>> GetAdmissionByPointOfCareId(ObjectId pocId)
|
||||
{
|
||||
try
|
||||
@@ -482,6 +495,7 @@ public class AdmissionService(
|
||||
/// <param name="pocId">The identifier of the point of care whose admissions will be retrieved.</param>
|
||||
/// <param name="locale">The locale used to translate the admission fields.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of admissions with their fields translated to the specified locale.</returns>
|
||||
/// <!-- aidoc:v1 sig=2f28a6c body=8c5b998 -->
|
||||
public async Task<List<Admission>> GetAdmissionByPointOfCareIdAndLocale(ObjectId pocId, LocaleEnum locale)
|
||||
{
|
||||
var admissions = await GetAdmissionByPointOfCareId(pocId);
|
||||
@@ -500,6 +514,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="unitId">The identifier of the unit whose admissions (without PoC) are being requested.</param>
|
||||
/// <returns>A task that returns a list of <see cref="Admission"/> objects for the given unit, or an empty list if an error occurs.</returns>
|
||||
/// <!-- aidoc:v1 sig=a0f7f96 body=714008c -->
|
||||
public async Task<List<Admission>> GetAdmissionByUnitIdWithOutPoC(ObjectId unitId)
|
||||
{
|
||||
try
|
||||
@@ -520,6 +535,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="unitId">The identifier of the unit whose admissions should be counted.</param>
|
||||
/// <returns>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.</returns>
|
||||
/// <!-- aidoc:v1 sig=d15b339 body=27c30bc -->
|
||||
public async Task<long> CountAdmissionsByUnitId(ObjectId unitId)
|
||||
{
|
||||
try
|
||||
@@ -540,6 +556,7 @@ public class AdmissionService(
|
||||
/// <param name="patientNumber">The unique patient number used as the primary search key.</param>
|
||||
/// <param name="unitId">The identifier of the unit used to filter the archived patient and admission searches.</param>
|
||||
/// <returns>A <see cref="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.</returns>
|
||||
/// <!-- aidoc:v1 sig=b6a87e4 body=624e811 -->
|
||||
public async Task<PatientSearch?> SearchByPatientNumberAndDistinctUnit(string patientNumber, ObjectId unitId)
|
||||
{
|
||||
var patient = await patientService.FindByPatientNumber(patientNumber);
|
||||
@@ -570,6 +587,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="patientNumber">The patient's clinical record number (NHC) used to look up the admission.</param>
|
||||
/// <returns>A task that resolves to the matching <see cref="Admission"/> if found, or <c>null</c> when no admission exists for the given patient number.</returns>
|
||||
/// <!-- aidoc:v1 sig=3fe6f66 body=9a0b8ac -->
|
||||
public Task<Admission?> GetAdmissionByPatientNumber(string patientNumber)
|
||||
{
|
||||
return admissionRepository.FindByNhc(patientNumber);
|
||||
@@ -581,6 +599,7 @@ public class AdmissionService(
|
||||
/// <param name="opt">The master list update options to apply to the matching admissions.</param>
|
||||
/// <param name="unitList">The collection of units whose admissions are affected by the update.</param>
|
||||
/// <param name="typeName">The name of the master list type being modified.</param>
|
||||
/// <!-- aidoc:v1 sig=b539b7b body=000b050 -->
|
||||
public async Task UpdatePatientMasterListItemChange(UpdateOptionMasterListDto opt, IEnumerable<Unit> unitList,
|
||||
string typeName)
|
||||
{
|
||||
@@ -601,6 +620,7 @@ public class AdmissionService(
|
||||
/// <param name="opt">The master list option to remove from the admissions.</param>
|
||||
/// <param name="unitList">The collection of units whose admissions will be processed for the deletion.</param>
|
||||
/// <param name="typeName">The name of the option type being deleted.</param>
|
||||
/// <!-- aidoc:v1 sig=cb62e44 body=c1573d6 -->
|
||||
public async Task DeletePatientMasterListItem(OptionList opt, IEnumerable<Unit> unitList, string typeName)
|
||||
{
|
||||
var unitIds = unitList.Select(x => x.Id).ToList();
|
||||
@@ -622,6 +642,7 @@ public class AdmissionService(
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="apiRequest">The API request containing the admission payload and the operation type to execute.</param>
|
||||
/// <!-- aidoc:v1 sig=229d8cd body=9f05a36 -->
|
||||
public async Task SaveRequest(ApiRequest apiRequest)
|
||||
{
|
||||
try
|
||||
@@ -681,6 +702,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="apiRequest">The API request to persist.</param>
|
||||
/// <returns>A task that represents the asynchronous save operation.</returns>
|
||||
/// <!-- aidoc:v1 sig=a3706aa body=c8d77ba -->
|
||||
public Task SaveRequestAsync(ApiRequest apiRequest)
|
||||
{
|
||||
return Task.FromResult(Task.Run(async () => { await SaveRequest(apiRequest); }));
|
||||
@@ -691,6 +713,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admission">The current admission containing the updated PointOfCare identifier.</param>
|
||||
/// <param name="oldAdmission">The previous admission state used to identify the original PointOfCare to release.</param>
|
||||
/// <!-- aidoc:v1 sig=4fcd57d body=2365bd2 -->
|
||||
private async Task HandlePointOfCareChange(Admission admission, Admission oldAdmission)
|
||||
{
|
||||
// Check if PointOfCare has changed.
|
||||
@@ -747,6 +770,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="pointOfCareId">The identifier of the point of care whose status will be updated.</param>
|
||||
/// <param name="status">The new status to assign to the point of care.</param>
|
||||
/// <!-- aidoc:v1 sig=2c82bd3 body=69fe4f4 -->
|
||||
private async Task SetPointOfCareStatus(ObjectId pointOfCareId, StatusEnum.PointOfCare status)
|
||||
{
|
||||
var pointOfCare = await pointOfCareService.FindById(pointOfCareId);
|
||||
@@ -761,6 +785,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission record to broadcast.</param>
|
||||
/// <param name="operation">The operation type associated with the broadcast.</param>
|
||||
/// <!-- aidoc:v1 sig=c26bb38 body=b6386c1 -->
|
||||
private async void SendAdmissionBroadcast(Admission admission, OperationType operation)
|
||||
{
|
||||
try
|
||||
@@ -783,6 +808,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission whose broadcast is being sent; its Point of Care is used to select subscribers and locale-specific content.</param>
|
||||
/// <param name="operation">The type of operation to send to the subscribers.</param>
|
||||
/// <!-- aidoc:v1 sig=078ad3d body=8427094 -->
|
||||
private async Task SendAdmissionBroadcastByPoC(Admission admission, OperationType operation)
|
||||
{
|
||||
if (!admission.PointOfCareId.HasValue)
|
||||
@@ -821,6 +847,7 @@ public class AdmissionService(
|
||||
/// </summary>
|
||||
/// <param name="admission">The admission to broadcast, which supplies the target unit identifier.</param>
|
||||
/// <param name="operation">The operation type associated with the broadcast message.</param>
|
||||
/// <!-- aidoc:v1 sig=d37a566 body=b40a845 -->
|
||||
private async Task SendAdmissionByUnitId(Admission admission, OperationType operation)
|
||||
{
|
||||
if (admission.UnitId == ObjectId.Empty)
|
||||
@@ -855,6 +882,7 @@ public class AdmissionService(
|
||||
/// <param name="admission">The admission whose reference names will be updated with localized values.</param>
|
||||
/// <param name="locale">The locale used to retrieve the appropriate master list translations.</param>
|
||||
/// <returns>The same <see cref="Admission"/> instance with its localized reference names applied when available.</returns>
|
||||
/// <!-- aidoc:v1 sig=0afb3a4 body=2138792 -->
|
||||
private async Task<Admission> GetAdmissionWithLocale(Admission admission, LocaleEnum locale)
|
||||
{
|
||||
var unit = await unitService.FindById(admission.UnitId);
|
||||
|
||||
Reference in New Issue
Block a user