Search in sources :

Example 36 with DataValue

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

the class EventDataValuesValidationHookTest method failValidationWhenDataElementIsNotPresentInProgramStage.

@Test
void failValidationWhenDataElementIsNotPresentInProgramStage() {
    setUpIdentifiers();
    DataElement dataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
    DataElement notPresentDataElement = dataElement();
    notPresentDataElement.setUid("de_not_present_in_program_stage");
    when(context.getDataElement("de_not_present_in_program_stage")).thenReturn(notPresentDataElement);
    ProgramStage programStage = new ProgramStage();
    ProgramStageDataElement mandatoryStageElement1 = new ProgramStageDataElement();
    DataElement mandatoryElement1 = new DataElement();
    mandatoryElement1.setUid(dataValue().getDataElement());
    mandatoryStageElement1.setDataElement(mandatoryElement1);
    mandatoryStageElement1.setCompulsory(true);
    programStage.setProgramStageDataElements(Set.of(mandatoryStageElement1));
    when(context.getProgramStage("PROGRAM_STAGE")).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue notPresentDataValue = dataValue();
    notPresentDataValue.setDataElement("de_not_present_in_program_stage");
    Event event = Event.builder().programStage("PROGRAM_STAGE").status(EventStatus.ACTIVE).dataValues(Set.of(dataValue(), notPresentDataValue)).build();
    hook.validateEvent(reporter, event);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1305, reporter.getReportList().get(0).getErrorCode());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 37 with DataValue

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

the class EventDataValuesValidationHookTest method succeedsOnActiveEventWithDataElementValueIsNullAndValidationStrategyOnComplete.

@Test
void succeedsOnActiveEventWithDataElementValueIsNullAndValidationStrategyOnComplete() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    programStage.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 38 with DataValue

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

the class EventDataValuesValidationHookTest method successValidationDataElementOptionValueIsValid.

@Test
void successValidationDataElementOptionValueIsValid() {
    setUpIdentifiers();
    DataValue validDataValue = dataValue("code");
    DataValue nullDataValue = dataValue(null);
    OptionSet optionSet = new OptionSet();
    Option option = new Option();
    option.setCode("CODE");
    Option option1 = new Option();
    option1.setCode("CODE1");
    optionSet.setOptions(Arrays.asList(option, option1));
    DataElement dataElement = dataElement();
    dataElement.setOptionSet(optionSet);
    when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue, nullDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) Option(org.hisp.dhis.option.Option) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) OptionSet(org.hisp.dhis.option.OptionSet) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 39 with DataValue

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

the class EventDataValuesValidationHookTest method dataValue.

private DataValue dataValue() {
    DataValue dataValue = new DataValue();
    dataValue.setCreatedAt(DateUtils.instantFromDateAsString("2020-10-10"));
    dataValue.setUpdatedAt(DateUtils.instantFromDateAsString("2020-10-10"));
    dataValue.setValue("text");
    dataValue.setDataElement(dataElementUid);
    return dataValue;
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue)

Example 40 with DataValue

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

the class EventDataValuesValidationHookTest method successValidationWhenCreatedAtIsNull.

@Test
void successValidationWhenCreatedAtIsNull() {
    setUpIdentifiers();
    DataElement dataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setCreatedAt(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Aggregations

DataValue (org.hisp.dhis.tracker.domain.DataValue)45 Event (org.hisp.dhis.tracker.domain.Event)35 DataElement (org.hisp.dhis.dataelement.DataElement)33 Test (org.junit.jupiter.api.Test)29 ProgramStage (org.hisp.dhis.program.ProgramStage)26 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)10 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)9 Lists (com.google.common.collect.Lists)6 Sets (com.google.common.collect.Sets)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Set (java.util.Set)6 ValueType (org.hisp.dhis.common.ValueType)6 EventStatus (org.hisp.dhis.event.EventStatus)6 RuleActionAssign (org.hisp.dhis.rules.models.RuleActionAssign)6 SettingKey (org.hisp.dhis.setting.SettingKey)6 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)6