# Class CalculatedObservations

Namespace
  adas_core.Application.Customizations.HUVH.UCIA

Assembly
  adas-core.Application.dll

Represents a concrete implementation of the ICalculatedObservations interface, providing functionality to manage a collection of calculated observations.

    public class CalculatedObservations : ICalculatedObservations

Inheritance
  object
  CalculatedObservations

Implements
  ICalculatedObservations

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### CalculatedObservations(IServiceProvider)

    public CalculatedObservations(IServiceProvider serviceProvider)

#### Parameters

`serviceProvider` IServiceProvider

## Methods

### CalculateActiveBolus(ObjectId)

Asynchronously calculates the active bolus for the specified patient.

    public Task CalculateActiveBolus(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The identifier of the patient whose active bolus should be calculated.

#### Returns

Task

#### Exceptions

NotImplementedException

  Thrown when the method is invoked, as the calculation logic has not yet been implemented.

### CalculateMedicineObservation(List<Medicine>, ObjectId)

Calculates medicine observations for a patient by validating the categories of their active medications. Typically invoked by the scheduler service to review current medication statuses.

    public Task CalculateMedicineObservation(List<Medicine> activeMedicines, ObjectId patientId)

#### Parameters

`activeMedicines` List<Medicine>

  The list of currently active medicines assigned to the patient.

`patientId` ObjectId

  The unique identifier of the patient whose medication categories will be checked.

#### Returns

Task

### FixTimeInconsistencyWithLast(PatientObservation)

Ensures the timestamp of the new observation does not collide with the most recent observation for the same patient and observation name. If the new observation's time is equal to or earlier than the last observation's time (compared at second precision), the new observation's time is incremented by one second. If the observation name is null or empty, the new observation is returned unchanged after logging an error.

    public Task<PatientObservation?> FixTimeInconsistencyWithLast(PatientObservation newObservation)

#### Parameters

`newObservation` PatientObservation

  The new patient observation whose timestamp should be adjusted to avoid time inconsistencies with prior observations.

#### Returns

Task<PatientObservation>

  The patient observation, with its `Time` adjusted when a time collision is detected, or the original observation when its name is null or empty.

### GetActiveTreatmentsByPatient(ObjectId)

Retrieves all currently active treatments associated with the specified patient.

    public Task<IEnumerable<PatientTreatment?>> GetActiveTreatmentsByPatient(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the patient whose active treatments should be retrieved.

#### Returns

Task<IEnumerable<PatientTreatment>>

  A collection of PatientTreatment objects representing the patient's active treatments.

### Map(PatientDiagnosis)

Asynchronously maps a PatientDiagnosis instance to its corresponding data representation or transfer model.

    public Task<PatientDiagnosis> Map(PatientDiagnosis diagnosis)

#### Parameters

`diagnosis` PatientDiagnosis

  The PatientDiagnosis to be mapped.

#### Returns

Task<PatientDiagnosis>

  A task that represents the asynchronous mapping operation, containing the resulting PatientDiagnosis.

#### Exceptions

NotImplementedException

  Thrown when the method is invoked, as the mapping logic has not yet been implemented.

### Map(PatientTreatment)

Maps a PatientTreatment by determining the appropriate order control status, handling cases for missing placer orders, previous expired treatments, and treatments with a defined end time.

    public Task<PatientTreatment> Map(PatientTreatment treatment)

#### Parameters

`treatment` PatientTreatment

  The patient treatment to map and update.

#### Returns

Task<PatientTreatment>

  The patient treatment with its order control set according to the evaluated business rules.

### Map(PumpObservation)

Maps a PumpObservation instance to its output representation as a pass-through operation.

    public Task<PumpObservation> Map(PumpObservation pumpObservation)

#### Parameters

`pumpObservation` PumpObservation

  The pump observation to map.

#### Returns

Task<PumpObservation>

  A completed task containing the provided PumpObservation.

### MapSourceAlarm(PatientObservation, PatientObservationAlarm)

Maps a source alarm to a patient observation. Returns the provided observation without applying changes from the alarm.

    public Task<PatientObservation> MapSourceAlarm(PatientObservation obs, PatientObservationAlarm alarmToInsert)

#### Parameters

`obs` PatientObservation

  The patient observation to be returned as the mapping result.

`alarmToInsert` PatientObservationAlarm

  The patient observation alarm intended to be associated with the observation.

#### Returns

Task<PatientObservation>

  A task containing the patient observation.

### Map<T>(T, bool)

Processes a patient observation by dispatching to the appropriate domain-specific calculation based on the observation name, handling over-sedation, ventilation mode, ECMO location, over-analgesia, driving pressure, ROX index, diuresis, and rehabilitation alarm assessments.

    public Task<T?> Map<T>(T obs, bool onlyByName = false) where T : BasePatientObservation

#### Parameters

`obs` T

  The patient observation to map; may be replaced with the result of the matched asynchronous calculation when applicable.

`onlyByName` bool

  Indicates whether the mapping should be performed using only the observation's name.

#### Returns

Task<T>

  The processed patient observation, potentially updated by the applicable calculation.

#### Type Parameters

`T`

### PreMapList(List<PatientObservation>)

Pre-maps the provided list of patient observations, returning it as a completed task for asynchronous processing pipelines.

    public Task<List<PatientObservation>> PreMapList(List<PatientObservation> listToInsert)

#### Parameters

`listToInsert` List<PatientObservation>

  The list of patient observations to pre-map before insertion.

#### Returns

Task<List<PatientObservation>>

  A completed task containing the provided list of patient observations.

### SendAlarm(PatientObservation, string, Name?)

Asynchronously sends an alarm notification associated with a patient observation, identified by a name and an optional alarm code.

    public Task SendAlarm(PatientObservation obs, string name, AlarmEnum.Name? code)

#### Parameters

`obs` PatientObservation

  The patient observation that triggers the alarm.

`name` string

  The name associated with the alarm.

`code` AlarmEnum.Name?

  The optional alarm code categorizing the alarm, or null if no code is specified.

#### Returns

Task

  A task that represents the asynchronous alarm sending operation.

#### Exceptions

NotImplementedException

  Thrown to indicate that the method has not yet been implemented.