Search in sources :

Example 31 with TrackedEntityType

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

the class ProgramSupplier method loadPrograms.

private Map<String, Program> loadPrograms(IdSchemes idSchemes) {
    // Get Id scheme for programs, programs should support also the
    // attribute scheme based on JSONB
    IdScheme idScheme = idSchemes.getProgramIdScheme();
    String sqlSelect = "select p.programid as id, p.uid, p.code, p.name, p.sharing as program_sharing, " + "p.type, p.opendaysaftercoenddate, tet.trackedentitytypeid, tet.sharing  as tet_sharing, " + "tet.uid           as tet_uid, c.categorycomboid as catcombo_id, " + "c.uid             as catcombo_uid, c.name            as catcombo_name, " + "c.code            as catcombo_code, ps.programstageid as ps_id, ps.uid as ps_uid, " + "ps.code           as ps_code, ps.name           as ps_name, " + "ps.featuretype    as ps_feature_type, ps.sort_order, ps.sharing   as ps_sharing, " + "ps.repeatable     as ps_repeatable, ps.enableuserassignment, ps.validationstrategy";
    if (idScheme.isAttribute()) {
        sqlSelect += ",p.attributevalues->'" + idScheme.getAttribute() + "'->>'value' as " + ATTRIBUTESCHEME_COL;
    }
    final String sql = sqlSelect + " from program p " + "LEFT JOIN categorycombo c on p.categorycomboid = c.categorycomboid " + "LEFT JOIN trackedentitytype tet on p.trackedentitytypeid = tet.trackedentitytypeid " + "LEFT JOIN programstage ps on p.programid = ps.programid " + "LEFT JOIN program_organisationunits pou on p.programid = pou.programid " + "LEFT JOIN organisationunit ou on pou.organisationunitid = ou.organisationunitid " + "group by p.programid, tet.trackedentitytypeid, c.categorycomboid, ps.programstageid, ps.sort_order " + "order by p.programid, ps.sort_order";
    return jdbcTemplate.query(sql, (ResultSet rs) -> {
        Map<String, Program> results = new HashMap<>();
        long programId = 0;
        while (rs.next()) {
            if (programId != rs.getLong("id")) {
                Set<ProgramStage> programStages = new HashSet<>();
                Program program = new Program();
                program.setId(rs.getLong("id"));
                program.setUid(rs.getString("uid"));
                program.setName(rs.getString("name"));
                program.setCode(rs.getString("code"));
                program.setOpenDaysAfterCoEndDate(rs.getInt("opendaysaftercoenddate"));
                program.setProgramType(ProgramType.fromValue(rs.getString("type")));
                program.setSharing(toSharing(rs.getString("program_sharing")));
                // Program Stage without a Program Id
                if (rs.getLong("ps_id") != 0) {
                    programStages.add(toProgramStage(rs));
                }
                CategoryCombo categoryCombo = new CategoryCombo();
                categoryCombo.setId(rs.getLong("catcombo_id"));
                categoryCombo.setUid(rs.getString("catcombo_uid"));
                categoryCombo.setName(rs.getString("catcombo_name"));
                categoryCombo.setCode(rs.getString("catcombo_code"));
                program.setCategoryCombo(categoryCombo);
                long tetId = rs.getLong(TRACKED_ENTITY_TYPE_ID);
                if (tetId != 0) {
                    TrackedEntityType trackedEntityType = new TrackedEntityType();
                    trackedEntityType.setId(tetId);
                    trackedEntityType.setUid(rs.getString("tet_uid"));
                    trackedEntityType.setSharing(toSharing(rs.getString("tet_sharing")));
                    program.setTrackedEntityType(trackedEntityType);
                }
                program.setProgramStages(programStages);
                results.put(getProgramKey(idScheme, rs), program);
                programId = program.getId();
            } else {
                results.get(getProgramKey(idScheme, rs)).getProgramStages().add(toProgramStage(rs));
            }
        }
        return results;
    });
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Program(org.hisp.dhis.program.Program) HashMap(java.util.HashMap) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ResultSet(java.sql.ResultSet) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage) HashSet(java.util.HashSet)

Example 32 with TrackedEntityType

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

the class AbstractTrackedEntityInstanceService method createDAOTrackedEntityInstance.

