Search in sources :

Example 6 with ValueType

use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.

the class DefaultQueryItemLocator method getDataElement.

private Optional<QueryItem> getDataElement(String dimension, Program program, LegendSet legendSet, EventOutputType type) {
    QueryItem qi = null;
    ProgramStage programStage = getProgramStageOrFail(dimension);
    DataElement de = dataElementService.getDataElement(getSecondElement(dimension));
    if (de != null && program.containsDataElement(de)) {
        ValueType valueType = legendSet != null ? ValueType.TEXT : de.getValueType();
        qi = new QueryItem(de, program, legendSet, valueType, de.getAggregationType(), de.getOptionSet());
        if (programStage != null) {
            qi.setProgramStage(programStage);
            qi.setRepeatableStageParams(getRepeatableStageParams(dimension));
        } else if (type != null && type.equals(EventOutputType.ENROLLMENT)) {
            throwIllegalQueryEx(ErrorCode.E7225, dimension);
        }
    }
    return Optional.ofNullable(qi);
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) DataElement(org.hisp.dhis.dataelement.DataElement) ValueType(org.hisp.dhis.common.ValueType) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 7 with ValueType

use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.

the class QueryPlannerUtils method getDataTypeDataElementMap.

/**
 * Creates a mapping between data type and data elements for the given data
 * elements.
 *
 * @param dataElements list of data elements.
 */
public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap(List<DimensionalItemObject> dataElements) {
    ListMap<DataType, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject element : dataElements) {
        DataElement dataElement = (DataElement) element;
        ValueType valueType = dataElement.getValueType();
        // Both text and date types are recognized as DataType.TEXT
        DataType dataType = (valueType.isText() || valueType.isDate()) ? DataType.TEXT : DataType.NUMERIC;
        map.putValue(dataType, dataElement);
    }
    return map;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ValueType(org.hisp.dhis.common.ValueType) DataType(org.hisp.dhis.analytics.DataType) ListMap(org.hisp.dhis.common.ListMap)

Example 8 with ValueType

use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.

the class AbstractAnalyticsService method getGrid.

