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;
}
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;
}
Aggregations