Search in sources :

Example 36 with TrackedEntityAttribute

use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getCoordinateField.

@Override
public String getCoordinateField(String coordinateField) {
    if (coordinateField == null || EventQueryParams.EVENT_COORDINATE_FIELD.equals(coordinateField)) {
        return "geom";
    }
    DataElement dataElement = dataElementService.getDataElement(coordinateField);
    if (dataElement != null) {
        if (ValueType.COORDINATE != dataElement.getValueType()) {
            throw new IllegalQueryException("Data element must be of value type coordinate to be used as coordinate field: " + coordinateField);
        }
        return dataElement.getUid();
    }
    TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(coordinateField);
    if (attribute != null) {
        if (ValueType.COORDINATE != attribute.getValueType()) {
            throw new IllegalQueryException("Attribute must be of value type coordinate to be used as coordinate field: " + coordinateField);
        }
        return attribute.getUid();
    }
    throw new IllegalQueryException("Cluster field not valid: " + coordinateField);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 37 with TrackedEntityAttribute

use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.

the class JdbcEnrollmentAnalyticsTableManager method getDimensionColumns.

@Override
protected 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 + "'";
    List<AnalyticsTableColumn> columns = new ArrayList<>();
    List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
    List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
    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 (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
        String column = quote(periodType.getName().toLowerCase());
        columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
    }
    for (ProgramStage programStage : table.getProgram().getProgramStages()) {
        for (ProgramStageDataElement programStageDataElement : programStage.getProgramStageDataElements()) {
            DataElement dataElement = programStageDataElement.getDataElement();
            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 tedv " + "inner join programstageinstance psi on psi.programstageinstanceid = tedv.programstageinstanceid " + "where psi.executiondate is not null " + "and psi.deleted is false " + "and psi.programinstanceid=pi.programinstanceid " + dataClause + " " + "and tedv.dataelementid=" + dataElement.getId() + " " + "and psi.programstageid=" + programStage.getId() + " " + "order by psi.executiondate desc " + "limit 1) as " + quote(programStage.getUid() + DB_SEPARATOR_ID + dataElement.getUid());
            columns.add(new AnalyticsTableColumn(quote(programStage.getUid() + DB_SEPARATOR_ID + dataElement.getUid()), dataType, sql, skipIndex));
        }
    }
    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));
    }
    AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
    AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
    AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
    final String executionDateSql = "(select psi.executionDate from programstageinstance psi " + "where psi.programinstanceid=pi.programinstanceid " + "and psi.executiondate is not null " + "and psi.deleted is false " + "order by psi.executiondate desc " + "limit 1) as " + quote("executiondate");
    AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", executionDateSql);
    final String dueDateSql = "(select psi.duedate from programstageinstance psi " + "where psi.programinstanceid = pi.programinstanceid " + "and psi.duedate is not null " + "and psi.deleted is false " + "order by psi.duedate desc " + "limit 1) as " + quote("duedate");
    AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", dueDateSql);
    AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "case status when 'COMPLETED' then enddate end");
    AnalyticsTableColumn es = new AnalyticsTableColumn(quote("enrollmentstatus"), "character(50)", "pi.status");
    AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "pi.longitude");
    AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "pi.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(pi, erd, id, ed, es, dd, cd, longitude, latitude, ou, oun, ouc));
    if (databaseInfo.isSpatialSupport()) {
        String alias = "(select ST_SetSRID(ST_MakePoint(pi.longitude, pi.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) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ProgramStage(org.hisp.dhis.program.ProgramStage) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 38 with TrackedEntityAttribute

use of org.hisp.dhis.trackedentity.TrackedEntityAttribute in project dhis2-core by dhis2.

the class DefaultDimensionService method getDimensionType.

@Override
public DimensionType getDimensionType(String uid) {
    DataElementCategory cat = idObjectManager.get(DataElementCategory.class, uid);
    if (cat != null) {
        return DimensionType.CATEGORY;
    }
    DataElementGroupSet degs = idObjectManager.get(DataElementGroupSet.class, uid);
    if (degs != null) {
        return DimensionType.DATA_ELEMENT_GROUP_SET;
    }
    OrganisationUnitGroupSet ougs = idObjectManager.get(OrganisationUnitGroupSet.class, uid);
    if (ougs != null) {
        return DimensionType.ORGANISATION_UNIT_GROUP_SET;
    }
    CategoryOptionGroupSet cogs = idObjectManager.get(CategoryOptionGroupSet.class, uid);
    if (cogs != null) {
        return DimensionType.CATEGORY_OPTION_GROUP_SET;
    }
    TrackedEntityAttribute tea = idObjectManager.get(TrackedEntityAttribute.class, uid);
    if (tea != null) {
        return DimensionType.PROGRAM_ATTRIBUTE;
    }
    DataElement pde = idObjectManager.get(DataElement.class, uid);
    if (pde != null && DataElementDomain.TRACKER.equals(pde.getDomainType())) {
        return DimensionType.PROGRAM_DATA_ELEMENT;
    }
    ProgramIndicator pin = idObjectManager.get(ProgramIndicator.class, uid);
    if (pin != null) {
        return DimensionType.PROGRAM_INDICATOR;
    }
    final Map<String, DimensionType> dimObjectTypeMap = new HashMap<>();
    dimObjectTypeMap.put(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X);
    dimObjectTypeMap.put(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD);
    dimObjectTypeMap.put(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT);
    return dimObjectTypeMap.get(uid);
}
Also used : DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionType(org.hisp.dhis.common.DimensionType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) HashMap(java.util.HashMap) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)38 DataElement (org.hisp.dhis.dataelement.DataElement)10 Program (org.hisp.dhis.program.Program)10 ArrayList (java.util.ArrayList)9 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)9 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)9 Date (java.util.Date)8 HashSet (java.util.HashSet)5 List (java.util.List)5 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)5 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)4 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)4 Grid (org.hisp.dhis.common.Grid)4 QueryItem (org.hisp.dhis.common.QueryItem)4 PeriodType (org.hisp.dhis.period.PeriodType)4 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3