Search in sources :

Example 71 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class PredictionServiceTest method getDataValue.

private String getDataValue(DataElement dataElement, CategoryOptionCombo combo, CategoryOptionCombo attributeOptionCombo, OrganisationUnit source, Period period) {
    DataExportParams params = new DataExportParams().setDataElementOperands(Sets.newHashSet(new DataElementOperand(dataElement, combo))).setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo)).setOrganisationUnits(Sets.newHashSet(source)).setPeriods(Sets.newHashSet(periodService.reloadPeriod(period)));
    List<DeflatedDataValue> values = dataValueService.getDeflatedDataValues(params);
    if (values != null && values.size() > 0) {
        return values.get(0).getValue();
    }
    return null;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams)

Example 72 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataValidationTask method getDataValueMap.

/**
 * Gets data elements and data element operands from the datavalue table.
 */
private void getDataValueMap() {
    DataExportParams params = new DataExportParams();
    params.setDataElements(periodTypeX.getDataElements());
    params.setDataElementOperands(periodTypeX.getDataElementOperands());
    params.setIncludedDate(period.getStartDate());
    params.setOrganisationUnits(new HashSet<>(orgUnits));
    params.setPeriodTypes(periodTypeX.getAllowedPeriodTypes());
    params.setCoDimensionConstraints(context.getCoDimensionConstraints());
    params.setCogDimensionConstraints(context.getCogDimensionConstraints());
    if (context.getAttributeCombo() != null) {
        params.setAttributeOptionCombos(Sets.newHashSet(context.getAttributeCombo()));
    }
    List<DeflatedDataValue> dataValues = dataValueService.getDeflatedDataValues(params);
    dataMap = new MapMapMap<>();
    MapMapMap<Long, String, DimensionalItemObject, Long> duplicateCheck = new MapMapMap<>();
    for (DeflatedDataValue dv : dataValues) {
        DataElement dataElement = periodTypeX.getDataElementIdMap().get(dv.getDataElementId());
        String deoIdKey = periodTypeX.getDeoIds(dv.getDataElementId(), dv.getCategoryOptionComboId());
        DataElementOperand dataElementOperand = periodTypeX.getDataElementOperandIdMap().get(deoIdKey);
        Period p = getPeriod(dv.getPeriodId());
        long orgUnitId = dv.getSourceId();
        String attributeOptionComboUid = getAttributeOptionCombo(dv.getAttributeOptionComboId()).getUid();
        if (dataElement != null) {
            Object value = getObjectValue(dv.getValue(), dataElement.getValueType());
            addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElement, value, p, duplicateCheck);
        }
        if (dataElementOperand != null) {
            Object value = getObjectValue(dv.getValue(), dataElementOperand.getDataElement().getValueType());
            addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElementOperand, value, p, duplicateCheck);
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.dataelement.DataElement) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataExportParams(org.hisp.dhis.datavalue.DataExportParams)

Example 73 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataElementGroupController method getOperandsByQuery.

@GetMapping("/{uid}/operands/query/{q}")
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    WebOptions options = new WebOptions(parameters);
    setUserContext(translateParams);
    List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
    if (dataElementGroups.isEmpty()) {
        throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
    }
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands = Lists.newArrayList();
    for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
        if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
            dataElementOperands.add(dataElementOperand);
        }
    }
    metadata.setDataElementOperands(dataElementOperands);
    if (options.hasPaging()) {
        Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        metadata.setPager(pager);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    metadata.setDataElementOperands(dataElementOperands);
    linkService.generateLinks(metadata, false);
    model.addAttribute("model", metadata);
    model.addAttribute("viewClass", options.getViewClass("basic"));
    return StringUtils.uncapitalize(getEntitySimpleName());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 74 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataElementOperandControllerTest method verifyPaginationGetFirstPage.

@Test
void verifyPaginationGetFirstPage() throws Exception {
    int pageSize = 15;
    long totalSize = 150;
    // Given
    final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
    when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
    final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
    when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
    final List<DataElementOperand> first50elements = dataElementOperands.subList(0, pageSize);
    ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
    when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(first50elements));
    doReturn(totalSize).when(queryService).count(any(Query.class));
    // Then
    ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("1")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
    final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
    assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
    assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
    // Make sure that the first and last element in the page matches with
    // the
    // original list
    List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
    assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(0).getDimensionItem()));
    assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(pageSize - 1).getDimensionItem()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Query(org.hisp.dhis.query.Query) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ResultActions(org.springframework.test.web.servlet.ResultActions) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 75 with DataElementOperand

use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.

the class DataElementOperandControllerTest method verifyPaginationGetThirdPage.

@Test
void verifyPaginationGetThirdPage() throws Exception {
    int pageSize = 25;
    long totalSize = 100;
    // Given
    final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
    when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
    final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
    when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
    final List<DataElementOperand> thirdPageElements = dataElementOperands.subList(50, 50 + pageSize);
    ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
    when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(thirdPageElements));
    doReturn(totalSize).when(queryService).count(any(Query.class));
    // Then
    ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize)).param("page", Integer.toString(3))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("3")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
    final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
    assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
    assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
    // Make sure that the first and last element in the page matches with
    // the
    // original list
    List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
    assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(50).getDimensionItem()));
    assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(74).getDimensionItem()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Query(org.hisp.dhis.query.Query) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ResultActions(org.springframework.test.web.servlet.ResultActions) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)75 DataElement (org.hisp.dhis.dataelement.DataElement)36 Test (org.junit.jupiter.api.Test)30 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)25 Period (org.hisp.dhis.period.Period)24 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)23 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)17 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)14 PeriodType.getPeriodFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodFromIsoString)14 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 Indicator (org.hisp.dhis.indicator.Indicator)11 HashMap (java.util.HashMap)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 IndicatorType (org.hisp.dhis.indicator.IndicatorType)10 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)9 DataSet (org.hisp.dhis.dataset.DataSet)9 ArrayList (java.util.ArrayList)8 DataValue (org.hisp.dhis.datavalue.DataValue)8 List (java.util.List)7