public void testAdvanceReportWorkflow() {
    Integer id = 10;
    Integer wfId = 5;
    String transitionToTake = "abcd";
    String loginId = "SYSTEM_ADMIN";
    ReviewStatus reviewStatus = ReviewStatus.DRAFT_INCOMPLETE;
    Report report = Fixtures.createReport("testReport");
    report.setStatus(ReportStatus.INPROCESS);
    report.setReviewComments(new ArrayList<ReportReviewComment>());
    report.setWorkflowId(wfId);
    List<String> transitions = new ArrayList<String>();

    ReportSubmittability errorMessagesMock = registerMockFor(ReportSubmittability.class);
    EasyMock.expect(errorMessagesMock.isSubmittable()).andReturn(true);
    EasyMock.expect(reportValidationService.isSubmittable(report)).andReturn(errorMessagesMock);
    EasyMock.expect(wfService.nextTransitionNames(wfId, loginId)).andReturn(transitions);
    EasyMock.expect(wfService.advanceWorkflow(wfId, transitionToTake)).andReturn(reviewStatus);
    EasyMock.expect(reportDao.getById(id)).andReturn(report);
    reportDao.save(report);
    replayMocks();
    List<String> transitionsNames = impl.advanceReportWorkflow(wfId, transitionToTake, id, loginId);

    verifyMocks();
    assertEquals(
        "A review comment for the action of advancing workflow was not added",
        1,
        report.getReviewCommentsInternal().size());
  }
  public void testEnactReportWorkflow() {
    long processId = 5;
    StudyParticipantAssignment assignment = Fixtures.createAssignment();
    ExpeditedAdverseEventReport aeReport = Fixtures.createSavableExpeditedReport();
    Report report = Fixtures.createReport("testReport");
    aeReport.setId(55);
    AdverseEventReportingPeriod reportingPeriod = Fixtures.createReportingPeriod();
    WorkflowConfig workflowConfig = Fixtures.createWorkflowConfig("test");
    StudySite site = assignment.getStudySite();
    StudySiteWorkflowConfig ssWfCfg = new StudySiteWorkflowConfig("report", site, workflowConfig);
    site.addStudySiteWorkflowConfig(ssWfCfg);
    reportingPeriod.addAeReport(aeReport);
    aeReport.setAssignment(assignment);
    aeReport.addReport(report);

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(WorkflowService.VAR_STUDY_ID, site.getStudy().getId());
    variables.put(WorkflowService.VAR_WF_TYPE, Report.class.getName());
    variables.put(WorkflowService.VAR_REPORT_ID, report.getId());
    variables.put(WorkflowService.VAR_EXPEDITED_REPORT_ID, aeReport.getId());
    variables.put(WorkflowService.VAR_WF_STUDY_NAME, reportingPeriod.getStudy().getDisplayName());
    variables.put(
        WorkflowService.VAR_WF_SUBJECT_NAME, reportingPeriod.getParticipant().getFullName());
    variables.put(WorkflowService.VAR_WF_COURSE_NAME, reportingPeriod.getName());

    EasyMock.expect(wfService.createProcessInstance("test", variables)).andReturn(processInstance);
    EasyMock.expect(processInstance.getId()).andReturn(processId).anyTimes();
    reportDao.save(report);
    replayMocks();
    impl.enactReportWorkflow(report);
    verifyMocks();
  }
 public void testIsReportingPeriodHavingReportsWithSpecifiedStatusNegative() {
   AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
   Report report = Fixtures.createReport("test report");
   report.setStatus(ReportStatus.INPROCESS);
   ExpeditedAdverseEventReport aeReport = new ExpeditedAdverseEventReport();
   aeReport.addReport(report);
   rp.addAeReport(aeReport);
   assertFalse(impl.isReportingPeriodHavingReportsWithSpecifiedStatus(rp, ReportStatus.COMPLETED));
 }
 public void testAeReportHasWorkflowOnActiveReportsWithInactiveReports() {
   Report report = Fixtures.createReport("test report");
   report.setStatus(ReportStatus.AMENDED);
   report.setWorkflowId(2);
   ExpeditedAdverseEventReport aeReport = new ExpeditedAdverseEventReport();
   aeReport.addReport(report);
   assertFalse(
       "aeReportHasWorkflowOnActive reports should have returned false",
       impl.aeReportHasWorkflowOnActiveReports(aeReport));
 }
 public void testAeReportHasWorkflowOnActiveReportsWithActiveReports() {
   Report report = Fixtures.createReport("test report");
   report.setStatus(ReportStatus.COMPLETED);
   report.setWorkflowId(1);
   ExpeditedAdverseEventReport aeReport = new ExpeditedAdverseEventReport();
   aeReport.addReport(report);
   assertTrue(
       "aeReportHasWorkflowOnActive reports should have returned true",
       impl.aeReportHasWorkflowOnActiveReports(aeReport));
 }
  public void testFindAdverseEventReportingPeriods() {
    String userId = "tester";
    AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
    ExpeditedAdverseEventReport aeReport = Fixtures.createSavableExpeditedReport();
    Report report = Fixtures.createReport("test report");
    report.setStatus(ReportStatus.INPROCESS);
    report.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);
    report.setWorkflowId(1);
    rp.addAeReport(aeReport);
    aeReport.addReport(report);

    List<AdverseEventReportingPeriod> reportingPeriods =
        new ArrayList<AdverseEventReportingPeriod>();
    reportingPeriods.add(rp);

    rp.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);
    rp.setWorkflowId(1);

    AdverseEventReportingPeriodDTO rpDto = new AdverseEventReportingPeriodDTO();
    ExpeditedAdverseEventReportDTO rDto = new ExpeditedAdverseEventReportDTO();
    ReportDTO reportDto = new ReportDTO();
    rDto.addReportDTO(reportDto);
    List<String> possibleActions = new ArrayList<String>();
    possibleActions.add("abc");
    reportDto.setPossibleActions(possibleActions);
    EasyMock.expect(
            rpDao.findAdverseEventReportingPeriods(
                (AdverseEventReportingPeriodForReviewQuery) EasyMock.anyObject()))
        .andReturn(reportingPeriods);

    EasyMock.expect(factory.createAdverseEventEvalutionPeriodDTO(rp, userId, true))
        .andReturn(rpDto);
    EasyMock.expect(factory.createAdverseEventReportDTO(aeReport, userId)).andReturn(rDto);
    List rrList = new ArrayList<ReconciliationReport>();
    EasyMock.expect(
            reconciliationReportDao.search((ReconciliationReportQuery) EasyMock.anyObject()))
        .andReturn(rrList)
        .anyTimes();
    replayMocks();

    Participant participant = Fixtures.createParticipant("Joel", "biju");
    Study study = Fixtures.createStudy("Hello");
    Organization org = Fixtures.createOrganization("test org");
    ReviewStatus reviewStatus = null;
    ReportStatus reportStatus = null;

    List<AdverseEventReportingPeriodDTO> dtos =
        impl.findAdverseEventReportingPeriods(
            participant, study, org, reviewStatus, reportStatus, userId, true);

    verifyMocks();

    assertEquals(1, dtos.size());
    assertEquals(1, dtos.get(0).getAeReports().size());
  }
  public void testFetchReviewCommentsForReport() {
    Report report = Fixtures.createReport("testReport");
    List<ReportReviewComment> reviewComments = new ArrayList<ReportReviewComment>();
    report.setReviewComments(reviewComments);
    Integer reportId = 10;

    EasyMock.expect(reportDao.getById(reportId)).andReturn(report);
    replayMocks();
    List<? extends ReviewComment> comments = impl.fetchReviewCommentsForReport(reportId);
    verifyMocks();
    assertEquals(reviewComments.size(), comments.size());
  }
  public void testAddReportReviewComment() {
    Integer reportId = 10;
    String comment = "mycomment";
    String userId = "userId";

    Report report = Fixtures.createReport("testReport");
    report.setReviewComments(new ArrayList<ReportReviewComment>());
    EasyMock.expect(reportDao.getById(reportId)).andReturn(report);
    reportDao.save(report);
    replayMocks();
    impl.addReportReviewComment(reportId, comment, userId);
    verifyMocks();
  }
  public void testIsEntityHavingSpecifiedReviewStatus() {
    Report report = Fixtures.createReport("testReport");
    report.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);

    boolean result = impl.isEntityHavingSpecifiedReviewStatus(null, report);
    assertTrue(result);

    report.setReviewStatus(null);
    result = impl.isEntityHavingSpecifiedReviewStatus(ReviewStatus.DRAFT_INCOMPLETE, report);
    assertFalse(result);

    report.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);
    result = impl.isEntityHavingSpecifiedReviewStatus(ReviewStatus.DRAFT_INCOMPLETE, report);
    assertTrue(result);
  }
 public void testDeleteReportReviewComment() {
   Report report = Fixtures.createReport("testReport");
   ArrayList<ReportReviewComment> commentsList = new ArrayList<ReportReviewComment>();
   commentsList.add(Fixtures.createReportReviewComment(1, "comment 1"));
   commentsList.add(Fixtures.createReportReviewComment(2, "comment 2"));
   commentsList.add(Fixtures.createReportReviewComment(3, "comment 3"));
   report.setReviewComments(commentsList);
   EasyMock.expect(reportDao.getById(10)).andReturn(report);
   reportDao.save(report);
   replayMocks();
   impl.deleteReportReviewComment(10, 2);
   verifyMocks();
   assertEquals(
       "Comment not deleted from comments list", 2, report.getReviewCommentsInternal().size());
 }
  public void testNextTransitionsForAeReportWithCompleteReports() throws Exception {
    Report report = Fixtures.createReport("testReport");
    report.setWorkflowId(1);
    ReportSubmittability errorMessagesMock = registerMockFor(ReportSubmittability.class);
    report.setStatus(ReportStatus.PENDING);
    List<String> transitions = new ArrayList<String>();
    transitions.add("test action");
    transitions.add("Submit to Central Office Report Reviewer");

    EasyMock.expect(wfService.nextTransitionNames(1, "SYSTEM_ADMIN")).andReturn(transitions);
    EasyMock.expect(reportValidationService.isSubmittable(report)).andReturn(errorMessagesMock);
    EasyMock.expect(errorMessagesMock.isSubmittable()).andReturn(true);
    replayMocks();
    List<String> filteredTransitions =
        impl.nextTransitionNamesForReportWorkflow(report, "SYSTEM_ADMIN");
    verifyMocks();
    assertEquals(2, filteredTransitions.size());
  }
  // test the transition, were the physician can login to the system.
  public void testNextTransitionsForAeReportWithAnInvestigatorHavingLogin() throws Exception {
    Report report = Fixtures.createReport("testReport");
    Investigator investigator = Fixtures.createInvestigator("tester");
    investigator.setLoginId("hai");
    report.getPhysician().setPerson(investigator);
    report.setWorkflowId(1);
    ReportSubmittability errorMessagesMock = registerMockFor(ReportSubmittability.class);
    report.setStatus(ReportStatus.PENDING);
    List<String> transitions = new ArrayList<String>();
    transitions.add("test action");
    transitions.add("Send to Physician for Review");

    EasyMock.expect(wfService.nextTransitionNames(1, "SYSTEM_ADMIN")).andReturn(transitions);
    EasyMock.expect(reportValidationService.isSubmittable(report)).andReturn(errorMessagesMock);
    EasyMock.expect(errorMessagesMock.isSubmittable()).andReturn(true);
    replayMocks();
    List<String> filteredTransitions =
        impl.nextTransitionNamesForReportWorkflow(report, "SYSTEM_ADMIN");
    verifyMocks();
    assertEquals(1, filteredTransitions.size());
  }