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);
        }
Example #2
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);
        }
        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(ChangeReportInstanceActivityCommand message, CancellationToken cancellationToken)
        {
            var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid &&
                                                                                  ri.Id == message.ReportInstanceId,
                                                                                  new string[] { "Activities.ExecutionEvents.ExecutionStatus", "Tasks.CreatedBy", "CreatedBy", "TerminologyMedDra" });

            if (reportInstanceFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate report instance");
            }

            if (await _workFlowService.ValidateExecutionStatusForCurrentActivityAsync(reportInstanceFromRepo.ContextGuid, message.NewExecutionStatus) == false)
            {
                throw new DomainException("Invalid status for activity");
            }

            await _workFlowService.ExecuteActivityAsync(reportInstanceFromRepo.ContextGuid, message.NewExecutionStatus, message.Comments, message.ContextDate, message.ContextCode);

            _logger.LogInformation($"----- Task {message.ReportInstanceId} report instance activity changed");

            return(await _unitOfWork.CompleteAsync());
        }
        public async Task <bool> Handle(CreateE2BForSpontaneousCommand message, CancellationToken cancellationToken)
        {
            var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.WorkFlow.WorkFlowGuid == message.WorkFlowGuid &&
                                                                                  ri.Id == message.ReportInstanceId, new string[] { "CreatedBy", "WorkFlow" });

            if (reportInstanceFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate report instance");
            }

            var spontaneousReport = await _datasetInstanceRepository.GetAsync(ds => ds.DatasetInstanceGuid == reportInstanceFromRepo.ContextGuid, new string[] { "Dataset" });

            if (spontaneousReport == null)
            {
                throw new KeyNotFoundException("Unable to locate spontaneous report");
            }

            var dataset = await GetDatasetForInstance();

            if (dataset == null)
            {
                throw new KeyNotFoundException("Unable to locate E2B dataset");
            }

            var newActivityExecutionStatusEvent = await _workFlowService.ExecuteActivityAsync(reportInstanceFromRepo.ContextGuid, "E2BINITIATED", "AUTOMATION: E2B dataset created", null, "");

            var e2bInstance = dataset.CreateInstance(newActivityExecutionStatusEvent.Id, "Spontaneous", null, spontaneousReport, null);
            await _datasetInstanceRepository.SaveAsync(e2bInstance);

            UpdateValuesUsingSource(e2bInstance, spontaneousReport, dataset);

            await _unitOfWork.CompleteAsync();

            _logger.LogInformation($"----- E2B instance created for spontaneous report {message.ReportInstanceId} created");

            return(true);
        }