Search in sources :

Example 1 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTei.

@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTei() {
    List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeNOTSet());
    List<TrackedEntity> trackedEntities = Lists.newArrayList(getTrackedEntitiesWithAttributeSet());
    bundle.setEnrollments(enrollments);
    bundle.setTrackedEntities(trackedEntities);
    bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
    Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
    Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(SECOND_ENROLLMENT_ID)).findAny().get();
    TrackedEntity trackedEntity = bundle.getTrackedEntities().stream().filter(e -> e.getTrackedEntity().equals(TRACKED_ENTITY_ID)).findAny().get();
    Optional<Attribute> enrollmentAttribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
    Optional<Attribute> teiAttribute = trackedEntity.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
    assertFalse(enrollmentAttribute.isPresent());
    assertTrue(teiAttribute.isPresent());
    assertEquals(TEI_ATTRIBUTE_OLD_VALUE, teiAttribute.get().getValue());
    assertEquals(1, enrollmentIssues.size());
    assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
    assertEquals(ERROR, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
Also used : Strictness(org.mockito.quality.Strictness) WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) BeforeEach(org.junit.jupiter.api.BeforeEach) TRACKED_ENTITY_ATTRIBUTE(org.hisp.dhis.rules.models.AttributeType.TRACKED_ENTITY_ATTRIBUTE) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) RuleEffects(org.hisp.dhis.rules.models.RuleEffects) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) Mock(org.mockito.Mock) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ENROLLMENT(org.hisp.dhis.rules.models.TrackerObjectType.ENROLLMENT) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DATA_ELEMENT(org.hisp.dhis.rules.models.AttributeType.DATA_ELEMENT) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) AssignValueImplementer(org.hisp.dhis.tracker.programrule.implementers.AssignValueImplementer) InjectMocks(org.mockito.InjectMocks) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EVENT(org.hisp.dhis.rules.models.TrackerObjectType.EVENT) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Mockito.when(org.mockito.Mockito.when) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) EnrollmentStatus(org.hisp.dhis.tracker.domain.EnrollmentStatus) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleAction(org.hisp.dhis.rules.models.RuleAction) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 2 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class AssignValueImplementerTest method getEnrollmentWithAttributeNOTSet.

private Enrollment getEnrollmentWithAttributeNOTSet() {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(SECOND_ENROLLMENT_ID);
    enrollment.setStatus(EnrollmentStatus.COMPLETED);
    enrollment.setTrackedEntity(TRACKED_ENTITY_ID);
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Example 3 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsEmpty.

@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsEmpty() {
    List<TrackedEntity> trackedEntities = Lists.newArrayList(getTrackedEntitiesWithAttributeNOTSet());
    List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeNOTSet());
    bundle.setTrackedEntities(trackedEntities);
    bundle.setEnrollments(enrollments);
    bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
    Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
    Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(SECOND_ENROLLMENT_ID)).findAny().get();
    Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
    assertTrue(attribute.isPresent());
    assertEquals(TEI_ATTRIBUTE_NEW_VALUE, attribute.get().getValue());
    assertEquals(1, enrollmentIssues.size());
    assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
    assertEquals(WARNING, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
Also used : Strictness(org.mockito.quality.Strictness) WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) BeforeEach(org.junit.jupiter.api.BeforeEach) TRACKED_ENTITY_ATTRIBUTE(org.hisp.dhis.rules.models.AttributeType.TRACKED_ENTITY_ATTRIBUTE) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) RuleEffects(org.hisp.dhis.rules.models.RuleEffects) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) Mock(org.mockito.Mock) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ENROLLMENT(org.hisp.dhis.rules.models.TrackerObjectType.ENROLLMENT) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DATA_ELEMENT(org.hisp.dhis.rules.models.AttributeType.DATA_ELEMENT) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) AssignValueImplementer(org.hisp.dhis.tracker.programrule.implementers.AssignValueImplementer) InjectMocks(org.mockito.InjectMocks) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EVENT(org.hisp.dhis.rules.models.TrackerObjectType.EVENT) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Mockito.when(org.mockito.Mockito.when) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) EnrollmentStatus(org.hisp.dhis.tracker.domain.EnrollmentStatus) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleAction(org.hisp.dhis.rules.models.RuleAction) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 4 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndSystemSettingToOverwriteIsTrue.

