Search in sources :

Example 31 with TrackedEntityAttribute

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

the class AbstractTrackedEntityInstanceService method validateAttributeType.

//--------------------------------------------------------------------------
// VALIDATION
//--------------------------------------------------------------------------
private List<ImportConflict> validateAttributeType(Attribute attribute, ImportOptions importOptions) {
    List<ImportConflict> importConflicts = Lists.newArrayList();
    if (attribute == null || attribute.getValue() == null) {
        return importConflicts;
    }
    TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute(importOptions.getIdSchemes(), attribute.getAttribute());
    if (trackedEntityAttribute == null) {
        importConflicts.add(new ImportConflict("Attribute.attribute", "Does not point to a valid attribute."));
        return importConflicts;
    }
    String errorMessage = trackedEntityAttributeService.validateValueType(trackedEntityAttribute, attribute.getValue());
    if (errorMessage != null) {
        importConflicts.add(new ImportConflict("Attribute.value", errorMessage));
    }
    return importConflicts;
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 32 with TrackedEntityAttribute

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

the class UpdateProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    displayProvidedOtherFacility = (displayProvidedOtherFacility == null) ? false : displayProvidedOtherFacility;
    displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
    generateBydEnrollmentDate = (generateBydEnrollmentDate == null) ? false : generateBydEnrollmentDate;
    ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
    blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
    remindCompleted = (remindCompleted == null) ? false : remindCompleted;
    selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
    selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
    Program program = programService.getProgram(id);
    program.setName(StringUtils.trimToNull(name));
    program.setShortName(StringUtils.trimToNull(shortName));
    program.setDescription(StringUtils.trimToNull(description));
    program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
    program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
    program.setProgramType(programType);
    program.setDisplayIncidentDate(displayIncidentDate);
    program.setOnlyEnrollOnce(onlyEnrollOnce);
    program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
    program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
    program.setSkipOffline(skipOffline);
    program.setDisplayFrontPageList(displayFrontPageList);
    program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
    program.setCaptureCoordinates(captureCoordinates);
    program.setExpiryDays(expiryDays);
    program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
    if (program.isRegistration()) {
        program.setIgnoreOverdueEvents(ignoreOverdueEvents);
    } else {
        program.setIgnoreOverdueEvents(false);
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        program.setExpiryPeriodType(null);
    }
    if (relationshipTypeId != null) {
        RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
        program.setRelationshipType(relationshipType);
        program.setRelationshipFromA(relationshipFromA);
        program.setRelationshipText(relationshipText);
        Program relatedProgram = programService.getProgram(relatedProgramId);
        program.setRelatedProgram(relatedProgram);
    } else {
        program.setRelationshipType(null);
        program.setRelationshipFromA(null);
        program.setRelationshipText(null);
        program.setRelatedProgram(null);
    }
    if (trackedEntityId != null) {
        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
        program.setTrackedEntity(trackedEntity);
    } else if (program.getTrackedEntity() != null) {
        program.setTrackedEntity(null);
    }
    if (program.getProgramAttributes() != null) {
        program.getProgramAttributes().clear();
    }
    int index = 0;
    for (String selectedPropertyId : selectedPropertyIds) {
        String[] ids = selectedPropertyId.split("_");
        if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
            TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
            ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
            programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
            programAttribute.setAutoFields();
            program.getProgramAttributes().add(programAttribute);
        }
        index++;
    }
    //TODO make more fine-grained
    program.increaseVersion();
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(program, jsonAttributeValues);
    }
    if (categoryComboId != null) {
        program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }
    if (workflowId != null && workflowId > 0) {
        program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
    } else {
        program.setWorkflow(null);
    }
    programService.updateProgram(program);
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 33 with TrackedEntityAttribute

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

