Search in sources :

Example 11 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class AbstractWebApiTest method createTestObject.

@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
    if (DataElementGroup.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroup(uniqueName);
    } else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
        return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
    } else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOption(uniqueName);
    } else if (DataElement.class.isAssignableFrom(clazz)) {
        return (T) createDataElement(uniqueName);
    } else if (DataElementCategory.class.isAssignableFrom(clazz)) {
        return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
    } else if (Program.class.isAssignableFrom(clazz)) {
        OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
        manager.save(organisationUnitA);
        return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
    } else if (DataElementOperand.class.isAssignableFrom(clazz)) {
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
        manager.save(coc);
        return (T) new DataElementOperand(deA, coc);
    } else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroupSet(uniqueName);
    } else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        return (T) createCategoryOptionCombo(cc, co);
    } else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(co);
        return (T) createCategoryOptionGroup(uniqueName, co);
    } else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOptionGroupSet(uniqueName);
    } else if (EventChart.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventChart ecA = new EventChart("evc" + uniqueName);
        ecA.setProgram(prA);
        ecA.setType(ChartType.COLUMN);
        return (T) ecA;
    } else if (EventReport.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventReport erA = new EventReport("er" + uniqueName);
        erA.setProgram(prA);
        return (T) erA;
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        return (T) new ProgramDataElementDimensionItem(prA, deA);
    } else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
        Program program = (Program) createTestObject(Program.class, uniqueName);
        manager.save(program);
        Constant constantA = createConstant(uniqueName, 7.0);
        manager.save(constantA);
        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
        return (T) createProgramIndicator(uniqueName, program, expressionA, null);
    } else if (Indicator.class.isAssignableFrom(clazz)) {
        IndicatorType indicatorType = createIndicatorType(uniqueName);
        manager.save(indicatorType);
        return (T) createIndicator(uniqueName, indicatorType);
    } else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroup(uniqueName);
    } else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroupSet(uniqueName);
    } else if (IndicatorType.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorType(uniqueName);
    } else if (Legend.class.isAssignableFrom(clazz)) {
        return (T) createLegend(uniqueName, 0d, 10d);
    } else if (LegendSet.class.isAssignableFrom(clazz)) {
        return (T) createLegendSet(uniqueName);
    } else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnit(uniqueName);
    } else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroup(uniqueName);
    } else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroupSet(uniqueName);
    } else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
        return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
    } else if (Color.class.isAssignableFrom(clazz)) {
        Color color = new Color("#ff3200");
        color.setName("Color" + uniqueName);
        return (T) color;
    } else if (ColorSet.class.isAssignableFrom(clazz)) {
        ColorSet colorSet = new ColorSet();
        colorSet.setName("ColorSet" + uniqueName);
        return (T) colorSet;
    } else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
        org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
        map.setName("Map" + uniqueName);
        map.setDisplayName("DisplayName" + uniqueName);
        map.setLatitude(952175.62553525);
        map.setLongitude(-1378543.6774686);
        return (T) map;
    } else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
        ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
        externalMapLayer.setMapService(MapService.WMS);
        externalMapLayer.setUrl("testUrl");
        externalMapLayer.setImageFormat(ImageFormat.JPG);
        externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
        return (T) externalMapLayer;
    } else if (OptionGroup.class.isAssignableFrom(clazz)) {
        OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
        optionGroup.setShortName("Group" + uniqueName);
        return (T) optionGroup;
    } else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
    } else if (Option.class.isAssignableFrom(clazz)) {
        return (T) new Option("Option" + uniqueName, "code" + uniqueName);
    } else if (OptionSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
    } else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
        ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
        ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
        group.addAttribute(attr);
        return (T) group;
    } else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
        return (T) createProgramTrackedEntityAttribute(uniqueName);
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        return (T) createProgramDataElement(uniqueName);
    }
    return null;
}
Also used : ColorSet(org.hisp.dhis.color.ColorSet) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ExternalMapLayer(org.hisp.dhis.mapping.ExternalMapLayer) Legend(org.hisp.dhis.legend.Legend) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Constant(org.hisp.dhis.constant.Constant) EventReport(org.hisp.dhis.eventreport.EventReport) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) IndicatorType(org.hisp.dhis.indicator.IndicatorType) OptionGroup(org.hisp.dhis.option.OptionGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) Color(org.hisp.dhis.color.Color) EventChart(org.hisp.dhis.eventchart.EventChart) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.option.Option) ProgramTrackedEntityAttributeGroup(org.hisp.dhis.program.ProgramTrackedEntityAttributeGroup) OptionSet(org.hisp.dhis.option.OptionSet) Map(java.util.Map) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 12 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DhisConvenienceTest method createCategoryOptionCombo.

/**
     * @param categoryCombo   the category combo.
     * @param categoryOptions the category options.
     * @return DataElementCategoryOptionCombo
     */
