Search in sources :

Example 86 with TrackerImportParams

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

the class OwnershipTest method testProgramOwnerWhenEnrolled.

@Test
void testProgramOwnerWhenEnrolled() throws IOException {
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
    assertEquals(1, teis.size());
    TrackedEntityInstance tei = teis.get(0);
    assertNotNull(tei.getProgramOwners());
    Set<TrackedEntityProgramOwner> tepos = tei.getProgramOwners();
    assertEquals(1, tepos.size());
    TrackedEntityProgramOwner tepo = tepos.iterator().next();
    assertNotNull(tepo.getEntityInstance());
    assertNotNull(tepo.getProgram());
    assertNotNull(tepo.getOrganisationUnit());
    assertEquals(enrollmentParams.getEnrollments().get(0).getProgram(), tepo.getProgram().getUid());
    assertEquals(enrollmentParams.getEnrollments().get(0).getOrgUnit(), tepo.getOrganisationUnit().getUid());
    assertEquals(enrollmentParams.getEnrollments().get(0).getTrackedEntity(), tepo.getEntityInstance().getUid());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 87 with TrackerImportParams

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

the class OwnershipTest method testUpdateEnrollment.

@Test
void testUpdateEnrollment() throws IOException {
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
    assertEquals(2, pis.size());
    ProgramInstance pi = pis.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
    compareEnrollmentBasicProperties(pi, enrollmentParams.getEnrollments().get(0));
    Enrollment updatedEnrollment = enrollmentParams.getEnrollments().get(0);
    updatedEnrollment.setStatus(EnrollmentStatus.COMPLETED);
    updatedEnrollment.setCompletedBy("admin");
    updatedEnrollment.setCompletedAt(Instant.now());
    updatedEnrollment.setCreatedAtClient(Instant.now());
    updatedEnrollment.setUpdatedAtClient(Instant.now());
    updatedEnrollment.setEnrolledAt(Instant.now());
    updatedEnrollment.setOccurredAt(Instant.now());
    enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertNoImportErrors(updatedReport);
    assertEquals(1, updatedReport.getStats().getUpdated());
    pis = manager.getAll(ProgramInstance.class);
    assertEquals(2, pis.size());
    pi = pis.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
    compareEnrollmentBasicProperties(pi, updatedEnrollment);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Autowired(org.springframework.beans.factory.annotation.Autowired) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackerImportService(org.hisp.dhis.tracker.TrackerImportService) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerStatus(org.hisp.dhis.tracker.report.TrackerStatus) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) ProgramInstance(org.hisp.dhis.program.ProgramInstance) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Set(java.util.Set) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) IOException(java.io.IOException) Instant(java.time.Instant) TrackedEntityProgramOwner(org.hisp.dhis.trackedentity.TrackedEntityProgramOwner) EnrollmentStatus(org.hisp.dhis.tracker.domain.EnrollmentStatus) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) List(java.util.List) TrackerTest(org.hisp.dhis.tracker.TrackerTest) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) CodeGenerator(org.hisp.dhis.common.CodeGenerator) DateUtils(org.hisp.dhis.util.DateUtils) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 88 with TrackerImportParams

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

the class OwnershipTest method testCreateEnrollmentWithoutOwnership.

@Test
void testCreateEnrollmentWithoutOwnership() throws IOException {
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
    assertEquals(2, pis.size());
    enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertNoImportErrors(updatedReport);
    assertEquals(1, updatedReport.getStats().getDeleted());
    TrackedEntityInstance tei = manager.get(TrackedEntityInstance.class, "IOR1AXXl24H");
    OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP");
    Program pgm = manager.get(Program.class, "BFcipDERJnf");
    trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
    enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE);
    enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid());
    updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertEquals(1, updatedReport.getStats().getIgnored());
    assertEquals(TrackerErrorCode.E1102, updatedReport.getValidationReport().getErrors().get(0).getErrorCode());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 89 with TrackerImportParams

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

the class ReportSummaryDeleteIntegrationTest method testEnrollmentDeletion.

@Test
void testEnrollmentDeletion() throws IOException {
    assertEquals(4, manager.getAll(ProgramInstance.class).size());
    assertEquals(2, manager.getAll(ProgramStageInstance.class).size());
    TrackerImportParams params = fromJson("tracker/enrollment_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
    // remaining
    assertEquals(3, manager.getAll(ProgramInstance.class).size());
    // delete associated events as well
    assertEquals(1, manager.getAll(ProgramStageInstance.class).size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 90 with TrackerImportParams

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

the class ReportSummaryDeleteIntegrationTest method testDeleteMultipleEntities.

@Test
void testDeleteMultipleEntities() throws IOException {
    TrackerImportParams params = fromJson("tracker/tracker_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
    assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.TRACKED_ENTITY);
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5