=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===
This commit is contained in:
@@ -18,6 +18,7 @@ namespace adas_core.Infrastructure.Repositories;
|
||||
/// <summary>
|
||||
/// Provides a MongoDB-backed repository implementation for managing patient data, exposing patient-specific data access operations defined by the IPatientRepository contract.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=c81c577 -->
|
||||
public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
{
|
||||
private readonly ApiSettings _apiSettings;
|
||||
@@ -47,6 +48,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// or falling back to the default "patients" if the setting is null.
|
||||
/// </summary>
|
||||
/// <returns>The configured patients collection name, or "patients" as a default when the setting is not set.</returns>
|
||||
/// <!-- aidoc:v1 sig=94e22ff body=04f5507 -->
|
||||
public override string GetCollectionName()
|
||||
{
|
||||
return _apiSettings.Patients ?? "patients";
|
||||
@@ -58,6 +60,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient to locate.</param>
|
||||
/// <returns>A <see cref="Patient"/> instance matching the provided id, or <c>null</c> if not found or on error.</returns>
|
||||
/// <!-- aidoc:v1 sig=f97bb0d body=2c27a66 -->
|
||||
public async Task<Patient?> FindById(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -80,6 +83,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The point of care identifier used to locate the patient.</param>
|
||||
/// <returns>A <see cref="Patient"/> instance if a match is found; otherwise, <c>null</c>.</returns>
|
||||
/// <!-- aidoc:v1 sig=8a4443e body=e3fe55b -->
|
||||
public async Task<Patient?> FindByPointOfCareId(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -103,6 +107,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="unit">The identifier of the unit to filter by.</param>
|
||||
/// <param name="pointOfCare">The identifier of the point of care to filter by.</param>
|
||||
/// <returns>The first matching <see cref="Patient"/>, or null if no patient is found or an error is encountered.</returns>
|
||||
/// <!-- aidoc:v1 sig=9b461f1 body=c98f5c9 -->
|
||||
public async Task<Patient> FindByUnitAndPocId(ObjectId unit, ObjectId pointOfCare)
|
||||
{
|
||||
try
|
||||
@@ -129,6 +134,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="location">The location information used to locate the patient. Can be null.</param>
|
||||
/// <returns>A <see cref="Patient"/> matching the location criteria, or null if no match is found or the location is null.</returns>
|
||||
/// <!-- aidoc:v1 sig=556acef body=7ff7fec -->
|
||||
public async Task<Patient?> FindByLocation(PatientLocation? location)
|
||||
{
|
||||
if (location == null)
|
||||
@@ -155,6 +161,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// Asynchronously inserts a new <see cref="Patient"/> record, setting its creation date to the current UTC time. If the insertion fails but an existing patient with the same patient number is found at the same location, the exception is logged as a warning; otherwise, the error is logged and rethrown.
|
||||
/// </summary>
|
||||
/// <param name="patient">The <see cref="Patient"/> entity to insert into the data store.</param>
|
||||
/// <!-- aidoc:v1 sig=334af9d body=f6ea95d -->
|
||||
public override async Task InsertOneAsync(Patient patient)
|
||||
{
|
||||
try
|
||||
@@ -183,6 +190,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// Updates an existing patient record, refreshing the update timestamp to the current UTC time before persisting the changes.
|
||||
/// </summary>
|
||||
/// <param name="patient">The patient entity containing the updated information to be saved.</param>
|
||||
/// <!-- aidoc:v1 sig=f9d52dc body=06dccd6 -->
|
||||
public async Task Update(Patient patient)
|
||||
{
|
||||
patient.UpdateDate = DateTime.UtcNow;
|
||||
@@ -193,6 +201,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// Deletes a patient from the collection that matches the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient to remove.</param>
|
||||
/// <!-- aidoc:v1 sig=3de1ad6 body=60a9b9b -->
|
||||
public async Task Delete(ObjectId id)
|
||||
{
|
||||
var filter = Builders<Patient>.Filter.Eq(x => x.Id, id);
|
||||
@@ -204,6 +213,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient whose location will be updated.</param>
|
||||
/// <param name="location">The new location to assign to the patient.</param>
|
||||
/// <!-- aidoc:v1 sig=a6d84a4 body=af93f9e -->
|
||||
public async Task UpdateLocation(ObjectId id, PatientLocation location)
|
||||
{
|
||||
var patient = await FindById(id);
|
||||
@@ -236,6 +246,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient whose location will be updated.</param>
|
||||
/// <param name="location">The new point of care (location) identifier to assign to the patient.</param>
|
||||
/// <!-- aidoc:v1 sig=ca2f737 body=b5de0cf -->
|
||||
public async Task UpdateLocation(ObjectId id, ObjectId location)
|
||||
{
|
||||
var patient = await FindById(id);
|
||||
@@ -255,6 +266,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the patient whose attending doctor is being updated.</param>
|
||||
/// <param name="attendingDoctor">The new attending doctor to assign to the patient.</param>
|
||||
/// <!-- aidoc:v1 sig=724f112 body=44fd27b -->
|
||||
public async Task UpdateAttendingDoctor(ObjectId id, Person attendingDoctor)
|
||||
{
|
||||
var update = Builders<Patient>.Update
|
||||
@@ -272,6 +284,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="patientNumber">The new patient number to apply when <paramref name="updatePatientNumber"/> is true.</param>
|
||||
/// <param name="data">The new <see cref="Person"/> information to store for the patient.</param>
|
||||
/// <param name="updatePatientNumber">Indicates whether the patient number should be updated as part of the operation; defaults to true.</param>
|
||||
/// <!-- aidoc:v1 sig=06ac587 body=114be5c -->
|
||||
public async Task UpdatePatientData(ObjectId id, string patientNumber, Person data, bool updatePatientNumber = true)
|
||||
{
|
||||
var filterBuilder = Builders<Patient>.Filter;
|
||||
@@ -615,6 +628,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="unitIds">The list of unit identifiers used to filter patients.</param>
|
||||
/// <param name="typeName">The name of the type to validate against the MasterListType enumeration.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a list of Patient objects matching the specified unit identifiers, or an empty list if the type name is invalid.</returns>
|
||||
/// <!-- aidoc:v1 sig=6f3d195 body=74ee8d7 -->
|
||||
public async Task<List<Patient>> GetPatientsByUnitIds(List<ObjectId> unitIds, string typeName)
|
||||
{
|
||||
var isParsed = Enum.TryParse<MasterListType>(typeName, out _);
|
||||
@@ -630,6 +644,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="unitId">The unit identifier used to filter patients.</param>
|
||||
/// <returns>The number of patients matching the specified unit identifier, or 0 if an error occurs.</returns>
|
||||
/// <!-- aidoc:v1 sig=baa8175 body=e692f35 -->
|
||||
public async Task<long> CountByUnitId(ObjectId unitId)
|
||||
{
|
||||
try
|
||||
@@ -818,6 +833,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// Retrieves all <see cref="Patient"/> records from the data store.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of all patients.</returns>
|
||||
/// <!-- aidoc:v1 sig=e8bb639 body=c6cbf36 -->
|
||||
public async Task<List<Patient>> FindAll()
|
||||
{
|
||||
return (await Collection.FindAsync(Builders<Patient>.Filter.Empty)).ToList();
|
||||
@@ -829,6 +845,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="pointOfCare">The unit or point of care used to filter the patients.</param>
|
||||
/// <returns>A task containing a list of <see cref="Patient"/> objects whose unit matches the specified point of care; an empty list is returned when no matches are found.</returns>
|
||||
/// <!-- aidoc:v1 sig=c4523a3 body=eff26de -->
|
||||
public async Task<List<Patient>> FindByPointOfCare(string pointOfCare)
|
||||
{
|
||||
var filterBuilder = Builders<Patient>.Filter;
|
||||
@@ -844,6 +861,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="pointOfCare">The identifier of the point of care used to filter the patient records.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of patients matching the specified point of care.</returns>
|
||||
/// <!-- aidoc:v1 sig=1cea52d body=b9dfd95 -->
|
||||
public async Task<List<Patient>> FindByPointOfCare(ObjectId pointOfCare)
|
||||
{
|
||||
var filterBuilder = Builders<Patient>.Filter;
|
||||
@@ -932,6 +950,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="filter">The pagination and filtering criteria, including optional text, time range, unit, and point of care filters.</param>
|
||||
/// <returns>A find fluent for the filtered and sorted patient query.</returns>
|
||||
/// <!-- aidoc:v1 sig=6790d47 body=f65667b -->
|
||||
public IFindFluent<Patient, Patient> GetPaginatedPatients(PaginationFilter filter)
|
||||
{
|
||||
var filterBuilder = Builders<Patient>.Filter;
|
||||
@@ -981,6 +1000,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="date">The cutoff date; patients with an <c>UpdateDate</c> strictly earlier than this value, or with no <c>UpdateDate</c> set, will be returned.</param>
|
||||
/// <returns>A task that resolves to a list of <see cref="Patient"/> instances matching the filter criteria.</returns>
|
||||
/// <!-- aidoc:v1 sig=42988dc body=d938adb -->
|
||||
public async Task<List<Patient>> FindPatientsNotUpdatedSince(DateTime date)
|
||||
{
|
||||
var filter = Builders<Patient>.Filter.Or(
|
||||
@@ -999,6 +1019,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <returns>A task that resolves to a list of discharged <see cref="Patient"/> records,
|
||||
/// or an empty list if the operation fails.</returns>
|
||||
/// <!-- aidoc:v1 sig=c56ad55 body=600ef72 -->
|
||||
public async Task<List<Patient>> FindDischargedPatients()
|
||||
{
|
||||
try
|
||||
@@ -1022,6 +1043,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="updatedPatient">The patient entity containing the updated values and the identifier of the record to modify.</param>
|
||||
/// <returns>The updated <see cref="Patient"/> after the modification is applied, or <c>null</c> if no matching document exists.</returns>
|
||||
/// <!-- aidoc:v1 sig=5cf3377 body=b2c2664 -->
|
||||
public async Task<Patient?> UpdateOne(Patient updatedPatient)
|
||||
{
|
||||
var filter = Builders<Patient>.Filter.Eq("_id", updatedPatient.Id);
|
||||
@@ -1042,6 +1064,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="patientId">The unique identifier of the patient to update.</param>
|
||||
/// <param name="person">The patient object containing the new values for the incoming data fields.</param>
|
||||
/// <returns>The updated <see cref="Patient"/> document after the modification, or <c>null</c> if no document was found.</returns>
|
||||
/// <!-- aidoc:v1 sig=c195b1f body=20e831b -->
|
||||
public async Task<Patient?> UpdatePatientIncomingData(ObjectId patientId, Patient person)
|
||||
{
|
||||
var filter = Builders<Patient>.Filter.Eq("_id", patientId);
|
||||
@@ -1064,6 +1087,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="patientId">The unique identifier of the patient whose data will be updated.</param>
|
||||
/// <param name="person">The patient object containing the new demographic and clinical values to persist.</param>
|
||||
/// <returns>The updated <see cref="Patient"/> document, or <c>null</c> if no patient with the specified identifier was found.</returns>
|
||||
/// <!-- aidoc:v1 sig=a6fa876 body=4fc291c -->
|
||||
public async Task<Patient?> UpdatePatientDemographicData(ObjectId patientId, Patient person)
|
||||
{
|
||||
var filter = Builders<Patient>.Filter.Eq("_id", patientId);
|
||||
@@ -1084,6 +1108,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <summary>
|
||||
/// Creates MongoDB indexes for the Patient collection, including a unique index on the <c>patientNumber</c> field and a non-unique index on the <c>admTime</c> field, using background index creation.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=4955da2 body=6e16010 -->
|
||||
public override async Task CreateIndexes()
|
||||
{
|
||||
var options = new CreateIndexOptions<Patient> { Background = true, Unique = false };
|
||||
@@ -1111,6 +1136,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="requestFilter">The request containing the optional start and end time values used to build each range filter.</param>
|
||||
/// <param name="filters">The collection of filter definitions to which the constructed filters are added.</param>
|
||||
/// <param name="filterBuilder">The builder used to create the Gte and Lte filter definitions for each time range.</param>
|
||||
/// <!-- aidoc:v1 sig=095d341 body=8b4f9c0 -->
|
||||
private static void AddTimeFilters(FilteredRequest requestFilter, List<FilterDefinition<Patient>> filters,
|
||||
FilterDefinitionBuilder<Patient> filterBuilder)
|
||||
{
|
||||
@@ -1164,6 +1190,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// </summary>
|
||||
/// <param name="pointOfCare">The ObjectId of the point of care used to filter the patients.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of patients matching the specified point of care.</returns>
|
||||
/// <!-- aidoc:v1 sig=4945a00 body=b9dfd95 -->
|
||||
public async Task<List<Patient>> FindAllByPointOfCareId(ObjectId pointOfCare)
|
||||
{
|
||||
var filterBuilder = Builders<Patient>.Filter;
|
||||
@@ -1181,6 +1208,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="filters">The list of filter definitions to which the new filter will be appended.</param>
|
||||
/// <param name="filter">The pagination filter containing the request criteria used to build the default filter.</param>
|
||||
/// <param name="filterBuilder">The builder used to construct the MongoDB filter definitions for the <see cref="Patient"/> entity.</param>
|
||||
/// <!-- aidoc:v1 sig=6206f14 body=1a8e3bd -->
|
||||
private void AddDefaultFilters(List<FilterDefinition<Patient>> filters, PaginationFilter filter,
|
||||
FilterDefinitionBuilder<Patient> filterBuilder)
|
||||
{
|
||||
@@ -1206,6 +1234,7 @@ public class PatientRepository : MongoRepository<Patient>, IPatientRepository
|
||||
/// <param name="filters">The list of filter definitions to combine; when empty, an empty filter (match-all) is used.</param>
|
||||
/// <param name="sort">The sort definition to apply to the query results.</param>
|
||||
/// <returns>An <see cref="IFindFluent{TSource, TDocument}"/> configured with the combined filter and sort.</returns>
|
||||
/// <!-- aidoc:v1 sig=6ee44b3 body=7b7fa02 -->
|
||||
private IFindFluent<Patient, Patient> CreateFindFluent(List<FilterDefinition<Patient>> filters,
|
||||
SortDefinition<Patient> sort)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user