use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EnrollmentController method getEnrollments.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEnrollments(EnrollmentCriteria enrollmentCriteria) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("enrollment,created,lastUpdated,trackedEntityType,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
}
RootNode rootNode = NodeUtils.createMetadata();
List<Enrollment> listEnrollments;
if (enrollmentCriteria.getEnrollment() == null) {
ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(TextUtils.splitToArray(enrollmentCriteria.getOu(), TextUtils.SEMICOLON), enrollmentCriteria.getOuMode(), enrollmentCriteria.getLastUpdated(), enrollmentCriteria.getLastUpdatedDuration(), enrollmentCriteria.getProgram(), enrollmentCriteria.getProgramStatus(), enrollmentCriteria.getProgramStartDate(), enrollmentCriteria.getProgramEndDate(), enrollmentCriteria.getTrackedEntityType(), enrollmentCriteria.getTrackedEntityInstance(), enrollmentCriteria.getFollowUp(), enrollmentCriteria.getPage(), enrollmentCriteria.getPageSize(), enrollmentCriteria.isTotalPages(), PagerUtils.isSkipPaging(enrollmentCriteria.getSkipPaging(), enrollmentCriteria.getPaging()), enrollmentCriteria.isIncludeDeleted(), enrollmentCriteria.getOrder());
Enrollments enrollments = enrollmentService.getEnrollments(params);
if (enrollments.getPager() != null) {
if (params.isTotalPages()) {
rootNode.addChild(NodeUtils.createPager(enrollments.getPager()));
} else {
rootNode.addChild(NodeUtils.createSlimPager((SlimPager) enrollments.getPager()));
}
}
listEnrollments = enrollments.getEnrollments();
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(enrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
listEnrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
}
rootNode.addChild(fieldFilterService.toCollectionNode(Enrollment.class, new FieldFilterParams(listEnrollments, fields)));
return rootNode;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class DataValueController method getDataValueFile.
// ---------------------------------------------------------------------
// GET file
// ---------------------------------------------------------------------
@GetMapping("/files")
public void getDataValueFile(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(defaultValue = "original") String dimension, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
// ---------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------
DataElement dataElement = dataValueValidation.getAndValidateDataElement(de);
if (!dataElement.isFileType()) {
throw new WebMessageException(conflict("DataElement must be of type file"));
}
CategoryOptionCombo categoryOptionCombo = dataValueValidation.getAndValidateCategoryOptionCombo(co, false);
CategoryOptionCombo attributeOptionCombo = dataValueValidation.getAndValidateAttributeOptionCombo(cc, cp);
Period period = dataValueValidation.getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = dataValueValidation.getAndValidateOrganisationUnit(ou);
dataValueValidation.validateOrganisationUnitPeriod(organisationUnit, period);
// ---------------------------------------------------------------------
// Get data value
// ---------------------------------------------------------------------
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new WebMessageException(conflict("Data value does not exist"));
}
// ---------------------------------------------------------------------
// Get file resource
// ---------------------------------------------------------------------
String uid = dataValue.getValue();
FileResource fileResource = fileResourceService.getFileResource(uid);
if (fileResource == null || fileResource.getDomain() != FileResourceDomain.DATA_VALUE) {
throw new WebMessageException(notFound("A data value file resource with id " + uid + " does not exist."));
}
FileResourceStorageStatus storageStatus = fileResource.getStorageStatus();
if (storageStatus != FileResourceStorageStatus.STORED) {
// HTTP 409, for lack of a more suitable status code
throw new WebMessageException(conflict("The content is being processed and is not available yet. Try again later.", "The content requested is in transit to the file store and will be available at a later time.").setResponse(new FileResourceWebMessageResponse(fileResource)));
}
response.setContentType(fileResource.getContentType());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileResource.getName());
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(fileResourceService.getFileResourceContentLength(fileResource)));
setNoStore(response);
try {
fileResourceService.copyFileResourceContent(fileResource, response.getOutputStream());
} catch (IOException e) {
throw new WebMessageException(error("Failed fetching the file from storage", "There was an exception when trying to fetch the file from the storage backend, could be network or filesystem related"));
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EventController method queryEventsCsv.
@GetMapping(value = "/query", produces = ContextUtils.CONTENT_TYPE_CSV)
public void queryEventsCsv(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) AssignedUserSelectionMode assignedUserMode, @RequestParam(required = false) String assignedUser, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @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 paging, @RequestParam(required = false) List<OrderCriteria> order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam(required = false, defaultValue = "false") boolean includeAllDataElements, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, false);
if (attributeOptionCombo == null) {
throw new WebMessageException(conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
Set<String> assignedUserIds = TextUtils.splitToArray(assignedUser, TextUtils.SEMICOLON);
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
skipPaging = PagerUtils.isSkipPaging(skipPaging, paging);
EventSearchParams params = requestToSearchParamsMapper.map(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, null, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, false, assignedUserMode, assignedUserIds, filter, dataElement, includeAllDataElements, includeDeleted);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.NO_CACHE);
Grid grid = eventService.getEventsGrid(params);
GridUtils.toCsv(grid, response.getWriter());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EventController method queryEventsXls.
@GetMapping(value = "/query", produces = ContextUtils.CONTENT_TYPE_EXCEL)
public void queryEventsXls(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) AssignedUserSelectionMode assignedUserMode, @RequestParam(required = false) String assignedUser, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @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 paging, @RequestParam(required = false) List<OrderCriteria> order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam(required = false, defaultValue = "false") boolean includeAllDataElements, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, false);
if (attributeOptionCombo == null) {
throw new WebMessageException(conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
Set<String> assignedUserIds = TextUtils.splitToArray(assignedUser, TextUtils.SEMICOLON);
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
skipPaging = PagerUtils.isSkipPaging(skipPaging, paging);
EventSearchParams params = requestToSearchParamsMapper.map(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, null, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, false, assignedUserMode, assignedUserIds, filter, dataElement, includeAllDataElements, includeDeleted);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.NO_CACHE);
Grid grid = eventService.getEventsGrid(params);
GridUtils.toXls(grid, response.getOutputStream());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class RequestToSearchParamsMapper method map.
public EventSearchParams map(String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate, Date dueDateStart, Date dueDateEnd, Date lastUpdatedStartDate, Date lastUpdatedEndDate, String lastUpdatedDuration, EventStatus status, CategoryOptionCombo attributeOptionCombo, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, List<OrderParam> orders, List<OrderParam> gridOrders, boolean includeAttributes, Set<String> events, Set<String> programInstances, Boolean skipEventId, AssignedUserSelectionMode assignedUserSelectionMode, Set<String> assignedUsers, Set<String> filters, Set<String> dataElements, boolean includeAllDataElements, boolean includeDeleted) {
User user = currentUserService.getCurrentUser();
EventSearchParams params = new EventSearchParams();
Program pr = programService.getProgram(program);
if (!StringUtils.isEmpty(program) && pr == null) {
throw new IllegalQueryException("Program is specified but does not exist: " + program);
}
ProgramStage ps = programStageService.getProgramStage(programStage);
if (!StringUtils.isEmpty(programStage) && ps == null) {
throw new IllegalQueryException("Program stage is specified but does not exist: " + programStage);
}
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(orgUnit);
if (!StringUtils.isEmpty(orgUnit) && ou == null) {
throw new IllegalQueryException("Org unit is specified but does not exist: " + orgUnit);
}
if (pr != null && !user.isSuper() && !aclService.canDataRead(user, pr)) {
throw new IllegalQueryException("User has no access to program: " + pr.getUid());
}
if (ps != null && !user.isSuper() && !aclService.canDataRead(user, ps)) {
throw new IllegalQueryException("User has no access to program stage: " + ps.getUid());
}
TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(trackedEntityInstance);
if (!StringUtils.isEmpty(trackedEntityInstance) && tei == null) {
throw new IllegalQueryException("Tracked entity instance is specified but does not exist: " + trackedEntityInstance);
}
if (attributeOptionCombo != null && !user.isSuper() && !aclService.canDataRead(user, attributeOptionCombo)) {
throw new IllegalQueryException("User has no access to attribute category option combo: " + attributeOptionCombo.getUid());
}
if (!CollectionUtils.isEmpty(events) && !CollectionUtils.isEmpty(filters)) {
throw new IllegalQueryException("Event UIDs and filters can not be specified at the same time");
}
if (events == null) {
events = new HashSet<>();
}
if (filters != null) {
if (!StringUtils.isEmpty(programStage) && ps == null) {
throw new IllegalQueryException("ProgramStage needs to be specified for event filtering to work");
}
for (String filter : filters) {
QueryItem item = getQueryItem(filter);
params.getFilters().add(item);
}
}
if (dataElements != null) {
for (String de : dataElements) {
QueryItem dataElement = getQueryItem(de);
params.getDataElements().add(dataElement);
}
}
if (assignedUserSelectionMode != null && assignedUsers != null && !assignedUsers.isEmpty() && !assignedUserSelectionMode.equals(AssignedUserSelectionMode.PROVIDED)) {
throw new IllegalQueryException("Assigned User uid(s) cannot be specified if selectionMode is not PROVIDED");
}
if (assignedUsers != null) {
assignedUsers = assignedUsers.stream().filter(CodeGenerator::isValidUid).collect(Collectors.toSet());
}
if (programInstances != null) {
programInstances = programInstances.stream().filter(CodeGenerator::isValidUid).collect(Collectors.toSet());
}
return params.setProgram(pr).setProgramStage(ps).setOrgUnit(ou).setTrackedEntityInstance(tei).setProgramStatus(programStatus).setFollowUp(followUp).setOrgUnitSelectionMode(orgUnitSelectionMode).setAssignedUserSelectionMode(assignedUserSelectionMode).setAssignedUsers(assignedUsers).setStartDate(startDate).setEndDate(endDate).setDueDateStart(dueDateStart).setDueDateEnd(dueDateEnd).setLastUpdatedStartDate(lastUpdatedStartDate).setLastUpdatedEndDate(lastUpdatedEndDate).setLastUpdatedDuration(lastUpdatedDuration).setEventStatus(status).setCategoryOptionCombo(attributeOptionCombo).setIdSchemes(idSchemes).setPage(page).setPageSize(pageSize).setTotalPages(totalPages).setSkipPaging(skipPaging).setSkipEventId(skipEventId).setIncludeAttributes(includeAttributes).setIncludeAllDataElements(includeAllDataElements).setOrders(orders).setGridOrders(gridOrders).setEvents(events).setProgramInstances(programInstances).setIncludeDeleted(includeDeleted);
}
Aggregations