Search in sources :

Example 56 with TrackerImportReport

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

the class EventDataValueTest method testEventDataValue.

@Test
void testEventDataValue() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<ProgramStageInstance> events = manager.getAll(ProgramStageInstance.class);
    assertEquals(1, events.size());
    ProgramStageInstance psi = events.get(0);
    Set<EventDataValue> eventDataValues = psi.getEventDataValues();
    assertEquals(4, eventDataValues.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 57 with TrackerImportReport

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

the class EventDataValueTest method testTrackedEntityProgramAttributeValueUpdate.

@Test
void testTrackedEntityProgramAttributeValueUpdate() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<ProgramStageInstance> events = manager.getAll(ProgramStageInstance.class);
    assertEquals(1, events.size());
    ProgramStageInstance psi = events.get(0);
    Set<EventDataValue> eventDataValues = psi.getEventDataValues();
    assertEquals(4, eventDataValues.size());
    // update
    trackerImportParams = fromJson("tracker/event_with_updated_data_values.json");
    // make sure that the uid property is populated as well - otherwise
    // update will
    // not work
    trackerImportParams.getEvents().get(0).setEvent(trackerImportParams.getEvents().get(0).getEvent());
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
    trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    List<ProgramStageInstance> updatedEvents = manager.getAll(ProgramStageInstance.class);
    assertEquals(1, updatedEvents.size());
    ProgramStageInstance updatedPsi = programStageInstanceService.getProgramStageInstance(updatedEvents.get(0).getUid());
    assertEquals(3, updatedPsi.getEventDataValues().size());
    List<String> values = updatedPsi.getEventDataValues().stream().map(EventDataValue::getValue).collect(Collectors.toList());
    assertThat(values, hasItem("First"));
    assertThat(values, hasItem("Second"));
    assertThat(values, hasItem("Fourth updated"));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 58 with TrackerImportReport

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

the class EventDataValueTest method successWhenEventHasNoProgramAndHasProgramStage.

@Test
void successWhenEventHasNoProgramAndHasProgramStage() throws IOException {
    TrackerImportParams params = fromJson("tracker/validations/events-with_no_program.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
}
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 59 with TrackerImportReport

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

the class OwnershipTest method testCreateEnrollmentAfterDeleteEnrollment.

@Test
void testCreateEnrollmentAfterDeleteEnrollment() 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());
    pis = manager.getAll(ProgramInstance.class);
    assertEquals(1, pis.size());
    enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE);
    enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid());
    updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertNoImportErrors(updatedReport);
    assertEquals(1, updatedReport.getStats().getCreated());
    pis = manager.getAll(ProgramInstance.class);
    assertEquals(2, pis.size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 60 with TrackerImportReport

use of org.hisp.dhis.tracker.report.TrackerImportReport 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)

Aggregations

TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)114 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)105 Test (org.junit.jupiter.api.Test)99 User (org.hisp.dhis.user.User)23 TrackerTest (org.hisp.dhis.tracker.TrackerTest)21 ClassPathResource (org.springframework.core.io.ClassPathResource)20 InputStream (java.io.InputStream)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)15 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 Date (java.util.Date)4 List (java.util.List)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)3 TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3