Search in sources :

Example 21 with Enrollments

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;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Example 22 with Enrollments

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());
}
Also used : User(org.hisp.dhis.user.User) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with Enrollments

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 24 with Enrollments

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);
}
Also used : ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 25 with Enrollments

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;
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) PathVariable(org.springframework.web.bind.annotation.PathVariable) APPLICATION_XML_VALUE(org.springframework.http.MediaType.APPLICATION_XML_VALUE) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeUtils(org.hisp.dhis.node.NodeUtils) Model(org.springframework.ui.Model) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) PagerUtils(org.hisp.dhis.common.PagerUtils) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) ContextService(org.hisp.dhis.webapi.service.ContextService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) EnrollmentCriteria(org.hisp.dhis.webapi.controller.event.webrequest.EnrollmentCriteria) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AsyncTaskExecutor(org.hisp.dhis.common.AsyncTaskExecutor) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RootNode(org.hisp.dhis.node.types.RootNode) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENROLLMENT_IMPORT(org.hisp.dhis.scheduling.JobType.ENROLLMENT_IMPORT) Controller(org.springframework.stereotype.Controller) StreamUtils(org.hisp.dhis.commons.util.StreamUtils) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) SlimPager(org.hisp.dhis.common.SlimPager) WebMessageUtils.importSummaries(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummaries) EnrollmentCriteriaMapper(org.hisp.dhis.webapi.controller.event.mapper.EnrollmentCriteriaMapper) WebMessageUtils.importSummary(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.importSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) WebMessageUtils.jobConfigurationReport(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.jobConfigurationReport) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) IOException(java.io.IOException) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) HttpStatus(org.springframework.http.HttpStatus) CurrentUserService(org.hisp.dhis.user.CurrentUserService) InputStream(java.io.InputStream) TextUtils(org.hisp.dhis.commons.util.TextUtils) RootNode(org.hisp.dhis.node.types.RootNode) SlimPager(org.hisp.dhis.common.SlimPager) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)16 List (java.util.List)12 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)12 ArrayList (java.util.ArrayList)11 Lists (com.google.common.collect.Lists)9 Map (java.util.Map)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)9 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)8 ProgramInstanceService (org.hisp.dhis.program.ProgramInstanceService)8 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)8 CurrentUserService (org.hisp.dhis.user.CurrentUserService)8 Program (org.hisp.dhis.program.Program)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 ProgramInstanceQueryParams (org.hisp.dhis.program.ProgramInstanceQueryParams)7 SlimPager (org.hisp.dhis.common.SlimPager)6 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)5 Date (java.util.Date)4