@Override
  public String allowDeleteProgram(Program program) {
    Collection<CaseAggregationCondition> conditions =
        aggregationConditionService.getAllCaseAggregationCondition();

    for (CaseAggregationCondition condition : conditions) {
      Collection<Program> programs =
          aggregationConditionService.getProgramsInCondition(condition.getAggregationExpression());

      if (programs != null && programs.contains(program)) {
        return condition.getName();
      }
    }

    return null;
  }
  @Override
  public String allowDeletePatientAttribute(PatientAttribute patientAttribute) {
    Collection<CaseAggregationCondition> conditions =
        aggregationConditionService.getAllCaseAggregationCondition();

    for (CaseAggregationCondition condition : conditions) {
      Collection<PatientAttribute> patientAttributes =
          aggregationConditionService.getPatientAttributesInCondition(
              condition.getAggregationExpression());

      if (patientAttributes != null && patientAttributes.contains(patientAttribute)) {
        return condition.getName();
      }
    }

    return null;
  }
  @Override
  public String allowDeleteDataElementCategoryCombo(DataElementCategoryCombo categoryCombo) {
    Collection<CaseAggregationCondition> conditions =
        aggregationConditionService.getAllCaseAggregationCondition();

    for (CaseAggregationCondition condition : conditions) {
      if (categoryCombo.getOptionCombos().contains(condition.getOptionCombo())) {
        return ERROR;
      }
    }

    return null;
  }
  @Override
  public String allowDeleteDataElement(DataElement dataElement) {
    Collection<CaseAggregationCondition> conditions =
        aggregationConditionService.getCaseAggregationCondition(dataElement);

    if (conditions != null && conditions.size() > 0) {
      return ERROR;
    }

    conditions = aggregationConditionService.getAllCaseAggregationCondition();

    for (CaseAggregationCondition condition : conditions) {
      Collection<DataElement> dataElements =
          aggregationConditionService.getDataElementsInCondition(
              condition.getAggregationExpression());

      if (dataElements != null && dataElements.contains(dataElement)) {
        return ERROR;
      }
    }

    return null;
  }