Search in sources :

Example 81 with TrackerImportParams

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

the class RelationshipTrackerConverterServiceTest method setUpTest.

@Override
protected void setUpTest() throws IOException {
    preCreateInjectAdminUserWithoutPersistence();
    renderService = _renderService;
    userService = _userService;
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    Program program = createProgram('A');
    programService.addProgram(program);
    ProgramStage programStage = createProgramStage('A', program);
    programStageService.saveProgramStage(programStage);
    TrackedEntityAttribute trackedEntityAttribute = createTrackedEntityAttribute('A');
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    TrackedEntityInstance trackedEntityInstance = createTrackedEntityInstance('A', organisationUnit, trackedEntityAttribute);
    trackedEntityInstance.setUid(TEI);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setEnrollmentDate(new Date());
    programInstance.setProgram(program);
    programInstance.setUid(ENROLLMENT);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setUid(EVENT);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setProgramStage(programStage);
    trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstance);
    programInstanceService.addProgramInstance(programInstance);
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    RelationshipType relationshipTypeA = createTeiToEnrollmentRelationshipType('A', program, trackedEntityType, false);
    relationshipTypeA.setUid(TEI_TO_ENROLLMENT_RELATIONSHIP_TYPE);
    RelationshipType relationshipTypeB = createTeiToEventRelationshipType('B', program, trackedEntityType, false);
    relationshipTypeB.setUid(TEI_TO_EVENT_RELATIONSHIP_TYPE);
    relationshipTypeService.addRelationshipType(relationshipTypeA);
    relationshipTypeService.addRelationshipType(relationshipTypeB);
    TrackerImportParams trackerImportParams = renderService.fromJson(new ClassPathResource("tracker/relationships.json").getInputStream(), TrackerImportParams.class);
    User adminUser = createAndInjectAdminUser();
    trackerImportParams.setUser(adminUser);
    trackerBundle = trackerBundleService.create(trackerImportParams);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) User(org.hisp.dhis.user.User) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) ClassPathResource(org.springframework.core.io.ClassPathResource) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 82 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams 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 83 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams 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 84 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams 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 85 with TrackerImportParams

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

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