Class TreatmentRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Represents a MongoDB-backed repository for PatientTreatment entities, inheriting common data access functionality from MongoRepository<T> and implementing the ITreatmentRepository contract.
public class TreatmentRepository : MongoRepository<PatientTreatment>, ITreatmentRepository, IMongoRepository<PatientTreatment>
- Inheritance
-
TreatmentRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
TreatmentRepository(IOptions<ApiSettings>, IMongoDatabase)
public TreatmentRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>databaseIMongoDatabase
Methods
CreateIndexes()
Ensures the required MongoDB indexes exist for the PatientTreatment collection, creating a non-unique background index on the patientid field to optimize query performance without blocking other database operations.
public override Task CreateIndexes()
Returns
DeleteAsync(ObjectId)
Deletes a patient treatment record from the database by its unique identifier.
public Task DeleteAsync(ObjectId id)
Parameters
idObjectIdThe unique identifier of the patient treatment to remove.
Returns
DeleteByPatientId(ObjectId)
Deletes all PatientTreatment records associated with the specified patient identifier.
Returns true when the delete operation completes, and false if an exception is encountered, in which case the error is logged.
public Task<bool> DeleteByPatientId(ObjectId patientId)
Parameters
patientIdObjectIdThe identifier of the patient whose treatment records should be removed.
Returns
- Task<bool>
A task that resolves to
trueon successful deletion, orfalseif the operation failed due to an exception.
FindBolusTreatments(ObjectId)
Retrieves all bolus treatments associated with the specified patient, filtering for records that have at least one entry in their RequestedGiveCodesStatus array.
public Task<List<PatientTreatment>> FindBolusTreatments(ObjectId patientId)
Parameters
patientIdObjectIdThe unique identifier of the patient whose bolus treatments are being queried.
Returns
- Task<List<PatientTreatment>>
A task that represents the asynchronous operation, containing a list of PatientTreatment documents matching the patient and having a non-empty
RequestedGiveCodesStatus.
FindByPatientId(ObjectId)
Asynchronously retrieves all patient treatment records associated with the specified patient identifier from the underlying data store.
public Task<IEnumerable<PatientTreatment>> FindByPatientId(ObjectId patientId)
Parameters
patientIdObjectIdThe unique MongoDB.Bson.ObjectId of the patient whose treatments are being queried.
Returns
- Task<IEnumerable<PatientTreatment>>
A task that represents the asynchronous operation, containing an IEnumerable<T> with the matching treatment records. Returns an empty sequence if no treatments are found.
FindByPatientIdAsync(ObjectId)
Retrieves all patient treatment records associated with the specified patient identifier from the MongoDB collection.
public Task<IAsyncCursor<PatientTreatment>> FindByPatientIdAsync(ObjectId patientId)
Parameters
patientIdObjectIdThe unique ObjectId of the patient whose treatment records should be returned.
Returns
- Task<IAsyncCursor<PatientTreatment>>
An MongoDB.Driver.IAsyncCursor<TDocument> of PatientTreatment containing the matching treatment records.
GetActiveTreatmentsByPatientIdAndOrder(ObjectId, string)
Retrieves the list of patient treatments associated with the specified patient and placer order identifier, limited to treatments whose order control is set to New (Nw) or Xo.
public Task<List<PatientTreatment>> GetActiveTreatmentsByPatientIdAndOrder(ObjectId patientId, string order)
Parameters
patientIdObjectIdThe identifier of the patient whose treatments will be searched.
orderstringThe entity identifier of the placer order used to match treatments.
Returns
- Task<List<PatientTreatment>>
A task that represents the asynchronous operation. The task result contains the list of matching PatientTreatment entries.
GetById(ObjectId)
Retrieves a patient treatment record from the database that matches the specified identifier.
public Task<IAsyncCursor<PatientTreatment>> GetById(ObjectId id)
Parameters
idObjectIdThe unique identifier of the patient treatment to locate.
Returns
- Task<IAsyncCursor<PatientTreatment>>
An asynchronous cursor containing the patient treatment matching the provided identifier.
GetByPatientId(ObjectId)
Retrieves all patient treatment records associated with the specified patient identifier.
public Task<IEnumerable<PatientTreatment>> GetByPatientId(ObjectId patientId)
Parameters
patientIdObjectIdThe unique identifier of the patient whose treatments are being queried.
Returns
- Task<IEnumerable<PatientTreatment>>
A collection of PatientTreatment records matching the specified patient identifier.
GetCollectionName()
Retrieves the collection name for patients treatments, using the value configured in API settings or falling back to the default "patients_treatments" when the setting is not specified.
public override string GetCollectionName()
Returns
- string
The configured patients treatments collection name, or "patients_treatments" if no setting is defined.
GetPaginatedTreatments(PaginationFilter)
Retrieves a paginated, fluent queryable collection of patient treatments based on the provided pagination filter.
public IFindFluent<PatientTreatment, PatientTreatment> GetPaginatedTreatments(PaginationFilter filter)
Parameters
filterPaginationFilterThe pagination filter containing page size, page number, and other pagination criteria.
Returns
- IFindFluent<PatientTreatment, PatientTreatment>
An MongoDB.Driver.IFindFluent<TDocument, TProjection> for PatientTreatment that supports further fluent query composition and pagination.
InsertOneAsync(PatientTreatment)
Inserts a patient treatment record, defaulting the order time to the current UTC time when it is not already set.
public override Task InsertOneAsync(PatientTreatment treatment)
Parameters
treatmentPatientTreatmentThe patient treatment to insert.
Returns
Update(PatientTreatment)
Updates an existing patient treatment record asynchronously, returning a boolean indicating success or failure. If the update operation throws an exception, the error is logged and the method returns false instead of propagating the exception.
public Task<bool> Update(PatientTreatment treatment)
Parameters
treatmentPatientTreatmentThe patient treatment entity containing the updated information, identified by its
Id.
Returns
- Task<bool>
trueif the update succeeds; otherwise,falseif an exception occurs during the operation.
UpdateManyObjectId(string, ObjectId, ObjectId)
Updates the identifier of a related entity by replacing the old object identifier with the new one across multiple records.
public Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId)
Parameters
nameIdstringThe name of the field or relationship whose object identifier should be updated.
idObjectIdThe new object identifier to replace the old one with.
oldIdObjectIdThe existing object identifier that should be replaced.