rama creada apartir de master en j
This commit is contained in:
@@ -8,6 +8,9 @@ using MongoDB.Bson;
|
||||
|
||||
namespace adas_core.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Implements the <see cref="ICalculatedObservationsService"/> contract, providing a service for working with calculated observations.
|
||||
/// </summary>
|
||||
public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
{
|
||||
private static ICalculatedObservations? _service;
|
||||
@@ -61,6 +64,13 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="PatientObservation"/> by delegating to the configured mapping service.
|
||||
/// If no service is available, the original observation is returned unchanged; if the service produces no mapping, a debug message is logged and <c>null</c> is returned.
|
||||
/// </summary>
|
||||
/// <param name="obs">The patient observation to map.</param>
|
||||
/// <param name="onlyByName">When <c>true</c>, restricts the mapping to lookups by name only.</param>
|
||||
/// <returns>The mapped <see cref="PatientObservation"/>, or <c>null</c> when the service yields no result; the input <paramref name="obs"/> is returned unchanged when no mapping service is configured.</returns>
|
||||
public virtual async Task<PatientObservation?> Map(PatientObservation obs, bool onlyByName = false)
|
||||
{
|
||||
if (_service == null) return obs;
|
||||
@@ -71,6 +81,12 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="PatientObservationAlarm"/> using the configured mapping service. Falls back to returning the original alarm unchanged when no service is available, and logs a debug entry when the service produces a null result (i.e., the alarm is ignored).
|
||||
/// </summary>
|
||||
/// <param name="obs">The patient observation alarm to be mapped.</param>
|
||||
/// <param name="onlyByName">When true, restricts the mapping to a name-based lookup only.</param>
|
||||
/// <returns>The mapped <see cref="PatientObservationAlarm"/>, or <c>null</c> if the service mapped it to null, or the original <paramref name="obs"/> when no service is configured.</returns>
|
||||
public virtual async Task<PatientObservationAlarm?> Map(PatientObservationAlarm obs, bool onlyByName = false)
|
||||
{
|
||||
if (_service == null) return obs;
|
||||
@@ -81,6 +97,12 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps the supplied <see cref="PumpObservation"/> by delegating to the configured mapping service.
|
||||
/// Returns <see langword="null"/> when the underlying service has not been initialized.
|
||||
/// </summary>
|
||||
/// <param name="obs">The pump observation to be mapped.</param>
|
||||
/// <returns>A task that yields the mapped <see cref="PumpObservation"/>, or <see langword="null"/> if no mapping service is available.</returns>
|
||||
public virtual async Task<PumpObservation?> Map(PumpObservation obs)
|
||||
{
|
||||
if (_service == null) return null;
|
||||
@@ -88,6 +110,11 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="PatientRecordingAlert"/> using the configured mapping service. Falls back to returning the original alert when no service is configured, and logs a debug entry when the service produces no mapping.
|
||||
/// </summary>
|
||||
/// <param name="obs">The <see cref="PatientRecordingAlert"/> instance to be mapped.</param>
|
||||
/// <returns>The mapped <see cref="PatientRecordingAlert"/>, the original <paramref name="obs"/> if no service is available, or <c>null</c> if the service returned no result.</returns>
|
||||
public async Task<PatientRecordingAlert?> Map(PatientRecordingAlert obs)
|
||||
{
|
||||
if (_service == null) return obs;
|
||||
@@ -98,6 +125,11 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously maps a <see cref="PatientTreatment"/> using the underlying service. If the service is unavailable (null), the original treatment is returned unchanged as a fallback.
|
||||
/// </summary>
|
||||
/// <param name="treatment">The patient treatment instance to be mapped or transformed.</param>
|
||||
/// <returns>A task that represents the asynchronous mapping operation, containing the mapped <see cref="PatientTreatment"/> or <c>null</c> if the service returns no result.</returns>
|
||||
public async Task<PatientTreatment?> Map(PatientTreatment treatment)
|
||||
{
|
||||
if (_service == null) return treatment;
|
||||
@@ -105,6 +137,11 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="PatientDiagnosis"/> by delegating to the configured mapping service. If no service is available, the original <paramref name="diagnosis"/> is returned as a fallback.
|
||||
/// </summary>
|
||||
/// <param name="diagnosis">The patient diagnosis to be mapped.</param>
|
||||
/// <returns>A task that yields the mapped <see cref="PatientDiagnosis"/>, or <c>null</c> if the underlying service returns no result.</returns>
|
||||
public virtual async Task<PatientDiagnosis?> Map(PatientDiagnosis diagnosis)
|
||||
{
|
||||
if (_service == null) return diagnosis;
|
||||
@@ -112,30 +149,58 @@ public class CalculatedObservationsService : ICalculatedObservationsService
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously calculates medicine observations for a patient based on their active medicines.
|
||||
/// Delegates the calculation to the underlying service if it has been initialized; otherwise, the call is silently skipped.
|
||||
/// </summary>
|
||||
/// <param name="activeMedicines">The list of medicines currently active for the patient.</param>
|
||||
/// <param name="patientId">The unique identifier of the patient whose medicine observations are being calculated.</param>
|
||||
public virtual async Task CalculateMedicineObservation(List<Medicine> activeMedicines, ObjectId patientId)
|
||||
{
|
||||
if (_service != null) await _service.CalculateMedicineObservation(activeMedicines, patientId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously calculates the active bolus dosage of opiates for the specified patient by delegating to the underlying service.
|
||||
/// If the service dependency is not initialized, the call is skipped silently as a no-op fallback.
|
||||
/// </summary>
|
||||
/// <param name="patientId">The unique identifier of the patient for whom the active bolus opiates calculation is performed.</param>
|
||||
public async Task CalculateBolusOpiates(ObjectId patientId)
|
||||
{
|
||||
if (_service != null) await _service.CalculateActiveBolus(patientId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the active treatments associated with the specified patient.
|
||||
/// If the underlying service is not available, returns an empty list as a fallback instead of throwing.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient whose active treatments should be retrieved.</param>
|
||||
/// <returns>A task that yields the collection of active <see cref="PatientTreatment"/> entries for the patient, or an empty list when the service is unavailable.</returns>
|
||||
public virtual async Task<IEnumerable<PatientTreatment?>> GetActiveTreatmentsByPatient(ObjectId id)
|
||||
{
|
||||
if (_service != null) return await _service.GetActiveTreatmentsByPatient(id);
|
||||
return new List<PatientTreatment?>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a list of patient observations by delegating to the configured service's pre-mapping logic when available; otherwise, returns an empty list.
|
||||
/// </summary>
|
||||
/// <param name="listToInsert">The list of patient observations to be mapped.</param>
|
||||
/// <returns>A task containing the mapped list of patient observations, or an empty list if no service is configured.</returns>
|
||||
public virtual async Task<List<PatientObservation>> MapList(List<PatientObservation> listToInsert)
|
||||
{
|
||||
if (_service != null) return await _service.PreMapList(listToInsert);
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a source alarm onto the given patient observation by delegating to the configured service when available; if no service is configured, returns the original observation unchanged.
|
||||
/// </summary>
|
||||
/// <param name="observation">The patient observation onto which the source alarm will be mapped.</param>
|
||||
/// <param name="observationAlarm">The source alarm to be applied to the observation.</param>
|
||||
/// <returns>The <see cref="PatientObservation"/> produced by the service mapping, or the original <paramref name="observation"/> when no service is configured.</returns>
|
||||
public virtual async Task<PatientObservation> MapSourceAlarm(PatientObservation observation,
|
||||
PatientObservationAlarm observationAlarm)
|
||||
PatientObservationAlarm observationAlarm)
|
||||
{
|
||||
if (_service != null) return await _service.MapSourceAlarm(observation, observationAlarm);
|
||||
return observation;
|
||||
|
||||
Reference in New Issue
Block a user