Search in sources :

Example 6 with Attribute

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

the class FileResourceSupplierTest method getEnrollment.

private Enrollment getEnrollment() {
    Attribute attribute = new Attribute();
    attribute.setAttribute(FILE_RESOURCE_ATTRIBUTE_UID);
    attribute.setValueType(ValueType.FILE_RESOURCE);
    attribute.setValue(ANOTHER_FILE_RESOURCE_UID);
    Enrollment enrollment = new Enrollment();
    enrollment.setAttributes(Lists.newArrayList(attribute));
    return enrollment;
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Example 7 with Attribute

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

the class EnrollmentAttributeValidationHookTest method shouldPassValidationWhenValueIsNullAndAttributeIsNotMandatory.

@Test
void shouldPassValidationWhenValueIsNullAndAttributeIsNotMandatory() {
    // 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 only 1 tracked attributes is mandatory
    when(program.getProgramAttributes()).thenReturn(Arrays.asList(new ProgramTrackedEntityAttribute(program, trackedEntityAttribute, false, true), new ProgramTrackedEntityAttribute(program, trackedEntityAttribute1, false, false)));
    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(0));
}
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 8 with Attribute

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

the class AssignValueImplementerTest method getAttributesSameValue.

private List<Attribute> getAttributesSameValue() {
    Attribute attribute = new Attribute();
    attribute.setAttribute(ATTRIBUTE_ID);
    attribute.setValue(TEI_ATTRIBUTE_NEW_VALUE);
    return Lists.newArrayList(attribute);
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 9 with Attribute

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

the class SetMandatoryFieldValidatorTest method getAttributes.

private List<Attribute> getAttributes() {
    Attribute attribute = new Attribute();
    attribute.setAttribute(ATTRIBUTE_ID);
    attribute.setValue(ATTRIBUTE_VALUE);
    return Lists.newArrayList(attribute);
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute)

Example 10 with Attribute

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

the class AttributeValueConverterService method to.

@Override
public Attribute to(TrackedEntityAttributeValue teav) {
    Attribute attribute = new Attribute();
    attribute.setAttribute(teav.getAttribute().getUid());
    attribute.setCode(teav.getAttribute().getCode());
    attribute.setDisplayName(teav.getAttribute().getDisplayName());
    attribute.setCreatedAt(instantFromDate(teav.getCreated()));
    attribute.setUpdatedAt(instantFromDate(teav.getLastUpdated()));
    attribute.setStoredBy(teav.getStoredBy());
    attribute.setValueType(teav.getAttribute().getValueType());
    attribute.setValue(teav.getValue());
    return attribute;
}
Also used : Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

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