Search in sources :

Example 11 with ProgramTrackedEntityAttribute

use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.

the class DefaultTrackedEntityAttributeService method getOrAddProgramTrackedEntityAttribute.

// -------------------------------------------------------------------------
// ProgramTrackedEntityAttribute
// -------------------------------------------------------------------------
@Override
public ProgramTrackedEntityAttribute getOrAddProgramTrackedEntityAttribute(String programUid, String attributeUid) {
    Program program = programService.getProgram(programUid);
    TrackedEntityAttribute attribute = getTrackedEntityAttribute(attributeUid);
    if (program == null || attribute == null) {
        return null;
    }
    ProgramTrackedEntityAttribute programAttribute = programAttributeStore.get(program, attribute);
    if (programAttribute == null) {
        programAttribute = new ProgramTrackedEntityAttribute(program, attribute);
        programAttributeStore.save(programAttribute);
    }
    return programAttribute;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Example 12 with ProgramTrackedEntityAttribute

use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.

the class DefaultTrackedEntityAttributeService method getProgramTrackedEntityAttribute.

@Override
public ProgramTrackedEntityAttribute getProgramTrackedEntityAttribute(String programUid, String attributeUid) {
    Program program = programService.getProgram(programUid);
    TrackedEntityAttribute attribute = getTrackedEntityAttribute(attributeUid);
    if (program == null || attribute == null) {
        return null;
    }
    return new ProgramTrackedEntityAttribute(program, attribute);
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Example 13 with ProgramTrackedEntityAttribute

use of org.hisp.dhis.program.ProgramTrackedEntityAttribute in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgram.

public static Program createProgram(char uniqueCharacter, Set<ProgramStage> programStages, Set<TrackedEntityAttribute> attributes, Set<OrganisationUnit> organisationUnits, DataElementCategoryCombo categoryCombo) {
    Program program = new Program();
    program.setAutoFields();
    program.setName("Program" + uniqueCharacter);
    program.setCode("ProgramCode" + uniqueCharacter);
    program.setShortName("ProgramShort" + uniqueCharacter);
    program.setDescription("Description" + uniqueCharacter);
    program.setEnrollmentDateLabel("DateOfEnrollmentDescription");
    program.setIncidentDateLabel("DateOfIncidentDescription");
    program.setProgramType(ProgramType.WITH_REGISTRATION);
    if (programStages != null) {
        for (ProgramStage programStage : programStages) {
            programStage.setProgram(program);
            program.getProgramStages().add(programStage);
        }
    }
    if (attributes != null) {
        for (TrackedEntityAttribute attribute : attributes) {
            ProgramTrackedEntityAttribute ptea = new ProgramTrackedEntityAttribute(program, attribute, false, false);
            ptea.setAutoFields();
            program.getProgramAttributes().add(ptea);
        }
    }
    if (organisationUnits != null) {
        program.getOrganisationUnits().addAll(organisationUnits);
    }
    if (categoryCombo != null) {
        program.setCategoryCombo(categoryCombo);
    } else if (categoryService != null) {
        program.setCategoryCombo(categoryService.getDefaultDataElementCategoryCombo());
    }
    return program;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)13 Program (org.hisp.dhis.program.Program)9 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 ProgramStage (org.hisp.dhis.program.ProgramStage)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 PeriodType (org.hisp.dhis.period.PeriodType)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 RelationshipType (org.hisp.dhis.relationship.RelationshipType)2 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1