use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method eventDataValue.
private EventDataValue eventDataValue(String dataElement, String value) {
EventDataValue eventDataValue = new EventDataValue();
eventDataValue.setDataElement(dataElement);
eventDataValue.setValue(value);
return eventDataValue;
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class JsonEventDataValueSetBinaryType method convertEventDataValuesMapIntoSet.
public static Set<EventDataValue> convertEventDataValuesMapIntoSet(Map<String, EventDataValue> data) {
Set<EventDataValue> eventDataValues = new HashSet<>();
for (Map.Entry<String, EventDataValue> entry : data.entrySet()) {
EventDataValue eventDataValue = entry.getValue();
eventDataValue.setDataElement(entry.getKey());
eventDataValues.add(eventDataValue);
}
return eventDataValues;
}
use of org.hisp.dhis.eventdatavalue.EventDataValue 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.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class TrackedEntityDataValueAuditStoreTest method setUpTest.
@Override
public void setUpTest() {
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
Program program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
ProgramStage stageA = new ProgramStage("StageA", program);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
ProgramStage stageB = new ProgramStage("StageB", program);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
program.setProgramStages(programStages);
programService.updateProgram(program);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
TrackedEntityInstance entityInstance = createTrackedEntityInstance(organisationUnit);
entityInstanceService.addTrackedEntityInstance(entityInstance);
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, new Date(), new Date(), organisationUnit);
stageInstance = programStageInstanceService.createProgramStageInstance(programInstance, stageA, new Date(), new Date(), organisationUnit);
dataValueA = new EventDataValue(dataElementA.getUid(), "1", UserInfoTestHelper.testUserInfo("test-user"));
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class ProgramNotificationMessageRendererTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
Date incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
Date enrollmentDate = testDate2.toDate();
dataElementA = createDataElement('A', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
dataElementA.setUid(dataElementUid);
dataElementB = createDataElement('B', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
dataElementB.setUid("DEB-UID");
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
trackedEntityAttributeA = createTrackedEntityAttribute('A');
trackedEntityAttributeA.setUid(trackedEntityAttributeUid);
trackedEntityAttributeB = createTrackedEntityAttribute('B');
attributeService.addTrackedEntityAttribute(trackedEntityAttributeA);
attributeService.addTrackedEntityAttribute(trackedEntityAttributeB);
organisationUnitA = createOrganisationUnit('A');
organisationUnitA.setUid(orgUnitUid);
organisationUnitService.addOrganisationUnit(organisationUnitA);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setUid(programUid);
programService.addProgram(programA);
programTrackedEntityAttributeA = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeA);
programTrackedEntityAttributeB = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeB);
programTrackedEntityAttributeStore.save(programTrackedEntityAttributeA);
programTrackedEntityAttributeStore.save(programTrackedEntityAttributeB);
programA.setProgramAttributes(Arrays.asList(programTrackedEntityAttributeA, programTrackedEntityAttributeB));
programService.updateProgram(programA);
programStageA = createProgramStage('A', programA);
programStageA.setUid(programStageUid);
programStageService.saveProgramStage(programStageA);
programStageDataElementA = createProgramStageDataElement(programStageA, dataElementA, 1);
programStageDataElementB = createProgramStageDataElement(programStageA, dataElementB, 2);
programStageDataElementService.addProgramStageDataElement(programStageDataElementA);
programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
programStageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA, programStageDataElementB));
programStageService.updateProgramStage(programStageA);
programA.setProgramStages(Sets.newHashSet(programStageA));
programService.updateProgram(programA);
trackedEntityInstanceA = createTrackedEntityInstance(organisationUnitA);
trackedEntityInstanceA.setUid(trackedEntityUid);
entityInstanceService.addTrackedEntityInstance(trackedEntityInstanceA);
trackedEntityAttributeValueA = new TrackedEntityAttributeValue(trackedEntityAttributeA, trackedEntityInstanceA, "attribute-test");
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(trackedEntityAttributeValueA);
trackedEntityInstanceA.setTrackedEntityAttributeValues(Sets.newHashSet(trackedEntityAttributeValueA));
entityInstanceService.updateTrackedEntityInstance(trackedEntityInstanceA);
// ProgramInstance to be provided in message renderer
programInstanceA = programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceA, programA, enrollmentDate, incidentDate, organisationUnitA);
programInstanceA.setUid(enrollmentUid);
programInstanceService.updateProgramInstance(programInstanceA);
// ProgramStageInstance to be provided in message renderer
programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA);
programStageInstanceA.setOrganisationUnit(organisationUnitA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setExecutionDate(new Date());
programStageInstanceA.setUid("PSI-UID");
eventDataValueA = new EventDataValue();
eventDataValueA.setDataElement(dataElementA.getUid());
eventDataValueA.setAutoFields();
eventDataValueA.setValue("dataElementA-Text");
eventDataValueB = new EventDataValue();
eventDataValueB.setDataElement(dataElementB.getUid());
eventDataValueB.setAutoFields();
eventDataValueB.setValue("dataElementB-Text");
programStageInstanceA.setEventDataValues(Sets.newHashSet(eventDataValueA, eventDataValueB));
programStageInstanceService.addProgramStageInstance(programStageInstanceA);
programInstanceA.getProgramStageInstances().add(programStageInstanceA);
programInstanceService.updateProgramInstance(programInstanceA);
programNotificationTemplate = new ProgramNotificationTemplate();
programNotificationTemplate.setName("Test-PNT");
programNotificationTemplate.setMessageTemplate("message_template");
programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
programNotificationTemplate.setSubjectTemplate("subject_template");
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.PROGRAM_RULE);
programNotificationTemplate.setAutoFields();
programNotificationTemplate.setUid("PNT-1");
programNotificationTemplateStore.save(programNotificationTemplate);
}
Aggregations