use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class AbstractEventService method getFromUrl.
@Override
public EventSearchParams getFromUrl(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, EventStatus status, DataElementCategoryOptionCombo attributeOptionCombo, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, List<Order> orders, List<String> gridOrders, boolean includeAttributes, Set<String> events, Set<String> filters, Set<String> dataElements, boolean includeDeleted) {
UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
EventSearchParams params = new EventSearchParams();
Program pr = programService.getProgram(program);
if (StringUtils.isNotEmpty(program) && pr == null) {
throw new IllegalQueryException("Program is specified but does not exist: " + program);
}
ProgramStage ps = programStageService.getProgramStage(programStage);
if (StringUtils.isNotEmpty(programStage) && ps == null) {
throw new IllegalQueryException("Program stage is specified but does not exist: " + programStage);
}
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(orgUnit);
if (StringUtils.isNotEmpty(orgUnit) && ou == null) {
throw new IllegalQueryException("Org unit is specified but does not exist: " + orgUnit);
}
if (ou != null && !organisationUnitService.isInUserHierarchy(ou)) {
if (!userCredentials.isSuper() && !userCredentials.isAuthorized("F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS")) {
throw new IllegalQueryException("User has no access to organisation unit: " + ou.getUid());
}
}
if (pr != null && !userCredentials.isSuper() && !userCredentials.canAccessProgram(pr)) {
throw new IllegalQueryException("User has no access to program: " + pr.getUid());
}
TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(trackedEntityInstance);
if (StringUtils.isNotEmpty(trackedEntityInstance) && tei == null) {
throw new IllegalQueryException("Tracked entity instance is specified but does not exist: " + trackedEntityInstance);
}
if (events != null && filters != null) {
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.isNotEmpty(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);
}
}
params.setProgram(pr);
params.setProgramStage(ps);
params.setOrgUnit(ou);
params.setTrackedEntityInstance(tei);
params.setProgramStatus(programStatus);
params.setFollowUp(followUp);
params.setOrgUnitSelectionMode(orgUnitSelectionMode);
params.setStartDate(startDate);
params.setEndDate(endDate);
params.setDueDateStart(dueDateStart);
params.setDueDateEnd(dueDateEnd);
params.setLastUpdatedStartDate(lastUpdatedStartDate);
params.setLastUpdatedEndDate(lastUpdatedEndDate);
params.setEventStatus(status);
params.setCategoryOptionCombo(attributeOptionCombo);
params.setIdSchemes(idSchemes);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
params.setIncludeAttributes(includeAttributes);
params.setOrders(orders);
params.setGridOrders(gridOrders);
params.setEvents(events);
params.setIncludeDeleted(includeDeleted);
return params;
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class AbstractEventService method buildAnonymousEventsSearchParams.
private EventSearchParams buildAnonymousEventsSearchParams(Date lastSuccessTime) {
EventSearchParams params = new EventSearchParams();
params.setProgramType(ProgramType.WITHOUT_REGISTRATION);
params.setLastUpdatedStartDate(lastSuccessTime);
return params;
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class EventController method getCsvEvents.
@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/csv", "application/csv+gzip", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
public void getCsvEvents(@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) 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, defaultValue = "false") boolean skipHeader, IdSchemes idSchemes, HttpServletResponse response, HttpServletRequest request) throws IOException, WebMessageException {
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));
}
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, null, null, null, includeDeleted);
Events events = eventService.getEvents(params);
OutputStream outputStream = response.getOutputStream();
response.setContentType("application/csv");
if (ContextUtils.isAcceptCsvGzip(request)) {
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
outputStream = new GZIPOutputStream(outputStream);
response.setContentType("application/csv+gzip");
}
if (!StringUtils.isEmpty(attachment)) {
response.addHeader("Content-Disposition", "attachment; filename=" + attachment);
}
csvEventService.writeEvents(outputStream, events, !skipHeader);
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class AbstractEventService method getEventRows.
@Transactional(readOnly = true)
@Override
public EventRows getEventRows(EventSearchParams params) {
User user = currentUserService.getCurrentUser();
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
EventRows eventRows = new EventRows();
List<EventRow> eventRowList = eventStore.getEventRows(params, organisationUnits);
EventContext eventContext = eventServiceContextBuilder.build(eventRowList, user);
for (EventRow eventRow : eventRowList) {
if (trackerOwnershipAccessManager.hasAccessUsingContext(user, eventRow.getTrackedEntityInstance(), eventRow.getProgram(), eventContext)) {
eventRows.getEventRows().add(eventRow);
}
}
return eventRows;
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class JdbcEventStore method getEventRows.
@Override
public List<EventRow> getEventRows(EventSearchParams params, List<OrganisationUnit> organisationUnits) {
User user = currentUserService.getCurrentUser();
setAccessiblePrograms(user, params);
List<EventRow> eventRows = new ArrayList<>();
String sql = buildSql(params, organisationUnits, user);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
log.debug("Event query SQL: " + sql);
EventRow eventRow = new EventRow();
eventRow.setEvent("not_valid");
Set<String> notes = new HashSet<>();
Map<String, List<DataValue>> processedDataValues = new HashMap<>();
while (rowSet.next()) {
if (rowSet.getString("psi_uid") == null || (params.getCategoryOptionCombo() == null && !isSuper(user) && !userHasAccess(rowSet))) {
continue;
}
if (eventRow.getUid() == null || !eventRow.getUid().equals(rowSet.getString("psi_uid"))) {
validateIdentifiersPresence(rowSet, params.getIdSchemes(), false);
eventRow = new EventRow();
eventRow.setUid(rowSet.getString("psi_uid"));
eventRow.setEvent(rowSet.getString("psi_uid"));
eventRow.setTrackedEntityInstance(rowSet.getString("tei_uid"));
eventRow.setTrackedEntityInstanceOrgUnit(rowSet.getString("tei_ou"));
eventRow.setTrackedEntityInstanceOrgUnitName(rowSet.getString("tei_ou_name"));
eventRow.setTrackedEntityInstanceCreated(rowSet.getString("tei_created"));
eventRow.setTrackedEntityInstanceInactive(rowSet.getBoolean("tei_inactive"));
eventRow.setDeleted(rowSet.getBoolean("psi_deleted"));
eventRow.setProgram(rowSet.getString("p_identifier"));
eventRow.setProgramStage(rowSet.getString("ps_identifier"));
eventRow.setOrgUnit(rowSet.getString("ou_identifier"));
ProgramType programType = ProgramType.fromValue(rowSet.getString("p_type"));
if (programType == ProgramType.WITHOUT_REGISTRATION) {
eventRow.setEnrollment(rowSet.getString("pi_uid"));
eventRow.setFollowup(rowSet.getBoolean("pi_followup"));
}
eventRow.setTrackedEntityInstance(rowSet.getString("tei_uid"));
eventRow.setOrgUnitName(rowSet.getString("ou_name"));
eventRow.setDueDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_duedate")));
eventRow.setEventDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_executiondate")));
eventRows.add(eventRow);
}
if (rowSet.getString("pav_value") != null && rowSet.getString("ta_uid") != null) {
String valueType = rowSet.getString("ta_valuetype");
Attribute attribute = new Attribute();
attribute.setCreated(DateUtils.getIso8601NoTz(rowSet.getDate("pav_created")));
attribute.setLastUpdated(DateUtils.getIso8601NoTz(rowSet.getDate("pav_lastupdated")));
attribute.setValue(rowSet.getString("pav_value"));
attribute.setDisplayName(rowSet.getString("ta_name"));
attribute.setValueType(valueType != null ? ValueType.valueOf(valueType.toUpperCase()) : null);
attribute.setAttribute(rowSet.getString("ta_uid"));
eventRow.getAttributes().add(attribute);
}
if (!StringUtils.isEmpty(rowSet.getString("psi_eventdatavalues")) && !processedDataValues.containsKey(rowSet.getString("psi_uid"))) {
List<DataValue> dataValues = new ArrayList<>();
Set<EventDataValue> eventDataValues = convertEventDataValueJsonIntoSet(rowSet.getString("psi_eventdatavalues"));
for (EventDataValue dv : eventDataValues) {
dataValues.add(convertEventDataValueIntoDtoDataValue(dv));
}
processedDataValues.put(rowSet.getString("psi_uid"), dataValues);
}
if (rowSet.getString("psinote_value") != null && !notes.contains(rowSet.getString("psinote_id"))) {
Note note = new Note();
note.setNote(rowSet.getString("psinote_uid"));
note.setValue(rowSet.getString("psinote_value"));
note.setStoredDate(DateUtils.getIso8601NoTz(rowSet.getDate("psinote_storeddate")));
note.setStoredBy(rowSet.getString("psinote_storedby"));
eventRow.getNotes().add(note);
notes.add(rowSet.getString("psinote_id"));
}
}
eventRows.forEach(e -> e.setDataValues(processedDataValues.get(e.getUid())));
IdSchemes idSchemes = ObjectUtils.firstNonNull(params.getIdSchemes(), new IdSchemes());
IdScheme dataElementIdScheme = idSchemes.getDataElementIdScheme();
if (dataElementIdScheme != IdScheme.ID && dataElementIdScheme != IdScheme.UID) {
CachingMap<String, String> dataElementUidToIdentifierCache = new CachingMap<>();
List<Collection<DataValue>> dataValuesList = eventRows.stream().map(EventRow::getDataValues).collect(Collectors.toList());
populateCache(dataElementIdScheme, dataValuesList, dataElementUidToIdentifierCache);
convertDataValuesIdentifiers(dataElementIdScheme, dataValuesList, dataElementUidToIdentifierCache);
}
return eventRows;
}
Aggregations