private org.hisp.dhis.trackedentity.TrackedEntityInstance createDAOTrackedEntityInstance(TrackedEntityInstance dtoEntityInstance, ImportOptions importOptions, ImportSummary importSummary) {
    if (StringUtils.isEmpty(dtoEntityInstance.getOrgUnit())) {
        importSummary.addConflict(dtoEntityInstance.getTrackedEntityInstance(), "No org unit ID in tracked entity instance object");
        return null;
    }
    org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
    OrganisationUnit organisationUnit = getOrganisationUnit(importOptions.getIdSchemes(), dtoEntityInstance.getOrgUnit());
    if (organisationUnit == null) {
        importSummary.addConflict(dtoEntityInstance.getTrackedEntityInstance(), "Invalid org unit ID: " + dtoEntityInstance.getOrgUnit());
        return null;
    }
    daoEntityInstance.setOrganisationUnit(organisationUnit);
    TrackedEntityType trackedEntityType = getTrackedEntityType(importOptions.getIdSchemes(), dtoEntityInstance.getTrackedEntityType());
    if (trackedEntityType == null) {
        importSummary.addConflict(dtoEntityInstance.getTrackedEntityInstance(), "Invalid tracked entity ID: " + dtoEntityInstance.getTrackedEntityType());
        return null;
    }
    if (dtoEntityInstance.getGeometry() != null) {
        FeatureType featureType = trackedEntityType.getFeatureType();
        if (featureType.equals(FeatureType.NONE) || !featureType.equals(FeatureType.getTypeFromName(dtoEntityInstance.getGeometry().getGeometryType()))) {
            importSummary.addConflict(dtoEntityInstance.getTrackedEntityInstance(), "Geometry does not conform to feature type '" + featureType + "'");
            importSummary.incrementIgnored();
            return null;
        } else {
            daoEntityInstance.setGeometry(dtoEntityInstance.getGeometry());
        }
    } else if (!FeatureType.NONE.equals(dtoEntityInstance.getFeatureType()) && dtoEntityInstance.getCoordinates() != null) {
        try {
            daoEntityInstance.setGeometry(GeoUtils.getGeometryFromCoordinatesAndType(dtoEntityInstance.getFeatureType(), dtoEntityInstance.getCoordinates()));
        } catch (IOException e) {
            importSummary.addConflict(dtoEntityInstance.getTrackedEntityInstance(), "Could not parse coordinates");
            importSummary.incrementIgnored();
            return null;
        }
    } else {
        daoEntityInstance.setGeometry(null);
    }
    daoEntityInstance.setTrackedEntityType(trackedEntityType);
    daoEntityInstance.setUid(CodeGenerator.isValidUid(dtoEntityInstance.getTrackedEntityInstance()) ? dtoEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateUid());
    String storedBy = !StringUtils.isEmpty(dtoEntityInstance.getStoredBy()) ? dtoEntityInstance.getStoredBy() : (importOptions.getUser() == null || StringUtils.isEmpty(importOptions.getUser().getUsername()) ? "system-process" : importOptions.getUser().getUsername());
    daoEntityInstance.setStoredBy(storedBy);
    daoEntityInstance.setPotentialDuplicate(dtoEntityInstance.isPotentialDuplicate());
    updateDateFields(dtoEntityInstance, daoEntityInstance);
    return daoEntityInstance;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) FeatureType(org.hisp.dhis.organisationunit.FeatureType) IOException(java.io.IOException)

Example 33 with TrackedEntityType

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

the class EventImportTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    CategoryOption categoryOption1 = new CategoryOption("male");
    categoryOption1.setAutoFields();
    CategoryOption categoryOption2 = new CategoryOption("female");
    categoryOption2.setAutoFields();
    manager.save(Lists.newArrayList(categoryOption1, categoryOption2));
    Category cat1 = new Category("cat1", DataDimensionType.DISAGGREGATION);
    cat1.setShortName(cat1.getName());
    cat1.setCategoryOptions(Lists.newArrayList(categoryOption1, categoryOption2));
    manager.save(Lists.newArrayList(cat1));
    CategoryCombo categoryCombo = manager.getByName(CategoryCombo.class, "default");
    categoryCombo.setCategories(Lists.newArrayList(cat1));
    dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.setCategoryCombo(categoryCombo);
    manager.save(dataElementA);
    dataElementA2 = createDataElement('a');
    dataElementA2.setValueType(ValueType.INTEGER);
    dataElementA2.setCategoryCombo(categoryCombo);
    manager.save(dataElementA2);
    dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.INTEGER);
    dataElementB.setCategoryCombo(categoryCombo);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageA.setFeatureType(FeatureType.POINT);
    manager.save(programStageA);
    programStageA2 = createProgramStage('a', 0);
    programStageA2.setFeatureType(FeatureType.POINT);
    programStageA2.setRepeatable(true);
    manager.save(programStageA2);
    programStageB = createProgramStage('B', 0);
    programStageB.setFeatureType(FeatureType.POINT);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setCategoryCombo(categoryCombo);
    manager.save(programA);
    programB = createProgram('B', new HashSet<>(), organisationUnitB);
    programB.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    programB.setCategoryCombo(categoryCombo);
    manager.save(programB);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    ProgramStageDataElement programStageDataElementA2 = new ProgramStageDataElement();
    programStageDataElementA2.setDataElement(dataElementA2);
    programStageDataElementA2.setProgramStage(programStageA2);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementA2);
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA2.getProgramStageDataElements().add(programStageDataElementA2);
    programStageA.setProgram(programA);
    programStageA2.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageA2);
    programStageB.getProgramStageDataElements().add(programStageDataElementB);
    programStageB.setProgram(programB);
    programB.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageA2);
    manager.update(programA);
    manager.update(programStageB);
    manager.update(programB);
    pi = new ProgramInstance();
    pi.setEnrollmentDate(new Date());
    pi.setIncidentDate(new Date());
    pi.setProgram(programB);
    pi.setStatus(ProgramStatus.ACTIVE);
    pi.setStoredBy("test");
    pi.setName("EventImportTestPI");
    pi.setUid(CodeGenerator.generateUid());
    manager.save(pi);
    event = createEvent("eventUid001");
    createUserAndInjectSecurityContext(true);
    // Flush all data to disk
    manager.flush();
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramInstance(org.hisp.dhis.program.ProgramInstance) CategoryOption(org.hisp.dhis.category.CategoryOption) Date(java.util.Date) HashSet(java.util.HashSet)

