private Obs doNotGoToServiceToFormatMembers(Obs obsGroup) {
    Set<Obs> replacements = new HashSet<Obs>();
    for (Obs member : obsGroup.getGroupMembers()) {
      replacements.add(new DoNotGoToServiceWhenFormatting(member));
    }

    obsGroup.setGroupMembers(replacements);
    return obsGroup;
  }
Ejemplo n.º 2
0
  /** @see {@link ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)} */
  @Test
  @Verifies(
      value = "should fail if the parent obs has values",
      method = "validate(java.lang.Object, org.springframework.validation.Errors)")
  public void validate_shouldFailIfParentObshasValues() throws Exception {

    Obs obs = new Obs();
    obs.setPerson(Context.getPersonService().getPerson(2));
    obs.setConcept(Context.getConceptService().getConcept(18));

    obs.setValueBoolean(false);
    obs.setValueCoded(Context.getConceptService().getConcept(18));
    obs.setValueComplex("test");
    obs.setValueDatetime(new Date());
    obs.setValueDrug(Context.getConceptService().getDrug(3));
    obs.setValueGroupId(getLoadCount());
    obs.setValueModifier("test");
    obs.setValueNumeric(1212.0);
    obs.setValueText("test");

    Set<Obs> group = new HashSet<Obs>();
    group.add(Context.getObsService().getObs(7));
    group.add(Context.getObsService().getObs(9));
    obs.setGroupMembers(group);

    Errors errors = new BindException(obs, "obs");
    new ObsValidator().validate(obs, errors);

    Assert.assertFalse(errors.hasFieldErrors("person"));
    Assert.assertFalse(errors.hasFieldErrors("concept"));
    Assert.assertTrue(errors.hasFieldErrors("valueCoded"));
    Assert.assertTrue(errors.hasFieldErrors("valueDrug"));
    Assert.assertTrue(errors.hasFieldErrors("valueDatetime"));
    Assert.assertTrue(errors.hasFieldErrors("valueNumeric"));
    Assert.assertTrue(errors.hasFieldErrors("valueModifier"));
    Assert.assertTrue(errors.hasFieldErrors("valueText"));
    Assert.assertTrue(errors.hasFieldErrors("valueBoolean"));
    Assert.assertTrue(errors.hasFieldErrors("valueComplex"));
  }
Ejemplo n.º 3
0
  /** @see {@link ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors)} */
  @Test
  @Verifies(
      value = "should fail validation if obs ancestors contains obs",
      method = "validate(java.lang.Object, org.springframework.validation.Errors)")
  public void validate_shouldFailValidationIfObsAncestorsContainsObs() throws Exception {
    Obs obs = new Obs();
    obs.setPerson(Context.getPersonService().getPerson(2));
    obs.setConcept(Context.getConceptService().getConcept(3)); // datatype = N/A
    obs.setObsDatetime(new Date());

    Set<Obs> group = new HashSet<Obs>();
    group.add(obs);
    obs.setGroupMembers(group);

    Errors errors = new BindException(obs, "obs");
    new ObsValidator().validate(obs, errors);

    Assert.assertFalse(errors.hasFieldErrors("person"));
    Assert.assertFalse(errors.hasFieldErrors("concept"));
    Assert.assertFalse(errors.hasFieldErrors("obsDatetime"));
    Assert.assertTrue(errors.hasFieldErrors("groupMembers"));
  }