Class ObservationArchiveRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository implementation for managing PatientObservation archive entities in MongoDB. Provides operations for storing and retrieving historical patient observations.
public class ObservationArchiveRepository : MongoRepository<PatientObservation>, IObservationArchiveRepository, IMongoRepository<PatientObservation>
- Inheritance
-
ObservationArchiveRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
ObservationArchiveRepository(IOptions<ApiSettings>, IMongoDatabase)
Initializes a new instance of the ObservationArchiveRepository.
public ObservationArchiveRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>API settings containing collection names configuration.
databaseIMongoDatabaseThe MongoDB database instance.
Exceptions
- ArgumentNullException
Thrown when apiSettings is null.
Methods
AggregatedPatientLastObservations(ObjectId, int, DateTime, List<string>?)
Retrieves the aggregated last observations for a specific patient. Filters observations by name and date, returning the most recent ones.
public Task<List<PatientObservation>> AggregatedPatientLastObservations(ObjectId patientId, int num, DateTime lastDate, List<string>? filterObservations = null)
Parameters
patientIdObjectIdThe ObjectId of the patient.
numintThe maximum number of observations to return per observation type.
lastDateDateTimeThe cutoff date to filter observations (inclusive).
filterObservationsList<string>Optional list of observation names to filter by. If null, retrieves all distinct observations.
Returns
- Task<List<PatientObservation>>
A list of PatientObservation entities sorted by time descending.
DeleteBeforeDate(DateTime)
Deletes all patient observations before a specified date. Useful for archival cleanup operations.
public Task DeleteBeforeDate(DateTime date)
Parameters
dateDateTimeThe cutoff date. Observations older than this date will be deleted.
Returns
- Task
The number of deleted documents.
FindAllFromPatient(ObjectId)
Retrieves all archived observations for a specific patient.
public Task<List<PatientObservation>> FindAllFromPatient(ObjectId patientId)
Parameters
patientIdObjectIdThe ObjectId of the patient.
Returns
- Task<List<PatientObservation>>
A list of all PatientObservation entities for the patient.
GetCollectionName()
Gets the name of the collection for archived patient observations.
public override string GetCollectionName()
Returns
- string
The collection name from API settings, or default "archive_patients_observations".
InsertBatch(IEnumerable<PatientObservation>)
Inserts a batch of patient observations using bulk write operation.
public Task<long> InsertBatch(IEnumerable<PatientObservation> observations)
Parameters
observationsIEnumerable<PatientObservation>An enumerable of PatientObservation entities to insert.
Returns
InsertOneAsync(PatientObservation)
Inserts a new patient observation into the archive with retry logic for duplicate key errors. If a duplicate key error occurs, generates a new ObjectId and retries up to maxRetries times.
public Task InsertOneAsync(PatientObservation patientObservation)
Parameters
patientObservationPatientObservationThe PatientObservation entity to insert.
Returns
Exceptions
- MongoWriteException
Throws when duplicate key error persists after max retries.
- Exception
Throws when insertion fails for reasons other than duplicate key.