# Class AlarmRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Repository for managing patient observation alarms in MongoDB. Provides methods to retrieve aggregated patient observations based on specified fields and expiration status. Implements the IAlarmRepository interface and extends the MongoRepository base class for common MongoDB operations.

    public class AlarmRepository : MongoRepository<PatientObservationAlarm>, IAlarmRepository, IMongoRepository<PatientObservationAlarm>

Inheritance
  object
  MongoRepository<PatientObservationAlarm>
  AlarmRepository

Implements
  IAlarmRepository
  IMongoRepository<PatientObservationAlarm>

Inherited Members
  MongoRepository<PatientObservationAlarm>.Db
  MongoRepository<PatientObservationAlarm>.Collection
  MongoRepository<PatientObservationAlarm>.InsertOneAsync(PatientObservationAlarm)
  MongoRepository<PatientObservationAlarm>.UpdateOneAsync(ObjectId, PatientObservationAlarm)
  MongoRepository<PatientObservationAlarm>.DeleteAsync(ObjectId)
  MongoRepository<PatientObservationAlarm>.InsertInitialLoad()
  MongoRepository<PatientObservationAlarm>.InsertManyAsync(List<PatientObservationAlarm>)
  MongoRepository<PatientObservationAlarm>.UpdateManyObjectIdAsync(string, ObjectId, ObjectId)
  MongoRepository<PatientObservationAlarm>.DeleteAsync(string)
  MongoRepository<PatientObservationAlarm>.CollectionExists(string)
  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

### AlarmRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<AlarmRepository>)

Constructor for the AlarmRepository class. Initializes the repository with the provided API settings, MongoDB database instance, and logger. Validates the input parameters and sets up the necessary configurations for accessing the patient observation alarms collection in MongoDB.

    public AlarmRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<AlarmRepository> logger)

#### Parameters

`apiSettings` IOptions<ApiSettings>

  The API settings containing configuration for the MongoDB collection name and other relevant settings.

`database` IMongoDatabase

  The MongoDB database instance.

`logger` ILogger<AlarmRepository>

  The logger instance for logging errors and information.

#### Exceptions

ArgumentNullException

  Thrown when any of the input parameters are null.

## Methods

### AggregatedPatientLastObservationsByField(ObjectId, List<Field>?)

Retrieves a list of patient observation alarms for a specific patient based on the provided filter criteria. The method allows filtering observations by name and expiration status, and returns the most recent observations for each specified field. If no filter is provided, it retrieves all observations for the patient sorted by time in descending order.

    public Task<List<PatientObservationAlarm>> AggregatedPatientLastObservationsByField(ObjectId patientId, List<Field>? filterObservations = null)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient.

`filterObservations` List<Field>

  A list of fields to filter the observations. If null, all observations for the patient are retrieved.

#### Returns

Task<List<PatientObservationAlarm>>

  A list of patient observation alarms matching the filter criteria.

### AggregatedPatientNotExpiredObservationsByField(ObjectId, List<Field>?, List<ConfigObservation>)

Retrieves a list of patient observation alarms for a specific patient based on the provided filter criteria, including expiration status.

    public Task<List<PatientObservationAlarm>> AggregatedPatientNotExpiredObservationsByField(ObjectId patientId, List<Field>? filterObservations, List<ConfigObservation> configAlarm)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient.

`filterObservations` List<Field>

  A list of fields to filter the observations. If null, all observations for the patient are retrieved.

`configAlarm` List<ConfigObservation>

  A list of configuration settings for the observations, including expiration times.

#### Returns

Task<List<PatientObservationAlarm>>

  A list of patient observation alarms matching the filter criteria and expiration settings.

### CreateIndexes()

Creates indexes for the patient observation alarms collection in MongoDB to optimize query performance.

    public override Task CreateIndexes()

#### Returns

Task

  A task that represents the asynchronous operation of creating indexes.

### GetCollectionName()

Gets the name of the MongoDB collection for patient observation alarms. The collection name is determined based on the API settings provided during the repository initialization. If the collection name is not specified in the API settings, it defaults to "patients_alarms".

    public override string GetCollectionName()

#### Returns

string

  The name of the MongoDB collection for patient observation alarms.