Search in sources :

Example 1 with EventRow

use of org.hisp.dhis.dxf2.events.report.EventRow 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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) EventRows(org.hisp.dhis.dxf2.events.report.EventRows) EventRow(org.hisp.dhis.dxf2.events.report.EventRow) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EventRow

use of org.hisp.dhis.dxf2.events.report.EventRow 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;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) User(org.hisp.dhis.user.User) IdSchemes(org.hisp.dhis.common.IdSchemes) HashMap(java.util.HashMap) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ArrayList(java.util.ArrayList) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getLongGmtDateString(org.hisp.dhis.util.DateUtils.getLongGmtDateString) IdScheme(org.hisp.dhis.common.IdScheme) EventRow(org.hisp.dhis.dxf2.events.report.EventRow) CachingMap(org.hisp.dhis.commons.collection.CachingMap) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ProgramType(org.hisp.dhis.program.ProgramType) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) HashSet(java.util.HashSet)

Aggregations

EventRow (org.hisp.dhis.dxf2.events.report.EventRow)2 User (org.hisp.dhis.user.User)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 IdScheme (org.hisp.dhis.common.IdScheme)1 IdSchemes (org.hisp.dhis.common.IdSchemes)1 CachingMap (org.hisp.dhis.commons.collection.CachingMap)1 TextUtils.getQuotedCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)1 EventRows (org.hisp.dhis.dxf2.events.report.EventRows)1 Attribute (org.hisp.dhis.dxf2.events.trackedentity.Attribute)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramType (org.hisp.dhis.program.ProgramType)1 DateUtils.getLongGmtDateString (org.hisp.dhis.util.DateUtils.getLongGmtDateString)1 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)1