Search in sources :

Example 66 with Program

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

the class AnalyticsTableTest method testGetTablePartitionName.

@Test
void testGetTablePartitionName() {
    Program program = new Program("ProgramA", "DescriptionA");
    program.setUid("UIDA");
    Period periodA = new YearlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate());
    Period periodB = new YearlyPeriodType().createPeriod(new DateTime(2015, 1, 1, 0, 0).toDate());
    AnalyticsTable tableA = new AnalyticsTable(AnalyticsTableType.EVENT, Lists.newArrayList(), Lists.newArrayList(), program);
    tableA.addPartitionTable(2014, periodA.getStartDate(), periodA.getEndDate());
    tableA.addPartitionTable(2015, periodB.getStartDate(), periodB.getEndDate());
    AnalyticsTablePartition partitionA = tableA.getTablePartitions().get(0);
    AnalyticsTablePartition partitionB = tableA.getTablePartitions().get(1);
    assertNotNull(partitionA);
    assertNotNull(partitionB);
    assertEquals("analytics_event_uida_2014", partitionA.getTableName());
    assertEquals("analytics_event_uida_2015", partitionB.getTableName());
    assertEquals("analytics_event_temp_uida_2014", partitionA.getTempTableName());
    assertEquals("analytics_event_temp_uida_2015", partitionB.getTempTableName());
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Period(org.hisp.dhis.period.Period) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 67 with Program

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

the class AnalyticsTableTest method testGetTableName.

@Test
void testGetTableName() {
    Program program = new Program("ProgramA", "DescriptionA");
    program.setUid("UIDA");
    AnalyticsTable tableA = new AnalyticsTable(AnalyticsTableType.EVENT, Lists.newArrayList(), Lists.newArrayList(), program);
    assertEquals("analytics_event_uida", tableA.getTableName());
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Test(org.junit.jupiter.api.Test)

Example 68 with Program

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

the class JdbcEnrollmentAnalyticsTableManagerTest method verifyTeiTypeOrgUnitFetchesOuUidWhenPopulatingEventAnalyticsTable.

@Test
void verifyTeiTypeOrgUnitFetchesOuUidWhenPopulatingEventAnalyticsTable() {
    ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
    when(databaseInfo.isSpatialSupport()).thenReturn(true);
    Program p1 = createProgram('A');
    TrackedEntityAttribute tea = createTrackedEntityAttribute('a', ValueType.ORGANISATION_UNIT);
    tea.setId(9999);
    ProgramTrackedEntityAttribute programTrackedEntityAttribute = createProgramTrackedEntityAttribute(p1, tea);
    p1.setProgramAttributes(Lists.newArrayList(programTrackedEntityAttribute));
    when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Lists.newArrayList(p1));
    AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(2).withStartTime(START_TIME).build();
    subject.populateTable(params, PartitionUtils.getTablePartitions(subject.getAnalyticsTables(params)).get(0));
    verify(jdbcTemplate).execute(sql.capture());
    String ouQuery = "(select ou.%s from organisationunit ou where ou.uid = " + "(select value from trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid and " + "trackedentityattributeid=9999)) as \"" + tea.getUid() + "\"";
    assertThat(sql.getValue(), containsString(String.format(ouQuery, "uid")));
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) DhisConvenienceTest.createTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Example 69 with Program

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

the class DefaultProgramStageInstanceFilterService method validate.

// -------------------------------------------------------------------------
// ProgramStageInstanceFilterService implementation
// -------------------------------------------------------------------------
@Override
public List<String> validate(ProgramStageInstanceFilter programStageInstanceFilter) {
    List<String> errors = new ArrayList<>();
    if (programStageInstanceFilter.getProgram() == null) {
        errors.add("Program should be specified for event filters.");
    } else {
        Program pr = programService.getProgram(programStageInstanceFilter.getProgram());
        if (pr == null) {
            errors.add("Program is specified but does not exist: " + programStageInstanceFilter.getProgram());
        }
    }
    if (programStageInstanceFilter.getProgramStage() != null) {
        ProgramStage ps = programStageService.getProgramStage(programStageInstanceFilter.getProgramStage());
        if (ps == null) {
            errors.add("Program stage is specified but does not exist: " + programStageInstanceFilter.getProgramStage());
        }
    }
    EventQueryCriteria eventQC = programStageInstanceFilter.getEventQueryCriteria();
    if (eventQC != null) {
        if (eventQC.getOrganisationUnit() != null) {
            OrganisationUnit ou = organisationUnitService.getOrganisationUnit(eventQC.getOrganisationUnit());
            if (ou == null) {
                errors.add("Org unit is specified but does not exist: " + eventQC.getOrganisationUnit());
            }
        }
        if (eventQC.getAssignedUserMode() != null && eventQC.getAssignedUsers() != null && !eventQC.getAssignedUsers().isEmpty() && !eventQC.getAssignedUserMode().equals(AssignedUserSelectionMode.PROVIDED)) {
            errors.add("Assigned User uid(s) cannot be specified if selectionMode is not PROVIDED");
        }
        if (eventQC.getEvents() != null && !eventQC.getEvents().isEmpty() && eventQC.getDataFilters() != null && !eventQC.getDataFilters().isEmpty()) {
            errors.add("Event UIDs and filters can not be specified at the same time");
        }
        if (eventQC.getDisplayColumnOrder() != null && eventQC.getDisplayColumnOrder().size() > 0 && (new HashSet<String>(eventQC.getDisplayColumnOrder())).size() < eventQC.getDisplayColumnOrder().size()) {
            errors.add("Event query criteria can not have duplicate column ordering fields");
        }
    }
    return errors;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) HashSet(java.util.HashSet)

Example 70 with Program

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

the class OrganisationUnitServiceTest method testAddAndDelOrganisationUnitWithPrgUserAndDataSet.

@Test
void testAddAndDelOrganisationUnitWithPrgUserAndDataSet() {
    OrganisationUnit organisationUnit1 = createOrganisationUnit('A');
    Program program = createProgram('A');
    User user = createUser('A');
    DataSet dataSet = createDataSet('A');
    long id1 = organisationUnitService.addOrganisationUnit(organisationUnit1);
    long programId = programService.addProgram(program);
    long userId = userService.addUser(user);
    long dataSetId = dataSetService.addDataSet(dataSet);
    program.getOrganisationUnits().add(organisationUnit1);
    organisationUnit1.getPrograms().add(program);
    user.addOrganisationUnit(organisationUnit1);
    organisationUnit1.addUser(user);
    dataSet.addOrganisationUnit(organisationUnit1);
    organisationUnit1.addDataSet(dataSet);
    organisationUnitService.updateOrganisationUnit(organisationUnit1);
    programService.updateProgram(program);
    userService.updateUser(user);
    dataSetService.updateDataSet(dataSet);
    assertNotNull(organisationUnitService.getOrganisationUnit(id1));
    organisationUnitService.deleteOrganisationUnit(organisationUnitService.getOrganisationUnit(id1));
    assertNull(organisationUnitService.getOrganisationUnit(id1));
    assertTrue(programService.getProgram(programId).getOrganisationUnits().isEmpty());
    assertTrue(userService.getUser(userId).getOrganisationUnits().isEmpty());
    assertTrue(dataSetService.getDataSet(dataSetId).getSources().isEmpty());
}
Also used : Program(org.hisp.dhis.program.Program) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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