# Interface IObservationRepository

Namespace
  adas_core.Application.Repositories.Interfaces

Assembly
  adas-core.Application.dll

    public interface IObservationRepository : IMongoRepository<PatientObservation>

Inherited Members
  IMongoRepository<PatientObservation>.Collection
  IMongoRepository<PatientObservation>.GetCollectionName()
  IMongoRepository<PatientObservation>.UpdateOneAsync(ObjectId, PatientObservation)

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Methods

### AggregatedPatientActiveIntravenousLinesObservations(ObjectId)

Retrieves the aggregated active intravenous lines observations for the specified patient.

    Task<List<PatientObservation?>> AggregatedPatientActiveIntravenousLinesObservations(ObjectId patientId)

#### Parameters

`patientId` ObjectId

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

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing a list of PatientObservation entries representing the patient's active intravenous lines observations, where each entry may be null.

### AggregatedPatientGroupedObservations(ObjectId, GroupedField)

Asynchronously aggregates a patient's observations grouped by the specified field.

    Task<List<BsonDocument>> AggregatedPatientGroupedObservations(ObjectId patientId, GroupedField groupedField)

#### Parameters

`patientId` ObjectId

  The identifier of the patient whose observations will be aggregated.

`groupedField` GroupedField

  The field used to group the patient's observations during aggregation.

#### Returns

Task<List<BsonDocument>>

  A task that represents the asynchronous operation, containing a list of BSON documents with the aggregated results.

### AggregatedPatientLastObservations(ObjectId, int, List<string>?)

Asynchronously retrieves the most recent aggregated observations for a specified patient, returning up to the requested number of entries. Optionally filters the results to include only observations whose identifiers match the provided list.

    Task<List<PatientObservation>> AggregatedPatientLastObservations(ObjectId patientId, int num, List<string>? filterObservations = null)

#### Parameters

`patientId` ObjectId

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

`num` int

  The maximum number of most recent observations to return.

`filterObservations` List<string>

  An optional list of observation identifiers used to restrict the returned results; if null, no filter is applied.

#### Returns

Task<List<PatientObservation>>

  A task representing the asynchronous operation, containing a list of the patient's most recent PatientObservation records.

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

Retrieves the most recent patient observations, aggregated by field, for the specified patient.

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

#### Parameters

`patientId` ObjectId

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

`filterObservations` List<Field>

  An optional list of fields to filter the observations by; if null, observations for all fields are returned.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation. The task result contains a list of the latest patient observations grouped by field.

### AggregatedPatientLastObservationsByLastDate(ObjectId, int, DateTime, List<string>?)

Retrieves the most recent aggregated patient observations for the specified patient up to the given last date, optionally filtered by a set of observation names.

    Task<List<PatientObservation>> AggregatedPatientLastObservationsByLastDate(ObjectId patientId, int num, DateTime lastDate, List<string>? filterObservations = null)

#### Parameters

`patientId` ObjectId

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

`num` int

  The maximum number of observations to return.

`lastDate` DateTime

  The cutoff date; only observations on or before this date are considered.

`filterObservations` List<string>

  An optional list of observation names to restrict the results to. If null, no observation-name filter is applied.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing the list of aggregated PatientObservation entries that match the criteria.

### DeleteAsync(ObjectId)

