Search in sources :

Example 21 with Attribute

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

the class FileResourceSupplierTest method getTrackedEntity.

private TrackedEntity getTrackedEntity() {
    Attribute attribute = new Attribute();
    attribute.setAttribute(NUMERIC_ATTRIBUTE_UID);
    attribute.setValueType(ValueType.NUMBER);
    TrackedEntity trackedEntity = new TrackedEntity();
    trackedEntity.setAttributes(Lists.newArrayList(attribute));
    return trackedEntity;
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity)

Example 22 with Attribute

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

the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenAttributeIsNotPresentInDB.

@Test
void shouldFailValidationWhenAttributeIsNotPresentInDB() {
    Attribute attribute = Attribute.builder().attribute("invalidAttribute").valueType(ValueType.TEXT).value("value").build();
    when(program.getProgramAttributes()).thenReturn(Collections.emptyList());
    when(enrollment.getAttributes()).thenReturn(Collections.singletonList(attribute));
    when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Collections.singletonList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance))));
    when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    hookToTest.validateEnrollment(reporter, enrollment);
    assertThat(reporter.getReportList(), hasSize(1));
    hasTrackerError(reporter, TrackerErrorCode.E1006, TrackerType.ENROLLMENT, enrollment.getUid());
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 23 with Attribute

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

the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsMandatory.

@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsMandatory() {
    // given 1 attribute has null value
    Attribute attribute = Attribute.builder().attribute(trackedAttribute).valueType(ValueType.TEXT).value("value").build();
    Attribute attribute1 = Attribute.builder().attribute(trackedAttribute1).valueType(ValueType.TEXT).build();
    // when both tracked attributes are mandatory
    when(program.getProgramAttributes()).thenReturn(Arrays.asList(new ProgramTrackedEntityAttribute(program, trackedEntityAttribute, false, true), new ProgramTrackedEntityAttribute(program, trackedEntityAttribute1, false, true)));
    when(enrollment.getAttributes()).thenReturn(Arrays.asList(attribute, attribute1));
    when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Arrays.asList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance), new TrackedEntityAttributeValue(trackedEntityAttribute1, trackedEntityInstance))));
    when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    hookToTest.validateEnrollment(reporter, enrollment);
    assertThat(reporter.getReportList(), hasSize(1));
    hasTrackerError(reporter, TrackerErrorCode.E1076, TrackerType.ENROLLMENT, enrollment.getUid());
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 24 with Attribute

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

the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsNotMandatoryAndAttributeNotExistsInTei.

@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsNotMandatoryAndAttributeNotExistsInTei() {
    // given 1 attribute has null value and do not exists in Tei
    Attribute attribute = Attribute.builder().attribute(trackedAttribute).valueType(ValueType.TEXT).value("value").build();
    Attribute attribute1 = Attribute.builder().attribute(trackedAttribute1).valueType(ValueType.TEXT).build();
    // when 2 tracked attributes are mandatory
    when(program.getProgramAttributes()).thenReturn(Arrays.asList(new ProgramTrackedEntityAttribute(program, trackedEntityAttribute, false, true), new ProgramTrackedEntityAttribute(program, trackedEntityAttribute1, false, true)));
    when(enrollment.getAttributes()).thenReturn(Arrays.asList(attribute, attribute1));
    when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Collections.singletonList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance))));
    when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    hookToTest.validateEnrollment(reporter, enrollment);
    assertThat(reporter.getReportList(), hasSize(2));
    hasTrackerError(reporter, TrackerErrorCode.E1076, TrackerType.ENROLLMENT, enrollment.getUid());
    hasTrackerError(reporter, TrackerErrorCode.E1018, TrackerType.ENROLLMENT, enrollment.getUid());
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.hisp.dhis.tracker.domain.Attribute)24 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)22 Map (java.util.Map)11 Optional (java.util.Optional)11 Set (java.util.Set)11 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)11 Test (org.junit.jupiter.api.Test)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)10 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)10 List (java.util.List)9 ValueType (org.hisp.dhis.common.ValueType)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 Lists (com.google.common.collect.Lists)8 Sets (com.google.common.collect.Sets)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 RuleActionAssign (org.hisp.dhis.rules.models.RuleActionAssign)8 SettingKey (org.hisp.dhis.setting.SettingKey)8 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)8 DataValue (org.hisp.dhis.tracker.domain.DataValue)8 Event (org.hisp.dhis.tracker.domain.Event)8