=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===

This commit is contained in:
julian
2026-06-28 02:50:05 -07:00
parent a19fb90902
commit 586f02a2ca
654 changed files with 5260 additions and 0 deletions
@@ -21,6 +21,7 @@ namespace adas_core.Application.Services;
/// Provides the concrete implementation of the <see cref="IAlarmService"/> contract,
/// encapsulating the business logic for managing and processing alarms within the application.
/// </summary>
/// <!-- aidoc:v1 sig=060faf3 -->
public class AlarmService : IAlarmService
{
private readonly IAlarmRepository _alarmRepository;
@@ -122,6 +123,7 @@ public class AlarmService : IAlarmService
/// <param name="apiRequest">The API request containing patient, location, observation, and alarm data to process.</param>
/// <exception cref="InvalidFormatException">Thrown when both the patient number and location unit name are missing.</exception>
/// <exception cref="ApiRequestException">Thrown when the API request type is not valid for observations.</exception>
/// <!-- aidoc:v1 sig=229d8cd body=405bafb -->
public async Task SaveRequest(ApiRequest apiRequest)
{
if (
@@ -178,6 +180,7 @@ public class AlarmService : IAlarmService
/// Asynchronously saves the specified API request by delegating to the underlying save operation.
/// </summary>
/// <param name="apiRequest">The API request to be saved.</param>
/// <!-- aidoc:v1 sig=655d140 body=fe3d8b2 -->
public async Task SaveRequestAsync(ApiRequest apiRequest)
{
await SaveRequest(apiRequest);
@@ -190,6 +193,7 @@ public class AlarmService : IAlarmService
/// <param name="obs">The patient observation alarm to be mapped.</param>
/// <param name="onlyByName">If true, mapping is performed by name only; otherwise the full mapping is applied.</param>
/// <returns>A mapped <see cref="PatientObservationAlarm"/> if both mapping steps succeed; otherwise, null.</returns>
/// <!-- aidoc:v1 sig=78ca950 body=5f19c29 -->
public async Task<PatientObservationAlarm?> MapObservation(PatientObservationAlarm obs, bool onlyByName = false)
{
try
@@ -229,6 +233,7 @@ public class AlarmService : IAlarmService
/// <param name="patientId">The identifier of the patient whose last observations should be retrieved.</param>
/// <param name="filterObservations">An optional list of fields used to restrict which observations are returned; when null, no field filter is applied.</param>
/// <returns>A task that represents the asynchronous operation, containing a list of the patient's last <see cref="PatientObservationAlarm"/> entries.</returns>
/// <!-- aidoc:v1 sig=a25fefd body=4cd8879 -->
public async Task<List<PatientObservationAlarm>> FindLastObservationsByField(ObjectId patientId,
List<Field>? filterObservations = null)
{
@@ -244,6 +249,7 @@ public class AlarmService : IAlarmService
/// <param name="filterObservations">The list of fields used to filter the observations included in the aggregation.</param>
/// <param name="configAlarm">The list of alarm configurations that define the criteria applied during the aggregation.</param>
/// <returns>A task that resolves to a list of the latest non-expired <see cref="PatientObservationAlarm"/> entries matching the criteria.</returns>
/// <!-- aidoc:v1 sig=2739a83 body=5e76a47 -->
public async Task<List<PatientObservationAlarm>> FindLastValuesNotExpired(ObjectId patientId,
List<Field> filterObservations, List<ConfigObservation> configAlarm)
{
@@ -258,6 +264,7 @@ public class AlarmService : IAlarmService
/// </summary>
/// <param name="obs">The patient observation alarm to be mapped by name.</param>
/// <returns>A task that returns the mapped <see cref="PatientObservationAlarm"/> if a matching configuration is found; otherwise, <c>null</c>.</returns>
/// <!-- aidoc:v1 sig=5372879 body=c476eb8 -->
public async Task<PatientObservationAlarm?> MapObservationsByName(PatientObservationAlarm obs)
{
return await _configObservationService.Map(obs, true);
@@ -271,6 +278,7 @@ public class AlarmService : IAlarmService
/// <param name="patient">The patient the alarms are associated with.</param>
/// <param name="messageTime">The message time assigned to each alarm.</param>
/// <param name="observationData">Optional parent observation metadata applied to all alarms in the batch.</param>
/// <!-- aidoc:v1 sig=c249a9d body=81d79c0 -->
public async Task ProcessAlarmObservations(List<PatientObservationAlarm> alarmObservations,
List<PatientObservation> observations, Patient patient,
DateTime messageTime, ObservationData? observationData = null)
@@ -398,6 +406,7 @@ public class AlarmService : IAlarmService
/// <param name="obs">The patient observation alarm to insert.</param>
/// <param name="persistObs">Indicates whether the observation should be persisted to the repository. Defaults to true and is forced to false if the observation's <c>Persist</c> property is false.</param>
/// <param name="mapObs">Indicates whether the observation should be mapped before being processed. Set to false only when the observation originates from the inner refactor job.</param>
/// <!-- aidoc:v1 sig=a04333a body=d8cb988 -->
private async Task InsertObservation(PatientObservationAlarm obs, bool persistObs = true, bool mapObs = true)
{
try
@@ -436,6 +445,7 @@ public class AlarmService : IAlarmService
/// Skips observations without a name and returns silently when the associated patient cannot be resolved from the observation or the patient service.
/// </summary>
/// <param name="obs">The patient observation to be sent to matching subscribers as an alarm operation.</param>
/// <!-- aidoc:v1 sig=52a60f2 body=dc24760 -->
private async Task SendObsBroadcast(BasePatientObservation obs)
{
if (obs.Name == null) return;
@@ -473,6 +483,7 @@ public class AlarmService : IAlarmService
/// 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.
/// </summary>
/// <param name="obs">The patient observation whose value is evaluated against configured alert rules and preconditions.</param>
/// <!-- aidoc:v1 sig=a86f464 body=bee7a9f -->
public async Task CheckObservationAlarm(PatientObservation obs)
{
//ConfigObservations
@@ -551,6 +562,7 @@ public class AlarmService : IAlarmService
/// <param name="config">The configuration observation providing the coding system, code, name, and alarm settings.</param>
/// <param name="type">The status type to assign to the new observation.</param>
/// <returns>A new <see cref="PatientObservation"/> populated with the merged values from the source observation and configuration.</returns>
/// <!-- aidoc:v1 sig=91e2989 body=7ec15fe -->
private static PatientObservation CreateNewObservation(PatientObservation obs, ConfigObservation config,
StatusEnum.Type type)
{
@@ -572,6 +584,7 @@ public class AlarmService : IAlarmService
/// </summary>
/// <param name="pobs">The patient observation whose alarm configuration will be checked and updated.</param>
/// <returns>The patient observation with the configured alarm applied, or with a null alarm if no configuration was found.</returns>
/// <!-- aidoc:v1 sig=4d79a28 body=efca777 -->
private async Task<PatientObservation> CheckAlarmConfig(PatientObservation pobs)
{
var configObs = await _configObservationService.Get(new PatientObservation
@@ -596,6 +609,10 @@ public class AlarmService : IAlarmService
/// <param name="type"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
/// <returns>New alarm created</returns>
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "Method returns Task (void async), not a 'New alarm created'. There is no return value produced." -->
/// <!-- aidoc-review:v1 severity=high kind=missing_param
/// "The 'type' parameter has an empty <param> tag with no description, while name/code/severity are described." -->
public async Task SendAlarm(PatientObservation obs, string name, AlarmEnum.Name? code, AlarmEnum.Severity severity,
AlarmEnum.Type type)
{
@@ -775,6 +792,8 @@ public class AlarmService : IAlarmService
/// </summary>
/// <param name="source">The patient observation value used to look up the alarm configuration and identify the target patient.</param>
/// <param name="name">The name associated with the observation, used for logging and alarm context.</param>
/// <!-- aidoc-review:v1 severity=medium kind=wrong_param_role
/// "The 'name' parameter is documented as 'used for logging and alarm context', but the method body never references it; all logging uses obs.PatientId and obs.Name instead." -->
public async Task CalculateAlarmTest(BasePatientObservationValue source, string name)
{
if (source is not PatientObservation obs) return;
@@ -824,6 +843,7 @@ public class AlarmService : IAlarmService
/// </summary>
/// <param name="color">The beacon color to transmit to the light beacon service.</param>
/// <param name="patient">The patient whose associated point of care device should display the beacon color.</param>
/// <!-- aidoc:v1 sig=1b6b9f9 body=c0fe279 -->
private Task SendBeaconCode(AlarmEnum.BeaconColor color, Patient patient)
{
if (!patient.PointOfCareId.HasValue)
@@ -862,6 +882,12 @@ public class AlarmService : IAlarmService
/// <param name="endAfter"></param>
/// <param name="severity"></param>
/// <param name="type"></param>
/// <!-- aidoc-review:v1 severity=medium kind=wrong_summary
/// "Summary is empty and does not describe what the method does (starts a recording based on patient, POC, and alarm data)." -->
/// <!-- aidoc-review:v1 severity=medium kind=missing_returns
/// "Method returns Task but no <returns> tag is present." -->
/// <!-- aidoc-review:v1 severity=medium kind=missing_param
/// "No documentation for what each parameter represents (patientId, recording, alarmName, alarmDescription, endAfter, severity, type are all undocumented beyond a placeholder or a single line)." -->
private async Task StartRecording(ObjectId patientId, DateTime eventTime, AlarmItem? recording,
AlarmEnum.Name? alarmName, AlarmEnum.Severity severity, string? alarmDescription, int? endAfter,
AlarmEnum.Type type = AlarmEnum.Type.Manual)
@@ -896,6 +922,7 @@ public class AlarmService : IAlarmService
/// </summary>
/// <param name="patientId">The identifier of the patient whose relay should be powered on.</param>
/// <param name="type">The type of relay to power on, used to locate the matching configuration in the point of care's relay list.</param>
/// <!-- aidoc:v1 sig=7ecd7ee body=04cade6 -->
private async Task RelayPowerOn(ObjectId patientId, RelayEnum.Type type)
{
try
@@ -922,6 +949,7 @@ public class AlarmService : IAlarmService
/// Starts a periodic background timer that retrieves the list of locations and periodically checks for expired alarms, using a semaphore to ensure thread-safe execution.
/// Logs any errors encountered during timer initialization or execution without rethrowing them.
/// </summary>
/// <!-- aidoc:v1 sig=fac87dc body=29b2aa2 -->
private async void StartTimer()
{
try
@@ -957,6 +985,7 @@ public class AlarmService : IAlarmService
/// Asynchronously checks for expired alarms by running the beacon and relay expiration checks in parallel.
/// </summary>
/// <param name="pocList">The list of points of care to be evaluated for expired beacon alarms.</param>
/// <!-- aidoc:v1 sig=e77aa4b body=99bc6c5 -->
private async Task CheckExpiredAlarms(List<PointOfCare> pocList)
{
_logger.LogTrace("Checking Expired Alarms Started");
@@ -981,6 +1010,7 @@ public class AlarmService : IAlarmService
/// the still-valid observations.
/// </summary>
/// <param name="pocList">The list of points of care whose beacons should be turned off when no alarms are active.</param>
/// <!-- aidoc:v1 sig=5baf90c body=8c4d364 -->
private async Task CheckExpiredBeaconsAsync(List<PointOfCare> pocList)
{
await _beaconListSemaphore.WaitAsync();
@@ -1050,6 +1080,7 @@ public class AlarmService : IAlarmService
/// patients without an assigned <c>PointOfCareId</c> are processed, and the relay alarm list is
/// synchronized under a lock with the filtered non-expired observations.
/// </summary>
/// <!-- aidoc:v1 sig=6193459 body=f16dcb9 -->
private async Task CheckExpiredRelayAsync()
{
var now = DateTime.UtcNow;