Search in sources :

Example 6 with TrackedEntityAttribute

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

the class AbstractTrackedEntityInstanceService method updateAttributeValues.

private void updateAttributeValues(TrackedEntityInstance trackedEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance) {
    for (Attribute attribute : trackedEntityInstance.getAttributes()) {
        TrackedEntityAttribute entityAttribute = manager.get(TrackedEntityAttribute.class, attribute.getAttribute());
        if (entityAttribute != null) {
            TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue();
            attributeValue.setEntityInstance(entityInstance);
            attributeValue.setValue(attribute.getValue());
            attributeValue.setAttribute(entityAttribute);
            trackedEntityAttributeValueService.addTrackedEntityAttributeValue(attributeValue);
        }
    }
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)

Example 7 with TrackedEntityAttribute

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

the class EventDataQueryServiceTest method testSetItemsForDimensionFilters.

@Test
public void testSetItemsForDimensionFilters() {
    TrackedEntityAttribute tea = new TrackedEntityAttribute();
    tea.setAutoFields();
    TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:2");
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.getColumnDimensions().add(tea.getUid());
    eventChart.getAttributeDimensions().add(tead);
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(tea.getUid(), tea.getName()));
    grid.addRow().addValue("1");
    grid.addRow().addValue("2");
    grid.addRow().addValue("3");
    grid.addRow().addValue(null);
    eventChart.populateAnalyticalProperties();
    DimensionalObject dim = eventChart.getColumns().get(0);
    DimensionalObjectUtils.setDimensionItemsForFilters(dim, grid, true);
    assertNotNull(dim);
    assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
    assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
    assertEquals(tead.getFilter(), dim.getFilter());
    List<DimensionalItemObject> items = dim.getItems();
    assertEquals(4, items.size());
    assertNotNull(items.get(0).getUid());
    assertNotNull(items.get(0).getName());
    assertNotNull(items.get(0).getCode());
    assertNotNull(items.get(0).getShortName());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) EventChart(org.hisp.dhis.eventchart.EventChart) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with TrackedEntityAttribute

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

the class DhisConvenienceTest method createTrackedEntityAttribute.

/**
     * @param uniqueChar A unique character to identify the object.
     * @return TrackedEntityAttribute
     */
public static TrackedEntityAttribute createTrackedEntityAttribute(char uniqueChar) {
    TrackedEntityAttribute attribute = new TrackedEntityAttribute();
    attribute.setAutoFields();
    attribute.setName("Attribute" + uniqueChar);
    attribute.setCode("AttributeCode" + uniqueChar);
    attribute.setDescription("Attribute" + uniqueChar);
    attribute.setValueType(ValueType.TEXT);
    attribute.setAggregationType(AggregationType.NONE);
    return attribute;
}
Also used : ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 9 with TrackedEntityAttribute

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

the class DhisConvenienceTest method createTrackedEntityAttribute.

/**
     * @param uniqueChar A unique character to identify the object.
     * @return TrackedEntityAttribute
     */
public static TrackedEntityAttribute createTrackedEntityAttribute(char uniqueChar, ValueType valueType) {
    TrackedEntityAttribute attribute = new TrackedEntityAttribute();
    attribute.setAutoFields();
    attribute.setName("Attribute" + uniqueChar);
    attribute.setCode("AttributeCode" + uniqueChar);
    attribute.setDescription("Attribute" + uniqueChar);
    attribute.setValueType(valueType);
    attribute.setAggregationType(AggregationType.NONE);
    return attribute;
}
Also used : ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 10 with TrackedEntityAttribute

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

the class DefaultProgramIndicatorService method getSubstitutedExpression.

/**
     * Generates an expression where all items are substituted with a sample value
     * in order to maintain a valid expression syntax.
     *
     * @param expression the expression.
     */
private String getSubstitutedExpression(String expression) {
    StringBuffer expr = new StringBuffer();
    Matcher matcher = ProgramIndicator.EXPRESSION_PATTERN.matcher(expression);
    while (matcher.find()) {
        String key = matcher.group(1);
        String uid = matcher.group(2);
        if (ProgramIndicator.KEY_DATAELEMENT.equals(key)) {
            String de = matcher.group(3);
            ProgramStage programStage = programStageService.getProgramStage(uid);
            DataElement dataElement = dataElementService.getDataElement(de);
            if (programStage != null && dataElement != null) {
                String sample = ValidationUtils.getSubstitutionValue(dataElement.getValueType());
                matcher.appendReplacement(expr, sample);
            } else {
                return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
            }
        } else if (ProgramIndicator.KEY_ATTRIBUTE.equals(key)) {
            TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(uid);
            if (attribute != null) {
                String sample = ValidationUtils.getSubstitutionValue(attribute.getValueType());
                matcher.appendReplacement(expr, sample);
            } else {
                return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
            }
        } else if (ProgramIndicator.KEY_CONSTANT.equals(key)) {
            Constant constant = constantService.getConstant(uid);
            if (constant != null) {
                matcher.appendReplacement(expr, String.valueOf(constant.getValue()));
            } else {
                return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
            }
        } else if (ProgramIndicator.KEY_PROGRAM_VARIABLE.equals(key)) {
            String sampleValue = VARIABLE_SAMPLE_VALUE_MAP.get(uid);
            if (sampleValue != null) {
                matcher.appendReplacement(expr, sampleValue);
            } else {
                return ProgramIndicator.UNKNOWN_VARIABLE;
            }
        }
    }
    matcher.appendTail(expr);
    return expr.toString();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Matcher(java.util.regex.Matcher) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Constant(org.hisp.dhis.constant.Constant)

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