Search in sources :

Example 16 with Program

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

the class JdbcEventAnalyticsTableManager method getTables.

@Override
@Transactional
public List<AnalyticsTable> getTables(Date earliest) {
    log.info(String.format("Get tables using earliest: %s, spatial support: %b", earliest, databaseInfo.isSpatialSupport()));
    List<AnalyticsTable> tables = new UniqueArrayList<>();
    Calendar calendar = PeriodType.getCalendar();
    String baseName = getTableName();
    List<Program> programs = idObjectManager.getAllNoAcl(Program.class);
    for (Program program : programs) {
        List<Integer> dataYears = getDataYears(program, earliest);
        Collections.sort(dataYears);
        for (Integer year : dataYears) {
            Period period = PartitionUtils.getPeriod(calendar, year);
            AnalyticsTable table = new AnalyticsTable(baseName, null, period, program);
            List<AnalyticsTableColumn> dimensionColumns = getDimensionColumns(table);
            table.setDimensionColumns(dimensionColumns);
            tables.add(table);
        }
    }
    return tables;
}
Also used : Program(org.hisp.dhis.program.Program) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) Calendar(org.hisp.dhis.calendar.Calendar) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Program

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

the class AnalyticsUtilsTest method testGetByDataDimensionType.

@Test
public void testGetByDataDimensionType() {
    Program prA = createProgram('A');
    DataElement deA = createDataElement('A', new DataElementCategoryCombo());
    DataElement deB = createDataElement('B', new DataElementCategoryCombo());
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
    ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
    List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
    assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
    assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
    assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 18 with Program

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

the class DefaultTrackedEntityAttributeService method getTrackedEntityAttributesWithoutProgram.

@Override
public List<TrackedEntityAttribute> getTrackedEntityAttributesWithoutProgram() {
    List<TrackedEntityAttribute> result = new ArrayList<>(attributeStore.getAll());
    List<Program> programs = programService.getAllPrograms();
    for (Program program : programs) {
        result.removeAll(program.getProgramAttributes());
    }
    return result;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ArrayList(java.util.ArrayList)

Example 19 with Program

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

the class DefaultTrackedEntityInstanceService method getFromUrl.

@Override
public TrackedEntityInstanceQueryParams getFromUrl(String query, Set<String> attribute, Set<String> filter, Set<String> ou, OrganisationUnitSelectionMode ouMode, String program, ProgramStatus programStatus, Boolean followUp, Date lastUpdatedStartDate, Date lastUpdatedEndDate, Date programEnrollmentStartDate, Date programEnrollmentEndDate, Date programIncidentStartDate, Date programIncidentEndDate, String trackedEntity, EventStatus eventStatus, Date eventStartDate, Date eventEndDate, boolean skipMeta, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, boolean includeDeleted, List<String> orders) {
    TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
    QueryFilter queryFilter = getQueryFilter(query);
    if (attribute != null) {
        for (String attr : attribute) {
            QueryItem it = getQueryItem(attr);
            params.getAttributes().add(it);
        }
    }
    if (filter != null) {
        for (String filt : filter) {
            QueryItem it = getQueryItem(filt);
            params.getFilters().add(it);
        }
    }
    if (ou != null) {
        for (String orgUnit : ou) {
            OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
            if (organisationUnit == null) {
                throw new IllegalQueryException("Organisation unit does not exist: " + orgUnit);
            }
            params.getOrganisationUnits().add(organisationUnit);
        }
    }
    Program pr = program != null ? programService.getProgram(program) : null;
    if (program != null && pr == null) {
        throw new IllegalQueryException("Program does not exist: " + program);
    }
    TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity(trackedEntity) : null;
    if (trackedEntity != null && te == null) {
        throw new IllegalQueryException("Tracked entity does not exist: " + program);
    }
    params.setQuery(queryFilter).setProgram(pr).setProgramStatus(programStatus).setFollowUp(followUp).setLastUpdatedStartDate(lastUpdatedStartDate).setLastUpdatedEndDate(lastUpdatedEndDate).setProgramEnrollmentStartDate(programEnrollmentStartDate).setProgramEnrollmentEndDate(programEnrollmentEndDate).setProgramIncidentStartDate(programIncidentStartDate).setProgramIncidentEndDate(programIncidentEndDate).setTrackedEntity(te).setOrganisationUnitMode(ouMode).setEventStatus(eventStatus).setEventStartDate(eventStartDate).setEventEndDate(eventEndDate).setSkipMeta(skipMeta).setPage(page).setPageSize(pageSize).setTotalPages(totalPages).setSkipPaging(skipPaging).setIncludeDeleted(includeDeleted).setOrders(orders);
    return params;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryFilter(org.hisp.dhis.common.QueryFilter) Program(org.hisp.dhis.program.Program) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)

Example 20 with Program

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

the class CreateSMSCommandForm method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SMSCommand command = new SMSCommand();
    command.setName(name);
    command.setParserType(parserType);
    if (parserType.equals(ParserType.KEY_VALUE_PARSER) || parserType.equals(ParserType.J2ME_PARSER)) {
        DataSet dataset = dataSetService.getDataSet(selectedDataSetID);
        command.setDataset(dataset);
    } else if (parserType.equals(ParserType.ALERT_PARSER) || parserType.equals(ParserType.UNREGISTERED_PARSER)) {
        UserGroup userGroup = new UserGroup();
        userGroup = userGroupService.getUserGroup(userGroupID);
        command.setUserGroup(userGroup);
    } else if (parserType.equals(ParserType.TRACKED_ENTITY_REGISTRATION_PARSER)) {
        Program program = programService.getProgram(selectedProgramId);
        command.setProgram(program);
    } else if (parserType.equals(ParserType.EVENT_REGISTRATION_PARSER)) {
        Program program = programService.getProgram(selectedProgramIdWithoutRegistration);
        command.setProgram(program);
        command.setProgramStage(program.getProgramStages().iterator().next());
    }
    smsCommandService.save(command);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataSet(org.hisp.dhis.dataset.DataSet) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) UserGroup(org.hisp.dhis.user.UserGroup)

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