Program: 86823
Project: 86823
Buggy source:
/** 
 * @see DataSetEvaluator#evaluate(DataSetDefinition,EvaluationContext)
 * @should evaluate a CohortIndicatorDataSetDefinition
 */
public MapDataSet evaluate(DataSetDefinition dataSetDefinition,EvaluationContext context){
  CohortIndicatorDataSetDefinition dsd=(CohortIndicatorDataSetDefinition)dataSetDefinition;
  context=ObjectUtil.nvl(context,new EvaluationContext());
  if (context.getBaseCohort() == null || context.getBaseCohort().isEmpty()) {
    context.setBaseCohort(Context.getPatientSetService().getAllPatients());
  }
  IndicatorService is=Context.getService(IndicatorService.class);
  DimensionService ds=Context.getService(DimensionService.class);
  MapDataSet ret=new MapDataSet(dataSetDefinition,context);
  for (  DataSetColumn dsc : dsd.getColumns()) {
    ret.getMetaData().addColumn(dsc);
  }
  Map<String,Map<String,Cohort>> dimensionCalculationCache=new HashMap<String,Map<String,Cohort>>();
  for (  Map.Entry<String,Mapped<CohortDefinitionDimension>> e : dsd.getDimensions().entrySet()) {
    String dimensionKey=e.getKey();
    CohortDimensionResult dim=(CohortDimensionResult)ds.evaluate(e.getValue(),context);
    dimensionCalculationCache.put(dimensionKey,dim.getOptionCohorts());
  }
  Map<Mapped<? extends CohortIndicator>,CohortIndicatorResult> indicatorCalculationCache=new HashMap<Mapped<? extends CohortIndicator>,CohortIndicatorResult>();
  for (  DataSetColumn c : dsd.getColumns()) {
    CohortIndicatorAndDimensionColumn col=(CohortIndicatorAndDimensionColumn)c;
    if (!indicatorCalculationCache.containsKey(col.getIndicator())) {
      CohortIndicatorResult result=(CohortIndicatorResult)is.evaluate(col.getIndicator(),context);
      log.debug("String_Node_Str" + col.getIndicator());
      indicatorCalculationCache.put(col.getIndicator(),result);
    }
  }
  for (  DataSetColumn c : dsd.getColumns()) {
    CohortIndicatorAndDimensionColumn col=(CohortIndicatorAndDimensionColumn)c;
    CohortIndicatorResult result=indicatorCalculationCache.get(col.getIndicator());
    CohortIndicatorAndDimensionResult resultWithDimensions=new CohortIndicatorAndDimensionResult(result,context);
    if (col.getDimensionOptions() != null) {
      for (      Map.Entry<String,String> e : col.getDimensionOptions().entrySet()) {
        log.debug("String_Node_Str" + e.getKey() + "String_Node_Str"+ e.getValue());
        CohortDefinitionDimension dimension=dsd.getDimension(e.getKey()).getParameterizable();
        Cohort dimensionCohort=dimensionCalculationCache.get(e.getKey()).get(e.getValue());
        resultWithDimensions.addDimensionResult(dimension,dimensionCohort);
      }
    }
    ret.addData(col,resultWithDimensions);
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * @see DataSetEvaluator#evaluate(DataSetDefinition,EvaluationContext)
 * @should evaluate a CohortIndicatorDataSetDefinition
 */
public MapDataSet evaluate(DataSetDefinition dataSetDefinition,EvaluationContext context){
  CohortIndicatorDataSetDefinition dsd=(CohortIndicatorDataSetDefinition)dataSetDefinition;
  context=ObjectUtil.nvl(context,new EvaluationContext());
  if (context.getBaseCohort() == null) {
    context.setBaseCohort(Context.getPatientSetService().getAllPatients());
  }
  IndicatorService is=Context.getService(IndicatorService.class);
  DimensionService ds=Context.getService(DimensionService.class);
  MapDataSet ret=new MapDataSet(dataSetDefinition,context);
  for (  DataSetColumn dsc : dsd.getColumns()) {
    ret.getMetaData().addColumn(dsc);
  }
  Map<String,Map<String,Cohort>> dimensionCalculationCache=new HashMap<String,Map<String,Cohort>>();
  for (  Map.Entry<String,Mapped<CohortDefinitionDimension>> e : dsd.getDimensions().entrySet()) {
    String dimensionKey=e.getKey();
    CohortDimensionResult dim=(CohortDimensionResult)ds.evaluate(e.getValue(),context);
    dimensionCalculationCache.put(dimensionKey,dim.getOptionCohorts());
  }
  Map<Mapped<? extends CohortIndicator>,CohortIndicatorResult> indicatorCalculationCache=new HashMap<Mapped<? extends CohortIndicator>,CohortIndicatorResult>();
  for (  DataSetColumn c : dsd.getColumns()) {
    CohortIndicatorAndDimensionColumn col=(CohortIndicatorAndDimensionColumn)c;
    if (!indicatorCalculationCache.containsKey(col.getIndicator())) {
      CohortIndicatorResult result=(CohortIndicatorResult)is.evaluate(col.getIndicator(),context);
      log.debug("String_Node_Str" + col.getIndicator());
      indicatorCalculationCache.put(col.getIndicator(),result);
    }
  }
  for (  DataSetColumn c : dsd.getColumns()) {
    CohortIndicatorAndDimensionColumn col=(CohortIndicatorAndDimensionColumn)c;
    CohortIndicatorResult result=indicatorCalculationCache.get(col.getIndicator());
    CohortIndicatorAndDimensionResult resultWithDimensions=new CohortIndicatorAndDimensionResult(result,context);
    if (col.getDimensionOptions() != null) {
      for (      Map.Entry<String,String> e : col.getDimensionOptions().entrySet()) {
        log.debug("String_Node_Str" + e.getKey() + "String_Node_Str"+ e.getValue());
        CohortDefinitionDimension dimension=dsd.getDimension(e.getKey()).getParameterizable();
        Cohort dimensionCohort=dimensionCalculationCache.get(e.getKey()).get(e.getValue());
        resultWithDimensions.addDimensionResult(dimension,dimensionCohort);
      }
    }
    ret.addData(col,resultWithDimensions);
  }
  return ret;
}