# Class RecordingService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

Provides functionality for recording operations as defined by the IRecordingService contract.

    public class RecordingService : IRecordingService, IApiRequestService

Inheritance
  object
  RecordingService

Implements
  IRecordingService
  IApiRequestService

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

### RecordingService(IOptions<RabbitMqSettings>, IOptions<RecordingSettings>, ILogger<RecordingService>, IHttpClientFactory, IPublisherService, IAuthService, IOptions<ApiSettings>, IClientMessageService, ISubscribersService, Lazy<IPatientService>)

    public RecordingService(IOptions<RabbitMqSettings> rabbitMqSettings, IOptions<RecordingSettings> recordingSettings, ILogger<RecordingService> logger, IHttpClientFactory httpClientFactory, IPublisherService publisherService, IAuthService authService, IOptions<ApiSettings> apiSettings, IClientMessageService clientMessageService, ISubscribersService subscribersService, Lazy<IPatientService> patientService)

#### Parameters

`rabbitMqSettings` IOptions<RabbitMqSettings>
`recordingSettings` IOptions<RecordingSettings>
`logger` ILogger<RecordingService>
`httpClientFactory` IHttpClientFactory
`publisherService` IPublisherService
`authService` IAuthService
`apiSettings` IOptions<ApiSettings>
`clientMessageService` IClientMessageService
`subscribersService` ISubscribersService
`patientService` Lazy<IPatientService>

## Methods

### Base64Encode(string)

Encodes the specified plain text to a Base64 string using UTF-8 encoding.

    protected static string Base64Encode(string plainText)

#### Parameters

`plainText` string

  The text to encode.

#### Returns

string

  The Base64 encoded representation of the input text.

### GetRecordings(int)

Asynchronously retrieves the list of in-progress recordings for the specified room from the recording API. Performs token-based authentication, retries transient HTTP request failures up to the configured maximum, and falls back to an empty list or `null` when the API is unreachable, the room has no recordings, or retries are exhausted.

    public Task<List<RecordingData>?> GetRecordings(int roomId)

#### Parameters

`roomId` int

  The identifier of the room whose recordings should be fetched.

#### Returns

Task<List<RecordingData>>

  A task that resolves to a list of RecordingData for the room, an empty list when the request fails or the room has no recordings, or `null` when the recording API URL or authentication token is not configured or when the maximum number of retries is reached.

### SaveRequest(ApiRequest)

Saves the specified API request. The method is not yet implemented.

    public Task SaveRequest(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request to save.

#### Returns

Task

#### Exceptions

NotImplementedException

  Always thrown because the method has not been implemented.

### SaveRequestAsync(ApiRequest)

Sends the recording data from the given API request to the Recording API with authentication, retrying on failure up to the configured maximum and routing unsuccessful requests to the error queue. Clears the access token on 401 responses, maps the returned video data into a recording broadcast message on success, and falls back to the error queue when retries are exhausted or a connection error occurs.

    public Task SaveRequestAsync(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request whose recording data and patient information will be sent to the Recording API.

#### Returns

Task

#### Exceptions

Exception

  Rethrown via Task.FromException when a non-HTTP error occurs while sending the recording request.

### SendAutoRecordingData(Patient, PointOfCare, RecordingData)

Sends automatic recording data for the specified patient and point of care to the recording data queue. Validates that the alarm name can be parsed to AlarmEnum.Name; returns `false` if the name is invalid or if an exception occurs during the send operation.

    public Task<bool> SendAutoRecordingData(Patient patient, PointOfCare poc, RecordingData automaticRecording)

#### Parameters

`patient` Patient

  The patient associated with the automatic recording.

`poc` PointOfCare

  The point of care where the recording was captured.

`automaticRecording` RecordingData

  The automatic recording payload, including alarm name, start/stop/event timestamps, severity, and description.

#### Returns

Task<bool>

  A task that resolves to `true` if the recording data was queued successfully; otherwise, `false` when the alarm name cannot be parsed or the send operation fails.

### SendCancelRecordingToRecordingApi(Patient, PointOfCare)

Sends a cancel recording request to the recording API for the specified patient and point of care. Throws an exception if the recording API URL is not configured or a valid authentication token cannot be obtained.

    public Task<bool> SendCancelRecordingToRecordingApi(Patient patient, PointOfCare poc)

#### Parameters

`patient` Patient

  The patient whose recording in progress should be cancelled.

`poc` PointOfCare

  The point of care associated with the recording.

#### Returns

Task<bool>

  A task that resolves to `true` if the cancel request succeeded; otherwise, `false`.

#### Exceptions

Exception

  Thrown when the recording API URL is not defined or the authentication token is null or empty.

### SendRecordingData(Patient, PointOfCare, ManualRecording, bool)

Sends the manual recording data to the processing queue, forwarding the recording's start and stop times along with the patient and point of care information.

    public Task SendRecordingData(Patient patient, PointOfCare poc, ManualRecording manualRecording, bool start)

#### Parameters

`patient` Patient

  The patient associated with the manual recording.

`poc` PointOfCare

  The point of care where the recording was performed.

`manualRecording` ManualRecording

  The manual recording whose start and stop times are forwarded to the queue.

`start` bool

  A flag indicating whether the recording is being started or stopped.

#### Returns

Task

### SendRecordingDataToQueue(Patient, PointOfCare, DateTime?, DateTime?, DateTime?, Name?, Severity, string?, bool, Type)

Sends recording data for a patient to the recording message queue, broadcasting the recording after a successful send. Validates the patient number when the start-without-patient-number feature is disabled, ensures the point of care is in use, defaults a missing alarm description to "UNKNOWN", and retries the send on transient HTTP connection failures up to the configured maximum, routing the last failure to the error recording queue.

    public Task SendRecordingDataToQueue(Patient patient, PointOfCare poc, DateTime? date, DateTime? endDate, DateTime? eventDate, AlarmEnum.Name? alarmName, AlarmEnum.Severity severity, string? alarmDescription, bool start = true, AlarmEnum.Type type = Type.Manual)

#### Parameters

`patient` Patient

  The patient whose recording is being sent; its patient number is validated when required.

`poc` PointOfCare

  The point of care (box) that must be in use to allow the recording to be sent.

`date` DateTime?

  Optional recording date used to build the recording payload.

`endDate` DateTime?

  Optional end date used to build the recording payload.

`eventDate` DateTime?

  Optional event date used to build the recording payload.

`alarmName` AlarmEnum.Name?

  Optional alarm name to associate with the recording.

`severity` AlarmEnum.Severity

  The alarm severity for the recording.

`alarmDescription` string

  Optional alarm description; when null or empty it is replaced with "UNKNOWN".

`start` bool

  Flag indicating whether the recording is a start event; defaults to true.

`type` AlarmEnum.Type

  The alarm type for the recording; defaults to Manual.

#### Returns

Task

#### Exceptions

Exception

  Thrown when the point of care status is not InUse, including the serialized point of care in the message.