Search in sources :

Example 21 with DataValue

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;
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Map(java.util.Map) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) EventActionRule(org.hisp.dhis.tracker.programrule.EventActionRule) EnrollmentActionRule(org.hisp.dhis.tracker.programrule.EnrollmentActionRule) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Sets(com.google.common.collect.Sets) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) IssueType(org.hisp.dhis.tracker.programrule.IssueType) SettingKey(org.hisp.dhis.setting.SettingKey) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue)

Example 22 with DataValue

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());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 23 with DataValue

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;
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue)

Example 24 with 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());
    });
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Event(org.hisp.dhis.tracker.domain.Event) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 25 with DataValue

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Event(org.hisp.dhis.tracker.domain.Event) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DataValue (org.hisp.dhis.tracker.domain.DataValue)45 Event (org.hisp.dhis.tracker.domain.Event)35 DataElement (org.hisp.dhis.dataelement.DataElement)33 Test (org.junit.jupiter.api.Test)29 ProgramStage (org.hisp.dhis.program.ProgramStage)26 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)10 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)9 Lists (com.google.common.collect.Lists)6 Sets (com.google.common.collect.Sets)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Set (java.util.Set)6 ValueType (org.hisp.dhis.common.ValueType)6 EventStatus (org.hisp.dhis.event.EventStatus)6 RuleActionAssign (org.hisp.dhis.rules.models.RuleActionAssign)6 SettingKey (org.hisp.dhis.setting.SettingKey)6 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)6