Search in sources :

Example 96 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class AttributeOptionComboDateCheckTest method failOnCategoryOptionStartDateBeforeEventDate.

@Test
void failOnCategoryOptionStartDateBeforeEventDate() {
    event.setEventDate("2019-05-01");
    event.setDueDate("2019-05-10");
    CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo("2020-01-01", true);
    mockContext(categoryOptionCombo);
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), this.workContext);
    assertHasError(importSummary, event, "Event date 2019-05-01 is before start date 2020-01-01 for attributeOption 'test'");
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 97 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryOptionComboSupplierTest method setUp.

@BeforeEach
void setUp() {
    this.subject = new CategoryOptionComboSupplier(jdbcTemplate, programSupplier, attributeOptionComboLoader, programStageInstanceSupplier);
    programMap = new HashMap<>();
    programStageInstanceMap = new HashMap<>();
    // create a Program for the ProgramSupplier
    program = new Program();
    program.setId(999L);
    program.setUid("prabcde");
    programMap.put("prabcde", program);
    // create a ProgramStageInstance for the ProgramStageInstanceSupplier
    coc = new CategoryOptionCombo();
    coc.setUid("coc1");
    programStageInstance = new ProgramStageInstance();
    programStageInstance.setId(888L);
    programStageInstance.setUid("psuid1");
    programStageInstance.setAttributeOptionCombo(coc);
    programStageInstanceMap.put("psuid1", programStageInstance);
    // create event to import
    event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setAttributeOptionCombo("aoc1234");
    event.setProgram(program.getUid());
}
Also used : Program(org.hisp.dhis.program.Program) Event(org.hisp.dhis.dxf2.events.event.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 98 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryOptionComboSupplierTest method case1.

private void case1(ImportOptions importOptions) {
    when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
    CategoryOptionCombo coc = new CategoryOptionCombo();
    coc.setUid(event.getAttributeOptionCombo());
    when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), event.getAttributeOptionCombo())).thenReturn(coc);
    Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(event));
    CategoryOptionCombo categoryOptionCombo = map.get(event.getUid());
    assertThat(categoryOptionCombo, is(notNullValue()));
}
Also used : CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 99 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryOptionComboSupplierTest method case6.

private void case6(ImportOptions importOptions) {
    when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
    when(programStageInstanceSupplier.get(eq(importOptions), anyList())).thenReturn(programStageInstanceMap);
    when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), programStageInstance.getAttributeOptionCombo().getUid())).thenReturn(coc);
    Event eventWithoutAoc = new Event();
    eventWithoutAoc.setUid("psuid1");
    eventWithoutAoc.setProgram(program.getUid());
    Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(eventWithoutAoc));
    CategoryOptionCombo categoryOptionCombo = map.get(eventWithoutAoc.getUid());
    assertThat(categoryOptionCombo, is(notNullValue()));
    assertThat(categoryOptionCombo.getUid(), is(coc.getUid()));
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 100 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class CategoryOptionComboSupplierTest method case2.

private void case2(ImportOptions importOptions) {
    when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
    CategoryOptionCombo coc = new CategoryOptionCombo();
    coc.setUid("def123");
    coc.setName("default ");
    when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), event.getAttributeOptionCombo())).thenReturn(null);
    when(attributeOptionComboLoader.getDefault()).thenReturn(coc);
    Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(event));
    CategoryOptionCombo categoryOptionCombo = map.get(event.getUid());
    assertThat(categoryOptionCombo, is(notNullValue()));
    assertThat(categoryOptionCombo.getName(), is(coc.getName()));
}
Also used : CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16