@Override
  public List<DataElementOperand> validateRequiredComments(
      DataSet dataSet,
      Period period,
      OrganisationUnit organisationUnit,
      DataElementCategoryOptionCombo attributeOptionCombo) {
    List<DataElementOperand> violations = new ArrayList<>();

    if (dataSet.isNoValueRequiresComment()) {
      for (DataElement de : dataSet.getDataElements()) {
        for (DataElementCategoryOptionCombo co : de.getCategoryCombo().getOptionCombos()) {
          DataValue dv =
              dataValueService.getDataValue(de, period, organisationUnit, co, attributeOptionCombo);

          boolean missingValue = dv == null || StringUtils.trimToNull(dv.getValue()) == null;
          boolean missingComment = dv == null || StringUtils.trimToNull(dv.getComment()) == null;

          if (missingValue && missingComment) {
            violations.add(new DataElementOperand(de, co));
          }
        }
      }
    }

    return violations;
  }
  @Test
  public void testAverageIntDataElement() {
    DataElement dataElement = createDataElement('A', categoryCombo);

    dataElement.setType(DataElement.VALUE_TYPE_INT);
    dataElement.setAggregationOperator(DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM);

    dataElementIds.add(dataElementService.addDataElement(dataElement));

    DataSet dataSet = createDataSet('A', new YearlyPeriodType());
    dataSet.getDataElements().add(dataElement);
    dataSetService.addDataSet(dataSet);
    dataElement.getDataSets().add(dataSet);
    dataElementService.updateDataElement(dataElement);

    Period dataPeriod =
        createPeriod(new YearlyPeriodType(), getDate(2000, 1, 1), getDate(2000, 12, 31));

    OrganisationUnit unit = createOrganisationUnit('A');

    organisationUnitIds.add(organisationUnitService.addOrganisationUnit(unit));

    dataValueService.addDataValue(
        createDataValue(dataElement, dataPeriod, unit, "100", categoryOptionCombo));

    Period periodA =
        createPeriod(new MonthlyPeriodType(), getDate(2000, 3, 1), getDate(2000, 3, 31));
    Period periodB =
        createPeriod(new MonthlyPeriodType(), getDate(2000, 4, 1), getDate(2000, 4, 30));
    Period periodC =
        createPeriod(new QuarterlyPeriodType(), getDate(2000, 3, 1), getDate(2000, 5, 31));

    periodIds.add(periodService.addPeriod(periodA));
    periodIds.add(periodService.addPeriod(periodB));
    periodIds.add(periodService.addPeriod(periodC));

    dataMartEngine.export(dataElementIds, indicatorIds, periodIds, organisationUnitIds);

    assertEquals(
        100.0,
        aggregatedDataValueService.getAggregatedValue(
            dataElement, categoryOptionCombo, periodA, unit),
        DELTA);
    assertEquals(
        100.0,
        aggregatedDataValueService.getAggregatedValue(
            dataElement, categoryOptionCombo, periodB, unit),
        DELTA);
    assertEquals(
        100.0,
        aggregatedDataValueService.getAggregatedValue(
            dataElement, categoryOptionCombo, periodC, unit),
        DELTA);
  }
Esempio n. 3
0
  public DataElement getDataElement(org.hisp.dhis.dataelement.DataElement dataElement) {
    DataElement de = new DataElement();
    de.setId(dataElement.getId());
    de.setName(dataElement.getFormNameFallback());
    de.setType(dataElement.getType());

    de.setCategoryOptionCombos(getCategoryOptionCombos(dataElement));

    // Limit the optionset transfer to the client
    if (dataElement.getOptionSet() != null
        && dataElement.getOptionSet().getOptions().size() <= 50) {
      de.setOptionSet(getOptionSet(dataElement));
    }

    return de;
  }
  public String execute() {
    dataElementList =
        new ArrayList<DataElement>(
            programStageDataElementService.getListDataElement(
                programStageService.getProgramStage(psId)));

    if (dataElementList != null && !dataElementList.isEmpty()) {
      Iterator<DataElement> deIterator = dataElementList.iterator();

      while (deIterator.hasNext()) {
        DataElement de = deIterator.next();

        if (!de.getType().equals(DataElement.VALUE_TYPE_INT)) {
          deIterator.remove();
        }
      }
    }

    return SUCCESS;
  }
Esempio n. 5
0
  public OptionSet getOptionSet(org.hisp.dhis.dataelement.DataElement dataElement) {
    org.hisp.dhis.option.OptionSet dhisOptionSet = dataElement.getOptionSet();
    OptionSet mobileOptionSet = new OptionSet();
    if (dhisOptionSet != null) {
      mobileOptionSet.setId(dhisOptionSet.getId());
      mobileOptionSet.setName(dhisOptionSet.getName());
      mobileOptionSet.setOptions(dhisOptionSet.getOptions());
    } else {
      return null;
    }

    return mobileOptionSet;
  }
