Search in sources :

Example 1 with LegendSet

use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.

the class LegendSetController method postJsonObject.

@Override
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('F_GIS_ADMIN') or hasRole('F_LEGEND_SET_PUBLIC_ADD') or hasRole('F_LEGEND_SET_PRIVATE_ADD') or hasRole('ALL')")
@ResponseStatus(HttpStatus.CREATED)
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
    LegendSet legendSet = renderService.fromJson(request.getInputStream(), LegendSet.class);
    legendSet.getTranslations().clear();
    legendSetService.addLegendSet(legendSet);
    response.addHeader("Location", LegendSetSchemaDescriptor.API_ENDPOINT + "/" + legendSet.getUid());
    webMessageService.send(WebMessageUtils.created("Legend set created"), response, request);
}
Also used : LegendSet(org.hisp.dhis.legend.LegendSet) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with LegendSet

use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.

the class JdbcEventAnalyticsTableManager method getDimensionColumns.

@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
    final String dbl = statementBuilder.getDoubleColumnType();
    final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
    final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
    //TODO dateClause regular expression
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    if (table.getProgram().hasCategoryCombo()) {
        List<DataElementCategory> categories = table.getProgram().getCategoryCombo().getCategories();
        for (DataElementCategory category : categories) {
            if (category.isDataDimension()) {
                columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
            }
        }
    }
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
    for (OrganisationUnitLevel level : levels) {
        String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
        columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
    }
    for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
        columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
    }
    for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
    }
    for (DataElement dataElement : table.getProgram().getDataElements()) {
        ValueType valueType = dataElement.getValueType();
        String dataType = getColumnType(valueType);
        String dataClause = dataElement.isNumericType() ? numericClause : dataElement.getValueType().isDate() ? dateClause : "";
        String select = getSelectClause(valueType);
        boolean skipIndex = NO_INDEX_VAL_TYPES.contains(dataElement.getValueType()) && !dataElement.hasOptionSet();
        String sql = "(select " + select + " from trackedentitydatavalue where programstageinstanceid=psi.programstageinstanceid " + "and dataelementid=" + dataElement.getId() + dataClause + ") as " + quote(dataElement.getUid());
        columns.add(new AnalyticsTableColumn(quote(dataElement.getUid()), dataType, sql, skipIndex));
    }
    for (DataElement dataElement : table.getProgram().getDataElementsWithLegendSet()) {
        for (LegendSet legendSet : dataElement.getLegendSets()) {
            String column = quote(dataElement.getUid() + PartitionUtils.SEP + legendSet.getUid());
            String select = getSelectClause(dataElement.getValueType());
            String sql = "(select l.uid from maplegend l " + "inner join trackedentitydatavalue dv on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and dv.programstageinstanceid=psi.programstageinstanceid " + "and dv.dataelementid=" + dataElement.getId() + numericClause + ") as " + column;
            columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
        }
    }
    for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributes()) {
        String dataType = getColumnType(attribute.getValueType());
        String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
        String select = getSelectClause(attribute.getValueType());
        boolean skipIndex = NO_INDEX_VAL_TYPES.contains(attribute.getValueType()) && !attribute.hasOptionSet();
        String sql = "(select " + select + " from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid " + "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote(attribute.getUid());
        columns.add(new AnalyticsTableColumn(quote(attribute.getUid()), dataType, sql, skipIndex));
    }
    for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributesWithLegendSet()) {
        for (LegendSet legendSet : attribute.getLegendSets()) {
            String column = quote(attribute.getUid() + PartitionUtils.SEP + legendSet.getUid());
            String select = getSelectClause(attribute.getValueType());
            String sql = "(select l.uid from maplegend l " + "inner join trackedentityattributevalue av on l.startvalue <= " + select + " " + "and l.endvalue > " + select + " " + "and l.maplegendsetid=" + legendSet.getId() + " " + "and av.trackedentityinstanceid=pi.trackedentityinstanceid " + "and av.trackedentityattributeid=" + attribute.getId() + numericClause + ") as " + column;
            columns.add(new AnalyticsTableColumn(column, "character(11)", sql));
        }
    }
    AnalyticsTableColumn psi = new AnalyticsTableColumn(quote("psi"), "character(11) not null", "psi.uid");
    AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
    AnalyticsTableColumn ps = new AnalyticsTableColumn(quote("ps"), "character(11) not null", "ps.uid");
    AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
    AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
    AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
    AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", "psi.executiondate");
    AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", "psi.duedate");
    AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "psi.completeddate");
    AnalyticsTableColumn pes = new AnalyticsTableColumn(quote("pistatus"), "character(25)", "pi.status");
    AnalyticsTableColumn es = new AnalyticsTableColumn(quote("psistatus"), "character(25)", "psi.status");
    AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "psi.longitude");
    AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "psi.latitude");
    AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
    AnalyticsTableColumn oun = new AnalyticsTableColumn(quote("ouname"), "character varying(230) not null", "ou.name");
    AnalyticsTableColumn ouc = new AnalyticsTableColumn(quote("oucode"), "character varying(50)", "ou.code");
    columns.addAll(Lists.newArrayList(psi, pi, ps, ao, erd, id, ed, dd, cd, pes, es, longitude, latitude, ou, oun, ouc));
    if (databaseInfo.isSpatialSupport()) {
        String alias = "(select ST_SetSRID(ST_MakePoint(psi.longitude, psi.latitude), 4326)) as geom";
        columns.add(new AnalyticsTableColumn(quote("geom"), "geometry(Point, 4326)", alias, false, "gist"));
    }
    if (table.hasProgram() && table.getProgram().isRegistration()) {
        columns.add(new AnalyticsTableColumn(quote("tei"), "character(11)", "tei.uid"));
    }
    return filterDimensionColumns(columns);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ValueType(org.hisp.dhis.common.ValueType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) LegendSet(org.hisp.dhis.legend.LegendSet) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 3 with LegendSet

