=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===

This commit is contained in:
julian
2026-06-28 02:50:05 -07:00
parent a19fb90902
commit 586f02a2ca
654 changed files with 5260 additions and 0 deletions
@@ -23,6 +23,7 @@ namespace adas_core.Application.Services;
/// 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>
/// <!-- aidoc:v1 sig=6dd13a3 -->
public class MasterListService<T> : IMasterListService<T> where T : MasterList, new()
{
private readonly Lazy<IAdmissionService> _admissionService;
@@ -88,6 +89,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=bbde86c body=1e4169e -->
public async Task DeleteMasterListById(ObjectId id)
{
var repository = GetRepository();
@@ -133,6 +135,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=1602f0d body=c7da593 -->
public async Task<OptionList?> AddOptionToMasterList(ObjectId id, FilterOptionListElement opt)
{
try
@@ -172,6 +175,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=da045e6 body=6f739c4 -->
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList opt, string typeName,
LocaleEnum locale)
{
@@ -210,6 +214,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=f0915ad body=ec1df57 -->
public async Task<OptionList?> UpdateMasterListOption(ObjectId id, OptionList opt, string typeName)
{
try
@@ -249,6 +254,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=4a7ad76 body=2986e84 -->
public async Task<OptionList?> UpdateFullMasterListOption(ObjectId id, OptionList opt, string typeName)
{
try
@@ -286,6 +292,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=e654e5f body=b693722 -->
public async Task<bool> DeleteMasterListOption(ObjectId id, ObjectId optId, string typeName)
{
try
@@ -322,6 +329,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=53d4179 body=f5f38c9 -->
public async Task<UpdateMasterListDetailsDto?> UpdateOptionDetailsToMasterList(ObjectId id,
UpdateMasterListDetailsDto opt)
{
@@ -354,6 +362,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=5b79a51 body=2b55065 -->
public async Task<bool> UpdateMasterListName(ObjectId id, string name)
{
try
@@ -384,6 +393,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=f402203 body=2065699 -->
public async Task<bool> UpdateMasterListDescription(ObjectId id, string name)
{
try
@@ -414,6 +424,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=8de50cd body=2393e14 -->
public async Task<bool> RemoveMasterListOption(ObjectId id, OptionList oldOpt)
{
try
@@ -444,6 +455,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// 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>
/// <!-- aidoc:v1 sig=438d930 body=23055ad -->
public async Task<IEnumerable<T>> GetAllMasterList()
{
try
@@ -463,6 +475,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// 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>
/// <!-- aidoc:v1 sig=ff97d15 body=6dc7eab -->
public async Task<IEnumerable<MasterListDto>> GetAllMasterListWithoutOptions()
{
try
@@ -485,6 +498,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=fdb2628 body=57f7d69 -->
public async Task<OptionList?> FindOptionItemById(ObjectId masterId, ObjectId optionId, LocaleEnum locale)
{
try
@@ -505,6 +519,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=e2b42f3 body=87dac37 -->
public async Task<IEnumerable<MasterListWithPaginatedOptionsDto>> GetAllMasterListWithPaginatedOptions(
PaginationFilter request)
{
@@ -534,6 +549,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// 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>
/// <!-- aidoc:v1 sig=c52b4f8 body=ba61e78 -->
public async Task<int> GetAllMasterListCount()
{
try
@@ -555,6 +571,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=3e8f3d7 body=947fcc9 -->
public async Task<T?> GetMasterListById(ObjectId id, LocaleEnum? locale)
{
try
@@ -576,6 +593,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=d2dd8ff body=6215360 -->
public async Task<MasterListWithPaginatedOptionsDto?> GetMasterListByIdWithPaginatedOptions(ObjectId id,
PaginationFilter request)
{
@@ -604,6 +622,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=6fb6e81 body=27002bc -->
public async Task<List<string>> GetMasterListOptionsNamesById(ObjectId id)
{
try
@@ -629,6 +648,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=a3a824e body=218b0ef -->
public async Task<List<OptionList>> GetMasterListByIdAndTextSearch(ObjectId id, string? textSearch)
{
try
@@ -649,6 +669,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=2a76fbd body=1d979f3 -->
public async Task<List<OptionList>> GetMasterListByIdAndSearchOptions(ObjectId id,
FilterOptionListElement filterOption)
{
@@ -661,6 +682,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=4e2a946 body=4d99da2 -->
public async Task<T?> GetMasterListByName(string name)
{
try
@@ -681,6 +703,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=c6c73b2 body=8453888 -->
public async Task<PaginationResponse<T>> GetPaginatedMasterList(PaginationFilter filter)
{
var repository = GetRepository();
@@ -707,6 +730,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=97d48e5 body=dadadb5 -->
public async Task<PaginationResponse<MasterListWithPaginatedOptionsDto>> GetPaginatedMasterListWithPaginatedOptions(
PaginationFilter listFilter, PaginationFilter optionFilter)
{
@@ -741,6 +765,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=5a05956 body=0aee55a -->
public async Task<PaginationResponse<OptionList>> GetPaginatedOptions(PaginationFilter filter, ObjectId listId)
{
var repository = GetRepository();
@@ -757,6 +782,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=70bbd79 body=44b9a00 -->
public async Task<T?> InsertMasterList(T item)
{
try
@@ -781,6 +807,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=525dfd0 body=7010df2 -->
public async Task<T?> UpdateMasterList(T item)
{
try
@@ -810,6 +837,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=e127506 body=2c24e0e -->
public async Task<ObjectId?> GetAssociatedList(ObjectId id, MasterListType masterListType1,
MasterListType masterListType2)
{
@@ -855,6 +883,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=ec8c6e3 body=716cd88 -->
public async Task<List<string>> GetOptionsOfList(ObjectId id)
{
var repository = GetRepository();
@@ -869,6 +898,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// 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>
/// <!-- aidoc:v1 sig=d65745e body=789f6e7 -->
private IMasterListRepository<T> GetRepository()
{
return _serviceProvider.GetRequiredService<IMasterListRepository<T>>();
@@ -880,6 +910,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=624e0d5 body=c47ad11 -->
private async Task UpdatePatientItemList(ObjectId id, UpdateOptionMasterListDto opt, string typeName)
{
// Necesito saber que unidades tienen el id de lista que estamos modificando
@@ -897,6 +928,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=4492294 body=9b327f2 -->
private async Task DeletePatientItemList(ObjectId id, OptionList opt, string typeName)
{
// Necesito saber que unidades tienen el id de lista que estamos modificando
@@ -912,6 +944,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// 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>
/// <!-- aidoc:v1 sig=a3706aa body=c8d77ba -->
public Task SaveRequestAsync(ApiRequest apiRequest)
{
return Task.FromResult(Task.Run(async () => { await SaveRequest(apiRequest); }));
@@ -921,6 +954,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// Saves the specified API request.
/// </summary>
/// <param name="apiRequest">The API request to save.</param>
/// <!-- aidoc:v1 sig=3385bba body=6805ef5 -->
public Task SaveRequest(ApiRequest apiRequest)
{
return Task.CompletedTask;
@@ -932,6 +966,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=73619af body=f177e6e -->
private async Task SendMasterListBroadcast(T masterList, OperationType operation)
{
try
@@ -974,6 +1009,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// <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>
/// <!-- aidoc:v1 sig=e48c5b0 body=c41b16d -->
private async Task SendMasterListItemBroadcast(T masterList, OptionList? updatedItem, OptionList? oldItem,
OperationType operation)
{
@@ -1043,6 +1079,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=e1e565a body=764dda0 -->
private async Task<List<UnitInfoDto>> IsInUse(T list)
{
var units = await _unitService.Value.FindUnitsByMasterListId(list.Id, list.ListType);
@@ -1063,6 +1100,7 @@ public class MasterListService<T> : IMasterListService<T> where T : MasterList,
/// </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>
/// <!-- aidoc:v1 sig=83c6ba6 body=a349dfa -->
private async Task<long> IsInUseCount(T list)
{
return await _unitService.Value.CountUnitsByMasterListId(list.Id, list.ListType);