rama creada apartir de master en j
This commit is contained in:
@@ -36,12 +36,20 @@ public class DisplayService(
|
||||
IOptions<CacheSettings> cacheSettings)
|
||||
: IDisplayService
|
||||
{
|
||||
private readonly CacheSettings? _cacheSettings = cacheSettings.Value ;
|
||||
|
||||
private readonly CacheSettings? _cacheSettings = cacheSettings.Value;
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Create
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new <see cref="Display"/> using the default configuration for its type.
|
||||
/// If no default configuration exists for the display type, a <see cref="NotFoundException"/> is thrown.
|
||||
/// An audit log entry is created after the display is persisted.
|
||||
/// </summary>
|
||||
/// <param name="display">The display to insert. Its <c>DisplayConfigId</c> is assigned from the resolved default configuration.</param>
|
||||
/// <returns>The inserted <see cref="Display"/> with its <c>DisplayConfigId</c> populated.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when no default configuration is found for the specified display type.</exception>
|
||||
public async Task<Display> InsertOne(Display display)
|
||||
{
|
||||
var defaultConfig = await displayConfigService.GetDefaultConfig(display.Type) ??
|
||||
@@ -52,6 +60,10 @@ public class DisplayService(
|
||||
return display;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a test Display record into the repository and records a corresponding audit log entry using the current HTTP context user.
|
||||
/// </summary>
|
||||
/// <returns>The newly created <see cref="Display"/> entity.</returns>
|
||||
public async Task<Display> InsertOneTest()
|
||||
{
|
||||
var d = new Display
|
||||
@@ -69,6 +81,10 @@ public class DisplayService(
|
||||
|
||||
#region Read
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all displays from the repository and maps them to a compact representation.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="DisplayMinimalDto"/> with the mapped display data.</returns>
|
||||
public async Task<List<DisplayMinimalDto>> GetAllCompact()
|
||||
{
|
||||
var result = await displayRepository.GetAll();
|
||||
@@ -77,11 +93,22 @@ public class DisplayService(
|
||||
return listToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all display items, optionally filtered by the specified user name.
|
||||
/// </summary>
|
||||
/// <param name="userName">The user name used to filter the display items, or <see langword="null"/> to retrieve all items.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="Display"/> items.</returns>
|
||||
/// <exception cref="NotImplementedException">The method has not been implemented yet.</exception>
|
||||
public Task<List<Display>> GetAll(string? userName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a paginated list of <see cref="Display"/> items along with the total document count, applying page number and page size from the provided filter.
|
||||
/// </summary>
|
||||
/// <param name="filter">The pagination filter containing the page number and page size used to determine the slice of results to return.</param>
|
||||
/// <returns>A <see cref="Task{PaginationResponse{Display}}"/> containing the requested page of displays, the current page number, the page size, and the total number of documents.</returns>
|
||||
public async Task<PaginationResponse<Display>> GetPaginatedDisplays(PaginationFilter filter)
|
||||
{
|
||||
var result = displayRepository.GetPaginatedDisplays(filter);
|
||||
@@ -97,6 +124,13 @@ public class DisplayService(
|
||||
return new PaginationResponse<Display>(dataList, filter.PageNumber, filter.PageSize, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all displays accessible to the specified user, together with their associated permissions, by resolving the user's authorizations (both unit-scoped and display-scoped).
|
||||
/// Returns an empty list when the username is null, when the user cannot be found, or when no authorizations are available; throws an exception if permissions for a unit-scoped display cannot be resolved.
|
||||
/// </summary>
|
||||
/// <param name="userName">The username whose displays should be retrieved; when null, the method returns an empty list.</param>
|
||||
/// <returns>A task that yields a list of <see cref="DisplayWithPermissionsDto"/> containing the displays the user can access along with their permissions.</returns>
|
||||
/// <exception cref="ForbbidenException">Thrown when permissions for a unit-scoped display cannot be obtained for the user.</exception>
|
||||
public async Task<List<DisplayWithPermissionsDto>> GetAllByUser(string? userName)
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
@@ -119,7 +153,7 @@ public class DisplayService(
|
||||
var dis = await displayRepository.GetByUnitId(dId);
|
||||
foreach (var display in dis)
|
||||
{
|
||||
var toAdd = await GetInfo(display.Id, userName, user.Authorization,null, false, false, false, false);
|
||||
var toAdd = await GetInfo(display.Id, userName, user.Authorization, null, false, false, false, false);
|
||||
|
||||
if (toAdd != null)
|
||||
{
|
||||
@@ -160,11 +194,24 @@ public class DisplayService(
|
||||
return listToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a display with the specified identifier exists in the provided collection of display permissions.
|
||||
/// The check safely skips entries whose <c>Display</c> reference is null before comparing the display identifier.
|
||||
/// </summary>
|
||||
/// <param name="displayId">The identifier of the display to look up, compared as a string.</param>
|
||||
/// <param name="perms">The collection of display-with-permissions entries to search through.</param>
|
||||
/// <returns><c>true</c> if a non-null display with a matching identifier is found; otherwise, <c>false</c>.</returns>
|
||||
private static bool FindDisplayInPerms(string displayId, List<DisplayWithPermissionsDto> perms)
|
||||
{
|
||||
return perms.Any(p => p.Display != null && p.Display.Id.ToString() == displayId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all displays associated with the specified display type by resolving the matching display configurations and loading their corresponding displays.
|
||||
/// Each returned display is enriched with its parent configuration, and configurations without associated displays are skipped.
|
||||
/// </summary>
|
||||
/// <param name="type">The display type used to filter the display configurations.</param>
|
||||
/// <returns>A list of displays matching the specified type, each with its related configuration assigned; an empty list is returned when no displays are found.</returns>
|
||||
public async Task<List<Display>> GetByType(DisplayConfigEnums.DisplayType type)
|
||||
{
|
||||
var configs = await displayConfigService.GetByType(type);
|
||||
@@ -179,32 +226,65 @@ public class DisplayService(
|
||||
return listToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a list of displays associated with the specified point of care.
|
||||
/// </summary>
|
||||
/// <param name="pointOfCare">The point of care used to filter the displays.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the list of displays matching the specified point of care.</returns>
|
||||
public async Task<List<Display>> GetByPointOfCare(PointOfCare pointOfCare)
|
||||
{
|
||||
return await displayRepository.GetByPointOfCare(pointOfCare);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the list of displays associated with the specified configuration identifier by delegating to the display repository.
|
||||
/// </summary>
|
||||
/// <param name="configId">The configuration identifier used to look up the associated displays.</param>
|
||||
/// <returns>A task that returns the list of <see cref="Display"/> objects matching the given configuration identifier.</returns>
|
||||
public Task<List<Display>> GetByConfigId(ObjectId configId)
|
||||
{
|
||||
return displayRepository.GetByConfigId(configId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a list of displays associated with the specified card configuration identifier by delegating to the underlying repository.
|
||||
/// </summary>
|
||||
/// <param name="configId">The unique identifier of the card configuration used to look up the associated displays.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="Display"/> objects matching the provided card configuration identifier.</returns>
|
||||
public Task<List<Display>> GetByCardConfigId(ObjectId configId)
|
||||
{
|
||||
return displayRepository.GetByCardConfigId(configId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="Display"/> by its name. Throws a <see cref="NotFoundException"/> if no matching display is found.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the display to look up.</param>
|
||||
/// <returns>The <see cref="Display"/> that matches the specified name.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when no display is found for the given name.</exception>
|
||||
public async Task<Display?> GetByName(string name)
|
||||
{
|
||||
return await displayRepository.GetByName(name) ??
|
||||
throw new NotFoundException(HttpEnum.ErrorMessage.NotFoundResourceMissing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="Display"/> by its unique identifier from the repository.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the display to retrieve.</param>
|
||||
/// <returns>The matching <see cref="Display"/> if found; otherwise, <c>null</c>.</returns>
|
||||
public async Task<Display?> GetById(ObjectId id)
|
||||
{
|
||||
return await displayRepository.GetById(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a display by its identifier, enriches it with localized point-of-care information, its display configuration, and the permissions available to the current user.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the display to retrieve.</param>
|
||||
/// <param name="localeEnum">The locale used to localize the related point-of-care information.</param>
|
||||
/// <returns>A <see cref="DisplayWithPermissionsDto"/> containing the display and its associated permissions.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when the current user cannot be identified from the JWT or when no display is found for the specified <paramref name="id"/>.</exception>
|
||||
public async Task<DisplayWithPermissionsDto> GetByIdWithPermissions(ObjectId id, LocaleEnum localeEnum)
|
||||
{
|
||||
var username = JwtHelper.GetUsernameFromPrincipal(httpContextAccessor.HttpContext?.User!) ??
|
||||
@@ -241,18 +321,38 @@ public class DisplayService(
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously counts the number of displays associated with the specified unit identifier.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The unique identifier of the unit whose displays should be counted.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the total number of displays for the given unit.</returns>
|
||||
public async Task<long> CountDisplaysByUnitId(ObjectId unitId)
|
||||
{
|
||||
return await displayRepository.CountByUnitId(unitId);
|
||||
}
|
||||
|
||||
public async Task<Display?> GetInfo(ObjectId id,
|
||||
string? userName,
|
||||
/// <summary>
|
||||
/// Retrieves display information by id, with optional enrichment of point-of-care, patient data, and section list based on the provided flags.
|
||||
/// Uses cached data when display configuration is requested; otherwise fetches the base display and caches the result.
|
||||
/// Fetches user authorizations from the user repository when not supplied, and logs an error if the display list cannot be populated due to a missing configuration.
|
||||
/// </summary>
|
||||
/// <param name="id">Identifier of the display to retrieve.</param>
|
||||
/// <param name="userName">Optional user name used to look up authorizations when none are provided.</param>
|
||||
/// <param name="authorizations">Optional pre-resolved authorizations used to filter the display section list.</param>
|
||||
/// <param name="locale">Optional locale applied when loading point-of-care data.</param>
|
||||
/// <param name="fillPointOfCare">If true, populates the point-of-care entries for the display.</param>
|
||||
/// <param name="fillPatientData">If true, includes patient data when retrieving point-of-care information.</param>
|
||||
/// <param name="fillDisplayList">If true, populates the display section list filtered by the resolved authorizations.</param>
|
||||
/// <param name="fillDisplayConfig">If true, retrieves the full display including its configuration (cached); otherwise retrieves the base display.</param>
|
||||
/// <param name="ct">Cancellation token to cancel the operation.</param>
|
||||
/// <returns>The requested <see cref="Display"/>, or <c>null</c> if no display is found for the given id.</returns>
|
||||
public async Task<Display?> GetInfo(ObjectId id,
|
||||
string? userName,
|
||||
List<Authorization>? authorizations,
|
||||
LocaleEnum? locale,
|
||||
LocaleEnum? locale,
|
||||
bool fillPointOfCare = true,
|
||||
bool fillPatientData = false,
|
||||
bool fillDisplayList = true,
|
||||
bool fillPatientData = false,
|
||||
bool fillDisplayList = true,
|
||||
bool fillDisplayConfig = true,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
@@ -261,7 +361,7 @@ public class DisplayService(
|
||||
Display? display;
|
||||
if (fillDisplayConfig)
|
||||
{
|
||||
|
||||
|
||||
// Clave: display con configuración
|
||||
var (key, ttl) = CacheKeys.DisplayWithConfigKeyWithTtl(_cacheSettings, id);
|
||||
|
||||
@@ -270,7 +370,7 @@ public class DisplayService(
|
||||
async () => await BuildDisplayWithConfig(id, ct),
|
||||
ttl,
|
||||
ct);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -285,7 +385,7 @@ public class DisplayService(
|
||||
|
||||
}
|
||||
if (display == null) return null;
|
||||
|
||||
|
||||
// PointOfCare (cacheado en su propio servicio)
|
||||
if (fillPointOfCare)
|
||||
foreach (var poc in display.PointOfCareIdList)
|
||||
@@ -315,7 +415,13 @@ public class DisplayService(
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Builds a <see cref="Display"/> enriched with its display configuration. Returns <c>null</c> when the display is not found, and for <see cref="SmartDisplay"/> instances that have a <c>CardRotatingLayout</c>, resolves and assigns each card's configuration, falling back to an empty <see cref="CardConfig"/> when a card configuration cannot be retrieved.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the display to load.</param>
|
||||
/// <param name="ct">The cancellation token used to cancel the asynchronous operation.</param>
|
||||
/// <returns>The <see cref="Display"/> with its configuration populated, or <c>null</c> if no display exists for the given <paramref name="id"/>.</returns>
|
||||
private async Task<Display?> BuildDisplayWithConfig(ObjectId id, CancellationToken ct)
|
||||
{
|
||||
var display = await displayRepository.GetById(id);
|
||||
@@ -328,10 +434,10 @@ public class DisplayService(
|
||||
await displayConfigService.GetById(display.DisplayConfigId, display.UnitId, type);
|
||||
|
||||
if (type != DisplayConfigEnums.DisplayType.SmartDisplay ||
|
||||
display.DisplayConfig is not SmartDisplay { CardRotatingLayout: not null } smart)
|
||||
display.DisplayConfig is not SmartDisplay { CardRotatingLayout: not null } smart)
|
||||
return display;
|
||||
|
||||
if(smart.CardRotatingLayout== null)
|
||||
|
||||
if (smart.CardRotatingLayout == null)
|
||||
return display;
|
||||
|
||||
foreach (var card in smart.CardRotatingLayout)
|
||||
@@ -339,15 +445,24 @@ public class DisplayService(
|
||||
?? new CardConfig();
|
||||
|
||||
return display;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the display sections accessible to a specific user, filtered by display type, based on the user's authorities (either provided or fetched from the authority service).
|
||||
/// Supports both direct display references and unit-based references, marks the currently selected display, and returns an empty list if the user is not found or no matching sections exist.
|
||||
/// </summary>
|
||||
/// <param name="type">The display type used to filter the returned sections.</param>
|
||||
/// <param name="currentDisplay">The identifier of the currently selected display, which will be flagged as selected in the result; may be null.</param>
|
||||
/// <param name="userName">The username used to look up the user and their authorities; if null, an empty list is returned.</param>
|
||||
/// <param name="authorizations">Optional pre-fetched list of user authorities; when null, authorities are retrieved from the authority service.</param>
|
||||
/// <returns>A task that resolves to a list of <see cref="MinimalDisplaySection"/> items accessible to the user and matching the specified display type.</returns>
|
||||
public async Task<List<MinimalDisplaySection>> GetDisplaySectionByUser(
|
||||
DisplayConfigEnums.DisplayType type,
|
||||
ObjectId? currentDisplay,
|
||||
string? userName,
|
||||
List<Authorization>? authorizations)
|
||||
DisplayConfigEnums.DisplayType type,
|
||||
ObjectId? currentDisplay,
|
||||
string? userName,
|
||||
List<Authorization>? authorizations)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -413,6 +528,10 @@ public class DisplayService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously retrieves all display configurations of type DisplayNurse and SmartDisplay, mapping them into minimal display sections and grouping them within a display list DTO.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a MinimalDisplayListDto with the populated DisplayNurse and SmartDisplay collections.</returns>
|
||||
public async Task<MinimalDisplayListDto> GetAllDisplaySection()
|
||||
{
|
||||
var minimalDisplayListDto = new MinimalDisplayListDto();
|
||||
@@ -441,11 +560,23 @@ public class DisplayService(
|
||||
return minimalDisplayListDto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the list of displays associated with the specified unit identifier by delegating to the display repository.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The identifier of the unit whose displays should be returned.</param>
|
||||
/// <returns>A task that represents the asynchronous operation, containing the list of <see cref="Display"/> objects for the given unit.</returns>
|
||||
public async Task<List<Display>> GetByUnitId(ObjectId unitId)
|
||||
{
|
||||
return await displayRepository.GetByUnitId(unitId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all available points of care (POC) and their associated unit information for the specified display identifiers. Invalid display ID strings are silently skipped, virtual points of care can optionally be excluded, and a <see cref="NotFoundException"/> is thrown when a resolved unit cannot be found; any unexpected error is logged and an empty result is returned.
|
||||
/// </summary>
|
||||
/// <param name="displayIds">A list of display identifier strings used to resolve the related units and their available points of care.</param>
|
||||
/// <param name="excludeVirtual">When set to <c>true</c>, virtual points of care are excluded from the result; otherwise, they are included.</param>
|
||||
/// <returns>A <see cref="PocAndUnitDto"/> containing the available points of care and their associated unit details.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when a unit associated with one of the resolved display identifiers cannot be found.</exception>
|
||||
public async Task<PocAndUnitDto> GetAllAvailablePoc(List<string> displayIds, bool excludeVirtual = false)
|
||||
{
|
||||
try
|
||||
@@ -492,6 +623,11 @@ public class DisplayService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all points of care associated with the specified display. Returns an empty list when the display is not found, when no associated points of care exist, or when an error occurs during retrieval.
|
||||
/// </summary>
|
||||
/// <param name="id">The ObjectId of the display whose points of care should be retrieved.</param>
|
||||
/// <returns>A list of points of care linked to the display, or an empty list if the display cannot be found or if an error is encountered.</returns>
|
||||
public async Task<List<PointOfCare>> GetAllPocsByDisplayId(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -516,6 +652,11 @@ public class DisplayService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the display configuration locations associated with the specified display configuration ID, mapping each display to its corresponding unit name. If a unit cannot be found for a display, the resulting location's unit name will be null.
|
||||
/// </summary>
|
||||
/// <param name="displayConfigId">The identifier of the display configuration whose locations are being retrieved.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="DisplayConfigLocationDto"/> objects with display and unit information.</returns>
|
||||
public async Task<List<DisplayConfigLocationDto>> GetDisplayConfigLocations(ObjectId displayConfigId)
|
||||
{
|
||||
var displays = await GetByConfigId(displayConfigId);
|
||||
@@ -534,6 +675,11 @@ public class DisplayService(
|
||||
return locations;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified display configuration is currently in use by checking if it is referenced by any related entity.
|
||||
/// </summary>
|
||||
/// <param name="displayConfigId">The unique identifier of the display configuration to check.</param>
|
||||
/// <returns><c>true</c> if the display configuration is referenced by at least one entity; otherwise, <c>false</c>.</returns>
|
||||
public async Task<bool> IsDisplayConfigInUse(ObjectId displayConfigId)
|
||||
{
|
||||
return await displayRepository.IsDisplayConfigInUse(displayConfigId) > 0;
|
||||
@@ -547,21 +693,35 @@ public class DisplayService(
|
||||
* En esta actualización se espera una resubscipción al id del display ya que actualizar los PoC conlleva actualizar
|
||||
* subscrioptor y locations para las observaciones
|
||||
*/
|
||||
/// <summary>
|
||||
/// Updates the point of care list associated with the specified display, invalidating the related cache entries and broadcasting the change to subscribers.
|
||||
/// </summary>
|
||||
/// <param name="objectId">The identifier of the display whose point of care list is being updated.</param>
|
||||
/// <param name="listPocObId">The list of point of care object identifiers to assign to the display.</param>
|
||||
/// <returns>The updated <see cref="Display"/> instance after the point of care list change.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when no display exists for the specified <paramref name="objectId"/>.</exception>
|
||||
/// <exception cref="ConflictException">Thrown when the point of care list update cannot be persisted.</exception>
|
||||
public async Task<Display?> UpdatePointOfCareList(ObjectId objectId, List<ObjectId> listPocObId)
|
||||
{
|
||||
var oldDisplay = await displayRepository.GetById(objectId) ??
|
||||
throw new NotFoundException(HttpEnum.ErrorMessage.NotFoundResourceMissing);
|
||||
var displayToReturn = await displayRepository.UpdatePointOfCareList(objectId, listPocObId) ??
|
||||
throw new ConflictException(HttpEnum.ErrorMessage.ConflictUpdateFailed);
|
||||
|
||||
|
||||
await cacheService.DeleteByPatternAsync(CacheKeys.DisplayBase(objectId));
|
||||
|
||||
|
||||
SendDisplayBroadcast(displayToReturn, OperationType.UpdateDisplayPoC);
|
||||
|
||||
|
||||
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, oldDisplay, displayToReturn);
|
||||
return displayToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the configuration of an existing display by casting the new configuration to its specific type based on <see cref="DisplayConfigEnums.DisplayType"/>, supporting <c>DisplayNurse</c> and <c>SmartDisplay</c>. On a successful update, broadcasts the change, creates an audit log entry, and invalidates the related cache entry. Returns <c>null</c> if the provided configuration type is not supported or the cast results in <c>null</c>.
|
||||
/// </summary>
|
||||
/// <param name="oldDisplay">The existing display whose configuration will be updated.</param>
|
||||
/// <param name="newDisplayConfig">The new configuration to apply, or <c>null</c> if no update is provided.</param>
|
||||
/// <returns>The updated <see cref="Display"/> if the configuration was successfully applied; otherwise, <c>null</c>.</returns>
|
||||
public async Task<Display?> UpdateConfig(Display oldDisplay, DisplayConfig? newDisplayConfig)
|
||||
{
|
||||
var newDisplayConfigCast = new DisplayConfig();
|
||||
@@ -584,15 +744,21 @@ public class DisplayService(
|
||||
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, oldDisplay,
|
||||
displayToReturn);
|
||||
}
|
||||
|
||||
|
||||
await cacheService.DeleteByPatternAsync(CacheKeys.DisplayBase(oldDisplay.Id));
|
||||
|
||||
|
||||
return displayToReturn;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the configuration ID associated with the specified display. On a successful update, the related cache entries are invalidated, a display update broadcast is sent, and an audit log entry is created.
|
||||
/// </summary>
|
||||
/// <param name="oldDisplay">The display whose configuration ID is being updated.</param>
|
||||
/// <param name="configId">The new configuration ID to assign to the display.</param>
|
||||
/// <returns>The updated display, or <c>null</c> if the display was not found.</returns>
|
||||
public async Task<Display?> UpdateConfigId(Display oldDisplay, ObjectId configId)
|
||||
{
|
||||
var displayToReturn = await displayRepository.UpdateConfigId(oldDisplay.Id, configId);
|
||||
@@ -606,13 +772,21 @@ public class DisplayService(
|
||||
return displayToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the configuration preset associated with the specified display, invalidates the display cache, records an audit log entry, and broadcasts a notification to subscribers based on the resolved display type (DisplayNurse, SmartDisplay, or Unknown). Throws a not-found exception when the update result or configuration cannot be resolved, and an invalid-format exception when the configuration type is not one of the handled types.
|
||||
/// </summary>
|
||||
/// <param name="objectIdDisplay">The identifier of the display whose configuration preset is being updated.</param>
|
||||
/// <param name="objectIdConfigDisplay">The identifier of the new configuration preset to apply to the display.</param>
|
||||
/// <returns>The updated <see cref="Display"/> entity, or <c>null</c> if the update could not be completed.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when the update result or the resolved configuration is <c>null</c>.</exception>
|
||||
/// <exception cref="InvalidFormatException">Thrown when the configuration type is not one of the handled display types.</exception>
|
||||
public async Task<Display?> UpdateConfigPreset(ObjectId objectIdDisplay, ObjectId objectIdConfigDisplay)
|
||||
{
|
||||
var oldConfig = await displayConfigService.GetById(objectIdConfigDisplay);
|
||||
var result = await displayRepository.UpdateConfigPreset(objectIdDisplay, objectIdConfigDisplay);
|
||||
|
||||
|
||||
await cacheService.DeleteByPatternAsync(CacheKeys.DisplayBase(objectIdDisplay));
|
||||
|
||||
|
||||
var config = await displayConfigService.GetById(objectIdConfigDisplay);
|
||||
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, oldConfig, config);
|
||||
if (result == null || config == null)
|
||||
@@ -636,14 +810,21 @@ public class DisplayService(
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the name of an existing display identified by the given identifier, invalidates the related cache entries, and records an audit log entry for the change.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the display to update.</param>
|
||||
/// <param name="name">The new name to assign to the display.</param>
|
||||
/// <returns>The updated <see cref="Display"/> instance, or <c>null</c> if the update could not be performed.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when no display is found for the specified <paramref name="id"/>.</exception>
|
||||
public async Task<Display?> UpdateName(ObjectId id, string name)
|
||||
{
|
||||
var display = await displayRepository.GetById(id) ??
|
||||
throw new NotFoundException(HttpEnum.ErrorMessage.NotFoundResourceMissing);
|
||||
var newDisplay = await displayRepository.UpdateName(display, name);
|
||||
|
||||
|
||||
await cacheService.DeleteByPatternAsync(CacheKeys.DisplayBase(id));
|
||||
|
||||
|
||||
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, display, newDisplay);
|
||||
return newDisplay;
|
||||
}
|
||||
@@ -652,27 +833,37 @@ public class DisplayService(
|
||||
|
||||
#region Delete
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a display by its identifier, removing the record, invalidating the related cache, clearing associated authorities, and recording an audit log entry.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the display to delete.</param>
|
||||
/// <returns>A task that resolves to <c>true</c> when the display has been successfully deleted.</returns>
|
||||
/// <exception cref="NotFoundException">Thrown when no display is found for the specified <paramref name="id"/>.</exception>
|
||||
public async Task<bool> DeleteDisplay(ObjectId id)
|
||||
{
|
||||
var display = await displayRepository.GetById(id) ??
|
||||
throw new NotFoundException(HttpEnum.ErrorMessage.NotFoundResourceMissing);
|
||||
await displayRepository.DeleteAsync(id);
|
||||
|
||||
|
||||
// Invalidar CACHE (colección completa)
|
||||
await cacheService.DeleteByPatternAsync(CacheKeys.DisplayBase(id));
|
||||
|
||||
await authorityService.DeleteByDisplayId(id);
|
||||
|
||||
|
||||
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, display, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all displays associated with the specified unit identifier, invalidates the displays cache, and removes related authority data for the unit.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The unique identifier of the unit whose displays and related authority data will be removed.</param>
|
||||
public async Task DeleteDisplaysByUnitId(ObjectId unitId)
|
||||
{
|
||||
await displayRepository.DeleteManyByUnitId(unitId);
|
||||
// Invalidar CACHE (colección completa)
|
||||
await cacheService.DeleteByPatternAsync(CacheKeyPatterns.ForEntity(CacheEnum.EntityType.Displays));
|
||||
|
||||
|
||||
await authorityService.DeleteByUnitId(unitId);
|
||||
}
|
||||
|
||||
@@ -680,18 +871,34 @@ public class DisplayService(
|
||||
|
||||
#region Send Notification
|
||||
|
||||
/// <summary>
|
||||
/// Sends a smart display configuration update broadcast asynchronously to all specified WebSocket subscribers.
|
||||
/// </summary>
|
||||
/// <param name="subscribers">The list of WebSocket subscribers that will receive the smart display configuration update.</param>
|
||||
/// <param name="config">The smart display configuration to broadcast. May be <c>null</c> if no configuration is provided.</param>
|
||||
private void SendSmartDisplayBroadcast(List<WsSubscriber> subscribers, SmartDisplay? config)
|
||||
{
|
||||
foreach (var subscriber in subscribers)
|
||||
_ = clientMessageService.SendAsync(subscriber.Id, OperationType.UpdateSmartDisplayConfig, config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts a nurse display configuration update to all specified WebSocket subscribers by sending an asynchronous update message to each one.
|
||||
/// </summary>
|
||||
/// <param name="subscribers">The list of WebSocket subscribers that will receive the nurse display configuration update.</param>
|
||||
/// <param name="config">The nurse display configuration to broadcast, which may be <c>null</c>.</param>
|
||||
private void SendNurseDisplayBroadcast(List<WsSubscriber> subscribers, DisplayNurse? config)
|
||||
{
|
||||
foreach (var subscriber in subscribers)
|
||||
_ = clientMessageService.SendAsync(subscriber.Id, OperationType.UpdateNurseDisplayConfig, config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a broadcast message to all subscribers associated with the specified display.
|
||||
/// Currently only handles the <see cref="OperationType.UpdateDisplayPoC"/> operation, dispatching an asynchronous notification to each subscriber; other operation types are ignored.
|
||||
/// </summary>
|
||||
/// <param name="display">The display whose subscribers will receive the broadcast; used to filter the subscriber list by its identifier.</param>
|
||||
/// <param name="operation">The type of operation being broadcast, which determines the action taken on matching subscribers.</param>
|
||||
private void SendDisplayBroadcast(Display display, OperationType operation)
|
||||
{
|
||||
var subscribers = subscribersService.GetSubscribers().Where(s =>
|
||||
|
||||
Reference in New Issue
Block a user