# Class DisplayService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

    public class DisplayService : IDisplayService

Inheritance
  object
  DisplayService

Implements
  IDisplayService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### DisplayService(IDisplayRepository, IPointOfCareService, Lazy<IUnitService>, IDisplayConfigService, ISubscribersService, IClientMessageService, IUserRepository, IAuthService, ILogger<DisplayService>, IHttpContextAccessor, ILocalAuditService, Lazy<IPermissionService>, ICacheService, IOptions<CacheSettings>)

    public DisplayService(IDisplayRepository displayRepository, IPointOfCareService pointOfCareService, Lazy<IUnitService> unitService, IDisplayConfigService displayConfigService, ISubscribersService subscribersService, IClientMessageService clientMessageService, IUserRepository userRepository, IAuthService authorityService, ILogger<DisplayService> logger, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, Lazy<IPermissionService> permissionService, ICacheService cacheService, IOptions<CacheSettings> cacheSettings)

#### Parameters

`displayRepository` IDisplayRepository
`pointOfCareService` IPointOfCareService
`unitService` Lazy<IUnitService>
`displayConfigService` IDisplayConfigService
`subscribersService` ISubscribersService
`clientMessageService` IClientMessageService
`userRepository` IUserRepository
`authorityService` IAuthService
`logger` ILogger<DisplayService>
`httpContextAccessor` IHttpContextAccessor
`auditService` ILocalAuditService
`permissionService` Lazy<IPermissionService>
`cacheService` ICacheService
`cacheSettings` IOptions<CacheSettings>

## Methods

### CountDisplaysByUnitId(ObjectId)

Asynchronously counts the number of displays associated with the specified unit identifier.

    public Task<long> CountDisplaysByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose displays should be counted.

#### Returns

Task<long>

  A task that represents the asynchronous operation. The task result contains the total number of displays for the given unit.

### DeleteDisplay(ObjectId)

