# Class CalculatedObservations

Namespace
  adas_core.Application.Customizations.HPAZ

Assembly
  adas-core.Application.dll

Represents a service that provides calculated observations, receiving its dependencies through the supplied IServiceProvider.

    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?)

## Remarks

This class implements the ICalculatedObservations contract, exposing the behavior defined by that interface while relying on constructor-injected services for its operations.

## Constructors

### CalculatedObservations(IServiceProvider)

Represents a service that provides calculated observations, receiving its dependencies through the supplied IServiceProvider.

    public CalculatedObservations(IServiceProvider serviceProvider)

#### Parameters

`serviceProvider` IServiceProvider

#### Remarks

This class implements the ICalculatedObservations contract, exposing the behavior defined by that interface while relying on constructor-injected services for its operations.

## Methods

### CalculateActiveBolus(ObjectId)

Asynchronously calculates the active bolus for the specified patient.

    public Task CalculateActiveBolus(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose active bolus is to be calculated.

#### Returns

Task

### CalculateBlueCodeList(List<PatientObservation?>?)

Checks if a blue code observation Lists needs to be generated and inserts it.

    public Task CalculateBlueCodeList(List<PatientObservation?>? obsList)

#### Parameters

`obsList` List<PatientObservation>

#### Returns

Task

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

Calculates medicine observations for the specified patient based on their active medicines.

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

#### Parameters

`activeMedicines` List<Medicine>

  The list of medicines currently active for the patient.

`patientId` ObjectId

  The unique identifier of the patient whose medicine observations are being calculated.

#### Returns

Task

### CalculateOxygenationIndex(BasePatientObservationValue, string)

Oxygenation index is calculated => P_VAM x FiO2 x 100 / PaO2_Tidal the method is called when it receives P_VAM or FiO2 or PaO2_Tidal and tries to take the other values to perform the calculation if they are not in database then does nothing.

    public Task CalculateOxygenationIndex(BasePatientObservationValue obs, string name)

#### Parameters

`obs` BasePatientObservationValue
`name` string

#### Returns

Task

### FixTimeInconsistencyWithLast(PatientObservation)

Ensures chronological order of patient observations by adjusting a new observation's time to one second after the most recent observation with the same name, when its time is earlier than or equal to the previous one (compared at second precision). Returns the observation unchanged and logs an error if the observation name is null or empty.

    public Task<PatientObservation?> FixTimeInconsistencyWithLast(PatientObservation newObservation)

#### Parameters

`newObservation` PatientObservation

  The new patient observation to validate and potentially adjust for time consistency.

#### Returns

Task<PatientObservation>

  The patient observation with its time corrected if a time inconsistency was detected, otherwise the original observation.

### GetActiveTreatmentsByPatient(ObjectId)

Retrieves the active treatments associated with the specified patient identifier. Returns an empty collection when no active treatments are found.

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

#### Parameters

`id` ObjectId

  The unique identifier of the patient whose active treatments are being retrieved.

#### Returns

Task<IEnumerable<PatientTreatment>>

  A task that represents the asynchronous operation, containing a collection of active PatientTreatment records for the patient, or an empty collection if none exist.

### Map(PatientDiagnosis)

Maps a PatientDiagnosis instance. This method is a placeholder and has not been implemented yet.

    public Task<PatientDiagnosis> Map(PatientDiagnosis diagnosis)

#### Parameters

`diagnosis` PatientDiagnosis

  The PatientDiagnosis to be mapped.

#### Returns

Task<PatientDiagnosis>

  A task that represents the asynchronous operation, containing the mapped PatientDiagnosis.

#### Exceptions

NotImplementedException

  Thrown to indicate that the mapping logic has not been implemented.

### Map(PatientTreatment)

Maps a PatientTreatment instance, performing the required transformation logic.

    public Task<PatientTreatment> Map(PatientTreatment treatment)

#### Parameters

`treatment` PatientTreatment

  The PatientTreatment to be mapped.

#### Returns

Task<PatientTreatment>

  A task representing the asynchronous operation, containing the mapped PatientTreatment.

#### Exceptions

NotImplementedException

  Thrown in all cases because the method has not yet been implemented.

### Map(PumpObservation)

Maps the specified pump observation to a new PumpObservation instance asynchronously.

    public Task<PumpObservation> Map(PumpObservation pumpObservation)

#### Parameters

`pumpObservation` PumpObservation

  The source PumpObservation to map.

#### Returns

Task<PumpObservation>

  A task that represents the asynchronous mapping operation. The task result contains the mapped PumpObservation.

### MapSourceAlarm(PatientObservation, PatientObservationAlarm)

Maps fields from a PatientObservationAlarm onto an existing PatientObservation, copying the alarm's EventId to Code and Event to Name when those values are provided, and always copying the alarm's Value.

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

#### Parameters

`obs` PatientObservation

  The target PatientObservation instance that will be updated with values from the alarm.

`alarmToInsert` PatientObservationAlarm

  The source PatientObservationAlarm whose values are applied to `obs`.

#### Returns

Task<PatientObservation>

  A completed Task<TResult> containing the updated `obs`.

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

Maps the obs to an event or alarm depending on its type and inserts it if needed

    public Task<T?> Map<T>(T source, bool onlyByName) where T : BasePatientObservation

#### Parameters

`source` T

  Observation

`onlyByName` bool

  True if the observation needs to generate an alert

#### Returns

Task<T>

  Mapped observation

#### Type Parameters

`T`

  Type

### PreMapList(List<PatientObservation>)

Pre-maps a list of patient observations by creating deep copies, applying configuration-based mapping, and triggering blue code calculation. Returns the original list of patient observations unchanged.

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

#### Parameters

`listToMap` List<PatientObservation>

  The list of patient observations to process for mapping and blue code calculation.

#### Returns

Task<List<PatientObservation>>

  The original list of patient observations passed to the method.