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());
}
}
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());
}
}
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());
}
}
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;
}
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());
}
Aggregations