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
// -------------------------------------------------------------------------
@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.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class EventController method getEvents.
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public RootNode getEvents(@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) 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) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
WebOptions options = new WebOptions(parameters);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
}
Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, getOrderParams(order), null, false, eventIds, null, null, includeDeleted);
Events events = eventService.getEvents(params);
if (hasHref(fields)) {
events.getEvents().forEach(e -> e.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + e.getEvent()));
}
if (!skipMeta && params.getProgram() != null) {
events.setMetaData(getMetaData(params.getProgram()));
}
model.addAttribute("model", events);
model.addAttribute("viewClass", options.getViewClass("detailed"));
RootNode rootNode = NodeUtils.createMetadata();
if (events.getPager() != null) {
rootNode.addChild(NodeUtils.createPager(events.getPager()));
}
if (!StringUtils.isEmpty(attachment)) {
response.addHeader(ContextUtils.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + attachment);
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
}
rootNode.addChild(fieldFilterService.filter(Event.class, events.getEvents(), 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
// ---------------------------------------------------------------------
@RequestMapping(value = "/files", method = RequestMethod.GET)
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, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
// ---------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------
DataElement dataElement = getAndValidateDataElement(de);
if (!dataElement.isFileType()) {
throw new WebMessageException(WebMessageUtils.conflict("DataElement must be of type file"));
}
DataElementCategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(co, false);
DataElementCategoryOptionCombo attributeOptionCombo = getAndValidateAttributeOptionCombo(cc, cp);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrganisationUnit(ou);
// ---------------------------------------------------------------------
// Get data value
// ---------------------------------------------------------------------
DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new WebMessageException(WebMessageUtils.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(WebMessageUtils.notFound("A data value file resource with id " + uid + " does not exist."));
}
FileResourceStorageStatus storageStatus = fileResource.getStorageStatus();
if (storageStatus != FileResourceStorageStatus.STORED) {
// Special case:
// The FileResource exists and has been tied to this DataValue, however, the underlying file
// content is still not stored to the (most likely external) file store provider.
// HTTP 409, for lack of a more suitable status code
WebMessage webMessage = WebMessageUtils.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.");
webMessage.setResponse(new FileResourceWebMessageResponse(fileResource));
throw new WebMessageException(webMessage);
}
ByteSource content = fileResourceService.getFileResourceContent(fileResource);
if (content == null) {
throw new WebMessageException(WebMessageUtils.notFound("The referenced file could not be found"));
}
// ---------------------------------------------------------------------
// Attempt to build signed URL request for content and redirect
// ---------------------------------------------------------------------
URI signedGetUri = fileResourceService.getSignedGetFileResourceContentUri(uid);
if (signedGetUri != null) {
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
response.setHeader(HttpHeaders.LOCATION, signedGetUri.toASCIIString());
return;
}
// ---------------------------------------------------------------------
// Build response and return
// ---------------------------------------------------------------------
response.setContentType(fileResource.getContentType());
response.setContentLength(new Long(fileResource.getContentLength()).intValue());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileResource.getName());
// ---------------------------------------------------------------------
// Request signing is not available, stream content back to client
// ---------------------------------------------------------------------
InputStream inputStream = null;
try {
inputStream = content.openStream();
IOUtils.copy(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new WebMessageException(WebMessageUtils.error("Failed fetching the file from storage", "There was an exception when trying to fetch the file from the storage backend. " + "Depending on the provider the root cause could be network or file system related."));
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalByCategoryOptionCombos.
@RequestMapping(value = APPROVALS_PATH + "/categoryOptionCombos", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalByCategoryOptionCombos(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam(required = false) String ou, HttpServletResponse response) throws IOException, WebMessageException {
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit != null && orgUnit.isRoot()) {
// Look for all org units.
orgUnit = null;
}
SetMap<DataApprovalWorkflow, DataElementCategoryCombo> workflowCategoryComboMap = new SetMap<>();
for (DataSet dataSet : dataSets) {
workflowCategoryComboMap.putValue(dataSet.getWorkflow(), dataSet.getCategoryCombo());
}
List<DataApprovalStatus> statusList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflowCategoryComboMap.keySet()) {
for (DataElementCategoryCombo attributeCombo : workflowCategoryComboMap.get(workflow)) {
statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (DataApprovalStatus status : statusList) {
Map<String, Object> item = new HashMap<>();
Map<String, String> approvalLevel = new HashMap<>();
if (status.getApprovedLevel() != null) {
approvalLevel.put("id", status.getApprovedLevel().getUid());
approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
}
item.put("id", status.getAttributeOptionComboUid());
item.put("level", approvalLevel);
item.put("ou", status.getOrganisationUnitUid());
item.put("ouName", status.getOrganisationUnitName());
item.put("accepted", status.isAccepted());
item.put("permissions", status.getPermissions());
list.add(item);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), list);
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class SmsController method sendSMSMessage.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/outbound", method = RequestMethod.POST, consumes = "application/json")
public void sendSMSMessage(HttpServletResponse response, HttpServletRequest request) throws WebMessageException, IOException {
OutboundSms sms = renderService.fromJson(request.getInputStream(), OutboundSms.class);
OutboundMessageResponse status = smsSender.sendMessage(null, sms.getMessage(), sms.getRecipients());
if (status.isOk()) {
webMessageService.send(WebMessageUtils.ok("SMS sent"), response, request);
} else {
throw new WebMessageException(WebMessageUtils.error(status.getDescription()));
}
}
Aggregations