@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndSystemSettingToOverwriteIsTrue() {
    List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSet());
    bundle.setEnrollments(enrollments);
    bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
    when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.TRUE);
    Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
    Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(FIRST_ENROLLMENT_ID)).findAny().get();
    Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
    assertTrue(attribute.isPresent());
    assertEquals(TEI_ATTRIBUTE_NEW_VALUE, attribute.get().getValue());
    assertEquals(1, enrollmentIssues.size());
    assertEquals(1, enrollmentIssues.get(FIRST_ENROLLMENT_ID).size());
    assertEquals(WARNING, enrollmentIssues.get(FIRST_ENROLLMENT_ID).get(0).getIssueType());
}
Also used : Strictness(org.mockito.quality.Strictness) WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) BeforeEach(org.junit.jupiter.api.BeforeEach) TRACKED_ENTITY_ATTRIBUTE(org.hisp.dhis.rules.models.AttributeType.TRACKED_ENTITY_ATTRIBUTE) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) RuleEffects(org.hisp.dhis.rules.models.RuleEffects) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) Mock(org.mockito.Mock) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ENROLLMENT(org.hisp.dhis.rules.models.TrackerObjectType.ENROLLMENT) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DATA_ELEMENT(org.hisp.dhis.rules.models.AttributeType.DATA_ELEMENT) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) AssignValueImplementer(org.hisp.dhis.tracker.programrule.implementers.AssignValueImplementer) InjectMocks(org.mockito.InjectMocks) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EVENT(org.hisp.dhis.rules.models.TrackerObjectType.EVENT) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Mockito.when(org.mockito.Mockito.when) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) EnrollmentStatus(org.hisp.dhis.tracker.domain.EnrollmentStatus) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleAction(org.hisp.dhis.rules.models.RuleAction) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 5 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresent.

@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresent() {
    List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSet());
    bundle.setEnrollments(enrollments);
    bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
    Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
    Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(FIRST_ENROLLMENT_ID)).findAny().get();
    Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
    assertTrue(attribute.isPresent());
    assertEquals(TEI_ATTRIBUTE_OLD_VALUE, attribute.get().getValue());
    assertEquals(1, enrollmentIssues.size());
    assertEquals(1, enrollmentIssues.get(FIRST_ENROLLMENT_ID).size());
    assertEquals(ERROR, enrollmentIssues.get(FIRST_ENROLLMENT_ID).get(0).getIssueType());
}
Also used : Strictness(org.mockito.quality.Strictness) WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) BeforeEach(org.junit.jupiter.api.BeforeEach) TRACKED_ENTITY_ATTRIBUTE(org.hisp.dhis.rules.models.AttributeType.TRACKED_ENTITY_ATTRIBUTE) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) RuleEffects(org.hisp.dhis.rules.models.RuleEffects) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) Mock(org.mockito.Mock) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ENROLLMENT(org.hisp.dhis.rules.models.TrackerObjectType.ENROLLMENT) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DATA_ELEMENT(org.hisp.dhis.rules.models.AttributeType.DATA_ELEMENT) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) AssignValueImplementer(org.hisp.dhis.tracker.programrule.implementers.AssignValueImplementer) InjectMocks(org.mockito.InjectMocks) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EVENT(org.hisp.dhis.rules.models.TrackerObjectType.EVENT) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Mockito.when(org.mockito.Mockito.when) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) EnrollmentStatus(org.hisp.dhis.tracker.domain.EnrollmentStatus) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) RuleAction(org.hisp.dhis.rules.models.RuleAction) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14