Esempio n. 6
0
  public ModelList getCategoryOptionCombos(org.hisp.dhis.dataelement.DataElement dataElement) {
    DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();

    // Client DataElement
    ModelList deCateOptCombo = new ModelList();
    List<Model> listCateOptCombo = new ArrayList<Model>();
    deCateOptCombo.setModels(listCateOptCombo);

    for (DataElementCategoryOptionCombo oneCatOptCombo : categoryCombo.getSortedOptionCombos()) {
      Model oneCateOptCombo = new Model();
      oneCateOptCombo.setId(oneCatOptCombo.getId());
      oneCateOptCombo.setName(oneCatOptCombo.getName());
      listCateOptCombo.add(oneCateOptCombo);
    }
    return deCateOptCombo;
  }
  @Test
  public void averageIntDataElement() {
    dataElementA.setAggregationOperator(DataElement.AGGREGATION_OPERATOR_AVERAGE);
    dataElementService.updateDataElement(dataElementA);

    assertEquals(
        90.0,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, mar31, unitC),
        DELTA);
    assertEquals(
        105.0,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, mar31, unitF),
        DELTA);
    assertEquals(
        150.0,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, mar31, unitB),
        DELTA);

    assertEquals(
        85.2,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, may31, unitC),
        0.3);
    assertEquals(
        115.3,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, may31, unitF),
        0.3);
    assertEquals(
        193.3,
        aggregationService.getAggregatedDataValue(
            dataElementA, categoryOptionComboA, mar01, may31, unitB),
        0.6);
  }
  @Test
  public void averageBoolDataElement() {
    dataElementB.setAggregationOperator(DataElement.AGGREGATION_OPERATOR_AVERAGE);
    dataElementService.updateDataElement(dataElementB);

    assertEquals(
        1.0,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, mar31, unitC),
        DELTA);
    assertEquals(
        0.67,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, mar31, unitF),
        DELTA);
    assertEquals(
        0.6,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, mar31, unitB),
        DELTA);

    assertEquals(
        0.66,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, may31, unitC),
        DELTA);
    assertEquals(
        0.78,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, may31, unitF),
        DELTA);
    assertEquals(
        0.67,
        aggregationService.getAggregatedDataValue(
            dataElementB, categoryOptionComboA, mar01, may31, unitB),
        DELTA);
  }
  @Override
  public String execute() {
    if (dataElementGroupId > 0) {
      DataElementGroup group =
          dataElementService.getDataElementGroup(dataElementGroupId.intValue());

      dataElements = new ArrayList<>(group.getMembers());
    } else {
      dataElements = new ArrayList<>(dataElementService.getAllDataElements());
    }

    Collections.sort(dataElements, new IdentifiableObjectNameComparator());

    for (DataElement dataElement : dataElements) {
      DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();

      Set<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getOptionCombos();

      if (optionCombos.size() > 1) {
        for (DataElementCategoryOptionCombo optionCombo : optionCombos) {
          DataElementOperand operand =
              new DataElementOperand(
                  dataElement.getUid(),
                  optionCombo.getUid(),
                  dataElement.getName() + optionCombo.getName());
          operands.add(operand);
        }
      } else {
        DataElementOperand operand =
            new DataElementOperand(
                dataElement.getUid(),
                optionCombos.iterator().next().getUid(),
                dataElement.getName());
        operands.add(operand);
      }
    }

    return SUCCESS;
  }
  @Override
  public void setUpTest() {
    aggregationService = (AggregationService) getBean(AggregationService.ID);

    categoryService = (DataElementCategoryService) getBean(DataElementCategoryService.ID);

    dataElementService = (DataElementService) getBean(DataElementService.ID);

    indicatorService = (IndicatorService) getBean(IndicatorService.ID);

    dataSetService = (DataSetService) getBean(DataSetService.ID);

    periodService = (PeriodService) getBean(PeriodService.ID);

    organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);

    dataValueService = (DataValueService) getBean(DataValueService.ID);

    expressionService = (ExpressionService) getBean(ExpressionService.ID);

    // ---------------------------------------------------------------------
    // Setup Dimensions
    // ---------------------------------------------------------------------

    categoryOptionA = new DataElementCategoryOption("Male");
    categoryOptionB = new DataElementCategoryOption("Female");

    categoryService.addDataElementCategoryOption(categoryOptionA);
    categoryService.addDataElementCategoryOption(categoryOptionB);

    category = new DataElementCategory("Gender");
    category.getCategoryOptions().add(categoryOptionA);
    category.getCategoryOptions().add(categoryOptionB);

    categoryService.addDataElementCategory(category);

    categoryCombo = new DataElementCategoryCombo("Gender");
    categoryCombo.getCategories().add(category);

    categoryService.addDataElementCategoryCombo(categoryCombo);

    categoryOptionComboA = createCategoryOptionCombo(categoryCombo, categoryOptionA);
    categoryOptionComboB = createCategoryOptionCombo(categoryCombo, categoryOptionB);

    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboB);

    // ---------------------------------------------------------------------
    // Setup DataElements
    // ---------------------------------------------------------------------

    dataElementA =
        createDataElement(
            'A', DataElement.VALUE_TYPE_INT, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo);
    dataElementB =
        createDataElement(
            'B', DataElement.VALUE_TYPE_BOOL, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo);
    dataElementC =
        createDataElement(
            'C', DataElement.VALUE_TYPE_INT, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo);

    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);

    // ---------------------------------------------------------------------
    // Setup Indicators
    // ---------------------------------------------------------------------

    indicatorType = createIndicatorType('A');
    indicatorType.setFactor(100);

    indicatorService.addIndicatorType(indicatorType);

    indicatorA = createIndicator('A', indicatorType);
    indicatorA.setNumerator(
        "#{" + dataElementA.getUid() + SEPARATOR + categoryOptionComboA.getUid() + "}+150");
    indicatorA.setDenominator(
        "#{" + dataElementB.getUid() + SEPARATOR + categoryOptionComboA.getUid() + "}");

    indicatorB = createIndicator('B', indicatorType);
    indicatorB.setNumerator("#{" + dataElementC.getUid() + "}");
    indicatorB.setDenominator("1");

    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);

    // ---------------------------------------------------------------------
    // Setup DataSets (to get correct PeriodType for DataElements)
    // ---------------------------------------------------------------------

    dataSet = createDataSet('A', new MonthlyPeriodType());
    dataSet.getDataElements().add(dataElementA);
    dataSet.getDataElements().add(dataElementB);
    dataSetService.addDataSet(dataSet);
    dataElementA.getDataSets().add(dataSet);
    dataElementB.getDataSets().add(dataSet);
    dataElementC.getDataSets().add(dataSet);
    dataElementService.updateDataElement(dataElementA);
    dataElementService.updateDataElement(dataElementB);
    dataElementService.updateDataElement(dataElementC);

    // ---------------------------------------------------------------------
    // Setup Periods
    // ---------------------------------------------------------------------

    PeriodType monthly = new MonthlyPeriodType();

    periodA = createPeriod(monthly, mar01, mar31);
    periodB = createPeriod(monthly, apr01, apr30);
    periodC = createPeriod(monthly, may01, may31);

    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    periodService.addPeriod(periodC);

    // ---------------------------------------------------------------------
    // Setup OrganisationUnits
    // ---------------------------------------------------------------------

    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitA);
    unitD = createOrganisationUnit('D', unitB);
    unitE = createOrganisationUnit('E', unitB);
    unitF = createOrganisationUnit('F', unitB);
    unitG = createOrganisationUnit('G', unitF);
    unitH = createOrganisationUnit('H', unitF);
    unitI = createOrganisationUnit('I');

    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    organisationUnitService.addOrganisationUnit(unitC);
    organisationUnitService.addOrganisationUnit(unitD);
    organisationUnitService.addOrganisationUnit(unitE);
    organisationUnitService.addOrganisationUnit(unitF);
    organisationUnitService.addOrganisationUnit(unitG);
    organisationUnitService.addOrganisationUnit(unitH);
    organisationUnitService.addOrganisationUnit(unitI);

    // ---------------------------------------------------------------------
    // Setup DataValues
    // ---------------------------------------------------------------------

    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitC, "90", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitD, "10", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitE, "35", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitF, "25", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitG, "20", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodA, unitH, "60", categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitC, "70", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitD, "40", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitE, "65", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitF, "55", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitG, "20", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodB, unitH, "15", categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitC, "95", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitD, "40", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitE, "45", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitF, "30", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitG, "50", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementA, periodC, unitH, "70", categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitC, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitD, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitE, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitF, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitG, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodA, unitH, T, categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitC, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitD, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitE, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitF, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitG, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodB, unitH, T, categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitC, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitD, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitE, F, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitF, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitG, T, categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementB, periodC, unitH, T, categoryOptionComboA));

    dataValueService.addDataValue(
        createDataValue(dataElementC, periodA, unitB, "30", categoryOptionComboA));
    dataValueService.addDataValue(
        createDataValue(dataElementC, periodA, unitB, "20", categoryOptionComboB));

    aggregationService.clearCache();
  }
  @Transactional
  public void matchObject(int importObjectId, int existingObjectId) {
    ImportObject importObject = importObjectStore.getImportObject(importObjectId);

    Object object = importObject.getObject();

    // ---------------------------------------------------------------------
    // Updates the name of the import object to the name of the existing
    // object.
    // ---------------------------------------------------------------------

    if (object.getClass().equals(DataElement.class)) {
      DataElement element = (DataElement) object;

      element.setName(dataElementService.getDataElement(existingObjectId).getName());
    } else if (object.getClass().equals(DataElementGroup.class)) {
      DataElementGroup group = (DataElementGroup) object;

      group.setName(dataElementService.getDataElementGroup(existingObjectId).getName());
    } else if (object.getClass().equals(DataElementGroupSet.class)) {
      DataElementGroupSet groupSet = (DataElementGroupSet) object;

      groupSet.setName(dataElementService.getDataElementGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorType.class)) {
      IndicatorType type = (IndicatorType) object;

      type.setName(indicatorService.getIndicatorType(existingObjectId).getName());
    } else if (object.getClass().equals(Indicator.class)) {
      Indicator indicator = (Indicator) object;

      indicator.setName(indicatorService.getIndicator(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorGroup.class)) {
      IndicatorGroup group = (IndicatorGroup) object;

      group.setName(indicatorService.getIndicatorGroup(existingObjectId).getName());
    } else if (object.getClass().equals(IndicatorGroupSet.class)) {
      IndicatorGroupSet groupSet = (IndicatorGroupSet) object;

      groupSet.setName(indicatorService.getIndicatorGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(DataDictionary.class)) {
      DataDictionary dictionary = (DataDictionary) object;

      dictionary.setName(dataDictionaryService.getDataDictionary(existingObjectId).getName());
    } else if (object.getClass().equals(DataSet.class)) {
      DataSet dataSet = (DataSet) object;

      dataSet.setName(dataSetService.getDataSet(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnit.class)) {
      OrganisationUnit unit = (OrganisationUnit) object;

      unit.setName(organisationUnitService.getOrganisationUnit(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitGroup.class)) {
      OrganisationUnitGroup group = (OrganisationUnitGroup) object;

      group.setName(
          organisationUnitGroupService.getOrganisationUnitGroup(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitGroupSet.class)) {
      OrganisationUnitGroupSet groupSet = (OrganisationUnitGroupSet) object;

      groupSet.setName(
          organisationUnitGroupService.getOrganisationUnitGroupSet(existingObjectId).getName());
    } else if (object.getClass().equals(OrganisationUnitLevel.class)) {
      OrganisationUnitLevel level = (OrganisationUnitLevel) object;

      level.setName(organisationUnitService.getOrganisationUnitLevel(existingObjectId).getName());
    } else if (object.getClass().equals(ValidationRule.class)) {
      ValidationRule validationRule = (ValidationRule) object;

      validationRule.setName(validationRuleService.getValidationRule(existingObjectId).getName());
    } else if (object.getClass().equals(Report.class)) {
      Report report = (Report) object;

      report.setName(reportService.getReport(existingObjectId).getName());
    } else if (object.getClass().equals(ReportTable.class)) {
      ReportTable reportTable = (ReportTable) object;

      reportTable.setName(reportTableService.getReportTable(existingObjectId).getName());
    } else if (object.getClass().equals(Chart.class)) {
      Chart chart = (Chart) object;

      chart.setName(chartService.getChart(existingObjectId).getName());
    } else if (object.getClass().equals(DataValue.class)) {
      DataValue dataValue = (DataValue) object;

      dataValue =
          updateDataValue(
              dataValue,
              dataValueService.getDataValue(
                  dataValue.getSource(),
                  dataValue.getDataElement(),
                  dataValue.getPeriod(),
                  dataValue.getOptionCombo()));
    }

    // ---------------------------------------------------------------------
    // Sets the status of the import object to match, these objects will
    // later be ignored on import all but is needed for matching of
    // associations.
    // ---------------------------------------------------------------------

    importObject.setStatus(ImportObjectStatus.MATCH);

    importObjectStore.updateImportObject(importObject);
  }
Esempio n. 12
0
  /** TODO replace string value type on data element with ValueType and remove this method. */
  public static ValueType getFromDataElement(DataElement dataElement) {
    if (DataElement.VALUE_TYPE_STRING.equals(dataElement.getType())) {
      if (DataElement.VALUE_TYPE_LONG_TEXT.equals(dataElement.getTextType())) {
        return ValueType.LONG_TEXT;
      } else {
        return ValueType.TEXT;
      }
    } else if (DataElement.VALUE_TYPE_INT.equals(dataElement.getType())) {
      if (DataElement.VALUE_TYPE_UNIT_INTERVAL.equals(dataElement.getNumberType())) {
        return ValueType.UNIT_INTERVAL;
      } else if (DataElement.VALUE_TYPE_PERCENTAGE.equals(dataElement.getNumberType())) {
        return ValueType.PERCENTAGE;
      } else if (DataElement.VALUE_TYPE_INT.equals(dataElement.getNumberType())) {
        return ValueType.INTEGER;
      } else if (DataElement.VALUE_TYPE_POSITIVE_INT.equals(dataElement.getNumberType())) {
        return ValueType.INTEGER_POSITIVE;
      } else if (DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT.equals(dataElement.getNumberType())) {
        return ValueType.INTEGER_ZERO_OR_POSITIVE;
      } else if (DataElement.VALUE_TYPE_NEGATIVE_INT.equals(dataElement.getNumberType())) {
        return ValueType.INTEGER_NEGATIVE;
      } else {
        return ValueType.NUMBER;
      }
    } else if (DataElement.VALUE_TYPE_BOOL.equals(dataElement.getType())) {
      return ValueType.BOOLEAN;
    } else if (DataElement.VALUE_TYPE_TRUE_ONLY.equals(dataElement.getType())) {
      return ValueType.TRUE_ONLY;
    } else if (DataElement.VALUE_TYPE_DATE.equals(dataElement.getType())) {
      return ValueType.DATE;
    } else if (DataElement.VALUE_TYPE_DATETIME.equals(dataElement.getType())) {
      return ValueType.DATETIME;
    }

    return ValueType.TEXT; // Fall back
  }
  @Override
  public void setUpTest() {
    // ---------------------------------------------------------------------
    // Services
    // ---------------------------------------------------------------------

    dataIntegrityService = (DataIntegrityService) getBean(DataIntegrityService.ID);
    dataElementService = (DataElementService) getBean(DataElementService.ID);
    indicatorService = (IndicatorService) getBean(IndicatorService.ID);
    dataSetService = (DataSetService) getBean(DataSetService.ID);
    organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);
    organisationUnitGroupService =
        (OrganisationUnitGroupService) getBean(OrganisationUnitGroupService.ID);

    // ---------------------------------------------------------------------
    // Objects
    // ---------------------------------------------------------------------

    elementA = createDataElement('A');
    elementB = createDataElement('B');
    elementC = createDataElement('C');

    dataElementService.addDataElement(elementA);
    dataElementService.addDataElement(elementB);
    dataElementService.addDataElement(elementC);

    indicatorTypeA = createIndicatorType('A');

    indicatorService.addIndicatorType(indicatorTypeA);

    indicatorA = createIndicator('A', indicatorTypeA);
    indicatorB = createIndicator('B', indicatorTypeA);
    indicatorC = createIndicator('C', indicatorTypeA);

    indicatorA.setNumerator(" ");
    indicatorB.setNumerator("Numerator");
    indicatorB.setDenominator("Denominator");
    indicatorC.setNumerator("Numerator");
    indicatorC.setDenominator("Denominator");

    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);

    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B', unitA);
    unitC = createOrganisationUnit('C', unitB);
    unitD = createOrganisationUnit('D', unitC);
    unitE = createOrganisationUnit('E', unitD);
    unitF = createOrganisationUnit('F');

    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    organisationUnitService.addOrganisationUnit(unitC);
    organisationUnitService.addOrganisationUnit(unitD);
    organisationUnitService.addOrganisationUnit(unitE);
    organisationUnitService.addOrganisationUnit(unitF);

    unitA.setParent(unitC);

    organisationUnitService.updateOrganisationUnit(unitA);

    dataSetA = createDataSet('A', new MonthlyPeriodType());
    dataSetB = createDataSet('B', new QuarterlyPeriodType());

    dataSetA.getDataElements().add(elementA);
    dataSetA.getDataElements().add(elementB);
    elementA.getDataSets().add(dataSetA);
    elementB.getDataSets().add(dataSetA);

    dataSetA.getSources().add(unitA);
    unitA.getDataSets().add(dataSetA);

    dataSetB.getDataElements().add(elementA);
    elementA.getDataSets().add(dataSetB);

    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);

    // ---------------------------------------------------------------------
    // Groups
    // ---------------------------------------------------------------------

    elementGroupA = createDataElementGroup('A');

    elementGroupA.getMembers().add(elementA);
    elementA.getGroups().add(elementGroupA);

    dataElementService.addDataElementGroup(elementGroupA);

    indicatorGroupA = createIndicatorGroup('A');

    indicatorGroupA.getMembers().add(indicatorA);
    indicatorA.getGroups().add(indicatorGroupA);

    indicatorService.addIndicatorGroup(indicatorGroupA);

    unitGroupA = createOrganisationUnitGroup('A');
    unitGroupB = createOrganisationUnitGroup('B');
    unitGroupC = createOrganisationUnitGroup('C');
    unitGroupD = createOrganisationUnitGroup('D');

    unitGroupA.getMembers().add(unitA);
    unitGroupA.getMembers().add(unitB);
    unitGroupA.getMembers().add(unitC);
    unitA.getGroups().add(unitGroupA);
    unitB.getGroups().add(unitGroupA);
    unitC.getGroups().add(unitGroupA);

    unitGroupB.getMembers().add(unitA);
    unitGroupB.getMembers().add(unitB);
    unitGroupB.getMembers().add(unitF);
    unitA.getGroups().add(unitGroupB);
    unitB.getGroups().add(unitGroupB);
    unitF.getGroups().add(unitGroupB);

    unitGroupC.getMembers().add(unitA);
    unitA.getGroups().add(unitGroupC);

    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupC);
    organisationUnitGroupService.addOrganisationUnitGroup(unitGroupD);

    // ---------------------------------------------------------------------
    // Group sets
    // ---------------------------------------------------------------------

    unitGroupSetA = createOrganisationUnitGroupSet('A');
    unitGroupSetB = createOrganisationUnitGroupSet('B');

    unitGroupSetA.setCompulsory(true);
    unitGroupSetB.setCompulsory(false);

    unitGroupSetA.getOrganisationUnitGroups().add(unitGroupA);
    unitGroupA.setGroupSet(unitGroupSetA);

    unitGroupSetB.getOrganisationUnitGroups().add(unitGroupB);
    unitGroupSetB.getOrganisationUnitGroups().add(unitGroupC);
    unitGroupB.setGroupSet(unitGroupSetB);
    unitGroupC.setGroupSet(unitGroupSetB);

    organisationUnitGroupService.addOrganisationUnitGroupSet(unitGroupSetA);
    organisationUnitGroupService.addOrganisationUnitGroupSet(unitGroupSetB);
  }
  @Transactional
  public void cascadeDeleteImportObject(int importObjectId) {
    ImportObject importObject = importObjectStore.getImportObject(importObjectId);

    if (importObject != null) {
      if (importObject.getClassName().equals(DataElement.class.getName())) {
        DataElement element = (DataElement) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.DATAELEMENTGROUP, element.getId());
        deleteMemberAssociations(GroupMemberType.DATASET, element.getId());
        deleteMemberAssociations(GroupMemberType.DATADICTIONARY_DATAELEMENT, element.getId());

        deleteIndicatorsContainingDataElement(element.getId());

        importDataValueService.deleteImportDataValuesByDataElement(element.getId());
      } else if (importObject.getClassName().equals(DataElementGroup.class.getName())) {
        DataElementGroup group = (DataElementGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATAELEMENTGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.DATAELEMENTGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(DataElementGroupSet.class.getName())) {
        DataElementGroupSet groupSet = (DataElementGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATAELEMENTGROUPSET, groupSet.getId());
      } else if (importObject.getClassName().equals(IndicatorType.class.getName())) {
        IndicatorType type = (IndicatorType) importObject.getObject();

        deleteIndicatorsWithIndicatorType(type.getId());
      } else if (importObject.getClassName().equals(Indicator.class.getName())) {
        Indicator indicator = (Indicator) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.INDICATORGROUP, indicator.getId());
        deleteMemberAssociations(GroupMemberType.DATADICTIONARY_INDICATOR, indicator.getId());
      } else if (importObject.getClassName().equals(IndicatorGroup.class.getName())) {
        IndicatorGroup group = (IndicatorGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.INDICATORGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.INDICATORGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(IndicatorGroupSet.class.getName())) {
        IndicatorGroupSet groupSet = (IndicatorGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.INDICATORGROUPSET, groupSet.getId());
      } else if (importObject.getClassName().equals(DataDictionary.class.getName())) {
        DataDictionary dictionary = (DataDictionary) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATADICTIONARY_DATAELEMENT, dictionary.getId());
        deleteGroupAssociations(GroupMemberType.DATADICTIONARY_INDICATOR, dictionary.getId());
      } else if (importObject.getClassName().equals(DataSet.class.getName())) {
        DataSet dataSet = (DataSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.DATASET, dataSet.getId());
        deleteMemberAssociations(GroupMemberType.DATASET_SOURCE, dataSet.getId());

        deleteCompleteDataSetRegistrationsByDataSet(dataSet.getId());
      } else if (importObject.getClassName().equals(OrganisationUnit.class.getName())) {
        OrganisationUnit unit = (OrganisationUnit) importObject.getObject();

        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITGROUP, unit.getId());
        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITRELATIONSHIP, unit.getId());
        deleteMemberAssociations(GroupMemberType.DATASET_SOURCE, unit.getId());
        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITRELATIONSHIP, unit.getId());

        deleteCompleteDataSetRegistrationsBySource(unit.getId());

        importDataValueService.deleteImportDataValuesBySource(unit.getId());
      } else if (importObject.getClassName().equals(OrganisationUnitGroup.class.getName())) {
        OrganisationUnitGroup group = (OrganisationUnitGroup) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITGROUP, group.getId());
        deleteMemberAssociations(GroupMemberType.ORGANISATIONUNITGROUPSET, group.getId());
      } else if (importObject.getClassName().equals(OrganisationUnitGroupSet.class.getName())) {
        OrganisationUnitGroupSet groupSet = (OrganisationUnitGroupSet) importObject.getObject();

        deleteGroupAssociations(GroupMemberType.ORGANISATIONUNITGROUPSET, groupSet.getId());
      }
    }

    deleteImportObject(importObjectId);
  }
 @Override
 public boolean retain(DataElement object) {
   return object != null && VALUE_TYPES.contains(object.getValueType());
 }
