Search in sources :

Example 6 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class TrackerEntityInstanceStrategyTest method verifyStrategyIgnoresPersistedTei.

@Test
void verifyStrategyIgnoresPersistedTei() {
    // Create preheat params
    final List<TrackedEntity> trackedEntities = rnd.objects(TrackedEntity.class, 2).collect(Collectors.toList());
    final TrackerImportParams params = TrackerImportParams.builder().trackedEntities(trackedEntities).build();
    // Preheat
    User user = new User();
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.setUser(user);
    final List<String> rootUids = trackedEntities.stream().map(TrackedEntity::getTrackedEntity).collect(Collectors.toList());
    // Add uid of non-root tei
    rootUids.add("noroottei");
    List<List<String>> uids = new ArrayList<>();
    uids.add(rootUids);
    when(trackedEntityInstanceStore.getIncludingDeleted(rootUids)).thenReturn(Lists.newArrayList(new TrackedEntityInstance() {

        {
            setUid(trackedEntities.get(0).getTrackedEntity());
        }
    }));
    // when
    strategy.add(params, uids, preheat);
    preheat.createReferenceTree();
    assertFalse(preheat.getReference(trackedEntities.get(0).getTrackedEntity()).isPresent());
    assertTrue(preheat.getReference(trackedEntities.get(1).getTrackedEntity()).isPresent());
    assertFalse(preheat.getReference("noroottei").isPresent());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) User(org.hisp.dhis.user.User) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ArrayList(java.util.ArrayList) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ArrayList(java.util.ArrayList) List(java.util.List) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 7 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class DuplicateRelationshipsPreProcessorTest method setUp.

@BeforeEach
void setUp() {
    preheat = new TrackerPreheat();
    RelationshipType relationshipTypeBidirectional = new RelationshipType();
    relationshipTypeBidirectional.setUid(REL_TYPE_BIDIRECTIONAL_UID);
    relationshipTypeBidirectional.setBidirectional(true);
    RelationshipType relationshipTypeNonBidirectional = new RelationshipType();
    relationshipTypeNonBidirectional.setUid(REL_TYPE_NONBIDIRECTIONAL_UID);
    preheat.put(TrackerIdentifier.UID, relationshipTypeBidirectional);
    preheat.put(TrackerIdentifier.UID, relationshipTypeNonBidirectional);
    this.preProcessor = new DuplicateRelationshipsPreProcessor();
}
Also used : RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration.

@Test
void testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration() {
    // Given
    Event event = new Event();
    event.setProgramStage("programStageUid");
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid("programInstanceUid");
    Program program = new Program();
    program.setUid("programUid");
    ProgramStage programStage = new ProgramStage();
    programStage.setUid("programStageUid");
    programStage.setProgram(program);
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
    preheat.put(TrackerIdentifier.UID, programStage);
    bundle.setPreheat(preheat);
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertEquals("programInstanceUid", bundle.getEvents().get(0).getEnrollment());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 9 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram.

@Test
void testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram() {
    // Given
    Event event = new Event();
    event.setProgramStage("programStageUid");
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid("programInstanceUid");
    Program program = new Program();
    program.setUid("programUid");
    ProgramStage programStage = new ProgramStage();
    programStage.setUid("programStageUid");
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
    preheat.put(TrackerIdentifier.UID, programStage);
    bundle.setPreheat(preheat);
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertNull(bundle.getEvents().get(0).getEnrollment(), "programInstanceUid");
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 10 with TrackerPreheat

use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.

the class UniqueAttributesSupplier method getEntityForEnrollment.

private TrackedEntity getEntityForEnrollment(TrackerImportParams params, TrackerPreheat preheat, String teiUid) {
    TrackedEntityInstance trackedEntity = preheat.getTrackedEntity(TrackerIdScheme.UID, teiUid);
    // Get tei from Preheat
    Optional<TrackedEntity> optionalTei = params.getTrackedEntities().stream().filter(tei -> Objects.equals(tei.getTrackedEntity(), teiUid)).findAny();
    if (optionalTei.isPresent()) {
        return optionalTei.get();
    } else if (// Otherwise build it from Payload
    trackedEntity != null) {
        TrackedEntity tei = new TrackedEntity();
        tei.setTrackedEntity(teiUid);
        tei.setOrgUnit(trackedEntity.getOrganisationUnit().getUid());
        return tei;
    } else // TEI is not present. but we do not fail here.
    // A validation error will be thrown in validation phase
    {
        TrackedEntity tei = new TrackedEntity();
        tei.setTrackedEntity(teiUid);
        return tei;
    }
}
Also used : TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Attribute(org.hisp.dhis.tracker.domain.Attribute) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Function(java.util.function.Function) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) Lists(com.google.common.collect.Lists) Collectors.toMap(java.util.stream.Collectors.toMap) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) TrackerIdScheme(org.hisp.dhis.tracker.TrackerIdScheme) NonNull(lombok.NonNull) UniqueAttributeValue(org.hisp.dhis.tracker.preheat.UniqueAttributeValue) Collection(java.util.Collection) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Objects(java.util.Objects) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Optional(java.util.Optional) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Aggregations

TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)33 Test (org.junit.jupiter.api.Test)17 List (java.util.List)11 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)10 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)10 Event (org.hisp.dhis.tracker.domain.Event)9 Collectors (java.util.stream.Collectors)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Optional (java.util.Optional)6 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)6 ProgramStage (org.hisp.dhis.program.ProgramStage)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 Component (org.springframework.stereotype.Component)5 Lists (com.google.common.collect.Lists)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 RequiredArgsConstructor (lombok.RequiredArgsConstructor)4 Program (org.hisp.dhis.program.Program)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4