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