use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DataSetController method getStructureDefinition.
// -------------------------------------------------------------------------
// Controller
// -------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@RequestMapping(produces = "application/dsd+xml")
public void getStructureDefinition(@RequestParam Map<String, String> parameters, HttpServletResponse response) throws IOException, TransformerException {
MetadataExportParams exportParams = filterMetadataOptions();
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadataMap = exportService.getMetadata(exportParams);
Metadata metadata = new Metadata();
metadata.setDataElements((List<DataElement>) metadataMap.get(DataElement.class));
metadata.setDataSets((List<DataSet>) metadataMap.get(DataSet.class));
metadata.setCategoryOptionCombos((List<DataElementCategoryOptionCombo>) metadataMap.get(DataElementCategoryOptionCombo.class));
InputStream input = new ByteArrayInputStream(DefaultRenderService.getXmlMapper().writeValueAsString(metadata).getBytes("UTF-8"));
TransformerFactory tf = TransformerFactory.newInstance();
tf.setURIResolver(new ClassPathUriResolver());
Transformer transformer = tf.newTransformer(new StreamSource(new ClassPathResource(DSD_TRANSFORM).getInputStream()));
transformer.transform(new StreamSource(input), new StreamResult(response.getOutputStream()));
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetDataElementOperandIdSchemeCodeMap.
@Test
public void testGetDataElementOperandIdSchemeCodeMap() {
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setUid("D123456789A");
deB.setUid("D123456789B");
deA.setCode("DCodeA");
deB.setCode("DCodeB");
DataElementCategoryOptionCombo ocA = new DataElementCategoryOptionCombo();
ocA.setUid("C123456789A");
ocA.setCode("CCodeA");
DataElementOperand opA = new DataElementOperand(deA, ocA);
DataElementOperand opB = new DataElementOperand(deB, ocA);
List<DataElementOperand> operands = Lists.newArrayList(opA, opB);
Map<String, String> map = DimensionalObjectUtils.getDataElementOperandIdSchemeMap(operands, IdScheme.CODE);
assertEquals(3, map.size());
assertEquals("DCodeA", map.get("D123456789A"));
assertEquals("DCodeB", map.get("D123456789B"));
assertEquals("CCodeA", map.get("C123456789A"));
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class AnalyticsUtils method getCocNameMap.
/**
* Returns a mapping between the category option combo identifiers and names
* for the given query.
*
* @param params the data query parameters.
* @returns a mapping between identifiers and names.
*/
public static Map<String, String> getCocNameMap(DataQueryParams params) {
Map<String, String> metaData = new HashMap<>();
List<DimensionalItemObject> des = params.getAllDataElements();
if (!des.isEmpty()) {
for (DimensionalItemObject de : des) {
DataElement dataElement = (DataElement) de;
for (DataElementCategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
metaData.put(coc.getUid(), coc.getName());
}
}
}
return metaData;
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetCocNameMap.
@Test
public void testGetCocNameMap() {
DataElementCategoryCombo ccA = createCategoryCombo('A', new DataElementCategory[0]);
DataElementCategoryCombo ccB = createCategoryCombo('B', new DataElementCategory[0]);
DataElementCategoryOptionCombo cocA = createCategoryOptionCombo('A');
DataElementCategoryOptionCombo cocB = createCategoryOptionCombo('B');
ccA.getOptionCombos().add(cocA);
ccB.getOptionCombos().add(cocB);
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
deA.setDataElementCategoryCombo(ccA);
deB.setDataElementCategoryCombo(ccB);
DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB));
DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
Map<String, String> map = AnalyticsUtils.getCocNameMap(params);
assertEquals(map.get(cocA.getUid()), cocA.getName());
assertEquals(map.get(cocB.getUid()), cocB.getName());
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testHandleGridForDataValueSet.
@Test
public void testHandleGridForDataValueSet() {
IndicatorType itA = new IndicatorType();
DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
ocA.setUid("ceabcdefghA");
DataElement dxA = createDataElement('A');
dxA.setUid("deabcdefghA");
dxA.setValueType(ValueType.INTEGER);
DataElement dxB = createDataElement('B');
dxB.setUid("deabcdefghB");
dxB.setValueType(ValueType.NUMBER);
Indicator dxC = createIndicator('C', itA);
dxC.setUid("deabcdefghC");
dxC.setDecimals(0);
dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
Indicator dxD = createIndicator('D', itA);
dxD.setUid("deabcdefghD");
dxD.setDecimals(2);
dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
DataElementOperand dxE = new DataElementOperand(dxA, ocA);
DataElementOperand dxF = new DataElementOperand(dxB, ocA);
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
assertEquals(4, grid.getWidth());
assertEquals(6, grid.getHeight());
AnalyticsUtils.handleGridForDataValueSet(params, grid);
assertEquals(6, grid.getWidth());
assertEquals(6, grid.getHeight());
assertEquals("deabcdefghA", grid.getRow(0).get(0));
assertNull(grid.getRow(0).get(3));
assertNull(grid.getRow(0).get(4));
assertEquals(1, grid.getRow(0).get(5));
assertEquals("deabcdefghB", grid.getRow(1).get(0));
assertNull(grid.getRow(1).get(3));
assertNull(grid.getRow(1).get(4));
assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
assertEquals("deabcdefghC", grid.getRow(2).get(0));
assertNull(grid.getRow(2).get(3));
assertEquals("ceabcdefghA", grid.getRow(2).get(4));
assertEquals(3, grid.getRow(2).get(5));
assertEquals("deabcdefghD", grid.getRow(3).get(0));
assertEquals("ceabcdefghB", grid.getRow(3).get(3));
assertNull(grid.getRow(3).get(4));
assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
assertEquals("deabcdefghA", grid.getRow(4).get(0));
assertEquals("ceabcdefghA", grid.getRow(4).get(3));
assertNull(grid.getRow(4).get(4));
assertEquals(5, grid.getRow(4).get(5));
assertEquals("deabcdefghB", grid.getRow(5).get(0));
assertEquals("ceabcdefghA", grid.getRow(5).get(3));
assertNull(grid.getRow(5).get(4));
assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
Aggregations