rama creada apartir de master en j
This commit is contained in:
@@ -21,98 +21,104 @@ namespace adas_core.Test.Services;
|
||||
[TestFixture]
|
||||
public class ObservationServiceTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the test fixture for the <see cref="ObservationService"/> by creating and configuring
|
||||
/// all required dependency mocks, instantiating the service under test with the mocked collaborators,
|
||||
/// and pre-configuring common lookup behavior for the default "UCI5C" unit (including <c>FindByName</c>
|
||||
/// and <c>FindById</c>) along with the <c>ICalculatedObservationsService.Map</c> passthrough.
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
//_observationServiceMock = new Mock<IObservationService>();
|
||||
|
||||
//var medicineServiceMock = new Mock<IMedicineService>();1
|
||||
var groupedObservationServiceMock = new Mock<IGroupedObservationService>();
|
||||
var alarmServiceMock = new Mock<IAlarmService>();
|
||||
|
||||
var clientMessageServiceMock = new Mock<IClientMessageService>();
|
||||
|
||||
var subscribersServiceMock = new Mock<ISubscribersService>();
|
||||
|
||||
var subscriberGroupedServiceMock = new Mock<ISubscriberGroupedService>();
|
||||
|
||||
_patientServiceMock = new Mock<IPatientService>();
|
||||
|
||||
_configObservationService = new Mock<IConfigObservationService>();
|
||||
|
||||
_observationRepository = new Mock<IObservationRepository>();
|
||||
|
||||
var observationArchiveRepository = new Mock<IObservationArchiveRepository>();
|
||||
|
||||
var calculatedObservationsServiceMock = new Mock<ICalculatedObservationsService>();
|
||||
var calculatedObservationsServiceLazy =
|
||||
new Lazy<ICalculatedObservationsService>(() => calculatedObservationsServiceMock.Object);
|
||||
calculatedObservationsServiceMock.Setup(o => o.Map(It.IsAny<PatientObservation>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservation obs, bool _) => obs);
|
||||
|
||||
_configUnitsService = new Mock<IConfigUnitsService>();
|
||||
_unitServiceMock = new Mock<IUnitService>();
|
||||
|
||||
var diagnosisServiceMock = new Mock<IDiagnosisService>();
|
||||
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
Options.Create(_recordingSettings);
|
||||
_optionsCacheSettings = Options.Create(_cacheSettings);
|
||||
|
||||
var balizaService = new Mock<ILightBeaconService>();
|
||||
var pocService = new Mock<IPointOfCareService>();
|
||||
var relayService = new Mock<IRelayService>();
|
||||
var recordingService = new Mock<IRecordingService>();
|
||||
|
||||
_logger = new Mock<ILogger<ObservationService>>();
|
||||
|
||||
_observationService = new ObservationService(
|
||||
_patientServiceMock.Object,
|
||||
//Ipoc.Object,
|
||||
_configObservationService.Object,
|
||||
_observationRepository.Object,
|
||||
observationArchiveRepository.Object,
|
||||
_configUnitsService.Object,
|
||||
diagnosisServiceMock.Object,
|
||||
_optionsApiSettings,
|
||||
_optionsCacheSettings,
|
||||
balizaService.Object,
|
||||
relayService.Object,
|
||||
recordingService.Object,
|
||||
_logger.Object,
|
||||
groupedObservationServiceMock.Object,
|
||||
alarmServiceMock.Object,
|
||||
clientMessageServiceMock.Object,
|
||||
subscribersServiceMock.Object,
|
||||
subscriberGroupedServiceMock.Object,
|
||||
calculatedObservationsServiceLazy,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object,
|
||||
pocService.Object,
|
||||
Mock.Of<ICacheService>()
|
||||
);
|
||||
|
||||
// Create a mock of the singleton class subscribers
|
||||
var mockSingleton = new Mock<ICalculatedObservationsService>();
|
||||
|
||||
// Set up the mock object to return a specific value when a method is called
|
||||
mockSingleton.Setup(x => x.Map(It.IsAny<PatientObservation>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservation? value, bool _) => value);
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var unit = new Unit
|
||||
public void Setup()
|
||||
{
|
||||
Id = unitId,
|
||||
Name = "UCI5C",
|
||||
Title = "CONTROLC",
|
||||
Configuration = new UnitConfiguration
|
||||
//_observationServiceMock = new Mock<IObservationService>();
|
||||
|
||||
//var medicineServiceMock = new Mock<IMedicineService>();1
|
||||
var groupedObservationServiceMock = new Mock<IGroupedObservationService>();
|
||||
var alarmServiceMock = new Mock<IAlarmService>();
|
||||
|
||||
var clientMessageServiceMock = new Mock<IClientMessageService>();
|
||||
|
||||
var subscribersServiceMock = new Mock<ISubscribersService>();
|
||||
|
||||
var subscriberGroupedServiceMock = new Mock<ISubscriberGroupedService>();
|
||||
|
||||
_patientServiceMock = new Mock<IPatientService>();
|
||||
|
||||
_configObservationService = new Mock<IConfigObservationService>();
|
||||
|
||||
_observationRepository = new Mock<IObservationRepository>();
|
||||
|
||||
var observationArchiveRepository = new Mock<IObservationArchiveRepository>();
|
||||
|
||||
var calculatedObservationsServiceMock = new Mock<ICalculatedObservationsService>();
|
||||
var calculatedObservationsServiceLazy =
|
||||
new Lazy<ICalculatedObservationsService>(() => calculatedObservationsServiceMock.Object);
|
||||
calculatedObservationsServiceMock.Setup(o => o.Map(It.IsAny<PatientObservation>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservation obs, bool _) => obs);
|
||||
|
||||
_configUnitsService = new Mock<IConfigUnitsService>();
|
||||
_unitServiceMock = new Mock<IUnitService>();
|
||||
|
||||
var diagnosisServiceMock = new Mock<IDiagnosisService>();
|
||||
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
Options.Create(_recordingSettings);
|
||||
_optionsCacheSettings = Options.Create(_cacheSettings);
|
||||
|
||||
var balizaService = new Mock<ILightBeaconService>();
|
||||
var pocService = new Mock<IPointOfCareService>();
|
||||
var relayService = new Mock<IRelayService>();
|
||||
var recordingService = new Mock<IRecordingService>();
|
||||
|
||||
_logger = new Mock<ILogger<ObservationService>>();
|
||||
|
||||
_observationService = new ObservationService(
|
||||
_patientServiceMock.Object,
|
||||
//Ipoc.Object,
|
||||
_configObservationService.Object,
|
||||
_observationRepository.Object,
|
||||
observationArchiveRepository.Object,
|
||||
_configUnitsService.Object,
|
||||
diagnosisServiceMock.Object,
|
||||
_optionsApiSettings,
|
||||
_optionsCacheSettings,
|
||||
balizaService.Object,
|
||||
relayService.Object,
|
||||
recordingService.Object,
|
||||
_logger.Object,
|
||||
groupedObservationServiceMock.Object,
|
||||
alarmServiceMock.Object,
|
||||
clientMessageServiceMock.Object,
|
||||
subscribersServiceMock.Object,
|
||||
subscriberGroupedServiceMock.Object,
|
||||
calculatedObservationsServiceLazy,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object,
|
||||
pocService.Object,
|
||||
Mock.Of<ICacheService>()
|
||||
);
|
||||
|
||||
// Create a mock of the singleton class subscribers
|
||||
var mockSingleton = new Mock<ICalculatedObservationsService>();
|
||||
|
||||
// Set up the mock object to return a specific value when a method is called
|
||||
mockSingleton.Setup(x => x.Map(It.IsAny<PatientObservation>(), It.IsAny<bool>()))
|
||||
.ReturnsAsync((PatientObservation? value, bool _) => value);
|
||||
var unitId = ObjectId.GenerateNewId();
|
||||
var unit = new Unit
|
||||
{
|
||||
AutoAdt = true
|
||||
}
|
||||
};
|
||||
|
||||
_unitServiceMock.Setup(u => u.FindByName(unit.Name)).ReturnsAsync(unit);
|
||||
_unitServiceMock.Setup(u => u.FindById(unit.Id)).ReturnsAsync(unit);
|
||||
}
|
||||
Id = unitId,
|
||||
Name = "UCI5C",
|
||||
Title = "CONTROLC",
|
||||
Configuration = new UnitConfiguration
|
||||
{
|
||||
AutoAdt = true
|
||||
}
|
||||
};
|
||||
|
||||
_unitServiceMock.Setup(u => u.FindByName(unit.Name)).ReturnsAsync(unit);
|
||||
_unitServiceMock.Setup(u => u.FindById(unit.Id)).ReturnsAsync(unit);
|
||||
}
|
||||
|
||||
private ObservationService _observationService;
|
||||
|
||||
@@ -637,172 +643,178 @@ public class ObservationServiceTest
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that when an isolation observation is processed through SaveRequest, the configuration observation and units mapping services are invoked, and the resulting mapped observation is inserted into the observation repository with the expected value, patient identifier, name, time, message time, and coding system.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ProcessIsolationObservation_Return_IsolationObs()
|
||||
{
|
||||
var patientObs = new Person
|
||||
public async Task ProcessIsolationObservation_Return_IsolationObs()
|
||||
{
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitId = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
var patientObs = new Person
|
||||
{
|
||||
Code = "302147001",
|
||||
CodingSystem = "SNM",
|
||||
Value = "Aire; Contacto; Preventivo",
|
||||
Text = "Aislamiento",
|
||||
Time = Now
|
||||
},
|
||||
Observations =
|
||||
[
|
||||
new PatientObservation
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitId = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
{
|
||||
Code = "code",
|
||||
Code = "302147001",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name",
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Time = Now,
|
||||
Value = "value"
|
||||
}
|
||||
],
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
var newObs = new PatientObservation
|
||||
{
|
||||
Value = "Aire, Contacto, Preventivo",
|
||||
Name = "Isolation",
|
||||
CodingSystem = "ADAS",
|
||||
PatientId = patient.Id,
|
||||
MessageTime = Now,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_configObservationService
|
||||
.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id), false))
|
||||
.ReturnsAsync(newObs);
|
||||
_configUnitsService.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id)))
|
||||
.ReturnsAsync(newObs);
|
||||
_configObservationService.Setup(o => o.RetentionActions(It.IsAny<PatientObservation>()))
|
||||
.ReturnsAsync(new ObservatitonRetentionResult());
|
||||
_unitServiceMock.Setup(o => o.FindById(It.IsAny<ObjectId>())).ReturnsAsync(new Unit
|
||||
{ Configuration = new UnitConfiguration { AutoAdt = true } });
|
||||
await _observationService.SaveRequest(apiRequest);
|
||||
|
||||
|
||||
_observationRepository.Verify(o => o.InsertOneAsync(It.Is<PatientObservation>(arg =>
|
||||
arg.Value == newObs.Value &&
|
||||
arg.PatientId == newObs.PatientId &&
|
||||
arg.Name == newObs.Name &&
|
||||
arg.Time == newObs.Time &&
|
||||
arg.MessageTime == newObs.MessageTime &&
|
||||
arg.CodingSystem == newObs.CodingSystem
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task ProcessPositionObservation_Return_PositionObs()
|
||||
{
|
||||
var patientObs = new Person
|
||||
{
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitId = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
Value = "Aire; Contacto; Preventivo",
|
||||
Text = "Aislamiento",
|
||||
Time = Now
|
||||
},
|
||||
Observations =
|
||||
[
|
||||
new PatientObservation
|
||||
{
|
||||
Code = "code",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name",
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Time = Now,
|
||||
Value = "value"
|
||||
}
|
||||
],
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
var newObs = new PatientObservation
|
||||
{
|
||||
Value = "Aire, Contacto, Preventivo",
|
||||
Name = "Isolation",
|
||||
CodingSystem = "ADAS",
|
||||
PatientId = patient.Id,
|
||||
MessageTime = Now,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_configObservationService
|
||||
.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id), false))
|
||||
.ReturnsAsync(newObs);
|
||||
_configUnitsService.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id)))
|
||||
.ReturnsAsync(newObs);
|
||||
_configObservationService.Setup(o => o.RetentionActions(It.IsAny<PatientObservation>()))
|
||||
.ReturnsAsync(new ObservatitonRetentionResult());
|
||||
_unitServiceMock.Setup(o => o.FindById(It.IsAny<ObjectId>())).ReturnsAsync(new Unit
|
||||
{ Configuration = new UnitConfiguration { AutoAdt = true } });
|
||||
await _observationService.SaveRequest(apiRequest);
|
||||
|
||||
|
||||
_observationRepository.Verify(o => o.InsertOneAsync(It.Is<PatientObservation>(arg =>
|
||||
arg.Value == newObs.Value &&
|
||||
arg.PatientId == newObs.PatientId &&
|
||||
arg.Name == newObs.Name &&
|
||||
arg.Time == newObs.Time &&
|
||||
arg.MessageTime == newObs.MessageTime &&
|
||||
arg.CodingSystem == newObs.CodingSystem
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that processing a position observation through the observation service persists a new <see cref="PatientObservation"/> with the expected values (Value, PatientId, Name, Time, MessageTime, and CodingSystem) when a valid API request is provided.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ProcessPositionObservation_Return_PositionObs()
|
||||
{
|
||||
var patientObs = new Person
|
||||
{
|
||||
FirstName = "Miguel",
|
||||
LastName = "Villanueva",
|
||||
Ids = new Dictionary<string, string> { { "MR", "437537" } }
|
||||
};
|
||||
|
||||
var patient = new Patient
|
||||
{
|
||||
Id = ObjectId.GenerateNewId(),
|
||||
UnitId = ObjectId.GenerateNewId(),
|
||||
UnitString = "UCI5C",
|
||||
Bed = "Box4",
|
||||
PatientNumber = "437537",
|
||||
Person = patientObs
|
||||
};
|
||||
|
||||
var apiRequest = new ApiRequest
|
||||
{
|
||||
Location = new PatientLocation("UCI5C", "Box4"),
|
||||
ObservationData = new ObservationData
|
||||
{
|
||||
Code = "386053000",
|
||||
CodingSystem = "SNM",
|
||||
Text = "CAMBIOS POSTURALES",
|
||||
Value = "Cama Hill-rom",
|
||||
Time = Now
|
||||
},
|
||||
Observations =
|
||||
[
|
||||
new PatientObservation
|
||||
{
|
||||
Code = "code",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name",
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Time = Now,
|
||||
Value = "Cama Hill-rom"
|
||||
}
|
||||
],
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
var newObs = new PatientObservation
|
||||
{
|
||||
Code = "386053000",
|
||||
CodingSystem = "SNM",
|
||||
Text = "CAMBIOS POSTURALES",
|
||||
Value = "Cama Hill-rom",
|
||||
Name = "Patient_Position",
|
||||
CodingSystem = "ADAS",
|
||||
PatientId = patient.Id,
|
||||
MessageTime = Now,
|
||||
Time = Now
|
||||
},
|
||||
Observations =
|
||||
[
|
||||
new PatientObservation
|
||||
{
|
||||
Code = "code",
|
||||
CodingSystem = "SNM",
|
||||
Name = "name",
|
||||
Status = StatusEnum.Type.Ok,
|
||||
Time = Now,
|
||||
Value = "Cama Hill-rom"
|
||||
}
|
||||
],
|
||||
Patient = patientObs,
|
||||
PatientNumber = "437537",
|
||||
Type = "ORU_R01",
|
||||
PatientId = PatientId.ToString(),
|
||||
MessageTime = Now
|
||||
};
|
||||
|
||||
var newObs = new PatientObservation
|
||||
{
|
||||
Value = "Cama Hill-rom",
|
||||
Name = "Patient_Position",
|
||||
CodingSystem = "ADAS",
|
||||
PatientId = patient.Id,
|
||||
MessageTime = Now,
|
||||
Time = Now
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_configObservationService
|
||||
.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id), false))
|
||||
.ReturnsAsync(newObs);
|
||||
_configUnitsService.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id)))
|
||||
.ReturnsAsync(newObs);
|
||||
_configObservationService.Setup(o => o.RetentionActions(It.IsAny<PatientObservation>()))
|
||||
.ReturnsAsync(new ObservatitonRetentionResult());
|
||||
_unitServiceMock.Setup(o => o.FindById(It.IsAny<ObjectId>())).ReturnsAsync(new Unit
|
||||
{ Configuration = new UnitConfiguration { AutoAdt = true } });
|
||||
await _observationService.SaveRequest(apiRequest);
|
||||
|
||||
|
||||
_observationRepository.Verify(o => o.InsertOneAsync(It.Is<PatientObservation>(arg =>
|
||||
arg.Value == newObs.Value &&
|
||||
arg.PatientId == newObs.PatientId &&
|
||||
arg.Name == newObs.Name &&
|
||||
arg.Time == newObs.Time &&
|
||||
arg.MessageTime == newObs.MessageTime &&
|
||||
arg.CodingSystem == newObs.CodingSystem
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
_patientServiceMock.Setup(cm => cm.FindPatientByApiRequest(apiRequest)).ReturnsAsync(patient);
|
||||
_configObservationService
|
||||
.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id), false))
|
||||
.ReturnsAsync(newObs);
|
||||
_configUnitsService.Setup(o => o.Map(It.Is<PatientObservation>(arg => arg.PatientId == patient.Id)))
|
||||
.ReturnsAsync(newObs);
|
||||
_configObservationService.Setup(o => o.RetentionActions(It.IsAny<PatientObservation>()))
|
||||
.ReturnsAsync(new ObservatitonRetentionResult());
|
||||
_unitServiceMock.Setup(o => o.FindById(It.IsAny<ObjectId>())).ReturnsAsync(new Unit
|
||||
{ Configuration = new UnitConfiguration { AutoAdt = true } });
|
||||
await _observationService.SaveRequest(apiRequest);
|
||||
|
||||
|
||||
_observationRepository.Verify(o => o.InsertOneAsync(It.Is<PatientObservation>(arg =>
|
||||
arg.Value == newObs.Value &&
|
||||
arg.PatientId == newObs.PatientId &&
|
||||
arg.Name == newObs.Name &&
|
||||
arg.Time == newObs.Time &&
|
||||
arg.MessageTime == newObs.MessageTime &&
|
||||
arg.CodingSystem == newObs.CodingSystem
|
||||
)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessIntravenousLinesObservation_Return_PositionObs()
|
||||
|
||||
Reference in New Issue
Block a user