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;
}
}
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"));
}
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);
}
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());
}
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());
}
Aggregations