# Class CalculatedObservations

Namespace
  adas_core.Application.Customizations.HUVH.UCIN

Assembly
  adas-core.Application.dll

Represents a concrete implementation of the ICalculatedObservations interface, providing a collection of calculated observation data.

    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)

Calculates the active bolus for the specified patient.

    public Task CalculateActiveBolus(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient for whom the active bolus is calculated.

#### Returns

Task

#### Exceptions

NotImplementedException

  Thrown because the method has not been implemented yet.

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

Persists a multivalue medication observation for the specified patient based on the currently active medicines, expiring any previous medication observation recorded for the same patient.

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

#### Parameters

`activeMedicines` List<Medicine>

  The list of active medicines from which distinct medication names are extracted to build the observation value.

`patientId` ObjectId

  The identifier of the patient for whom the medication observation is calculated and stored.

#### Returns

Task

### FixTimeInconsistencyWithLast(PatientObservation)

Adjusts the time of a new patient observation to ensure it is at least one second after the most recent observation with the same name, preventing time conflicts. If the observation name is null or empty, the method logs an error and returns the observation unchanged.

    public Task<PatientObservation?> FixTimeInconsistencyWithLast(PatientObservation newObservation)

#### Parameters

`newObservation` PatientObservation

  The new patient observation whose time may be adjusted to follow the most recent observation for the same patient and measurement.

#### Returns

Task<PatientObservation>

  The patient observation with a corrected time if a time conflict was detected, or the original observation if no adjustment was needed or the name was invalid.

### GetActiveTreatmentsByPatient(ObjectId)

Asynchronously retrieves the collection of active treatments associated with the specified patient identifier.

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

#### Parameters

`id` ObjectId

  The unique MongoDB.Bson.ObjectId of the patient whose active treatments should be fetched.

#### Returns

Task<IEnumerable<PatientTreatment>>

  A task that represents the asynchronous operation, containing an IEnumerable<T> of nullable PatientTreatment instances for the patient.

### Map(PatientDiagnosis)

Asynchronously maps a PatientDiagnosis to a target PatientDiagnosis representation.

    public Task<PatientDiagnosis> Map(PatientDiagnosis diagnosis)

#### Parameters

`diagnosis` PatientDiagnosis

  The source PatientDiagnosis instance to be mapped.

#### Returns

Task<PatientDiagnosis>

  A Task<TResult> that represents the asynchronous mapping operation, containing the mapped 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 its OrderControlType based on prior treatments and expiration status. If the placer order number is missing, the treatment is returned unchanged. The order control is set to Xo when previous treatments exist, Dc when the treatment has expired (end time set), or Nw otherwise.

    public Task<PatientTreatment> Map(PatientTreatment treatment)

#### Parameters

`treatment` PatientTreatment

  The patient treatment to map, including its placer order, end time, and medicines.

#### Returns

Task<PatientTreatment>

  The mapped PatientTreatment with its order control type and medicines updated.

### Map(PumpObservation)

Maps the provided PumpObservation instance by returning it unchanged, wrapped in a completed task.

    public Task<PumpObservation> Map(PumpObservation pumpObservation)

#### Parameters

`pumpObservation` PumpObservation

  The pump observation to map.

#### Returns

Task<PumpObservation>

  A completed Task<TResult> containing the provided PumpObservation.

### MapSourceAlarm(PatientObservation, PatientObservationAlarm)

Maps a source alarm onto a patient observation, returning the observation unchanged without applying the alarm data.

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

#### Parameters

`obs` PatientObservation

  The patient observation that the alarm is to be associated with.

`alarmToInsert` PatientObservationAlarm

  The alarm intended to be inserted into the observation.

#### Returns

Task<PatientObservation>

  A task containing the patient observation, returned as-is.

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

Maps a patient observation by applying the appropriate calculation logic based on its name, handling multi-value interventions, surgeries, complexity scoring, pre/post saturation differences, pain scales, and last defecation value.

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

#### Parameters

`obs` T

  The patient observation to be mapped, which may be transformed depending on its name.

`onlyByName` bool

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

#### Returns

Task<T>

  The mapped patient observation, potentially enriched with computed values, wrapped in a task.

#### Type Parameters

`T`

### PreMapList(List<PatientObservation>)

Performs a pre-mapping operation on a list of patient observations, returning the list for further processing.

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

#### Parameters

`listToInsert` List<PatientObservation>

  The list of patient observations to pre-map.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing the provided list of patient observations.

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

Sends an alarm notification for the specified patient observation, identified by name and 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 type of alarm to be sent.

#### Returns

Task

#### Exceptions

NotImplementedException

  Thrown because the method has not been implemented.