Search in sources :

Example 16 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class AuditController method getAggregateDataValueAudit.

@GetMapping("dataValue")
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = new ArrayList<>();
    dataElements.addAll(getDataElements(de));
    dataElements.addAll(getDataElementsByDataSet(ds));
    List<Period> periods = getPeriods(pe);
    List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
    CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
    CategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
    List<DataValueAudit> dataValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
    } else {
        int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(DataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class AuditController method getTrackedEntityAttributeValueAudit.

@GetMapping("trackedEntityAttributeValue")
@ResponseBody
public RootNode getTrackedEntityAttributeValueAudit(@RequestParam(required = false, defaultValue = "") List<String> tea, @RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
    List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
    List<TrackedEntityAttributeValueAudit> attributeValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
    } else {
        int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
        pager = new Pager(page, total, pageSize);
        attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityAttributeValueAudit.class, new FieldFilterParams(attributeValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class AuditController method getTrackedEntityDataValueAudit.

@GetMapping("trackedEntityDataValue")
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = getDataElements(de);
    List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
    List<TrackedEntityDataValueAudit> dataValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
    } else {
        int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityDataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class DataApprovalController method getApproval.

@GetMapping(value = STATUS_PATH, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws WebMessageException, BadRequestException {
    List<String> fields = new ArrayList<>(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
        List<String> defaults = new ArrayList<>();
        defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
    Set<Period> periods = parsePeriods(pe, startDate, endDate);
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
    }
    List<DataApprovalStateResponse> responses = new ArrayList<>();
    for (DataSet dataSet : dataSets) {
        for (OrganisationUnit organisationUnit : organisationUnits) {
            for (Period period : periods) {
                responses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
            }
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(DataApprovalStateResponse.class, new FieldFilterParams(responses, fields)));
    return rootNode;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalStateResponse(org.hisp.dhis.dataapproval.DataApprovalStateResponse) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with FieldFilterParams

use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.

the class DataSetController method getCategoryCombinations.

@GetMapping("/{uid}/categoryCombos")
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
    setUserContext(translateParams);
    DataSet dataSet = manager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(conflict("Data set does not exist: " + uid));
    }
    List<CategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
    Collections.sort(categoryCombos);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CategoryCombo(org.hisp.dhis.category.CategoryCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataSetElement(org.hisp.dhis.dataset.DataSetElement) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)32 RootNode (org.hisp.dhis.node.types.RootNode)28 GetMapping (org.springframework.web.bind.annotation.GetMapping)25 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)23 Pager (org.hisp.dhis.common.Pager)10 CollectionNode (org.hisp.dhis.node.types.CollectionNode)10 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)8 ArrayList (java.util.ArrayList)7 Query (org.hisp.dhis.query.Query)6 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)5 DataElement (org.hisp.dhis.dataelement.DataElement)4 DataSet (org.hisp.dhis.dataset.DataSet)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 Test (org.junit.jupiter.api.Test)4 List (java.util.List)3 Map (java.util.Map)3 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3 Order (org.hisp.dhis.query.Order)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2