rama creada apartir de master en j
This commit is contained in:
@@ -18,6 +18,11 @@ using MongoDB.Driver;
|
||||
|
||||
namespace adas_core.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a generic service implementation for managing <see cref="MasterList"/> entities of type <typeparamref name="T"/>.
|
||||
/// Acts as the concrete implementation of the <see cref="IMasterListService{T}"/> contract for master list operations.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of master list entity managed by the service. Must derive from <see cref="MasterList"/> and expose a public parameterless constructor.</typeparam>
|
||||
public class MasterListService<T> : IMasterListService<T> where T : MasterList, new()
|
||||
{
|
||||
private readonly Lazy<IAdmissionService> _admissionService;
|
||||
@@ -62,6 +67,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
_assetsDirectory = Path.Combine(apiSettings.Value.PathToDisplayAssets);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a master list identified by the specified identifier. If the master list is not found, the operation is skipped and logged; if the master list is in use, a conflict exception is thrown.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list to delete.</param>
|
||||
/// <exception cref="ConflictException">Thrown when the master list is currently in use and cannot be deleted.</exception>
|
||||
public async Task DeleteMasterListById(ObjectId id)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
@@ -101,6 +111,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// Adds a filter option to an existing master list, records the change in the audit log, and broadcasts the update to subscribed clients.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list to which the option will be added.</param>
|
||||
/// <param name="opt">The filter option element to add to the master list.</param>
|
||||
/// <returns>The resulting <see cref="OptionList"/> entry if the option is successfully added; <c>null</c> if the master list cannot be found, no result is produced, or an error is encountered during the operation.</returns>
|
||||
public async Task<OptionList?> AddOptionToMasterList(ObjectId id, FilterOptionListElement opt)
|
||||
{
|
||||
try
|
||||
@@ -132,8 +148,16 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an option within the master list for the specified locale, and when the update succeeds, creates an audit log entry, broadcasts the change, and propagates the update to the affected patient item list. Returns <c>null</c> if the update fails, the result is <c>null</c>, or an exception is thrown during processing.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list whose option will be updated.</param>
|
||||
/// <param name="opt">The option to be applied to the master list.</param>
|
||||
/// <param name="typeName">The type name used when propagating the update to the patient item list.</param>
|
||||
/// <param name="locale">The locale used for the master list option update and retrieval of the updated entity for auditing.</param>
|
||||
/// <returns>The updated <see cref="OptionList"/>, or <c>null</c> if the update failed, the result was <c>null</c>, or an exception occurred.</returns>
|
||||
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList opt, string typeName,
|
||||
LocaleEnum locale)
|
||||
LocaleEnum locale)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -151,7 +175,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
await SendMasterListItemBroadcast(masterList, opt, oldOption, OperationType.UpdateMasterListItem);
|
||||
await UpdatePatientItemList(id,
|
||||
new UpdateOptionMasterListDto
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -163,6 +187,13 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a master list option, performing audit logging, broadcasting the change, and updating the patient item list when successful. Returns <c>null</c> if the option cannot be found or an error occurs.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list containing the option to update.</param>
|
||||
/// <param name="opt">The option containing the new values to apply.</param>
|
||||
/// <param name="typeName">The name of the type used when updating the associated patient item list.</param>
|
||||
/// <returns>The updated <see cref="OptionList"/> if the operation succeeds, or <c>null</c> if the master list is not found or an exception is thrown.</returns>
|
||||
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList opt, string typeName)
|
||||
{
|
||||
try
|
||||
@@ -181,7 +212,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
await SendMasterListItemBroadcast(masterList, opt, oldOption, OperationType.UpdateMasterListItem);
|
||||
await UpdatePatientItemList(id,
|
||||
new UpdateOptionMasterListDto
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -193,6 +224,15 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a full master list option, records the change in the audit log, notifies subscribers via broadcast, and propagates the update to the associated patient item list.
|
||||
/// Returns <c>null</c> if the underlying repository update fails or an exception is encountered, in which case the error is logged.
|
||||
/// Uses the default locale when retrieving the updated master list for audit purposes (locale handling is pending).
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list that contains the option to update.</param>
|
||||
/// <param name="opt">The option with the new values to apply to the master list.</param>
|
||||
/// <param name="typeName">The name of the entity type used when updating the related patient item list.</param>
|
||||
/// <returns>The updated <see cref="OptionList"/> when the operation succeeds; <c>null</c> when the update fails or an error is caught.</returns>
|
||||
public async Task<OptionList?> UpdateFullMasterListOption(ObjectId id, OptionList opt, string typeName)
|
||||
{
|
||||
try
|
||||
@@ -211,7 +251,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
await SendMasterListItemBroadcast(masterList, opt, oldOption, OperationType.UpdateMasterListItem);
|
||||
await UpdatePatientItemList(id,
|
||||
new UpdateOptionMasterListDto
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
{ OldOption = oldOption, UpdatedOption = opt, OptionId = opt.Id.ToString() }, typeName);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -223,6 +263,13 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an option from a master list by its identifier. On success, cascades the change to related patient item lists, creates an audit log entry, and broadcasts update and deletion events; returns <c>false</c> if the deletion fails, the master list or option is not found, or an error is logged.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list that contains the option.</param>
|
||||
/// <param name="optId">The identifier of the option to remove from the master list.</param>
|
||||
/// <param name="typeName">The name of the type used when cascading the deletion to related patient item lists.</param>
|
||||
/// <returns>A task that resolves to <c>true</c> when the option is successfully deleted and the side-effects are applied; otherwise, <c>false</c>.</returns>
|
||||
public async Task<bool> DeleteMasterListOption(ObjectId id, ObjectId optId, string typeName)
|
||||
{
|
||||
try
|
||||
@@ -253,8 +300,14 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the option details of a master list identified by the given identifier, records an audit log entry for the change, and broadcasts the update. Returns the updated details, or <c>null</c> if the update fails or an error occurs.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list whose option details will be updated.</param>
|
||||
/// <param name="opt">The new option details to apply to the master list.</param>
|
||||
/// <returns>A task that yields the updated <see cref="UpdateMasterListDetailsDto"/> on success, or <c>null</c> when the update fails or an exception is caught and logged.</returns>
|
||||
public async Task<UpdateMasterListDetailsDto?> UpdateOptionDetailsToMasterList(ObjectId id,
|
||||
UpdateMasterListDetailsDto opt)
|
||||
UpdateMasterListDetailsDto opt)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -278,6 +331,13 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the name of an existing master list identified by the specified id, records an audit log entry for the change, and broadcasts the update to subscribers.
|
||||
/// Returns <c>false</c> if the update fails or an exception is encountered, in which case the error is logged.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list to rename.</param>
|
||||
/// <param name="name">The new name to assign to the master list.</param>
|
||||
/// <returns>A task that resolves to <c>true</c> if the master list name was updated successfully; otherwise, <c>false</c>.</returns>
|
||||
public async Task<bool> UpdateMasterListName(ObjectId id, string name)
|
||||
{
|
||||
try
|
||||
@@ -302,6 +362,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the description of a master list identified by the specified id, creating an audit log entry and broadcasting the change when the update succeeds.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list to update.</param>
|
||||
/// <param name="name">The new description to apply to the master list.</param>
|
||||
/// <returns>A task that resolves to <c>true</c> if the update succeeded; otherwise, <c>false</c> when the update fails or an exception is caught and logged.</returns>
|
||||
public async Task<bool> UpdateMasterListDescription(ObjectId id, string name)
|
||||
{
|
||||
try
|
||||
@@ -326,6 +392,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified option from a master list identified by its id, auditing the change and broadcasting the update and deleted item to subscribers.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list from which the option will be removed.</param>
|
||||
/// <param name="oldOpt">The option to remove from the master list.</param>
|
||||
/// <returns>A task that resolves to <c>true</c> if the option was successfully removed; <c>false</c> if the operation failed or an error occurred.</returns>
|
||||
public async Task<bool> RemoveMasterListOption(ObjectId id, OptionList oldOpt)
|
||||
{
|
||||
try
|
||||
@@ -351,6 +423,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all master list entries of the generic type from the underlying repository.
|
||||
/// If an exception occurs during retrieval, the error is logged and an empty collection is returned as a fallback.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains all retrieved entries, or an empty collection if an error occurs.</returns>
|
||||
public async Task<IEnumerable<T>> GetAllMasterList()
|
||||
{
|
||||
try
|
||||
@@ -365,6 +442,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all master list entries without applying any optional filters or parameters.
|
||||
/// If an error occurs, the exception is logged and an empty collection is returned as a fallback.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a collection of <see cref="MasterListDto"/> items, or an empty collection if an error is encountered.</returns>
|
||||
public async Task<IEnumerable<MasterListDto>> GetAllMasterListWithoutOptions()
|
||||
{
|
||||
try
|
||||
@@ -379,6 +461,14 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an <see cref="OptionList"/> item that matches the specified master identifier, option identifier, and locale.
|
||||
/// Returns <c>null</c> and logs the error if the lookup fails.
|
||||
/// </summary>
|
||||
/// <param name="masterId">The identifier of the master item that owns the option.</param>
|
||||
/// <param name="optionId">The identifier of the specific option to locate.</param>
|
||||
/// <param name="locale">The locale used to resolve the localized option item.</param>
|
||||
/// <returns>A <see cref="Task{T}"/> containing the matching <see cref="OptionList"/>, or <c>null</c> if no item is found or an error occurs.</returns>
|
||||
public async Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId, LocaleEnum locale)
|
||||
{
|
||||
try
|
||||
@@ -393,8 +483,14 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all master list entries, maps each one to a paginated DTO enriched with its in-use status, and returns the resulting collection.
|
||||
/// Logs the error and returns an empty collection when the retrieval or mapping process fails.
|
||||
/// </summary>
|
||||
/// <param name="request">The pagination filter whose page size is applied when building each result entry.</param>
|
||||
/// <returns>A task that yields an enumerable of <see cref="MasterListWithPaginatedOptionsDto"/> containing the mapped master lists, or an empty enumerable if an error occurs.</returns>
|
||||
public async Task<IEnumerable<MasterListWithPaginatedOptionsDto>> GetAllMasterListWithPaginatedOptions(
|
||||
PaginationFilter request)
|
||||
PaginationFilter request)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -417,6 +513,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously retrieves the total count of all records in the master list for the current entity type.
|
||||
/// Returns 0 if an error occurs while accessing the repository.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the total count of records, or 0 if an error was encountered.</returns>
|
||||
public async Task<int> GetAllMasterListCount()
|
||||
{
|
||||
try
|
||||
@@ -431,6 +532,13 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a master list by its unique identifier, optionally filtered by locale.
|
||||
/// Logs and returns null if an error occurs during the lookup.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the master list to retrieve.</param>
|
||||
/// <param name="locale">The optional locale used to localize the retrieved master list.</param>
|
||||
/// <returns>The master list of type <typeparamref name="T"/> if found; otherwise, null.</returns>
|
||||
public async Task<T?> GetMasterListById(ObjectId id, LocaleEnum? locale)
|
||||
{
|
||||
try
|
||||
@@ -445,8 +553,15 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a master list by its identifier and returns it with paginated options, including whether the list is currently in use.
|
||||
/// Returns null when the master list is not found or when an error occurs during retrieval.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the master list to retrieve.</param>
|
||||
/// <param name="request">The pagination filter that determines the page size for the returned options.</param>
|
||||
/// <returns>A task that yields a <see cref="MasterListWithPaginatedOptionsDto"/> when the master list is found; otherwise, null.</returns>
|
||||
public async Task<MasterListWithPaginatedOptionsDto?> GetMasterListByIdWithPaginatedOptions(ObjectId id,
|
||||
PaginationFilter request)
|
||||
PaginationFilter request)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -467,6 +582,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the names of all options associated with a master list identified by the specified id using the default locale.
|
||||
/// Returns an empty list if the master list is not found or if an error occurs while retrieving the data.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list whose option names are to be retrieved.</param>
|
||||
/// <returns>A list of option names for the found master list, or an empty list if the list is not found or an error is encountered.</returns>
|
||||
public async Task<List<string>> GetMasterListOptionsNamesById(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -485,6 +606,13 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a master list of options filtered by the specified identifier and an optional text search term.
|
||||
/// Returns an empty list if an error occurs during retrieval.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier used to locate the master list in the repository.</param>
|
||||
/// <param name="textSearch">The optional text search term used to filter the results; may be null.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing the list of <see cref="OptionList"/> entries that match the specified identifier and text search criteria.</returns>
|
||||
public async Task<List<OptionList>> GetMasterListByIdAndTextSearch(ObjectId id, string? textSearch)
|
||||
{
|
||||
try
|
||||
@@ -499,13 +627,24 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a master list of <see cref="OptionList"/> items from the repository using the specified identifier and search filter options.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier used to locate the master list.</param>
|
||||
/// <param name="filterOption">The filter options applied to narrow the search within the master list.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="OptionList"/> items matching the given criteria.</returns>
|
||||
public async Task<List<OptionList>> GetMasterListByIdAndSearchOptions(ObjectId id,
|
||||
FilterOptionListElement filterOption)
|
||||
FilterOptionListElement filterOption)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
return await repository.GetMasterListByIdAndSearchOptions(id, filterOption);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a master list entry by its name. Returns the matching item, or null if no entry is found or if an error occurs while querying the repository.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the master list entry to look up.</param>
|
||||
/// <returns>A task that resolves to the matching item of type T, or null when no item is found or the lookup fails.</returns>
|
||||
public async Task<T?> GetMasterListByName(string name)
|
||||
{
|
||||
try
|
||||
@@ -521,6 +660,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a paginated master list based on the specified pagination filter, applying skip and limit operations according to the page number and page size.
|
||||
/// </summary>
|
||||
/// <param name="filter">The pagination filter containing the page number and page size used to determine the subset of records to return.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a <see cref="PaginationResponse{T}"/> with the paginated data, the current page number, the page size, and the total document count.</returns>
|
||||
public async Task<PaginationResponse<T>> GetPaginatedMasterList(PaginationFilter filter)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
@@ -540,8 +684,15 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a paginated collection of master list items, each enriched with a paginated set of associated options and a usage indicator.
|
||||
/// Applies the supplied <paramref name="listFilter"/> to paginate the master lists and the <paramref name="optionFilter"/> to size the embedded options within each list DTO.
|
||||
/// </summary>
|
||||
/// <param name="listFilter">Pagination parameters (page number and page size) used to slice the master list result set.</param>
|
||||
/// <param name="optionFilter">Pagination parameters whose page size is applied to the options associated with each returned master list item.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing a <see cref="PaginationResponse{T}"/> of <see cref="MasterListWithPaginatedOptionsDto"/> with the requested page of master lists, their paginated options, the current page metadata, and the total document count.</returns>
|
||||
public async Task<PaginationResponse<MasterListWithPaginatedOptionsDto>> GetPaginatedMasterListWithPaginatedOptions(
|
||||
PaginationFilter listFilter, PaginationFilter optionFilter)
|
||||
PaginationFilter listFilter, PaginationFilter optionFilter)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
|
||||
@@ -568,6 +719,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
listFilter.PageSize, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a paginated subset of options for the specified list, applying the page number and page size from the filter after fetching the full result set from the repository.
|
||||
/// </summary>
|
||||
/// <param name="filter">The pagination filter that defines the page number and page size to apply to the results.</param>
|
||||
/// <param name="listId">The identifier of the list whose options are being retrieved.</param>
|
||||
/// <returns>A <see cref="PaginationResponse{OptionList}"/> containing the requested page of options, the current page metadata, and the total count of available options.</returns>
|
||||
public async Task<PaginationResponse<OptionList>> GetPaginatedOptions(PaginationFilter filter, ObjectId listId)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
@@ -579,6 +736,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
return new PaginationResponse<OptionList>(data, filter.PageNumber, filter.PageSize, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new master list item, broadcasts the change to subscribers, and records an audit log entry for the operation.
|
||||
/// </summary>
|
||||
/// <param name="item">The master list entity to insert.</param>
|
||||
/// <returns>The inserted entity retrieved from the repository, or <c>null</c> if the operation fails.</returns>
|
||||
public async Task<T?> InsertMasterList(T item)
|
||||
{
|
||||
try
|
||||
@@ -597,6 +759,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing item in the master list, broadcasts the update operation, and creates an audit log entry comparing the old and new state.
|
||||
/// Returns <c>null</c> if the update fails, logging the error internally.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to update in the master list.</param>
|
||||
/// <returns>The updated item retrieved from the repository, or <c>null</c> if an error occurred during the update.</returns>
|
||||
public async Task<T?> UpdateMasterList(T item)
|
||||
{
|
||||
try
|
||||
@@ -617,8 +785,17 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the identifier of a master list associated with a given unit, based on the relationship between two master list types.
|
||||
/// Looks up the unit that contains the first master list reference (<paramref name="masterListType1"/>) and returns the identifier of the secondary associated list defined by <paramref name="masterListType2"/>.
|
||||
/// Returns <c>null</c> when no unit is found for the given list, or when <paramref name="masterListType2"/> does not map to a known associated list.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list used to locate the associated unit.</param>
|
||||
/// <param name="masterListType1">The master list type used to find the unit (e.g., the primary list reference on the unit).</param>
|
||||
/// <param name="masterListType2">The master list type that determines which associated list identifier is returned from the resolved unit.</param>
|
||||
/// <returns>A task that yields the associated <see cref="ObjectId"/> when a matching list exists, or <c>null</c> when no unit is found or the type is not mapped.</returns>
|
||||
public async Task<ObjectId?> GetAssociatedList(ObjectId id, MasterListType masterListType1,
|
||||
MasterListType masterListType2)
|
||||
MasterListType masterListType2)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
await repository.FindById(id, LocaleEnum.Default);
|
||||
@@ -657,6 +834,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the names of all options associated with the list identified by the specified identifier, using the default locale. Returns an empty list if no list is found for the given identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the list whose options should be retrieved.</param>
|
||||
/// <returns>A list of option names belonging to the matching list, or an empty list if the list is not found.</returns>
|
||||
public async Task<List<string>> GetOptionsOfList(ObjectId id)
|
||||
{
|
||||
var repository = GetRepository();
|
||||
@@ -667,11 +849,21 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves and returns the master list repository instance for the current entity type from the dependency injection service provider.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="IMasterListRepository{T}"/> instance retrieved from the configured <see cref="IServiceProvider"/>.</returns>
|
||||
private IMasterListRepository<T> GetRepository()
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<IMasterListRepository<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Propagates an update of a master list option to the patient, discharge, and admission services for all units that reference the given master list identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the master list whose dependent units and related records need to be updated.</param>
|
||||
/// <param name="opt">The update payload describing the master list change to apply to the related patient records.</param>
|
||||
/// <param name="typeName">The name of the master list type used to scope the update across the affected services.</param>
|
||||
private async Task UpdatePatientItemList(ObjectId id, UpdateOptionMasterListDto opt, string typeName)
|
||||
{
|
||||
// Necesito saber que unidades tienen el id de lista que estamos modificando
|
||||
@@ -683,6 +875,12 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
await _admissionService.Value.UpdatePatientMasterListItemChange(opt, units, typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a master list item across all patients, discharges, and admissions that belong to units referencing the specified master list identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The master list identifier used to locate the units that reference it.</param>
|
||||
/// <param name="opt">The option list containing the item to be removed from the affected records.</param>
|
||||
/// <param name="typeName">The type name of the master list item to delete.</param>
|
||||
private async Task DeletePatientItemList(ObjectId id, OptionList opt, string typeName)
|
||||
{
|
||||
// Necesito saber que unidades tienen el id de lista que estamos modificando
|
||||
@@ -694,16 +892,30 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
await _admissionService.Value.DeletePatientMasterListItem(opt, units, typeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously saves the specified API request by offloading the save operation to a background task.
|
||||
/// </summary>
|
||||
/// <param name="apiRequest">The API request to be saved.</param>
|
||||
public Task SaveRequestAsync(ApiRequest apiRequest)
|
||||
{
|
||||
return Task.FromResult(Task.Run(async () => { await SaveRequest(apiRequest); }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the specified API request.
|
||||
/// </summary>
|
||||
/// <param name="apiRequest">The API request to save.</param>
|
||||
public Task SaveRequest(ApiRequest apiRequest)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a master list change to all subscribers linked to the displays of the units associated with the given master list.
|
||||
/// Returns early if the master list type cannot be parsed as a <see cref="MasterListType"/> or if no related units are found, and logs any exception encountered while sending the notifications.
|
||||
/// </summary>
|
||||
/// <param name="masterList">The master list entity triggering the broadcast; its runtime type name is used to determine the master list category.</param>
|
||||
/// <param name="operation">The operation performed on the master list, which is sent to each subscriber along with the localized master list options.</param>
|
||||
private async Task SendMasterListBroadcast(T masterList, OperationType operation)
|
||||
{
|
||||
try
|
||||
@@ -739,8 +951,15 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a broadcast notification to all subscribers linked to a master list when an option list item is added, updated, or deleted. The message payload is tailored per operation: add includes the new item, delete includes the deleted item, and update includes both. Returns early if the master list type cannot be parsed from the type name or if no related units are found.
|
||||
/// </summary>
|
||||
/// <param name="masterList">The master list entity whose type and identifier are used to locate related units and subscribers.</param>
|
||||
/// <param name="updatedItem">The new or modified option list item, included in add and update operations.</param>
|
||||
/// <param name="oldItem">The previous option list item, included in delete and update operations.</param>
|
||||
/// <param name="operation">The operation type that determines the structure of the broadcast message sent to subscribers.</param>
|
||||
private async Task SendMasterListItemBroadcast(T masterList, OptionList? updatedItem, OptionList? oldItem,
|
||||
OperationType operation)
|
||||
OperationType operation)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -803,6 +1022,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the units that are associated with the specified master list and maps them to a collection of <see cref="UnitInfoDto"/> objects, returning an empty list when no units are found.
|
||||
/// </summary>
|
||||
/// <param name="list">The master list whose associated units should be retrieved. Its identifier and list type are used to look up the related units.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="UnitInfoDto"/> instances for the units linked to the specified list, or an empty list if none exist.</returns>
|
||||
private async Task<List<UnitInfoDto>> IsInUse(T list)
|
||||
{
|
||||
var units = await _unitService.Value.FindUnitsByMasterListId(list.Id, list.ListType);
|
||||
@@ -818,6 +1042,11 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
|
||||
return unitInfoDtos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously retrieves the count of units associated with the specified master list, indicating how many records are currently in use.
|
||||
/// </summary>
|
||||
/// <param name="list">The master list entity whose associated unit count is being queried.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the number of units referencing the master list.</returns>
|
||||
private async Task<long> IsInUseCount(T list)
|
||||
{
|
||||
return await _unitService.Value.CountUnitsByMasterListId(list.Id, list.ListType);
|
||||
|
||||
Reference in New Issue
Block a user