use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.
the class TrackerTest method deleteOneEnrollment.
public Enrollment deleteOneEnrollment(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance trackedEntityInstance) {
List<Enrollment> enrollments = trackedEntityInstance.getEnrollments();
assertThat(enrollments, is(not(empty())));
Enrollment enrollment = enrollments.get(0);
ImportSummary importSummary = enrollmentService.deleteEnrollment(enrollment.getEnrollment());
assertEquals(0, importSummary.getConflictCount());
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.
the class EnrollmentSecurityTest method testGetEnrollmentsInSearchScopeForUser.
/**
* program = DATA READ orgUnit = Accessible in search scope status = SUCCESS
*/
@Test
void testGetEnrollmentsInSearchScopeForUser() {
ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
manager.update(programA);
User user = createUser("user1");
user.setOrganisationUnits(Sets.newHashSet(organisationUnitB));
user.setTeiSearchOrganisationUnits(Sets.newHashSet(organisationUnitA, organisationUnitB));
user.setDataViewOrganisationUnits(Sets.newHashSet(organisationUnitB));
injectSecurityContext(user);
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
params.setProgram(programA);
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE);
params.setUser(user);
Enrollments enrollments = enrollmentService.getEnrollments(params);
assertNotNull(enrollments);
assertNotNull(enrollments.getEnrollments());
assertEquals(1, enrollments.getEnrollments().size());
assertEquals(importSummary.getReference(), enrollments.getEnrollments().get(0).getEnrollment());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnMultipleProgramInstanceByActiveProgramAndTei.
@Test
void failOnMultipleProgramInstanceByActiveProgramAndTei() {
// Data preparation
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
ProgramInstance programInstance1 = new ProgramInstance();
ProgramInstance programInstance2 = new ProgramInstance();
when(this.programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
event.setProgram(program.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Tracked entity instance: " + tei.getUid() + " has multiple active enrollments in program: " + program.getUid());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.
the class EnrollmentController method startAsyncImport.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
/**
* Starts an asynchronous enrollment task.
*
* @param importOptions the ImportOptions.
* @param enrollments the enrollments to import.
*/
private WebMessage startAsyncImport(ImportOptions importOptions, List<Enrollment> enrollments) {
JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", ENROLLMENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
taskExecutor.executeTask(new ImportEnrollmentsTask(enrollments, enrollmentService, importOptions, jobId));
return jobConfigurationReport(jobId).setLocation("/system/tasks/" + ENROLLMENT_IMPORT);
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollments in project dhis2-core by dhis2.
the class EnrollmentController method getEnrollments.
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public RootNode getEnrollments(EnrollmentCriteria enrollmentCriteria) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add("enrollment,created,lastUpdated,trackedEntityType,trackedEntityInstance,program,status,orgUnit,orgUnitName,enrollmentDate,incidentDate,followup");
}
RootNode rootNode = NodeUtils.createMetadata();
List<Enrollment> listEnrollments;
if (enrollmentCriteria.getEnrollment() == null) {
ProgramInstanceQueryParams params = enrollmentCriteriaMapper.getFromUrl(TextUtils.splitToArray(enrollmentCriteria.getOu(), TextUtils.SEMICOLON), enrollmentCriteria.getOuMode(), enrollmentCriteria.getLastUpdated(), enrollmentCriteria.getLastUpdatedDuration(), enrollmentCriteria.getProgram(), enrollmentCriteria.getProgramStatus(), enrollmentCriteria.getProgramStartDate(), enrollmentCriteria.getProgramEndDate(), enrollmentCriteria.getTrackedEntityType(), enrollmentCriteria.getTrackedEntityInstance(), enrollmentCriteria.getFollowUp(), enrollmentCriteria.getPage(), enrollmentCriteria.getPageSize(), enrollmentCriteria.isTotalPages(), PagerUtils.isSkipPaging(enrollmentCriteria.getSkipPaging(), enrollmentCriteria.getPaging()), enrollmentCriteria.isIncludeDeleted(), enrollmentCriteria.getOrder());
Enrollments enrollments = enrollmentService.getEnrollments(params);
if (enrollments.getPager() != null) {
if (params.isTotalPages()) {
rootNode.addChild(NodeUtils.createPager(enrollments.getPager()));
} else {
rootNode.addChild(NodeUtils.createSlimPager((SlimPager) enrollments.getPager()));
}
}
listEnrollments = enrollments.getEnrollments();
} else {
Set<String> enrollmentIds = TextUtils.splitToArray(enrollmentCriteria.getEnrollment(), TextUtils.SEMICOLON);
listEnrollments = enrollmentIds != null ? enrollmentIds.stream().map(enrollmentId -> enrollmentService.getEnrollment(enrollmentId)).collect(Collectors.toList()) : null;
}
rootNode.addChild(fieldFilterService.toCollectionNode(Enrollment.class, new FieldFilterParams(listEnrollments, fields)));
return rootNode;
}
Aggregations