Search in sources :

Example 91 with DataElementCategoryOptionCombo

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()));
}
Also used : ClassPathUriResolver(org.hisp.dhis.webapi.view.ClassPathUriResolver) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) DataSet(org.hisp.dhis.dataset.DataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 92 with DataElementCategoryOptionCombo

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"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Test(org.junit.Test)

Example 93 with DataElementCategoryOptionCombo

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;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 94 with DataElementCategoryOptionCombo

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 95 with DataElementCategoryOptionCombo

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4