Search in sources :

Example 66 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class TrackerImporterServiceTest method setUp.

@BeforeEach
public void setUp() {
    subject = new DefaultTrackerImportService(trackerBundleService, trackerValidationService, trackerPreprocessService, trackerUserService, notifier);
    final List<Event> events = rnd.objects(Event.class, 3).collect(Collectors.toList());
    params = TrackerImportParams.builder().events(events).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).userId("123").build();
    TrackerBundleReport trackerBundleReport = TrackerBundleReport.builder().build();
    when(trackerUserService.getUser(anyString())).thenReturn(getUser());
    when(trackerBundleService.commit(any(TrackerBundle.class))).thenReturn(trackerBundleReport);
    when(trackerValidationService.validate(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
    when(trackerValidationService.validateRuleEngine(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
    when(trackerPreprocessService.preprocess(any(TrackerBundle.class))).thenReturn(ParamsConverter.convert(params));
}
Also used : TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) DefaultTrackerImportService(org.hisp.dhis.tracker.DefaultTrackerImportService) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 67 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class RepeatedEventsValidationHook method validate.

@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
    TrackerBundle bundle = context.getBundle();
    Map<Pair<String, String>, List<Event>> eventsByEnrollmentAndNotRepeatableProgramStage = bundle.getEvents().stream().filter(e -> !reporter.isInvalid(e)).filter(e -> !context.getStrategy(e).isDelete()).filter(e -> {
        ProgramStage programStage = context.getProgramStage(e.getProgramStage());
        return programStage.getProgram().isRegistration() && !programStage.getRepeatable();
    }).collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment())));
    for (Map.Entry<Pair<String, String>, List<Event>> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) {
        if (mapEntry.getValue().size() > 1) {
            for (Event event : mapEntry.getValue()) {
                reporter.addError(event, TrackerErrorCode.E1039, mapEntry.getKey().getLeft());
            }
        }
    }
    bundle.getEvents().forEach(e -> validateNotMultipleEvents(reporter, context, e));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Map(java.util.Map) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Example 68 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventTrackerConverterServiceTest method event.

private Event event(String uid, DataValue dataValue) {
    Event event = new Event();
    event.setEvent(uid);
    event.setProgramStage(PROGRAM_STAGE_UID);
    event.setProgram(PROGRAM_UID);
    event.setOrgUnit(ORGANISATION_UNIT_UID);
    event.setDataValues(Sets.newHashSet(dataValue));
    return event;
}
Also used : Event(org.hisp.dhis.tracker.domain.Event)

Example 69 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventTrackerConverterServiceTest method fromForRuleEngineGivenNewEvent.

@Test
void fromForRuleEngineGivenNewEvent() {
    setUpMocks();
    DataElement dataElement = new DataElement();
    dataElement.setUid(CodeGenerator.generateUid());
    when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
    DataValue dataValue = dataValue(dataElement.getUid(), "900");
    Event event = event(dataValue);
    ProgramStageInstance programStageInstance = converter.fromForRuleEngine(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());
    assertEquals(1, programStageInstance.getEventDataValues().size());
    EventDataValue actual = programStageInstance.getEventDataValues().stream().findFirst().get();
    assertEquals(dataValue.getDataElement(), actual.getDataElement());
    assertEquals(dataValue.getValue(), actual.getValue());
    assertTrue(actual.getProvidedElsewhere());
    assertEquals(USERNAME, actual.getCreatedByUserInfo().getUsername());
    assertEquals(USERNAME, actual.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 70 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventTrackerConverterServiceTest method fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeUID.

@Test
void fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeUID() {
    setUpMocks();
    DataElement dataElement = new DataElement();
    dataElement.setUid(CodeGenerator.generateUid());
    when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
    ProgramStageInstance existingPsi = programStageInstance();
    existingPsi.setEventDataValues(Set.of(eventDataValue(dataElement.getUid(), "658")));
    // dataElement is of idScheme UID if the NTI dataElementIdScheme is set
    // to UID
    DataValue updatedValue = dataValue(dataElement.getUid(), "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(updatedValue.getDataElement());
    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

Event (org.hisp.dhis.tracker.domain.Event)192 Test (org.junit.jupiter.api.Test)153 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)114 ProgramStage (org.hisp.dhis.program.ProgramStage)68 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)64 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)53 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)43 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)41 Mockito.when (org.mockito.Mockito.when)38 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)37 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)36 DataElement (org.hisp.dhis.dataelement.DataElement)35 Program (org.hisp.dhis.program.Program)35 ProgramInstance (org.hisp.dhis.program.ProgramInstance)35 DataValue (org.hisp.dhis.tracker.domain.DataValue)35 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)35 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)34 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)33 CodeGenerator (org.hisp.dhis.common.CodeGenerator)32 BeforeEach (org.junit.jupiter.api.BeforeEach)32