Search in sources :

Example 1 with OrganisationUnitGroupSet

use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.

the class MergeServiceTest method mergeOrgUnitGroupSet.

@Test
public void mergeOrgUnitGroupSet() {
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    OrganisationUnit organisationUnitC = createOrganisationUnit('C');
    OrganisationUnit organisationUnitD = createOrganisationUnit('D');
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    organisationUnitGroupA.getMembers().add(organisationUnitA);
    organisationUnitGroupA.getMembers().add(organisationUnitB);
    organisationUnitGroupA.getMembers().add(organisationUnitC);
    organisationUnitGroupA.getMembers().add(organisationUnitD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
    organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
    mergeService.merge(new MergeParams<>(organisationUnitGroupSetA, organisationUnitGroupSetB).setMergeMode(MergeMode.REPLACE));
    assertFalse(organisationUnitGroupSetB.getOrganisationUnitGroups().isEmpty());
    assertEquals(organisationUnitGroupSetA.getName(), organisationUnitGroupSetB.getName());
    assertEquals(organisationUnitGroupSetA.getDescription(), organisationUnitGroupSetB.getDescription());
    assertEquals(organisationUnitGroupSetA.isCompulsory(), organisationUnitGroupSetB.isCompulsory());
    assertEquals(organisationUnitGroupSetA.isIncludeSubhierarchyInAnalytics(), organisationUnitGroupSetB.isIncludeSubhierarchyInAnalytics());
    assertEquals(1, organisationUnitGroupSetB.getOrganisationUnitGroups().size());
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MergeParams(org.hisp.dhis.schema.MergeParams) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with OrganisationUnitGroupSet

use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getOrganisationUnitsViolatingExclusiveGroupSets.

@Override
public SortedMap<OrganisationUnit, Collection<OrganisationUnitGroup>> getOrganisationUnitsViolatingExclusiveGroupSets() {
    Collection<OrganisationUnitGroupSet> groupSets = organisationUnitGroupService.getAllOrganisationUnitGroupSets();
    TreeMap<OrganisationUnit, Collection<OrganisationUnitGroup>> targets = new TreeMap<>();
    for (OrganisationUnitGroupSet groupSet : groupSets) {
        Collection<OrganisationUnit> duplicates = getDuplicates(new ArrayList<>(groupSet.getOrganisationUnits()));
        for (OrganisationUnit duplicate : duplicates) {
            targets.put(duplicate, new HashSet<>(duplicate.getGroups()));
        }
    }
    return targets;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Collection(java.util.Collection) TreeMap(java.util.TreeMap) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 3 with OrganisationUnitGroupSet

use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.

the class OrganisationUnitGroupSetResourceTable method getCreateTempTableStatement.

@Override
public String getCreateTempTableStatement() {
    String statement = "create table " + getTempTableName() + " (" + "organisationunitid integer not null, " + "organisationunitname varchar(230), ";
    for (OrganisationUnitGroupSet groupSet : objects) {
        statement += columnQuote + groupSet.getName() + columnQuote + " varchar(230), ";
        statement += columnQuote + groupSet.getUid() + columnQuote + " character(11), ";
    }
    statement += "primary key (organisationunitid))";
    return statement;
}
Also used : OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 4 with OrganisationUnitGroupSet

use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.

the class OrganisationUnitGroupSetResourceTable method getPopulateTempTableStatement.

@Override
public Optional<String> getPopulateTempTableStatement() {
    String sql = "insert into " + getTempTableName() + " " + "select ou.organisationunitid as organisationunitid, ou.name as organisationunitname, ";
    for (OrganisationUnitGroupSet groupSet : objects) {
        if (!groupSet.isIncludeSubhierarchyInAnalytics()) {
            sql += "(" + "select oug.name from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "where ougm.organisationunitid = ou.organisationunitid " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
            sql += "(" + "select oug.uid from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "where ougm.organisationunitid = ou.organisationunitid " + "limit 1) as " + columnQuote + groupSet.getUid() + columnQuote + ", ";
        } else {
            sql += "(" + "select oug.name " + "from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "inner join organisationunit ou2 ON ou2.organisationunitid = ougm.organisationunitid AND ou.path LIKE concat(ou2.path, '%') " + "where ougm.orgunitgroupid is not null " + "order by hierarchylevel desc " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
            sql += "(" + "select oug.uid " + "from orgunitgroup oug " + "inner join orgunitgroupmembers ougm on ougm.orgunitgroupid = oug.orgunitgroupid " + "inner join orgunitgroupsetmembers ougsm on ougsm.orgunitgroupid = ougm.orgunitgroupid and ougsm.orgunitgroupsetid = " + groupSet.getId() + " " + "inner join organisationunit ou2 ON ou2.organisationunitid = ougm.organisationunitid AND ou.path LIKE concat(ou2.path, '%') " + "where ougm.orgunitgroupid is not null " + "order by hierarchylevel desc " + "limit 1) as " + columnQuote + groupSet.getName() + columnQuote + ", ";
        }
    }
    sql = TextUtils.removeLastComma(sql) + " ";
    sql += "from organisationunit ou";
    return Optional.of(sql);
}
Also used : OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 5 with OrganisationUnitGroupSet

use of org.hisp.dhis.organisationunit.OrganisationUnitGroupSet in project dhis2-core by dhis2.

the class OrganisationUnitLocationController method getEntitiesWithinRange.

/**
     * Get Organisation Units within a distance from a location
     */
@RequestMapping(value = "/withinRange", method = RequestMethod.GET, produces = { "*/*", "application/json" })
public void getEntitiesWithinRange(@RequestParam Double longitude, @RequestParam Double latitude, @RequestParam Double distance, @RequestParam(required = false) String orgUnitGroupSetId, HttpServletResponse response) throws Exception {
    List<OrganisationUnit> entityList = new ArrayList<>(organisationUnitService.getOrganisationUnitWithinDistance(longitude, latitude, distance));
    for (OrganisationUnit organisationUnit : entityList) {
        Set<AttributeValue> attributeValues = organisationUnit.getAttributeValues();
        attributeValues.clear();
        if (orgUnitGroupSetId != null) {
            for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
                for (OrganisationUnitGroupSet orgunitGroupSet : organisationUnitGroup.getGroupSets()) {
                    if (orgunitGroupSet.getUid().compareTo(orgUnitGroupSetId) == 0) {
                        AttributeValue attributeValue = new AttributeValue();
                        // attributeValue.setAttribute( new Attribute( ORGUNIGROUP_SYMBOL, ORGUNIGROUP_SYMBOL ) );
                        attributeValue.setAttribute(new Attribute(ORGUNIGROUP_SYMBOL, ValueType.TEXT));
                        attributeValue.setValue(organisationUnitGroup.getSymbol());
                        attributeValues.add(attributeValue);
                    }
                }
            }
        }
        organisationUnit.setAttributeValues(attributeValues);
        // Clear out all data not needed for this task
        organisationUnit.removeAllDataSets();
        organisationUnit.removeAllUsers();
        organisationUnit.removeAllOrganisationUnitGroups();
    }
    renderService.toJson(response.getOutputStream(), entityList);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) ArrayList(java.util.ArrayList) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)7 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)6 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)6 ArrayList (java.util.ArrayList)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)4 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)4 PeriodType (org.hisp.dhis.period.PeriodType)4 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 Test (org.junit.Test)3 ValueType (org.hisp.dhis.common.ValueType)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1