Table of Contents

Class MasterListRepository<T>

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

Generic repository implementation for managing MasterList entities in MongoDB. Provides CRUD operations and specialized queries for various master list types including options lists, diagnoses, allergies, procedures, treatments, and other reference data.

public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository<T>, IMongoRepository<T> where T : MasterList

Type Parameters

T

The type of MasterList entity to manage.

Inheritance
MasterListRepository<T>
Implements
Inherited Members
Extension Methods

Constructors

MasterListRepository(IOptions<ApiSettings>, IMongoDatabase)

Initializes a new instance of the MasterListRepository.

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

Parameters

apiSettings IOptions<ApiSettings>

API settings containing collection names configuration.

database IMongoDatabase

The MongoDB database instance.

Exceptions

ArgumentNullException

Thrown when apiSettings is null.

Methods

AddOptionToMasterList(ObjectId, FilterOptionListElement)

Adds a new option to a master list.

public Task<OptionList?> AddOptionToMasterList(ObjectId id, FilterOptionListElement opt)

Parameters

id ObjectId

The ObjectId of the master list.

opt FilterOptionListElement

The option element to add.

Returns

Task<OptionList>

The newly created OptionList if successful; otherwise, null if duplicate exists.

Exceptions

Exception

Logs errors and returns null on failure.

Count()

Counts the total number of master list entities in the collection.

public Task<int> Count()

Returns

Task<int>

The total count of entities.

Exceptions

Exception

Logs errors and returns 0 on failure.

CreateIndexes()

Creates necessary indexes for the MasterList collection. Currently creates text indexes for DiagnosisList on options.name, options.description, and options._id.

public override Task CreateIndexes()

Returns

Task

Delete(ObjectId)

Deletes a master list entity by its ID.

public Task Delete(ObjectId id)

Parameters

id ObjectId

The ObjectId of the entity to delete.

Returns

Task

Exceptions

Exception

Throws and re-throws exceptions after logging.

DeleteMasterListOption(ObjectId, ObjectId)

Deletes a specific option from a master list.

public Task<bool> DeleteMasterListOption(ObjectId id, ObjectId deleteOptId)

Parameters

id ObjectId

The ObjectId of the master list.

deleteOptId ObjectId

The ObjectId of the option to delete.

Returns

Task<bool>

True if the option was deleted; otherwise, false.

FindById(ObjectId)

Finds a master list entity by its ID with options projection limited to 100 items.

public Task<T?> FindById(ObjectId id)

Parameters

id ObjectId

The ObjectId of the entity to retrieve.

Returns

Task<T>

The MasterList entity if found; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

FindById(ObjectId, LocaleEnum?)

Finds a master list entity by its ID with optional locale translation for options. Uses MongoDB aggregation to unwind options and apply translations.

public Task<T?> FindById(ObjectId id, LocaleEnum? locale)

Parameters

id ObjectId

The ObjectId of the entity to retrieve.

locale LocaleEnum?

Optional locale for translated option names.

Returns

Task<T>

The MasterList entity with translated options if found; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

FindByName(string)

Finds a master list entity by its name.

public Task<T?> FindByName(string name)

Parameters

name string

The name of the master list to retrieve.

Returns

Task<T>

The MasterList entity if found; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

FindOptionItemById(ObjectId, ObjectId)

Finds a specific option within a master list by master and option IDs without locale translation.

public Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId)

Parameters

masterId ObjectId

The ObjectId of the master list.

optionId ObjectId

The ObjectId of the option to retrieve.

Returns

Task<OptionList>

The OptionList if found; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

FindOptionItemById(ObjectId, ObjectId, LocaleEnum)

Finds a specific option within a master list by master and option IDs with locale translation. Uses MongoDB aggregation to apply translations and return the translated option.

public Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId, LocaleEnum locale)

Parameters

masterId ObjectId

The ObjectId of the master list.

optionId ObjectId

The ObjectId of the option to retrieve.

locale LocaleEnum

The locale for translation.

Returns

Task<OptionList>

The OptionList with translated fields if found; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

GetAll()

Retrieves all master list entities.

public Task<IEnumerable<T>> GetAll()

Returns

Task<IEnumerable<T>>

An enumerable of all MasterList entities.

Exceptions

Exception

Logs errors and returns empty list on failure.

GetAllWithoutOptions()

Retrieves all master list entities without options, returning only metadata.

public Task<IEnumerable<MasterListDto>> GetAllWithoutOptions()

Returns

Task<IEnumerable<MasterListDto>>

An enumerable of MasterListDto containing id, name, description, listType, and options count.

Exceptions

Exception

Logs errors and returns empty list on failure.

GetCollectionName()

Gets the name of the collection based on the entity type T. Maps different MasterList subtypes to their corresponding MongoDB collection names.

public override string GetCollectionName()

Returns

string

The collection name for the current MasterList type.

GetMasterListByIdAndSearchOptions(ObjectId, FilterOptionListElement?)

Searches for options within a master list using multiple filter criteria. Uses MongoDB aggregation pipeline to apply filters and locale translations.