public static DataElementCategoryOptionCombo createCategoryOptionCombo(DataElementCategoryCombo categoryCombo, DataElementCategoryOption... categoryOptions) {
    DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
    categoryOptionCombo.setAutoFields();
    categoryOptionCombo.setCategoryCombo(categoryCombo);
    for (DataElementCategoryOption categoryOption : categoryOptions) {
        categoryOptionCombo.getCategoryOptions().add(categoryOption);
        categoryOption.getCategoryOptionCombos().add(categoryOptionCombo);
    }
    return categoryOptionCombo;
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 13 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class PredictorStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementX = createDataElement('X');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementX);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    defaultCombo = categoryOptionCombo;
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionA);
    periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Also used : Expression(org.hisp.dhis.expression.Expression) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 14 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class MinMaxDataElementStoreTest method testBasic.

@Test
public void testBasic() {
    OrganisationUnit source1 = createOrganisationUnit('A');
    OrganisationUnit source2 = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(source1);
    organisationUnitService.addOrganisationUnit(source2);
    DataElement dataElement1 = createDataElement('A');
    DataElement dataElement2 = createDataElement('B');
    DataElement dataElement3 = createDataElement('C');
    DataElement dataElement4 = createDataElement('D');
    dataElementService.addDataElement(dataElement1);
    dataElementService.addDataElement(dataElement2);
    dataElementService.addDataElement(dataElement3);
    dataElementService.addDataElement(dataElement4);
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(source1, dataElement1, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(source2, dataElement2, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(source2, dataElement3, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(source2, dataElement4, optionCombo, 0, 100, false);
    minMaxDataElementStore.save(minMaxDataElement1);
    int mmdeid1 = minMaxDataElement1.getId();
    minMaxDataElementStore.save(minMaxDataElement2);
    minMaxDataElementStore.save(minMaxDataElement3);
    minMaxDataElementStore.save(minMaxDataElement4);
    // ----------------------------------------------------------------------
    // Assertions
    // ----------------------------------------------------------------------
    assertNotNull(minMaxDataElementStore.get(mmdeid1));
    assertTrue(minMaxDataElementStore.get(mmdeid1).getMax() == 100);
    List<DataElement> dataElements1 = new ArrayList<>();
    dataElements1.add(dataElement1);
    List<DataElement> dataElements2 = new ArrayList<>();
    dataElements2.add(dataElement2);
    dataElements2.add(dataElement3);
    dataElements2.add(dataElement4);
    assertNotNull(minMaxDataElementStore.get(source1, dataElement1, optionCombo));
    assertNull(minMaxDataElementStore.get(source2, dataElement1, optionCombo));
    assertEquals(1, minMaxDataElementStore.get(source1, dataElements1).size());
    assertEquals(3, minMaxDataElementStore.get(source2, dataElements2).size());
    minMaxDataElementStore.delete(minMaxDataElement1);
    assertNull(minMaxDataElementStore.get(mmdeid1));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 15 with DataElementCategoryOptionCombo

use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.

the class DefaultPdfDataEntryFormService method insertTable_DataSetSections.

private void insertTable_DataSetSections(PdfPTable mainTable, PdfWriter writer, Rectangle rectangle, Collection<DataElement> dataElements, String sectionName) throws IOException, DocumentException {
    boolean hasBorder = true;
    // Add Section Name and Section Spacing
    insertTable_TextRow(writer, mainTable, TEXT_BLANK);
    if (sectionName != null && !sectionName.isEmpty()) {
        insertTable_TextRow(writer, mainTable, sectionName, pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_SECTIONHEADER));
    }
    // Create A Table To Add For Each Section
    PdfPTable table = new PdfPTable(2);
    table.setWidths(new int[] { 2, 1 });
    table.setWidthPercentage(100.0f);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    // row.
    for (DataElement dataElement : dataElements) {
        for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
            String categoryOptionComboDisplayName = "";
            // Hide Default category option combo name
            if (!categoryOptionCombo.isDefault()) {
                categoryOptionComboDisplayName = categoryOptionCombo.getDisplayName();
            }
            addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback() + " " + categoryOptionComboDisplayName, Element.ALIGN_RIGHT);
            String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + dataElement.getUid() + "_" + categoryOptionCombo.getUid();
            ValueType valueType = dataElement.getValueType();
            // Yes Only case - render as check-box
            if (ValueType.TRUE_ONLY == valueType) {
                addCell_WithCheckBox(table, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            } else if (ValueType.BOOLEAN == valueType) {
                // Create Yes - true, No - false, Select..
                String[] optionList = new String[] { "[No Value]", "Yes", "No" };
                String[] valueList = new String[] { "", "true", "false" };
                // addCell_WithRadioButton(table, writer, strFieldLabel);
                addCell_WithDropDownListField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, optionList, valueList);
            } else if (valueType.isNumeric()) {
                Rectangle rectNum = new Rectangle(TEXTBOXWIDTH_NUMBERTYPE, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
                addCell_WithTextField(table, rectNum, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER);
            } else {
                addCell_WithTextField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            }
        }
    }
    PdfPCell cell_withInnerTable = new PdfPCell(table);
    cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
    mainTable.addCell(cell_withInnerTable);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) PdfPCell(com.lowagie.text.pdf.PdfPCell) PdfPTable(com.lowagie.text.pdf.PdfPTable) ValueType(org.hisp.dhis.common.ValueType) Rectangle(com.lowagie.text.Rectangle) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4