# Class ObservationRepositoryTest

Namespace
  adas_core.Test.Repositories

Assembly
  adas-core.Test.dll

    [TestFixture]
    [Order(1)]
    [Category("Integration")]
    public class ObservationRepositoryTest

Inheritance
  object
  ObservationRepositoryTest

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?)

## Methods

### AggregatedPatientActiveIntravenousLinesObservations_Filter_Not_PatientIntravenousLineasValue_Return_List_Obs()

Verifies that _repository.AggregatedPatientActiveIntravenousLinesObservations returns an empty list of observations when the filter value is not the Patient Intravenous Lines value.

    [Test]
    public Task AggregatedPatientActiveIntravenousLinesObservations_Filter_Not_PatientIntravenousLineasValue_Return_List_Obs()

#### Returns

Task

### AggregatedPatientActiveIntravenousLinesObservations_Filter_PatientIntravenousLineasValue_Return_List_Obs()

Verifies that Repository.AggregatedPatientActiveIntravenousLinesObservations returns the expected list of active intravenous lines observations when filtering by patient id and the observation value is a `PatientIntravenousLinesValue` instance. The test inserts a single matching observation, asserts that exactly one record is returned, and confirms successful cleanup by deletion.

    [Test]
    public Task AggregatedPatientActiveIntravenousLinesObservations_Filter_PatientIntravenousLineasValue_Return_List_Obs()

#### Returns

Task

### AggregatedPatientActiveIntravenousLinesObservations_Null_Filter_Return_List_Obs()

Verifies that AggregatedPatientActiveIntravenousLinesObservations returns a non-null, empty list of observations for the specified patient when no filter criteria are provided.

    [Test]
    public Task AggregatedPatientActiveIntravenousLinesObservations_Null_Filter_Return_List_Obs()

#### Returns

Task

### AggregatedPatientGroupedObservations_Day_Firs_Return_List_8()

Verifies that `AggregatedPatientGroupedObservations` returns at most the configured maximum number of entries when grouping patient observations by day and selecting the first result, even when more observations exist. Also confirms that observations inserted for the test patient are removed by the cleanup step.

    [Test]
    public Task AggregatedPatientGroupedObservations_Day_Firs_Return_List_8()

#### Returns

Task

  A task that completes when the aggregation result is validated and the test data is cleaned up.

### AggregatedPatientGroupedObservations_Hour_Firs_Return_List_9()

Tests that AggregatedPatientGroupedObservations returns 9 grouped results when 30 hourly observations are aggregated for a patient using the First result selection strategy with a maximum of 8 groups. Verifies successful aggregation and ensures all inserted test observations are removed by patient id.

    [Test]
    public Task AggregatedPatientGroupedObservations_Hour_Firs_Return_List_9()

#### Returns

Task

### AggregatedPatientGroupedObservations_Hour_Firs_Since_Last_Return_List_8()

Verifies that AggregatedPatientGroupedObservations returns up to 8 hourly grouped observations using the `First` result selection and the `Last` since filter for a given patient. Inserts 30 observations, asserts the aggregated result count is 8, and confirms cleanup by patient id removes all inserted records.

    [Test]
    public Task AggregatedPatientGroupedObservations_Hour_Firs_Since_Last_Return_List_8()

#### Returns

Task

  A task that completes when the test finishes, including assertions and cleanup.

### AggregatedPatientGroupedObservations_Insert_5_Hour_Average_Return_List_5()

Tests that _repository.AggregatedPatientGroupedObservations returns a list of 5 aggregated results when grouping hourly observations by average over a 5-hour period. Inserts 10 observations across 5 different hours (two per hour with values 5 and 3), verifies the result count is 5, and asserts that each entry contains the "average" field with a value of 3 or 4. Cleans up by deleting all observations for the test patient after verification.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_Average_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_Count_Return_List_5()

Verifies that `AggregatedPatientGroupedObservations` groups observations by hour using the `Count` result and returns a list with one entry per hour bucket for the inserted records. Inserts ten observations (two per hour for five consecutive hours) for a new patient, runs the aggregation, and asserts that the result contains five entries each reporting a count of 1 or 2. Also confirms that cleanup via `DeleteByPatientId` removes the inserted observations for the generated patient.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_Count_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_Firs_Return_List_5()

Verifies that inserting five patient observations with hourly regularity and aggregating them using the first result returns a list of four or five grouped entries, and ensures the inserted observations are removed by patient id.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_Firs_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_HalfHour_Return_List_5()

