rama creada apartir de master en j
This commit is contained in:
@@ -24,15 +24,27 @@ public class ConfigUnitsService(
|
||||
private readonly string _key = apiSettings.Value.ConfigUnitsKey ?? "PV1";
|
||||
private readonly int? _refreshTimeout = apiSettings.Value.ConfigObservation?.Refresh;
|
||||
|
||||
/// <summary>
|
||||
/// Maps a patient observation using the unit configuration when configuration units are required.
|
||||
/// If configuration units are not required, the observation's units are not specified, or no matching configuration is found, the original observation is returned unchanged.
|
||||
/// </summary>
|
||||
/// <param name="obs">The patient observation to be mapped.</param>
|
||||
/// <returns>The mapped observation when a matching unit configuration is resolved; otherwise, the original observation.</returns>
|
||||
public async Task<T> Map<T>(T obs) where T : BasePatientObservation
|
||||
{
|
||||
if (!_configUnitsRequired) return obs;
|
||||
|
||||
|
||||
var conf = !string.IsNullOrEmpty(obs.Units) ? await Get(obs.Units) : null;
|
||||
|
||||
return conf == null ? obs : MapConf(obs, conf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="PumpObservation"/> by processing its pump value properties.
|
||||
/// If configuration units are not required, the observation is returned unchanged; otherwise, the pump values are mapped via <c>MapPumpValues</c> and the observation is returned.
|
||||
/// </summary>
|
||||
/// <param name="obs">The <see cref="PumpObservation"/> to be mapped.</param>
|
||||
/// <returns>The mapped <see cref="PumpObservation"/>, returned as-is when units configuration is not required or after pump value mapping otherwise.</returns>
|
||||
public async Task<PumpObservation> Map(PumpObservation obs)
|
||||
{
|
||||
if (!_configUnitsRequired) return obs;
|
||||
@@ -42,7 +54,7 @@ public class ConfigUnitsService(
|
||||
|
||||
// var conf = !string.IsNullOrEmpty(obs.Units) ? await Get(obs.Units) : null;
|
||||
// return conf == null ? obs : MapConf(obs, conf);
|
||||
|
||||
|
||||
return obs;
|
||||
}
|
||||
|
||||
@@ -81,6 +93,12 @@ public class ConfigUnitsService(
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Maps a configuration unit value onto a patient observation. If the observation is not a <see cref="PatientObservation"/>, the original observation is returned unchanged; otherwise, its <c>Units</c> property is assigned from the configuration unit item's value.
|
||||
/// </summary>
|
||||
/// <param name="obs">The base patient observation to which the configured unit value will be applied.</param>
|
||||
/// <param name="conf">The configuration unit item whose <c>Value</c> is used as the unit to assign.</param>
|
||||
/// <returns>The input observation, with <c>Units</c> set from <paramref name="conf"/> when applicable, or the unchanged observation when it is not a <see cref="PatientObservation"/>.</returns>
|
||||
private T MapConf<T>(T obs, ConfigUnitItem conf) where T : BasePatientObservation
|
||||
{
|
||||
if (obs is not PatientObservation pobs) return obs;
|
||||
@@ -91,6 +109,12 @@ public class ConfigUnitsService(
|
||||
return obs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a configuration unit item by its unique code from the configuration store.
|
||||
/// Returns null when the configuration cannot be loaded or when no item matches the specified code.
|
||||
/// </summary>
|
||||
/// <param name="code">The unique code identifier of the configuration unit item to look up.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the matching <see cref="ConfigUnitItem"/>, or null if the configuration is unavailable or no item is found.</returns>
|
||||
public async Task<ConfigUnitItem?> Get(string code)
|
||||
{
|
||||
var result = await GetConfig();
|
||||
@@ -98,6 +122,15 @@ public class ConfigUnitsService(
|
||||
return result?.Items?.FirstOrDefault(i => i.Code == code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="ConfigUnits"/> configuration associated with the current key, using a time-based cache
|
||||
/// to avoid repeated repository calls before the configured refresh timeout elapses. On any failure during the
|
||||
/// repository lookup, the error is logged and <c>null</c> is returned.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="Task{TResult}"/> containing the cached or freshly fetched <see cref="ConfigUnits"/>, or
|
||||
/// <c>null</c> if the repository lookup fails.
|
||||
/// </returns>
|
||||
private async Task<ConfigUnits?> GetConfig()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user