# Class PumpAlarmStateRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Represents a MongoDB-based repository for PumpAlarmState entities, providing concrete data access functionality defined by the IPumpAlarmStateRepository contract.

    public class PumpAlarmStateRepository : MongoRepository<PumpAlarmState>, IMongoRepository<PumpAlarmState>, IPumpAlarmStateRepository

Inheritance
  object
  MongoRepository<PumpAlarmState>
  PumpAlarmStateRepository

Implements
  IMongoRepository<PumpAlarmState>
  IPumpAlarmStateRepository

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

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

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

#### Parameters

`apiSettings` IOptions<ApiSettings>
`database` IMongoDatabase

## Methods

### CreateIndexes()

Creates the indexes required for the collection. The base implementation is a no-op; derived classes should override this method to define their own indexes.

    public override Task CreateIndexes()

#### Returns

Task

  A Task representing the asynchronous index creation operation.

### DeleteByPatientId(ObjectId)

Asynchronously deletes all records associated with the specified patient identifier by removing every document whose `PatientId` matches the supplied value.

    public Task DeleteByPatientId(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose associated records should be removed.

#### Returns

Task

### FindActiveAsync(string, AlarmType?, string?)

Retrieves the first active PumpAlarmState matching the specified device and optional alarm criteria. The filter is always constrained by `deviceId`, and additionally by `alarmType` and `alarmCodeMdc` when those values are provided. Returns `null` when no matching alarm state is found.

    public Task<PumpAlarmState?> FindActiveAsync(string deviceId, PumpEnum.AlarmType? alarmType, string? alarmCodeMdc = null)

#### Parameters

`deviceId` string

  The identifier of the device whose alarm state should be retrieved. Always applied to the query filter.

`alarmType` PumpEnum.AlarmType?

  The optional alarm type used to further narrow the filter. When `null`, the alarm type is not applied.

`alarmCodeMdc` string

  The optional alarm code (MDC) used to further narrow the filter. Ignored when `null`, empty, or whitespace.

#### Returns

Task<PumpAlarmState>

  A PumpAlarmState instance if a matching record is found; otherwise, `null`.

### FindAllActiveByDeviceAsync(string)

Asynchronously retrieves all pump alarm states associated with the specified device identifier.

    public Task<IEnumerable<PumpAlarmState>> FindAllActiveByDeviceAsync(string deviceId)

#### Parameters

`deviceId` string

  The unique identifier of the device whose pump alarm states are being queried.

#### Returns

Task<IEnumerable<PumpAlarmState>>

  A task that represents the asynchronous operation. The task result contains an IEnumerable<T> with the pump alarm states matching the provided device identifier.

### GetCollectionName()

Gets the collection name for the pump alarm state, returning the value configured in the API settings or the default "pump_alarm_state" when the configuration is not set.

    public override string GetCollectionName()

#### Returns

string

  The configured collection name, or the default "pump_alarm_state" if the API setting is null.

### RemoveAsync(string?, AlarmType?, string?)

Removes pump alarm state records from the collection that match the specified device identifier, optionally narrowed by alarm type and/or alarm code MDC.

    public Task RemoveAsync(string? deviceId, PumpEnum.AlarmType? alarmType, string? alarmCodeMdc = null)

#### Parameters

`deviceId` string

  The identifier of the device whose alarm state records should be removed. Used as a mandatory filter criterion.

`alarmType` PumpEnum.AlarmType?

  The optional alarm type to further restrict which records are deleted. When null, records of any alarm type for the device are removed.

`alarmCodeMdc` string

  The optional alarm code MDC used to further narrow the deletion. Blank or whitespace values are ignored.

#### Returns

Task

### UpdateManyObjectIdByFieldNameAsync(string, ObjectId, ObjectId)

Asynchronously updates all PumpAlarmState documents that match the specified `oldId` on the given `fieldName`, replacing the value with `newId`. Used to bulk rewire MongoDB.Bson.ObjectId references stored on a dynamic field.

    public Task<long> UpdateManyObjectIdByFieldNameAsync(string fieldName, ObjectId newId, ObjectId oldId)

#### Parameters

`fieldName` string

  Name of the document field to filter and update.

`newId` ObjectId

  The new MongoDB.Bson.ObjectId value to assign to the field.

`oldId` ObjectId

  The existing MongoDB.Bson.ObjectId value used to locate matching documents.

#### Returns

Task<long>

  The number of documents that were modified by the update operation.

### UpsertActiveAsync(PumpAlarmState)

Inserts a new active pump alarm state or updates the existing one, maintaining the current state for the alarm.

    public Task UpsertActiveAsync(PumpAlarmState state)

#### Parameters

`state` PumpAlarmState

  The pump alarm state to upsert as the active record.

#### Returns

Task