|
|
|
@@ -20,6 +20,7 @@ namespace adas_core.Infrastructure.Repositories;
|
|
|
|
|
/// options lists, diagnoses, allergies, procedures, treatments, and other reference data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">The type of MasterList entity to manage.</typeparam>
|
|
|
|
|
/// <!-- aidoc:v1 sig=f958de2 -->
|
|
|
|
|
public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository<T> where T : MasterList
|
|
|
|
|
{
|
|
|
|
|
private readonly ApiSettings _apiSettings;
|
|
|
|
@@ -30,6 +31,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="apiSettings">API settings containing collection names configuration.</param>
|
|
|
|
|
/// <param name="database">The MongoDB database instance.</param>
|
|
|
|
|
/// <exception cref="ArgumentNullException">Thrown when apiSettings is null.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=800d538 body=d2b18a3 -->
|
|
|
|
|
public MasterListRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
|
|
|
|
|
{
|
|
|
|
|
if (apiSettings == null) throw new ArgumentNullException(nameof(apiSettings));
|
|
|
|
@@ -41,6 +43,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// Maps different MasterList subtypes to their corresponding MongoDB collection names.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The collection name for the current MasterList type.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=94e22ff body=64e6c55 -->
|
|
|
|
|
public override string GetCollectionName()
|
|
|
|
|
{
|
|
|
|
|
return typeof(T) switch
|
|
|
|
@@ -76,6 +79,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">The entity to insert.</param>
|
|
|
|
|
/// <exception cref="Exception">Throws and re-throws exceptions after logging.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=c7a7ad8 body=26b3581 -->
|
|
|
|
|
public override async Task InsertOneAsync(T entity)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -94,6 +98,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the entity to delete.</param>
|
|
|
|
|
/// <exception cref="Exception">Throws and re-throws exceptions after logging.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=3de1ad6 body=fe0ba8c -->
|
|
|
|
|
public async Task Delete(ObjectId id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -109,10 +114,11 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates an existing master list entity with full replacement.
|
|
|
|
|
/// Replaces the document matching <paramref name="entity"/>'s identifier, or inserts it as a new document when no match is found (upsert).
|
|
|
|
|
/// Any exception raised during the operation is logged and rethrown to the caller.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">The entity with updated values.</param>
|
|
|
|
|
/// <exception cref="Exception">Throws and re-throws exceptions after logging.</exception>
|
|
|
|
|
/// <param name="entity">The entity to persist; its <c>Id</c> property is used to locate the existing document to replace.</param>
|
|
|
|
|
/// <!-- aidoc:v1 sig=019b691 body=863650a -->
|
|
|
|
|
public async Task Update(T entity)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -133,6 +139,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="newOpt">The OptionList with updated values.</param>
|
|
|
|
|
/// <returns>The updated OptionList if found; otherwise, null.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=64ca4dd body=a7714e6 -->
|
|
|
|
|
public async Task<OptionList?> UpdateFullMasterListOption(ObjectId id, OptionList newOpt)
|
|
|
|
|
{
|
|
|
|
|
var filter = Builders<T>.Filter.Where(o => o.Id == id && o.Options.Any(opt => opt.Id == newOpt.Id)
|
|
|
|
@@ -161,11 +168,11 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds a master list entity by its ID with options projection limited to 100 items.
|
|
|
|
|
/// Asynchronously finds an entity by its <paramref name="id"/>, returning the first matching document with its "options" array limited to 100 elements via projection. If no document matches or an exception is thrown, the error is logged and <c>null</c> is returned.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the entity to retrieve.</param>
|
|
|
|
|
/// <returns>The MasterList entity if found; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="ObjectId"/> used to build the equality filter against the entity's identifier.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{T}"/> that yields the matching entity, or <c>null</c> when no document is found or the operation fails.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=81ac96a body=1519944 -->
|
|
|
|
|
public async Task<T?> FindById(ObjectId id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -189,14 +196,13 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// Retrieves a single <see cref="OptionList"/> item identified by <paramref name="masterId"/> and <paramref name="optionId"/>, applying locale-based translation. When <paramref name="locale"/> is <see cref="LocaleEnum.Default"/> or matches the document's default locale, the base option name is used; otherwise the method looks up a translation in the option's locale items and falls back to the base name when no translation exists. Returns <c>null</c> when no matching option is found or when an error is encountered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="masterId">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="optionId">The ObjectId of the option to retrieve.</param>
|
|
|
|
|
/// <param name="locale">The locale for translation.</param>
|
|
|
|
|
/// <returns>The OptionList with translated fields if found; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="masterId">The identifier of the master document that owns the options collection.</param>
|
|
|
|
|
/// <param name="optionId">The identifier of the specific option to retrieve.</param>
|
|
|
|
|
/// <param name="locale">The desired locale used to select translated content.</param>
|
|
|
|
|
/// <returns>A <see cref="Task"/> that yields the matching <see cref="OptionList"/>, or <c>null</c> if the option does not exist or the lookup fails.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=fdb2628 body=0e4983e -->
|
|
|
|
|
public async Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId, LocaleEnum locale)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -342,6 +348,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="optionId">The ObjectId of the option to retrieve.</param>
|
|
|
|
|
/// <returns>The OptionList if found; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=ccc34cb body=71837cc -->
|
|
|
|
|
public async Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -367,13 +374,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds a master list entity by its ID with optional locale translation for options.
|
|
|
|
|
/// Uses MongoDB aggregation to unwind options and apply translations.
|
|
|
|
|
/// Retrieves an entity of type <c>T</c> by its <see cref="ObjectId"/> identifier, applying locale-aware resolution of option names through a MongoDB aggregation pipeline. When <paramref name="locale"/> is <see langword="null"/>, equals <see cref="LocaleEnum.Default"/>, or matches the document's <c>defaultLocale</c>, the original option name is returned; otherwise, the translated name from <c>localeItems</c> is used with a fallback to the original name when no translation exists. Any exception is logged and swallowed, returning <see langword="null"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the entity to retrieve.</param>
|
|
|
|
|
/// <param name="locale">Optional locale for translated option names.</param>
|
|
|
|
|
/// <returns>The MasterList entity with translated options if found; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="ObjectId"/> of the document to retrieve.</param>
|
|
|
|
|
/// <param name="locale">The optional <see cref="LocaleEnum"/> used to resolve translated option names. When omitted or set to <see cref="LocaleEnum.Default"/>, the original names are used.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{T}"/> that yields the matching entity, or <see langword="null"/> when no document is found or an error is logged.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=cb4a658 body=f2e88d8 -->
|
|
|
|
|
public async Task<T?> FindById(ObjectId id, LocaleEnum? locale)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -551,11 +557,13 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds a master list entity by its name.
|
|
|
|
|
/// Asynchronously searches the underlying collection for an entity matching the specified <paramref name="name"/>,
|
|
|
|
|
/// projecting the <c>options</c> field to a maximum of 100 elements to limit the payload size.
|
|
|
|
|
/// Returns <see langword="null"/> if no entity is found or if an error occurs while querying the collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the master list to retrieve.</param>
|
|
|
|
|
/// <returns>The MasterList entity if found; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="name">The name of the entity to search for. Used to build an equality filter against the <c>Name</c> field.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{T}"/> that yields the matching entity of type <c>T</c>, or <see langword="null"/> when no match is found or an error is logged.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=80a1541 body=8b5b558 -->
|
|
|
|
|
public async Task<T?> FindByName(string name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -584,16 +592,19 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="textSearch">Optional text to search within options.</param>
|
|
|
|
|
/// <returns>A list of matching OptionList items.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=569d223 body=bb7f2c6 -->
|
|
|
|
|
public async Task<List<OptionList>> GetMasterListByIdAndTextSearchContaining(ObjectId id, string? textSearch)
|
|
|
|
|
{
|
|
|
|
|
return await GetOptionsByTextSearch(textSearch, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves paginated master lists with optional text filtering.
|
|
|
|
|
/// Builds a sorted master-list query for documents of type <typeparamref name="T"/>, returning all documents ordered ascending by the <c>name</c> field, or only those whose <c>Name</c> matches <paramref name="filter"/>'s search text via a case-insensitive regex (with special characters escaped) when provided.
|
|
|
|
|
/// If <paramref name="filter"/> is null, its <c>FilteredRequest</c> is null, or <c>FilteredRequest.Text</c> is null or empty, no additional filter is applied and the unfiltered, sorted result is returned.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filter">The pagination and filtering parameters.</param>
|
|
|
|
|
/// <returns>A fluent queryable for MasterList results.</returns>
|
|
|
|
|
/// <param name="filter">The <see cref="PaginationFilter"/> containing the optional <c>FilteredRequest.Text</c> used to match the <c>Name</c> field.</param>
|
|
|
|
|
/// <returns>An <see cref="IFindFluent{TDocument, TProjection}"/> representing the sorted, filtered query against the collection of <typeparamref name="T"/>.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=bbb39c7 body=f42ebaa -->
|
|
|
|
|
public IFindFluent<T, T> GetPaginatedMasterList(PaginationFilter filter)
|
|
|
|
|
{
|
|
|
|
|
var filterBuilder = Builders<T>.Filter;
|
|
|
|
@@ -616,11 +627,13 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves paginated options within a master list with optional text filtering.
|
|
|
|
|
/// Asynchronously retrieves options from the master list identified by <paramref name="listId"/>, optionally applying a case-insensitive text filter against each option's name, description, and option type.
|
|
|
|
|
/// Returns an empty list when no master list matches the supplied identifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filter">The pagination and filtering parameters.</param>
|
|
|
|
|
/// <param name="listId">The ObjectId of the master list.</param>
|
|
|
|
|
/// <returns>A list of filtered OptionList items.</returns>
|
|
|
|
|
/// <param name="filter">A <see cref="PaginationFilter"/> whose <c>FilteredRequest.Text</c>, when provided, is used to narrow the options by matching against the name, description, or option type.</param>
|
|
|
|
|
/// <param name="listId">The identifier of the master list whose options should be returned.</param>
|
|
|
|
|
/// <returns>A task that resolves to a <see cref="List{OptionList}"/> containing the matching options, or an empty list if the master list is not found.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=2ac8d75 body=b25fb18 -->
|
|
|
|
|
public async Task<List<OptionList>> GetPaginatedOptions(PaginationFilter filter, ObjectId listId)
|
|
|
|
|
{
|
|
|
|
|
//TODO: LOCALE
|
|
|
|
@@ -640,12 +653,14 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a new option to a master list.
|
|
|
|
|
/// Adds a new <see cref="OptionList"/> to the master list identified by <paramref name="id"/>.
|
|
|
|
|
/// Returns null if a matching option already exists, if the update modifies no documents, or if an exception is thrown.
|
|
|
|
|
/// When the request comes from the admin panel, the locale items from <paramref name="opt"/> are reused; otherwise, a new locale entry is generated based on the current default locale of the list.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="opt">The option element to add.</param>
|
|
|
|
|
/// <returns>The newly created OptionList if successful; otherwise, null if duplicate exists.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="ObjectId"/> of the master list to update.</param>
|
|
|
|
|
/// <param name="opt">The <see cref="FilterOptionListElement"/> describing the option to add.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{T}"/> containing the created <see cref="OptionList"/> on success, or null if the operation does not persist any change.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=1602f0d body=e7fd138 -->
|
|
|
|
|
public async Task<OptionList?> AddOptionToMasterList(ObjectId id, FilterOptionListElement opt)
|
|
|
|
|
{
|
|
|
|
|
var exist = await GetMasterListByIdAndSearchOptions(id, opt);
|
|
|
|
@@ -685,10 +700,11 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves all master list entities.
|
|
|
|
|
/// Retrieves all entities of type <typeparamref name="T"/> from the data store asynchronously.
|
|
|
|
|
/// If an error occurs during retrieval, it is logged and an empty collection is returned instead of propagating the exception.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An enumerable of all MasterList entities.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns empty list on failure.</exception>
|
|
|
|
|
/// <returns>A task that yields an <see cref="IEnumerable{T}"/> containing all entities, or an empty collection when an error is encountered.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=3a61c61 body=40d7129 -->
|
|
|
|
|
public async Task<IEnumerable<T>> GetAll()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -704,10 +720,10 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves all master list entities without options, returning only metadata.
|
|
|
|
|
/// Retrieves every entry from the master list collection and projects each into a <see cref="MasterListDto"/>, where <see cref="MasterListDto.Options"/> contains the total count of options. If the underlying query fails, the exception is logged and an empty collection is returned.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An enumerable of MasterListDto containing id, name, description, listType, and options count.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns empty list on failure.</exception>
|
|
|
|
|
/// <returns>A task that resolves to an <see cref="IEnumerable{MasterListDto}"/> containing all master list entries, or an empty collection when an error occurs.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=e493435 body=1c299ba -->
|
|
|
|
|
public async Task<IEnumerable<MasterListDto>> GetAllWithoutOptions()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -732,10 +748,11 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Counts the total number of master list entities in the collection.
|
|
|
|
|
/// Asynchronously counts the total number of documents in the underlying collection.
|
|
|
|
|
/// If the operation fails, the exception is logged and the method returns 0 as a fallback value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The total count of entities.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns 0 on failure.</exception>
|
|
|
|
|
/// <returns>A <see cref="Task{Int32}"/> representing the asynchronous operation, containing the total document count, or 0 if an error occurred.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=f1f0a98 body=01cd3d1 -->
|
|
|
|
|
public async Task<int> Count()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -758,6 +775,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="filters">The filter criteria including text, name, description, and optionType.</param>
|
|
|
|
|
/// <returns>A list of matching OptionList items ordered by name.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns empty list on failure.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=f6ee5be body=17d6a96 -->
|
|
|
|
|
public async Task<List<OptionList>> GetMasterListByIdAndSearchOptions(ObjectId id, FilterOptionListElement? filters)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -973,6 +991,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="locale">The locale for translation updates.</param>
|
|
|
|
|
/// <returns>The updated OptionList if successful; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=e771f23 body=5520a4a -->
|
|
|
|
|
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt, LocaleEnum locale)
|
|
|
|
|
{
|
|
|
|
|
// 1. Evitar duplicados
|
|
|
|
@@ -1073,6 +1092,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="newOpt">The OptionList with updated values.</param>
|
|
|
|
|
/// <returns>The updated OptionList if successful; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=6def54c body=9554543 -->
|
|
|
|
|
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList newOpt)
|
|
|
|
|
{
|
|
|
|
|
var master = await FindById(id);
|
|
|
|
@@ -1108,6 +1128,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="deleteOptId">The ObjectId of the option to delete.</param>
|
|
|
|
|
/// <returns>True if the option was deleted; otherwise, false.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=e663f16 body=75627bc -->
|
|
|
|
|
public async Task<bool> DeleteMasterListOption(ObjectId id, ObjectId deleteOptId)
|
|
|
|
|
{
|
|
|
|
|
// Define el filtro para encontrar el documento por su _id
|
|
|
|
@@ -1126,12 +1147,15 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the metadata details for a master list.
|
|
|
|
|
/// Updates the option details of an existing master list document identified by <paramref name="id"/>, applying only the
|
|
|
|
|
/// fields that are provided in <paramref name="opt"/> (<c>CanAddElement</c> and <c>OptionListDetails</c>) using a partial
|
|
|
|
|
/// <c>$set</c> update. Returns the supplied <see cref="UpdateMasterListDetailsDto"/> when the document is found and modified,
|
|
|
|
|
/// or <see langword="null"/> when no document matches the filter, no fields are modified, or the operation fails.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="opt">The UpdateMasterListDetailsDto with updated values.</param>
|
|
|
|
|
/// <returns>The updated UpdateMasterListDetailsDto if successful; otherwise, null.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns null on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="MongoDB.Bson.ObjectId"/> identifier of the master list document to update.</param>
|
|
|
|
|
/// <param name="opt">The <see cref="UpdateMasterListDetailsDto"/> containing the new values; only non-null properties are applied to the document.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{UpdateMasterListDetailsDto}"/> that resolves to the updated DTO on success, or <see langword="null"/> if the document was not found, was not modified, or an error was logged.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=53d4179 body=49f50ca -->
|
|
|
|
|
public async Task<UpdateMasterListDetailsDto?> UpdateOptionDetailsToMasterList(ObjectId id,
|
|
|
|
|
UpdateMasterListDetailsDto opt)
|
|
|
|
|
{
|
|
|
|
@@ -1161,12 +1185,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the name of a master list.
|
|
|
|
|
/// Updates the <see cref="Name"/> of the master list entry identified by <paramref name="id"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="name">The new name.</param>
|
|
|
|
|
/// <returns>True if the update was successful; otherwise, false.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns false on failure.</exception>
|
|
|
|
|
/// <param name="id">The identifier of the master list entry to update.</param>
|
|
|
|
|
/// <param name="name">The new name to assign to the master list entry.</param>
|
|
|
|
|
/// <returns><see langword="true"/> if the document was modified; otherwise, <see langword="false"/>, including when the update fails due to an exception.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=5b79a51 body=36dfe99 -->
|
|
|
|
|
public async Task<bool> UpdateMasterListName(ObjectId id, string name)
|
|
|
|
|
{
|
|
|
|
|
var filter = Builders<T>.Filter.And(
|
|
|
|
@@ -1187,12 +1211,13 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the description of a master list.
|
|
|
|
|
/// Updates the <c>Description</c> field of the document identified by <paramref name="id"/> in the master list collection.
|
|
|
|
|
/// Returns <see langword="true"/> when the update modified at least one document, and <see langword="false"/> when no document was modified or when an error is caught and logged.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="description">The new description.</param>
|
|
|
|
|
/// <returns>True if the update was successful; otherwise, false.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns false on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="ObjectId"/> of the document whose description should be updated.</param>
|
|
|
|
|
/// <param name="description">The new description value to set on the document.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{Boolean}"/> that resolves to <see langword="true"/> if the document was modified, otherwise <see langword="false"/>.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=5a27a55 body=3552f46 -->
|
|
|
|
|
public async Task<bool> UpdateMasterListDescription(ObjectId id, string description)
|
|
|
|
|
{
|
|
|
|
|
var filter = Builders<T>.Filter.And(
|
|
|
|
@@ -1213,12 +1238,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes an option from a master list by matching all its properties.
|
|
|
|
|
/// Removes the specified <paramref name="oldOpt"/> entry from the "options" array of the MasterList document identified by <paramref name="id"/>, matching on all of the option's properties (name, option type, icons, colors, default flag, and description). Returns <see langword="true"/> when the document was modified (the option was found and pulled), and <see langword="false"/> when no document was modified or when the update fails and the exception is logged.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="oldOpt">The OptionList to remove.</param>
|
|
|
|
|
/// <returns>True if the option was removed; otherwise, false.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns false on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="ObjectId"/> of the MasterList document to update.</param>
|
|
|
|
|
/// <param name="oldOpt">The <see cref="OptionList"/> instance whose properties define the filter used to pull the matching entry from the "options" array.</param>
|
|
|
|
|
/// <returns>A <see cref="Task{Boolean}"/> that resolves to <see langword="true"/> if an option was successfully removed, otherwise <see langword="false"/>.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=8de50cd body=d974b9b -->
|
|
|
|
|
public async Task<bool> RemoveMasterListOption(ObjectId id, OptionList oldOpt)
|
|
|
|
|
{
|
|
|
|
|
var filter = Builders<T>.Filter.Eq("_id", id);
|
|
|
|
@@ -1247,9 +1272,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates necessary indexes for the MasterList collection.
|
|
|
|
|
/// Currently creates text indexes for DiagnosisList on options.name, options.description, and options._id.
|
|
|
|
|
/// Creates MongoDB indexes on the underlying collection when the document type is <see cref="DiagnosisList"/>.
|
|
|
|
|
/// Three ascending indexes are created on the <c>options.name</c>, <c>options.description</c>, and <c>options._id</c> fields,
|
|
|
|
|
/// configured with <c>Background = true</c>, <c>Unique = false</c>, and Spanish text indexing via <c>LanguageOverride</c> and <c>DefaultLanguage</c>.
|
|
|
|
|
/// For any other type <typeparamref name="T"/>, no indexes are created.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <!-- aidoc:v1 sig=4955da2 body=2c8d1f7 -->
|
|
|
|
|
public override async Task CreateIndexes()
|
|
|
|
|
{
|
|
|
|
|
if (typeof(T) == typeof(DiagnosisList))
|
|
|
|
@@ -1275,6 +1303,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="textSearch">Optional text to search within options.</param>
|
|
|
|
|
/// <returns>A list of matching OptionList items.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=484b092 body=48e3496 -->
|
|
|
|
|
public async Task<List<OptionList>> GetMasterListByTextSearch(string? textSearch)
|
|
|
|
|
{
|
|
|
|
|
return await GetOptionsByTextSearch(textSearch);
|
|
|
|
@@ -1287,6 +1316,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// <param name="id">Optional master list ObjectId to filter results.</param>
|
|
|
|
|
/// <returns>A list of matching OptionList items ordered by name.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns empty list on failure.</exception>
|
|
|
|
|
/// <!-- aidoc:v1 sig=6ebeac8 body=1d7bbb7 -->
|
|
|
|
|
private async Task<List<OptionList>> GetOptionsByTextSearch(string? textSearch, ObjectId? id = null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -1359,11 +1389,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a fluent query for paginated results with combined filters.
|
|
|
|
|
/// Builds a fluent MongoDB find query against the collection, combining the supplied <paramref name="filters"/> with a logical AND when any are present, or using an empty filter that matches every document when the list is empty. The returned query is pre-configured with the given <paramref name="sort"/> ordering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filters">List of filter definitions to apply.</param>
|
|
|
|
|
/// <param name="sort">Sort definition for the query results.</param>
|
|
|
|
|
/// <returns>A fluent queryable for T results.</returns>
|
|
|
|
|
/// <param name="filters">List of <see cref="FilterDefinition{T}"/> predicates to apply; an empty list results in no filtering.</param>
|
|
|
|
|
/// <param name="sort">The <see cref="SortDefinition{T}"/> ordering applied to the results.</param>
|
|
|
|
|
/// <returns>An <see cref="IFindFluent{T, T}"/> representing the configured find operation.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=704d715 body=2a35652 -->
|
|
|
|
|
private IFindFluent<T, T> CreateFindFluent(List<FilterDefinition<T>> filters, SortDefinition<T> sort)
|
|
|
|
|
{
|
|
|
|
|
var combinedFilter = filters.Any()
|
|
|
|
@@ -1373,12 +1404,12 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates new locale items for a master list option based on a default locale.
|
|
|
|
|
/// Creates LocaleItem entries for all locales except the specified default.
|
|
|
|
|
/// Creates a new <see cref="Locale"/> instance and populates each property whose name matches a <see cref="LocaleEnum"/> value, excluding <see cref="LocaleEnum.Default"/> and the value supplied in <paramref name="localeList"/>, with a new <see cref="LocaleItem"/> whose <see cref="LocaleItem.Name"/> is set to <paramref name="opt"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="localeList">The default locale to exclude from translations.</param>
|
|
|
|
|
/// <param name="opt">The option name to use as default translation.</param>
|
|
|
|
|
/// <returns>A Locale object with translations for all other locales.</returns>
|
|
|
|
|
/// <param name="localeList">The <see cref="LocaleEnum"/> value to skip when populating the new <see cref="Locale"/>.</param>
|
|
|
|
|
/// <param name="opt">The name assigned to each created <see cref="LocaleItem"/> entry.</param>
|
|
|
|
|
/// <returns>A <see cref="Locale"/> with its matching <see cref="LocaleItem"/> properties initialized, except for the omitted locale.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=147db59 body=9b63847 -->
|
|
|
|
|
private Locale GetNewItemLocale(LocaleEnum localeList, string opt)
|
|
|
|
|
{
|
|
|
|
|
var newLocale = new Locale();
|
|
|
|
@@ -1418,6 +1449,7 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">The input string to build the pattern from.</param>
|
|
|
|
|
/// <returns>A regex-compatible pattern string.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=2992c00 body=ae88daf -->
|
|
|
|
|
private static string BuildRegexPattern(string input)
|
|
|
|
|
{
|
|
|
|
|
var regexPattern = new StringBuilder();
|
|
|
|
@@ -1451,14 +1483,18 @@ public class MasterListRepository<T> : MongoRepository<T>, IMasterListRepository
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Searches for options within a master list by name with locale translation.
|
|
|
|
|
/// Uses MongoDB aggregation pipeline to apply locale-aware filtering.
|
|
|
|
|
/// Retrieves the options of a master list document identified by <paramref name="id"/>, applying locale-aware
|
|
|
|
|
/// translation of the option name and filtering the results to those whose translated name matches
|
|
|
|
|
/// <paramref name="newOptName"/>. When the requested <paramref name="locale"/> matches the document's default
|
|
|
|
|
/// locale the original name is used; otherwise the translated name is preferred and falls back to the original
|
|
|
|
|
/// when no translation exists. Returns the matching options ordered by name, or an empty list when the
|
|
|
|
|
/// document is not found, no option matches, or an error is logged.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ObjectId of the master list.</param>
|
|
|
|
|
/// <param name="newOptName">The option name to search for.</param>
|
|
|
|
|
/// <param name="locale">The locale for translation.</param>
|
|
|
|
|
/// <returns>A list of matching OptionList items ordered by name.</returns>
|
|
|
|
|
/// <exception cref="Exception">Logs errors and returns empty list on failure.</exception>
|
|
|
|
|
/// <param name="id">The <see cref="MongoDB.Bson.ObjectId"/> of the master list document to query.</param>
|
|
|
|
|
/// <param name="newOptName">The option name to match against the locale-resolved name of each option.</param>
|
|
|
|
|
/// <param name="locale">The <see cref="LocaleEnum"/> value used to select the translated name for each option.</param>
|
|
|
|
|
/// <returns>A <see cref="Task"/> containing a <see cref="List{Object}"/> of matching options ordered by name, or an empty list when no options match or an error occurs.</returns>
|
|
|
|
|
/// <!-- aidoc:v1 sig=342dc63 body=21f31fc -->
|
|
|
|
|
private async Task<List<OptionList>> GetMasterListByIdAndTextSearch(
|
|
|
|
|
ObjectId id, string newOptName, LocaleEnum locale)
|
|
|
|
|
{
|
|
|
|
|