Verifies that aggregated patient observations grouped by hour with half-hour result granularity return the expected list of grouped entries for a newly inserted patient. Inserts two sets of observations at different minute offsets across the last five hours, then asserts the aggregation result count matches the expected number of groups and the "all" subset is returned. Also validates cleanup by ensuring no observations remain for the test patient after deletion.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_HalfHour_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_LastAll_Return_List_5()

Tests that the repository's aggregated patient grouped observations, configured with hourly regularity and the LastAll result option, returns a list of 5 entries when 5 hours of data are inserted (with two observations per hour at minutes 15 and 31), and verifies that cleanup by patient ID removes all inserted records.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_LastAll_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_LastFilled_Return_List_5()

Verifies that `AggregatedPatientGroupedObservations` returns up to 5 hourly aggregated entries when using the `LastFilled` result option, ensuring each hour contains the most recently filled observation value (either 5 or 3 depending on insertion order) and that the inserted test data is cleaned up afterwards.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_LastFilled_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_Max_Return_List_5()

Tests that `AggregatedPatientGroupedObservations` correctly groups observations by hour and returns the maximum value for each group, producing one aggregated result per hour when inserting two observations (with different values) for each of five consecutive hours.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_Max_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_Min_Return_List_5()

Verifies that when five hourly PatientObservation records are inserted with two values per hour (5 and 3), AggregatedPatientGroupedObservations returns a list of five entries, each containing the minimum value of 3. Also confirms that observations are cleaned up by patient id after the test executes.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_Min_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_last_Return_List_5()

Tests that `AggregatedPatientGroupedObservations` returns a list of 5 entries when 5 observations are inserted per hour and the `Result.Last` aggregation rule is applied. Inserts two observations for each of the last 5 hours (at minutes 15 and 30), runs the aggregation for a new patient, and verifies the result count is 5 and that every entry contains the "last" marker. Cleanup is performed by deleting the inserted observations by patient id and asserting that the collection is empty afterwards.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_last_Return_List_5()

#### Returns

Task

### AggregatedPatientGroupedObservations_Insert_5_Hour_sum_Return_List_5()

Verifies that the AggregatedPatientGroupedObservations method correctly aggregates patient observations into hourly groups and returns the sum of values for each hour when five hours of data are inserted.

    [Test]
    public Task AggregatedPatientGroupedObservations_Insert_5_Hour_sum_Return_List_5()

#### Returns

Task

  A task that represents the asynchronous test execution.

### AggregatedPatientGroupedObservations_Minute_Firs_Return_List_8()

Verifies that the aggregated grouped observations query, configured with minute regularity, the `First` result and a maximum of 8, returns a list of exactly 8 entries even when 30 underlying observations exist for the patient.

    [Test]
    public Task AggregatedPatientGroupedObservations_Minute_Firs_Return_List_8()

#### Returns

Task

### AggregatedPatientGroupedObservations_Null_groupedField_Return_List_Emty()

Verifies that `AggregatedPatientGroupedObservations` returns a non-null, empty list when called with a default GroupedField instance for the given patient.

    [Test]
    public Task AggregatedPatientGroupedObservations_Null_groupedField_Return_List_Emty()

#### Returns

Task

### AggregatedPatientGroupedObservations_Shift_Firs_Return_List_9()

Verifies that `AggregatedPatientGroupedObservations` returns a list of 9 entries containing the "first" marker when grouping 30 patient observations by a shift-regularity field with a max of 8 and `Result.First` selected, and that all inserted observations are removed by the cleanup call.

    [Test]
    public Task AggregatedPatientGroupedObservations_Shift_Firs_Return_List_9()

#### Returns

Task

### AggregatedPatientGroupedObservations_Times_Firs_Return_List_8()

    [Test]
    public Task AggregatedPatientGroupedObservations_Times_Firs_Return_List_8()

#### Returns

Task

### AggregatedPatientGroupedObservations_second_Firs_Return_List()

Verifies that `AggregatedPatientGroupedObservations` returns a non-empty list when patient observations are grouped by a field with second-level regularity and the aggregation selects only the first result per group, and that the inserted observations are fully removed by the cleanup step.

    [Test]
    public Task AggregatedPatientGroupedObservations_second_Firs_Return_List()

#### Returns

Task

### AggregatedPatientLastObservationsByField_Filter_OnlyExpired_Return_Empty_List()

