Search in sources :

Example 1 with SmsDataValue

use of org.hisp.dhis.smscompression.models.SmsDataValue in project dhis2-core by dhis2.

the class SimpleEventSMSListenerTest method createSimpleEventSubmission.

private SimpleEventSmsSubmission createSimpleEventSubmission() {
    SimpleEventSmsSubmission subm = new SimpleEventSmsSubmission();
    subm.setUserId(user.getUid());
    subm.setOrgUnit(organisationUnit.getUid());
    subm.setEventProgram(program.getUid());
    subm.setAttributeOptionCombo(categoryOptionCombo.getUid());
    subm.setEvent(programStageInstance.getUid());
    subm.setEventStatus(SmsEventStatus.COMPLETED);
    subm.setEventDate(new Date());
    subm.setDueDate(new Date());
    subm.setCoordinates(new GeoPoint(59.9399586f, 10.7195609f));
    ArrayList<SmsDataValue> values = new ArrayList<>();
    values.add(new SmsDataValue(categoryOptionCombo.getUid(), dataElement.getUid(), "true"));
    subm.setValues(values);
    subm.setSubmissionId(1);
    return subm;
}
Also used : GeoPoint(org.hisp.dhis.smscompression.models.GeoPoint) SimpleEventSmsSubmission(org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 2 with SmsDataValue

use of org.hisp.dhis.smscompression.models.SmsDataValue in project dhis2-core by dhis2.

the class TrackerEventSMSListenerTest method createTrackerEventSubmission.

private TrackerEventSmsSubmission createTrackerEventSubmission() {
    TrackerEventSmsSubmission subm = new TrackerEventSmsSubmission();
    subm.setUserId(user.getUid());
    subm.setOrgUnit(organisationUnit.getUid());
    subm.setProgramStage(programStage.getUid());
    subm.setAttributeOptionCombo(categoryOptionCombo.getUid());
    subm.setEnrollment(programInstance.getUid());
    subm.setEvent(programStageInstance.getUid());
    subm.setEventStatus(SmsEventStatus.COMPLETED);
    subm.setEventDate(new Date());
    subm.setDueDate(new Date());
    subm.setCoordinates(new GeoPoint(59.9399586f, 10.7195609f));
    ArrayList<SmsDataValue> values = new ArrayList<>();
    values.add(new SmsDataValue(categoryOptionCombo.getUid(), dataElement.getUid(), "10"));
    subm.setValues(values);
    subm.setSubmissionId(1);
    return subm;
}
Also used : GeoPoint(org.hisp.dhis.smscompression.models.GeoPoint) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) ArrayList(java.util.ArrayList) TrackerEventSmsSubmission(org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission) Date(java.util.Date)

Example 3 with SmsDataValue

use of org.hisp.dhis.smscompression.models.SmsDataValue in project dhis2-core by dhis2.

the class CompressionSMSListener method saveNewEvent.

protected List<Object> saveNewEvent(String eventUid, OrganisationUnit orgUnit, ProgramStage programStage, ProgramInstance programInstance, IncomingSms sms, CategoryOptionCombo aoc, User user, List<SmsDataValue> values, SmsEventStatus eventStatus, Date eventDate, Date dueDate, GeoPoint coordinates) {
    ArrayList<Object> errorUids = new ArrayList<>();
    ProgramStageInstance programStageInstance;
    if (programStageInstanceService.programStageInstanceExists(eventUid)) {
        programStageInstance = programStageInstanceService.getProgramStageInstance(eventUid);
    } else {
        programStageInstance = new ProgramStageInstance();
        programStageInstance.setUid(eventUid);
    }
    programStageInstance.setOrganisationUnit(orgUnit);
    programStageInstance.setProgramStage(programStage);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setExecutionDate(eventDate);
    programStageInstance.setDueDate(dueDate);
    programStageInstance.setAttributeOptionCombo(aoc);
    programStageInstance.setStoredBy(user.getUsername());
    UserInfoSnapshot currentUserInfo = UserInfoSnapshot.from(user);
    programStageInstance.setCreatedByUserInfo(currentUserInfo);
    programStageInstance.setLastUpdatedByUserInfo(currentUserInfo);
    programStageInstance.setStatus(getCoreEventStatus(eventStatus));
    programStageInstance.setGeometry(convertGeoPointToGeometry(coordinates));
    if (eventStatus.equals(SmsEventStatus.COMPLETED)) {
        programStageInstance.setCompletedBy(user.getUsername());
        programStageInstance.setCompletedDate(new Date());
    }
    Map<DataElement, EventDataValue> dataElementsAndEventDataValues = new HashMap<>();
    if (values != null) {
        for (SmsDataValue dv : values) {
            Uid deid = dv.getDataElement();
            String val = dv.getValue();
            DataElement de = dataElementService.getDataElement(deid.getUid());
            // TODO: Is this the correct way of handling errors here?
            if (de == null) {
                log.warn(String.format("Given data element [%s] could not be found. Continuing with submission...", deid));
                errorUids.add(deid);
                continue;
            } else if (val == null || StringUtils.isEmpty(val)) {
                log.warn(String.format("Value for atttribute [%s] is null or empty. Continuing with submission...", deid));
                continue;
            }
            EventDataValue eventDataValue = new EventDataValue(deid.getUid(), dv.getValue(), currentUserInfo);
            eventDataValue.setAutoFields();
            dataElementsAndEventDataValues.put(de, eventDataValue);
        }
    }
    programStageInstanceService.saveEventDataValuesAndSaveProgramStageInstance(programStageInstance, dataElementsAndEventDataValues);
    return errorUids;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) Uid(org.hisp.dhis.smscompression.models.Uid) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) UserInfoSnapshot(org.hisp.dhis.program.UserInfoSnapshot) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 4 with SmsDataValue

