Table of Contents

Class LightBeaconService

Namespace
adas_core.module.LightBeacons.Services
Assembly
adas-core.module.LightBeacons.dll

Service responsible for managing light beacons, including sending color alerts, powering off LEDs, and broadcasting beacon status to subscribers. It interacts with the point of care service to determine which beacons are associated with specific locations and maintains an in-memory cache of the current color state of each location's beacon. The service also handles CRUD operations for light beacon configurations stored in a MongoDB repository.

public class LightBeaconService : ILightBeaconService
Inheritance
LightBeaconService
Implements
Inherited Members
Extension Methods

Constructors

LightBeaconService(IOptions<ApiSettings>, ILogger<LightBeaconService>, IClientMessageService, ISubscribersService, IPointOfCareService, ILightBeaconRepository)

Initializes a new instance of the LightBeaconService class with the specified dependencies and configuration settings.

public LightBeaconService(IOptions<ApiSettings> apiSettings, ILogger<LightBeaconService> logger, IClientMessageService clientMessageService, ISubscribersService subscribersService, IPointOfCareService pointOfCareService, ILightBeaconRepository lightBeaconRepository)

Parameters

apiSettings IOptions<ApiSettings>

The API settings containing configuration values for the light beacon service.

logger ILogger<LightBeaconService>

The logger instance for logging information and errors.

clientMessageService IClientMessageService

The client message service for sending messages to clients.

subscribersService ISubscribersService

The subscribers service for managing subscribers.

pointOfCareService IPointOfCareService

The point of care service for retrieving point of care information.

lightBeaconRepository ILightBeaconRepository

The light beacon repository for managing light beacon data.

Methods

DictionaryToString(ConcurrentDictionary<ObjectId, LightBeaconColor>)

Converts the contents of a concurrent dictionary mapping point of care IDs to their associated light beacon colors into a string representation for logging purposes.

public static string DictionaryToString(ConcurrentDictionary<ObjectId, LightBeaconColor> dictionary)

Parameters

dictionary ConcurrentDictionary<ObjectId, LightBeaconColor>

Returns

string

GenerateColorAlert(PatientObservation)

Generates a color alert for a patient observation by determining the appropriate color based on the observation's status and configured colors for warnings and alerts.

public void GenerateColorAlert(PatientObservation obs)

Parameters

obs PatientObservation

The patient observation for which to generate the color alert.

GetColor(ObjectId)

Retrieves the current color state of the light beacon associated with the specified point of care ID.

public Task<LightBeaconColor> GetColor(ObjectId pocId)

Parameters

pocId ObjectId

The ID of the point of care for which to retrieve the color state.

Returns

Task<LightBeaconColor>

A task representing the asynchronous operation, with the current color state of the light beacon.

GetColor(PointOfCare)

Retrieves the current color state of the light beacon associated with the specified point of care.

public Task<LightBeaconColor> GetColor(PointOfCare poc)

Parameters

poc PointOfCare

The point of care for which to retrieve the color state.

Returns

Task<LightBeaconColor>

A task representing the asynchronous operation, with the current color state of the light beacon.

GetPaginatedBeacons(PaginationFilter)

Retrieves a paginated list of light beacons from the repository based on the specified pagination filter. The method also checks which beacons are currently in use by querying the point of care service and updates the "InUse" property of each beacon accordingly before returning the paginated response.

