Search in sources :

Example 41 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackerRelationshipCriteriaTest method getIdentifierClassThrowsIfTrackedEntityAndEnrollmentAreSet.

@Test
void getIdentifierClassThrowsIfTrackedEntityAndEnrollmentAreSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    criteria.setTrackedEntity("Hq3Kc6HK4OZ");
    criteria.setEnrollment("Hq3Kc6HK4OZ");
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierClass);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 42 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackerRelationshipCriteriaTest method getIdentifierClassThrowsIfAllParamsAreSet.

@Test
void getIdentifierClassThrowsIfAllParamsAreSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    criteria.setTrackedEntity("Hq3Kc6HK4OZ");
    criteria.setTei("Hq3Kc6HK4OZ");
    criteria.setEnrollment("Hq3Kc6HK4OZ");
    criteria.setEvent("Hq3Kc6HK4OZ");
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierClass);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 43 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackerRelationshipCriteriaTest method getIdentifierClassThrowsIfTeiAndEnrollmentAreSet.

@Test
void getIdentifierClassThrowsIfTeiAndEnrollmentAreSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    criteria.setTei("Hq3Kc6HK4OZ");
    criteria.setEnrollment("Hq3Kc6HK4OZ");
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierClass);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 44 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackerRelationshipCriteriaTest method getIdentifierParamThrowsIfNoParamsIsSet.

@Test
void getIdentifierParamThrowsIfNoParamsIsSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierParam);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Missing required parameter 'trackedEntity', 'enrollment' or 'event'.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 45 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testUpdateTeiAfterChangingTextPatternForGeneratedAttribute.

@Test
void testUpdateTeiAfterChangingTextPatternForGeneratedAttribute() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    assertNotNull(trackedEntityInstance.getEnrollments());
    assertEquals(1, trackedEntityInstance.getEnrollments().size());
    Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
    enrollment1.setStatus(EnrollmentStatus.COMPLETED);
    enrollment1.setCompletedBy("test");
    enrollment1.setCompletedDate(new Date());
    Enrollment enrollment2 = new Enrollment();
    enrollment2.setTrackedEntityInstance(maleA.getUid());
    TextPattern textPattern = new TextPattern(Lists.newArrayList(new TextPatternSegment(TextPatternMethod.RANDOM, "RANDOM(#######)")));
    textPattern.setOwnerUid("owneruid");
    textPattern.setOwnerObject(Objects.CONSTANT);
    uniqueIdAttribute.setTextPattern(textPattern);
    trackedEntityAttributeService.updateTrackedEntityAttribute(uniqueIdAttribute);
    enrollment2.setEnrollmentDate(new Date());
    enrollment2.setOrgUnit(organisationUnitA.getUid());
    enrollment2.setProgram(programA.getUid());
    enrollment2.setStatus(EnrollmentStatus.ACTIVE);
    trackedEntityInstance.getEnrollments().add(enrollment2);
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
}
Also used : TextPattern(org.hisp.dhis.textpattern.TextPattern) TextPatternSegment(org.hisp.dhis.textpattern.TextPatternSegment) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) 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