use of org.hisp.dhis.smscompression.models.SmsDataValue in project dhis2-core by dhis2.

the class AggregateDataSetSMSListener method submitDataValues.

private List<Object> submitDataValues(List<SmsDataValue> values, Period period, OrganisationUnit orgUnit, CategoryOptionCombo aoc, User user) {
    ArrayList<Object> errorElems = new ArrayList<>();
    if (values == null) {
        return errorElems;
    }
    for (SmsDataValue smsdv : values) {
        Uid deid = smsdv.getDataElement();
        Uid cocid = smsdv.getCategoryOptionCombo();
        String combid = deid + "-" + cocid;
        DataElement de = dataElementService.getDataElement(deid.getUid());
        if (de == null) {
            log.warn(String.format("Data element [%s] does not exist. Continuing with submission...", deid));
            errorElems.add(combid);
            continue;
        }
        CategoryOptionCombo coc = categoryService.getCategoryOptionCombo(cocid.getUid());
        if (coc == null) {
            log.warn(String.format("Category Option Combo [%s] does not exist. Continuing with submission...", cocid));
            errorElems.add(combid);
            continue;
        }
        String val = smsdv.getValue();
        if (val == null || StringUtils.isEmpty(val)) {
            log.warn(String.format("Value for [%s]  is null or empty. Continuing with submission...", combid));
            continue;
        }
        DataValue dv = dataValueService.getDataValue(de, period, orgUnit, coc, aoc);
        boolean newDataValue = false;
        if (dv == null) {
            dv = new DataValue();
            dv.setCategoryOptionCombo(coc);
            dv.setSource(orgUnit);
            dv.setDataElement(de);
            dv.setPeriod(period);
            dv.setComment("");
            newDataValue = true;
        }
        dv.setValue(val);
        dv.setLastUpdated(new java.util.Date());
        dv.setStoredBy(user.getUsername());
        if (newDataValue) {
            boolean addedDataValue = dataValueService.addDataValue(dv);
            if (!addedDataValue) {
                log.warn(String.format("Failed to submit data value [%s]. Continuing with submission...", combid));
                errorElems.add(combid);
            }
        } else {
            dataValueService.updateDataValue(dv);
        }
    }
    return errorElems;
}
Also used : Uid(org.hisp.dhis.smscompression.models.Uid) DataElement(org.hisp.dhis.dataelement.DataElement) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) Date(java.util.Date) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 5 with SmsDataValue

use of org.hisp.dhis.smscompression.models.SmsDataValue in project dhis2-core by dhis2.

the class EnrollmentSMSListenerTest method createEvent.

private SmsEvent createEvent() {
    SmsEvent event = new SmsEvent();
    event.setOrgUnit(organisationUnit.getUid());
    event.setProgramStage(programStage.getUid());
    event.setAttributeOptionCombo(categoryOptionCombo.getUid());
    event.setEvent(programStageInstance.getUid());
    event.setEventStatus(SmsEventStatus.COMPLETED);
    event.setEventDate(new Date());
    event.setDueDate(new Date());
    event.setCoordinates(new GeoPoint(59.9399586f, 10.7195609f));
    ArrayList<SmsDataValue> eventValues = new ArrayList<>();
    eventValues.add(new SmsDataValue(categoryOptionCombo.getUid(), dataElement.getUid(), "10"));
    event.setValues(eventValues);
    return event;
}
Also used : GeoPoint(org.hisp.dhis.smscompression.models.GeoPoint) SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) SmsEvent(org.hisp.dhis.smscompression.models.SmsEvent) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)6 SmsDataValue (org.hisp.dhis.smscompression.models.SmsDataValue)6 Date (java.util.Date)5 GeoPoint (org.hisp.dhis.smscompression.models.GeoPoint)3 DataElement (org.hisp.dhis.dataelement.DataElement)2 Uid (org.hisp.dhis.smscompression.models.Uid)2 HashMap (java.util.HashMap)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)1 UserInfoSnapshot (org.hisp.dhis.program.UserInfoSnapshot)1 AggregateDatasetSmsSubmission (org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission)1 SimpleEventSmsSubmission (org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission)1 SmsEvent (org.hisp.dhis.smscompression.models.SmsEvent)1 TrackerEventSmsSubmission (org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission)1