Deletes a display by its identifier, removing the record, invalidating the related cache, clearing associated authorities, and recording an audit log entry.

    public Task<bool> DeleteDisplay(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the display to delete.

#### Returns

Task<bool>

  A task that resolves to `true` when the display has been successfully deleted.

#### Exceptions

NotFoundException

  Thrown when no display is found for the specified `id`.

### DeleteDisplaysByUnitId(ObjectId)

Deletes all displays associated with the specified unit identifier, invalidates the displays cache, and removes related authority data for the unit.

    public Task DeleteDisplaysByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose displays and related authority data will be removed.

#### Returns

Task

### GetAll(string?)

Retrieves all display items, optionally filtered by the specified user name.

    public Task<List<Display>> GetAll(string? userName)

#### Parameters

`userName` string

  The user name used to filter the display items, or null to retrieve all items.

#### Returns

Task<List<Display>>

  A task that represents the asynchronous operation. The task result contains a list of Display items.

#### Exceptions

NotImplementedException

  The method has not been implemented yet.

### GetAllAvailablePoc(List<string>, bool)

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 NotFoundException is thrown when a resolved unit cannot be found; any unexpected error is logged and an empty result is returned.

    public Task<PocAndUnitDto> GetAllAvailablePoc(List<string> displayIds, bool excludeVirtual = false)

#### Parameters

`displayIds` List<string>

  A list of display identifier strings used to resolve the related units and their available points of care.

`excludeVirtual` bool

  When set to `true`, virtual points of care are excluded from the result; otherwise, they are included.

#### Returns

Task<PocAndUnitDto>

  A PocAndUnitDto containing the available points of care and their associated unit details.

#### Exceptions

NotFoundException

  Thrown when a unit associated with one of the resolved display identifiers cannot be found.

### GetAllByUser(string?)

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.

    public Task<List<DisplayWithPermissionsDto>> GetAllByUser(string? userName)

#### Parameters

`userName` string

  The username whose displays should be retrieved; when null, the method returns an empty list.

#### Returns

Task<List<DisplayWithPermissionsDto>>

  A task that yields a list of DisplayWithPermissionsDto containing the displays the user can access along with their permissions.

#### Exceptions

ForbbidenException

  Thrown when permissions for a unit-scoped display cannot be obtained for the user.

### GetAllCompact()

Retrieves all displays from the repository and maps them to a compact representation.

    public Task<List<DisplayMinimalDto>> GetAllCompact()

#### Returns

Task<List<DisplayMinimalDto>>

  A task that represents the asynchronous operation, containing a list of DisplayMinimalDto with the mapped display data.

### GetAllDisplaySection()

Asynchronously retrieves all display configurations of type DisplayNurse and SmartDisplay, mapping them into minimal display sections and grouping them within a display list DTO.

    public Task<MinimalDisplayListDto> GetAllDisplaySection()

#### Returns

Task<MinimalDisplayListDto>

  A task that represents the asynchronous operation. The task result contains a MinimalDisplayListDto with the populated DisplayNurse and SmartDisplay collections.

### GetAllPocsByDisplayId(ObjectId)

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.

    public Task<List<PointOfCare>> GetAllPocsByDisplayId(ObjectId id)

#### Parameters

`id` ObjectId

  The ObjectId of the display whose points of care should be retrieved.

#### Returns

Task<List<PointOfCare>>

  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.

### GetByCardConfigId(ObjectId)

Retrieves a list of displays associated with the specified card configuration identifier by delegating to the underlying repository.

    public Task<List<Display>> GetByCardConfigId(ObjectId configId)

#### Parameters

`configId` ObjectId

  The unique identifier of the card configuration used to look up the associated displays.

#### Returns

Task<List<Display>>

  A task that represents the asynchronous operation, containing a list of Display objects matching the provided card configuration identifier.

### GetByConfigId(ObjectId)

Retrieves the list of displays associated with the specified configuration identifier by delegating to the display repository.

    public Task<List<Display>> GetByConfigId(ObjectId configId)

#### Parameters

`configId` ObjectId

  The configuration identifier used to look up the associated displays.

#### Returns

Task<List<Display>>

  A task that returns the list of Display objects matching the given configuration identifier.

### GetById(ObjectId)

Retrieves a Display by its unique identifier from the repository.

    public Task<Display?> GetById(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the display to retrieve.

#### Returns

Task<Display>

  The matching Display if found; otherwise, `null`.

### GetByIdWithPermissions(ObjectId, LocaleEnum)

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.

    public Task<DisplayWithPermissionsDto> GetByIdWithPermissions(ObjectId id, LocaleEnum localeEnum)

#### Parameters

`id` ObjectId

  The unique identifier of the display to retrieve.

`localeEnum` LocaleEnum

  The locale used to localize the related point-of-care information.

#### Returns

Task<DisplayWithPermissionsDto>

  A DisplayWithPermissionsDto containing the display and its associated permissions.

#### Exceptions

NotFoundException

  Thrown when the current user cannot be identified from the JWT or when no display is found for the specified `id`.

### GetByName(string)

Retrieves a Display by its name. Throws a NotFoundException if no matching display is found.

    public Task<Display?> GetByName(string name)

#### Parameters

`name` string

  The name of the display to look up.

#### Returns

Task<Display>

  The Display that matches the specified name.

#### Exceptions

NotFoundException

  Thrown when no display is found for the given name.

### GetByPointOfCare(PointOfCare)

Retrieves a list of displays associated with the specified point of care.

    public Task<List<Display>> GetByPointOfCare(PointOfCare pointOfCare)

#### Parameters

`pointOfCare` PointOfCare

  The point of care used to filter the displays.

#### Returns

Task<List<Display>>

  A task that represents the asynchronous operation. The task result contains the list of displays matching the specified point of care.

### GetByType(DisplayType)

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.

    public Task<List<Display>> GetByType(DisplayConfigEnums.DisplayType type)

#### Parameters

`type` DisplayConfigEnums.DisplayType

  The display type used to filter the display configurations.

#### Returns

Task<List<Display>>

  A list of displays matching the specified type, each with its related configuration assigned; an empty list is returned when no displays are found.

### GetByUnitId(ObjectId)

Retrieves the list of displays associated with the specified unit identifier by delegating to the display repository.

    public Task<List<Display>> GetByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The identifier of the unit whose displays should be returned.

#### Returns

Task<List<Display>>

  A task that represents the asynchronous operation, containing the list of Display objects for the given unit.

### GetDisplayConfigLocations(ObjectId)

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.

    public Task<List<DisplayConfigLocationDto>> GetDisplayConfigLocations(ObjectId displayConfigId)

#### Parameters

`displayConfigId` ObjectId

  The identifier of the display configuration whose locations are being retrieved.

#### Returns

Task<List<DisplayConfigLocationDto>>

  A task that represents the asynchronous operation. The task result contains a list of DisplayConfigLocationDto objects with display and unit information.

### GetDisplaySectionByUser(DisplayType, ObjectId?, string?, List<Authorization>?)

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.

    public Task<List<MinimalDisplaySection>> GetDisplaySectionByUser(DisplayConfigEnums.DisplayType type, ObjectId? currentDisplay, string? userName, List<Authorization>? authorizations)

#### Parameters

`type` DisplayConfigEnums.DisplayType

  The display type used to filter the returned sections.

`currentDisplay` ObjectId?

  The identifier of the currently selected display, which will be flagged as selected in the result; may be null.

`userName` string

  The username used to look up the user and their authorities; if null, an empty list is returned.

`authorizations` List<Authorization>

  Optional pre-fetched list of user authorities; when null, authorities are retrieved from the authority service.

#### Returns

Task<List<MinimalDisplaySection>>

  A task that resolves to a list of MinimalDisplaySection items accessible to the user and matching the specified display type.

### GetInfo(ObjectId, string?, List<Authorization>?, LocaleEnum?, bool, bool, bool, bool, CancellationToken)

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.

    public Task<Display?> GetInfo(ObjectId id, string? userName, List<Authorization>? authorizations, LocaleEnum? locale, bool fillPointOfCare = true, bool fillPatientData = false, bool fillDisplayList = true, bool fillDisplayConfig = true, CancellationToken ct = default)

#### Parameters

`id` ObjectId

  Identifier of the display to retrieve.

`userName` string

  Optional user name used to look up authorizations when none are provided.

`authorizations` List<Authorization>

  Optional pre-resolved authorizations used to filter the display section list.

`locale` LocaleEnum?

  Optional locale applied when loading point-of-care data.

`fillPointOfCare` bool

  If true, populates the point-of-care entries for the display.

`fillPatientData` bool

  If true, includes patient data when retrieving point-of-care information.

`fillDisplayList` bool

  If true, populates the display section list filtered by the resolved authorizations.

`fillDisplayConfig` bool

  If true, retrieves the full display including its configuration (cached); otherwise retrieves the base display.

`ct` CancellationToken

  Cancellation token to cancel the operation.

#### Returns

Task<Display>

  The requested Display, or `null` if no display is found for the given id.

### GetPaginatedDisplays(PaginationFilter)

Retrieves a paginated list of Display items along with the total document count, applying page number and page size from the provided filter.

    public Task<PaginationResponse<Display>> GetPaginatedDisplays(PaginationFilter filter)

#### Parameters

`filter` PaginationFilter

  The pagination filter containing the page number and page size used to determine the slice of results to return.

#### Returns

Task<PaginationResponse<Display>>

  A Task<TResult> containing the requested page of displays, the current page number, the page size, and the total number of documents.

### InsertOne(Display)

Inserts a new Display using the default configuration for its type. If no default configuration exists for the display type, a NotFoundException is thrown. An audit log entry is created after the display is persisted.

    public Task<Display> InsertOne(Display display)

#### Parameters

`display` Display

  The display to insert. Its `DisplayConfigId` is assigned from the resolved default configuration.

#### Returns

Task<Display>

  The inserted Display with its `DisplayConfigId` populated.

#### Exceptions

NotFoundException

  Thrown when no default configuration is found for the specified display type.

### InsertOneTest()

Inserts a test Display record into the repository and records a corresponding audit log entry using the current HTTP context user.

    public Task<Display> InsertOneTest()

#### Returns

Task<Display>

  The newly created Display entity.

### IsDisplayConfigInUse(ObjectId)

Determines whether the specified display configuration is currently in use by checking if it is referenced by any related entity.

    public Task<bool> IsDisplayConfigInUse(ObjectId displayConfigId)

#### Parameters

`displayConfigId` ObjectId

  The unique identifier of the display configuration to check.

#### Returns

Task<bool>

  `true` if the display configuration is referenced by at least one entity; otherwise, `false`.

### UpdateConfig(Display, DisplayConfig?)

Updates the configuration of an existing display by casting the new configuration to its specific type based on DisplayConfigEnums.DisplayType, supporting `DisplayNurse` and `SmartDisplay`. On a successful update, broadcasts the change, creates an audit log entry, and invalidates the related cache entry. Returns `null` if the provided configuration type is not supported or the cast results in `null`.

    public Task<Display?> UpdateConfig(Display oldDisplay, DisplayConfig? newDisplayConfig)

#### Parameters

`oldDisplay` Display

  The existing display whose configuration will be updated.

`newDisplayConfig` DisplayConfig

  The new configuration to apply, or `null` if no update is provided.

#### Returns

Task<Display>

  The updated Display if the configuration was successfully applied; otherwise, `null`.

### UpdateConfigId(Display, ObjectId)

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.

    public Task<Display?> UpdateConfigId(Display oldDisplay, ObjectId configId)

#### Parameters

`oldDisplay` Display

  The display whose configuration ID is being updated.

`configId` ObjectId

  The new configuration ID to assign to the display.

#### Returns

Task<Display>

  The updated display, or `null` if the display was not found.

### UpdateConfigPreset(ObjectId, ObjectId)

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.

    public Task<Display?> UpdateConfigPreset(ObjectId objectIdDisplay, ObjectId objectIdConfigDisplay)

#### Parameters

`objectIdDisplay` ObjectId

  The identifier of the display whose configuration preset is being updated.

`objectIdConfigDisplay` ObjectId

  The identifier of the new configuration preset to apply to the display.

#### Returns

Task<Display>

  The updated Display entity, or `null` if the update could not be completed.

#### Exceptions

NotFoundException

  Thrown when the update result or the resolved configuration is `null`.

InvalidFormatException

  Thrown when the configuration type is not one of the handled display types.

### UpdateName(ObjectId, string)

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.

    public Task<Display?> UpdateName(ObjectId id, string name)

#### Parameters

`id` ObjectId

  The unique identifier of the display to update.

`name` string

  The new name to assign to the display.

#### Returns

Task<Display>

  The updated Display instance, or `null` if the update could not be performed.

#### Exceptions

NotFoundException

  Thrown when no display is found for the specified `id`.

### UpdatePointOfCareList(ObjectId, List<ObjectId>)

Updates the point of care list associated with the specified display, invalidating the related cache entries and broadcasting the change to subscribers.

    public Task<Display?> UpdatePointOfCareList(ObjectId objectId, List<ObjectId> listPocObId)

#### Parameters

`objectId` ObjectId

  The identifier of the display whose point of care list is being updated.

`listPocObId` List<ObjectId>

  The list of point of care object identifiers to assign to the display.

#### Returns

Task<Display>

  The updated Display instance after the point of care list change.

#### Exceptions

NotFoundException

  Thrown when no display exists for the specified `objectId`.

ConflictException

  Thrown when the point of care list update cannot be persisted.