use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.
the class AssignValueImplementer method isTheSameValue.
private boolean isTheSameValue(EventActionRule actionRule, TrackerPreheat preheat) {
DataElement dataElement = preheat.get(DataElement.class, actionRule.getField());
String dataValue = actionRule.getValue();
Optional<DataValue> optionalDataValue = actionRule.getDataValues().stream().filter(dv -> dv.getDataElement().equals(actionRule.getField())).findAny();
if (optionalDataValue.isPresent()) {
return areEquals(dataValue, optionalDataValue.get().getValue(), dataElement.getValueType());
}
return false;
}
use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.
the class TrackerPreheatIdentifiersTest method testDataElementIdentifiers.
@Test
void testDataElementIdentifiers() {
List<Pair<String, TrackerIdentifier>> data = buildDataSet("DSKTW8qFP0z", "DEAGE", "DE Age");
for (Pair<String, TrackerIdentifier> pair : data) {
Event event = new Event();
event.setProgramStage("NpsdDv6kKSO");
DataValue dv1 = new DataValue();
dv1.setDataElement(pair.getLeft());
dv1.setValue("val1");
event.setDataValues(Collections.singleton(dv1));
TrackerImportParams params = buildParams(event, builder().dataElementIdScheme(pair.getRight()).build());
TrackerPreheat preheat = trackerPreheatService.preheat(params);
assertPreheatedObjectExists(preheat, DataElement.class, pair.getRight(), pair.getLeft());
}
}
use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method dataValue.
private DataValue dataValue(String dataElement, String value) {
DataValue dataValue = new DataValue();
dataValue.setDataElement(dataElement);
dataValue.setValue(value);
dataValue.setProvidedElsewhere(true);
dataValue.setCreatedBy(USERNAME);
dataValue.setLastUpdatedBy(USERNAME);
dataValue.setCreatedAt(Instant.now());
dataValue.setStoredBy(USERNAME);
dataValue.setUpdatedAt(Instant.now());
return dataValue;
}
use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method testToProgramStageInstance.
@Test
void testToProgramStageInstance() {
setUpMocks();
DataElement dataElement = new DataElement();
dataElement.setUid(CodeGenerator.generateUid());
when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
DataValue dataValue = new DataValue();
dataValue.setValue("value");
dataValue.setCreatedBy(USERNAME);
dataValue.setLastUpdatedBy(USERNAME);
dataValue.setCreatedAt(Instant.now());
dataValue.setStoredBy(USERNAME);
dataValue.setUpdatedAt(Instant.now());
dataValue.setDataElement(dataElement.getUid());
Event event = event(dataValue);
ProgramStageInstance programStageInstance = converter.from(preheat, event);
assertNotNull(programStageInstance);
assertNotNull(programStageInstance.getProgramStage());
assertNotNull(programStageInstance.getProgramStage().getProgram());
assertNotNull(programStageInstance.getOrganisationUnit());
assertEquals(PROGRAM_UID, programStageInstance.getProgramStage().getProgram().getUid());
assertEquals(PROGRAM_STAGE_UID, programStageInstance.getProgramStage().getUid());
assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
Set<EventDataValue> eventDataValues = programStageInstance.getEventDataValues();
eventDataValues.forEach(e -> {
assertEquals(USERNAME, e.getCreatedByUserInfo().getUsername());
assertEquals(USERNAME, e.getLastUpdatedByUserInfo().getUsername());
});
}
use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeCode.
@Test
void fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeCode() {
// NTI supports multiple idSchemes. Event.dataElement can thus be any of
// the supported ones
// UID, CODE, ATTRIBUTE, NAME
// merging existing & new data values on events needs to respect the
// user configured idScheme
setUpMocks();
DataElement dataElement = new DataElement();
dataElement.setUid(CodeGenerator.generateUid());
dataElement.setCode("DE_424050");
when(preheat.get(DataElement.class, dataElement.getCode())).thenReturn(dataElement);
ProgramStageInstance existingPsi = programStageInstance();
existingPsi.setEventDataValues(Set.of(eventDataValue(dataElement.getUid(), "658")));
// dataElement is of idScheme CODE if the NTI dataElementIdScheme is set
// to CODE
DataValue updatedValue = dataValue(dataElement.getCode(), "900");
Event event = event(existingPsi.getUid(), updatedValue);
when(preheat.getEvent(TrackerIdScheme.UID, event.getEvent())).thenReturn(existingPsi);
ProgramStageInstance programStageInstance = converter.fromForRuleEngine(preheat, event);
assertEquals(1, programStageInstance.getEventDataValues().size());
EventDataValue expect1 = new EventDataValue();
expect1.setDataElement(dataElement.getUid());
expect1.setValue(updatedValue.getValue());
assertContainsOnly(programStageInstance.getEventDataValues(), expect1);
}
Aggregations