the class AddProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
    ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
    onlyEnrollOnce = (onlyEnrollOnce == null) ? false : onlyEnrollOnce;
    selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
    selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
    Program program = new Program();
    program.setName(StringUtils.trimToNull(name));
    program.setShortName(StringUtils.trimToNull(shortName));
    program.setDescription(StringUtils.trimToNull(description));
    program.setVersion(1);
    program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
    program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
    program.setProgramType(programType);
    program.setDisplayIncidentDate(displayIncidentDate);
    program.setOnlyEnrollOnce(onlyEnrollOnce);
    program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
    program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
    program.setSkipOffline(skipOffline);
    program.setDisplayFrontPageList(displayFrontPageList);
    program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
    program.setCaptureCoordinates(captureCoordinates);
    program.setExpiryDays(expiryDays);
    program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
    if (programType == ProgramType.WITH_REGISTRATION) {
        program.setIgnoreOverdueEvents(ignoreOverdueEvents);
    } else {
        program.setIgnoreOverdueEvents(false);
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        program.setExpiryPeriodType(null);
    }
    if (relationshipTypeId != null) {
        RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
        program.setRelationshipType(relationshipType);
        program.setRelationshipFromA(relationshipFromA);
        program.setRelationshipText(relationshipText);
        Program relatedProgram = programService.getProgram(relatedProgramId);
        program.setRelatedProgram(relatedProgram);
    } else {
        program.setRelationshipType(null);
        program.setRelationshipFromA(null);
        program.setRelationshipText(null);
        program.setRelatedProgram(null);
    }
    if (trackedEntityId != null) {
        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
        program.setTrackedEntity(trackedEntity);
    }
    if (categoryComboId != null) {
        program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }
    if (workflowId != null && workflowId > 0) {
        program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
    }
    programService.addProgram(program);
    int index = 0;
    for (String selectedPropertyId : selectedPropertyIds) {
        String[] ids = selectedPropertyId.split("_");
        if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
            TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
            ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
            programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
            programAttribute.setAutoFields();
            program.getProgramAttributes().add(programAttribute);
        }
        index++;
    }
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(program, jsonAttributeValues);
    }
    programService.updateProgram(program);
    if (program.isWithoutRegistration()) {
        ProgramStage programStage = new ProgramStage();
        programStage.setName(name);
        programStage.setDescription(description);
        programStage.setProgram(program);
        programStage.setMinDaysFromStart(0);
        programStage.setAutoGenerateEvent(true);
        programStage.setExecutionDateLabel(REPORT_DATE_DESCRIPTION);
        programStageService.saveProgramStage(programStage);
    }
    if (program.isWithoutRegistration()) {
        // Add a new program-instance
        ProgramInstance programInstance = new ProgramInstance();
        programInstance.setEnrollmentDate(new Date());
        programInstance.setIncidentDate(new Date());
        programInstance.setProgram(program);
        programInstance.setStatus(ProgramStatus.ACTIVE);
        programInstanceService.addProgramInstance(programInstance);
    }
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date)

Example 34 with TrackedEntityAttribute

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

the class DefaultProgramIndicatorService method getExpressionDescription.

@Override
@Transactional
public String getExpressionDescription(String expression) {
    if (expression == null) {
        return null;
    }
    I18n i18n = i18nManager.getI18n();
    StringBuffer description = 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 programStageName = programStage.getDisplayName();
                String dataelementName = dataElement.getDisplayName();
                matcher.appendReplacement(description, programStageName + ProgramIndicator.SEPARATOR_ID + dataelementName);
            }
        } else if (ProgramIndicator.KEY_ATTRIBUTE.equals(key)) {
            TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(uid);
            if (attribute != null) {
                matcher.appendReplacement(description, attribute.getDisplayName());
            }
        } else if (ProgramIndicator.KEY_CONSTANT.equals(key)) {
            Constant constant = constantService.getConstant(uid);
            if (constant != null) {
                matcher.appendReplacement(description, constant.getDisplayName());
            }
        } else if (ProgramIndicator.KEY_PROGRAM_VARIABLE.equals(key)) {
            String varName = i18n.getString(uid);
            if (varName != null) {
                matcher.appendReplacement(description, varName);
            }
        }
    }
    matcher.appendTail(description);
    return description.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) I18n(org.hisp.dhis.i18n.I18n) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with TrackedEntityAttribute

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

the class BaseAnalyticalObjectTest method testPopulateAnalyticalProperties.

@Test
public void testPopulateAnalyticalProperties() {
    TrackedEntityAttribute tea = new TrackedEntityAttribute();
    tea.setAutoFields();
    TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:10");
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.getColumnDimensions().add(tea.getUid());
    eventChart.getAttributeDimensions().add(tead);
    eventChart.populateAnalyticalProperties();
    assertEquals(1, eventChart.getColumns().size());
    DimensionalObject dim = eventChart.getColumns().get(0);
    assertNotNull(dim);
    assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
    assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
    assertEquals(tead.getFilter(), dim.getFilter());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) EventChart(org.hisp.dhis.eventchart.EventChart) Test(org.junit.Test)

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