Verifies that _repository.AggregatedPatientLastObservationsByField returns an empty list when the filter field has `OnlyExpired` set to `true`, indicating no expired observations are available for the patient.

    [Test]
    public Task AggregatedPatientLastObservationsByField_Filter_OnlyExpired_Return_Empty_List()

#### Returns

Task

### AggregatedPatientLastObservationsByField_Filter_Return_List()

Tests that filtering aggregated patient last observations by a specific field returns a non-null list containing the expected number of results.

    [Test]
    public Task AggregatedPatientLastObservationsByField_Filter_Return_List()

#### Returns

Task

### AggregatedPatientLastObservationsByField_Null_Filter_Return_List()

Verifies that AggregatedPatientLastObservationsByField returns a non-null list of aggregated patient last observations when the filter is `null`, confirming the expected fallback behavior and default result set.

    [Test]
    public Task AggregatedPatientLastObservationsByField_Null_Filter_Return_List()

#### Returns

Task

### AggregatedPatientLastObservationsByLastDate_Filter_Not_Find_Return_Empty_List()

Verifies that AggregatedPatientLastObservationsByLastDate returns an empty list when the provided filter does not match any patient observations.

    [Test]
    public Task AggregatedPatientLastObservationsByLastDate_Filter_Not_Find_Return_Empty_List()

#### Returns

Task

### AggregatedPatientLastObservationsByLastDate_Filter_Return_List()

Verifies that _repository.AggregatedPatientLastObservationsByLastDate returns a non-null list containing the expected number of aggregated patient last observations when a filter is provided.

    [Test]
    public Task AggregatedPatientLastObservationsByLastDate_Filter_Return_List()

#### Returns

Task

### AggregatedPatientLastObservationsByLastDate_Null_Filter_Return_List()

Verifies that `AggregatedPatientLastObservationsByLastDate` returns a non-null list of aggregated patient last observations for a given patient and date, even when no filter is applied.

    [Test]
    public Task AggregatedPatientLastObservationsByLastDate_Null_Filter_Return_List()

#### Returns

Task

### AggregatedPatientLastObservations_Filter_Not_Find_Return_Empty_List()

Verifies that AggregatedPatientLastObservations returns an empty list when the provided filter does not match any observations.

    [Test]
    public Task AggregatedPatientLastObservations_Filter_Not_Find_Return_Empty_List()

#### Returns

Task

### AggregatedPatientLastObservations_Filter_Return_List()

Verifies that the AggregatedPatientLastObservations repository method returns a non-null filtered list with the expected number of entries when a name filter is provided.

    [Test]
    public Task AggregatedPatientLastObservations_Filter_Return_List()

#### Returns

Task

### AggregatedPatientLastObservations_Null_Filter_Return_List()

Verifies that the AggregatedPatientLastObservations method returns a non-null list containing the expected number of aggregated last observations for the specified patient.

    [Test]
    public Task AggregatedPatientLastObservations_Null_Filter_Return_List()

#### Returns

Task

### DeleteAsync()

Verifies that DeleteAsync() correctly removes a patient observation from the repository by inserting a record, confirming its presence, deleting it, and ensuring it is no longer retrievable.

    [Test]
    public Task DeleteAsync()

#### Returns

Task

### DeleteByPatientId()

Verifies that the `DeleteByPatientId` repository method removes all PatientObservation records associated with a given patient identifier. The test inserts a single observation, confirms it is persisted, deletes it by patient id, and asserts that no records remain for that patient.

    [Test]
    public Task DeleteByPatientId()

#### Returns

Task

### DeleteOlderDaysAsync()

Verifies that the repository's `DeleteOlderDaysAsync` method removes PatientObservation records older than the specified day threshold while keeping more recent ones, and that `DeleteByPatientId` subsequently clears the remaining records associated with the same patient.

    [Test]
    public Task DeleteOlderDaysAsync()

#### Returns

Task

### DeleteOlderNumberAsync()

Verifies that the repository's `DeleteOlderNumberAsync` method retains only the most recent specified count of PatientObservation records sharing the same name, deleting the older entries, and that `DeleteByPatientId` subsequently removes all remaining records for the patient.

    [Test]
    public Task DeleteOlderNumberAsync()

#### Returns

Task

### DeleteOlderSecondsAsync()

Verifies that `DeleteOlderSecondsAsync` removes `PatientObservation` entries whose timestamp is older than the specified number of seconds, keeping more recent entries with the same name intact, and that `DeleteByPatientId` clears all remaining observations for the given patient.

    [Test]
    public Task DeleteOlderSecondsAsync()

