use of org.hisp.dhis.dxf2.events.report.EventRows in project dhis2-core by dhis2.
the class JdbcEventStore method getEventRows.
@Override
public List<EventRow> getEventRows(EventSearchParams params, List<OrganisationUnit> organisationUnits) {
List<EventRow> eventRows = new ArrayList<>();
String sql = buildSql(params, organisationUnits);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
log.debug("Event query SQL: " + sql);
EventRow eventRow = new EventRow();
eventRow.setEvent("not_valid");
Set<String> notes = new HashSet<>();
IdSchemes idSchemes = ObjectUtils.firstNonNull(params.getIdSchemes(), new IdSchemes());
while (rowSet.next()) {
if (rowSet.getString("psi_uid") == null) {
continue;
}
if (eventRow.getUid() == null || !eventRow.getUid().equals(rowSet.getString("psi_uid"))) {
eventRow = new EventRow();
eventRow.setUid(rowSet.getString("psi_uid"));
eventRow.setEvent(IdSchemes.getValue(rowSet.getString("psi_uid"), rowSet.getString("psi_code"), idSchemes.getProgramStageInstanceIdScheme()));
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(IdSchemes.getValue(rowSet.getString("p_uid"), rowSet.getString("p_code"), idSchemes.getProgramIdScheme()));
eventRow.setProgramStage(IdSchemes.getValue(rowSet.getString("ps_uid"), rowSet.getString("ps_code"), idSchemes.getProgramStageIdScheme()));
eventRow.setOrgUnit(IdSchemes.getValue(rowSet.getString("ou_uid"), rowSet.getString("ou_code"), idSchemes.getOrgUnitIdScheme()));
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 (rowSet.getString("pdv_value") != null && rowSet.getString("de_uid") != null) {
DataValue dataValue = new DataValue();
dataValue.setCreated(DateUtils.getIso8601NoTz(rowSet.getDate("pdv_created")));
dataValue.setLastUpdated(DateUtils.getIso8601NoTz(rowSet.getDate("pdv_lastupdated")));
dataValue.setValue(rowSet.getString("pdv_value"));
dataValue.setProvidedElsewhere(rowSet.getBoolean("pdv_providedelsewhere"));
dataValue.setDataElement(IdSchemes.getValue(rowSet.getString("de_uid"), rowSet.getString("de_code"), idSchemes.getDataElementIdScheme()));
dataValue.setStoredBy(rowSet.getString("pdv_storedby"));
eventRow.getDataValues().add(dataValue);
}
if (rowSet.getString("psinote_value") != null && !notes.contains(rowSet.getString("psinote_id"))) {
Note note = new Note();
note.setValue(rowSet.getString("psinote_value"));
note.setStoredDate(rowSet.getString("psinote_storeddate"));
note.setStoredBy(rowSet.getString("psinote_storedby"));
eventRow.getNotes().add(note);
notes.add(rowSet.getString("psinote_id"));
}
}
return eventRows;
}
use of org.hisp.dhis.dxf2.events.report.EventRows in project dhis2-core by dhis2.
the class AbstractEventService method getEventRows.
@Override
public EventRows getEventRows(EventSearchParams params) {
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params);
EventRows eventRows = new EventRows();
List<EventRow> eventRowList = eventStore.getEventRows(params, organisationUnits);
eventRows.setEventRows(eventRowList);
return eventRows;
}
use of org.hisp.dhis.dxf2.events.report.EventRows 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);
}
Aggregations