Search in sources :

Example 6 with OrganisationUnitGroup

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

the class AbstractDataSetCompletenessService method getDataSetCompleteness.

@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, Collection<Integer> organisationUnitIds, int dataSetId, Set<Integer> groupIds) {
    final DataSet dataSet = dataSetService.getDataSet(dataSetId);
    final Period period = periodService.getPeriod(periodId);
    final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
    final Map<Integer, OrganisationUnit> orgUnits = Maps.uniqueIndex(organisationUnitService.getOrganisationUnits(organisationUnitIds), OrganisationUnit::getId);
    final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
    final List<DataSetCompletenessResult> results = new ArrayList<>();
    for (final Integer unitId : organisationUnitIds) {
        final OrganisationUnit unit = orgUnits.get(unitId);
        final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(unit.getId());
        final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
        final DataSetCompletenessResult result = getDataSetCompleteness(period, periodsBetweenDates, unit, relevantSources, dataSet);
        if (result.getSources() > 0) {
            results.add(result);
        }
    }
    return results;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with OrganisationUnitGroup

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

the class DefaultCsvImportService method organisationUnitGroupsFromCsv.

private List<OrganisationUnitGroup> organisationUnitGroupsFromCsv(CsvReader reader) throws IOException {
    List<OrganisationUnitGroup> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            OrganisationUnitGroup object = new OrganisationUnitGroup();
            setIdentifiableObject(object, values);
            object.setAutoFields();
            object.setShortName(getSafe(values, 3, object.getName(), 50));
            list.add(object);
        }
    }
    return list;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ArrayList(java.util.ArrayList)

Example 8 with OrganisationUnitGroup

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

the class DefaultOrgUnitDistributionService method getOrganisationUnitDistribution.

@Override
@Transactional
public Grid getOrganisationUnitDistribution(OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit, boolean organisationUnitOnly) {
    Grid grid = new ListGrid();
    grid.setTitle(groupSet.getName() + TITLE_SEP + organisationUnit.getName());
    List<OrganisationUnit> units = organisationUnitOnly ? Arrays.asList(organisationUnit) : new ArrayList<>(organisationUnit.getChildren());
    List<OrganisationUnitGroup> groups = new ArrayList<>(groupSet.getOrganisationUnitGroups());
    Collections.sort(units);
    Collections.sort(groups);
    if (!organisationUnitOnly) {
        // Add parent itself to the end to get the total
        units.add(organisationUnit);
    }
    grid.addHeader(new GridHeader(FIRST_COLUMN_TEXT, FIRST_COLUMN_TEXT, ValueType.TEXT, String.class.getName(), false, true));
    for (OrganisationUnitGroup group : groups) {
        grid.addHeader(new GridHeader(group.getName(), false, false));
    }
    grid.addHeader(new GridHeader(HEADER_TOTAL, false, false));
    for (OrganisationUnit unit : units) {
        grid.addRow();
        grid.addValue(unit.getName());
        int totalGroup = 0;
        Set<OrganisationUnit> subTree = new HashSet<>(organisationUnitService.getOrganisationUnitWithChildren(unit.getId()));
        for (OrganisationUnitGroup group : groups) {
            Set<OrganisationUnit> result = Sets.intersection(subTree, group.getMembers());
            int count = result != null ? result.size() : 0;
            grid.addValue(count);
            totalGroup += count;
        }
        grid.addValue(totalGroup);
    }
    return grid;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with OrganisationUnitGroup

use of org.hisp.dhis.organisationunit.OrganisationUnitGroup 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)

Example 10 with OrganisationUnitGroup

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

the class CsdController method createCsd.

