@Test public void testSubjectCriteriaCorrect() { DichotomousCriterion criterion1 = new DichotomousCriterion(); criterion1.setName("criterion1"); DichotomousCriterion criterion2 = new DichotomousCriterion(); criterion2.setName("criterion2"); List< AbstractCriterion< ? extends Serializable, ? extends AbstractConstraint<? extends Serializable>>> criteria = new ArrayList< AbstractCriterion< ? extends Serializable, ? extends AbstractConstraint<? extends Serializable>>>(); criteria.add(criterion1); criteria.add(criterion2); validTrial.setCriteria(criteria); assertEquals(2, validTrial.getCriteria().size()); assertTrue(DichotomousCriterion.class.isInstance(validTrial.getCriteria().get(0))); assertEquals("criterion1", validTrial.getCriteria().get(0).getName()); assertTrue(DichotomousCriterion.class.isInstance(validTrial.getCriteria().get(1))); assertEquals("criterion2", validTrial.getCriteria().get(1).getName()); List< AbstractCriterion< ? extends Serializable, ? extends AbstractConstraint<? extends Serializable>>> list = new ArrayList< AbstractCriterion< ? extends Serializable, ? extends AbstractConstraint<? extends Serializable>>>(); validTrial.setCriteria(list); assertEquals(list, validTrial.getCriteria()); }
@Test public void testAddSubjectCriteria() { DichotomousCriterion criterion1 = new DichotomousCriterion(); criterion1.setName("criterion1"); DichotomousCriterion criterion2 = new DichotomousCriterion(); criterion2.setName("criterion2"); validTrial.addCriterion(criterion1); validTrial.addCriterion(criterion2); assertEquals(2, validTrial.getCriteria().size()); assertTrue(DichotomousCriterion.class.isInstance(validTrial.getCriteria().get(0))); assertEquals("criterion1", validTrial.getCriteria().get(0).getName()); assertTrue(DichotomousCriterion.class.isInstance(validTrial.getCriteria().get(1))); assertEquals("criterion2", validTrial.getCriteria().get(1).getName()); assertValid(validTrial); }
@Test public void testStrataNamesAndIdsStrataCriterionsTrialSite() { TrialSite site1 = new TrialSite(); site1.setId(1); site1.setName("site1"); TrialSite site2 = new TrialSite(); site2.setId(2); site2.setName("site2"); validTrial.addParticipatingSite(site1); validTrial.addParticipatingSite(site2); validTrial.setStratifyTrialSite(true); DichotomousCriterion criterion1 = new DichotomousCriterion(); criterion1.setId(1); criterion1.setName("criterion1"); criterion1.setOption1("option1"); criterion1.setOption2("option2"); try { DichotomousConstraint d1 = new DichotomousConstraint(Arrays.asList(new String[] {"option1"})); d1.setId(1); criterion1.addStrata(d1); DichotomousConstraint d2 = new DichotomousConstraint(Arrays.asList(new String[] {"option2"})); d2.setId(2); criterion1.addStrata(d2); } catch (ContraintViolatedException e) { fail(); } DichotomousCriterion criterion2 = new DichotomousCriterion(); criterion2.setId(2); criterion2.setName("criterion2"); criterion2.setOption1("option1"); criterion2.setOption2("option2"); try { DichotomousConstraint d1 = new DichotomousConstraint(Arrays.asList(new String[] {"option1"})); d1.setId(1); criterion2.addStrata(d1); DichotomousConstraint d2 = new DichotomousConstraint(Arrays.asList(new String[] {"option2"})); d2.setId(2); criterion2.addStrata(d2); } catch (ContraintViolatedException e) { fail(); } validTrial.addCriterion(criterion1); validTrial.addCriterion(criterion2); Pair<List<String>, List<String>> pair = validTrial.getAllStrataIdsAndNames(); assertEquals(8, pair.first().size()); assertEquals(8, pair.last().size()); Collections.sort(pair.first()); assertEquals("1__1_1;2_1;", pair.first().get(0)); assertEquals("1__1_1;2_2;", pair.first().get(1)); assertEquals("1__1_2;2_1;", pair.first().get(2)); assertEquals("1__1_2;2_2;", pair.first().get(3)); assertEquals("2__1_1;2_1;", pair.first().get(4)); assertEquals("2__1_1;2_2;", pair.first().get(5)); assertEquals("2__1_2;2_1;", pair.first().get(6)); assertEquals("2__1_2;2_2;", pair.first().get(7)); Collections.sort(pair.last()); assertEquals("site1 | criterion1_option1;criterion2_option1;", pair.last().get(0)); assertEquals("site1 | criterion1_option1;criterion2_option2;", pair.last().get(1)); assertEquals("site1 | criterion1_option2;criterion2_option1;", pair.last().get(2)); assertEquals("site1 | criterion1_option2;criterion2_option2;", pair.last().get(3)); assertEquals("site2 | criterion1_option1;criterion2_option1;", pair.last().get(4)); assertEquals("site2 | criterion1_option1;criterion2_option2;", pair.last().get(5)); assertEquals("site2 | criterion1_option2;criterion2_option1;", pair.last().get(6)); assertEquals("site2 | criterion1_option2;criterion2_option2;", pair.last().get(7)); }
@Test public void testChartSubGroups() { authenticatAsPrincipalInvestigator(); validTrial.setStartDate(new GregorianCalendar(2009, 0, 1)); validTrial.setEndDate(new GregorianCalendar(2010, 11, 1)); int blocksize = 4; int randomizations = 240; TreatmentArm arm1 = new TreatmentArm(); arm1.setPlannedSubjects(randomizations / 2); arm1.setName("arm1"); arm1.setTrial(validTrial); TreatmentArm arm2 = new TreatmentArm(); arm2.setPlannedSubjects(randomizations / 2); arm2.setName("arm2"); arm2.setTrial(validTrial); List<TreatmentArm> arms = new ArrayList<TreatmentArm>(); arms.add(arm1); arms.add(arm2); validTrial.setTreatmentArms(arms); DichotomousCriterion cr = new DichotomousCriterion(); cr.setOption1("1"); cr.setOption2("2"); DichotomousCriterion cr1 = new DichotomousCriterion(); cr1.setOption1("1"); cr1.setOption2("2"); DichotomousCriterion cr2 = new DichotomousCriterion(); cr2.setOption1("1"); cr2.setOption2("2"); try { cr.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"1"}))); cr.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"2"}))); cr1.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"1"}))); cr1.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"2"}))); cr2.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"1"}))); cr2.addStrata(new DichotomousConstraint(Arrays.asList(new String[] {"2"}))); validTrial.addCriterion(cr); validTrial.addCriterion(cr1); validTrial.addCriterion(cr2); } catch (ContraintViolatedException e) { BoxedException.throwBoxed(e); } BlockRandomizationConfig config = new BlockRandomizationConfig(); config.setMaximum(blocksize); config.setMinimum(blocksize); validTrial.setRandomizationConfiguration(config); trialService.create(validTrial); assertTrue(validTrial.getId() > 0); assertEquals(2, validTrial.getTreatmentArms().size()); authenticatAsInvestigator(); for (int i = 0; i < randomizations; i++) { TrialSubject subject = new TrialSubject(); subject.setIdentification("identification" + i); subject.setTrialSite(validTrial.getLeadingSite()); SubjectProperty<Serializable> subprob = new SubjectProperty<Serializable>(validTrial.getCriteria().get(0)); SubjectProperty<Serializable> subprob1 = new SubjectProperty<Serializable>(validTrial.getCriteria().get(1)); SubjectProperty<Serializable> subprob2 = new SubjectProperty<Serializable>(validTrial.getCriteria().get(2)); try { if ((new Random()).nextInt(2) == 0) { subprob.setValue(cr.getOption1()); } else { subprob.setValue(cr.getOption2()); } if ((new Random()).nextInt(2) == 0) { subprob1.setValue(cr1.getOption1()); } else { subprob1.setValue(cr1.getOption2()); } if ((new Random()).nextInt(2) == 0) { subprob2.setValue(cr2.getOption1()); } else { subprob2.setValue(cr2.getOption2()); } } catch (ContraintViolatedException e) { BoxedException.throwBoxed(e); } Set<SubjectProperty<?>> proberties = new HashSet<SubjectProperty<?>>(); proberties.add(subprob); proberties.add(subprob1); proberties.add(subprob2); subject.setProperties(proberties); trialService.randomize(validTrial, subject); subject.setCreatedAt(new GregorianCalendar(2009 + (i >= 120 ? 1 : 0), i % 12, 1)); sessionFactory.getCurrentSession().update(subject); } ChartData data = chartsService.generateRecruitmentChartFactors(validTrial); assertEquals(8, data.getData().size()); assertEquals(8, data.getData().get(0).length); assertEquals(8, data.getXLabels().size()); }