use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testFromDataQueryParams.
@Test
public void testFromDataQueryParams() {
DataQueryParams dataQueryParams = DataQueryParams.newBuilder().withProgramDataElements(getList(pdeA, pdeB, pdeC, pdeD)).withProgramAttributes(getList(patA, patB)).withOrganisationUnits(getList(ouA, ouB, ouC)).withPeriods(getList(createPeriod("200101"), createPeriod("200103"), createPeriod("200105"), createPeriod("200107"))).build();
EventQueryParams params = EventQueryParams.fromDataQueryParams(dataQueryParams);
assertEquals(6, params.getItems().size());
assertNull(params.getDimension(DimensionalObject.DATA_X_DIM_ID));
assertTrue(params.isAggregateData());
for (QueryItem item : params.getItems()) {
assertEquals(prA, item.getProgram());
}
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findVisitSchedule.
@Override
public String findVisitSchedule(int orgUnitId, int programId, String info) throws NotAllowedException {
String status = info.substring(0, info.indexOf("$"));
String fromDays = info.substring(info.indexOf("$") + 1, info.indexOf("/"));
String toDays = info.substring(info.indexOf("/") + 1);
// Event Status
EventStatus eventStatus = null;
if (status.equals("Schedule in future")) {
eventStatus = EventStatus.SCHEDULE;
} else if (status.equals("Overdue")) {
eventStatus = EventStatus.OVERDUE;
} else if (status.equals("Incomplete")) {
eventStatus = EventStatus.VISITED;
} else if (status.equals("Completed")) {
eventStatus = EventStatus.COMPLETED;
} else if (status.equals("Skipped")) {
eventStatus = EventStatus.SKIPPED;
}
// From/To Date
Date fromDate = getDate(-1, fromDays);
Date toDate = getDate(1, toDays);
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
List<TrackedEntityAttribute> trackedEntityAttributeList = new ArrayList<>(attributeService.getTrackedEntityAttributesByDisplayOnVisitSchedule(true));
for (TrackedEntityAttribute trackedEntityAttribute : trackedEntityAttributeList) {
QueryItem queryItem = new QueryItem(trackedEntityAttribute);
param.addAttribute(queryItem);
}
param.setProgram(programService.getProgram(programId));
param.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
param.setEventStatus(eventStatus);
param.setEventStartDate(fromDate);
param.setEventEndDate(toDate);
Grid programStageInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> listOfListProgramStageInstance = programStageInstanceGrid.getRows();
if (listOfListProgramStageInstance.size() == 0) {
throw NotAllowedException.NO_EVENT_FOUND;
}
String eventsInfo = "";
for (List<Object> row : listOfListProgramStageInstance) {
TrackedEntityInstance instance = entityInstanceService.getTrackedEntityInstance((String) row.get(0));
Collection<TrackedEntityAttribute> displayAttributes = attributeService.getTrackedEntityAttributesDisplayInList();
eventsInfo += instance.getId() + "/";
String displayName = "";
for (TrackedEntityAttribute displayAttribute : displayAttributes) {
TrackedEntityAttributeValue value = attValueService.getTrackedEntityAttributeValue(instance, displayAttribute);
if (value != null) {
displayName += value.getValue() + " ";
}
}
eventsInfo += displayName.trim() + "$";
}
return eventsInfo;
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class TrackedEntityInstanceQueryParams method getDuplicateAttributes.
/**
* Returns a list of attributes which appear more than once.
*/
public List<QueryItem> getDuplicateAttributes() {
Set<QueryItem> items = new HashSet<>();
List<QueryItem> duplicates = new ArrayList<>();
for (QueryItem item : getAttributes()) {
if (!items.add(item)) {
duplicates.add(item);
}
}
return duplicates;
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class JdbcEventStore method getEventsGrid.
@Override
public List<Map<String, String>> getEventsGrid(EventSearchParams params, List<OrganisationUnit> organisationUnits) {
SqlHelper hlp = new SqlHelper();
// ---------------------------------------------------------------------
// Select clause
// ---------------------------------------------------------------------
String sql = "select psi.uid as " + EVENT_ID + ", " + "psi.created as " + EVENT_CREATED_ID + ", " + "psi.lastupdated as " + EVENT_LAST_UPDATED_ID + ", " + "psi.storedby as " + EVENT_STORED_BY_ID + ", " + "psi.completedby as " + EVENT_COMPLETED_BY_ID + ", " + "psi.completeddate as " + EVENT_COMPLETED_DATE_ID + ", " + "psi.duedate as " + EVENT_DUE_DATE_ID + ", " + "psi.executiondate as " + EVENT_EXECUTION_DATE_ID + ", " + "ou.uid as " + EVENT_ORG_UNIT_ID + ", " + "ou.name as " + EVENT_ORG_UNIT_NAME + ", " + "psi.status as " + EVENT_STATUS_ID + ", " + "psi.longitude as " + EVENT_LONGITUDE_ID + ", " + "psi.latitude as " + EVENT_LATITUDE_ID + ", " + "ps.uid as " + EVENT_PROGRAM_STAGE_ID + ", " + "p.uid as " + EVENT_PROGRAM_ID + ", " + "coc.uid as " + EVENT_ATTRIBUTE_OPTION_COMBO_ID + ", " + "psi.deleted as " + EVENT_DELETED + ", ";
for (QueryItem item : params.getDataElementsAndFilters()) {
String col = statementBuilder.columnQuote(item.getItemId());
sql += item.isNumeric() ? "CAST( " + col + ".value AS NUMERIC ) as " : col + ".value as ";
sql += col + ", ";
}
sql = removeLastComma(sql) + " ";
// ---------------------------------------------------------------------
// From and where clause
// ---------------------------------------------------------------------
sql += getFromWhereClause(params, hlp, organisationUnits);
// ---------------------------------------------------------------------
// Order clause
// ---------------------------------------------------------------------
sql += getGridOrderQuery(params);
// ---------------------------------------------------------------------
// Paging clause
// ---------------------------------------------------------------------
sql += getEventPagingQuery(params);
// ---------------------------------------------------------------------
// Query
// ---------------------------------------------------------------------
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
log.debug("Event query SQL: " + sql);
List<Map<String, String>> list = new ArrayList<>();
while (rowSet.next()) {
final Map<String, String> map = new HashMap<>();
for (String col : STATIC_EVENT_COLUMNS) {
map.put(col, rowSet.getString(col));
}
for (QueryItem item : params.getDataElements()) {
map.put(item.getItemId(), rowSet.getString(item.getItemId()));
}
list.add(map);
}
return list;
}
use of org.hisp.dhis.common.QueryItem 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;
}
Aggregations