Asynchronously deletes the entity identified by the specified identifier.

    Task DeleteAsync(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the entity to delete.

#### Returns

Task

  A task that represents the asynchronous delete operation.

### DeleteByPatientId(ObjectId)

Deletes records associated with the specified patient identifier.

    Task DeleteByPatientId(ObjectId id)

#### Parameters

`id` ObjectId

  The ObjectId of the patient whose related records should be removed.

#### Returns

Task

### DeleteOlderDaysAsync(string, int)

Asynchronously deletes patient observations older than the specified retention period and returns the records that were removed.

    Task<List<PatientObservation>> DeleteOlderDaysAsync(string name, int retentionPolicyValue)

#### Parameters

`name` string

  The identifier used to locate the relevant patient observations to be evaluated for deletion.

`retentionPolicyValue` int

  The retention period in days; observations older than this value will be deleted.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing a list of the deleted PatientObservation records.

### DeleteOlderNumberAsync(string, int)

Asynchronously deletes patient observations based on the specified name and retention policy value.

    Task<List<PatientObservation>> DeleteOlderNumberAsync(string name, int retentionPolicyValue)

#### Parameters

`name` string

  The name used to identify or filter the patient observations to be deleted.

`retentionPolicyValue` int

  The retention policy threshold value that determines which older observations should be removed.

#### Returns

Task<List<PatientObservation>>

  A task representing the asynchronous operation, containing the list of patient observations that were deleted.

### DeleteOlderSecondsAsync(string, int)

Asynchronously deletes patient observations older than the specified number of seconds and returns the affected records.

    Task<List<PatientObservation>> DeleteOlderSecondsAsync(string name, int value)

#### Parameters

`name` string

  The name used to identify the patient observations to filter for deletion.

`value` int

  The age threshold in seconds; observations older than this value will be deleted.

#### Returns

Task<List<PatientObservation>>

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

### ExistBySystemId(ObjectId, string)

Asynchronously checks whether a record exists for the specified patient identified by the given system identifier.

    Task<bool> ExistBySystemId(ObjectId patientid, string systemId)

#### Parameters

`patientid` ObjectId

  The unique identifier of the patient whose record is being checked.

`systemId` string

  The system identifier used to look up the patient's record.

#### Returns

Task<bool>

  A task that represents the asynchronous operation. The task result is `true` if a matching record exists; otherwise, `false`.

### ExpireExpiredObservations(List<ConfigObservation>)

Asynchronously processes and expires the specified configuration observations that have met their expiration criteria.

    Task ExpireExpiredObservations(List<ConfigObservation> configObservationsToExpire)

#### Parameters

`configObservationsToExpire` List<ConfigObservation>

  The list of configuration observations to expire.

#### Returns

Task

### FindAll()

Retrieves all patient observation records.

    Task<IEnumerable<PatientObservation>> FindAll()

#### Returns

Task<IEnumerable<PatientObservation>>

  A task representing the asynchronous operation, containing a collection of PatientObservation entries.

### FindAllLastPatientObservationTime()

Asynchronously retrieves the most recent observation timestamp for every patient, returning a mapping of patient identifiers to their last observation times.

    Task<Dictionary<ObjectId, DateTime>> FindAllLastPatientObservationTime()

#### Returns

Task<Dictionary<ObjectId, DateTime>>

  A task that represents the asynchronous operation. The task result contains a dictionary where each key is a patient MongoDB.Bson.ObjectId and the associated value is the date and time of that patient's last observation.

### FindAnyBeforeDate(ObjectId, DateTime)

Asynchronously retrieves all patient observations recorded for the specified patient before the given date.

    Task<List<PatientObservation>> FindAnyBeforeDate(ObjectId patientId, DateTime date)

#### Parameters

`patientId` ObjectId

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

`date` DateTime

  The cutoff date; only observations recorded prior to this date are returned.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing a list of patient observations found before the specified date.

### FindAnyWithSameDate(ObjectId, string?, DateTime)

Finds any existing patient observations for the specified patient that share the same date, optionally filtered by observation name.

    Task<List<PatientObservation>?> FindAnyWithSameDate(ObjectId patientId, string? name, DateTime date)

#### Parameters

`patientId` ObjectId

  The identifier of the patient whose observations are being searched.

`name` string

  The optional name of the observation to match; if null, observations of any name are considered.

`date` DateTime

  The date used to match observations recorded on the same day.

#### Returns

Task<List<PatientObservation>>

  A task that returns a list of matching PatientObservation instances, or `null` if no matching observations are found.

### FindById(ObjectId)

Asynchronously retrieves a patient observation by its unique identifier, returning `null` when no matching record is found.

    Task<PatientObservation?> FindById(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the patient observation to locate.

#### Returns

Task<PatientObservation>

  A Task<TResult> that resolves to the matching PatientObservation, or `null` if no observation exists for the given identifier.

### FindByName(string, DateTime?)

Asynchronously retrieves patient observations matching the specified name, optionally filtered by the provided date.

    Task<IEnumerable<PatientObservation>> FindByName(string name, DateTime? date)

#### Parameters

`name` string

  The name used to look up the patient observations.

`date` DateTime?

  The optional date used to filter the observations; when null, results are not restricted by date.

#### Returns

Task<IEnumerable<PatientObservation>>

  A task that represents the asynchronous operation, containing a collection of PatientObservation entries that match the criteria.

### FindByPatientId(ObjectId)

Asynchronously retrieves a list of patient observations associated with the specified patient identifier. Returns null when no observations are found for the patient.

    Task<List<PatientObservation>?> FindByPatientId(ObjectId id)

#### Parameters

`id` ObjectId

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

#### Returns

Task<List<PatientObservation>>

  A task containing a list of PatientObservation objects for the specified patient, or null if no observations are found.

### FindByPatientIdAndCodingSystemAsync(ObjectId, string, string)

Asynchronously retrieves the PatientObservation records associated with the specified patient that belong to a given coding system, optionally filtered by name.

    Task<IAsyncCursor<PatientObservation>> FindByPatientIdAndCodingSystemAsync(ObjectId patientId, string codingSystem, string name)

#### Parameters

`patientId` ObjectId

  The identifier of the patient whose observations are being queried.

`codingSystem` string

  The coding system used to classify the observations (e.g., LOINC, SNOMED).

`name` string

  The name of the observation to filter within the coding system.

#### Returns

Task<IAsyncCursor<PatientObservation>>

  A Task<TResult> that yields an MongoDB.Driver.IAsyncCursor<TDocument> streaming the matching PatientObservation documents.

### FindByPatientIdAsync(ObjectId)

Asynchronously retrieves the collection of patient observations associated with the specified patient identifier.

    Task<IAsyncCursor<PatientObservation>> FindByPatientIdAsync(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose observations are to be retrieved.

#### Returns

Task<IAsyncCursor<PatientObservation>>

  A task that represents the asynchronous operation, containing an MongoDB.Driver.IAsyncCursor<TDocument> of PatientObservation instances to iterate through the matching records.

### FindLastNotExpiredObservatonsByPatient(ObjectId, string, int?, int?)

Asynchronously retrieves the most recent non-expired patient observations matching the specified name, supporting optional pagination.

    Task<IEnumerable<PatientObservation>> FindLastNotExpiredObservatonsByPatient(ObjectId patientId, string name, int? endAfter = null, int? num = null)

#### Parameters

`patientId` ObjectId

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

`name` string

  The name of the observation to filter by.

`endAfter` int?

  Optional pagination cursor indicating the number of results to skip.

`num` int?

  Optional maximum number of observations to return.

#### Returns

Task<IEnumerable<PatientObservation>>

  A task that represents the asynchronous operation, containing a collection of matching PatientObservation objects.

### FindLastObservationBeforeDate(ObjectId, string?, DateTime)

Retrieves the most recent PatientObservation for the specified patient recorded before the given date, optionally filtered by observation name.

    Task<PatientObservation?> FindLastObservationBeforeDate(ObjectId patientId, string? name, DateTime date)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose observation is being queried.

`name` string

  The optional name of the observation to filter by. If `null`, observations of any name are considered.

`date` DateTime

  The cutoff date; only observations recorded strictly before this date are eligible.

#### Returns

Task<PatientObservation>

  A task that resolves to the matching PatientObservation if found, or `null` if no observation exists before the specified date.

### FindLastObservations(ObjectId, string, string, int)

Retrieves the most recent patient observations that match the specified coding system and code, returning up to the requested number of results.

    Task<IEnumerable<PatientObservation>> FindLastObservations(ObjectId patientId, string codingSystem, string code, int num = 2)

#### Parameters

`patientId` ObjectId

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

`codingSystem` string

  The coding system used to classify the observations (for example, LOINC, SNOMED).

`code` string

  The specific code within the coding system identifying the type of observation to retrieve.

`num` int

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

#### Returns

Task<IEnumerable<PatientObservation>>

  A task that yields a collection of the matching PatientObservation records, ordered from most recent to oldest, containing at most `num` entries.

### FindLastObservationsByCodingSystem(ObjectId, string, int)

Retrieves the most recent patient observations filtered by the specified coding system.

    Task<List<PatientObservation>> FindLastObservationsByCodingSystem(ObjectId patientId, string codingSystem, int num = 10)

#### Parameters

`patientId` ObjectId

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

`codingSystem` string

  The coding system used to filter the observations.

`num` int

  The maximum number of recent observations to return. Defaults to 10.

#### Returns

Task<List<PatientObservation>>

  A task that represents the asynchronous operation, containing a list of the patient's most recent observations matching the coding system.

### FindLatestUniqueValuesByName(ObjectId, string, int?)

Retrieves the most recent unique patient observations matching the specified name for the given patient, returning a list of PatientObservation entries.

    Task<List<PatientObservation>> FindLatestUniqueValuesByName(ObjectId patientId, string name, int? expires)

#### Parameters

`patientId` ObjectId

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

`name` string

  The name used to match the relevant patient observations.

`expires` int?

  An optional expiration value in seconds used to control the time window for the lookup; if `null`, no expiration is applied.

#### Returns

Task<List<PatientObservation>>

  A task that resolves to a list of the latest unique PatientObservation records matching the specified name for the patient. The list is empty if no matching observations are found.

### FindNotExpired(List<string?>?)

Asynchronously retrieves patient observations that have not expired, optionally filtered by the specified observation identifiers.

    Task<IEnumerable<PatientObservation>> FindNotExpired(List<string?>? filterObservations)

#### Parameters

`filterObservations` List<string>

  An optional list of observation identifiers used to narrow the result set. May be null or contain null entries.

#### Returns

Task<IEnumerable<PatientObservation>>

  A task that resolves to a collection of non-expired PatientObservation instances matching the filter criteria.

### GetPaginatedObservations(PaginationFilter)

Retrieves a paginated, fluent-queryable collection of patient observations based on the provided pagination filter.

    IFindFluent<PatientObservation, PatientObservation> GetPaginatedObservations(PaginationFilter filter)

#### Parameters

`filter` PaginationFilter

  The pagination filter that defines the page size, page number, and sorting criteria applied to the observations.

#### Returns

IFindFluent<PatientObservation, PatientObservation>

  An MongoDB.Driver.IFindFluent<TDocument, TProjection> for PatientObservation that allows further refinement and execution of the paginated query.

### InsertOneAsync(PatientObservation)

Asynchronously inserts a single PatientObservation record into the underlying data store.

    Task InsertOneAsync(PatientObservation patientObservation)

#### Parameters

`patientObservation` PatientObservation

  The patient observation entity to persist.

#### Returns

Task

### Update(PatientObservation)

Updates an existing patient observation with the provided data.

    Task Update(PatientObservation observation)

#### Parameters

`observation` PatientObservation

  The patient observation containing the updated information to be persisted.

#### Returns

Task

### UpdateExpiredObservations(List<PatientObservation>)

Asynchronously updates the state of patient observations that have expired, applying the appropriate expiration handling to each item in the provided list.

    Task UpdateExpiredObservations(List<PatientObservation> expiredObservations)

#### Parameters

`expiredObservations` List<PatientObservation>

  The list of patient observations that have expired and require their state to be updated.

#### Returns

Task

### UpdateMany(IEnumerable<PatientObservation>, UpdateDefinition<PatientObservation>)

Updates multiple PatientObservation documents that match the provided update definition.

    Task UpdateMany(IEnumerable<PatientObservation> patientObservations, UpdateDefinition<PatientObservation> update)

#### Parameters

`patientObservations` IEnumerable<PatientObservation>

  The collection of patient observations to update.

`update` UpdateDefinition<PatientObservation>

  The update definition describing the modifications to apply to each patient observation.

#### Returns

Task

### UpdateManyObjectId(string, ObjectId, ObjectId)

Updates many records by replacing the specified old ObjectId with the new ObjectId identified by the given name.

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

#### Parameters

`nameId` string

  The name identifier used to locate the target collection or field to update.

`id` ObjectId

  The new ObjectId to assign to the matching records.

`oldId` ObjectId

  The existing ObjectId that identifies the records to be updated.

#### Returns

Task