public async Task AddOrUpdateMedicationsForWorkFlowInstanceAsync(Guid contextGuid, List <ReportInstanceMedicationListItem> medications) { if (medications == null) { throw new ArgumentNullException(nameof(medications)); } if (medications.Count == 0) { return; } ; var reportInstance = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == contextGuid, new string[] { "Medications" }); if (reportInstance == null) { return; } ; foreach (ReportInstanceMedicationListItem medication in medications) { if (reportInstance.HasMedication(medication.ReportInstanceMedicationGuid)) { reportInstance.SetMedicationIdentifier(medication.ReportInstanceMedicationGuid, medication.MedicationIdentifier); } else { reportInstance.AddMedication(medication.MedicationIdentifier, medication.ReportInstanceMedicationGuid); } } _reportInstanceRepository.Update(reportInstance); await _unitOfWork.CompleteAsync(); }
public async Task <IActionResult> UpdatePatientDeenrolment(long patientId, long cohortGroupEnrolmentId, [FromBody] DeenrolmentForUpdateDto deenrolmentForUpdateDto) { if (deenrolmentForUpdateDto == null) { ModelState.AddModelError("Message", "De-enrolment payload not populated"); return(BadRequest(ModelState)); } var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == patientId); if (patientFromRepo == null) { ModelState.AddModelError("Message", "Unable to locate patient record"); return(BadRequest(ModelState)); } var enrolmentFromRepo = await _cohortGroupEnrolmentRepository.GetAsync(f => f.Id == cohortGroupEnrolmentId); if (enrolmentFromRepo == null) { ModelState.AddModelError("Message", "Unable to locate enrolment record"); return(BadRequest(ModelState)); } var deenroledDate = deenrolmentForUpdateDto.DeenroledDate.AddDays(1).Date; if (deenroledDate > DateTime.Today) { ModelState.AddModelError("Message", "De-enrolment Date should be less than or the same date as today"); return(BadRequest(ModelState)); } if (deenroledDate < enrolmentFromRepo.EnroledDate.Date) { ModelState.AddModelError("Message", "De-enrolment Date should be after or the same date as the enrolment date"); return(BadRequest(ModelState)); } if (ModelState.IsValid) { enrolmentFromRepo.DeenroledDate = deenroledDate; _cohortGroupEnrolmentRepository.Update(enrolmentFromRepo); await _unitOfWork.CompleteAsync(); } return(CreatedAtAction("GetPatientEnrolmentByIdentifier", new { patientId, id = enrolmentFromRepo.Id }, CreateLinksForEnrolment <EnrolmentIdentifierDto>(patientId, _mapper.Map <EnrolmentIdentifierDto>(enrolmentFromRepo)))); }
public async Task <bool> Handle(ChangeCohortGroupDetailsCommand message, CancellationToken cancellationToken) { var cohortGroupFromRepo = await _cohortGroupRepository.GetAsync(cg => cg.Id == message.Id); if (cohortGroupFromRepo == null) { throw new KeyNotFoundException("Unable to locate cohort group"); } var conditionFromRepo = await _conditionRepository.GetAsync(c => c.Description == message.ConditionName); if (conditionFromRepo == null) { throw new KeyNotFoundException("Unable to locate condition"); } if (_cohortGroupRepository.Exists(l => (l.CohortName == message.CohortName || l.CohortCode == message.CohortCode) && l.Id != message.Id)) { throw new DomainException("Item with same name already exists"); } cohortGroupFromRepo.ChangeDetails(message.CohortName, message.CohortCode, conditionFromRepo, message.StartDate, message.FinishDate); _cohortGroupRepository.Update(cohortGroupFromRepo); _logger.LogInformation($"----- Cohort group {message.CohortName} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <IActionResult> UpdateHoliday(long id, [FromBody] HolidayForUpdateDto holidayForUpdate) { if (holidayForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <Holiday>().Queryable(). Where(l => l.HolidayDate == holidayForUpdate.HolidayDate && l.Id != id) .Count() > 0) { ModelState.AddModelError("Message", "A holiday has already been loaded for this date"); return(BadRequest(ModelState)); } var holidayFromRepo = await _holidayRepository.GetAsync(f => f.Id == id); if (holidayFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { holidayFromRepo.HolidayDate = holidayForUpdate.HolidayDate; holidayFromRepo.Description = holidayForUpdate.Description; _holidayRepository.Update(holidayFromRepo); await _unitOfWork.CompleteAsync(); } return(Ok()); }
public async Task <bool> Handle(RemoveFacilityFromUserCommand message, CancellationToken cancellationToken) { var userFromRepo = await _userRepository.GetAsync(u => u.Id == message.UserId, new string[] { "Facilities.Facility" }); if (userFromRepo == null) { throw new KeyNotFoundException("Unable to locate user"); } var facilityFromRepo = await _facilityRepository.GetAsync(message.FacilityId, new string[] { "" }); if (facilityFromRepo == null) { throw new KeyNotFoundException($"Unable to locate facility {message.FacilityId}"); } userFromRepo.RemoveFacility(facilityFromRepo); _userRepository.Update(userFromRepo); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- User {userFromRepo.Id} facilities updated"); return(true); }
public async Task <bool> Handle(ChangeMedicationDetailsCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] { "PatientClinicalEvents", "PatientMedications.Concept.MedicationForm", "PatientMedications.Product" }); if (patientFromRepo == null) { throw new KeyNotFoundException("Unable to locate patient"); } var medicationToUpdate = patientFromRepo.PatientMedications.Single(pm => pm.Id == message.PatientMedicationId); var medicationAttributes = await PrepareMedicationAttributesWithNewValuesAsync(medicationToUpdate, message.Attributes); var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; patientFromRepo.ChangeMedicationDetails(message.PatientMedicationId, message.StartDate, message.EndDate, message.Dose, message.DoseFrequency, message.DoseUnit); _modelExtensionBuilder.ValidateAndUpdateExtendable(medicationToUpdate, medicationAttributes, userName); _patientRepository.Update(patientFromRepo); await RefreshMedicationOnMatchingReportInstancesAsync(patientFromRepo, message.StartDate, message.EndDate, patientFromRepo.PatientMedications.Single(pm => pm.Id == message.PatientMedicationId).DisplayName, patientFromRepo.PatientMedications.Single(pm => pm.Id == message.PatientMedicationId).PatientMedicationGuid); _logger.LogInformation($"----- Medication {message.PatientMedicationId} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <bool> Handle(ChangeProductDetailsCommand message, CancellationToken cancellationToken) { var conceptFromRepo = await _conceptRepository.GetAsync(c => c.ConceptName + "; " + c.Strength + " (" + c.MedicationForm.Description + ")" == message.ConceptName, new string[] { "Products" }); if (conceptFromRepo == null) { throw new KeyNotFoundException($"Unable to locate concept {message.ConceptName}"); } if (_productRepository.Exists(p => p.ConceptId == conceptFromRepo.Id && p.ProductName == message.ProductName && p.Id != message.ProductId)) { throw new DomainException("Product with same name annd concept already exists"); } conceptFromRepo.ChangeProductDetails(message.ProductId, message.ProductName, message.Manufacturer, message.Description); if (message.Active) { conceptFromRepo.MarkProductAsActive(message.ProductId); } else { conceptFromRepo.MarkProductAsInActive(message.ProductId); } _conceptRepository.Update(conceptFromRepo); _logger.LogInformation($"----- Product {message.ProductId} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <IActionResult> UpdateLabResult(long id, [FromBody] LabResultForUpdateDto labResultForUpdate) { if (labResultForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <LabResult>().Queryable(). Where(l => l.Description == labResultForUpdate.LabResultName && l.Id != id) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } var labResultFromRepo = await _labResultRepository.GetAsync(f => f.Id == id); if (labResultFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { labResultFromRepo.Description = labResultForUpdate.LabResultName; labResultFromRepo.Active = (labResultForUpdate.Active == Models.ValueTypes.YesNoValueType.Yes); _labResultRepository.Update(labResultFromRepo); await _unitOfWork.CompleteAsync(); } return(Ok()); }
public async Task <bool> Handle(ChangeReportClassificationCommand message, CancellationToken cancellationToken) { var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid && ri.Id == message.ReportInstanceId, new string[] { "" }); if (reportInstanceFromRepo == null) { throw new KeyNotFoundException("Unable to locate report instance"); } if (await _workFlowService.ValidateExecutionStatusForCurrentActivityAsync(reportInstanceFromRepo.ContextGuid, "CLASSIFICATIONSET") == false) { throw new DomainException($"Activity CLASSIFICATIONSET not valid for workflow"); } reportInstanceFromRepo.ChangeClassification(message.ReportClassification); _reportInstanceRepository.Update(reportInstanceFromRepo); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- Report {reportInstanceFromRepo.Id} classification updated"); await _workFlowService.ExecuteActivityAsync(reportInstanceFromRepo.ContextGuid, "CLASSIFICATIONSET", $"AUTOMATION: Classification set to {message.ReportClassification}", null, ""); return(true); }
public async Task <ProductIdentifierDto> Handle(AddProductCommand message, CancellationToken cancellationToken) { var conceptFromRepo = await _conceptRepository.GetAsync(c => c.ConceptName + "; " + c.Strength + " (" + c.MedicationForm.Description + ")" == message.ConceptName); if (conceptFromRepo == null) { throw new KeyNotFoundException($"Unable to locate concept {message.ConceptName}"); } if (_productRepository.Exists(p => p.ConceptId == conceptFromRepo.Id && p.ProductName == message.ProductName)) { throw new DomainException("Product with same name annd concept already exists"); } var newProduct = conceptFromRepo.AddProduct(message.ProductName, message.Manufacturer, message.Description); _conceptRepository.Update(conceptFromRepo); _logger.LogInformation($"----- Product {message.ProductName} created"); await _unitOfWork.CompleteAsync(); var mappedProduct = _mapper.Map <ProductIdentifierDto>(newProduct); CreateLinks(mappedProduct); return(mappedProduct); }
public async Task <bool> Handle(ChangeReportTerminologyCommand message, CancellationToken cancellationToken) { var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid && ri.Id == message.ReportInstanceId, new string[] { "" }); if (reportInstanceFromRepo == null) { throw new KeyNotFoundException("Unable to locate report instance"); } var terminologyFromRepo = _terminologyMeddraRepository.Get(message.TerminologyMedDraId); if (terminologyFromRepo == null) { throw new KeyNotFoundException("Unable to locate terminology"); } if (await _workFlowService.ValidateExecutionStatusForCurrentActivityAsync(reportInstanceFromRepo.ContextGuid, "MEDDRASET") == false) { throw new DomainException($"Activity MEDDRASET not valid for workflow"); } reportInstanceFromRepo.ChangeTerminology(terminologyFromRepo); _reportInstanceRepository.Update(reportInstanceFromRepo); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- Report {reportInstanceFromRepo.Id} terminology updated"); await _workFlowService.ExecuteActivityAsync(reportInstanceFromRepo.ContextGuid, "MEDDRASET", $"AUTOMATION: MedDRA Term set to {terminologyFromRepo.DisplayName}", null, ""); return(true); }
public async Task <IActionResult> UpdateConfig(long id, [FromBody] ConfigForUpdateDto configForUpdate) { if (configForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } var configFromRepo = await _configRepository.GetAsync(f => f.Id == id); if (configFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { configFromRepo.ConfigValue = String.IsNullOrWhiteSpace(configForUpdate.ConfigValue) ? "-- not specified --" : configForUpdate.ConfigValue; _configRepository.Update(configFromRepo); await _unitOfWork.CompleteAsync(); } return(Ok()); }
public async Task <PatientClinicalEventIdentifierDto> Handle(AddClinicalEventToPatientCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] { "PatientClinicalEvents.SourceTerminologyMedDra", "PatientMedications.Concept", "PatientFacilities.Facility" }); if (patientFromRepo == null) { throw new KeyNotFoundException("Unable to locate patient"); } TerminologyMedDra sourceTermFromRepo = null; if (message.SourceTerminologyMedDraId.HasValue) { if (message.SourceTerminologyMedDraId > 0) { sourceTermFromRepo = await _terminologyMeddraRepository.GetAsync(message.SourceTerminologyMedDraId);; if (sourceTermFromRepo == null) { throw new KeyNotFoundException("Unable to locate terminology for MedDRA"); } } } var clinicalEventDetail = await PrepareClinicalEventDetailAsync(message.Attributes); if (!clinicalEventDetail.IsValid()) { clinicalEventDetail.InvalidAttributes.ForEach(element => throw new DomainException(element)); } var newPatientClinicalEvent = patientFromRepo.AddClinicalEvent(message.OnsetDate, message.ResolutionDate, sourceTermFromRepo, message.SourceDescription); _modelExtensionBuilder.UpdateExtendable(newPatientClinicalEvent, clinicalEventDetail.CustomAttributes, "Admin"); _patientRepository.Update(patientFromRepo); // TODO Move to domain event await _workFlowService.CreateWorkFlowInstanceAsync( workFlowName : "New Active Surveilliance Report", contextGuid : newPatientClinicalEvent.PatientClinicalEventGuid, patientIdentifier : String.IsNullOrWhiteSpace(message.PatientIdentifier)?patientFromRepo.FullName : $"{patientFromRepo.FullName} ({message.PatientIdentifier})", sourceIdentifier : newPatientClinicalEvent.SourceTerminologyMedDra?.DisplayName ?? newPatientClinicalEvent.SourceDescription, facilityIdentifier : patientFromRepo.CurrentFacilityCode); await LinkMedicationsToClinicalEvent(patientFromRepo, newPatientClinicalEvent.OnsetDate, newPatientClinicalEvent.PatientClinicalEventGuid); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- Clinical Event {message.SourceDescription} created"); var mappedPatientClinicalEvent = _mapper.Map <PatientClinicalEventIdentifierDto>(newPatientClinicalEvent); return(CreateLinks(mappedPatientClinicalEvent)); }
public async Task <IActionResult> UpdateCondition(int id, [FromBody] ConditionForUpdateDto conditionForUpdate) { if (conditionForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); } if (Regex.Matches(conditionForUpdate.ConditionName, @"[a-zA-Z0-9 ]").Count < conditionForUpdate.ConditionName.Length) { ModelState.AddModelError("Message", "Condition contains invalid characters (Enter A-Z, a-z, 0-9, space)"); return(BadRequest(ModelState)); } if (conditionForUpdate.ConditionMedDras.Count == 0) { ModelState.AddModelError("Message", "Condition must contain at least one MedDra term"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <Condition>().Queryable(). Where(l => l.Description == conditionForUpdate.ConditionName && l.Id != id) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); } var conditionFromRepo = await _conditionRepository.GetAsync(f => f.Id == id); if (conditionFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { conditionFromRepo.Description = conditionForUpdate.ConditionName; conditionFromRepo.Chronic = (conditionForUpdate.Chronic == Models.ValueTypes.YesNoValueType.Yes); conditionFromRepo.Active = (conditionForUpdate.Active == Models.ValueTypes.YesNoValueType.Yes); _conditionRepository.Update(conditionFromRepo); AddOrUpdateConditionLabTests(conditionForUpdate, conditionFromRepo); AddOrUpdateConditionMeddras(conditionForUpdate, conditionFromRepo); AddOrUpdateConditionMedications(conditionForUpdate, conditionFromRepo); await _unitOfWork.CompleteAsync(); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <IActionResult> ArchiveEncounter(long patientId, long id, [FromBody] ArchiveDto encounterForDelete) { var encounterFromRepo = await _encounterRepository.GetAsync(e => e.Patient.Id == patientId && e.Id == id); if (encounterFromRepo == null) { return(NotFound()); } if (Regex.Matches(encounterForDelete.Reason, @"[-a-zA-Z0-9 .']").Count < encounterForDelete.Reason.Length) { ModelState.AddModelError("Message", "Reason contains invalid characters (Enter A-Z, a-z, space, period, apostrophe)"); } var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = _userRepository.Get(u => u.UserName == userName); if (user == null) { ModelState.AddModelError("Message", "Unable to locate user"); } if (ModelState.IsValid) { foreach (var attachment in encounterFromRepo.Attachments.Where(x => !x.Archived)) { attachment.ArchiveAttachment(user, encounterForDelete.Reason); _attachmentRepository.Update(attachment); } foreach (var patientClinicalEvent in encounterFromRepo.PatientClinicalEvents.Where(x => !x.Archived)) { patientClinicalEvent.Archive(user, encounterForDelete.Reason); _patientClinicalEventRepository.Update(patientClinicalEvent); } encounterFromRepo.Archived = true; encounterFromRepo.ArchivedDate = DateTime.Now; encounterFromRepo.ArchivedReason = encounterForDelete.Reason; encounterFromRepo.AuditUser = user; _encounterRepository.Update(encounterFromRepo); await _unitOfWork.CompleteAsync(); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <bool> Handle(ChangePatientDateOfBirthCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId); if (patientFromRepo == null) { throw new KeyNotFoundException("Unable to locate patient"); } patientFromRepo.ChangePatientDateOfBirth(message.DateOfBirth); _patientRepository.Update(patientFromRepo); _logger.LogInformation($"----- Patient {message.PatientId} date of birth details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <bool> Handle(ChangeContactDetailsCommand message, CancellationToken cancellationToken) { var siteContactDetailFromRepo = await _siteContactDetailRepository.GetAsync(s => s.Id == message.Id); if (siteContactDetailFromRepo == null) { throw new KeyNotFoundException("Unable to locate contact detail"); } siteContactDetailFromRepo.ChangeDetails(message.OrganisationType, message.OrganisationName, message.DepartmentName, message.ContactFirstName, message.ContactSurname, message.StreetAddress, message.City, message.State, message.PostCode, message.CountryCode, message.ContactNumber, message.ContactEmail); _siteContactDetailRepository.Update(siteContactDetailFromRepo); _logger.LogInformation($"----- Contact detail {message.Id} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <bool> Handle(ChangePatientNameCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] { "PatientClinicalEvents.SourceTerminologyMedDra", "PatientConditions.TerminologyMedDra.ConditionMedDras.Condition" }); patientFromRepo.ChangePatientName(message.FirstName, message.MiddleName, message.LastName); _patientRepository.Update(patientFromRepo); // TODO Move to domain event await UpdateReportInstanceIdentifiers(patientFromRepo); _logger.LogInformation($"----- Patient {message.PatientId} name details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <bool> Handle(ChangeTaskDetailsCommand message, CancellationToken cancellationToken) { var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid && ri.Id == message.ReportInstanceId, new string[] { "Tasks" }); if (reportInstanceFromRepo == null) { throw new KeyNotFoundException("Unable to locate report instance"); } reportInstanceFromRepo.ChangeTaskDetails(message.ReportInstanceTaskId, message.Source, message.Description); _reportInstanceRepository.Update(reportInstanceFromRepo); _logger.LogInformation($"----- Task {message.Source} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <IActionResult> ArchivePatientCondition(long patientId, long id, [FromBody] ArchiveDto conditionForDelete) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == patientId); if (patientFromRepo == null) { return(NotFound()); } var conditionFromRepo = await _patientConditionRepository.GetAsync(f => f.Patient.Id == patientId && f.Id == id); if (conditionFromRepo == null) { return(NotFound()); } if (Regex.Matches(conditionForDelete.Reason, @"[-a-zA-Z0-9 .']").Count < conditionForDelete.Reason.Length) { ModelState.AddModelError("Message", "Reason contains invalid characters (Enter A-Z, a-z, space, period, apostrophe)"); } var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = _userRepository.Get(u => u.UserName == userName); if (user == null) { ModelState.AddModelError("Message", "Unable to locate user"); } if (ModelState.IsValid) { conditionFromRepo.Archived = true; conditionFromRepo.ArchivedDate = DateTime.Now; conditionFromRepo.ArchivedReason = conditionForDelete.Reason; conditionFromRepo.AuditUser = user; _patientConditionRepository.Update(conditionFromRepo); await _unitOfWork.CompleteAsync(); return(Ok()); } return(BadRequest(ModelState)); }
public async Task <bool> Handle(ChangeFacilityDetailsCommand message, CancellationToken cancellationToken) { var facilityFromRepo = await _facilityRepository.GetAsync(f => f.Id == message.Id); if (facilityFromRepo == null) { throw new KeyNotFoundException("Unable to locate facility"); } var facilityTypeFromRepo = await _facilityTypeRepository.GetAsync(c => c.Description == message.FacilityType); if (facilityTypeFromRepo == null) { throw new KeyNotFoundException("Unable to locate facility type"); } OrgUnit orgUnitFromRepo = null; if (message.OrgUnitId.HasValue) { if (message.OrgUnitId > 0) { orgUnitFromRepo = await _orgUnitRepository.GetAsync(message.OrgUnitId); if (orgUnitFromRepo == null) { throw new KeyNotFoundException($"Unable to locate organisation unit {message.OrgUnitId}"); } } } if (_facilityRepository.Exists(l => (l.FacilityName == message.FacilityName || l.FacilityCode == message.FacilityCode) && l.Id != message.Id)) { throw new DomainException("Item with same name already exists"); } facilityFromRepo.ChangeDetails(message.FacilityName, message.FacilityCode, facilityTypeFromRepo, message.TelNumber, message.MobileNumber, message.FaxNumber, orgUnitFromRepo); _facilityRepository.Update(facilityFromRepo); _logger.LogInformation($"----- Facility {message.FacilityName} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <bool> Handle(AcceptEulaCommand message, CancellationToken cancellationToken) { var userFromRepo = await _userRepository.GetAsync(u => u.Id == message.UserId, new string[] { "" }); if (userFromRepo == null) { throw new KeyNotFoundException("Unable to locate user"); } userFromRepo.AcceptEula(); _userRepository.Update(userFromRepo); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- User {userFromRepo.Id} EULA accepted"); return(true); }
public async Task UpdateCustomAttributeAsync(CustomAttributeConfigDetail customAttribute) { var updateCustomAttribute = _unitOfWork.Repository <CustomAttributeConfiguration>().Queryable().Single(ca => ca.ExtendableTypeName == customAttribute.EntityName && ca.AttributeKey == customAttribute.AttributeName); updateCustomAttribute.Category = customAttribute.Category; updateCustomAttribute.AttributeDetail = customAttribute.AttributeDetail; updateCustomAttribute.IsRequired = customAttribute.Required; updateCustomAttribute.IsSearchable = customAttribute.Searchable; switch (updateCustomAttribute.CustomAttributeType) { case CustomAttributeType.Numeric: if (customAttribute.NumericMinValue.HasValue) { updateCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value; } if (customAttribute.NumericMaxValue.HasValue) { updateCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value; } break; case CustomAttributeType.String: if (customAttribute.StringMaxLength.HasValue) { updateCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value; } break; case CustomAttributeType.DateTime: updateCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly; updateCustomAttribute.PastDateOnly = customAttribute.PastDateOnly; break; default: break; } _customAttributeConfigRepository.Update(updateCustomAttribute); await _unitOfWork.CompleteAsync(); }
public async Task <bool> Handle(ChangeReportMedicationCausalityCommand message, CancellationToken cancellationToken) { var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid && ri.Id == message.ReportInstanceId, new string[] { "Medications" }); if (reportInstanceFromRepo == null) { throw new KeyNotFoundException("Unable to locate report instance"); } var reportInstanceMedicationFromRepo = reportInstanceFromRepo.Medications.SingleOrDefault(m => m.Id == message.ReportInstanceMedicationId); if (reportInstanceMedicationFromRepo == null) { throw new KeyNotFoundException("Unable to locate report instance medication"); } if (await _workFlowService.ValidateExecutionStatusForCurrentActivityAsync(reportInstanceFromRepo.ContextGuid, "CAUSALITYSET") == false) { throw new DomainException($"Activity CAUSALITYSET not valid for workflow"); } if (message.CausalityConfigType == CausalityConfigType.NaranjoScale) { reportInstanceFromRepo.ChangeMedicationNaranjoCausality(message.ReportInstanceMedicationId, message.Causality); } if (message.CausalityConfigType == CausalityConfigType.WHOScale) { reportInstanceFromRepo.ChangeMedicationWhoCausality(message.ReportInstanceMedicationId, message.Causality); } _reportInstanceRepository.Update(reportInstanceFromRepo); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"----- Report {reportInstanceFromRepo.Id} classification updated"); await _workFlowService.ExecuteActivityAsync(reportInstanceFromRepo.ContextGuid, "CAUSALITYSET", $"AUTOMATION: Causality set for {reportInstanceMedicationFromRepo.MedicationIdentifier} to {message.Causality}", null, ""); return(true); }
public async Task <bool> Handle(ChangeClinicalEventDetailsCommand message, CancellationToken cancellationToken) { var patientFromRepo = await _patientRepository.GetAsync(f => f.Id == message.PatientId, new string[] { "PatientClinicalEvents.SourceTerminologyMedDra", "PatientConditions.TerminologyMedDra.ConditionMedDras.Condition" }); if (patientFromRepo == null) { throw new KeyNotFoundException("Unable to locate patient"); } TerminologyMedDra sourceTermFromRepo = null; if (message.SourceTerminologyMedDraId.HasValue) { sourceTermFromRepo = await _terminologyMeddraRepository.GetAsync(message.SourceTerminologyMedDraId);; if (sourceTermFromRepo == null) { throw new KeyNotFoundException("Unable to locate terminology for MedDRA"); } } var clinicalEventToUpdate = patientFromRepo.PatientClinicalEvents.Single(pce => pce.Id == message.PatientClinicalEventId); var clinicalEventAttributes = await PrepareClinicalEventAttributesWithNewValuesAsync(clinicalEventToUpdate, message.Attributes); var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; patientFromRepo.ChangeClinicalEventDetails(message.PatientClinicalEventId, message.OnsetDate, message.ResolutionDate, sourceTermFromRepo, message.SourceDescription); _modelExtensionBuilder.ValidateAndUpdateExtendable(clinicalEventToUpdate, clinicalEventAttributes, userName); _patientRepository.Update(patientFromRepo); // TODO Move to domain event await UpdateReportInstanceIdentifiers(patientFromRepo, clinicalEventToUpdate); _logger.LogInformation($"----- Clinical Event {message.PatientClinicalEventId} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <IActionResult> UpdateEncounterType(long id, [FromBody] EncounterTypeForUpdateDto encounterTypeForUpdate) { if (encounterTypeForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (Regex.Matches(encounterTypeForUpdate.EncounterTypeName, @"[a-zA-Z ']").Count < encounterTypeForUpdate.EncounterTypeName.Length) { ModelState.AddModelError("Message", "EncounterType name contains invalid characters (Enter A-Z, a-z, space)"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <EncounterType>().Queryable(). Where(l => l.Description == encounterTypeForUpdate.EncounterTypeName && l.Id != id) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } var encounterTypeFromRepo = await _encounterTypeRepository.GetAsync(f => f.Id == id); if (encounterTypeFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { encounterTypeFromRepo.Description = encounterTypeForUpdate.EncounterTypeName; encounterTypeFromRepo.Help = encounterTypeForUpdate.Help; _encounterTypeRepository.Update(encounterTypeFromRepo); await _unitOfWork.CompleteAsync(); } return(Ok()); }
public async Task <bool> Handle(ChangeAppointmentDetailsCommand message, CancellationToken cancellationToken) { var appointmentFromRepo = await _appointmentRepository.GetAsync(a => a.PatientId == message.PatientId && a.Id == message.AppointmentId); if (appointmentFromRepo == null) { throw new KeyNotFoundException("Unable to locate appointment"); } if (_appointmentRepository.Exists(a => a.PatientId == message.PatientId && a.AppointmentDate == message.AppointmentDate && a.Id != message.AppointmentId && !a.Archived)) { throw new DomainException("Patient already has an appointment for this date"); } appointmentFromRepo.ChangeDetails(message.AppointmentDate, message.Reason, message.Cancelled, message.CancellationReason); _appointmentRepository.Update(appointmentFromRepo); _logger.LogInformation($"----- Appointment {appointmentFromRepo.Id} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task <IActionResult> UpdateCareEvent(long id, [FromBody] CareEventForUpdateDto careEventForUpdate) { if (careEventForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (Regex.Matches(careEventForUpdate.CareEventName, @"[a-zA-Z ']").Count < careEventForUpdate.CareEventName.Length) { ModelState.AddModelError("Message", "Description contains invalid characters (Enter A-Z, a-z)"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <CareEvent>().Queryable(). Where(l => l.Description == careEventForUpdate.CareEventName && l.Id != id) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } var careEventFromRepo = await _careEventRepository.GetAsync(f => f.Id == id); if (careEventFromRepo == null) { return(NotFound()); } if (ModelState.IsValid) { careEventFromRepo.Description = careEventForUpdate.CareEventName; _careEventRepository.Update(careEventFromRepo); await _unitOfWork.CompleteAsync(); } return(Ok()); }
public async Task <bool> Handle(ChangeConceptDetailsCommand message, CancellationToken cancellationToken) { var conceptFromRepo = await _conceptRepository.GetAsync(c => c.Id == message.Id); if (conceptFromRepo == null) { throw new KeyNotFoundException("Unable to locate concept"); } var medicationFormFromRepo = await _medicationFormRepository.GetAsync(mf => mf.Description == message.MedicationForm); if (medicationFormFromRepo == null) { throw new KeyNotFoundException("Unable to locate medication form"); } if (_conceptRepository.Exists(c => c.ConceptName == message.ConceptName && c.Strength == message.Strength && c.MedicationForm.Id == medicationFormFromRepo.Id && c.Id != message.Id)) { throw new DomainException("Item with same name already exists"); } conceptFromRepo.ChangeDetails(message.ConceptName, message.Strength, medicationFormFromRepo); if (message.Active) { conceptFromRepo.MarkAsActive(); } else { conceptFromRepo.MarkAsInActive(); } _conceptRepository.Update(conceptFromRepo); _logger.LogInformation($"----- Concept {message.ConceptName} details updated"); return(await _unitOfWork.CompleteAsync()); }
public async Task SetConfigValueAsync(ConfigType configType, string configValue) { var config = _unitOfWork.Repository <Config>().Queryable(). FirstOrDefault(c => c.ConfigType == configType); if (config == null) { config = new Config() { // Prepare new config ConfigType = configType, ConfigValue = configValue }; await _configRepository.SaveAsync(config); } else { config.ConfigValue = configValue; _configRepository.Update(config); } await _unitOfWork.CompleteAsync(); }