Table of Contents

Class ArchivePatientCarePlanRepository

Namespace
adas_core.Infrastructure.Repositories
Assembly
adas-core.Infrastructure.dll

Repository for managing archived patient care plans in a MongoDB database. This class provides methods to perform CRUD operations and queries related to archived patient care plans, such as retrieving care plans by patient ID, inserting new care plans, and creating indexes. It utilizes the MongoDB driver for database interactions and is configured using application settings for collection names and other parameters.

public class ArchivePatientCarePlanRepository : MongoRepository<PatientCarePlan>, IArchivePatientCarePlanRepository, IMongoRepository<PatientCarePlan>
Inheritance
ArchivePatientCarePlanRepository
Implements
Inherited Members
Extension Methods

Constructors

ArchivePatientCarePlanRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<ArchivePatientCarePlanRepository>)

Initializes a new instance of the ArchivePatientCarePlanRepository class with the specified API settings, MongoDB database, and logger.

public ArchivePatientCarePlanRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<ArchivePatientCarePlanRepository> logger)

Parameters

apiSettings IOptions<ApiSettings>

The API settings containing configuration for the repository.

database IMongoDatabase

The MongoDB database instance.

logger ILogger<ArchivePatientCarePlanRepository>

The logger for logging information, warnings, and errors.

Methods

CreateIndexes()

Creates indexes for the MongoDB collection associated with this repository. This method ensures that the necessary indexes are created to optimize query performance, particularly for queries based on patient ID. The indexes are created in the background to avoid blocking operations on the database.

public override Task CreateIndexes()

Returns

Task

FindAll()

Finds all patient care plans in the MongoDB collection. This method retrieves all documents from the collection and returns them as a list of PatientCarePlan objects.

public Task<List<PatientCarePlan>> FindAll()

Returns

Task<List<PatientCarePlan>>

A task representing the asynchronous operation, containing a list of PatientCarePlan objects.

FindByIds(ObjectId, string?, string?)

Finds patient care plans by multiple identifiers, including patient ID, patient number, and patient ID as a string. This method attempts to find care plans using the provided identifiers in a specific order: it first tries to find care plans by the patient ID (as an ObjectId), then by the patient ID (as a string), and finally by the patient number. If any of the queries return results, it returns those results immediately. If no care plans are found using any of the identifiers, it returns an empty list.

public Task<List<PatientCarePlan>?> FindByIds(ObjectId oldPatientId, string? oldPatientPatientId, string? oldPatientPatientNumber)

Parameters

oldPatientId ObjectId

The ID of the patient whose care plans are to be retrieved, provided as an ObjectId.

oldPatientPatientId string

The ID of the patient whose care plans are to be retrieved, provided as a string.

oldPatientPatientNumber string

The number of the patient whose care plans are to be retrieved.

Returns

Task<List<PatientCarePlan>>

A task representing the asynchronous operation, containing a list of PatientCarePlan objects.

FindByPatientId(ObjectId)

Finds patient care plans by the specified patient ID. This method takes a patient ID as input and queries the MongoDB collection for care plans associated with that patient ID. It returns a list of PatientCarePlan objects that match the query. If no care plans are found, it returns an empty list.

public Task<List<PatientCarePlan>?> FindByPatientId(ObjectId patientId)

Parameters

patientId ObjectId

The ID of the patient whose care plans are to be retrieved.

Returns

Task<List<PatientCarePlan>>

A task representing the asynchronous operation, containing a list of PatientCarePlan objects.

FindByPatientId(string)

Finds patient care plans by the specified patient ID, where the patient ID is provided as a string. This method attempts to parse the string into an ObjectId and then queries the MongoDB collection for care plans associated with that patient ID.

public Task<List<PatientCarePlan>?> FindByPatientId(string patientId)

Parameters

patientId string

The ID of the patient whose care plans are to be retrieved, provided as a string.

Returns

Task<List<PatientCarePlan>>

A task representing the asynchronous operation, containing a list of PatientCarePlan objects.

FindByPatientNumber(string)

Finds patient care plans by the specified patient number. This method takes a patient number as input and queries the MongoDB collection for care plans associated with that patient number.

public Task<List<PatientCarePlan>?> FindByPatientNumber(string patientNumber)

Parameters

patientNumber string

The number of the patient whose care plans are to be retrieved.

Returns

Task<List<PatientCarePlan>>

A task representing the asynchronous operation, containing a list of PatientCarePlan objects.

GetCollectionName()

Gets the name of the MongoDB collection associated with this repository. The collection name is determined based on the API settings provided during the initialization of the repository. If the collection name is not specified in the settings, it defaults to "archive_patients_care_plan". This method is used by the base repository class to determine which collection to interact with for CRUD operations.

public override string GetCollectionName()

Returns

string

InsertManyAsync(List<PatientCarePlan>)

Inserts multiple patient care plans into the MongoDB collection. This method takes a list of PatientCarePlan objects as input and attempts to insert them into the database in a single operation.

public override Task InsertManyAsync(List<PatientCarePlan> patient)

Parameters

patient List<PatientCarePlan>

The list of patient care plans to be inserted.

Returns

Task

A task representing the asynchronous operation.

InsertOneAsync(PatientCarePlan)

Inserts a single patient care plan into the MongoDB collection. This method takes a PatientCarePlan object as input and attempts to insert it into the database. If an exception occurs during the insertion process, it logs the error with details about the patient and the exception, and then rethrows the exception to be handled by the calling code.

public override Task InsertOneAsync(PatientCarePlan patient)

Parameters

patient PatientCarePlan

The patient care plan to be inserted.

Returns

Task

A task representing the asynchronous operation.