/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(GetDtoByKeyRequest <AssessmentSectionSummaryDto> request, DtoResponse <AssessmentSectionSummaryDto> response) { var assessmentInstance = _assessmentInstanceRepository.GetByKey(request.Key); var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(assessmentInstance.AssessmentDefinitionKey); var assessmentSectionSummaryDto = new AssessmentSectionSummaryDto() { Key = assessmentInstance.Key, PatientKey = assessmentInstance.PatientKey, AssessmentDefinitionKey = assessmentDefinition.Key, AssessmentDefinitionCode = assessmentDefinition.CodedConcept.Code, AssessmentName = assessmentDefinition.CodedConcept.Name, IsSubmitted = assessmentInstance.IsSubmitted, IsComplete = Math.Abs(assessmentInstance.CalculateCompleteness().PercentComplete - 1.0d) <= double.Epsilon, Score = assessmentInstance.Score == null ? null : Mapper.Map <Score, ScoreDto> (assessmentInstance.Score), Sections = new List <SectionSummaryDto> (), PercentComplete = assessmentInstance.CalculateCompleteness().PercentComplete * 100, }; MapItems(assessmentSectionSummaryDto, assessmentDefinition, assessmentInstance); response.DataTransferObject = assessmentSectionSummaryDto; var messages = new List <IMessage> (_messageCollector.Messages); if (assessmentInstance.WorkflowKey.HasValue) { var message = _workflowMessageRepository.GetByKey(assessmentInstance.WorkflowKey.Value); if (message.Status == WorkflowMessageStatus.WaitingForResponse) { messages.Add(message); } } response.DataTransferObject.Messages = Mapper.Map <IEnumerable <IMessage>, IEnumerable <IMessageDto> > (messages); }
protected override void Handle(RejectWorkflowMessageRequest request, WorkflowMessageStatusChangedResponse response) { var workflowMessage = _workflowMessageRepository.GetByKey(request.WorkflowMessageKey); if (workflowMessage != null) { workflowMessage.Reject(); } }
public IReport Generate(Guid workflowKey, string reportName) { var workflow = _workflowMessageRepository.GetByKey(workflowKey); var reportModel = workflow.WorkflowReports.FirstOrDefault(r => r.Name == reportName); if (reportModel != null) { NidaPatientSummaryReportModelBuilder.FillDefaults(reportModel); } //todo: get report data from event store var nidaReportDataCollection = new NidaReportDataCollection { reportModel == null ? new NidaReportData() : new NidaReportData(reportModel) }; var report = new NidaReport { DataSource = nidaReportDataCollection, }; return(report); }
/// <summary> /// Initializes a new instance of the <see cref="NidaWorkflowRuleCollection"/> class. /// </summary> /// <param name="assessmentDefinitionRepository">The assessment definition repository.</param> /// <param name="repository">The repository.</param> /// <param name="assessmentInstanceRepository">The assessment instance repository.</param> /// <param name="resourcesManager">The resources manager.</param> public NidaWorkflowRuleCollection( IAssessmentDefinitionRepository assessmentDefinitionRepository, IWorkflowMessageRepository repository, IAssessmentInstanceRepository assessmentInstanceRepository, IResourcesManager resourcesManager = null) { _resourcesManager = resourcesManager; NewRule(() => ShouldRecommendDastRule).When(assessment => (int)assessment.Score.Value > 0) .Then( (assessment, ctx) => { var messageReporter = ctx.WorkingMemory.GetContextObject <IMessageCollector> ("MessageCollector"); var assessmentDefinitionKey = assessmentDefinitionRepository.GetKeyByCode(DrugAbuseScreeningTest.AssessmentCodedConcept.Code); WorkflowMessage message = null; if (assessment.WorkflowKey.HasValue) { message = repository.GetByKey(assessment.WorkflowKey.Value); } message = message ?? new WorkflowMessage( assessment.PatientKey, assessment.Key, NidaSingleQuestionScreener.AssessmentCodedConcept.Code, assessmentDefinitionKey, DrugAbuseScreeningTest.AssessmentCodedConcept.Code, assessment.Score); if (assessment.CanSelfAdminister) { message.AllowSelfAdministration(); } assessment.AddToWorkflow(message.Key); messageReporter.AddMessage(message); }) .ElseThen( (assessment, ctx) => { WorkflowMessage message = null; if (assessment.WorkflowKey.HasValue) { message = repository.GetByKey(assessment.WorkflowKey.Value); } message = message ?? new WorkflowMessage( assessment.PatientKey, assessment.Key, NidaSingleQuestionScreener.AssessmentCodedConcept.Code, Guid.Empty, null, assessment.Score); if (assessment.CanSelfAdminister) { message.AllowSelfAdministration(); } message.Complete(NidaPatientSummaryReportModelBuilder.GetGreenReportModel()); }); NewRuleSet(() => NidaSingleQuestionScreenerRuleSet, ShouldRecommendDastRule); NewRule(() => ShouldRecommendNidaAssessFurtherRule).When(assessment => assessment.WorkflowKey.HasValue) .Then( (assessment, ctx) => { var messageReporter = ctx.WorkingMemory .GetContextObject <IMessageCollector> ("MessageCollector"); var assessmentDefinitionKey = assessmentDefinitionRepository.GetKeyByCode(NidaAssessFurther.AssessmentCodedConcept.Code); var message = repository.GetByKey(assessment.WorkflowKey.Value); message.Advance( assessment.Key, DrugAbuseScreeningTest.AssessmentCodedConcept.Code, assessmentDefinitionKey, NidaAssessFurther.AssessmentCodedConcept.Code, assessment.Score); messageReporter.AddMessage(message); }); NewRuleSet(() => DrugAbuseScreeningTestRuleSet, ShouldRecommendNidaAssessFurtherRule); NewRule(() => ShouldCompleteWorkflowStatusRule).When(assessment => assessment.WorkflowKey.HasValue) .Then( (assessment, ctx) => { var message = repository.GetByKey(assessment.WorkflowKey.Value); var dastKey = message.GetAssessmentKeyforCodeInWorkflow(DrugAbuseScreeningTest.AssessmentCodedConcept.Code); var dastInstance = assessmentInstanceRepository.GetByKey(dastKey.Value); ReportModel reportModel; if (((long)dastInstance.Score.Value) <= 2 && !(((NidaAssessFurtherScoring)assessment.Score.Value).TotalScore)) { reportModel = NidaPatientSummaryReportModelBuilder.GetAmberReportModel( _resourcesManager, dastInstance, assessment); } else { reportModel = NidaPatientSummaryReportModelBuilder.GetRedReportModel( _resourcesManager, dastInstance, assessment); } message.Complete(reportModel); }); NewRuleSet(() => NidaAssessFurtherRuleSet, ShouldCompleteWorkflowStatusRule); }