Table of Contents

Class DiagnosisRepository

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

Repository for managing patient diagnoses in a MongoDB collection. Provides methods for CRUD operations and querying diagnoses by patient ID and code.

public class DiagnosisRepository : MongoRepository<PatientDiagnosis>, IDiagnosisRepository, IMongoRepository<PatientDiagnosis>
Inheritance
DiagnosisRepository
Implements
Inherited Members
Extension Methods

Constructors

DiagnosisRepository(IOptions<ApiSettings>, IMongoDatabase)

Initializes a new instance of the DiagnosisRepository class with the specified API settings and MongoDB database. The API settings are used to determine the collection name for storing patient diagnoses.

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

Parameters

apiSettings IOptions<ApiSettings>

The API settings containing configuration for the repository.

database IMongoDatabase

The MongoDB database instance.

Exceptions

ArgumentNullException

Thrown when the API settings are null.

Methods

CreateIndexes()

Creates indexes for the patient diagnosis collection. This method ensures that the necessary indexes are created on the MongoDB collection to optimize query performance.

public override Task CreateIndexes()

Returns

Task

A task representing the asynchronous operation.

DeleteAsync(ObjectId)

Deletes a patient diagnosis by its ID. This method removes the diagnosis document from the MongoDB collection based on the provided ID.

public Task DeleteAsync(ObjectId id)

Parameters

id ObjectId

The ID of the patient diagnosis to delete.

Returns

Task

A task representing the asynchronous operation.

DeleteByPatientId(ObjectId)

Deletes all patient diagnoses associated with a specific patient ID. This method removes all diagnosis documents from the MongoDB collection that match the provided patient ID.

public Task DeleteByPatientId(ObjectId patientId)

Parameters

patientId ObjectId

The ID of the patient whose diagnoses are to be deleted.

Returns

Task

FindByPatientIdAndCode(ObjectId, string?, string?)

Finds a patient diagnosis by patient ID, code, and coding system. This method retrieves a single diagnosis document from the MongoDB collection that matches the provided patient ID, code, and coding system. If no matching diagnosis is found, it returns null.

public Task<PatientDiagnosis?> FindByPatientIdAndCode(ObjectId patientId, string? code, string? codingSystem)

Parameters

patientId ObjectId

The ID of the patient.

code string

The code of the diagnosis.

codingSystem string

The coding system of the diagnosis.

Returns

Task<PatientDiagnosis>

The matching patient diagnosis, or null if not found.

FindByPatientIdAsync(ObjectId)

Finds patient diagnoses by patient ID. This method retrieves all diagnosis documents from the MongoDB collection that match the provided patient ID. The results are returned as an asynchronous cursor, allowing for efficient retrieval of large datasets.

public Task<IAsyncCursor<PatientDiagnosis>> FindByPatientIdAsync(ObjectId patientId)

Parameters

patientId ObjectId

The ID of the patient whose diagnoses are to be retrieved.

Returns

Task<IAsyncCursor<PatientDiagnosis>>

An asynchronous cursor of patient diagnoses.

GetByPatient(ObjectId)

Retrieves a list of patient diagnoses for a given patient ID. The diagnoses are sorted in descending order by time, with the most recent diagnoses appearing first.

public Task<List<PatientDiagnosis>> GetByPatient(ObjectId patientId)

Parameters

patientId ObjectId

The ID of the patient whose diagnoses are to be retrieved.

Returns

Task<List<PatientDiagnosis>>

A list of patient diagnoses for the specified patient ID.

GetCollectionName()

Gets the name of the MongoDB collection for storing patient diagnoses. The collection name is determined by the API settings, and defaults to "patients_diagnosis" if not specified.

public override string GetCollectionName()

Returns

string

The name of the MongoDB collection for patient diagnoses.

InsertOneAsync(PatientDiagnosis)

Inserts a new patient diagnosis into the MongoDB collection. This method adds a new diagnosis document to the collection based on the provided PatientDiagnosis object.

public override Task InsertOneAsync(PatientDiagnosis diagnosis)

Parameters

diagnosis PatientDiagnosis

The patient diagnosis to insert.

Returns

Task

A task representing the asynchronous operation.

UpdateManyObjectId(string, ObjectId, ObjectId)

Updates the patient ID for all diagnoses that match the old patient ID. This method performs a bulk update operation on the MongoDB collection, changing the patient ID from the old value to the new value for all matching diagnosis documents.

public Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId)

Parameters

nameId string

The name ID associated with the patient.

id ObjectId

The new patient ID to be set.

oldId ObjectId

The old patient ID to be replaced.

Returns

Task

A task representing the asynchronous operation.