IsAllImmunizationsGivenRule implements IRule { @Override public boolean apply(SafeMap reportFields) { ChildImmunization childImmunization = new ChildImmunization(); return childImmunization.isImmunizedWith(MEASLES_VALUE, reportFields) || (childImmunization.isImmunizedWith(MMR_VALUE, reportFields) && !childImmunization.isPreviouslyImmunizedWith(MEASLES_VALUE, reportFields)); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfAllImmunizationsWereGiven() { SafeMap safeMap = new SafeMap( mapOf("immunizationsGiven", "bcg opv_0 hepb_0 opv_1 pentavalent_1 opv_2 pentavalent_2 opv_3 pentavalent_3 measles")); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "bcg pentavalent_3 mmr") .put("previousImmunizations", "opv_0 hepb_0 opv_1 pentavalent_1 opv_2 pentavalent_2 opv_3") .map())); assertTrue(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "measles") .put("previousImmunizations", "") .map())); assertTrue(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "measles") .put("previousImmunizations", null) .map())); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfAllImmunizationsWereNotGiven() { SafeMap safeMap = new SafeMap( mapOf("immunizationsGiven", "bcg opv_0 hepb_0 opv_1 pentavalent_1 opv_2 pentavalent_2 opv_3 pentavalent_3")); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "mmr") .put("previousImmunizations", "measles") .map())); assertFalse(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "bcg") .put("previousImmunizations", "") .map())); assertFalse(didRuleApply); didRuleApply = rule.apply(new SafeMap( create("immunizationsGiven", "bcg") .put("previousImmunizations", null) .map())); assertFalse(didRuleApply); }