public NotificationMapper(IMigrationRepository migrationRepository, IReferenceDataRepository referenceDataRepository, IImportLogger logger, IPostcodeService postcodeService) { _migrationRepository = migrationRepository; _referenceDataRepository = referenceDataRepository; _logger = logger; _postcodeService = postcodeService; // This is a database-based value, but static from the runtime point of view, so we fetch it once here. _postMortemOutcomeType = _referenceDataRepository.GetTreatmentOutcomeForTypeAndSubType( TreatmentOutcomeType.Died, TreatmentOutcomeSubType.Unknown).Result; }
private void CalculateTreatmentOutcomes() { if (TreatmentOutcomesHelper.IsTreatmentOutcomeExpectedAtXYears(Notification, 1)) { Should12MonthOutcomeBeDisplayed = true; OutcomeAt12Months = TreatmentOutcomesHelper.GetTreatmentOutcomeAtXYears(Notification, 1); } if (TreatmentOutcomesHelper.IsTreatmentOutcomeExpectedAtXYears(Notification, 2)) { Should24MonthOutcomeBeDisplayed = true; OutcomeAt24Months = TreatmentOutcomesHelper.GetTreatmentOutcomeAtXYears(Notification, 2); } if (TreatmentOutcomesHelper.IsTreatmentOutcomeExpectedAtXYears(Notification, 3)) { Should36MonthOutcomeBeDisplayed = true; OutcomeAt36Months = TreatmentOutcomesHelper.GetTreatmentOutcomeAtXYears(Notification, 3); } }
public async Task <IActionResult> CreatePatientCondition(int patientId, [FromBody] PatientConditionForUpdateDto conditionForUpdate) { if (conditionForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new condition"); return(BadRequest(ModelState)); } var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == patientId); if (patientFromRepo == null) { return(NotFound()); } var sourceTermFromRepo = _terminologyMeddraRepository.Get(conditionForUpdate.SourceTerminologyMedDraId); if (sourceTermFromRepo == null) { ModelState.AddModelError("Message", "Unable to locate source term"); } Outcome outcomeFromRepo = null; if (!String.IsNullOrWhiteSpace(conditionForUpdate.Outcome)) { outcomeFromRepo = _outcomeRepository.Get(o => o.Description == conditionForUpdate.Outcome); if (outcomeFromRepo == null) { ModelState.AddModelError("Message", "Unable to locate outcome"); } } TreatmentOutcome treatmentOutcomeFromRepo = null; if (!String.IsNullOrWhiteSpace(conditionForUpdate.TreatmentOutcome)) { treatmentOutcomeFromRepo = _treatmentOutcomeRepository.Get(to => to.Description == conditionForUpdate.TreatmentOutcome); if (treatmentOutcomeFromRepo == null) { ModelState.AddModelError("Message", "Unable to locate treatment outcome"); } } ValidateConditionForUpdateModel(patientFromRepo, conditionForUpdate, 0); // Custom validation if (outcomeFromRepo != null && treatmentOutcomeFromRepo != null) { if (outcomeFromRepo.Description == "Fatal" && treatmentOutcomeFromRepo.Description != "Died") { ModelState.AddModelError("Message", "Treatment Outcome not consistent with Condition Outcome"); } if (outcomeFromRepo.Description != "Fatal" && treatmentOutcomeFromRepo.Description == "Died") { ModelState.AddModelError("Message", "Condition Outcome not consistent with Treatment Outcome"); } } if (ModelState.IsValid) { var conditionDetail = PrepareConditionDetail(conditionForUpdate); if (!conditionDetail.IsValid()) { conditionDetail.InvalidAttributes.ForEach(element => ModelState.AddModelError("Message", element)); } if (ModelState.IsValid) { var patientCondition = patientFromRepo.AddOrUpdatePatientCondition(0, sourceTermFromRepo, conditionForUpdate.StartDate, conditionForUpdate.OutcomeDate, outcomeFromRepo, treatmentOutcomeFromRepo, conditionForUpdate.CaseNumber, conditionForUpdate.Comments, conditionForUpdate.SourceDescription, _patientStatusRepository.Get(ps => ps.Description == "Died")); //throw new Exception(JsonConvert.SerializeObject(patientCondition)); _modelExtensionBuilder.UpdateExtendable(patientCondition, conditionDetail.CustomAttributes, "Admin"); _patientConditionRepository.Save(patientCondition); await _unitOfWork.CompleteAsync(); var mappedPatientCondition = _mapper.Map <PatientConditionIdentifierDto>(patientCondition); if (mappedPatientCondition == null) { return(StatusCode(500, "Unable to locate newly added condition")); } return(CreatedAtAction("GetPatientConditionByIdentifier", new { id = mappedPatientCondition.Id }, CreateLinksForPatientCondition <PatientConditionIdentifierDto>(mappedPatientCondition))); } } return(BadRequest(ModelState)); }
public async Task <bool> Handle(ChangeConditionDetailsCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] { "PatientConditions.TerminologyMedDra", "PatientStatusHistories.PatientStatus" }); if (patientFromRepo == null) { throw new KeyNotFoundException("Unable to locate patient"); } var sourceTerminologyFromRepo = _terminologyMeddraRepository.Get(message.SourceTerminologyMedDraId); if (sourceTerminologyFromRepo == null) { throw new KeyNotFoundException("Unable to locate source terminology"); } Outcome outcomeFromRepo = null; if (!String.IsNullOrWhiteSpace(message.Outcome)) { outcomeFromRepo = _outcomeRepository.Get(o => o.Description == message.Outcome); if (outcomeFromRepo == null) { throw new KeyNotFoundException("Unable to locate outcome"); } } TreatmentOutcome treatmentOutcomeFromRepo = null; if (!String.IsNullOrWhiteSpace(message.TreatmentOutcome)) { treatmentOutcomeFromRepo = _treatmentOutcomeRepository.Get(to => to.Description == message.TreatmentOutcome); if (treatmentOutcomeFromRepo == null) { throw new KeyNotFoundException("Unable to locate treatment outcome"); } } if (outcomeFromRepo != null && treatmentOutcomeFromRepo != null) { if (outcomeFromRepo.Description == "Fatal" && treatmentOutcomeFromRepo.Description != "Died") { throw new DomainException("Treatment Outcome not consistent with Condition Outcome"); } if (outcomeFromRepo.Description != "Fatal" && treatmentOutcomeFromRepo.Description == "Died") { throw new DomainException("Condition Outcome not consistent with Treatment Outcome"); } } var conditionDetail = await PrepareConditionDetailAsync(message.Attributes); if (!conditionDetail.IsValid()) { conditionDetail.InvalidAttributes.ForEach(element => throw new DomainException(element)); } patientFromRepo.ChangeConditionDetails(message.PatientConditionId, message.SourceTerminologyMedDraId, message.StartDate, message.OutcomeDate, outcomeFromRepo, treatmentOutcomeFromRepo, message.CaseNumber, message.Comments); _modelExtensionBuilder.UpdateExtendable(patientFromRepo.PatientConditions.Single(pm => pm.Id == message.PatientConditionId), conditionDetail.CustomAttributes, "Admin"); if (outcomeFromRepo?.Description == "Fatal" && patientFromRepo.GetCurrentStatus().PatientStatus.Description != "Died") { var patientStatus = await _patientStatusRepository.GetAsync(ps => ps.Description == "Died"); patientFromRepo.ChangePatientStatus(patientStatus, message.OutcomeDate ?? DateTime.Now, $"Marked as deceased through condition ({sourceTerminologyFromRepo.DisplayName})"); } _patientRepository.Update(patientFromRepo); _logger.LogInformation($"----- Condition {message.PatientConditionId} details updated"); return(await _unitOfWork.CompleteAsync()); }