Search in sources :

Example 46 with Enrollment

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;
}
Also used : ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Date(java.util.Date)

Example 47 with 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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 48 with Enrollment

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

Example 49 with Enrollment

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;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException)

Example 50 with Enrollment

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

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)46 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)44 Test (org.junit.jupiter.api.Test)35 Event (org.hisp.dhis.dxf2.events.event.Event)31 Date (java.util.Date)28 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)23 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 ArrayList (java.util.ArrayList)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)18 ProgramInstance (org.hisp.dhis.program.ProgramInstance)18 List (java.util.List)17 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)17 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)14 Program (org.hisp.dhis.program.Program)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Map (java.util.Map)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Lists (com.google.common.collect.Lists)11