Search in sources :

Example 81 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class QueryItemTest method before.

@BeforeEach
void before() {
    opA = new Option("OptionA", "CODEA");
    opA.setUid("UIDA");
    opB = new Option("OptionB", "CODEB");
    opB.setUid("UIDB");
    opC = new Option("OptionC", "CODEC");
    opC.setUid("UIDC");
    osA = new OptionSet("OptionSetA", ValueType.TEXT, Lists.newArrayList(opA, opB, opC));
    leA = new Legend("LegendA", 0d, 1d, "", "");
    leA.setUid("UIDA");
    leB = new Legend("LegendB", 1d, 2d, "", "");
    leB.setUid("UIDB");
    leC = new Legend("LegendC", 3d, 4d, "", "");
    leC.setUid("UIDC");
    lsA = new LegendSet("LegendSetA", "", Sets.newHashSet(leA, leB, leC));
    prA = new Program("ProgramA");
    prA.setUid("PRUIDA");
    prB = new Program("ProgramB");
    prB.setUid("PRUIDB");
    deA = new DataElement("DataElementA");
    deA.setOptionSet(osA);
    deB = new DataElement("DataElementB");
    deB.setLegendSets(Lists.newArrayList(lsA));
    rspA = new RepeatableStageParams();
    rspA.setStartIndex(1);
    rspA.setCount(2);
    rspB = new RepeatableStageParams();
    rspB.setStartIndex(10);
    rspB.setCount(20);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Legend(org.hisp.dhis.legend.Legend) Program(org.hisp.dhis.program.Program) Option(org.hisp.dhis.option.Option) LegendSet(org.hisp.dhis.legend.LegendSet) OptionSet(org.hisp.dhis.option.OptionSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 82 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class DimensionalObjectUtilsTest method testGetUidMapIsSchemeCodeCompositeObject.

@Test
void testGetUidMapIsSchemeCodeCompositeObject() {
    Program prA = new Program();
    prA.setUid("P123456789A");
    prA.setCode("PCodeA");
    DataElement deA = new DataElement("NameA");
    DataElement deB = new DataElement("NameB");
    deA.setUid("D123456789A");
    deB.setUid("D123456789B");
    deA.setCode("DCodeA");
    deB.setCode("DCodeB");
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    List<ProgramDataElementDimensionItem> elements = Lists.newArrayList(pdeA, pdeB);
    Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap(elements, IdScheme.CODE);
    assertEquals(2, map.size());
    assertEquals("PCodeA.DCodeA", map.get("P123456789A.D123456789A"));
    assertEquals("PCodeA.DCodeB", map.get("P123456789A.D123456789B"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) Test(org.junit.jupiter.api.Test)

Example 83 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class CategoryOptionComboTest method before.

@BeforeEach
void before() {
    jan1 = new DateTime(2000, 1, 1, 0, 0).toDate();
    jan2 = new DateTime(2000, 1, 2, 0, 0).toDate();
    jan4 = new DateTime(2000, 1, 4, 0, 0).toDate();
    jan5 = new DateTime(2000, 1, 5, 0, 0).toDate();
    jan6 = new DateTime(2000, 1, 6, 0, 0).toDate();
    optionA = new CategoryOption("optionA");
    optionB = new CategoryOption("optionB");
    optionC = new CategoryOption("optionC");
    optionB.setStartDate(jan1);
    optionB.setEndDate(jan4);
    optionC.setStartDate(jan2);
    optionC.setEndDate(jan5);
    optionComboA = new CategoryOptionCombo();
    optionComboB = new CategoryOptionCombo();
    optionComboC = new CategoryOptionCombo();
    optionComboA.setName("optionComboA");
    optionComboB.setName("optionComboB");
    optionComboC.setName("optionComboC");
    optionComboA.addCategoryOption(optionA);
    optionComboB.addCategoryOption(optionB);
    optionComboC.addCategoryOption(optionA);
    optionComboC.addCategoryOption(optionB);
    optionComboC.addCategoryOption(optionC);
    categoryComboA = new CategoryCombo();
    categoryComboB = new CategoryCombo();
    categoryComboC = new CategoryCombo();
    categoryComboA.getOptionCombos().add(optionComboA);
    categoryComboB.getOptionCombos().add(optionComboB);
    categoryComboC.getOptionCombos().add(optionComboC);
    optionComboA.setCategoryCombo(categoryComboA);
    optionComboB.setCategoryCombo(categoryComboB);
    optionComboC.setCategoryCombo(categoryComboC);
    dataElement = new DataElement("dataElementA");
    dataSetA = new DataSet("dataSetA", new DailyPeriodType());
    dataSetB = new DataSet("dataSetB", new DailyPeriodType());
    dataSetC = new DataSet("dataSetC", new DailyPeriodType());
    dataSetA.setCategoryCombo(categoryComboA);
    dataSetB.setCategoryCombo(categoryComboB);
    dataSetB.setCategoryCombo(categoryComboC);
    dataSetA.addDataSetElement(dataElement);
    dataSetB.addDataSetElement(dataElement);
    dataSetC.addDataSetElement(dataElement);
    dataSetA.setOpenPeriodsAfterCoEndDate(0);
    dataSetB.setOpenPeriodsAfterCoEndDate(1);
    dataSetC.setOpenPeriodsAfterCoEndDate(2);
    program = new Program();
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) DataSet(org.hisp.dhis.dataset.DataSet) DateTime(org.joda.time.DateTime) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 84 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class CategoryOptionTest method getAdjustedDate_Program.

@Test
void getAdjustedDate_Program() {
    CategoryOption categoryOption = new CategoryOption();
    Program program = new Program("program");
    assertNull(categoryOption.getAdjustedEndDate(program));
    categoryOption.setEndDate(new DateTime(2020, 1, 1, 0, 0).toDate());
    assertEquals(new DateTime(2020, 1, 1, 0, 0).toDate(), categoryOption.getAdjustedEndDate(program));
    program.setOpenDaysAfterCoEndDate(3);
    assertEquals(new DateTime(2020, 1, 4, 0, 0).toDate(), categoryOption.getAdjustedEndDate(program));
}
Also used : Program(org.hisp.dhis.program.Program) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 85 with Program

use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.

the class EventAnalyticsServiceTest method testDimensionRestrictionSuccessfully.

@Test
void testDimensionRestrictionSuccessfully() {
    // Given
    // A program
    Program aProgram = createProgram('B', null, null, Sets.newHashSet(ouA, ouB), null);
    aProgram.setUid("aProgram123");
    idObjectManager.save(aProgram);
    // The category options
    CategoryOption coA = createCategoryOption('A');
    CategoryOption coB = createCategoryOption('B');
    categoryService.addCategoryOption(coA);
    categoryService.addCategoryOption(coB);
    // The categories
    Category caA = createCategory('A', coA);
    Category caB = createCategory('B', coB);
    categoryService.addCategory(caA);
    categoryService.addCategory(caB);
    // The constraints
    Set<Category> catDimensionConstraints = Sets.newHashSet(caA, caB);
    // The user
    User user = createUser("A", "F_VIEW_EVENT_ANALYTICS");
    user.setCatDimensionConstraints(catDimensionConstraints);
    userService.addUser(user);
    enableDataSharing(user, aProgram, AccessStringHelper.DATA_READ_WRITE);
    idObjectManager.update(user);
    injectSecurityContext(user);
    // All events in program B - 2017
    EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(aProgram).build();
    // When
    Grid aggregatedDataValueGrid = eventAnalyticsService.getAggregatedEventData(events_2017_params);
    // Then
    boolean noCategoryRestrictionExceptionIsThrown = true;
    assertThat(aggregatedDataValueGrid, is(notNullValue()));
    assert (noCategoryRestrictionExceptionIsThrown);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Program(org.hisp.dhis.program.Program) Category(org.hisp.dhis.category.Category) User(org.hisp.dhis.user.User) Grid(org.hisp.dhis.common.Grid) CategoryOption(org.hisp.dhis.category.CategoryOption) Test(org.junit.jupiter.api.Test)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37