using adas_core.Application.Repositories.Interfaces; using adas_core.Domain.Models.AppSettings; using adas_core.Domain.Models.MongoModels; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Driver; namespace adas_core.Infrastructure.Repositories; /// /// Represents a MongoDB-backed repository for managing entities, /// providing concrete persistence operations defined by the contract. /// /// The type of the patient care plan entity managed by this repository. public class PatientCarePlanRepository : MongoRepository, IPatientCarePlanRepository { #region Properties private readonly ApiSettings _apiSettings; #endregion #region Update /// /// Asynchronously updates multiple object identifiers for a patient by delegating to the underlying asynchronous operation. /// /// The string identifier of the patient whose object identifiers will be updated. /// The new to assign to the patient's records. /// The existing to be replaced. public async Task UpdateManyObjectId(string patientid, ObjectId patientId, ObjectId oldId) { await UpdateManyObjectIdAsync(patientid, patientId, oldId); } #endregion #region Constructor public PatientCarePlanRepository( IOptions apiSettings, IMongoDatabase database ) : base(database) { _apiSettings = apiSettings.Value; } #endregion #region Read /// /// Returns the collection name for patient care plan data, using the configured setting if available or a default fallback otherwise. /// /// The patient care plan collection name from _apiSettings.PatientCarePlan, or "patients_care_plan" when the setting is null. public override string GetCollectionName() { return _apiSettings.PatientCarePlan ?? "patients_care_plan"; } /// /// Retrieves all care plans associated with the specified patient identifier from the data store. /// Returns an empty list when no matching care plans exist for the patient. /// /// The unique identifier of the patient whose care plans should be retrieved. /// A task that represents the asynchronous operation. The task result contains a list of objects associated with the specified patient, or an empty list if none are found. public async Task> FindByPatientId(ObjectId patientId) { var result = await Collection.FindAsync(Builders.Filter.Eq(p => p.PatientId, patientId)); return result.ToList(); } /// /// Retrieves all patient care plans associated with the specified user identifier from the collection. /// /// The unique identifier of the user whose patient care plans are being queried. /// A list of instances matching the specified user identifier; an empty list is returned if no plans are found. public async Task> FindByUserId(ObjectId userId) { var result = await Collection.FindAsync(Builders.Filter.Eq(p => p.UserId, userId)); return result.ToList(); } /// /// Retrieves all patient care plans from the data store without applying any filter. /// /// A task that represents the asynchronous operation, containing a list of all records. public async Task> FindAll() { var result = await Collection.Find(Builders.Filter.Empty).ToListAsync(); return result; } #endregion }