Example 34 with TrackedEntityType

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

the class RegistrationMultiEventsServiceTest method setUpTest.

@Override
protected void setUpTest() throws Exception {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    maleA = createTrackedEntityInstance(organisationUnitA);
    maleB = createTrackedEntityInstance(organisationUnitB);
    femaleA = createTrackedEntityInstance(organisationUnitA);
    femaleB = createTrackedEntityInstance(organisationUnitB);
    maleA.setTrackedEntityType(trackedEntityType);
    maleB.setTrackedEntityType(trackedEntityType);
    femaleA.setTrackedEntityType(trackedEntityType);
    femaleB.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    manager.save(maleB);
    manager.save(femaleA);
    manager.save(femaleB);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementB.setValueType(ValueType.INTEGER);
    manager.save(dataElementA);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageB = createProgramStage('B', 0);
    programStageB.setRepeatable(true);
    manager.save(programStageA);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    manager.save(programA);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA.setProgram(programA);
    programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementB);
    programStageDataElement.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageB.getProgramStageDataElements().add(programStageDataElement);
    programStageB.setProgram(programA);
    programStageB.setMinDaysFromStart(2);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageB);
    manager.update(programA);
    createUserAndInjectSecurityContext(true);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) HashSet(java.util.HashSet)

Example 35 with TrackedEntityType

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

the class EnrollmentSecurityTest method setUpTest.

@Override
protected void setUpTest() {
    userService = _userService;
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityType.getSharing().setPublicAccess(AccessStringHelper.FULL);
    manager.save(trackedEntityType, false);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementB.setValueType(ValueType.INTEGER);
    manager.save(dataElementA);
    manager.save(dataElementB);
    programStageA = createProgramStage('A', 0);
    programStageB = createProgramStage('B', 0);
    programStageB.setRepeatable(true);
    manager.save(programStageA);
    manager.save(programStageB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.setTrackedEntityType(trackedEntityType);
    manager.save(programA);
    ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementA);
    programStageDataElement.setProgramStage(programStageA);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageA.getProgramStageDataElements().add(programStageDataElement);
    programStageA.setProgram(programA);
    programStageDataElement = new ProgramStageDataElement();
    programStageDataElement.setDataElement(dataElementB);
    programStageDataElement.setProgramStage(programStageB);
    programStageDataElementService.addProgramStageDataElement(programStageDataElement);
    programStageB.getProgramStageDataElements().add(programStageDataElement);
    programStageB.setProgram(programA);
    programStageB.setMinDaysFromStart(2);
    programA.getProgramStages().add(programStageA);
    programA.getProgramStages().add(programStageB);
    manager.update(programStageA);
    manager.update(programStageB);
    manager.update(programA);
    maleA = createTrackedEntityInstance(organisationUnitA);
    maleB = createTrackedEntityInstance(organisationUnitB);
    femaleA = createTrackedEntityInstance(organisationUnitA);
    femaleB = createTrackedEntityInstance(organisationUnitB);
    maleA.setTrackedEntityType(trackedEntityType);
    maleB.setTrackedEntityType(trackedEntityType);
    femaleA.setTrackedEntityType(trackedEntityType);
    femaleB.setTrackedEntityType(trackedEntityType);
    manager.save(maleA);
    manager.save(maleB);
    manager.save(femaleA);
    manager.save(femaleB);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) HashSet(java.util.HashSet)

Aggregations

TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)57 Test (org.junit.jupiter.api.Test)27 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Program (org.hisp.dhis.program.Program)19 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)16 User (org.hisp.dhis.user.User)16 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)15 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)15 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 ProgramStage (org.hisp.dhis.program.ProgramStage)8 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)6 RelationshipType (org.hisp.dhis.relationship.RelationshipType)6 TrackedEntityTypeAttribute (org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)6 Collectors (java.util.stream.Collectors)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5