Search in sources :

Example 11 with Option

use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.

the class EventAnalyticsServiceMetadataTest method testGetQueryItemMetadata.

@Test
@SuppressWarnings("unchecked")
void testGetQueryItemMetadata() {
    DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
    DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA));
    QueryItem qiA = new QueryItem(deA, deA.getLegendSet(), deA.getValueType(), deA.getAggregationType(), null);
    QueryItem qiB = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), deE.getOptionSet());
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(qiA).addItemFilter(qiB).withSkipData(true).withSkipMeta(false).withApiVersion(DhisApiVersion.V29).build();
    Grid grid = eventAnalyticsService.getAggregatedEventData(params);
    Map<String, Object> metadata = grid.getMetaData();
    Map<String, MetadataItem> itemMap = (Map<String, MetadataItem>) metadata.get(AnalyticsMetaDataKey.ITEMS.getKey());
    assertNotNull(itemMap.get(DimensionalObject.PERIOD_DIM_ID));
    assertNotNull(itemMap.get(DimensionalObject.ORGUNIT_DIM_ID));
    for (Legend legend : deA.getLegendSet().getLegends()) {
        assertNotNull(itemMap.get(legend.getUid()));
    }
    for (Option option : deE.getOptionSet().getOptions()) {
        assertNotNull(itemMap.get(option.getUid()));
    }
    assertNotNull(itemMap.get(deA.getUid()));
    assertNotNull(itemMap.get(deE.getUid()));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) Legend(org.hisp.dhis.legend.Legend) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Option(org.hisp.dhis.option.Option) Map(java.util.Map) MetadataItem(org.hisp.dhis.common.MetadataItem) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with Option

use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.

the class EventAnalyticsUtilsTest method testGenerateEventDataPermutations.

@Test
void testGenerateEventDataPermutations() {
    Map<String, List<EventAnalyticsDimensionalItem>> tableRows = new LinkedHashMap<>();
    Grid grid = new ListGrid();
    DataElement deA = createDataElement('A');
    deA.setValueType(ValueType.BOOLEAN);
    grid.addMetaData(deA.getUid(), deA);
    TrackedEntityAttribute trackedEntityAttribute = createTrackedEntityAttribute('B');
    OptionSet optionSet = new OptionSet();
    optionSet.addOption(new Option("name", "code"));
    trackedEntityAttribute.setOptionSet(optionSet);
    grid.addMetaData(trackedEntityAttribute.getUid(), trackedEntityAttribute);
    List<EventAnalyticsDimensionalItem> objects = new ArrayList<>();
    Option t = new Option();
    t.setCode("1");
    t.setName("Yes");
    Option f = new Option();
    f.setCode("0");
    f.setName("No");
    objects.add(new EventAnalyticsDimensionalItem(t, deA.getUid()));
    objects.add(new EventAnalyticsDimensionalItem(f, deA.getUid()));
    objects.add(new EventAnalyticsDimensionalItem(new Option("name", "code"), trackedEntityAttribute.getUid()));
    tableRows.put(deA.getUid(), objects);
    tableRows.put(trackedEntityAttribute.getDimensionItem(), objects);
    List<Map<String, EventAnalyticsDimensionalItem>> rowPermutations = EventAnalyticsUtils.generateEventDataPermutations(tableRows);
    assertEquals(9, rowPermutations.size());
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) ListGrid(org.hisp.dhis.system.grid.ListGrid) LinkedHashMap(java.util.LinkedHashMap) DataElement(org.hisp.dhis.dataelement.DataElement) EventAnalyticsDimensionalItem(org.hisp.dhis.analytics.EventAnalyticsDimensionalItem) ArrayList(java.util.ArrayList) List(java.util.List) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 13 with Option

use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.

the class DefaultPdfDataEntryFormService method insertTable_ProgramStageSections.

