Search in sources :

Example 1 with TrackedEntityInstanceParams

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

the class AbstractEnrollmentService method getEnrollment.

@Override
public Enrollment getEnrollment(ProgramInstance programInstance, TrackedEntityInstanceParams params) {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(programInstance.getUid());
    if (programInstance.getEntityInstance() != null) {
        enrollment.setTrackedEntity(programInstance.getEntityInstance().getTrackedEntity().getUid());
        enrollment.setTrackedEntityInstance(programInstance.getEntityInstance().getUid());
    }
    if (programInstance.getOrganisationUnit() != null) {
        enrollment.setOrgUnit(programInstance.getOrganisationUnit().getUid());
        enrollment.setOrgUnitName(programInstance.getOrganisationUnit().getName());
    }
    if (programInstance.getProgram().getCaptureCoordinates()) {
        Coordinate coordinate = null;
        if (programInstance.getLongitude() != null && programInstance.getLatitude() != null) {
            coordinate = new Coordinate(programInstance.getLongitude(), programInstance.getLatitude());
            try {
                List<Double> list = OBJECT_MAPPER.readValue(coordinate.getCoordinateString(), new TypeReference<List<Double>>() {
                });
                coordinate.setLongitude(list.get(0));
                coordinate.setLatitude(list.get(1));
            } catch (IOException ignored) {
            }
        }
        if (coordinate != null && coordinate.isValid()) {
            enrollment.setCoordinate(coordinate);
        }
    }
    enrollment.setCreated(DateUtils.getIso8601NoTz(programInstance.getCreated()));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(programInstance.getCreatedAtClient()));
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(programInstance.getLastUpdated()));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programInstance.getLastUpdatedAtClient()));
    enrollment.setProgram(programInstance.getProgram().getUid());
    enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
    enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
    enrollment.setIncidentDate(programInstance.getIncidentDate());
    enrollment.setFollowup(programInstance.getFollowup());
    enrollment.setCompletedDate(programInstance.getEndDate());
    enrollment.setCompletedBy(programInstance.getCompletedBy());
    List<TrackedEntityComment> comments = programInstance.getComments();
    for (TrackedEntityComment comment : comments) {
        Note note = new Note();
        note.setValue(comment.getCommentText());
        note.setStoredBy(comment.getCreator());
        if (comment.getCreatedDate() != null) {
            note.setStoredDate(comment.getCreatedDate().toString());
        }
        enrollment.getNotes().add(note);
    }
    if (params.isIncludeEvents()) {
        for (ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances()) {
            enrollment.getEvents().add(eventService.getEvent(programStageInstance));
        }
    }
    return enrollment;
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Coordinate(org.hisp.dhis.dxf2.events.event.Coordinate) Note(org.hisp.dhis.dxf2.events.event.Note) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 2 with TrackedEntityInstanceParams

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

the class AbstractRelationshipService method includeRelationshipItem.

private org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem includeRelationshipItem(RelationshipItem dao, boolean uidOnly) {
    TrackedEntityInstanceParams teiParams = TrackedEntityInstanceParams.FALSE;
    org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem relationshipItem = new org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem();
    if (dao.getTrackedEntityInstance() != null) {
        org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance tei = new org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance();
        String uid = dao.getTrackedEntityInstance().getUid();
        if (uidOnly) {
            tei.clear();
            tei.setTrackedEntityInstance(uid);
        } else {
            tei = trackedEntityInstanceService.getTrackedEntityInstance(dao.getTrackedEntityInstance(), teiParams);
        }
        relationshipItem.setTrackedEntityInstance(tei);
    } else if (dao.getProgramInstance() != null) {
        Enrollment enrollment = new Enrollment();
        String uid = dao.getProgramInstance().getUid();
        if (uidOnly) {
            enrollment.clear();
            enrollment.setEnrollment(uid);
        } else {
            enrollment = enrollmentService.getEnrollment(dao.getProgramInstance(), teiParams);
        }
        relationshipItem.setEnrollment(enrollment);
    } else if (dao.getProgramStageInstance() != null) {
        Event event = new Event();
        String uid = dao.getProgramStageInstance().getUid();
        if (uidOnly) {
            event.clear();
            event.setEvent(uid);
        } else {
            event = eventService.getEvent(dao.getProgramStageInstance());
            event.setRelationships(null);
        }
        relationshipItem.setEvent(event);
    }
    return relationshipItem;
}
Also used : TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 3 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithEvents.

@Test
void testFetchTrackedEntityInstancesWithEvents() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(5));
    assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), hasSize(5));
}
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 4 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEvents.

@Test
void testFetchTrackedEntityInstancesWithoutEvents() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(false);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
    assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), hasSize(0));
}
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 5 with TrackedEntityInstanceParams

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

the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEnrollments.

@Test
void testFetchTrackedEntityInstancesWithoutEnrollments() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
        this.persistTrackedEntityInstanceWithEnrollment();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(false);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    assertThat(trackedEntityInstances, hasSize(4));
    assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(0));
    assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(0));
}
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

TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)30 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)26 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)24 Test (org.junit.jupiter.api.Test)24 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)8 Date (java.util.Date)7 List (java.util.List)6 Event (org.hisp.dhis.dxf2.events.event.Event)6 ProgramOwner (org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner)6 Collectors (java.util.stream.Collectors)5 Relationship (org.hisp.dhis.dxf2.events.trackedentity.Relationship)5 User (org.hisp.dhis.user.User)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Set (java.util.Set)4 QueryItem (org.hisp.dhis.common.QueryItem)4 TrackedEntityInstanceService (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Sets (com.google.common.collect.Sets)3