Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with TrackedEntityAttribute

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

the class ProgramStageInstanceServiceTest method setUpTest.

@Override
public void setUpTest() {
    mockFormat = new MockI18nFormat();
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnitA);
    organisationUnitB = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(organisationUnitB);
    entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
    entityInstanceService.addTrackedEntityInstance(entityInstanceA);
    entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
    entityInstanceService.addTrackedEntityInstance(entityInstanceB);
    TrackedEntityAttribute attribute = createTrackedEntityAttribute('A');
    attribute.setValueType(ValueType.PHONE_NUMBER);
    attributeService.addTrackedEntityAttribute(attribute);
    TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA, attribute);
    attributeValue.setValue("123456789");
    attributeValueService.addTrackedEntityAttributeValue(attributeValue);
    entityInstanceA.getTrackedEntityAttributeValues().add(attributeValue);
    entityInstanceService.updateTrackedEntityInstance(entityInstanceA);
    /**
         * Program A
         */
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programService.addProgram(programA);
    stageA = createProgramStage('A', 0);
    stageA.setProgram(programA);
    stageA.setSortOrder(1);
    programStageService.saveProgramStage(stageA);
    stageB = new ProgramStage("B", programA);
    stageB.setSortOrder(2);
    programStageService.saveProgramStage(stageB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(stageA);
    programStages.add(stageB);
    programA.setProgramStages(programStages);
    programService.updateProgram(programA);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    stageDataElementA = new ProgramStageDataElement(stageA, dataElementA, false, 1);
    stageDataElementB = new ProgramStageDataElement(stageA, dataElementB, false, 2);
    stageDataElementC = new ProgramStageDataElement(stageB, dataElementA, false, 1);
    stageDataElementD = new ProgramStageDataElement(stageB, dataElementB, false, 2);
    programStageDataElementService.addProgramStageDataElement(stageDataElementA);
    programStageDataElementService.addProgramStageDataElement(stageDataElementB);
    programStageDataElementService.addProgramStageDataElement(stageDataElementC);
    programStageDataElementService.addProgramStageDataElement(stageDataElementD);
    /**
         * Program B
         */
    Program programB = createProgram('B', new HashSet<>(), organisationUnitB);
    programService.addProgram(programB);
    stageC = new ProgramStage("C", programB);
    stageC.setSortOrder(1);
    programStageService.saveProgramStage(stageC);
    stageD = new ProgramStage("D", programB);
    stageB.setSortOrder(2);
    stageC.setRepeatable(true);
    programStageService.saveProgramStage(stageD);
    programStages = new HashSet<>();
    programStages.add(stageC);
    programStages.add(stageD);
    programB.setProgramStages(programStages);
    programService.updateProgram(programB);
    /**
         * Program Instance and Program Stage Instance
         */
    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays(70);
    incidenDate = testDate1.toDate();
    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    enrollmentDate = testDate2.toDate();
    programInstanceA = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programA);
    programInstanceA.setUid("UID-PIA");
    programInstanceService.addProgramInstance(programInstanceA);
    programInstanceB = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceB, programB);
    programInstanceService.addProgramInstance(programInstanceB);
    programStageInstanceA = new ProgramStageInstance(programInstanceA, stageA);
    programStageInstanceA.setDueDate(enrollmentDate);
    programStageInstanceA.setUid("UID-A");
    programStageInstanceB = new ProgramStageInstance(programInstanceA, stageB);
    programStageInstanceB.setDueDate(enrollmentDate);
    programStageInstanceB.setUid("UID-B");
    programStageInstanceC = new ProgramStageInstance(programInstanceB, stageC);
    programStageInstanceC.setDueDate(enrollmentDate);
    programStageInstanceC.setUid("UID-C");
    programStageInstanceD1 = new ProgramStageInstance(programInstanceB, stageD);
    programStageInstanceD1.setDueDate(enrollmentDate);
    programStageInstanceD1.setUid("UID-D1");
    programStageInstanceD2 = new ProgramStageInstance(programInstanceB, stageD);
    programStageInstanceD2.setDueDate(enrollmentDate);
    programStageInstanceD2.setUid("UID-D2");
}
Also used : MockI18nFormat(org.hisp.dhis.mock.MockI18nFormat) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

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