Files
adas-core/adas-core.Domain/Models/Observations/Medication.cs
T

242 lines
11 KiB
C#

using adas_core.Domain.Models.MongoModels;
using adas_core.Domain.Utils;
namespace adas_core.Domain.Models.Observations;
/// <summary>
/// Represents a medication-related observation, extending the base <see cref="Observation"/> type.
/// </summary>
/// <remarks>
/// Serves as a specialized observation for capturing and modeling medication-specific data within the inheritance hierarchy.
/// </remarks>
/// <!-- aidoc:v1 sig=a00759f -->
public class Medication : Observation
{
/// <summary>
/// Initializes a new instance of the <see cref="Medication"/> class with default values.
/// </summary>
/// <!-- aidoc:v1 sig=bb98407 body=4448e1d -->
public Medication()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Medication"/> class, which represents medication delivery state, by reading pump-related properties from <paramref name="obj"/> when their MDC codes are present and assigning <paramref name="id"/> to <see cref="Medication.Id"/>.
/// </summary>
/// <param name="id">The identifier stored in <see cref="Medication.Id"/>.</param>
/// <param name="obj">A <see cref="Dictionary{TKey,TValue}"/> of <see cref="PumpElement"/> entries keyed by MDC code, consulted via <see cref="Dictionary{TKey,TValue}.TryGetValue"/>.</param>
/// <!-- aidoc:v1 sig=b107edc body=3412539 -->
public Medication(string id, Dictionary<string, PumpElement> obj)
{
if (obj.TryGetValue("MDC_184504", out var mode)) PumpMode = new PumpMode(mode);
if (obj.TryGetValue("MDC_184519", out var status)) PumpStatus = new PumpStatus(status);
if (obj.TryGetValue("MDC_157784", out var flow)) FlowFluid = new FlowFluid(flow);
if (obj.TryGetValue("MDC_157993", out var fluid)) VolFluidTotal = new VolumeFluidDeliveryTotal(fluid);
if (obj.TryGetValue("MDCX_PUMP_DELIVERY_PRESSURE", out var pressure))
PumpDeliveryPressure = new PumpDeliveryPressure(pressure);
if (obj.TryGetValue("MDC_DEV_PUMP_ACTIVE_SOURCES", out var source))
PumpActiveSources = new PumpActiveSources(source);
if (obj.TryGetValue("MDC_184514", out var drug)) Drug = new Drug(drug);
if (obj.TryGetValue("MDC_157872", out var volume)) VolumeFluidTbiRemain = new VolumeFluidTbiRemain(volume);
if (obj.TryGetValue("MDC_157916", out var remain)) VolumeFluidTimeRemain = new VolumeFluidTimePdRemain(remain);
Id = id;
}
public string? Id { get; set; }
public PumpMode? PumpMode { get; set; }
public PumpStatus? PumpStatus { get; set; }
public FlowFluid? FlowFluid { get; set; }
public VolumeFluidDeliveryTotal? VolFluidTotal { get; set; }
public VolumeFluidTbiRemain? VolumeFluidTbiRemain { get; set; }
public VolumeFluidTimePdRemain? VolumeFluidTimeRemain { get; set; }
public PumpDeliveryPressure? PumpDeliveryPressure { get; set; }
public PumpActiveSources? PumpActiveSources { get; set; }
public Drug? Drug { get; set; }
}
/// <summary>
/// Represents a value or data entry associated with a drug, such as dosage, concentration, or other pharmaceutical-related information.
/// </summary>
/// <!-- aidoc:v1 sig=a9fb501 -->
public class DrugValue
{
/// <summary>
/// Initializes a new instance of the <see cref="DrugValue"/> class using default values. The <see cref="DrugValue"/> type represents the value associated with a drug.
/// </summary>
/// <!-- aidoc:v1 sig=b79012f body=4448e1d -->
public DrugValue()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrugValue"/> class by copying the medication-related values from the specified <see cref="PumpElement"/>.
/// This constructor populates the properties <see cref="DrugValue.Id"/>, <see cref="DrugValue.Text"/>, <see cref="DrugValue.Time"/>, <see cref="DrugValue.Units"/>, <see cref="DrugValue.CodingSystem"/>, and <see cref="DrugValue.Result"/> from the source element.
/// </summary>
/// <param name="pumpElement">The <see cref="PumpElement"/> from which to copy the medication data.</param>
/// <!-- aidoc:v1 sig=8c84a69 body=a72ec1a -->
public DrugValue(PumpElement pumpElement)
{
Id = pumpElement.Id;
Text = pumpElement.Text;
Time = pumpElement.Time;
Units = pumpElement.Units;
CodingSystem = pumpElement.CodingSystem;
Result = pumpElement.Result;
}
public string? Id { get; set; }
public string? Text { get; set; }
public string? Units { get; set; }
public DateTime? Time { get; set; }
public string? CodingSystem { get; set; }
public char? Result { get; set; } = 'R';
/// <summary>
/// Copies the values from the specified <see cref="DrugValue"/> instance into the current instance, replacing the existing Id, Text, Units, Time, CodingSystem, and Result properties.
/// </summary>
/// <param name="common">The <see cref="DrugValue"/> instance whose property values will be copied to the current instance.</param>
/// <!-- aidoc:v1 sig=04f2026 body=2cd00f7 -->
public void Copy(DrugValue common)
{
Id = common.Id;
Text = common.Text;
Units = common.Units;
Time = common.Time;
CodingSystem = common.CodingSystem;
Result = common.Result;
}
}
/// <summary>
/// Represents an abstract base class for drug values that are expressed as double-precision floating-point numbers, providing a common foundation for numerical drug-related data.
/// </summary>
/// <remarks>
/// As an abstract class, it must be inherited by a derived class that supplies the concrete implementation for the double-based drug value behavior.
/// </remarks>
/// <!-- aidoc:v1 sig=2c61895 -->
public abstract class DrugDoubleValue : DrugValue
{
/// <summary>
/// Initializes a new instance of the <see cref="DrugDoubleValue"/> class by forwarding <paramref name="pumpElement"/> to the base constructor and parsing its textual value as a <see cref="double"/> to set the Value property when the conversion succeeds.
/// </summary>
/// <param name="pumpElement">The <see cref="PumpElement"/> whose string representation is parsed as a <see cref="double"/> to initialize the Value property.</param>
/// <!-- aidoc:v1 sig=d14bd75 body=29c2c0d -->
protected DrugDoubleValue(PumpElement pumpElement) : base(pumpElement)
{
if (double.TryParse(pumpElement.Value?.ToString(), out var valueParsed))
Value = valueParsed;
}
public double? Value { get; set; }
}
/// <summary>
/// Serves as an abstract base class for drug values represented as strings, extending <see cref="DrugValue"/>.
/// </summary>
/// <remarks>
/// Inherits from <see cref="DrugValue"/> and is intended to be derived by concrete classes that encapsulate string-typed drug data associated with a <see cref="PumpElement"/>.
/// </remarks>
/// <!-- aidoc:v1 sig=b31b430 -->
public abstract class DrugStringValue(PumpElement pumpElement) : DrugValue(pumpElement)
{
public string? Value { get; set; } = pumpElement.Value?.ToString();
}
/// <summary>
/// Represents a double-precision drug value that describes the flow of a fluid for the specified <see cref="PumpElement"/>.
/// </summary>
/// <!-- aidoc:v1 sig=afae0d5 -->
public class FlowFluid(PumpElement pumpElement) : DrugDoubleValue(pumpElement);
/// <summary>
/// Represents the total volume of fluid delivered as a drug-related double value associated with a specific pump element.
/// </summary>
/// <remarks>
/// Inherits from <see cref="DrugDoubleValue"/>, sharing the pump element context with its base type.
/// </remarks>
/// <!-- aidoc:v1 sig=e2e9e55 -->
public class VolumeFluidDeliveryTotal(PumpElement pumpElement) : DrugDoubleValue(pumpElement);
/// <summary>
/// Represents the delivery pressure of a pump as a drug-related double precision value.
/// </summary>
/// <remarks>
/// Inherits from <see cref="DrugDoubleValue"/> and is constructed with a <see cref="PumpElement"/> instance that is forwarded to the base constructor.
/// </remarks>
/// <!-- aidoc:v1 sig=8d4645b -->
public class PumpDeliveryPressure(PumpElement pumpElement) : DrugDoubleValue(pumpElement);
/// <summary>
/// Represents the remaining volume of fluid to be infused (TBI) associated with a pump element, implemented as a drug-related double value.
/// </summary>
/// <!-- aidoc:v1 sig=dc8c1c6 -->
public class VolumeFluidTbiRemain(PumpElement pumpElement) : DrugDoubleValue(pumpElement);
/// <summary>
/// Represents the remaining time for volume fluid delivery, derived from a drug double value associated with a pump element.
/// </summary>
/// <remarks>
/// Inherits from <see cref="DrugDoubleValue"/> and is constructed with a <see cref="PumpElement"/> to capture time-related fluid volume metrics.
/// </remarks>
/// <!-- aidoc:v1 sig=9b38fa5 -->
public class VolumeFluidTimePdRemain(PumpElement pumpElement) : DrugDoubleValue(pumpElement);
/// <summary>
/// Represents the active sources of a pump element as a drug string value.
/// Inherits from <see cref="DrugStringValue"/>, encapsulating source information for pump operations.
/// </summary>
/// <!-- aidoc:v1 sig=ded4b3d -->
public class PumpActiveSources(PumpElement pumpElement) : DrugStringValue(pumpElement)
{
public string? ValueId { get; set; } = pumpElement.ValueId;
public string? ValueCodingSystem { get; set; } = pumpElement.ValueCodingSystem;
}
/// <summary>
/// Represents a drug value associated with a pump element, inheriting from the DrugStringValue base class.
/// </summary>
/// <!-- aidoc:v1 sig=284cad0 -->
public class Drug(PumpElement pumpElement) : DrugStringValue(pumpElement);
/// <summary>
/// Represents a pump mode as a drug-related string value, inheriting string-based value semantics from <see cref="DrugStringValue"/>.
/// </summary>
/// <!-- aidoc:v1 sig=d46f699 -->
public class PumpMode : DrugStringValue
{
/// <summary>
/// Initializes a new instance of the <see cref="PumpMode"/> class by forwarding the supplied <see cref="PumpElement"/> to the base constructor and computing the normalized mode identifier from its raw value. The type represents a pump mode value extracted from a pump element.
/// </summary>
/// <param name="pumpElement">The source element providing the raw mode text that is normalized to produce the mode identifier.</param>
/// <!-- aidoc:v1 sig=97f7b03 body=bdf432f -->
public PumpMode(PumpElement pumpElement) : base(pumpElement)
{
Value = pumpElement.Value?.ToString()?.SubstringAfter("pump-mode-").Replace("-", "_");
}
}
/// <summary>
/// Represents the operational status of a pump as a drug-related string value.
/// </summary>
/// <!-- aidoc:v1 sig=b46795e -->
public class PumpStatus : DrugStringValue
{
/// <summary>
/// Initializes a new instance of the <see cref="PumpStatus"/> class from the specified <paramref name="pumpElement"/>, deriving the <see cref="PumpStatus.Value"/> by stripping the "pump-status-" prefix and normalizing dashes to underscores.
/// </summary>
/// <param name="pumpElement">The <see cref="PumpElement"/> whose value is parsed to populate the status.</param>
/// <!-- aidoc:v1 sig=526c2d6 body=d13ab1e -->
public PumpStatus(PumpElement pumpElement) : base(pumpElement)
{
Value = pumpElement.Value?.ToString()?.SubstringAfter("pump-status-").Replace("-", "_");
}
}