Search in sources :

Example 1 with TrackerEventSmsSubmission

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

the class TrackerEventSMSListener method postProcess.

@Override
protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission) throws SMSProcessingException {
    TrackerEventSmsSubmission subm = (TrackerEventSmsSubmission) submission;
    Uid ouid = subm.getOrgUnit();
    Uid stageid = subm.getProgramStage();
    Uid enrolmentid = subm.getEnrollment();
    Uid aocid = subm.getAttributeOptionCombo();
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ouid.getUid());
    User user = userService.getUser(subm.getUserId().getUid());
    ProgramInstance programInstance = programInstanceService.getProgramInstance(enrolmentid.getUid());
    if (programInstance == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_ENROLL.set(enrolmentid));
    }
    ProgramStage programStage = programStageService.getProgramStage(stageid.getUid());
    if (programStage == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_STAGE.set(stageid));
    }
    CategoryOptionCombo aoc = categoryService.getCategoryOptionCombo(aocid.getUid());
    if (aoc == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_AOC.set(aocid));
    }
    List<Object> errorUIDs = saveNewEvent(subm.getEvent().getUid(), orgUnit, programStage, programInstance, sms, aoc, user, subm.getValues(), subm.getEventStatus(), subm.getEventDate(), subm.getDueDate(), subm.getCoordinates());
    if (!errorUIDs.isEmpty()) {
        return SmsResponse.WARN_DVERR.setList(errorUIDs);
    } else if (subm.getValues() == null || subm.getValues().isEmpty()) {
        // TODO: Should we save the event if there are no data values?
        return SmsResponse.WARN_DVEMPTY;
    }
    return SmsResponse.SUCCESS;
}
Also used : Uid(org.hisp.dhis.smscompression.models.Uid) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerEventSmsSubmission(org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission) ProgramStage(org.hisp.dhis.program.ProgramStage) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 2 with TrackerEventSmsSubmission

use of org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission 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 TrackerEventSmsSubmission

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

the class TrackerEventSMSListenerTest method createTrackerEventSubmissionWithNulls.

private TrackerEventSmsSubmission createTrackerEventSubmissionWithNulls() {
    TrackerEventSmsSubmission subm = createTrackerEventSubmission();
    subm.setEventDate(null);
    subm.setDueDate(null);
    subm.setCoordinates(null);
    return subm;
}
Also used : TrackerEventSmsSubmission(org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission)

Example 4 with TrackerEventSmsSubmission

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

the class TrackerEventSMSListenerTest method createTrackerEventSubmissionNoValues.

private TrackerEventSmsSubmission createTrackerEventSubmissionNoValues() {
    TrackerEventSmsSubmission subm = createTrackerEventSubmission();
    subm.setValues(null);
    return subm;
}
Also used : TrackerEventSmsSubmission(org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission)

Aggregations

TrackerEventSmsSubmission (org.hisp.dhis.smscompression.models.TrackerEventSmsSubmission)4 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 GeoPoint (org.hisp.dhis.smscompression.models.GeoPoint)1 SmsDataValue (org.hisp.dhis.smscompression.models.SmsDataValue)1 Uid (org.hisp.dhis.smscompression.models.Uid)1 User (org.hisp.dhis.user.User)1