Esempio n. 16
0
  /**
   * Creates a table with the given data element
   *
   * @param element The data element
   * @param i18n i18n object
   * @param HEADER3 The header3 font
   * @param ITALIC The italic font
   * @param TEXT The text font
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printDataElement(
      DataElement element, I18n i18n, boolean keepTogether, float... columnWidths) {
    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(element.getName(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("short_name")));
    table.addCell(getTextCell(element.getShortName()));

    if (nullIfEmpty(element.getCode()) != null) {
      table.addCell(getItalicCell(i18n.getString("code")));
      table.addCell(getTextCell(element.getCode()));
    }
    if (nullIfEmpty(element.getDescription()) != null) {
      table.addCell(getItalicCell(i18n.getString("description")));
      table.addCell(getTextCell(element.getDescription()));
    }

    if (nullIfEmpty(element.getType()) != null) {
      table.addCell(getItalicCell(i18n.getString("value_type")));
      table.addCell(getTextCell(i18n.getString(getType().get(element.getType()))));
    }
    if (nullIfEmpty(element.getAggregationOperator()) != null) {
      table.addCell(getItalicCell(i18n.getString("aggregation_operator")));
      table.addCell(
          getTextCell(
              i18n.getString(getAggregationOperator().get(element.getAggregationOperator()))));
    }

    for (AttributeValue value : element.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }
  @Override
  public void setUpTest() {
    // ---------------------------------------------------------------------
    // Services
    // ---------------------------------------------------------------------

    importObjectService = (ImportObjectService) getBean(ImportObjectService.ID);

    batchHandlerFactory = (BatchHandlerFactory) getBean("batchHandlerFactory");

    dataElementService = (DataElementService) getBean(DataElementService.ID);

    categoryService = (DataElementCategoryService) getBean(DataElementCategoryService.ID);

    periodService = (PeriodService) getBean(PeriodService.ID);

    organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);

    dataValueService = (DataValueService) getBean(DataValueService.ID);

    // ---------------------------------------------------------------------
    // CategoryOption
    // ---------------------------------------------------------------------

    categoryOptionA = new DataElementCategoryOption("CategoryOptionA");
    categoryOptionB = new DataElementCategoryOption("CategoryOptionB");
    categoryOptionC = new DataElementCategoryOption("CategoryOptionC");
    categoryOptionD = new DataElementCategoryOption("CategoryOptionD");

    categoryService.addDataElementCategoryOption(categoryOptionA);
    categoryService.addDataElementCategoryOption(categoryOptionB);
    categoryService.addDataElementCategoryOption(categoryOptionC);
    categoryService.addDataElementCategoryOption(categoryOptionD);

    categoryOptionADuplicate = new DataElementCategoryOption("CategoryOptionA");
    categoryOptionBDuplicate = new DataElementCategoryOption("CategoryOptionB");
    categoryOptionCDuplicate = new DataElementCategoryOption("CategoryOptionC");
    categoryOptionDDuplicate = new DataElementCategoryOption("CategoryOptionD");

    categoryOptionADuplicate.setId('A');
    categoryOptionBDuplicate.setId('B');
    categoryOptionCDuplicate.setId('C');
    categoryOptionDDuplicate.setId('D');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionBDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionCDuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryOptionDDuplicate, null);

    // ---------------------------------------------------------------------
    // Category
    // ---------------------------------------------------------------------

    categoryA = new DataElementCategory("CategoryA");
    categoryB = new DataElementCategory("CategoryB");

    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);

    categoryService.addDataElementCategory(categoryA);
    categoryService.addDataElementCategory(categoryB);

    categoryADuplicate = new DataElementCategory("CategoryA");
    categoryBDuplicate = new DataElementCategory("CategoryB");

    categoryADuplicate.setId('A');
    categoryBDuplicate.setId('B');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryBDuplicate, null);

    // ---------------------------------------------------------------------
    // Category - CategoryOption Association
    // ---------------------------------------------------------------------

    categoryCategoryOptionAssociationA = new GroupMemberAssociation('A', 'A', 1);
    categoryCategoryOptionAssociationB = new GroupMemberAssociation('A', 'B', 2);
    categoryCategoryOptionAssociationC = new GroupMemberAssociation('B', 'C', 1);
    categoryCategoryOptionAssociationD = new GroupMemberAssociation('B', 'D', 2);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationA);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationB);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationC);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORY_CATEGORYOPTION,
        categoryCategoryOptionAssociationD);

    // ---------------------------------------------------------------------
    // CategoryCombo
    // ---------------------------------------------------------------------

    categoryComboA = new DataElementCategoryCombo("CategoryComboA");
    categoryComboB = new DataElementCategoryCombo("CategoryComboB");

    categoryComboA.getCategories().add(categoryA);
    categoryComboA.getCategories().add(categoryB);
    categoryComboB.getCategories().add(categoryA);

    categoryService.addDataElementCategoryCombo(categoryComboA);
    categoryService.addDataElementCategoryCombo(categoryComboB);

    categoryComboADuplicate = new DataElementCategoryCombo("CategoryComboA");
    categoryComboBDuplicate = new DataElementCategoryCombo("CategoryComboB");

    categoryComboADuplicate.setId('A');
    categoryComboBDuplicate.setId('B');

    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryComboADuplicate, null);
    importObjectService.addImportObject(ImportObjectStatus.MATCH, categoryComboBDuplicate, null);

    // ---------------------------------------------------------------------
    // CategoryCombo - Category Association
    // ---------------------------------------------------------------------

    categoryComboCategoryAssociationA = new GroupMemberAssociation('A', 'A', 1);
    categoryComboCategoryAssociationB = new GroupMemberAssociation('A', 'B', 2);
    categoryComboCategoryAssociationC = new GroupMemberAssociation('B', 'A', 1);

    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationA);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationB);
    importObjectService.addImportObject(
        ImportObjectStatus.NEW,
        GroupMemberType.CATEGORYCOMBO_CATEGORY,
        categoryComboCategoryAssociationC);

    // ---------------------------------------------------------------------
    // CategoryOptionCombo
    // ---------------------------------------------------------------------

    categoryOptionComboA = new DataElementCategoryOptionCombo();
    categoryOptionComboB = new DataElementCategoryOptionCombo();
    categoryOptionComboC = new DataElementCategoryOptionCombo();
    categoryOptionComboD = new DataElementCategoryOptionCombo();

    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryOptionComboB.setCategoryCombo(categoryComboA);
    categoryOptionComboC.setCategoryCombo(categoryComboB);
    categoryOptionComboD.setCategoryCombo(categoryComboB);

    categoryOptionComboA.getCategoryOptions().add(categoryOptionA);
    categoryOptionComboA.getCategoryOptions().add(categoryOptionC);
    categoryOptionComboB.getCategoryOptions().add(categoryOptionB);
    categoryOptionComboB.getCategoryOptions().add(categoryOptionD);
    categoryOptionComboC.getCategoryOptions().add(categoryOptionA);
    categoryOptionComboD.getCategoryOptions().add(categoryOptionB);

    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboA);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboB);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboC);
    categoryService.addDataElementCategoryOptionCombo(categoryOptionComboD);

    categoryOptionComboADuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboBDuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboCDuplicate = new DataElementCategoryOptionCombo();
    categoryOptionComboDDuplicate = new DataElementCategoryOptionCombo();

    categoryOptionComboADuplicate.setId('A');
    categoryOptionComboBDuplicate.setId('B');
    categoryOptionComboCDuplicate.setId('C');
    categoryOptionComboDDuplicate.setId('D');

    categoryOptionComboADuplicate.setCategoryCombo(categoryComboADuplicate);
    categoryOptionComboBDuplicate.setCategoryCombo(categoryComboADuplicate);
    categoryOptionComboCDuplicate.setCategoryCombo(categoryComboBDuplicate);
    categoryOptionComboDDuplicate.setCategoryCombo(categoryComboBDuplicate);

    categoryOptionComboADuplicate.getCategoryOptions().add(categoryOptionADuplicate);
    categoryOptionComboADuplicate.getCategoryOptions().add(categoryOptionCDuplicate);
    categoryOptionComboBDuplicate.getCategoryOptions().add(categoryOptionBDuplicate);
    categoryOptionComboBDuplicate.getCategoryOptions().add(categoryOptionDDuplicate);
    categoryOptionComboCDuplicate.getCategoryOptions().add(categoryOptionADuplicate);
    categoryOptionComboDDuplicate.getCategoryOptions().add(categoryOptionBDuplicate);

    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboADuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboBDuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboCDuplicate, null);
    importObjectService.addImportObject(
        ImportObjectStatus.MATCH, categoryOptionComboDDuplicate, null);

    // ---------------------------------------------------------------------
    // DataElement
    // ---------------------------------------------------------------------

    dataElementA = createDataElement('A', categoryComboA);
    dataElementB = createDataElement('B', categoryComboA);
    dataElementC = createDataElement('C', categoryComboA);
    dataElementD = createDataElement('D', categoryComboA);

    dataElementAModified = createDataElement('A', categoryComboADuplicate);
    dataElementBModified = createDataElement('B', categoryComboADuplicate);
    dataElementCModified = createDataElement('C', categoryComboADuplicate);
    dataElementDModified = createDataElement('D', categoryComboADuplicate);

    dataElementAModified.setId('A');
    dataElementBModified.setId('B');
    dataElementCModified.setId('C');
    dataElementDModified.setId('D');

    dataElementAModified.setShortName("ShortNameModifiedA");
    dataElementBModified.setShortName("ShortNameModifiedB");
    dataElementCModified.setShortName("ShortNameModifiedC");
    dataElementDModified.setShortName("ShortNameModifiedD");

    // ---------------------------------------------------------------------
    // DataElementGroup
    // ---------------------------------------------------------------------

    dataElementGroupA = createDataElementGroup('A');
    dataElementGroupB = createDataElementGroup('B');
    dataElementGroupC = createDataElementGroup('C');

    dataElementGroupADuplicate = createDataElementGroup('A');
    dataElementGroupBDuplicate = createDataElementGroup('B');
    dataElementGroupCDuplicate = createDataElementGroup('C');

    dataElementGroupADuplicate.setId('A');
    dataElementGroupBDuplicate.setId('B');
    dataElementGroupCDuplicate.setId('C');

    dataElementGroupAssociationA = new GroupMemberAssociation('A', 'A');
    dataElementGroupAssociationB = new GroupMemberAssociation('A', 'B');
    dataElementGroupAssociationC = new GroupMemberAssociation('A', 'C');
    dataElementGroupAssociationD = new GroupMemberAssociation('A', 'D');
    dataElementGroupAssociationE = new GroupMemberAssociation('B', 'A');
    dataElementGroupAssociationF = new GroupMemberAssociation('B', 'B');
    dataElementGroupAssociationG = new GroupMemberAssociation('B', 'C');
    dataElementGroupAssociationH = new GroupMemberAssociation('B', 'D');
    dataElementGroupAssociationI = new GroupMemberAssociation('C', 'A');
    dataElementGroupAssociationJ = new GroupMemberAssociation('C', 'B');
    dataElementGroupAssociationK = new GroupMemberAssociation('C', 'C');
    dataElementGroupAssociationL = new GroupMemberAssociation('C', 'D');

    // ---------------------------------------------------------------------
    // Period
    // ---------------------------------------------------------------------

    periodTypeA = periodService.getPeriodTypeByName(MonthlyPeriodType.NAME);

    periodA = createPeriod(periodTypeA, getDate(1, 0, 2000), getDate(31, 0, 2000));

    periodADuplicate = createPeriod(periodTypeA, getDate(1, 0, 2000), getDate(31, 0, 2000));

    periodADuplicate.setId('A');

    // ---------------------------------------------------------------------
    // OrganisationUnit
    // ---------------------------------------------------------------------

    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    organisationUnitC = createOrganisationUnit('C');

    organisationUnitAModified = createOrganisationUnit('A');
    organisationUnitBModified = createOrganisationUnit('B');
    organisationUnitCModified = createOrganisationUnit('C');

    organisationUnitAModified.setId('A');
    organisationUnitBModified.setId('B');
    organisationUnitCModified.setId('C');

    organisationUnitAModified.setShortName("ShortNameModifiedA");
    organisationUnitBModified.setShortName("ShortNameModifiedB");
    organisationUnitCModified.setShortName("ShortNameModifiedC");

    // ---------------------------------------------------------------------
    // RelationshipAssociation
    // ---------------------------------------------------------------------

    relationshipAssociationA = new GroupMemberAssociation('A', 'B');
    relationshipAssociationB = new GroupMemberAssociation('B', 'C');

    // ---------------------------------------------------------------------
    // DataValue
    // ---------------------------------------------------------------------

    dataValueA =
        createDataValue(dataElementA, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueB =
        createDataValue(dataElementA, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueC =
        createDataValue(dataElementA, periodA, organisationUnitC, "10", categoryOptionComboA);
    dataValueD =
        createDataValue(dataElementB, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueE =
        createDataValue(dataElementB, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueF =
        createDataValue(dataElementB, periodA, organisationUnitC, "10", categoryOptionComboA);
    dataValueG =
        createDataValue(dataElementC, periodA, organisationUnitA, "10", categoryOptionComboA);
    dataValueH =
        createDataValue(dataElementC, periodA, organisationUnitB, "10", categoryOptionComboA);
    dataValueI =
        createDataValue(dataElementC, periodA, organisationUnitC, "10", categoryOptionComboA);

    dataValueADuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueBDuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueCDuplicate =
        createDataValue(
            dataElementAModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueDDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueEDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueFDuplicate =
        createDataValue(
            dataElementBModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueGDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitAModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueHDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitBModified,
            "10",
            categoryOptionComboADuplicate);
    dataValueIDuplicate =
        createDataValue(
            dataElementCModified,
            periodADuplicate,
            organisationUnitCModified,
            "10",
            categoryOptionComboADuplicate);
  }
Esempio n. 18
0
  @Override
  public void setUpTest() {
    mockDataValueBatchHandler = new MockBatchHandler<>();
    mockBatchHandlerFactory = new MockBatchHandlerFactory();
    mockBatchHandlerFactory.registerBatchHandler(
        DataValueBatchHandler.class, mockDataValueBatchHandler);
    setDependency(dataValueSetService, "batchHandlerFactory", mockBatchHandlerFactory);

    categoryOptionA = createCategoryOption('A');
    categoryOptionB = createCategoryOption('B');
    categoryA = createDataElementCategory('A', categoryOptionA, categoryOptionB);
    categoryComboA = createCategoryCombo('A', categoryA);
    ocDef = categoryService.getDefaultDataElementCategoryOptionCombo();

    ocA = createCategoryOptionCombo(categoryComboA, categoryOptionA);
    ocB = createCategoryOptionCombo(categoryComboA, categoryOptionB);
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deD = createDataElement('D');
    dsA = createDataSet('A', new MonthlyPeriodType());
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    peA =
        createPeriod(
            PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME),
            getDate(2012, 1, 1),
            getDate(2012, 1, 31));
    peB =
        createPeriod(
            PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME),
            getDate(2012, 2, 1),
            getDate(2012, 2, 29));

    ocA.setUid("kjuiHgy67hg");
    ocB.setUid("Gad33qy67g5");
    deA.setUid("f7n9E0hX8qk");
    deB.setUid("Ix2HsbDMLea");
    deC.setUid("eY5ehpbEsB7");
    dsA.setUid("pBOMPrpg1QX");
    ouA.setUid("DiszpKrYNg8");
    ouB.setUid("BdfsJfj87js");
    ouC.setUid("j7Hg26FpoIa");

    ocA.setCode("OC_A");
    ocB.setCode("OC_B");
    deA.setCode("DE_A");
    deB.setCode("DE_B");
    deC.setCode("DE_C");
    deD.setCode("DE_D");
    dsA.setCode("DS_A");
    ouA.setCode("OU_A");
    ouB.setCode("OU_B");
    ouC.setCode("OU_C");

    categoryService.addDataElementCategoryOption(categoryOptionA);
    categoryService.addDataElementCategoryOption(categoryOptionB);
    categoryService.addDataElementCategory(categoryA);
    categoryService.addDataElementCategoryCombo(categoryComboA);
    categoryService.addDataElementCategoryOptionCombo(ocA);
    categoryService.addDataElementCategoryOptionCombo(ocB);

    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataSetService.addDataSet(dsA);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    periodService.addPeriod(peA);
    periodService.addPeriod(peB);

    user = createUser('A');
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(dataValueSetService, "currentUserService", currentUserService);
  }
Esempio n. 19
0
  @Override
  public String execute() throws Exception {
    ExportParams params = new ExportParams();

    if (dataValue || dataValueDaily) {
      params.setCategories(null);
      params.setCategoryCombos(null);
      params.setCategoryOptions(null);
      params.setCategoryOptionCombos(null);
      /*
       * params.setDataElementGroups( null );
       * params.setDataElementGroupSets( null ); params.setIndicators(
       * null ); params.setIndicatorTypes( null );
       * params.setIndicatorGroups( null ); params.setIndicatorGroupSets(
       * null ); params.setDataDictionaries( null ); params.setDataSets(
       * null ); params.setOrganisationUnitGroups( null );
       * params.setOrganisationUnitGroupSets( null );
       * params.setOrganisationUnitLevels( null );
       * params.setValidationRules( null ); params.setReports( null );
       * params.setReportTables( null ); params.setPeriods( null ); //
       * TODO Include only relevant periods params.setCharts( null );
       * params.setPeriods( null );
       */

      Set<Integer> dataElementz = new HashSet<>();

      Collection<DataElement> children = dataElementService.getAllDataElements();

      for (DataElement child : children) {
        dataElementz.add(child.getId());
      }

      params.setDataElements(dataElementz);

      Set<Integer> orgUnits = new HashSet<>();

      Collection<OrganisationUnit> orgChildren = organisationUnitService.getAllOrganisationUnits();

      for (OrganisationUnit child : orgChildren) {
        orgUnits.add(child.getId());
      }

      params.setOrganisationUnits(orgUnits);
    }

    if (dataValue) {
      params.setMetaData(false);
    }

    if (dataValueDaily) {
      params.setMetaData(false);
    }

    // params.setMetaData( true );
    params.setIncludeDataValues(true);
    params.setCurrentUser(currentUserService.getCurrentUser());
    params.setDataValue(dataValue);
    params.setDataValueDaily(dataValueDaily);

    params.setI18n(i18n);
    params.setFormat(format);
    params.setStartDate(getMediumDate(startDate));
    params.setEndDate(getMediumDate(endDate));

    ExportService exportService = serviceProvider.provide(exportFormat);

    inputStream = exportService.exportData(params);

    fileName = FILENAME;

    return SUCCESS;
  }
  public void generateReport(
      Program selProgram, List<OrganisationUnit> orgUnitList, Date sDate, Date eDate)
      throws Exception {
    String raFolderName = reportService.getRAFolderName();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String query = "";
    int rowStart = 3;
    int colStart = 1;
    int rowCount = rowStart;
    int colCount = colStart;

    // String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName +
    // File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";

    String outputReportPath =
        System.getenv("DHIS2_HOME") + File.separator + Configuration_IN.DEFAULT_TEMPFOLDER;
    File newdir = new File(outputReportPath);
    if (!newdir.exists()) {
      newdir.mkdirs();
    }
    outputReportPath += File.separator + UUID.randomUUID().toString() + ".xls";

    WritableWorkbook outputReportWorkbook = Workbook.createWorkbook(new File(outputReportPath));
    WritableSheet sheet0 = outputReportWorkbook.createSheet(selProgram.getName(), 0);

    try {
      List<PatientIdentifierType> patientIdentifierTypes =
          new ArrayList<PatientIdentifierType>(
              patientIdentifierTypeService.getAllPatientIdentifierTypes());
      Collections.sort(patientIdentifierTypes, new PatientIdentifierTypeComparator());

      List<PatientAttribute> patientAttributes =
          new ArrayList<PatientAttribute>(patientAttributeService.getAllPatientAttributes());
      Collections.sort(patientAttributes, new PatientAttributeComparator());

      List<ProgramStage> programStages = new ArrayList<ProgramStage>(selProgram.getProgramStages());
      Collections.sort(programStages, new ProgramStageOrderComparator());

      Map<ProgramStage, List<DataElement>> programStageDataElementMap =
          new HashMap<ProgramStage, List<DataElement>>();
      for (ProgramStage programStage : programStages) {
        List<ProgramStageDataElement> programStageDataElements =
            new ArrayList<ProgramStageDataElement>(programStage.getProgramStageDataElements());

        List<DataElement> dataElements = new ArrayList<DataElement>();
        for (ProgramStageDataElement programStageDataElement : programStageDataElements) {
          dataElements.add(programStageDataElement.getDataElement());
        }

        Collections.sort(dataElements, new IdentifiableObjectNameComparator());
        programStageDataElementMap.put(programStage, dataElements);
      }

      // Printing Header Information
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "OrgUnit Hierarchy", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "OrgUnit", getCellFormat1()));
      colCount++;
      for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) {
        sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
        sheet0.addCell(
            new Label(colCount, rowCount - 1, patientIdentifierType.getName(), getCellFormat1()));
        colCount++;
      }

      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Benificiary ID", getCellFormat1()));
      colCount++;

      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Benificiary Name", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Gender", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Age", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Data of Birth", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Blood Group", getCellFormat1()));
      colCount++;
      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Registration Date", getCellFormat1()));
      colCount++;

      for (PatientAttribute patientAttribute : patientAttributes) {
        sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
        sheet0.addCell(
            new Label(colCount, rowCount - 1, patientAttribute.getName(), getCellFormat1()));
        colCount++;
      }

      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Incident Date", getCellFormat1()));
      colCount++;

      sheet0.mergeCells(colCount, rowCount - 1, colCount, rowCount);
      sheet0.addCell(new Label(colCount, rowCount - 1, "Enrollment Date", getCellFormat1()));
      colCount++;
      for (ProgramStage programStage : programStages) {
        List<DataElement> dataElementList =
            new ArrayList<DataElement>(programStageDataElementMap.get(programStage));
        sheet0.mergeCells(
            colCount, rowCount - 1, colCount + dataElementList.size() + 1, rowCount - 1);
        sheet0.addCell(new Label(colCount, rowCount - 1, programStage.getName(), getCellFormat1()));

        sheet0.addCell(new Label(colCount, rowCount, "Due Date", getCellFormat1()));
        colCount++;
        sheet0.addCell(new Label(colCount, rowCount, "Execution Date", getCellFormat1()));
        colCount++;

        for (DataElement dataElement : dataElementList) {
          sheet0.addCell(
              new Label(
                  colCount,
                  rowCount,
                  dataElement.getName() + "--" + dataElement.getType(),
                  getCellFormat1()));
          colCount++;
        }
      }

      rowCount++;

      for (OrganisationUnit orgUnit : orgUnitList) {
        if (sDate != null && eDate != null) {
          query =
              "SELECT patient.patientid, programinstance.programinstanceid,programinstance.dateofincident,programinstance.enrollmentdate FROM programinstance INNER JOIN patient "
                  + " ON programinstance.patientid = patient.patientid "
                  + " WHERE patient.organisationunitid = "
                  + orgUnit.getId()
                  + " AND programinstance.programid = "
                  + selProgram.getId()
                  + " AND patient.registrationdate >= '"
                  + startDate
                  + "'"
                  + " AND patient.registrationdate <= '"
                  + endDate
                  + "' "
                  + " AND enddate IS NULL";
        } else {
          query =
              "SELECT patient.patientid, programinstance.programinstanceid,programinstance.dateofincident,programinstance.enrollmentdate FROM programinstance INNER JOIN patient "
                  + " ON programinstance.patientid = patient.patientid "
                  + " WHERE patient.organisationunitid = "
                  + orgUnit.getId()
                  + " AND programinstance.programid = "
                  + selProgram.getId()
                  + " AND enddate IS NULL";
        }

        SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet(query);

        if (sqlResultSet != null) {
          int count = 1;
          String orgUnitBranch = "";
          sqlResultSet.beforeFirst();
          while (sqlResultSet.next()) {
            colCount = colStart;

            if (orgUnit.getParent() != null) {
              orgUnitBranch = getOrgunitBranch(orgUnit.getParent());
            } else {
              orgUnitBranch = " ";
            }

            sheet0.addCell(new Label(colCount, rowCount, orgUnitBranch, getCellFormat2()));
            colCount++;
            sheet0.addCell(new Label(colCount, rowCount, orgUnit.getName(), getCellFormat2()));
            colCount++;

            int patientId = sqlResultSet.getInt(1);
            int programInstanceId = sqlResultSet.getInt(2);
            Date dateOfIncident = sqlResultSet.getDate(3);
            Date dateOfEnrollment = sqlResultSet.getDate(4);

            Patient patient = patientService.getPatient(patientId);

            // Patient Identifier Details
            for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) {
              query =
                  "SELECT identifier from patientidentifier WHERE patientidentifiertypeid = "
                      + patientIdentifierType.getId()
                      + " AND patientid = "
                      + patient.getId();

              SqlRowSet sqlResultSet1 = jdbcTemplate.queryForRowSet(query);
              if (sqlResultSet1 != null && sqlResultSet1.next()) {
                String value = sqlResultSet1.getString(1);
                if (value != null && !value.trim().equalsIgnoreCase("")) {
                  sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2()));
                } else {
                  sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
                }
              } else {
                sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
              }

              colCount++;
            }

            // Patient Properties

            sheet0.addCell(
                new Label(colCount, rowCount, patient.getId().toString(), getCellFormat2()));
            colCount++;
            sheet0.addCell(new Label(colCount, rowCount, patient.getFullName(), getCellFormat2()));
            colCount++;
            sheet0.addCell(
                new Label(colCount, rowCount, patient.getTextGender(), getCellFormat2()));
            colCount++;
            sheet0.addCell(new Label(colCount, rowCount, patient.getAge(), getCellFormat2()));
            colCount++;
            sheet0.addCell(
                new Label(
                    colCount,
                    rowCount,
                    simpleDateFormat.format(patient.getBirthDate()),
                    getCellFormat2()));
            colCount++;
            /**
             * TODO BloodGroup is removed from Patient Object, so need to change this accordingly
             */
            sheet0.addCell(
                new Label(colCount, rowCount, "" /*patient.getBloodGroup()*/, getCellFormat2()));
            colCount++;
            sheet0.addCell(
                new Label(
                    colCount,
                    rowCount,
                    simpleDateFormat.format(patient.getRegistrationDate()),
                    getCellFormat2()));
            colCount++;

            // Patient Attribute Values
            for (PatientAttribute patientAttribute : patientAttributes) {
              query =
                  "SELECT value from patientattributevalue WHERE patientid = "
                      + patient.getId()
                      + " AND patientattributeid = "
                      + patientAttribute.getId();

              SqlRowSet sqlResultSet1 = jdbcTemplate.queryForRowSet(query);
              if (sqlResultSet1 != null && sqlResultSet1.next()) {
                String value = sqlResultSet1.getString(1);
                if (value != null && !value.trim().equalsIgnoreCase("")) {
                  sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2()));
                } else {
                  sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
                }
              } else {
                sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
              }

              colCount++;
            }

            // Program Enrollment Details
            sheet0.addCell(
                new Label(
                    colCount, rowCount, simpleDateFormat.format(dateOfIncident), getCellFormat2()));
            colCount++;
            sheet0.addCell(
                new Label(
                    colCount,
                    rowCount,
                    simpleDateFormat.format(dateOfEnrollment),
                    getCellFormat2()));
            colCount++;

            // ProgramStage Values
            for (ProgramStage programStage : programStages) {
              query =
                  "SELECT programstageinstanceid,duedate,executiondate from programstageinstance "
                      + " WHERE programinstanceid = "
                      + programInstanceId
                      + " AND programstageid = "
                      + programStage.getId();

              SqlRowSet sqlResultSet2 = jdbcTemplate.queryForRowSet(query);
              Integer programStageInstanceId = 0;
              if (sqlResultSet2 != null && sqlResultSet2.next()) {
                programStageInstanceId = sqlResultSet2.getInt(1);

                // ProgramStage DueDate and Execution Date
                Date dueDate = sqlResultSet2.getDate(2);
                Date exeDate = sqlResultSet2.getDate(3);

                if (dueDate != null) {
                  String dueDateStr = simpleDateFormat.format(dueDate);
                  sheet0.addCell(new Label(colCount, rowCount, dueDateStr, getCellFormat3()));
                } else {
                  sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3()));
                }
                colCount++;

                if (exeDate != null) {
                  String exeDateStr = simpleDateFormat.format(exeDate);
                  sheet0.addCell(new Label(colCount, rowCount, exeDateStr, getCellFormat3()));
                } else {
                  sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3()));
                }

                colCount++;
              } else {
                sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3()));
                colCount++;
                sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat3()));
                colCount++;
              }

              for (DataElement dataElement : programStageDataElementMap.get(programStage)) {
                query =
                    "SELECT value from patientdatavalue WHERE programstageinstanceid = "
                        + programStageInstanceId
                        + " AND dataelementid = "
                        + dataElement.getId();
                // " AND organisationunitid = " + orgUnit.getId();

                SqlRowSet sqlResultSet3 = jdbcTemplate.queryForRowSet(query);

                if (sqlResultSet3 != null && sqlResultSet3.next()) {
                  String value = sqlResultSet3.getString(1);

                  if (dataElement.getType().equalsIgnoreCase(DataElement.VALUE_TYPE_BOOL)) {
                    if (value.equalsIgnoreCase("false")) value = "No";
                    else value = "Yes";
                  }

                  if (value != null && !value.trim().equalsIgnoreCase("")) {
                    sheet0.addCell(new Label(colCount, rowCount, value, getCellFormat2()));
                  } else {
                    sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
                  }
                } else {
                  sheet0.addCell(new Label(colCount, rowCount, "-", getCellFormat2()));
                }

                colCount++;
              }
            }

            rowCount++;
          }
        }
      }
    } catch (Exception e) {
      System.out.println("Exception: " + e.getMessage());
      e.printStackTrace();
    }

    outputReportWorkbook.write();
    outputReportWorkbook.close();
    fileName = selProgram.getName() + ".xls";
    File outputReportFile = new File(outputReportPath);
    inputStream = new BufferedInputStream(new FileInputStream(outputReportFile));
    outputReportFile.deleteOnExit();
  }