use of org.hisp.dhis.dxf2.events.enrollment.Enrollment 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.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method createEnrollment.
private Enrollment createEnrollment(String program, String person) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setOrgUnit(organisationUnitA.getUid());
enrollment.setProgram(program);
enrollment.setTrackedEntityInstance(person);
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testAddEnrollmentWithOrgUnitIdSchemeToOrgUnitWithoutProgramAccess.
@Test
void testAddEnrollmentWithOrgUnitIdSchemeToOrgUnitWithoutProgramAccess() {
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.updateNoAcl(programA);
Enrollment en = createEnrollment(programA.getUid(), maleA.getUid());
Attribute attribute = new Attribute();
attribute.setUnique(true);
attribute.setUid("D1DDOl5hTsL");
attribute.setValueType(ValueType.NUMBER);
attribute.setOrganisationUnitAttribute(true);
attribute.setName("OrgUnitAttribute");
attributeService.addAttribute(attribute);
AttributeValue av = new AttributeValue();
av.setAttribute(attribute);
av.setValue("1025");
organisationUnitB.setAttributeValues(Collections.singleton(av));
manager.updateNoAcl(organisationUnitB);
en.setOrgUnit(av.getValue());
ImportOptions importOptions = new ImportOptions();
importOptions.getIdSchemes().setOrgUnitIdScheme("ATTRIBUTE");
importOptions.getIdSchemes().getOrgUnitIdScheme().setAttribute("D1DDOl5hTsL");
ImportSummary importSummary = enrollmentService.addEnrollment(en, importOptions);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals("Program is not assigned to this Organisation Unit: " + av.getValue(), importSummary.getDescription());
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
programA.getOrganisationUnits().add(organisationUnitB);
manager.updateNoAcl(programA);
importSummary = enrollmentService.addEnrollment(en, importOptions);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataReadWrite.
/**
* program = DATA READ/WRITE orgUnit = Accessible status = SUCCESS
*/
@Test
void testGetEnrollmentUserWithDataReadWrite() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
manager.updateNoAcl(programA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
injectSecurityContext(user);
Enrollment enrollment = enrollmentService.getEnrollment(importSummary.getReference());
assertNotNull(enrollment);
assertEquals(enrollment.getEnrollment(), importSummary.getReference());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method testSaveWithEnrollmentShouldNotFail.
@Test
void testSaveWithEnrollmentShouldNotFail() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
Aggregations