public Task<List<OptionList>> GetMasterListByIdAndSearchOptions(ObjectId id, FilterOptionListElement? filters)

Parameters

id ObjectId

The ObjectId of the master list.

filters FilterOptionListElement

The filter criteria including text, name, description, and optionType.

Returns

Task<List<OptionList>>

A list of matching OptionList items ordered by name.

Exceptions

Exception

Logs errors and returns empty list on failure.

GetMasterListByIdAndTextSearchContaining(ObjectId, string?)

Gets options from a master list filtered by text search.

public Task<List<OptionList>> GetMasterListByIdAndTextSearchContaining(ObjectId id, string? textSearch)

Parameters

id ObjectId

The ObjectId of the master list.

textSearch string

Optional text to search within options.

Returns

Task<List<OptionList>>

A list of matching OptionList items.

GetMasterListByTextSearch(string?)

Searches for options across all master lists using text search.

public Task<List<OptionList>> GetMasterListByTextSearch(string? textSearch)

Parameters

textSearch string

Optional text to search within options.

Returns

Task<List<OptionList>>

A list of matching OptionList items.

GetPaginatedMasterList(PaginationFilter)

Retrieves paginated master lists with optional text filtering.

public IFindFluent<T, T> GetPaginatedMasterList(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination and filtering parameters.

Returns

IFindFluent<T, T>

A fluent queryable for MasterList results.

GetPaginatedOptions(PaginationFilter, ObjectId)

Retrieves paginated options within a master list with optional text filtering.

public Task<List<OptionList>> GetPaginatedOptions(PaginationFilter filter, ObjectId listId)

Parameters

filter PaginationFilter

The pagination and filtering parameters.

listId ObjectId

The ObjectId of the master list.

Returns

Task<List<OptionList>>

A list of filtered OptionList items.

InsertOneAsync(T)

Inserts a new master list entity into the database.

public override Task InsertOneAsync(T entity)

Parameters

entity T

The entity to insert.

Returns

Task

Exceptions

Exception

Throws and re-throws exceptions after logging.

RemoveMasterListOption(ObjectId, OptionList)

Removes an option from a master list by matching all its properties.

public Task<bool> RemoveMasterListOption(ObjectId id, OptionList oldOpt)

Parameters

id ObjectId

The ObjectId of the master list.

oldOpt OptionList

The OptionList to remove.

Returns

Task<bool>

True if the option was removed; otherwise, false.

Exceptions

Exception

Logs errors and returns false on failure.

Update(T)

Updates an existing master list entity with full replacement.

public Task Update(T entity)

Parameters

entity T

The entity with updated values.

Returns

Task

Exceptions

Exception

Throws and re-throws exceptions after logging.

UpdateFullMasterListOption(ObjectId, OptionList)

Updates a specific option within a master list with full property replacement.

public Task<OptionList?> UpdateFullMasterListOption(ObjectId id, OptionList newOpt)

Parameters

id ObjectId

The ObjectId of the master list.

newOpt OptionList

The OptionList with updated values.

Returns

Task<OptionList>

The updated OptionList if found; otherwise, null.

UpdateMasterListDescription(ObjectId, string)

Updates the description of a master list.

public Task<bool> UpdateMasterListDescription(ObjectId id, string description)

Parameters

id ObjectId

The ObjectId of the master list.

description string

The new description.

Returns

Task<bool>

True if the update was successful; otherwise, false.

Exceptions

Exception

Logs errors and returns false on failure.

UpdateMasterListName(ObjectId, string)

Updates the name of a master list.

public Task<bool> UpdateMasterListName(ObjectId id, string name)

Parameters

id ObjectId

The ObjectId of the master list.

name string

The new name.

Returns

Task<bool>

True if the update was successful; otherwise, false.

Exceptions

Exception

Logs errors and returns false on failure.

UpdateMasterListOption(ObjectId, OptionList)

Updates a specific option within a master list with full replacement.

public Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt)

Parameters

id ObjectId

The ObjectId of the master list.

newOpt OptionList

The OptionList with updated values.

Returns

Task<OptionList>

The updated OptionList if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

UpdateMasterListOption(ObjectId, OptionList, LocaleEnum)

Updates a specific option within a master list with locale-aware field updates.

public Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt, LocaleEnum locale)

Parameters

id ObjectId

The ObjectId of the master list.

newOpt OptionList

The OptionList with updated values.

locale LocaleEnum

The locale for translation updates.

Returns

Task<OptionList>

The updated OptionList if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.

UpdateOptionDetailsToMasterList(ObjectId, UpdateMasterListDetailsDto)

Updates the metadata details for a master list.

public Task<UpdateMasterListDetailsDto?> UpdateOptionDetailsToMasterList(ObjectId id, UpdateMasterListDetailsDto opt)

Parameters

id ObjectId

The ObjectId of the master list.

opt UpdateMasterListDetailsDto

The UpdateMasterListDetailsDto with updated values.

Returns

Task<UpdateMasterListDetailsDto>

The updated UpdateMasterListDetailsDto if successful; otherwise, null.

Exceptions

Exception

Logs errors and returns null on failure.