Search in sources :

Example 1 with CompleteDataSetRegistrations

use of org.hisp.dhis.dataset.CompleteDataSetRegistrations in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrationsJson.

// Legacy (>= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getCompleteDataSetRegistrationsJson(@RequestParam Set<String> dataSet, @RequestParam(required = false) String period, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> orgUnit, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException {
    List<String> fields = Lists.newArrayList(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],attributeOptionCombo[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    response.setContentType(CONTENT_TYPE_JSON);
    CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations(dataSet, period, startDate, endDate, orgUnit, children);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(CompleteDataSetRegistration.class, completeDataSetRegistrations.getCompleteDataSetRegistrations(), fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CompleteDataSetRegistrations

use of org.hisp.dhis.dataset.CompleteDataSetRegistrations in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrations.

private CompleteDataSetRegistrations getCompleteDataSetRegistrations(Set<String> dataSet, String period, Date startDate, Date endDate, Set<String> orgUnit, boolean children) {
    Set<Period> periods = new HashSet<>();
    Set<DataSet> dataSets = new HashSet<>();
    Set<OrganisationUnit> organisationUnits = new HashSet<>();
    PeriodType periodType = periodService.getPeriodTypeByName(period);
    if (periodType != null) {
        periods.addAll(periodService.getPeriodsBetweenDates(periodType, startDate, endDate));
    } else {
        periods.addAll(periodService.getPeriodsBetweenDates(startDate, endDate));
    }
    if (periods.isEmpty()) {
        return new CompleteDataSetRegistrations();
    }
    if (children) {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(orgUnit));
    } else {
        organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(orgUnit));
    }
    dataSets.addAll(manager.getByUid(DataSet.class, dataSet));
    CompleteDataSetRegistrations completeDataSetRegistrations = new CompleteDataSetRegistrations();
    completeDataSetRegistrations.setCompleteDataSetRegistrations(new ArrayList<>(registrationService.getCompleteDataSetRegistrations(dataSets, organisationUnits, periods)));
    return completeDataSetRegistrations;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) HashSet(java.util.HashSet)

Aggregations

CompleteDataSetRegistrations (org.hisp.dhis.dataset.CompleteDataSetRegistrations)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 DataSet (org.hisp.dhis.dataset.DataSet)1 RootNode (org.hisp.dhis.node.types.RootNode)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 PeriodType (org.hisp.dhis.period.PeriodType)1 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1