Search in sources :

Example 16 with DataSet

use of org.hisp.dhis.dataset.DataSet 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)

Example 17 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class GetDataCompletenessAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Grid _grid = (Grid) SessionUtils.getSessionVar(KEY_DATA_COMPLETENESS);
    if (_grid != null && type != null && !type.equals(DEFAULT_TYPE)) {
        grid = _grid;
        return type;
    } else {
        OrganisationUnit selectedUnit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
        if (periodId == null || selectedUnit == null || criteria == null) {
            return INPUT;
        } else {
            Period period = periodService.reloadPeriod(PeriodType.getPeriodFromIsoString(periodId));
            Integer _periodId = period.getId();
            DataSet dataSet = null;
            List<DataSetCompletenessResult> mainResults = new ArrayList<>();
            List<DataSetCompletenessResult> footerResults = new ArrayList<>();
            DataSetCompletenessService completenessService = serviceProvider.provide(criteria);
            if (// One ds for one ou
            dataSetId != null && dataSetId != 0) {
                mainResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, getIdentifiers(selectedUnit.getChildren()), dataSetId, groupId));
                footerResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, Arrays.asList(selectedUnit.getId()), dataSetId, groupId));
                dataSet = dataSetService.getDataSet(dataSetId);
            } else // All ds for children of one ou               
            {
                mainResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, selectedUnit.getId(), groupId));
            }
            grid = getGrid(mainResults, footerResults, selectedUnit, dataSet, period);
            SessionUtils.setSessionVar(KEY_DATA_COMPLETENESS, grid);
        }
        return type != null ? type : DEFAULT_TYPE;
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataSetCompletenessService(org.hisp.dhis.completeness.DataSetCompletenessService)

Example 18 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class AnalyticsServiceTest method parseDataSetRegistrations.

/**
     * Adds data set registrations based on input from vales
     *
     * @param lines the arraylist of arrays of property values.
     */
private void parseDataSetRegistrations(ArrayList<String[]> lines) {
    String storedBy = "johndoe";
    Date now = new Date();
    for (String[] line : lines) {
        DataSet dataSet = dataSetService.getDataSet(line[0]);
        Period period = periodService.getPeriod(line[1]);
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(line[2]);
        CompleteDataSetRegistration completeDataSetRegistration = new CompleteDataSetRegistration(dataSet, period, organisationUnit, ocDef, now, storedBy);
        completeDataSetRegistrationService.saveCompleteDataSetRegistration(completeDataSetRegistration);
    }
    assertEquals("Import of data set registrations failed, number of imports are wrong", completeDataSetRegistrationService.getAllCompleteDataSetRegistrations().size(), 15);
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration)

Example 19 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDimensionalItemObjectMap.

@Test
public void testGetDimensionalItemObjectMap() {
    DataElement deA = createDataElement('A');
    Indicator inA = createIndicator('A', null);
    DataSet dsA = createDataSet('A');
    DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, DimensionalObjectUtils.getList(deA, inA, dsA));
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, DimensionalItemObject> map = AnalyticsUtils.getDimensionalItemObjectMap(params);
    assertEquals(map.get(deA.getDimensionItem()), deA);
    assertEquals(map.get(inA.getDimensionItem()), inA);
    assertEquals(map.get(dsA.getDimensionItem()), dsA);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 20 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDimensionItemNameMap.

@Test
public void testGetDimensionItemNameMap() {
    DataElement deA = createDataElement('A');
    Indicator inA = createIndicator('A', null);
    DataSet dsA = createDataSet('A');
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, DimensionalObjectUtils.getList(deA, inA, dsA));
    DimensionalObject ou = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB));
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).addDimension(ou).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, String> map = AnalyticsUtils.getDimensionItemNameMap(params);
    assertEquals(map.get(deA.getDimensionItem()), deA.getDisplayName());
    assertEquals(map.get(inA.getDimensionItem()), inA.getDisplayName());
    assertEquals(map.get(dsA.getDimensionItem()), dsA.getDisplayName());
    assertEquals(map.get(ouA.getDimensionItem()), ouA.getDisplayName());
    assertEquals(map.get(ouB.getDimensionItem()), ouB.getDisplayName());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)199 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)82 Test (org.junit.jupiter.api.Test)69 DataElement (org.hisp.dhis.dataelement.DataElement)58 Period (org.hisp.dhis.period.Period)56 ArrayList (java.util.ArrayList)41 List (java.util.List)40 User (org.hisp.dhis.user.User)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)32 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)28 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)22 HashSet (java.util.HashSet)20 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)20 CategoryCombo (org.hisp.dhis.category.CategoryCombo)19 HashMap (java.util.HashMap)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)17 ReportingRate (org.hisp.dhis.common.ReportingRate)16 Section (org.hisp.dhis.dataset.Section)16