use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getQueryItemFromDimension.

private QueryItem getQueryItemFromDimension(String dimension, Program program) {
    String[] split = dimension.split(ITEM_SEP);
    String item = split[0];
    LegendSet legendSet = split.length > 1 && split[1] != null ? legendSetService.getLegendSet(split[1]) : null;
    DataElement de = dataElementService.getDataElement(item);
    if (de != null && program.containsDataElement(de)) {
        ValueType valueType = legendSet != null ? ValueType.TEXT : de.getValueType();
        return new QueryItem(de, legendSet, valueType, de.getAggregationType(), de.getOptionSet());
    }
    TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute(item);
    if (at != null && program.containsAttribute(at)) {
        ValueType valueType = legendSet != null ? ValueType.TEXT : at.getValueType();
        return new QueryItem(at, legendSet, valueType, at.getAggregationType(), at.getOptionSet());
    }
    ProgramIndicator pi = programIndicatorService.getProgramIndicatorByUid(item);
    if (pi != null && program.getProgramIndicators().contains(pi)) {
        return new QueryItem(pi, legendSet, ValueType.NUMBER, pi.getAggregationType(), null);
    }
    throw new IllegalQueryException("Item identifier does not reference any data element, attribute or indicator part of the program: " + item);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) LegendSet(org.hisp.dhis.legend.LegendSet)

Example 4 with LegendSet

use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.

the class DimensionServiceTest method testGetDimensionalObjectEventReport.

@Test
void testGetDimensionalObjectEventReport() {
    EventReport report = new EventReport();
    report.setAutoFields();
    DataElement deA = createDataElement('A');
    LegendSet lsA = createLegendSet('A');
    ProgramStage psA = createProgramStage('A', 1);
    TrackedEntityDataElementDimension teDeDim = new TrackedEntityDataElementDimension(deA, lsA, psA, "EQ:1");
    report.addTrackedEntityDataElementDimension(teDeDim);
    report.getOrganisationUnits().addAll(Lists.newArrayList(ouA, ouB, ouC));
    report.getColumnDimensions().add(deA.getUid());
    report.getRowDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
    report.populateAnalyticalProperties();
    assertEquals(1, report.getColumns().size());
    assertEquals(1, report.getRows().size());
    DimensionalObject dim = report.getColumns().get(0);
    assertEquals(lsA, dim.getLegendSet());
    assertEquals(psA, dim.getProgramStage());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) LegendSet(org.hisp.dhis.legend.LegendSet) ProgramStage(org.hisp.dhis.program.ProgramStage) EventReport(org.hisp.dhis.eventreport.EventReport) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with LegendSet

use of org.hisp.dhis.legend.LegendSet in project dhis2-core by dhis2.

the class DefaultMetadataExportService method handleLegendSet.

private SetMap<Class<? extends IdentifiableObject>, IdentifiableObject> handleLegendSet(SetMap<Class<? extends IdentifiableObject>, IdentifiableObject> metadata, List<LegendSet> legendSets) {
    if (legendSets == null)
        return metadata;
    for (LegendSet legendSet : legendSets) {
        metadata.putValue(LegendSet.class, legendSet);
        handleAttributes(metadata, legendSet);
        legendSet.getLegends().forEach(legend -> handleLegend(metadata, legend));
    }
    return metadata;
}
Also used : LegendSet(org.hisp.dhis.legend.LegendSet)

Aggregations

LegendSet (org.hisp.dhis.legend.LegendSet)24 Test (org.junit.jupiter.api.Test)10 DataElement (org.hisp.dhis.dataelement.DataElement)8 QueryItem (org.hisp.dhis.common.QueryItem)4 Legend (org.hisp.dhis.legend.Legend)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 List (java.util.List)2 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)2 DhisConvenienceTest.createLegendSet (org.hisp.dhis.DhisConvenienceTest.createLegendSet)2 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)2 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2