#### Returns

Task

### ExistBySystemId_Return_List()

Verifies that _repository.`ExistBySystemId` returns a valid result when checking existence by the given patient and system identifiers.

    [Test]
    public Task ExistBySystemId_Return_List()

#### Returns

Task

### ExpireExpiredObservations()

Verifies that _repository.ExpireExpiredObservations" correctly marks the supplied configuration observations as expired so that a subsequent _repository.FindNotExpired call returns only the remaining non-expired observations, deduplicating the requested names.

    [Test]
    public Task ExpireExpiredObservations()

#### Returns

Task

### FindAllLastPatientObservationTime_Return_List()

Verifies that the repository method `FindAllLastPatientObservationTime` returns a non-null collection containing at least one last patient observation time record.

    [Test]
    public Task FindAllLastPatientObservationTime_Return_List()

#### Returns

Task

### FindAll_Return_List_Obs()

Verifies that the repository's `FindAll` method returns a non-null and non-empty collection of patient observations.

    [Test]
    public Task FindAll_Return_List_Obs()

#### Returns

Task

### FindAnyBeforeDate_Return_List_Obs()

Tests that the repository returns a non-null list of two observations for a patient, found before the specified date (yesterday).

    [Test]
    public Task FindAnyBeforeDate_Return_List_Obs()

#### Returns

Task

### FindAnyWithSameDate_Return_List_Obs()

Verifies that the repository's `FindAnyWithSameDate` method returns a non-null list containing exactly one observation when searching for observations associated with the specified patient, name, and date.

    [Test]
    public Task FindAnyWithSameDate_Return_List_Obs()

#### Returns

Task

### FindById_Return_Obs()

Verifies that the repository's `FindById` method returns a non-null entity whose identifier matches the requested `Id`.

    [Test]
    public Task FindById_Return_Obs()

#### Returns

Task

### FindById_Return_null()

Verifies that the repository's `FindById` method returns `null` when the requested entity does not exist in the data store.

    [Test]
    public Task FindById_Return_null()

#### Returns

Task

### FindByName_Return_List_Obs()

Verifies that the repository's `FindByName` method returns a non-null, non-empty list of PatientObservation objects when searching by the name "name1".

    [Test]
    public Task FindByName_Return_List_Obs()

#### Returns

Task

### FindByPatientIdAsync_Return_Cursor()

Verifies that FindByPatientIdAsync returns a non-null cursor containing the expected number of records for the specified patient identifier.

    [Test]
    public Task FindByPatientIdAsync_Return_Cursor()

#### Returns

Task

### FindLastObservationBeforeDate_Return_Obs()

Verifies that FindLastObservationBeforeDate returns a non-null observation whose timestamp is earlier than the specified date, confirming a matching record is retrieved successfully.

    [Test]
    public Task FindLastObservationBeforeDate_Return_Obs()

#### Returns

Task

### FindLastObservationsByCodingSystem_Return_List()

Verifies that FindLastObservationsByCodingSystem returns a non-null list of the expected count of the most recent observations for the specified patient filtered by the "SNM" coding system.

    [Test]
    public Task FindLastObservationsByCodingSystem_Return_List()

#### Returns

Task

### FindLastObservations_Return_List()

Verifies that the repository's last observations lookup returns a non-null list containing the expected number of observations for the specified patient, system ("SNM"), and observation code ("code1").

    [Test]
    public Task FindLastObservations_Return_List()

#### Returns

Task

### FindNotExpired_Return_List_Obs()

Verifies that the repository's `FindNotExpired` method returns a non-empty collection of patient observations for the provided observation names.

    [Test]
    public Task FindNotExpired_Return_List_Obs()

#### Returns

Task

### Init()

One-time setup that initializes the integration test environment for the ObservationRepository. Resets the `patients_observations` collection, creates the repository with mocked logging and configured API settings, and seeds it with six PatientObservation records covering different codes, coding systems, and timestamps (including observations without a `SystemId`).

    [OneTimeSetUp]
    public Task Init()

#### Returns

Task

### UpdateExpiredObservations()

Verifies that the repository's `UpdateExpiredObservations` method correctly marks all non-expired observations belonging to a patient as expired. The test inserts five fresh observations, asserts that none are expired, invokes the update, and then asserts that all five have been flagged as expired before cleaning up the inserted data.

    [Test]
    public Task UpdateExpiredObservations()

#### Returns

Task