Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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))));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public async Task <PatientIdentifierDto> Handle(AddPatientCommand message, CancellationToken cancellationToken)
        {
            await CheckIfPatientIsUniqueAsync(message.Attributes);
            await ValidateCommandModelAsync(message.MeddraTermId, message.CohortGroupId, message.EncounterTypeId);

            var patientDetail = await PreparePatientDetailAsync(message);

            if (!patientDetail.IsValid())
            {
                patientDetail.InvalidAttributes.ForEach(element => throw new DomainException(element));
            }

            var id = await _patientService.AddPatientAsync(patientDetail);

            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- Patient {message.LastName} created");

            var mappedPatient = await GetPatientAsync <PatientIdentifierDto>(id);

            if (mappedPatient == null)
            {
                throw new KeyNotFoundException("Unable to locate newly added patient");
            }

            return(CreateLinks(mappedPatient));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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(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());
        }
Exemplo n.º 10
0
        public async Task <bool> Handle(DeleteUserCommand message, CancellationToken cancellationToken)
        {
            var userFromRepo = await _userRepository.GetAsync(u => u.Id == message.UserId,
                                                              new string[] { "Facilities" });

            if (userFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate user");
            }

            if (_auditLogRepository.Exists(a => a.User.Id == message.UserId))
            {
                throw new DomainException("Unable to delete as item is in use");
            }

            var userFacilities = await _userFacilityRepository.ListAsync(c => c.User.Id == message.UserId);

            userFacilities.ToList().ForEach(userFacility => _userFacilityRepository.Delete(userFacility));

            _userRepository.Delete(userFromRepo);
            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- User {userFromRepo.Id} deleted");

            return(true);
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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(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);
        }
Exemplo n.º 14
0
        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 <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));
        }
Exemplo n.º 16
0
        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());
        }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 18
0
        public async Task <bool> Handle(DeleteCustomAttributeCommand message, CancellationToken cancellationToken)
        {
            var customAttributeFromRepo = await _customAttributeRepository.GetAsync(ca => ca.Id == message.Id, new string[] { "" });

            if (customAttributeFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate custom attribute");
            }

            _customAttributeRepository.Delete(customAttributeFromRepo);

            _logger.LogInformation($"----- Custom Attribute {message.Id} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Exemplo n.º 19
0
        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());
        }
Exemplo n.º 20
0
        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());
        }
Exemplo n.º 21
0
        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());
        }
Exemplo n.º 22
0
        public async Task <bool> Handle(ChangeUserFacilitiesCommand message, CancellationToken cancellationToken)
        {
            var userFromRepo = await _userRepository.GetAsync(u => u.Id == message.UserId,
                                                              new string[] { "Facilities" });

            if (userFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate user");
            }

            await UpdateUserFacilitiesAsync(message.Facilities, userFromRepo);

            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- User {userFromRepo.Id} facilities updated");

            return(true);
        }
Exemplo n.º 23
0
        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());
        }
Exemplo n.º 24
0
        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());
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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();
        }
Exemplo n.º 27
0
        public async Task <bool> Handle(DeleteFacilityCommand message, CancellationToken cancellationToken)
        {
            var facilityFromRepo = await _facilityRepository.GetAsync(f => f.Id == message.Id, new string[] { "PatientFacilities", "UserFacilities" });

            if (facilityFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate facility");
            }

            if (facilityFromRepo.PatientFacilities.Count > 0 || facilityFromRepo.UserFacilities.Count > 0)
            {
                throw new DomainException("Unable to delete the Facility as it is currently in use");
            }

            _facilityRepository.Delete(facilityFromRepo);

            _logger.LogInformation($"----- Facility {message.Id} deleted");

            return(await _unitOfWork.CompleteAsync());
        }
Exemplo n.º 28
0
        public async Task <bool> Handle(DeleteCohortGroupCommand message, CancellationToken cancellationToken)
        {
            var cohortGroupFromRepo = await _cohortGroupRepository.GetAsync(cg => cg.Id == message.Id);

            if (cohortGroupFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate cohort group");
            }

            if (_cohortGroupEnrolmentRepository.Exists(cge => cge.CohortGroup.Id == message.Id))
            {
                throw new DomainException("Unable to delete the Cohort Group as it is currently in use");
            }

            _cohortGroupRepository.Delete(cohortGroupFromRepo);

            _logger.LogInformation($"----- Cohort group {message.Id} deleted");

            return(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);
        }
Exemplo n.º 30
0
        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());
        }