rama creada apartir de master en j
This commit is contained in:
@@ -14,6 +14,9 @@ using Options = Microsoft.Extensions.Options.Options;
|
||||
|
||||
namespace adas_core.Test.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for verifying the behavior and functionality of the <see cref="AlarmService"/> class.
|
||||
/// </summary>
|
||||
public class AlarmServiceTest
|
||||
{
|
||||
private readonly Mock<IAlarmRepository> _alarmRepositoryMock;
|
||||
@@ -111,137 +114,154 @@ public class AlarmServiceTest
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that when an ORU_R40 type request is processed without any alarms, the patient is located but the observation is not persisted.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task SaveRequest_Oru_R40_Type_Without_Alarms_Dont_Insert()
|
||||
{
|
||||
// Arrange
|
||||
var apiRequest = new ApiRequest
|
||||
public async Task SaveRequest_Oru_R40_Type_Without_Alarms_Dont_Insert()
|
||||
{
|
||||
Type = "ORU_R40",
|
||||
PatientNumber = "12345",
|
||||
Observation = new PatientObservation { Value = "Test" },
|
||||
Alarms = [],
|
||||
Location = new PatientLocation { Bed = "Bed1", Room = "Bed1", UnitName = "Unit1" }
|
||||
};
|
||||
var unit = new Unit { Configuration = new UnitConfiguration { AutoAdt = true } };
|
||||
var patient = new Patient { Id = ObjectId.GenerateNewId(), Bed = "Bed1" };
|
||||
_unitServiceMock.Setup(u => u.FindByUnitNameOrPocName(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ReturnsAsync(unit);
|
||||
_patientServiceMock.Setup(p => p.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_observationServiceMock.Setup(o => o.SaveRequestAsync(It.IsAny<ApiRequest>())).Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _alarmService.SaveRequest(apiRequest);
|
||||
|
||||
// Assert
|
||||
_patientServiceMock.Verify(p => p.FindPatientByApiRequest(apiRequest), Times.Once);
|
||||
_observationServiceMock.Verify(o => o.SaveRequestAsync(It.IsAny<ApiRequest>()), Times.Never);
|
||||
}
|
||||
// Arrange
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Type = "ORU_R40",
|
||||
PatientNumber = "12345",
|
||||
Observation = new PatientObservation { Value = "Test" },
|
||||
Alarms = [],
|
||||
Location = new PatientLocation { Bed = "Bed1", Room = "Bed1", UnitName = "Unit1" }
|
||||
};
|
||||
var unit = new Unit { Configuration = new UnitConfiguration { AutoAdt = true } };
|
||||
var patient = new Patient { Id = ObjectId.GenerateNewId(), Bed = "Bed1" };
|
||||
_unitServiceMock.Setup(u => u.FindByUnitNameOrPocName(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ReturnsAsync(unit);
|
||||
_patientServiceMock.Setup(p => p.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_observationServiceMock.Setup(o => o.SaveRequestAsync(It.IsAny<ApiRequest>())).Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _alarmService.SaveRequest(apiRequest);
|
||||
|
||||
// Assert
|
||||
_patientServiceMock.Verify(p => p.FindPatientByApiRequest(apiRequest), Times.Once);
|
||||
_observationServiceMock.Verify(o => o.SaveRequestAsync(It.IsAny<ApiRequest>()), Times.Never);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AlarmService.ProcessAlarmObservations"/> inserts the provided alarm observations into the alarm repository.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ProcessAlarmObservations_Should_Insert_Alarm_Observations()
|
||||
{
|
||||
// Arrange
|
||||
var patient = new Patient { Id = ObjectId.GenerateNewId(), Bed = "Bed1" };
|
||||
var alarmObservations = new List<PatientObservationAlarm>
|
||||
public async Task ProcessAlarmObservations_Should_Insert_Alarm_Observations()
|
||||
{
|
||||
new() { Value = "Alarm1", Time = DateTime.UtcNow}
|
||||
};
|
||||
var observations = new List<PatientObservation>
|
||||
{
|
||||
new() { Value = "Alarm1", Time = DateTime.MinValue}
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(o => o.Map(It.IsAny<PatientObservationAlarm>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservationAlarm obs, bool _) => obs); // Correct setup
|
||||
|
||||
_calculatedObservationsServiceMock.Setup(o => o.Map(It.IsAny<PatientObservationAlarm>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservationAlarm obs, bool _) => obs); // Correct setup
|
||||
|
||||
// Act
|
||||
await _alarmService.ProcessAlarmObservations(alarmObservations, observations, patient, DateTime.UtcNow);
|
||||
|
||||
// Assert
|
||||
_alarmRepositoryMock.Verify(a => a.InsertOneAsync(It.IsAny<PatientObservationAlarm>()), Times.Once);
|
||||
}
|
||||
// Arrange
|
||||
var patient = new Patient { Id = ObjectId.GenerateNewId(), Bed = "Bed1" };
|
||||
var alarmObservations = new List<PatientObservationAlarm>
|
||||
{
|
||||
new() { Value = "Alarm1", Time = DateTime.UtcNow}
|
||||
};
|
||||
var observations = new List<PatientObservation>
|
||||
{
|
||||
new() { Value = "Alarm1", Time = DateTime.MinValue}
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(o => o.Map(It.IsAny<PatientObservationAlarm>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservationAlarm obs, bool _) => obs); // Correct setup
|
||||
|
||||
_calculatedObservationsServiceMock.Setup(o => o.Map(It.IsAny<PatientObservationAlarm>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservationAlarm obs, bool _) => obs); // Correct setup
|
||||
|
||||
// Act
|
||||
await _alarmService.ProcessAlarmObservations(alarmObservations, observations, patient, DateTime.UtcNow);
|
||||
|
||||
// Assert
|
||||
_alarmRepositoryMock.Verify(a => a.InsertOneAsync(It.IsAny<PatientObservationAlarm>()), Times.Once);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that when checking observation alarms for a patient observation with an "Event_PEEP_Low" configuration
|
||||
/// (coding system "ADAS_EVENT", description "EVT_LO and EVT_EXTR_LO"), the alarm service does not insert a new observation,
|
||||
/// as indicated by the verification that <c>InsertObservation</c> is never invoked.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task CheckObservationAlarm_Alarm_EventPEEP_PEEP_bajo_create_Event()
|
||||
{
|
||||
var obs = new PatientObservation();
|
||||
|
||||
var configs = new ConfigObservation
|
||||
public async Task CheckObservationAlarm_Alarm_EventPEEP_PEEP_bajo_create_Event()
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Event_PEEP_Low",
|
||||
CodingSystem = "ADAS_EVENT",
|
||||
Description = "EVT_LO and EVT_EXTR_LO"
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(c => c.Get(It.IsAny<PatientObservation>(), false))
|
||||
.ReturnsAsync(configs);
|
||||
|
||||
await _alarmService.CheckObservationAlarm(obs);
|
||||
|
||||
|
||||
_observationServiceMock.Verify(o => o.InsertObservation(obs, true, true), Times.Never);
|
||||
}
|
||||
var obs = new PatientObservation();
|
||||
|
||||
var configs = new ConfigObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Event_PEEP_Low",
|
||||
CodingSystem = "ADAS_EVENT",
|
||||
Description = "EVT_LO and EVT_EXTR_LO"
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(c => c.Get(It.IsAny<PatientObservation>(), false))
|
||||
.ReturnsAsync(configs);
|
||||
|
||||
await _alarmService.CheckObservationAlarm(obs);
|
||||
|
||||
|
||||
_observationServiceMock.Verify(o => o.InsertObservation(obs, true, true), Times.Never);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="AlarmService.CheckObservationAlarm"/> processes a patient observation
|
||||
/// matching a configured rule (name "EVT_LO" with required value "PEEP") by inserting a new
|
||||
/// observation with the original value preserved (e.g., "PEEP High") while the alarm
|
||||
/// configuration handles the red beacon signaling.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task CheckObservationAlarm_Should_Launch_Red_Alarm_And_Set_BeaconColor_Red()
|
||||
{
|
||||
var alarmConfig = new AlarmConfig
|
||||
public async Task CheckObservationAlarm_Should_Launch_Red_Alarm_And_Set_BeaconColor_Red()
|
||||
{
|
||||
Enabled = true,
|
||||
Priority = 10,
|
||||
Beacon = new AlarmItem
|
||||
var alarmConfig = new AlarmConfig
|
||||
{
|
||||
Enabled = true,
|
||||
BeaconColor = AlarmEnum.BeaconColor.Red, // Using the enum value
|
||||
EndAfter = 60 // Assuming the alarm should end after 60 seconds
|
||||
}
|
||||
};
|
||||
|
||||
var configs = new ConfigObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Event_PEEP_Low",
|
||||
CodingSystem = "ADAS_EVENT",
|
||||
Description = "logs an event. No generate an alarm.",
|
||||
Alarm = alarmConfig,
|
||||
RequiredValue = "PEEP"
|
||||
};
|
||||
|
||||
var obsConfig = new ConfigObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "EVT_LO",
|
||||
CheckObservations = true,
|
||||
CreateObservation = [configs]
|
||||
};
|
||||
var patId = ObjectId.GenerateNewId();
|
||||
// Arrange
|
||||
var obs = new PatientObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "EVT_LO",
|
||||
PatientId = patId,
|
||||
Value = "PEEP High",
|
||||
Time = DateTime.UtcNow,
|
||||
CheckObservations = true,
|
||||
CreateObservation = [configs]
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(c => c.Get(It.IsAny<PatientObservation>(), false))
|
||||
.ReturnsAsync(obsConfig);
|
||||
|
||||
|
||||
// Act
|
||||
await _alarmService.CheckObservationAlarm(obs);
|
||||
|
||||
_observationServiceMock.Verify(
|
||||
o => o.InsertObservation(
|
||||
It.Is<PatientObservation>(ob => ob.Value.ToString() == "PEEP High"), true, true),
|
||||
Times.Once);
|
||||
}
|
||||
Priority = 10,
|
||||
Beacon = new AlarmItem
|
||||
{
|
||||
Enabled = true,
|
||||
BeaconColor = AlarmEnum.BeaconColor.Red, // Using the enum value
|
||||
EndAfter = 60 // Assuming the alarm should end after 60 seconds
|
||||
}
|
||||
};
|
||||
|
||||
var configs = new ConfigObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "Event_PEEP_Low",
|
||||
CodingSystem = "ADAS_EVENT",
|
||||
Description = "logs an event. No generate an alarm.",
|
||||
Alarm = alarmConfig,
|
||||
RequiredValue = "PEEP"
|
||||
};
|
||||
|
||||
var obsConfig = new ConfigObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "EVT_LO",
|
||||
CheckObservations = true,
|
||||
CreateObservation = [configs]
|
||||
};
|
||||
var patId = ObjectId.GenerateNewId();
|
||||
// Arrange
|
||||
var obs = new PatientObservation
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
Name = "EVT_LO",
|
||||
PatientId = patId,
|
||||
Value = "PEEP High",
|
||||
Time = DateTime.UtcNow,
|
||||
CheckObservations = true,
|
||||
CreateObservation = [configs]
|
||||
};
|
||||
|
||||
_configObservationServiceMock.Setup(c => c.Get(It.IsAny<PatientObservation>(), false))
|
||||
.ReturnsAsync(obsConfig);
|
||||
|
||||
|
||||
// Act
|
||||
await _alarmService.CheckObservationAlarm(obs);
|
||||
|
||||
_observationServiceMock.Verify(
|
||||
o => o.InsertObservation(
|
||||
It.Is<PatientObservation>(ob => ob.Value.ToString() == "PEEP High"), true, true),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user