protected Grid getGrid(EventQueryParams params) {
    // ---------------------------------------------------------------------
    // Decide access, add constraints and validate
    // ---------------------------------------------------------------------
    securityManager.decideAccessEventQuery(params);
    params = securityManager.withUserConstraints(params);
    queryValidator.validate(params);
    // keywords as well as their periods are removed in the next step,
    // params object is modified
    List<DimensionItemKeywords.Keyword> periodKeywords = params.getDimensions().stream().map(DimensionalObject::getDimensionItemKeywords).filter(dimensionItemKeywords -> dimensionItemKeywords != null && !dimensionItemKeywords.isEmpty()).flatMap(dk -> dk.getKeywords().stream()).collect(Collectors.toList());
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    Grid grid = createGridWithHeaders(params);
    for (DimensionalObject dimension : params.getDimensions()) {
        grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, false, true));
    }
    for (QueryItem item : params.getItems()) {
        /**
         * Special case: If the request contains an item of Org Unit value
         * type and the item UID is linked to coordinates (coordinateField),
         * then create an Header of ValueType COORDINATE and type "Point"
         */
        if (item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals(item.getItem().getUid())) {
            grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), COORDINATE, false, true, item.getOptionSet(), item.getLegendSet()));
        } else if (hasNonDefaultRepeatableProgramStageOffset(item)) {
            String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
            RepeatableStageParams repeatableStageParams = item.getRepeatableStageParams();
            String name = repeatableStageParams.getDimension();
            grid.addHeader(new GridHeader(name, column, repeatableStageParams.simpleStageValueExpected() ? item.getValueType() : ValueType.REFERENCE, false, true, item.getOptionSet(), item.getLegendSet(), item.getProgramStage().getUid(), item.getRepeatableStageParams()));
        } else {
            final String uid = getItemUid(item);
            final String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
            grid.addHeader(new GridHeader(uid, column, item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
        }
    }
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    long count = 0;
    if (!params.isSkipData() || params.analyzeOnly()) {
        count = addEventData(grid, params);
    }
    // ---------------------------------------------------------------------
    // Meta-data
    // ---------------------------------------------------------------------
    addMetadata(params, periodKeywords, grid);
    if (params.hasDataIdScheme()) {
        substituteData(grid);
    }
    if (params.isPaging()) {
        Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
        grid.getMetaData().put(PAGER.getKey(), pager);
    }
    maybeApplyHeaders(params, grid);
    return grid;
}
Also used : DIMENSIONS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.DIMENSIONS) ORGUNIT_DIM_ID(org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID) Arrays(java.util.Arrays) QueryItem(org.hisp.dhis.common.QueryItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ValueType(org.hisp.dhis.common.ValueType) StringUtils.joinWith(org.apache.commons.lang3.StringUtils.joinWith) HashMap(java.util.HashMap) AnalyticsSecurityManager(org.hisp.dhis.analytics.AnalyticsSecurityManager) ArrayList(java.util.ArrayList) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) ORG_UNIT_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_HIERARCHY) Lists(com.google.common.collect.Lists) Calendar(org.hisp.dhis.calendar.Calendar) GridHeader(org.hisp.dhis.common.GridHeader) Map(java.util.Map) DimensionalObjectUtils.getDimensionalItemIds(org.hisp.dhis.common.DimensionalObjectUtils.getDimensionalItemIds) User(org.hisp.dhis.user.User) ORG_UNIT_NAME_HIERARCHY(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ORG_UNIT_NAME_HIERARCHY) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) PAGER(org.hisp.dhis.analytics.AnalyticsMetaDataKey.PAGER) COORDINATE(org.hisp.dhis.common.ValueType.COORDINATE) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Collection(java.util.Collection) EventQueryValidator(org.hisp.dhis.analytics.event.EventQueryValidator) Pager(org.hisp.dhis.common.Pager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Grid(org.hisp.dhis.common.Grid) Collectors(java.util.stream.Collectors) AnalyticsUtils(org.hisp.dhis.analytics.util.AnalyticsUtils) MetadataItem(org.hisp.dhis.common.MetadataItem) Objects(java.util.Objects) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) List(java.util.List) Option(org.hisp.dhis.option.Option) IdentifiableObjectUtils.getUids(org.hisp.dhis.common.IdentifiableObjectUtils.getUids) DimensionalObject(org.hisp.dhis.common.DimensionalObject) PeriodType(org.hisp.dhis.period.PeriodType) IdentifiableObjectUtils.getLocalPeriodIdentifiers(org.hisp.dhis.common.IdentifiableObjectUtils.getLocalPeriodIdentifiers) ITEMS(org.hisp.dhis.analytics.AnalyticsMetaDataKey.ITEMS) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) IdScheme(org.hisp.dhis.common.IdScheme) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) Grid(org.hisp.dhis.common.Grid) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader) Pager(org.hisp.dhis.common.Pager)

Example 9 with ValueType

use of org.hisp.dhis.common.ValueType 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 (CategoryOptionCombo 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) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 10 with ValueType

use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.

the class ValidationUtilsTest method testFileValueTypeOptionValidation.

@Test
void testFileValueTypeOptionValidation() throws IOException {
    long oneHundredMegaBytes = 1024 * (1024 * 100L);
    ValueType valueType = ValueType.FILE_RESOURCE;
    FileTypeValueOptions options = new FileTypeValueOptions();
    options.setMaxFileSize(oneHundredMegaBytes);
    options.setAllowedContentTypes(ImmutableSet.of("jpg", "pdf"));
    FileResource fileResource = new FileResource("name", "jpg", oneHundredMegaBytes, "md5sum", FileResourceDomain.DOCUMENT);
    assertNull(dataValueIsValid(fileResource, valueType, options));
    fileResource = new FileResource("name", "jpg", 1024 * (1024 * 101L), "md5sum", FileResourceDomain.DOCUMENT);
    assertEquals("not_valid_file_size_too_big", dataValueIsValid(fileResource, valueType, options));
    fileResource = new FileResource("name", "exe", oneHundredMegaBytes, "md5sum", FileResourceDomain.DOCUMENT);
    assertEquals("not_valid_file_content_type", dataValueIsValid(fileResource, valueType, options));
}
Also used : ValueType(org.hisp.dhis.common.ValueType) FileResource(org.hisp.dhis.fileresource.FileResource) FileTypeValueOptions(org.hisp.dhis.common.FileTypeValueOptions) Test(org.junit.jupiter.api.Test)

Aggregations

ValueType (org.hisp.dhis.common.ValueType)20 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 Date (java.util.Date)4 QueryItem (org.hisp.dhis.common.QueryItem)4 Matcher (java.util.regex.Matcher)3 Collectors (java.util.stream.Collectors)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)3 PeriodType (org.hisp.dhis.period.PeriodType)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 StringUtils (org.apache.commons.lang3.StringUtils)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2