Search in sources :

Example 51 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class HandleRelationshipsTrackedEntityInstanceServiceTest method createTeiToTeiRelationship.

private Relationship createTeiToTeiRelationship(char key, RelationshipType relationshipType, TrackedEntityInstance trackedEntityInstanceA, TrackedEntityInstance trackedEntityInstanceB) {
    RelationshipItem relationshipItemTeiA = new RelationshipItem();
    relationshipItemTeiA.setTrackedEntityInstance(trackedEntityInstanceA);
    RelationshipItem relationshipItemTeiB = new RelationshipItem();
    relationshipItemTeiB.setTrackedEntityInstance(trackedEntityInstanceB);
    Relationship relationship = new Relationship();
    relationship.setFrom(relationshipItemTeiA);
    relationship.setTo(relationshipItemTeiB);
    relationship.setRelationshipType(relationshipType.getUid());
    relationship.setRelationship("UID_" + key);
    relationship.setRelationshipName("Person to person");
    relationship.setBidirectional(relationshipType.isBidirectional());
    return relationship;
}
Also used : Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) RelationshipItem(org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem)

Example 52 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class ProgramInstancePreProcessorTest method verifyEnrollmentIsNotSetOnEventWhenMultipleProgramInstanceAreFound.

@Test
void verifyEnrollmentIsNotSetOnEventWhenMultipleProgramInstanceAreFound() {
    // 
    // Tracked Entity Instance
    // 
    TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
    Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
    teiMap.put(event.getUid(), Pair.of(tei, true));
    when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
    ProgramInstance programInstance1 = new ProgramInstance();
    ProgramInstance programInstance2 = new ProgramInstance();
    when(programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
    event.setProgram(program.getUid());
    subject.process(event, workContext);
    assertThat(event.getEnrollment(), is(nullValue()));
    assertThat(programInstanceMap.get(event.getUid()), is(nullValue()));
}
Also used : HashMap(java.util.HashMap) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) BasePreProcessTest(org.hisp.dhis.dxf2.events.importer.BasePreProcessTest) Test(org.junit.jupiter.api.Test)

Example 53 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackerTest method createEnrollmentWithEvents.

private Enrollment createEnrollmentWithEvents(Program program, TrackedEntityInstance trackedEntityInstance, int events) {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setOrgUnit(organisationUnitA.getUid());
    enrollment.setProgram(program.getUid());
    enrollment.setTrackedEntityInstance(trackedEntityInstance.getUid());
    enrollment.setEnrollmentDate(new Date());
    enrollment.setStatus(EnrollmentStatus.COMPLETED);
    enrollment.setIncidentDate(new Date());
    enrollment.setCompletedDate(new Date());
    enrollment.setCompletedBy("hello-world");
    if (events > 0) {
        List<Event> eventList = new ArrayList<>();
        String now = DateUtils.getIso8601NoTz(new Date());
        for (int i = 0; i < events; i++) {
            Event event1 = new Event();
            event1.setEnrollment(enrollment.getEnrollment());
            event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
            event1.setProgram(programA.getUid());
            event1.setProgramStage(programStageA1.getUid());
            event1.setStatus(EventStatus.COMPLETED);
            event1.setTrackedEntityInstance(trackedEntityInstance.getUid());
            event1.setOrgUnit(organisationUnitA.getUid());
            event1.setAttributeOptionCombo(DEF_COC_UID);
            event1.setCreatedAtClient(now);
            event1.setLastUpdatedAtClient(now);
            event1.setCompletedDate(now);
            event1.setCompletedBy("[Unknown]");
            eventList.add(event1);
        }
        enrollment.setEvents(eventList);
    }
    return enrollment;
}
Also used : ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Date(java.util.Date)

Example 54 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeSpecificProtectedProgram.

@Test
void testTrackedEntityInstanceIncludeSpecificProtectedProgram() {
    populatePrerequisites(false);
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setProgram(programB);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "E");
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 55 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceAttributesAggregateTest method testTrackedEntityInstanceIncludeAllAttributes.

@Test
void testTrackedEntityInstanceIncludeAllAttributes() {
    populatePrerequisites(false);
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertAttributes(trackedEntityInstances.get(0).getAttributes(), "A", "B", "C", "E");
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Aggregations

TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)61 Test (org.junit.jupiter.api.Test)57 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)50 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)37 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)34 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)29 Date (java.util.Date)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)26 ArrayList (java.util.ArrayList)25 List (java.util.List)25 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)25 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)24 Event (org.hisp.dhis.dxf2.events.event.Event)23 Program (org.hisp.dhis.program.Program)22 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Collectors (java.util.stream.Collectors)19 User (org.hisp.dhis.user.User)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)16 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)16