Search in sources :

Example 46 with TrackedEntityInstance

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

the class TrackerSynchronization method synchronizePage.

private void synchronizePage(TrackedEntityInstanceQueryParams queryParams, int page, int pageSize) {
    queryParams.setPage(page);
    List<TrackedEntityInstance> dtoTeis = teiService.getTrackedEntityInstances(queryParams, TrackedEntityInstanceParams.DATA_SYNCHRONIZATION, true, true);
    log.info(String.format("Synchronizing page %d with page size %d", page, pageSize));
    if (log.isDebugEnabled()) {
        log.debug("TEIs that are going to be synchronized are: " + dtoTeis);
    }
    if (sendSyncRequest(dtoTeis)) {
        List<String> teiUIDs = dtoTeis.stream().map(TrackedEntityInstance::getTrackedEntityInstance).collect(Collectors.toList());
        log.info("The lastSynchronized flag of these TEIs will be updated: " + teiUIDs);
        teiService.updateTrackedEntityInstancesSyncTimestamp(teiUIDs, new Date(clock.getStartTime()));
    } else {
        syncResult = false;
    }
}
Also used : TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date)

Example 47 with TrackedEntityInstance

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

the class TrackedEntityInstanceSupplierTest method verifySupplier.

@Test
void verifySupplier() throws SQLException {
    // mock resultset data
    when(mockResultSet.getLong("trackedentityinstanceid")).thenReturn(100L);
    when(mockResultSet.getString("uid")).thenReturn("abcded");
    when(mockResultSet.getString("code")).thenReturn("ALFA");
    // create event to import
    Event event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setTrackedEntityInstance("abcded");
    // mock resultset extraction
    mockResultSetExtractor(mockResultSet);
    Map<String, Pair<TrackedEntityInstance, Boolean>> map = subject.get(ImportOptions.getDefaultImportOptions(), Collections.singletonList(event));
    TrackedEntityInstance trackedEntityInstance = map.get(event.getUid()).getKey();
    assertThat(trackedEntityInstance, is(notNullValue()));
    assertThat(trackedEntityInstance.getId(), is(100L));
    assertThat(trackedEntityInstance.getUid(), is("abcded"));
    assertThat(trackedEntityInstance.getCode(), is("ALFA"));
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 48 with TrackedEntityInstance

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

the class ProgramInstanceRepeatableStageCheckTest method successOnNonRepeatableStageAndExistingEventsOnNewEnrollment.

@Test
void successOnNonRepeatableStageAndExistingEventsOnNewEnrollment() {
    // Data preparation
    Program program = createProgram('P');
    TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
    event.setProgramStage(CodeGenerator.generateUid());
    event.setProgram(program.getUid());
    event.setTrackedEntityInstance(tei.getUid());
    ProgramStage programStage = createProgramStage('A', program);
    programStage.setRepeatable(false);
    when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
    ProgramInstance programInstance = new ProgramInstance();
    programInstanceMap.put(event.getUid(), programInstance);
    Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
    Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
    teiMap.put(event.getUid(), teiPair);
    when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
    when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
    when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
    when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(false);
    // Method under test
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertNoError(summary);
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) Pair(org.apache.commons.lang3.tuple.Pair) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 49 with TrackedEntityInstance

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

the class HandleRelationshipsTrackedEntityInstanceServiceTest method testUpdateTeiWithUniDirectionalRelationshipEventToTei.

@Test
void testUpdateTeiWithUniDirectionalRelationshipEventToTei() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(this.trackedEntityInstanceA.getUid());
    RelationshipType malariaCaseLinkedToPersonRelationshipType = createMalariaCaseLinkedToPersonRelationshipType('A', programA, trackedEntityType);
    malariaCaseLinkedToPersonRelationshipType.setBidirectional(false);
    relationshipTypeService.addRelationshipType(malariaCaseLinkedToPersonRelationshipType);
    Relationship relationship = createEventToTeiRelationship('A', malariaCaseLinkedToPersonRelationshipType, trackedEntityInstance, programStageInstanceA);
    trackedEntityInstance.setRelationships(Lists.newArrayList(relationship));
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.ERROR, importSummary.getRelationships().getStatus());
    assertEquals("Can't update relationship '" + relationship.getRelationship() + "': TrackedEntityInstance '" + trackedEntityInstance.getTrackedEntityInstance() + "' is not the owner of the relationship", importSummary.getRelationships().getImportSummaries().get(0).getDescription());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 50 with TrackedEntityInstance

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

the class HandleRelationshipsTrackedEntityInstanceServiceTest method testUpdateTeiWithBidirectionalRelationshipEventToTei.

@Test
void testUpdateTeiWithBidirectionalRelationshipEventToTei() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(this.trackedEntityInstanceA.getUid());
    RelationshipType relationshipType = createMalariaCaseLinkedToPersonRelationshipType('A', programA, trackedEntityType);
    relationshipTypeService.addRelationshipType(relationshipType);
    Relationship relationship = createEventToTeiRelationship('A', relationshipType, trackedEntityInstance, programStageInstanceA);
    trackedEntityInstance.setRelationships(Lists.newArrayList(relationship));
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getRelationships().getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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