use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class AbstractEventService method getAnonymousEventValuesLastUpdatedAfter.
@Override
public Events getAnonymousEventValuesLastUpdatedAfter(Date lastSuccessTime) {
EventSearchParams params = buildAnonymousEventsSearchParams(lastSuccessTime);
Events anonymousEvents = new Events();
List<Event> events = eventStore.getEvents(params, null);
anonymousEvents.setEvents(events);
return anonymousEvents;
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class EventController method getEventsGrid.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "/query", method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Grid getEventsGrid(@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(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
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, null, getGridOrderParams(order), false, eventIds, filter, dataElement, includeDeleted);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE);
return eventService.getEventsGrid(params);
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams in project dhis2-core by dhis2.
the class EventController method getEventRows.
@RequestMapping(value = "/eventRows", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public EventRows getEventRows(@RequestParam(required = false) String program, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) EventStatus eventStatus, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam Map<String, String> parameters, Model model) throws WebMessageException {
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, true);
EventSearchParams params = eventService.getFromUrl(program, null, programStatus, null, orgUnit, ouMode, null, startDate, endDate, null, null, null, null, eventStatus, attributeOptionCombo, null, null, null, totalPages, skipPaging, getOrderParams(order), null, true, null, null, null, includeDeleted);
return eventRowService.getEventRows(params);
}
use of org.hisp.dhis.dxf2.events.event.EventSearchParams 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.event.EventSearchParams in project dhis2-core by dhis2.
the class JdbcEventStore method getEvents.
// -------------------------------------------------------------------------
// EventStore implementation
// -------------------------------------------------------------------------
@Override
public List<Event> getEvents(EventSearchParams params, List<OrganisationUnit> organisationUnits, Map<String, Set<String>> psdesWithSkipSyncTrue) {
User user = currentUserService.getCurrentUser();
setAccessiblePrograms(user, params);
Map<String, Event> eventUidToEventMap = new HashMap<>(params.getPageSizeWithDefault());
List<Event> events = new ArrayList<>();
List<Long> relationshipIds = new ArrayList<>();
final Gson gson = new Gson();
String sql = buildSql(params, organisationUnits, user);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
log.debug("Event query SQL: " + sql);
Set<String> notes = new HashSet<>();
while (rowSet.next()) {
if (rowSet.getString("psi_uid") == null || (params.getCategoryOptionCombo() == null && !isSuper(user) && !userHasAccess(rowSet))) {
continue;
}
String psiUid = rowSet.getString("psi_uid");
Event event;
if (!eventUidToEventMap.containsKey(psiUid)) {
validateIdentifiersPresence(rowSet, params.getIdSchemes(), true);
event = new Event();
eventUidToEventMap.put(psiUid, event);
if (!params.isSkipEventId()) {
event.setUid(psiUid);
event.setEvent(psiUid);
}
event.setTrackedEntityInstance(rowSet.getString("tei_uid"));
event.setStatus(EventStatus.valueOf(rowSet.getString("psi_status")));
ProgramType programType = ProgramType.fromValue(rowSet.getString("p_type"));
event.setProgram(rowSet.getString("p_identifier"));
event.setProgramType(programType);
event.setProgramStage(rowSet.getString("ps_identifier"));
event.setOrgUnit(rowSet.getString("ou_identifier"));
event.setDeleted(rowSet.getBoolean("psi_deleted"));
if (programType != ProgramType.WITHOUT_REGISTRATION) {
event.setEnrollment(rowSet.getString("pi_uid"));
event.setEnrollmentStatus(EnrollmentStatus.fromProgramStatus(ProgramStatus.valueOf(rowSet.getString("pi_status"))));
event.setFollowup(rowSet.getBoolean("pi_followup"));
}
if (params.getCategoryOptionCombo() == null && !isSuper(user)) {
event.setOptionSize(rowSet.getInt("option_size"));
}
event.setAttributeOptionCombo(rowSet.getString("coc_identifier"));
event.setAttributeCategoryOptions(rowSet.getString("deco_uid"));
event.setTrackedEntityInstance(rowSet.getString("tei_uid"));
event.setStoredBy(rowSet.getString("psi_storedby"));
event.setOrgUnitName(rowSet.getString("ou_name"));
event.setDueDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_duedate")));
event.setEventDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_executiondate")));
event.setCreated(DateUtils.getIso8601NoTz(rowSet.getDate("psi_created")));
event.setCreatedByUserInfo(jsonToUserInfo(rowSet.getString("psi_createdbyuserinfo"), jsonMapper));
event.setLastUpdated(DateUtils.getIso8601NoTz(rowSet.getDate("psi_lastupdated")));
event.setLastUpdatedByUserInfo(jsonToUserInfo(rowSet.getString("psi_lastupdatedbyuserinfo"), jsonMapper));
event.setCompletedBy(rowSet.getString("psi_completedby"));
event.setCompletedDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_completeddate")));
if (rowSet.getObject("psi_geometry") != null) {
try {
Geometry geom = new WKTReader().read(rowSet.getString("psi_geometry"));
event.setGeometry(geom);
} catch (ParseException e) {
log.error("Unable to read geometry for event '" + event.getUid() + "': ", e);
}
}
if (rowSet.getObject("user_assigned") != null) {
event.setAssignedUser(rowSet.getString("user_assigned"));
event.setAssignedUserUsername(rowSet.getString("user_assigned_username"));
event.setAssignedUserDisplayName(rowSet.getString("user_assigned_name"));
}
events.add(event);
} else {
event = eventUidToEventMap.get(psiUid);
String attributeCategoryCombination = event.getAttributeCategoryOptions();
String currentAttributeCategoryCombination = rowSet.getString("deco_uid");
if (!attributeCategoryCombination.contains(currentAttributeCategoryCombination)) {
event.setAttributeCategoryOptions(attributeCategoryCombination + ";" + currentAttributeCategoryCombination);
}
}
if (!StringUtils.isEmpty(rowSet.getString("psi_eventdatavalues"))) {
Set<EventDataValue> eventDataValues = convertEventDataValueJsonIntoSet(rowSet.getString("psi_eventdatavalues"));
for (EventDataValue dv : eventDataValues) {
DataValue dataValue = convertEventDataValueIntoDtoDataValue(dv);
if (params.isSynchronizationQuery()) {
if (psdesWithSkipSyncTrue.containsKey(rowSet.getString("ps_uid")) && psdesWithSkipSyncTrue.get(rowSet.getString("ps_uid")).contains(dv.getDataElement())) {
dataValue.setSkipSynchronization(true);
} else {
dataValue.setSkipSynchronization(false);
}
}
event.getDataValues().add(dataValue);
}
}
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"));
if (rowSet.getObject("usernote_id") != null) {
note.setLastUpdatedBy(UserInfoSnapshot.of(rowSet.getLong("usernote_id"), rowSet.getString("usernote_code"), rowSet.getString("usernote_uid"), rowSet.getString("usernote_username"), rowSet.getString("userinfo_firstname"), rowSet.getString("userinfo_surname")));
}
note.setLastUpdated(rowSet.getDate("psinote_lastupdated"));
event.getNotes().add(note);
notes.add(rowSet.getString("psinote_id"));
}
if (params.isIncludeRelationships() && rowSet.getObject("psi_rl") != null) {
PGobject pGobject = (PGobject) rowSet.getObject("psi_rl");
if (pGobject != null) {
String value = pGobject.getValue();
relationshipIds.addAll(Lists.newArrayList(gson.fromJson(value, Long[].class)));
}
}
}
final Multimap<String, Relationship> map = eventStore.getRelationshipsByIds(relationshipIds);
if (!map.isEmpty()) {
events.forEach(e -> e.getRelationships().addAll(map.get(e.getEvent())));
}
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 = events.stream().map(Event::getDataValues).collect(Collectors.toList());
populateCache(dataElementIdScheme, dataValuesList, dataElementUidToIdentifierCache);
convertDataValuesIdentifiers(dataElementIdScheme, dataValuesList, dataElementUidToIdentifierCache);
}
if (params.getCategoryOptionCombo() == null && !isSuper(user)) {
return events.stream().filter(ev -> ev.getAttributeCategoryOptions() != null && splitToArray(ev.getAttributeCategoryOptions(), TextUtils.SEMICOLON).size() == ev.getOptionSize()).collect(Collectors.toList());
}
return events;
}
Aggregations