use of org.hisp.dhis.common.OrganisationUnitSelectionMode in project dhis2-core by dhis2.
the class AbstractEventService method getOrganisationUnits.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private List<OrganisationUnit> getOrganisationUnits(EventSearchParams params) {
List<OrganisationUnit> organisationUnits = new ArrayList<>();
OrganisationUnit orgUnit = params.getOrgUnit();
OrganisationUnitSelectionMode orgUnitSelectionMode = params.getOrgUnitSelectionMode();
if (params.getOrgUnit() != null) {
if (OrganisationUnitSelectionMode.DESCENDANTS.equals(orgUnitSelectionMode)) {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitWithChildren(orgUnit.getUid()));
} else if (OrganisationUnitSelectionMode.CHILDREN.equals(orgUnitSelectionMode)) {
organisationUnits.add(orgUnit);
organisationUnits.addAll(orgUnit.getChildren());
} else // SELECTED
{
organisationUnits.add(orgUnit);
}
}
return organisationUnits;
}
use of org.hisp.dhis.common.OrganisationUnitSelectionMode in project dhis2-core by dhis2.
the class AbstractEventService method getOrganisationUnits.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private List<OrganisationUnit> getOrganisationUnits(EventSearchParams params, User user) {
OrganisationUnitSelectionMode orgUnitSelectionMode = params.getOrgUnitSelectionMode();
if (orgUnitSelectionMode == null) {
if (params.getOrgUnit() != null) {
return Collections.emptyList();
}
return getAccessibleOrgUnits(params, user);
}
List<OrganisationUnit> organisationUnits;
switch(orgUnitSelectionMode) {
case ALL:
organisationUnits = getAllOrgUnits(params, user);
break;
case CHILDREN:
organisationUnits = getChildrenOrgUnits(params);
break;
case DESCENDANTS:
organisationUnits = getDescendantOrgUnits(params);
break;
case CAPTURE:
organisationUnits = getCaptureOrgUnits(params, user);
break;
case SELECTED:
organisationUnits = getSelectedOrgUnits(params);
break;
default:
organisationUnits = getAccessibleOrgUnits(params, user);
break;
}
return organisationUnits;
}
use of org.hisp.dhis.common.OrganisationUnitSelectionMode in project dhis2-core by dhis2.
the class EnrollmentController method getEnrollments.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT') or hasRole('F_PROGRAM_UNENROLLMENT') or hasRole('F_PROGRAM_ENROLLMENT_READ')")
@ResponseBody
public RootNode getEnrollments(@RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String enrollment, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("enrollment,created,lastUpdated,trackedEntity,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
}
Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
List<Enrollment> enrollments;
if (enrollment == null) {
ProgramInstanceQueryParams params = programInstanceService.getFromUrl(orgUnits, ouMode, lastUpdated, program, programStatus, programStartDate, programEndDate, trackedEntity, trackedEntityInstance, followUp, page, pageSize, totalPages, skipPaging);
enrollments = new ArrayList<>(enrollmentService.getEnrollments(programInstanceService.getProgramInstances(params)));
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(enrollment, TextUtils.SEMICOLON);
enrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
}
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.filter(Enrollment.class, enrollments, fields));
return rootNode;
}
use of org.hisp.dhis.common.OrganisationUnitSelectionMode in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method getTrackedEntityInstances.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityInstances(@RequestParam(required = false) String query, @RequestParam(required = false) Set<String> attribute, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) String ou, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) String program, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) Date programStartDate, @RequestParam(required = false) Date programEnrollmentStartDate, @RequestParam(required = false) Date programEndDate, @RequestParam(required = false) Date programEnrollmentEndDate, @RequestParam(required = false) Date programIncidentStartDate, @RequestParam(required = false) Date programIncidentEndDate, @RequestParam(required = false) String trackedEntity, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date eventStartDate, @RequestParam(required = false) Date eventEndDate, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) boolean includeDeleted, @RequestParam(required = false) String order) throws Exception {
programEnrollmentStartDate = ObjectUtils.firstNonNull(programEnrollmentStartDate, programStartDate);
programEnrollmentEndDate = ObjectUtils.firstNonNull(programEnrollmentEndDate, programEndDate);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
Set<String> orgUnits = TextUtils.splitToArray(ou, TextUtils.SEMICOLON);
RootNode rootNode = NodeUtils.createMetadata();
List<TrackedEntityInstance> trackedEntityInstances;
TrackedEntityInstanceQueryParams queryParams = instanceService.getFromUrl(query, attribute, filter, orgUnits, ouMode, program, programStatus, followUp, lastUpdatedStartDate, lastUpdatedEndDate, programEnrollmentStartDate, programEnrollmentEndDate, programIncidentStartDate, programIncidentEndDate, trackedEntity, eventStatus, eventStartDate, eventEndDate, skipMeta, page, pageSize, totalPages, skipPaging, includeDeleted, getOrderParams(order));
if (trackedEntityInstance == null) {
trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, getTrackedEntityInstanceParams(fields));
} else {
Set<String> trackedEntityInstanceIds = TextUtils.splitToArray(trackedEntityInstance, TextUtils.SEMICOLON);
trackedEntityInstances = trackedEntityInstanceIds != null ? trackedEntityInstanceIds.stream().map(id -> trackedEntityInstanceService.getTrackedEntityInstance(id, getTrackedEntityInstanceParams(fields))).collect(Collectors.toList()) : null;
}
if (queryParams.isPaging() && queryParams.isTotalPages()) {
int count = trackedEntityInstanceService.getTrackedEntityInstanceCount(queryParams);
Pager pager = new Pager(queryParams.getPageWithDefault(), count, queryParams.getPageSizeWithDefault());
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(TrackedEntityInstance.class, trackedEntityInstances, fields));
return rootNode;
}
use of org.hisp.dhis.common.OrganisationUnitSelectionMode in project dhis2-core by dhis2.
the class AbstractEventService method getOuModeViolation.
private String getOuModeViolation(EventSearchParams params, User user) {
OrganisationUnitSelectionMode selectedOuMode = params.getOrgUnitSelectionMode();
String violation = null;
switch(selectedOuMode) {
case ALL:
violation = userCanSearchOuModeALL(user) ? null : "Current user is not authorized to query across all organisation units";
break;
case ACCESSIBLE:
case CAPTURE:
violation = user == null ? "User is required for ouMode: " + params.getOrgUnitSelectionMode() : null;
break;
case CHILDREN:
case SELECTED:
case DESCENDANTS:
violation = params.getOrgUnit() == null ? "Organisation unit is required for ouMode: " + params.getOrgUnitSelectionMode() : null;
break;
default:
violation = "Invalid ouMode: " + params.getOrgUnitSelectionMode();
break;
}
return violation;
}
Aggregations