Program: 86792
Project: 86792
Buggy source:
/** 
 * @see {@link EncounterAndObsDataSetEvaluator#evaluate(DataSetDefinition,EvaluationContext)}
 */
@Test @Verifies(value="String_Node_Str",method="String_Node_Str") public void evaluate_shouldEvaluateAnEncounterAndObsDataSetDefinitionAllEncounterObsValuesInReportRow() throws Exception {
  executeDataSet(XML_ENCOUNTER_DATASET);
  executeDataSet(XML_OBS_GROUP_DATASET);
  executeDataSet(XML_FORM_DATASET);
  Form form=Context.getFormService().getForm(2);
  Encounter encounter1=Context.getEncounterService().getEncounter(13);
  Encounter encounter2=Context.getEncounterService().getEncounter(14);
  encounter1.setForm(form);
  encounter2.setForm(form);
  EncounterAndObsDataSetDefinition d=new EncounterAndObsDataSetDefinition();
  d.setForms(Collections.singletonList(form));
  d.setColumnDisplayFormat(Collections.singletonList(EncounterAndObsDataSetDefinition.ColumnDisplayFormat.ID));
  Integer maxColumnHeaderWidth=d.getMaxColumnHeaderWidth();
  SimpleDataSet result=(SimpleDataSet)Context.getService(DataSetDefinitionService.class).evaluate(d,null);
  for (  DataSetRow row : result.getRows()) {
    Integer encounterId=(Integer)row.getColumnValue("String_Node_Str");
    Encounter e=Context.getEncounterService().getEncounter(encounterId);
    List<String> obsValues=new ArrayList<String>();
    for (    DataSetColumn dsc : row.getColumnValues().keySet()) {
      String obsValue=row.getColumnValue(dsc).toString();
      if (StringUtils.isNotEmpty(obsValue)) {
        obsValues.add(obsValue);
      }
    }
    for (    Obs obs : e.getObs()) {
      Concept obsCodedValue=obs.getValueCoded();
      String obsNonCodedValue=obs.getValueAsString(Context.getLocale());
      if ((obsCodedValue != null) || (obsNonCodedValue != null && StringUtils.isNotEmpty(obsNonCodedValue))) {
        if (obsCodedValue != null && obsValues.contains(obsCodedValue.toString())) {
          boolean obsRemoved=obsValues.remove(obsCodedValue.toString());
          boolean obsDateRemoved=obsValues.remove(Context.getDateFormat().format(obs.getObsDatetime()));
          boolean obsGroupRemoved=false;
          if (obs.getObsGroup() != null) {
            obsGroupRemoved=obsValues.remove(obs.getObsGroup().getId().toString());
          }
 else {
            obsGroupRemoved=true;
          }
          Assert.assertTrue(obsRemoved && obsDateRemoved && obsGroupRemoved);
        }
 else         if (obsValues.contains(obsNonCodedValue)) {
          boolean obsRemoved=obsValues.remove(obsNonCodedValue);
          boolean obsDateRemoved=obsValues.remove(Context.getDateFormat().format(obs.getObsDatetime()));
          boolean obsGroupRemoved=false;
          if (obs.getObsGroup() != null) {
            obsGroupRemoved=obsValues.remove(obs.getObsGroup().getId().toString());
          }
 else {
            obsGroupRemoved=true;
          }
          Assert.assertTrue(obsRemoved && obsDateRemoved && obsGroupRemoved);
        }
 else {
          Assert.assertFalse(true);
        }
      }
    }
    Assert.assertTrue(obsValues.size() == 5);
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getEncounterId().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getEncounterDatetime().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getLocation().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getProvider().getPersonName().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getPatientId().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
  }
}

Fixed version (ground truth):
/** 
 * @see {@link EncounterAndObsDataSetEvaluator#evaluate(DataSetDefinition,EvaluationContext)}
 */
@Test @Verifies(value="String_Node_Str",method="String_Node_Str") public void evaluate_shouldEvaluateAnEncounterAndObsDataSetDefinitionAllEncounterObsValuesInReportRow() throws Exception {
  executeDataSet(XML_ENCOUNTER_DATASET);
  executeDataSet(XML_OBS_GROUP_DATASET);
  executeDataSet(XML_FORM_DATASET);
  Form form=Context.getFormService().getForm(2);
  Encounter encounter1=Context.getEncounterService().getEncounter(13);
  Encounter encounter2=Context.getEncounterService().getEncounter(14);
  encounter1.setForm(form);
  encounter2.setForm(form);
  EncounterAndObsDataSetDefinition d=new EncounterAndObsDataSetDefinition();
  d.setForms(Collections.singletonList(form));
  d.setColumnDisplayFormat(Collections.singletonList(EncounterAndObsDataSetDefinition.ColumnDisplayFormat.ID));
  Integer maxColumnHeaderWidth=d.getMaxColumnHeaderWidth();
  SimpleDataSet result=(SimpleDataSet)Context.getService(DataSetDefinitionService.class).evaluate(d,null);
  for (  DataSetRow row : result.getRows()) {
    Integer encounterId=(Integer)row.getColumnValue("String_Node_Str");
    Encounter e=Context.getEncounterService().getEncounter(encounterId);
    List<String> obsValues=new ArrayList<String>();
    for (    DataSetColumn dsc : row.getColumnValues().keySet()) {
      String obsValue=row.getColumnValue(dsc).toString();
      if (StringUtils.isNotEmpty(obsValue)) {
        obsValues.add(obsValue);
      }
    }
    for (    Obs obs : e.getObs()) {
      Concept obsCodedValue=obs.getValueCoded();
      String obsNonCodedValue=obs.getValueAsString(Context.getLocale());
      if ((obsCodedValue != null) || (obsNonCodedValue != null && StringUtils.isNotEmpty(obsNonCodedValue))) {
        if (obsCodedValue != null && obsValues.contains(obsCodedValue.toString())) {
          boolean obsRemoved=obsValues.remove(obsCodedValue.toString());
          boolean obsDateRemoved=obsValues.remove(obs.getObsDatetime().toString());
          boolean obsGroupRemoved=false;
          if (obs.getObsGroup() != null) {
            obsGroupRemoved=obsValues.remove(obs.getObsGroup().getId().toString());
          }
 else {
            obsGroupRemoved=true;
          }
          Assert.assertTrue(obsRemoved && obsDateRemoved && obsGroupRemoved);
        }
 else         if (obsValues.contains(obsNonCodedValue)) {
          boolean obsRemoved=obsValues.remove(obsNonCodedValue);
          boolean obsDateRemoved=obsValues.remove(obs.getObsDatetime().toString());
          boolean obsGroupRemoved=false;
          if (obs.getObsGroup() != null) {
            obsGroupRemoved=obsValues.remove(obs.getObsGroup().getId().toString());
          }
 else {
            obsGroupRemoved=true;
          }
          Assert.assertTrue(obsRemoved && obsDateRemoved && obsGroupRemoved);
        }
 else {
          Assert.assertFalse(true);
        }
      }
    }
    Assert.assertTrue(obsValues.size() == 5);
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getEncounterId().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getEncounterDatetime().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getLocation().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getProvider().getPersonName().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
    Assert.assertEquals(ObjectUtil.trimStringIfNeeded(e.getPatientId().toString(),maxColumnHeaderWidth),ObjectUtil.trimStringIfNeeded(row.getColumnValue("String_Node_Str").toString(),maxColumnHeaderWidth));
  }
}