private Csd createCsd(Iterable<OrganisationUnit> organisationUnits) {
    Csd csd = new Csd();
    csd.getFacilityDirectory().setFacilities(new ArrayList<>());
    for (OrganisationUnit organisationUnit : organisationUnits) {
        boolean isFacility = false;
        for (OrganisationUnitGroup group : organisationUnit.getGroups()) {
            if (group.getName().equals(FACILITY_DISCRIMINATOR_GROUP)) {
                isFacility = true;
                break;
            }
        }
        // skip if orgunit is not a health facility
        if (!isFacility) {
            continue;
        }
        Facility facility = new Facility();
        facility.setOid("urn:x-dhis:facility." + organisationUnit.getUid());
        facility.getOtherID().add(new OtherID(organisationUnit.getUid(), "dhis2-uid"));
        if (organisationUnit.getCode() != null) {
            facility.getOtherID().add(new OtherID(organisationUnit.getCode(), "dhis2-code"));
        }
        facility.setPrimaryName(organisationUnit.getDisplayName());
        if (organisationUnit.getContactPerson() != null) {
            Contact contact = new Contact();
            Person person = new Person();
            Name name = new Name();
            contact.setPerson(person);
            person.setName(name);
            name.getCommonNames().add(new CommonName(organisationUnit.getContactPerson()));
            facility.getContacts().add(contact);
        }
        String facilityStatus = "Open";
        for (OrganisationUnitGroup organisationUnitGroup : organisationUnit.getGroups()) {
            if (organisationUnitGroup == null) {
                continue;
            }
            Set<String> groupSetNames = organisationUnitGroup.getGroupSets().stream().map(OrganisationUnitGroupSet::getName).collect(Collectors.toSet());
            if (groupSetNames.contains(FACILITY_STATUS_GROUPSET)) {
                facilityStatus = organisationUnitGroup.getCode();
                continue;
            }
            if (groupSetNames.contains(FACILITY_TYPE_GROUPSET)) {
                if (organisationUnitGroup.getCode() == null) {
                    continue;
                }
                CodedType codedType = new CodedType();
                codedType.setCode(organisationUnitGroup.getCode());
                codedType.setCodingSchema("Unknown");
                for (AttributeValue attributeValue : organisationUnitGroup.getAttributeValues()) {
                    if (attributeValue.getAttribute().getName().equals("code_system")) {
                        codedType.setCodingSchema(attributeValue.getValue());
                        break;
                    }
                }
                codedType.setValue(organisationUnitGroup.getDisplayName());
                facility.getCodedTypes().add(codedType);
            }
            if (groupSetNames.contains(FACILITY_OWNERSHIP_GROUPSET)) {
                Organization organization = new Organization("urn:x-dhis:ownership." + organisationUnitGroup.getUid());
                facility.getOrganizations().add(organization);
                for (DataSet dataSet : organisationUnit.getDataSets()) {
                    for (AttributeValue attributeValue : dataSet.getAttributeValues()) {
                        if (attributeValue.getAttribute().getName().equals(DATASET_SERVICE_ATTRIBUTE)) {
                            Service service = new Service();
                            service.setOid("urn:x-dhis:dataSet." + dataSet.getUid());
                            service.getNames().add(new Name(new CommonName(attributeValue.getValue())));
                            organization.getServices().add(service);
                            break;
                        }
                    }
                }
            }
        }
        if (organisationUnit.getFeatureType() == FeatureType.POINT) {
            Geocode geocode = new Geocode();
            try {
                GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates(organisationUnit.getCoordinates());
                geocode.setLongitude(coordinates.lng);
                geocode.setLatitude(coordinates.lat);
                facility.setGeocode(geocode);
            } catch (NumberFormatException ignored) {
            }
        }
        Record record = new Record();
        record.setCreated(organisationUnit.getCreated());
        record.setUpdated(organisationUnit.getLastUpdated());
        record.setStatus(facilityStatus);
        facility.setRecord(record);
        Map<String, List<AddressLine>> addressLines = Maps.newHashMap();
        List<AttributeValue> attributeValues = new ArrayList<>(organisationUnit.getAttributeValues());
        Collections.sort(attributeValues, AttributeValueSortOrderComparator.INSTANCE);
        for (AttributeValue attributeValue : attributeValues) {
            if (attributeValue.getAttribute().getName().startsWith("Address_")) {
                String[] attributeSplit = attributeValue.getAttribute().getName().split("_");
                if (attributeSplit.length > 3) {
                    continue;
                }
                if (addressLines.get(attributeSplit[1]) == null) {
                    addressLines.put(attributeSplit[1], Lists.<AddressLine>newArrayList());
                }
                AddressLine addressLine = new AddressLine();
                addressLine.setComponent(attributeSplit[2]);
                addressLine.setValue(attributeValue.getValue());
                addressLines.get(attributeSplit[1]).add(addressLine);
            }
        }
        for (String key : addressLines.keySet()) {
            Address address = new Address(key);
            address.setAddressLines(addressLines.get(key));
            facility.getAddresses().add(address);
        }
        csd.getFacilityDirectory().getFacilities().add(facility);
    }
    return csd;
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Organization(org.hisp.dhis.web.ohie.csd.domain.Organization) Address(org.hisp.dhis.web.ohie.csd.domain.Address) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) CommonName(org.hisp.dhis.web.ohie.csd.domain.CommonName) Name(org.hisp.dhis.web.ohie.csd.domain.Name) Csd(org.hisp.dhis.web.ohie.csd.domain.Csd) GeoUtils(org.hisp.dhis.web.ohie.utils.GeoUtils) Record(org.hisp.dhis.web.ohie.csd.domain.Record) List(java.util.List) ArrayList(java.util.ArrayList) CommonName(org.hisp.dhis.web.ohie.csd.domain.CommonName) Geocode(org.hisp.dhis.web.ohie.csd.domain.Geocode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AddressLine(org.hisp.dhis.web.ohie.csd.domain.AddressLine) Service(org.hisp.dhis.web.ohie.csd.domain.Service) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) OtherID(org.hisp.dhis.web.ohie.csd.domain.OtherID) CodedType(org.hisp.dhis.web.ohie.csd.domain.CodedType) Contact(org.hisp.dhis.web.ohie.csd.domain.Contact) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Facility(org.hisp.dhis.web.ohie.csd.domain.Facility) Person(org.hisp.dhis.web.ohie.csd.domain.Person)

Aggregations

OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ArrayList (java.util.ArrayList)10 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Transactional (org.springframework.transaction.annotation.Transactional)5 HashSet (java.util.HashSet)4 Period (org.hisp.dhis.period.Period)4 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 Constant (org.hisp.dhis.constant.Constant)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Matcher (java.util.regex.Matcher)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 AttributeValue (org.hisp.dhis.attribute.AttributeValue)2 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 Grid (org.hisp.dhis.common.Grid)2 DataSetCompletenessResult (org.hisp.dhis.completeness.DataSetCompletenessResult)2 Indicator (org.hisp.dhis.indicator.Indicator)2