private void insertTable_ProgramStageSections(PdfPTable mainTable, Rectangle rectangle, PdfWriter writer, Collection<DataElement> dataElements) throws IOException, DocumentException {
    boolean hasBorder = false;
    // Add one to column count due to date entry + one hidden height set
    // field.
    int colCount = dataElements.size() + 1 + 1;
    // Code 1
    PdfPTable table = new PdfPTable(colCount);
    float totalWidth = 800f;
    float firstCellWidth_dateEntry = PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 3;
    float lastCellWidth_hidden = PdfDataEntryFormUtil.UNITSIZE_DEFAULT;
    float dataElementCellWidth = (totalWidth - firstCellWidth_dateEntry - lastCellWidth_hidden) / dataElements.size();
    // Create 2 types of Rectangles, one for Date field, one for data
    // elements - to be used when rendering them.
    Rectangle rectangleDate = new Rectangle(0, 0, PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 2, PdfDataEntryFormUtil.UNITSIZE_DEFAULT);
    Rectangle rectangleDataElement = new Rectangle(0, 0, dataElementCellWidth, PdfDataEntryFormUtil.UNITSIZE_DEFAULT);
    // Cell Width Set
    float[] cellWidths = new float[colCount];
    // Date Field Settings
    cellWidths[0] = firstCellWidth_dateEntry;
    for (int i = 1; i < colCount - 1; i++) {
        cellWidths[i] = dataElementCellWidth;
    }
    cellWidths[colCount - 1] = lastCellWidth_hidden;
    table.setWidths(cellWidths);
    // Create Header
    addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), "Date", Element.ALIGN_CENTER);
    // Add Program Data Elements Columns
    for (DataElement dataElement : dataElements) {
        addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback(), Element.ALIGN_CENTER);
    }
    addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), TEXT_BLANK, Element.ALIGN_CENTER);
    for (int rowNo = 1; rowNo <= PROGRAM_FORM_ROW_NUMBER; rowNo++) {
        // Add Date Column
        String strFieldDateLabel = PdfDataEntryFormUtil.LABELCODE_DATADATETEXTFIELD + Integer.toString(rowNo);
        addCell_WithTextField(table, rectangleDate, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldDateLabel);
        // Add Program Data Elements Columns
        for (DataElement dataElement : dataElements) {
            OptionSet optionSet = dataElement.getOptionSet();
            String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + Long.toString(dataElement.getId()) + // Integer.toString(rowNo);
            "_" + Integer.toString(rowNo);
            if (optionSet != null) {
                // Get All Option
                String query = "";
                // TODO: This gets repeated <- Create an array of the
                // options. and apply only once.
                List<Option> options = optionService.getOptions(optionSet.getId(), query, MAX_OPTIONS_DISPLAYED);
                addCell_WithDropDownListField(table, rectangleDataElement, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, options.toArray(new String[0]), options.toArray(new String[0]));
            } else {
                // NOTE: When Rendering for DataSet, DataElement's OptionSet
                // does not get rendered.
                // Only for events, it gets rendered as dropdown list.
                addCell_WithTextField(table, rectangleDataElement, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
            }
        }
        addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), TEXT_BLANK, Element.ALIGN_LEFT);
    }
    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) Rectangle(com.lowagie.text.Rectangle) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet)

Example 14 with Option

use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.

the class DhisConvenienceTest method createOption.

public static Option createOption(char uniqueCharacter) {
    Option option = new Option();
    option.setAutoFields();
    option.setName("Option" + uniqueCharacter);
    option.setCode("OptionCode" + uniqueCharacter);
    return option;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) Option(org.hisp.dhis.option.Option)

Example 15 with Option

use of org.hisp.dhis.option.Option in project dhis2-core by dhis2.

the class ProgramRuleActionValidationContextLoader method load.

@Transactional(readOnly = true)
public ProgramRuleActionValidationContext load(Preheat preheat, PreheatIdentifier preheatIdentifier, ProgramRuleAction ruleAction) {
    ProgramRule rule = preheat.get(preheatIdentifier, ProgramRule.class, ruleAction.getProgramRule());
    Program program = preheat.get(preheatIdentifier, Program.class, rule.getProgram());
    List<ProgramStage> stages = preheat.getAll(preheatIdentifier, new ArrayList<>(program.getProgramStages()));
    return ProgramRuleActionValidationContext.builder().programRule(rule).program(program).programStages(stages).dataElement(ruleAction.hasDataElement() ? preheat.get(preheatIdentifier, DataElement.class, ruleAction.getDataElement()) : null).trackedEntityAttribute(ruleAction.hasTrackedEntityAttribute() ? preheat.get(preheatIdentifier, TrackedEntityAttribute.class, ruleAction.getAttribute()) : null).notificationTemplate(ruleAction.hasNotification() ? preheat.get(preheatIdentifier, ProgramNotificationTemplate.class, ruleAction.getTemplateUid()) : null).programStageSection(ruleAction.hasProgramStageSection() ? preheat.get(preheatIdentifier, ProgramStageSection.class, ruleAction.getProgramStageSection()) : null).programStage(ruleAction.hasProgramStage() ? preheat.get(preheatIdentifier, ProgramStage.class, ruleAction.getProgramStage()) : null).option(ruleAction.hasOption() ? preheat.get(preheatIdentifier, Option.class, ruleAction.getOption()) : null).optionGroup(ruleAction.hasOptionGroup() ? preheat.get(preheatIdentifier, OptionGroup.class, ruleAction.getOptionGroup()) : null).programRuleActionValidationService(validationService).build();
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Option(org.hisp.dhis.option.Option) ProgramStage(org.hisp.dhis.program.ProgramStage) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Option (org.hisp.dhis.option.Option)40 OptionSet (org.hisp.dhis.option.OptionSet)23 Test (org.junit.jupiter.api.Test)16 List (java.util.List)11 DataElement (org.hisp.dhis.dataelement.DataElement)10 HashMap (java.util.HashMap)8 Legend (org.hisp.dhis.legend.Legend)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)6 CategoryOption (org.hisp.dhis.category.CategoryOption)6 HashSet (java.util.HashSet)5 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 VersionedObject (org.hisp.dhis.common.VersionedObject)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)3 OptionGroup (org.hisp.dhis.option.OptionGroup)3 OptionGroupSet (org.hisp.dhis.option.OptionGroupSet)3