Search in sources :

Example 96 with TrackedEntityInstance

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

the class TrackedEntityInstanceServiceTest method testSavePerson.

@Test
@Disabled
void testSavePerson() {
    TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
    // person.setName( "NAME" );
    trackedEntityInstance.setOrgUnit(organisationUnitA.getUid());
    ImportSummary importSummary = trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstance, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
// assertEquals( "NAME", personService.getTrackedEntityInstance(
// importSummary.getReference() ).getName() );
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 97 with TrackedEntityInstance

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

the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment.

@Test
void testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    assertNotNull(trackedEntityInstance.getEnrollments());
    assertEquals(1, trackedEntityInstance.getEnrollments().size());
    Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
    enrollment1.setStatus(EnrollmentStatus.COMPLETED);
    enrollment1.setCompletedBy("test");
    enrollment1.setCompletedDate(new Date());
    Enrollment enrollment2 = new Enrollment();
    enrollment2.setTrackedEntityInstance(maleA.getUid());
    enrollment2.setEnrollmentDate(new Date());
    enrollment2.setOrgUnit(organisationUnitA.getUid());
    enrollment2.setProgram(programA.getUid());
    enrollment2.setStatus(EnrollmentStatus.ACTIVE);
    trackedEntityInstance.getEnrollments().add(enrollment2);
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 98 with TrackedEntityInstance

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

the class TrackedEntityInstanceServiceTest method testUpdatePerson.

@Test
@Disabled
void testUpdatePerson() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    // person.setName( "UPDATED_NAME" );
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
// assertEquals( "UPDATED_NAME", personService.getTrackedEntityInstance(
// maleA.getUid() ).getName() );
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 99 with TrackedEntityInstance

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

the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment.

/**
 * FIXME luciano: this is ignored because there is a bug in tracker, so that
 * new events that fail to validate are reported as success.
 */
@Disabled
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    assertNotNull(trackedEntityInstance.getEnrollments());
    assertEquals(1, trackedEntityInstance.getEnrollments().size());
    Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
    Event event1 = new Event();
    event1.setEnrollment(enrollment1.getEnrollment());
    event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
    event1.setOrgUnit(organisationUnitA.getUid());
    event1.setProgram(programA.getUid());
    event1.setProgramStage(programStageA1.getUid());
    event1.setStatus(EventStatus.ACTIVE);
    event1.setTrackedEntityInstance(maleA.getUid());
    enrollment1.setEvents(singletonList(event1));
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
    // This is required because the Event creation takes place using JDBC,
    // therefore Hibernate does not
    // "see" the new event in the context of this session
    sessionFactory.getCurrentSession().clear();
    trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    assertNotNull(trackedEntityInstance.getEnrollments());
    assertEquals(1, trackedEntityInstance.getEnrollments().size());
    assertNotNull(trackedEntityInstance.getEnrollments().get(0).getEvents());
    assertEquals(1, trackedEntityInstance.getEnrollments().get(0).getEvents().size());
    enrollment1 = trackedEntityInstance.getEnrollments().get(0);
    enrollment1.setStatus(EnrollmentStatus.COMPLETED);
    enrollment1.setCompletedBy("test");
    enrollment1.setCompletedDate(new Date());
    event1 = enrollment1.getEvents().get(0);
    event1.setStatus(EventStatus.COMPLETED);
    event1.setCompletedBy("test");
    event1.setCompletedDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
    importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 100 with TrackedEntityInstance

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

the class TrackedEntityInstanceAttributesAggregateAclTest method verifyTeiCantBeAccessedNoPublicAccessOnTrackedEntityType.

@Test
void verifyTeiCantBeAccessedNoPublicAccessOnTrackedEntityType() {
    doInTransaction(() -> {
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
        this.persistTrackedEntityInstance();
    });
    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);
    assertThat(trackedEntityInstances, 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

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