public async Task MigrationOutcomeEventMappedCorrectlyWithNoTbServiceOrCaseManagerAdded() { // Arrange GivenLegacyUserWithName("*****@*****.**", "Milicent", "Davis"); var migrationTransferEvent = new MigrationDbOutcomeEvent { EventDate = DateTime.Parse("12/12/2012"), NtbsHospitalId = new Guid("B8AA918D-233F-4C41-B9AE-BE8A8DC8BE7B"), TreatmentEventType = "TransferIn", TreatmentOutcomeId = 2, Note = "The patient had a specific outcome" }; var allOutcomes = ntbs_service.Models.SeedData.TreatmentOutcomes.GetTreatmentOutcomes().ToList(); // Act var mappedEvent = await _treatmentEventMapper.AsOutcomeEvent(migrationTransferEvent, allOutcomes, null, 1); // Assert Assert.Equal(DateTime.Parse("12/12/2012"), mappedEvent.EventDate); Assert.Equal(TreatmentEventType.TransferIn, mappedEvent.TreatmentEventType); Assert.Equal("The patient had a specific outcome", mappedEvent.Note); Assert.Equal(2, mappedEvent.TreatmentOutcomeId); Assert.Null(mappedEvent.TbServiceCode); Assert.Null(mappedEvent.CaseManagerId); }
private async Task <TreatmentEvent> AsOutcomeEvent(MigrationDbOutcomeEvent rawEvent) { var ev = new TreatmentEvent(); ev.EventDate = rawEvent.EventDate; ev.TreatmentEventType = Converter.GetEnumValue <TreatmentEventType>(rawEvent.TreatmentEventType); ev.TreatmentOutcomeId = rawEvent.TreatmentOutcomeId; ev.CaseManagerUsername = rawEvent.CaseManager; ev.Note = rawEvent.Note; // ReSharper disable once InvertIf if (rawEvent.NtbsHospitalId is Guid guid) { var tbService = (await _referenceDataRepository.GetTbServiceFromHospitalIdAsync(guid)); if (tbService == null) { Log.Warning( $"No TB service exists for hospital with guid {guid} - treatment event recorded without a service"); } else { ev.TbServiceCode = tbService.Code; } } return(ev); }
public async Task <TreatmentEvent> AsOutcomeEvent(MigrationDbOutcomeEvent rawEvent, List <TreatmentOutcome> allOutcomes, PerformContext context, int runId) { var ev = new TreatmentEvent { EventDate = rawEvent.EventDate, TreatmentEventType = Converter.GetEnumValue <TreatmentEventType>(rawEvent.TreatmentEventType), TreatmentOutcomeId = rawEvent.TreatmentOutcomeId, TreatmentOutcome = allOutcomes.SingleOrDefault(o => o.TreatmentOutcomeId == rawEvent.TreatmentOutcomeId), Note = rawEvent.Note }; await TryAddTbServiceAndCaseManagerToTreatmentEvent(ev, rawEvent.NtbsHospitalId, rawEvent.CaseManager, context, runId); return(ev); }