use of org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission 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;
}
use of org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission in project dhis2-core by dhis2.
the class SimpleEventSMSListener method postProcess.
@Override
protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission) throws SMSProcessingException {
SimpleEventSmsSubmission subm = (SimpleEventSmsSubmission) submission;
Uid ouid = subm.getOrgUnit();
Uid aocid = subm.getAttributeOptionCombo();
Uid progid = subm.getEventProgram();
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ouid.getUid());
User user = userService.getUser(subm.getUserId().getUid());
Program program = programService.getProgram(subm.getEventProgram().getUid());
if (program == null) {
throw new SMSProcessingException(SmsResponse.INVALID_PROGRAM.set(progid));
}
CategoryOptionCombo aoc = categoryService.getCategoryOptionCombo(aocid.getUid());
if (aoc == null) {
throw new SMSProcessingException(SmsResponse.INVALID_AOC.set(aocid));
}
if (!programService.hasOrgUnit(program, orgUnit)) {
throw new SMSProcessingException(SmsResponse.OU_NOTIN_PROGRAM.set(ouid, progid));
}
List<ProgramInstance> programInstances = new ArrayList<>(programInstanceService.getProgramInstances(program, ProgramStatus.ACTIVE));
// If it doesn't exist, this is the first event, we can create it here
if (programInstances.isEmpty()) {
ProgramInstance pi = new ProgramInstance();
pi.setEnrollmentDate(new Date());
pi.setIncidentDate(new Date());
pi.setProgram(program);
pi.setStatus(ProgramStatus.ACTIVE);
programInstanceService.addProgramInstance(pi);
programInstances.add(pi);
} else if (programInstances.size() > 1) {
// TODO: Are we sure this is a problem we can't recover from?
throw new SMSProcessingException(SmsResponse.MULTI_PROGRAMS.set(progid));
}
ProgramInstance programInstance = programInstances.get(0);
Set<ProgramStage> programStages = programInstance.getProgram().getProgramStages();
if (programStages.size() > 1) {
throw new SMSProcessingException(SmsResponse.MULTI_STAGES.set(progid));
}
ProgramStage programStage = programStages.iterator().next();
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.SimpleEventSmsSubmission in project dhis2-core by dhis2.
the class SimpleEventSMSListenerTest method createSimpleEventSubmissionWithNulls.
private SimpleEventSmsSubmission createSimpleEventSubmissionWithNulls() {
SimpleEventSmsSubmission subm = createSimpleEventSubmission();
subm.setEventDate(null);
subm.setDueDate(null);
subm.setCoordinates(null);
return subm;
}
use of org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission in project dhis2-core by dhis2.
the class SimpleEventSMSListenerTest method createSimpleEventSubmissionNoValues.
private SimpleEventSmsSubmission createSimpleEventSubmissionNoValues() {
SimpleEventSmsSubmission subm = createSimpleEventSubmission();
subm.setValues(null);
return subm;
}
Aggregations