Class PatientArchiveRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository implementation for managing Patient archive entities in MongoDB. Provides CRUD operations for historical/archived patient data.
public class PatientArchiveRepository : MongoRepository<Patient>, IPatientArchiveRepository, IMongoRepository<Patient>
- Inheritance
-
PatientArchiveRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
PatientArchiveRepository(IOptions<ApiSettings>, IMongoDatabase)
Initializes a new instance of the PatientArchiveRepository.
public PatientArchiveRepository(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
CreateIndexes()
Creates the necessary indexes for the PatientArchive collection. Creates an index on patientNumber for improved query performance.
public override Task CreateIndexes()
Returns
FindAll()
Retrieves all archived patients from the collection.
public Task<List<Patient>> FindAll()
Returns
FindByPatientNumber(string)
Finds an archived patient by their patient number.
public Task<Patient?> FindByPatientNumber(string patientNumber)
Parameters
patientNumberstringThe patient number to search for.
Returns
GetCollectionName()
Gets the name of the collection for archived patients.
public override string GetCollectionName()
Returns
- string
The collection name from API settings, or default "archive_patient".
InsertOneAsync(Patient)
Inserts or updates an archived patient. If a patient with the same PatientNumber already exists, merges the data and updates the record. If no match exists, performs a regular insert.
public override Task InsertOneAsync(Patient obj)
Parameters
objPatientThe Patient entity to insert or merge.
Returns
Exceptions
- Exception
Logs warning and silently fails on error.
SearchByPatientNumberAndDistinctUnit(string, ObjectId)
Searches for an archived patient by patient number, returning null if multiple matches exist. This is useful when patientNumber may be incomplete and could match multiple patients.
public Task<Patient?> SearchByPatientNumberAndDistinctUnit(string patientNumber, ObjectId unitId)
Parameters
patientNumberstringThe patient number to search for.
unitIdObjectIdThe unit ID (currently not used in query, kept for interface compatibility).