protected override async Task ValidateAndSave() { if (MDRDetails.CountryId != null) { MDRDetails.Country = await _referenceDataRepository.GetCountryByIdAsync((int)MDRDetails.CountryId); } UpdateFlags(); ValidateRelatedNotificationId(); ValidationService.TrySetFormattedDate(MDRDetails, "MDRDetails", nameof(MDRDetails.MDRTreatmentStartDate), FormattedMdrTreatmentDate); MDRDetails.DatesHaveBeenSet = true; // Add additional field required for date validation MDRDetails.Dob = Notification.PatientDetails.Dob; MDRDetails.SetValidationContext(Notification); if (TryValidateModel(MDRDetails, nameof(MDRDetails))) { await Service.UpdateMDRDetailsAsync(Notification, MDRDetails); await _enhancedSurveillanceAlertsService.CreateOrDismissMdrAlert(Notification); } }
public async Task UpdateDrugResistanceProfiles() { var drugResistanceProfiles = await _drugResistanceProfileRepository.GetDrugResistanceProfilesAsync(); foreach (var(notificationId, drugResistanceProfile) in drugResistanceProfiles) { var notification = await _notificationRepository.GetNotificationAsync(notificationId); if (notification == null) { throw new DataException( $"Reporting database sourced NotificationId {notificationId} was not found in NTBS database."); } if (notification.DrugResistanceProfile.Species == drugResistanceProfile.Species && notification.DrugResistanceProfile.DrugResistanceProfileString == drugResistanceProfile.DrugResistanceProfileString) { continue; } await _notificationService.UpdateDrugResistanceProfileAsync(notification, drugResistanceProfile); await _enhancedSurveillanceAlertsService.CreateOrDismissMdrAlert(notification); await _enhancedSurveillanceAlertsService.CreateOrDismissMBovisAlert(notification); } }
protected override async Task ValidateAndSave() { UpdateFlags(); SetDatesOnClinicalDetails(); if (ClinicalDetails.BCGVaccinationYear != null) { ValidationService.ValidateYearComparison(ClinicalDetails, nameof(ClinicalDetails.BCGVaccinationYear), (int)ClinicalDetails.BCGVaccinationYear, PatientBirthYear); } var notificationSites = CreateNotificationSitesFromModel(Notification).ToList(); // Add additional field required for date validation ClinicalDetails.Dob = Notification.PatientDetails.Dob; ClinicalDetails.SetValidationContext(Notification); OtherSite?.SetValidationContext(Notification); // Since notification has other properties which are not populated by this page but have validation rules, // validation of a whole Notification model will result in validation errors. // Therefore we need to manually validate NotificationSites and TryValidate other models if (Notification.ShouldValidateFull && !notificationSites.Any()) { ModelState.AddModelError("Notification.NotificationSites", ValidationMessages.DiseaseSiteIsRequired); } TryValidateModel(ClinicalDetails, nameof(ClinicalDetails)); if (OtherSite != null) { TryValidateModel(OtherSite, nameof(OtherSite)); } var mdrChanged = Notification.ClinicalDetails.TreatmentRegimen != ClinicalDetails.TreatmentRegimen; var nonMdrNotAllowed = !ClinicalDetails.IsMDRTreatment && Notification.MdrDetailsEntered; if (mdrChanged && nonMdrNotAllowed) { ModelState.AddModelError("ClinicalDetails.IsMDRTreatment", ValidationMessages.MDRCantChange); } AddPostMortemErrorsIfApplicable(); if (ModelState.IsValid) { await Service.UpdateClinicalDetailsAsync(Notification, ClinicalDetails); await Service.UpdateSitesAsync(Notification.NotificationId, notificationSites); if (mdrChanged) { await _enhancedSurveillanceAlertsService.CreateOrDismissMdrAlert(Notification); } } }
protected override async Task ValidateAndSave() { UpdateFlags(); new List <(string key, FormattedDate date)> { (nameof(ClinicalDetails.SymptomStartDate), FormattedSymptomDate), (nameof(ClinicalDetails.FirstPresentationDate), FormattedFirstPresentationDate), (nameof(ClinicalDetails.TBServicePresentationDate), FormattedTbServicePresentationDate), (nameof(ClinicalDetails.DiagnosisDate), FormattedDiagnosisDate), (nameof(ClinicalDetails.TreatmentStartDate), FormattedTreatmentDate), (nameof(ClinicalDetails.FirstHomeVisitDate), FormattedHomeVisitDate), (nameof(ClinicalDetails.MDRTreatmentStartDate), FormattedMdrTreatmentDate) }.ForEach(item => ValidationService.TrySetFormattedDate(ClinicalDetails, "ClinicalDetails", item.key, item.date) ); if (ClinicalDetails.BCGVaccinationYear != null) { ValidationService.ValidateYearComparison(ClinicalDetails, nameof(ClinicalDetails.BCGVaccinationYear), (int)ClinicalDetails.BCGVaccinationYear, PatientBirthYear); } var notificationSites = CreateNotificationSitesFromModel(Notification).ToList(); // Add additional field required for date validation ClinicalDetails.Dob = Notification.PatientDetails.Dob; ClinicalDetails.SetValidationContext(Notification); OtherSite?.SetValidationContext(Notification); // Since notification has other properties which are not populated by this page but have validation rules, // validation of a whole Notification model will result in validation errors. // Therefore we need to manually validate NotificationSites and TryValidate other models if (Notification.ShouldValidateFull && !notificationSites.Any()) { ModelState.AddModelError("Notification.NotificationSites", ValidationMessages.DiseaseSiteIsRequired); } TryValidateModel(ClinicalDetails, nameof(ClinicalDetails)); if (OtherSite != null) { TryValidateModel(OtherSite, nameof(OtherSite)); } var mdrChanged = Notification.ClinicalDetails.TreatmentRegimen != ClinicalDetails.TreatmentRegimen; var nonMdrNotAllowed = !ClinicalDetails.IsMDRTreatment && Notification.MDRDetails.MDRDetailsEntered; if (mdrChanged && nonMdrNotAllowed) { ModelState.AddModelError("ClinicalDetails.IsMDRTreatment", ValidationMessages.MDRCantChange); } if (ModelState.IsValid) { await Service.UpdateClinicalDetailsAsync(Notification, ClinicalDetails); await Service.UpdateSitesAsync(Notification.NotificationId, notificationSites); if (mdrChanged) { await _enhancedSurveillanceAlertsService.CreateOrDismissMdrAlert(Notification); } } }