Search in sources :

Example 36 with Program

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

the class TrackedEntityAttributeStoreIntegrationTest method setUpTest.

@Override
public void setUpTest() {
    attributeW = createTrackedEntityAttribute('W');
    attributeW.setUnique(true);
    attributeY = createTrackedEntityAttribute('Y');
    attributeY.setUnique(true);
    attributeZ = createTrackedEntityAttribute('Z', ValueType.NUMBER);
    Program program = createProgram('A');
    programService.addProgram(program);
    TrackedEntityType trackedEntityTypeA = createTrackedEntityType('A');
    trackedEntityTypeA.setPublicAccess(AccessStringHelper.FULL);
    trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeA);
    TrackedEntityType trackedEntityTypeB = createTrackedEntityType('B');
    trackedEntityTypeB.setPublicAccess(AccessStringHelper.FULL);
    trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeB);
    // Create 20 Tracked Entity Attributes (named A .. O)
    IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).forEach(c -> attributeService.addTrackedEntityAttribute(createTrackedEntityAttribute(c.charAt(0), ValueType.TEXT)));
    // Transform the Tracked Entity Attributes into a List of
    // TrackedEntityTypeAttribute
    List<TrackedEntityTypeAttribute> teatList = IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).map(s -> new TrackedEntityTypeAttribute(trackedEntityTypeA, attributeService.getTrackedEntityAttributeByName("Attribute" + s))).collect(Collectors.toList());
    // Setting searchable to true for 5 random tracked entity type
    // attributes
    TrackedEntityTypeAttribute teta = teatList.get(0);
    teta.setSearchable(true);
    teta = teatList.get(4);
    teta.setSearchable(true);
    teta = teatList.get(9);
    teta.setSearchable(true);
    teta = teatList.get(14);
    teta.setSearchable(true);
    teta = teatList.get(19);
    teta.setSearchable(true);
    // Assign 10 TrackedEntityTypeAttribute to Tracked Entity Type A
    trackedEntityTypeA.getTrackedEntityTypeAttributes().addAll(teatList.subList(0, 10));
    trackedEntityTypeService.updateTrackedEntityType(trackedEntityTypeA);
    // Assign 10 TrackedEntityTypeAttribute to Tracked Entity Type B
    trackedEntityTypeB.getTrackedEntityTypeAttributes().addAll(teatList.subList(10, 20));
    trackedEntityTypeService.updateTrackedEntityType(trackedEntityTypeB);
    programB = createProgram('B');
    programService.addProgram(programB);
    List<ProgramTrackedEntityAttribute> pteaList = IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).map(s -> new ProgramTrackedEntityAttribute(programB, attributeService.getTrackedEntityAttributeByName("Attribute" + s))).collect(Collectors.toList());
    // Setting searchable to true for 5 random program tracked entity
    // attributes
    ProgramTrackedEntityAttribute ptea = pteaList.get(0);
    ptea.setSearchable(true);
    ptea = pteaList.get(4);
    ptea.setSearchable(true);
    ptea = pteaList.get(9);
    ptea.setSearchable(true);
    ptea = pteaList.get(13);
    ptea.setSearchable(true);
    ptea = pteaList.get(18);
    ptea.setSearchable(true);
    programB.getProgramAttributes().addAll(pteaList);
    programService.updateProgram(programB);
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IntegrationTestBase(org.hisp.dhis.IntegrationTestBase) AccessStringHelper(org.hisp.dhis.security.acl.AccessStringHelper) ValueType(org.hisp.dhis.common.ValueType) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Program(org.hisp.dhis.program.Program) TrackedEntityAttributeTableManager(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeTableManager) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ProgramService(org.hisp.dhis.program.ProgramService) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute)

Example 37 with Program

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

the class RelationshipUtilsTest method setup.

@BeforeEach
void setup() {
    OrganisationUnit ou = createOrganisationUnit('A');
    teiA = createTrackedEntityInstance('A', ou);
    teiB = createTrackedEntityInstance('B', ou);
    Program p = createProgram('A');
    piA = createProgramInstance(p, teiA, ou);
    ProgramStage ps = createProgramStage('A', p);
    psiA = createProgramStageInstance(ps, piA, ou);
    relationshipType = createRelationshipType('A');
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with Program

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

the class RelationshipTypeObjectBundleHook method handleRelationshipConstraintReferences.

/**
 * Handles the references for RelationshipConstraint, persisting any bject
 * that might end up in a transient state.
 */
private void handleRelationshipConstraintReferences(RelationshipConstraint relationshipConstraint) {
    TrackedEntityType trackedEntityType = relationshipConstraint.getTrackedEntityType();
    Program program = relationshipConstraint.getProgram();
    ProgramStage programStage = relationshipConstraint.getProgramStage();
    if (trackedEntityType != null) {
        trackedEntityType = trackedEntityTypeService.getTrackedEntityType(trackedEntityType.getUid());
        relationshipConstraint.setTrackedEntityType(trackedEntityType);
    }
    if (program != null) {
        program = programService.getProgram(program.getUid());
        relationshipConstraint.setProgram(program);
    }
    if (programStage != null) {
        programStage = programStageService.getProgramStage(programStage.getUid());
        relationshipConstraint.setProgramStage(programStage);
    }
    sessionFactory.getCurrentSession().save(relationshipConstraint);
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 39 with Program

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

the class MetadataOrgUnitMergeHandlerTest method testMergePrograms.

@Test
void testMergePrograms() {
    Program prA = createProgram('A');
    prA.addOrganisationUnit(ouA);
    prA.addOrganisationUnit(ouB);
    Program prB = createProgram('B');
    prB.addOrganisationUnit(ouA);
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    assertEquals(2, ouA.getPrograms().size());
    assertEquals(1, ouB.getPrograms().size());
    assertEquals(0, ouC.getPrograms().size());
    handler.mergePrograms(request);
    assertEquals(0, ouA.getPrograms().size());
    assertEquals(0, ouB.getPrograms().size());
    assertEquals(2, ouC.getPrograms().size());
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 40 with Program

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

the class DataDimensionExtractor method getBaseDimensionalItemObject.

private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
    BaseDimensionalItemObject dimensionalItemObject = null;
    switch(id.getDimensionItemType()) {
        case DATA_ELEMENT:
            DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            if (dataElement != null) {
                dimensionalItemObject = cloneIfNeeded(dataElement, id);
            }
            break;
        case INDICATOR:
            final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
            if (indicator != null) {
                dimensionalItemObject = cloneIfNeeded(indicator, id);
            }
            break;
        case DATA_ELEMENT_OPERAND:
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
            final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
            if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
                dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
            }
            break;
        case REPORTING_RATE:
            final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
            if (dataSet != null) {
                dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
            }
            break;
        case PROGRAM_DATA_ELEMENT:
            Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
            if (program != null && dataElement != null) {
                dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
            }
            break;
        case PROGRAM_ATTRIBUTE:
            program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
            if (program != null && attribute != null) {
                dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
            }
            break;
        case PROGRAM_INDICATOR:
            final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
            if (programIndicator != null) {
                dimensionalItemObject = cloneIfNeeded(programIndicator, id);
            }
            break;
        default:
            log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
            break;
    }
    return dimensionalItemObject;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37