Search in sources :

Example 71 with Enrollment

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 72 with Enrollment

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

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

Example 74 with Enrollment

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());
}
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 75 with Enrollment

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

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