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;
}
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;
}
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;
}
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;
}
Aggregations