public Task<PaginationResponse<LightBeacon>> GetPaginatedBeacons(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination filter to apply when retrieving the light beacons.

Returns

Task<PaginationResponse<LightBeacon>>

A paginated response containing the light beacons that match the specified filter.

GetSearchByName(string)

Searches for light beacons in the repository that match the specified text in their name. The method returns a list of light beacons whose names contain the provided search text, allowing for partial matches.

public Task<List<LightBeacon>> GetSearchByName(string textToSearch)

Parameters

textToSearch string

The text to search for in the names of the light beacons.

Returns

Task<List<LightBeacon>>

A list of light beacons whose names contain the specified search text.

InsertOne(LightBeacon)

Inserts a new light beacon configuration into the repository. Before inserting, it checks if a beacon with the same name already exists to prevent duplicates.

public Task<LightBeacon?> InsertOne(LightBeacon beacon)

Parameters

beacon LightBeacon

The light beacon configuration to insert.

Returns

Task<LightBeacon>

The inserted light beacon configuration, or null if the insertion failed.

Exceptions

Exception

Thrown if a light beacon with the same name already exists.

PowerOffLed(ObjectId)

Powers off the LED of the light beacon associated with the specified point of care ID. It retrieves the point of care information, checks if there are any associated beacons, and sends a command to turn off the LED for each associated beacon. The method also updates the in-memory cache to reflect that the beacon is now off for the specified location.

public Task PowerOffLed(ObjectId pocId)

Parameters

pocId ObjectId

The ID of the point of care for which to power off the LED.

Returns

Task

A task representing the asynchronous operation.

PowerOffLed(PointOfCare)

Powers off the LED of the light beacon associated with the specified point of care. The method checks if the beacon is already off to avoid unnecessary commands, retrieves the beacon configuration for the point of care, and sends a command to turn off the LED for each associated beacon.

public Task PowerOffLed(PointOfCare poc)

Parameters

poc PointOfCare

The point of care for which to power off the LED.

Returns

Task

A task representing the asynchronous operation.

SendBeaconBroadcast(ObjectId, LightBeaconColor)

Sends a beacon broadcast message to all subscribers associated with the specified point of care ID, indicating the current color state of the beacon.

public Task SendBeaconBroadcast(ObjectId pocId, LightBeaconColor color)

Parameters

pocId ObjectId

The ID of the point of care for which to send the color command.

color LightBeaconColor

The color to set on the light beacon.

Returns

Task

A task representing the asynchronous operation.

SendBeaconBroadcast(PointOfCare, LightBeaconColor)

Sends a beacon broadcast message to all subscribers associated with the specified point of care, indicating the current color state of the beacon.

public Task SendBeaconBroadcast(PointOfCare poc, LightBeaconColor color)

Parameters

poc PointOfCare

The point of care for which to send the color command.

color LightBeaconColor

The color to set on the light beacon.

Returns

Task

A task representing the asynchronous operation.

SendColor(ObjectId, LightBeaconColor)

Sends a color command to the light beacon associated with the specified point of care ID. The method retrieves the point of care information, checks if there are any associated beacons, and sends a command to set the specified color for each associated beacon.

public Task SendColor(ObjectId pocId, LightBeaconColor color)

Parameters

pocId ObjectId

The ID of the point of care for which to send the color command.

color LightBeaconColor

The color to set on the light beacon.

Returns

Task

A task representing the asynchronous operation.

SendColor(PointOfCare, LightBeaconColor)

Sends a color command to the light beacon associated with the specified point of care. The method checks if the beacon is already set to the specified color to avoid unnecessary commands, retrieves the beacon configuration for the point of care, and sends a command to set the specified color for each associated beacon.

public Task SendColor(PointOfCare poc, LightBeaconColor color)

Parameters

poc PointOfCare

The point of care for which to send the color command.

color LightBeaconColor

The color to set on the light beacon.

Returns

Task

A task representing the asynchronous operation.

UpdateOne(LightBeacon)

Updates an existing light beacon configuration in the repository. The method takes a light beacon object with updated properties, updates the corresponding record in the repository based on the beacon's ID, and then retrieves and returns the updated light beacon configuration to confirm the changes.

public Task<LightBeacon?> UpdateOne(LightBeacon beacon)

Parameters

beacon LightBeacon

The light beacon object with updated properties.

Returns

Task<LightBeacon>

The updated light beacon configuration, or null if the update failed.