use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndHasTheSameValue.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndHasTheSameValue() {
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSetSameValue());
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_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());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method childEntitiesOfInvalidParentsAreStillValidated.
@Test
void childEntitiesOfInvalidParentsAreStillValidated() {
// Test shows
// the children of a tracked entity will still be validated even if it
// as a parent is invalid
TrackedEntity invalidTrackedEntity = trackedEntity();
Enrollment invalidEnrollment = enrollment();
invalidTrackedEntity.setEnrollments(enrollments(invalidEnrollment));
Event invalidEvent = event();
invalidEnrollment.setEvents(events(invalidEvent));
TrackerBundle bundle = newBundle().validationMode(ValidationMode.FULL).trackedEntities(trackedEntities(invalidTrackedEntity)).enrollments(invalidTrackedEntity.getEnrollments()).events(invalidEnrollment.getEvents()).build();
ValidationHook hook = ValidationHook.builder().validateTrackedEntity((reporter, te) -> reporter.addErrorIf(() -> invalidTrackedEntity.equals(te), te, TrackerErrorCode.E1090)).validateEnrollment((reporter, enrollment) -> reporter.addErrorIf(() -> invalidEnrollment.equals(enrollment), enrollment, TrackerErrorCode.E1069)).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertEquals(3, report.getErrors().size());
assertHasError(report, TrackerErrorCode.E1090, invalidTrackedEntity);
assertHasError(report, TrackerErrorCode.E1069, invalidEnrollment);
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
assertTrue(bundle.getTrackedEntities().isEmpty());
assertTrue(bundle.getEnrollments().isEmpty());
assertTrue(bundle.getEvents().isEmpty());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTeiAndCanBeOverwritten.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTeiAndCanBeOverwritten() {
when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.TRUE);
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_NEW_VALUE, teiAttribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
assertEquals(WARNING, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class AssignValueImplementerTest method getEnrollmentWithAttributeSetSameValue.
private Enrollment getEnrollmentWithAttributeSetSameValue() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(FIRST_ENROLLMENT_ID);
enrollment.setStatus(EnrollmentStatus.ACTIVE);
enrollment.setAttributes(getAttributesSameValue());
return enrollment;
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class SetMandatoryFieldValidatorTest method getEnrollmentWithMandatoryAttributeSet.
private Enrollment getEnrollmentWithMandatoryAttributeSet() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(ACTIVE_ENROLLMENT_ID);
enrollment.setTrackedEntity(TEI_ID);
enrollment.setStatus(EnrollmentStatus.ACTIVE);
enrollment.setAttributes(getAttributes());
return enrollment;
}
Aggregations