use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerTest method createEnrollmentWithEvents.
private Enrollment createEnrollmentWithEvents(Program program, TrackedEntityInstance trackedEntityInstance, int events) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setOrgUnit(organisationUnitA.getUid());
enrollment.setProgram(program.getUid());
enrollment.setTrackedEntityInstance(trackedEntityInstance.getUid());
enrollment.setEnrollmentDate(new Date());
enrollment.setStatus(EnrollmentStatus.COMPLETED);
enrollment.setIncidentDate(new Date());
enrollment.setCompletedDate(new Date());
enrollment.setCompletedBy("hello-world");
if (events > 0) {
List<Event> eventList = new ArrayList<>();
String now = DateUtils.getIso8601NoTz(new Date());
for (int i = 0; i < events; i++) {
Event event1 = new Event();
event1.setEnrollment(enrollment.getEnrollment());
event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event1.setProgram(programA.getUid());
event1.setProgramStage(programStageA1.getUid());
event1.setStatus(EventStatus.COMPLETED);
event1.setTrackedEntityInstance(trackedEntityInstance.getUid());
event1.setOrgUnit(organisationUnitA.getUid());
event1.setAttributeOptionCombo(DEF_COC_UID);
event1.setCreatedAtClient(now);
event1.setLastUpdatedAtClient(now);
event1.setCompletedDate(now);
event1.setCompletedBy("[Unknown]");
eventList.add(event1);
}
enrollment.setEvents(eventList);
}
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testAddEnrollmentToOrgUnitWithoutProgramAccess.
@Test
void testAddEnrollmentToOrgUnitWithoutProgramAccess() {
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.updateNoAcl(programA);
Enrollment en = createEnrollment(programA.getUid(), maleA.getUid());
en.setOrgUnit(organisationUnitB.getUid());
ImportSummary importSummary = enrollmentService.addEnrollment(en, ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals("Program is not assigned to this Organisation Unit: " + organisationUnitB.getUid(), importSummary.getDescription());
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
programA.getOrganisationUnits().add(organisationUnitB);
manager.updateNoAcl(programA);
importSummary = enrollmentService.addEnrollment(en, ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataRead.
/**
* program = DATA READ orgUnit = Accessible status = SUCCESS
*/
@Test
void testGetEnrollmentUserWithDataRead() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
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 TrackerRelationshipCriteria method getIdentifierParam.
public String getIdentifierParam() throws WebMessageException {
if (this.identifier != null) {
return this.identifier;
}
int count = 0;
if (!StringUtils.isBlank(this.trackedEntity)) {
this.identifier = this.trackedEntity;
this.identifierName = "trackedEntity";
this.identifierClass = TrackedEntityInstance.class;
count++;
}
if (!StringUtils.isBlank(this.enrollment)) {
this.identifier = this.enrollment;
this.identifierName = "enrollment";
this.identifierClass = ProgramInstance.class;
count++;
}
if (!StringUtils.isBlank(this.event)) {
this.identifier = this.event;
this.identifierName = "event";
this.identifierClass = ProgramStageInstance.class;
count++;
}
if (count == 0) {
throw new WebMessageException(badRequest("Missing required parameter 'trackedEntity', 'enrollment' or 'event'."));
} else if (count > 1) {
throw new WebMessageException(badRequest("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed."));
}
return this.identifier;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerTest method deleteOneEvent.
public Event deleteOneEvent(Enrollment enrollment) {
List<Event> events = enrollment.getEvents();
assertThat(events, is(not(empty())));
Event event = events.get(0);
ImportSummary importSummary = eventService.deleteEvent(event.getEvent());
assertEquals(0, importSummary.getConflictCount());
return event;
}
Aggregations