Search in sources :

Example 11 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportAttributeOptionCombo.

@Test
public void testExportAttributeOptionCombo() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouB)).setPeriods(Sets.newHashSet(peA)).setAttributeOptionCombos(Sets.newHashSet(cocA));
    dataValueSetService.writeDataValueSetJson(params, out);
    DataValueSet dvs = JacksonUtils.fromJson(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(ouB.getUid(), dv.getOrgUnit());
        assertEquals(peA.getUid(), dv.getPeriod());
    }
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportOrgUnitChildren.

@Test
public void testExportOrgUnitChildren() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsA)).setOrganisationUnits(Sets.newHashSet(ouA)).setIncludeChildren(true).setPeriods(Sets.newHashSet(peA));
    dataValueSetService.writeDataValueSetJson(params, out);
    DataValueSet dvs = JacksonUtils.fromJson(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(dsA.getUid(), dvs.getDataSet());
    assertEquals(8, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(peA.getUid(), dv.getPeriod());
    }
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetServiceExportTest method testExportOutputIdSchemeAttribute.

@Test
public void testExportOutputIdSchemeAttribute() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String attributeIdScheme = IdScheme.ATTR_ID_SCHEME_PREFIX + atA.getUid();
    IdSchemes idSchemes = new IdSchemes().setDataElementIdScheme(attributeIdScheme).setOrgUnitIdScheme(attributeIdScheme).setCategoryOptionComboIdScheme(attributeIdScheme);
    DataExportParams params = new DataExportParams().setDataSets(Sets.newHashSet(dsB)).setOrganisationUnits(Sets.newHashSet(ouA)).setPeriods(Sets.newHashSet(peB)).setOutputIdSchemes(idSchemes);
    dataValueSetService.writeDataValueSetJson(params, out);
    DataValueSet dvs = JacksonUtils.fromJson(out.toByteArray(), DataValueSet.class);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataSet());
    assertEquals(dsB.getUid(), dvs.getDataSet());
    assertEquals(2, dvs.getDataValues().size());
    for (org.hisp.dhis.dxf2.datavalue.DataValue dv : dvs.getDataValues()) {
        assertNotNull(dv);
        assertEquals(avA.getValue(), dv.getDataElement());
        assertEquals(avB.getValue(), dv.getOrgUnit());
    }
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataSetController method getForm.

private Form getForm(List<DataSet> dataSets, OrganisationUnit ou, Period pe, String categoryOptions, boolean metaData) throws IOException {
    DataSet dataSet = dataSets.get(0);
    Form form = FormUtils.fromDataSet(dataSets.get(0), metaData, null);
    Set<String> options = null;
    if (StringUtils.isNotEmpty(categoryOptions) && categoryOptions.startsWith("[") && categoryOptions.endsWith("]")) {
        String[] split = categoryOptions.substring(1, categoryOptions.length() - 1).split(",");
        options = new HashSet<>(Lists.newArrayList(split));
    }
    if (ou != null && pe != null) {
        List<DataValue> dataValues;
        if (options != null && !options.isEmpty()) {
            DataElementCategoryOptionCombo attrOptionCombo = inputUtils.getAttributeOptionCombo(dataSet.getCategoryCombo(), options, IdScheme.UID);
            dataValues = dataValueService.getDataValues(ou, pe, dataSets.get(0).getDataElements(), attrOptionCombo);
        } else {
            dataValues = dataValueService.getDataValues(new DataExportParams().setDataElements(dataSets.get(0).getDataElements()).setPeriods(Sets.newHashSet(pe)).setOrganisationUnits(Sets.newHashSet(ou)));
        }
        FormUtils.fillWithDataValues(form, dataValues);
    }
    return form;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) Form(org.hisp.dhis.webapi.webdomain.form.Form) DataValue(org.hisp.dhis.datavalue.DataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 15 with DataExportParams

use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.

the class DataValueSetController method getDataValueSetJson.

@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_JSON)
public void getDataValueSetJson(@RequestParam(required = false) Set<String> dataSet, @RequestParam(required = false) Set<String> dataElementGroup, @RequestParam(required = false) Set<String> period, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Set<String> orgUnit, @RequestParam(required = false) boolean children, @RequestParam(required = false) Set<String> orgUnitGroup, @RequestParam(required = false) Set<String> attributeOptionCombo, @RequestParam(required = false) boolean includeDeleted, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) String lastUpdatedDuration, @RequestParam(required = false) Integer limit, IdSchemes idSchemes, HttpServletResponse response) throws IOException {
    response.setContentType(CONTENT_TYPE_JSON);
    DataExportParams params = dataValueSetService.getFromUrl(dataSet, dataElementGroup, period, startDate, endDate, orgUnit, children, orgUnitGroup, attributeOptionCombo, includeDeleted, lastUpdated, lastUpdatedDuration, limit, idSchemes);
    dataValueSetService.writeDataValueSetJson(params, response.getOutputStream());
}
Also used : DataExportParams(org.hisp.dhis.datavalue.DataExportParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataExportParams (org.hisp.dhis.datavalue.DataExportParams)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Test (org.junit.Test)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 IdSchemes (org.hisp.dhis.common.IdSchemes)3 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)3 DataValue (org.hisp.dhis.datavalue.DataValue)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Period (org.hisp.dhis.period.Period)2 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1