Table of Contents

Class RelayController

Namespace
adas_core.Controllers
Assembly
adas-core.dll
[ApiController]
[Route("Relay")]
public class RelayController : ControllerBase
Inheritance
RelayController
Inherited Members
Extension Methods

Constructors

RelayController(IOptions<RecordingSettings>, IRelayService, ILogger<RelayController>, IPointOfCareService)

public RelayController(IOptions<RecordingSettings> recordingSettings, IRelayService relayService, ILogger<RelayController> logger, IPointOfCareService pointOfCareService)

Parameters

recordingSettings IOptions<RecordingSettings>
relayService IRelayService
logger ILogger<RelayController>
pointOfCareService IPointOfCareService

Methods

CheckRelayStatus(int, string, string, int, string, int, string, string)

Checks the status of a relay device by building a relay configuration from the supplied parameters and delegating the status check to the relay service.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthAdmin)]
[Route("{id}/status")]
public IActionResult CheckRelayStatus(int id, string driver, string host, int port, string relayName, int total, string username, string password)

Parameters

id int

The relay number identifier used to select the specific relay.

driver string

The driver type used to communicate with the relay.

host string

The host IP address of the relay device.

port int

The network port used to connect to the relay device.

relayName string

The name assigned to the relay configuration.

total int

The total number of relays in the configuration.

username string

The username used for relay authentication.

password string

The password used for relay authentication.

Returns

IActionResult

An IActionResult containing the relay status result returned by the relay service.

CheckSectionStatus()

Retrieves the status of point-of-care sections by querying the relay status for each configured box and its associated relays. Returns a 404 Not Found when no configurations are available, or a list containing the unit, bed, and status for each relay when configurations exist.

[HttpGet]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("status")]
public Task<IActionResult> CheckSectionStatus()

Returns

Task<IActionResult>

An IActionResult that is either a 404 Not Found when no configurations are found, or an HTTP 200 OK response containing a collection of objects with the unit name, bed, and relay status.

CreateRelay(Relay?)

Creates a new relay based on the provided request payload. Throws a bad request exception if the request body is missing required parameters.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> CreateRelay(Relay? request)

Parameters

request Relay

The relay data to create, supplied in the request body.

Returns

Task<IActionResult>

An IActionResult containing the created relay.

Exceptions

BadRequestException

Thrown when the request is null.

GetPaginatedUnits(PaginationFilter, bool)

Retrieves a paginated list of relays based on the provided pagination filter.

[HttpPost("paginated")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> GetPaginatedUnits(PaginationFilter request, bool withPoCs)

Parameters

request PaginationFilter

The pagination filter containing the paging parameters.

withPoCs bool

Flag indicating whether to include related point of contact data in the response.

Returns

Task<IActionResult>

An IActionResult containing the paginated relays.

Exceptions

BadRequestException

Thrown when the request is null.

ManualSwitch(string, string, string)

Manually switches a relay for a specific point of connection (POC) to a given status and type. Validates the input parameters and returns a bad request if the status, type, or POC identifier cannot be parsed; returns an internal server error if an unexpected exception occurs, otherwise returns a successful response.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("manual/{status}")]
public IActionResult ManualSwitch(string status, string pocId, string type)

Parameters

status string

The desired relay status as a string, which is parsed into RelayEnum.Status.

pocId string

The identifier of the point of connection, which must be a valid ObjectId string.

type string

The relay type as a string, which is parsed into RelayEnum.Type.

Returns

IActionResult

An IActionResult indicating the outcome: BadRequestResult for invalid input, StatusCodeResult for internal server errors, or OkObjectResult with false on success.

PowerOff(int, string, string, int, string, int, string, string?)

Powers off a relay identified by the given id using the provided relay configuration parameters. On failure to power off the relay, returns an Internal Server Error status; otherwise returns OK with a false result.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("{id}/power/off")]
public IActionResult PowerOff(int id, string driver, string host, int port, string relayName, int total, string username, string? password)

Parameters

id int

The identifier of the relay to power off.

driver string

The relay driver type to use for the operation.

host string

The host address of the relay device.

port int

The port number used to communicate with the relay device.

relayName string

The name assigned to the relay.

total int

The total number of relays managed by the device.

username string

The username used for relay authentication.

password string

The optional password used for relay authentication.

Returns

IActionResult

An IActionResult indicating the outcome: Ok with a false value on success, or an Internal Server Error status if the power off operation fails.

PowerOffPoC(PowerActionRequest)

Powers off the relay configuration for the specified unit, point of care, and bed by delegating the operation to the relay service.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("powerOff")]
public Task<IActionResult> PowerOffPoC(PowerActionRequest action)

Parameters

action PowerActionRequest

The power action request containing the unit identifier, point of care identifier, and bed information.

Returns

Task<IActionResult>

An IActionResult representing the result of the power off operation.

PowerOn(int, string, string, int, string, int, string, string?)

Powers on the relay identified by the specified id using the provided connection configuration. Returns HTTP 200 with a success indicator when the relay is powered on, or HTTP 500 if the relay service throws an exception.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("{id}/power/on")]
public IActionResult PowerOn(int id, string driver, string host, int port, string relayName, int total, string username, string? password)

Parameters

id int

The identifier of the relay to power on.

driver string

The relay driver to use for the connection.

host string

The host address of the relay device.

port int

The port number used to connect to the relay device.

relayName string

The name assigned to the relay.

total int

The total number of relays managed by the device.

username string

The username used to authenticate with the relay device.

password string

The optional password used to authenticate with the relay device.

Returns

IActionResult

An IActionResult containing HTTP 200 with a success value on success, or HTTP 500 if the relay service fails.

PowerOnPoC(PowerActionRequest)

Handles a power-on request for a Point of Care (PoC) device by delegating to the shared power action pipeline and turning on the configured relay for the specified unit, point of care, and bed.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[Route("powerOn")]
public Task<IActionResult> PowerOnPoC(PowerActionRequest action)

Parameters

action PowerActionRequest

The request payload containing the identifiers of the unit, point of care, and bed to power on.

Returns

Task<IActionResult>

An IActionResult representing the result of the power-on operation.

UpdateRelay(Relay, string)

Updates an existing relay identified by the specified id with the provided relay data.

[HttpPut("{id}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
public Task<IActionResult> UpdateRelay(Relay relay, string id)

Parameters

relay Relay

The relay data to apply to the existing record.

id string

The identifier of the relay to update, expected to be a valid ObjectId.

Returns

Task<IActionResult>

An IActionResult containing the updated relay when the operation succeeds.

Exceptions

BadRequestException

Thrown when the provided id cannot be parsed as a valid ObjectId.