Table of Contents

Class AppointmentArchiveRepository

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

Repository for managing archived patient appointments in MongoDB. This repository provides methods to insert, delete, and manage archived appointments, ensuring efficient storage and retrieval of historical appointment data.

public class AppointmentArchiveRepository : MongoRepository<PatientAppointment>, IMongoRepository<PatientAppointment>, IAppointmentArchiveRepository
Inheritance
AppointmentArchiveRepository
Implements
Inherited Members
Extension Methods

Constructors

AppointmentArchiveRepository(IOptions<ApiSettings>, IMongoDatabase)

Initializes a new instance of the AppointmentArchiveRepository class with the specified API settings and MongoDB database. The constructor ensures that the API settings are provided and initializes the base repository with the given database connection.

public AppointmentArchiveRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)

Parameters

apiSettings IOptions<ApiSettings>

The API settings containing configuration for the archive collection.

database IMongoDatabase

The MongoDB database instance.

Exceptions

ArgumentNullException

Thrown when any of the input parameters are null.

Methods

CreateIndexes()

Creates indexes on the MongoDB collection for archived patient appointments to optimize query performance. This method defines the necessary indexes, such as an index on the "patientid" field, and ensures that they are created in the background without blocking other operations.

public override Task CreateIndexes()

Returns

Task

A task representing the asynchronous operation.

DeleteBeforeDate(DateTime)

Deletes all patient appointments from the archive collection that were created before the specified date. This method is asynchronous and uses a filter to identify and remove the relevant documents from the MongoDB collection.

public Task DeleteBeforeDate(DateTime date)

Parameters

date DateTime

The date before which all patient appointments should be deleted.

Returns

Task

A task representing the asynchronous operation.

GetCollectionName()

Gets the name of the MongoDB collection used for storing archived patient appointments. This method retrieves the collection name from the API settings, allowing for flexible configuration. If the collection name is not specified in the settings, it defaults to "archive_patients_appointments".

public override string GetCollectionName()

Returns

string

The name of the MongoDB collection for archived patient appointments.

InsertBatch(IEnumerable<PatientAppointment>)

Inserts a batch of patient appointments into the archive collection. This method is asynchronous and uses the MongoDB driver's bulk write capabilities to efficiently insert multiple documents in a single operation. It returns the count of inserted documents, allowing for verification of the operation's success.

public Task<long> InsertBatch(IEnumerable<PatientAppointment> appointment)

Parameters

appointment IEnumerable<PatientAppointment>

The collection of patient appointments to be inserted into the archive.

Returns

Task<long>

A task representing the asynchronous operation, with the result being the count of inserted documents.

InsertOneAsync(PatientAppointment)

Inserts a single patient appointment into the archive collection. This method is asynchronous and ensures that the appointment is stored in the MongoDB collection designated for archived appointments. It uses the MongoDB driver to perform the insertion operation efficiently.

public override Task InsertOneAsync(PatientAppointment appointment)

Parameters

appointment PatientAppointment

The patient appointment to be inserted into the archive collection.

Returns

Task

A task representing the asynchronous operation.