Class AlarmService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
Provides the concrete implementation of the IAlarmService contract, encapsulating the business logic for managing and processing alarms within the application.
public class AlarmService : IAlarmService, IApiRequestService
- Inheritance
-
AlarmService
- Implements
- Inherited Members
- Extension Methods
Constructors
AlarmService(IAlarmRepository, ILogger<AlarmService>, IPatientService, IConfigObservationService, Lazy<IObservationService>, IClientMessageService, ISubscribersService, Lazy<ICalculatedObservationsService>, Lazy<ILightBeaconService>, Lazy<IRecordingService>, Lazy<IRelayService>, IOptions<ApiSettings>, IUnitService, IPointOfCareService, IHttpContextAccessor, ILocalAuditService, bool)
public AlarmService(IAlarmRepository alarmRepository, ILogger<AlarmService> logger, IPatientService patientService, IConfigObservationService configObservationService, Lazy<IObservationService> observationService, IClientMessageService clientMessageService, ISubscribersService subscribersService, Lazy<ICalculatedObservationsService> calculatedObservationsService, Lazy<ILightBeaconService> lightBeaconService, Lazy<IRecordingService> recordingService, Lazy<IRelayService> relayService, IOptions<ApiSettings> apiSettings, IUnitService unitService, IPointOfCareService pocService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, bool startTimer = true)
Parameters
alarmRepositoryIAlarmRepositoryloggerILogger<AlarmService>patientServiceIPatientServiceconfigObservationServiceIConfigObservationServiceobservationServiceLazy<IObservationService>clientMessageServiceIClientMessageServicesubscribersServiceISubscribersServicecalculatedObservationsServiceLazy<ICalculatedObservationsService>lightBeaconServiceLazy<ILightBeaconService>recordingServiceLazy<IRecordingService>relayServiceLazy<IRelayService>apiSettingsIOptions<ApiSettings>unitServiceIUnitServicepocServiceIPointOfCareServicehttpContextAccessorIHttpContextAccessorauditServiceILocalAuditServicestartTimerbool
Methods
CalculateAlarmTest(BasePatientObservationValue, string)
Calculates and dispatches test alarms for a patient observation based on its configuration. Supports beacon alerts, recording, and door control when the corresponding alarm components are enabled; if the source is not a PatientObservation, the method returns without action, and recordings fall back to a default Yellow severity when no severity string is provided.
public Task CalculateAlarmTest(BasePatientObservationValue source, string name)
Parameters
sourceBasePatientObservationValueThe patient observation value used to look up the alarm configuration and identify the target patient.
namestringThe name associated with the observation, used for logging and alarm context.
Returns
CheckObservationAlarm(PatientObservation)
Evaluates alarm configuration rules for a patient observation and, when matching conditions and preconditions are satisfied, generates a new alert observation, logs it, and triggers the corresponding alarm notification.
public Task CheckObservationAlarm(PatientObservation obs)
Parameters
obsPatientObservationThe patient observation whose value is evaluated against configured alert rules and preconditions.
Returns
FindLastObservationsByField(ObjectId, List<Field>?)
Retrieves the most recent patient observation alarms for the specified patient, optionally filtered by a set of fields.
public Task<List<PatientObservationAlarm>> FindLastObservationsByField(ObjectId patientId, List<Field>? filterObservations = null)
Parameters
patientIdObjectIdThe identifier of the patient whose last observations should be retrieved.
filterObservationsList<Field>An optional list of fields used to restrict which observations are returned; when null, no field filter is applied.
Returns
- Task<List<PatientObservationAlarm>>
A task that represents the asynchronous operation, containing a list of the patient's last PatientObservationAlarm entries.
FindLastValuesNotExpired(ObjectId, List<Field>, List<ConfigObservation>)
Retrieves the most recent non-expired patient observation alarms for the specified patient, filtered by the given observation fields and alarm configurations.
public Task<List<PatientObservationAlarm>> FindLastValuesNotExpired(ObjectId patientId, List<Field> filterObservations, List<ConfigObservation> configAlarm)
Parameters
patientIdObjectIdThe unique identifier of the patient whose alarms are being queried.
filterObservationsList<Field>The list of fields used to filter the observations included in the aggregation.
configAlarmList<ConfigObservation>The list of alarm configurations that define the criteria applied during the aggregation.
Returns
- Task<List<PatientObservationAlarm>>
A task that resolves to a list of the latest non-expired PatientObservationAlarm entries matching the criteria.
MapObservation(PatientObservationAlarm, bool)
Maps a PatientObservationAlarm through the configuration observation service and then through the calculated observations service. If either mapping step returns null, or an exception occurs, the method logs the issue and returns null instead of propagating the error.
public Task<PatientObservationAlarm?> MapObservation(PatientObservationAlarm obs, bool onlyByName = false)
Parameters
obsPatientObservationAlarmThe patient observation alarm to be mapped.
onlyByNameboolIf true, mapping is performed by name only; otherwise the full mapping is applied.
Returns
- Task<PatientObservationAlarm>
A mapped PatientObservationAlarm if both mapping steps succeed; otherwise, null.
MapObservationsByName(PatientObservationAlarm)
Maps the provided patient observation alarm to its corresponding configuration by name, returning the mapped alarm if a matching configuration is found.
public Task<PatientObservationAlarm?> MapObservationsByName(PatientObservationAlarm obs)
Parameters
obsPatientObservationAlarmThe patient observation alarm to be mapped by name.
Returns
- Task<PatientObservationAlarm>
A task that returns the mapped PatientObservationAlarm if a matching configuration is found; otherwise,
null.
ProcessAlarmObservations(List<PatientObservationAlarm>, List<PatientObservation>, Patient, DateTime, ObservationData?)
Processes and persists a list of patient observation alarms, enriching each alarm with patient, timing, and coding metadata. When a matching non-alarm observation is found in the provided list, its coding fields are reused; otherwise defaults derived from the alarm priority (Ph/Pm/Pl) are applied. For alarms that carry source data, related observations are mapped and submitted through the observation service before the alarm itself is inserted.
public Task ProcessAlarmObservations(List<PatientObservationAlarm> alarmObservations, List<PatientObservation> observations, Patient patient, DateTime messageTime, ObservationData? observationData = null)
Parameters
alarmObservationsList<PatientObservationAlarm>The alarm observations to process and insert.
observationsList<PatientObservation>Existing non-alarm observations used to look up and reuse coding information when a value match is found.
patientPatientThe patient the alarms are associated with.
messageTimeDateTimeThe message time assigned to each alarm.
observationDataObservationDataOptional parent observation metadata applied to all alarms in the batch.
Returns
SaveRequest(ApiRequest)
Processes and saves an incoming API request, handling ORU_R40 unsolicited alert observation messages. Validates that the patient number or location unit name is provided, resolves the patient and unit configuration, and processes any alarm observations; requests are ignored when no patient is found or auto-adt management is disabled.
public Task SaveRequest(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request containing patient, location, observation, and alarm data to process.
Returns
Exceptions
- InvalidFormatException
Thrown when both the patient number and location unit name are missing.
- ApiRequestException
Thrown when the API request type is not valid for observations.
SaveRequestAsync(ApiRequest)
Asynchronously saves the specified API request by delegating to the underlying save operation.
public Task SaveRequestAsync(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request to be saved.
Returns
SendAlarm(PatientObservation, string, Name?, Severity, Type)
Sends a new alarm
public Task SendAlarm(PatientObservation obs, string name, AlarmEnum.Name? code, AlarmEnum.Severity severity, AlarmEnum.Type type)
Parameters
obsPatientObservationObservation to generate the alarm
namestringName of the alarm
codeAlarmEnum.Name?Code of the alarm for the recording
severityAlarmEnum.SeveritySeverity of the alarm for the recording
typeAlarmEnum.Type
Returns
- Task
New alarm created