Search in sources :

Example 16 with STOREDBY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.

the class GetHistoryAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    DataElement dataElement = dataElementService.getDataElement(dataElementId);
    CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(optionComboId);
    if (categoryOptionCombo == null) {
        categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    }
    if (dataElement == null) {
        throw new IllegalArgumentException("DataElement doesn't exist: " + dataElementId);
    }
    Period period = PeriodType.getPeriodFromIsoString(periodId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
    dataElementHistory = historyRetriever.getHistory(dataElement, categoryOptionCombo, attributeOptionCombo, organisationUnit, period, HISTORY_LENGTH);
    dataValueAudits = dataValueAuditService.getDataValueAudits(Lists.newArrayList(dataElement), Lists.newArrayList(period), Lists.newArrayList(organisationUnit), categoryOptionCombo, attributeOptionCombo, null);
    dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
    if (dataValue != null) {
        User credentials = userService.getUserByUsername(dataValue.getStoredBy());
        storedBy = credentials != null ? credentials.getName() : dataValue.getStoredBy();
    }
    if (dataElement.isFileType()) {
        fileNames = new HashMap<String, String>();
        dataValueAudits.removeIf(audit -> fileResourceService.getFileResource(audit.getValue()) == null);
        dataValueAudits.stream().filter(audit -> audit != null).map(audit -> fileResourceService.getFileResource(audit.getValue())).forEach(fr -> fileNames.put(fr.getUid(), fr.getName()));
    }
    historyInvalid = dataElementHistory == null;
    minMaxInvalid = !dataElement.getValueType().isNumeric();
    commentOptionSet = dataElement.getCommentOptionSet();
    attributeOptionComboId = attributeOptionCombo.getUid();
    return SUCCESS;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataValueAuditService(org.hisp.dhis.datavalue.DataValueAuditService) DataElementService(org.hisp.dhis.dataelement.DataElementService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataElement(org.hisp.dhis.dataelement.DataElement) DataValueService(org.hisp.dhis.datavalue.DataValueService) Lists(com.google.common.collect.Lists) DataElementHistory(org.hisp.dhis.dataelementhistory.DataElementHistory) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) User(org.hisp.dhis.user.User) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) Period(org.hisp.dhis.period.Period) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) HistoryRetriever(org.hisp.dhis.dataelementhistory.HistoryRetriever) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Action(com.opensymphony.xwork2.Action) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 17 with STOREDBY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.

the class EventStoredByPreProcessor method process.

@Override
public void process(Event event, WorkContext ctx) {
    final String storedBy = EventUtils.getValidUsername(event.getStoredBy(), ctx.getImportOptions());
    event.setStoredBy(storedBy);
    Set<DataValue> dataValues = event.getDataValues();
    for (DataValue dataValue : dataValues) {
        dataValue.setStoredBy(storedBy);
    }
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue)

Example 18 with STOREDBY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method addAttributeValues.

private void addAttributeValues(TrackedEntityInstance dtoEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance, User user) {
    for (Attribute dtoAttribute : dtoEntityInstance.getAttributes()) {
        TrackedEntityAttribute daoEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute(dtoAttribute.getAttribute());
        if (daoEntityAttribute != null) {
            TrackedEntityAttributeValue daoAttributeValue = new TrackedEntityAttributeValue();
            daoAttributeValue.setEntityInstance(daoEntityInstance);
            daoAttributeValue.setValue(dtoAttribute.getValue());
            daoAttributeValue.setAttribute(daoEntityAttribute);
            daoEntityInstance.addAttributeValue(daoAttributeValue);
            String storedBy = getStoredBy(dtoAttribute, new ImportSummary(), User.username(user, Constants.UNKNOWN));
            daoAttributeValue.setStoredBy(storedBy);
            trackedEntityAttributeValueService.addTrackedEntityAttributeValue(daoAttributeValue);
        }
    }
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)

Example 19 with STOREDBY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method updateAttributeValues.

private void updateAttributeValues(TrackedEntityInstance dtoEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance, Program program, User user) {
    Set<String> incomingAttributes = new HashSet<>();
    Map<String, TrackedEntityAttributeValue> teiAttributeToValueMap = getTeiAttributeValueMap(trackedEntityAttributeValueService.getTrackedEntityAttributeValues(daoEntityInstance));
    for (Attribute dtoAttribute : dtoEntityInstance.getAttributes()) {
        String storedBy = getStoredBy(dtoAttribute, new ImportSummary(), User.username(user, Constants.UNKNOWN));
        TrackedEntityAttributeValue existingAttributeValue = teiAttributeToValueMap.get(dtoAttribute.getAttribute());
        incomingAttributes.add(dtoAttribute.getAttribute());
        if (// value exists
        existingAttributeValue != null) {
            if (// value
            !existingAttributeValue.getValue().equals(dtoAttribute.getValue())) // is
            // changed,
            // do
            // update
            {
                existingAttributeValue.setStoredBy(storedBy);
                existingAttributeValue.setValue(dtoAttribute.getValue());
                trackedEntityAttributeValueService.updateTrackedEntityAttributeValue(existingAttributeValue, user);
            }
        } else // value is new, do add
        {
            TrackedEntityAttribute daoEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute(dtoAttribute.getAttribute());
            TrackedEntityAttributeValue newAttributeValue = new TrackedEntityAttributeValue();
            newAttributeValue.setStoredBy(storedBy);
            newAttributeValue.setEntityInstance(daoEntityInstance);
            newAttributeValue.setValue(dtoAttribute.getValue());
            newAttributeValue.setAttribute(daoEntityAttribute);
            daoEntityInstance.getTrackedEntityAttributeValues().add(newAttributeValue);
            trackedEntityAttributeValueService.addTrackedEntityAttributeValue(newAttributeValue);
        }
    }
    if (program != null) {
        for (TrackedEntityAttribute att : program.getTrackedEntityAttributes()) {
            TrackedEntityAttributeValue attVal = teiAttributeToValueMap.get(att.getUid());
            if (attVal != null && !incomingAttributes.contains(att.getUid())) {
                trackedEntityAttributeValueService.deleteTrackedEntityAttributeValue(attVal);
            }
        }
    }
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) HashSet(java.util.HashSet)

Example 20 with STOREDBY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STOREDBY in project dhis2-core by dhis2.

the class EnrollmentRowCallbackHandler method getEnrollment.

private Enrollment getEnrollment(ResultSet rs) throws SQLException {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(rs.getString(getColumnName(UID)));
    MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
    enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
    enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
    enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
    enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
    enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
    enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
    enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
    enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
    final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
    enrollment.setFollowup(rs.wasNull() ? null : followup);
    enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
    enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
    enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    enrollment.setId(rs.getLong(getColumnName(ID)));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Aggregations

Date (java.util.Date)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 DataElement (org.hisp.dhis.dataelement.DataElement)6 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 Period (org.hisp.dhis.period.Period)6 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)5 DataSet (org.hisp.dhis.dataset.DataSet)4 DataValue (org.hisp.dhis.datavalue.DataValue)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IdScheme (org.hisp.dhis.common.IdScheme)3 Event (org.hisp.dhis.dxf2.events.event.Event)3 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)2 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)2