Search in sources :

Example 1 with SimpleEventSmsSubmission

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

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ArrayList(java.util.ArrayList) Date(java.util.Date) Uid(org.hisp.dhis.smscompression.models.Uid) SimpleEventSmsSubmission(org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission) ProgramStage(org.hisp.dhis.program.ProgramStage) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 3 with SimpleEventSmsSubmission

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;
}
Also used : SimpleEventSmsSubmission(org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission)

Example 4 with SimpleEventSmsSubmission

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;
}
Also used : SimpleEventSmsSubmission(org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission)

Aggregations

SimpleEventSmsSubmission (org.hisp.dhis.smscompression.models.SimpleEventSmsSubmission)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)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