# Class RecordingAlertRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Provides a MongoDB-backed repository implementation for PatientRecordingAlert entities, exposing data access operations defined by the IRecordingAlertRepository contract.

    public class RecordingAlertRepository : MongoRepository<PatientRecordingAlert>, IRecordingAlertRepository, IMongoRepository<PatientRecordingAlert>

Inheritance
  object
  MongoRepository<PatientRecordingAlert>
  RecordingAlertRepository

Implements
  IRecordingAlertRepository
  IMongoRepository<PatientRecordingAlert>

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

### RecordingAlertRepository(IOptions<ApiSettings>, IMongoDatabase)

    public RecordingAlertRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)

#### Parameters

`apiSettings` IOptions<ApiSettings>
`database` IMongoDatabase

## Methods

### AggregatedPatientLastObservations(ObjectId, int)

Retrieves the most recent observations for a specified patient from MongoDB using an aggregation pipeline, grouped by observation name, returning up to the specified number of records per group.

    public Task<List<PatientRecordingAlert>> AggregatedPatientLastObservations(ObjectId patientId, int num)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose observations are being retrieved.

`num` int

  The maximum number of recent observations to return per grouped observation name.

#### Returns

Task<List<PatientRecordingAlert>>

  A task containing a list of PatientRecordingAlert objects representing the aggregated last observations for the patient.

### CreateIndexes()

Creates MongoDB indexes for the PatientRecordingAlert collection, including a non-unique background index on the patientid field to optimize queries by patient.

    public override Task CreateIndexes()

#### Returns

Task

### DeleteAsync(ObjectId)

Deletes a patient recording alert identified by the specified identifier from the underlying collection.

    public Task DeleteAsync(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the patient recording alert to delete.

#### Returns

Task

### DeleteByPatientId(ObjectId)

Deletes all patient recording alerts associated with the specified patient identifier.

    public Task DeleteByPatientId(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose recording alerts will be removed.

#### Returns

Task

### DeleteOlderDaysAsync(string, int)

Deletes a single PatientRecordingAlert document whose Name matches the provided value and whose Time is older than the retention period defined by `retentionPolicyValue` days from now.

    public Task DeleteOlderDaysAsync(string name, int retentionPolicyValue)

#### Parameters

`name` string

  The name of the patient recording alert used to match the document for deletion.

`retentionPolicyValue` int

  The retention period in days; the cutoff time is calculated as UTC now minus this number of days.

#### Returns

Task

### DeleteOlderNumberAsync(string, int)

Deletes PatientRecordingAlert records that exceed the retention policy, keeping only the most recent records for the specified name. The method filters alerts by name, sorts them by time in descending order, skips the most recent records up to the retention threshold, and removes the remaining older entries.

    public Task DeleteOlderNumberAsync(string name, int retentionPolicyValue)

#### Parameters

`name` string

  The name used to filter the alerts subject to the retention policy.

`retentionPolicyValue` int

  The number of most recent records to retain; any additional older records will be deleted.

#### Returns

Task

### FindByPatientIdAsync(ObjectId)

Retrieves all patient recording alerts associated with the specified patient identifier.

    public Task<IAsyncCursor<PatientRecordingAlert>> FindByPatientIdAsync(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose recording alerts should be retrieved.

#### Returns

Task<IAsyncCursor<PatientRecordingAlert>>

  A task representing the asynchronous operation, containing a cursor over the matching patient recording alerts.

### FindLastObservations(ObjectId, string, int)

Retrieves the most recent observations for a specified patient, filtered by observation name and ordered by time in descending order.

    public Task<List<PatientRecordingAlert>> FindLastObservations(ObjectId patientId, string name, int num = 2)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose observations are being queried.

`name` string

  The name of the observation used to filter the results.

`num` int

  The maximum number of observations to return. Defaults to 2.

#### Returns

Task<List<PatientRecordingAlert>>

  A list of PatientRecordingAlert entries containing the latest matching observations for the patient.

### GetCollectionName()

Retrieves the collection name for patients recording alerts, returning the configured API setting value or a default fallback when the setting is not available.

    public override string GetCollectionName()

#### Returns

string

  The collection name from `_apiSettings.PatientsRecordingAlerts`, or the default value "patients_recordingalerts" if the setting is null.

### InsertOneAsync(PatientRecordingAlert)

Inserts a new patient recording alert into the underlying collection asynchronously.

    public override Task InsertOneAsync(PatientRecordingAlert patientRecordingAlert)

#### Parameters

`patientRecordingAlert` PatientRecordingAlert

  The patient recording alert document to be inserted.

#### Returns

Task

### UpdateManyObjectId(string, ObjectId, ObjectId)

Updates many records by replacing the old MongoDB.Bson.ObjectId with the new one, identified by the specified `nameId`. Delegates the operation to the asynchronous `UpdateManyObjectIdAsync` implementation.

    public Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId)

#### Parameters

`nameId` string

  The identifier of the field or collection used to target the records to update.

`id` ObjectId

  The new MongoDB.Bson.ObjectId value to assign to the matched records.

`oldId` ObjectId

  The existing MongoDB.Bson.ObjectId value to be replaced.

#### Returns

Task