use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testSavePerson.
@Test
@Disabled
void testSavePerson() {
TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
// person.setName( "NAME" );
trackedEntityInstance.setOrgUnit(organisationUnitA.getUid());
ImportSummary importSummary = trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstance, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
// assertEquals( "NAME", personService.getTrackedEntityInstance(
// importSummary.getReference() ).getName() );
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment.
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
enrollment1.setStatus(EnrollmentStatus.COMPLETED);
enrollment1.setCompletedBy("test");
enrollment1.setCompletedDate(new Date());
Enrollment enrollment2 = new Enrollment();
enrollment2.setTrackedEntityInstance(maleA.getUid());
enrollment2.setEnrollmentDate(new Date());
enrollment2.setOrgUnit(organisationUnitA.getUid());
enrollment2.setProgram(programA.getUid());
enrollment2.setStatus(EnrollmentStatus.ACTIVE);
trackedEntityInstance.getEnrollments().add(enrollment2);
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdatePerson.
@Test
@Disabled
void testUpdatePerson() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
// person.setName( "UPDATED_NAME" );
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
// assertEquals( "UPDATED_NAME", personService.getTrackedEntityInstance(
// maleA.getUid() ).getName() );
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment.
/**
* FIXME luciano: this is ignored because there is a bug in tracker, so that
* new events that fail to validate are reported as success.
*/
@Disabled
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndUpdateExistingEventsInSameEnrollment() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
Event event1 = new Event();
event1.setEnrollment(enrollment1.getEnrollment());
event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event1.setOrgUnit(organisationUnitA.getUid());
event1.setProgram(programA.getUid());
event1.setProgramStage(programStageA1.getUid());
event1.setStatus(EventStatus.ACTIVE);
event1.setTrackedEntityInstance(maleA.getUid());
enrollment1.setEvents(singletonList(event1));
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
// This is required because the Event creation takes place using JDBC,
// therefore Hibernate does not
// "see" the new event in the context of this session
sessionFactory.getCurrentSession().clear();
trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
assertNotNull(trackedEntityInstance.getEnrollments().get(0).getEvents());
assertEquals(1, trackedEntityInstance.getEnrollments().get(0).getEvents().size());
enrollment1 = trackedEntityInstance.getEnrollments().get(0);
enrollment1.setStatus(EnrollmentStatus.COMPLETED);
enrollment1.setCompletedBy("test");
enrollment1.setCompletedDate(new Date());
event1 = enrollment1.getEvents().get(0);
event1.setStatus(EventStatus.COMPLETED);
event1.setCompletedBy("test");
event1.setCompletedDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAttributesAggregateAclTest method verifyTeiCantBeAccessedNoPublicAccessOnTrackedEntityType.
@Test
void verifyTeiCantBeAccessedNoPublicAccessOnTrackedEntityType() {
doInTransaction(() -> {
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(0));
}
Aggregations