Search in sources :

Example 51 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class QueryPlannerTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    itA = createIndicatorType('A');
    idObjectManager.save(itA);
    inA = createIndicator('A', itA);
    inB = createIndicator('B', itA);
    idObjectManager.save(inA);
    idObjectManager.save(inB);
    prA = createProgram('A');
    idObjectManager.save(prA);
    deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
    deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM);
    deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
    deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
    deE = createDataElement('E', ValueType.TEXT, AggregationType.NONE);
    deF = createDataElement('F', ValueType.TEXT, AggregationType.NONE);
    deG = createDataElement('G', ValueType.INTEGER, AggregationType.SUM);
    deH = createDataElement('H', ValueType.INTEGER, AggregationType.SUM);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deE);
    dataElementService.addDataElement(deF);
    dataElementService.addDataElement(deG);
    dataElementService.addDataElement(deH);
    pdeA = new ProgramDataElementDimensionItem(prA, deA);
    pdeB = new ProgramDataElementDimensionItem(prA, deB);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    DataSet dsC = createDataSet('C', pt);
    DataSet dsD = createDataSet('D', pt);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
    dataSetService.addDataSet(dsC);
    dataSetService.addDataSet(dsD);
    rrA = new ReportingRate(dsA);
    rrB = new ReportingRate(dsB);
    rrC = new ReportingRate(dsC);
    rrD = new ReportingRate(dsD);
    peA = PeriodType.getPeriodFromIsoString("201501");
    peB = PeriodType.getPeriodFromIsoString("201502");
    coc = categoryService.getDefaultDataElementCategoryOptionCombo();
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    ouD = createOrganisationUnit('D');
    ouE = createOrganisationUnit('E');
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    degA = createDataElementGroup('A');
    degA.addDataElement(deA);
    degA.addDataElement(deB);
    dataElementService.addDataElementGroup(degA);
    dgsA = createDataElementGroupSet('A');
    dgsA.getMembers().add(degA);
    dataElementService.addDataElementGroupSet(dgsA);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate)

Example 52 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class SpringDataValueSetStore method writeDataValueSet.

private void writeDataValueSet(String sql, DataExportParams params, Date completeDate, final DataValueSet dataValueSet) {
    if (params.isSingleDataValueSet()) {
        IdSchemes idScheme = params.getOutputIdSchemes() != null ? params.getOutputIdSchemes() : new IdSchemes();
        IdScheme ouScheme = idScheme.getOrgUnitIdScheme();
        IdScheme dataSetScheme = idScheme.getDataSetIdScheme();
        dataValueSet.setDataSet(params.getFirstDataSet().getPropertyValue(dataSetScheme));
        dataValueSet.setCompleteDate(getLongGmtDateString(completeDate));
        dataValueSet.setPeriod(params.getFirstPeriod().getIsoDate());
        dataValueSet.setOrgUnit(params.getFirstOrganisationUnit().getPropertyValue(ouScheme));
    }
    final Calendar calendar = PeriodType.getCalendar();
    jdbcTemplate.query(sql, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            DataValue dataValue = dataValueSet.getDataValueInstance();
            PeriodType pt = PeriodType.getPeriodTypeByName(rs.getString("ptname"));
            boolean deleted = rs.getBoolean("deleted");
            dataValue.setDataElement(rs.getString("deid"));
            dataValue.setPeriod(pt.createPeriod(rs.getDate("pestart"), calendar).getIsoDate());
            dataValue.setOrgUnit(rs.getString("ouid"));
            dataValue.setCategoryOptionCombo(rs.getString("cocid"));
            dataValue.setAttributeOptionCombo(rs.getString("aocid"));
            dataValue.setValue(rs.getString("value"));
            dataValue.setStoredBy(rs.getString("storedby"));
            dataValue.setCreated(getLongGmtDateString(rs.getTimestamp("created")));
            dataValue.setLastUpdated(getLongGmtDateString(rs.getTimestamp("lastupdated")));
            dataValue.setComment(rs.getString("comment"));
            dataValue.setFollowup(rs.getBoolean("followup"));
            if (deleted) {
                dataValue.setDeleted(deleted);
            }
            dataValue.close();
        }
    });
    dataValueSet.close();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) IdSchemes(org.hisp.dhis.common.IdSchemes) SQLException(java.sql.SQLException) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) Calendar(org.hisp.dhis.calendar.Calendar) ResultSet(java.sql.ResultSet) IdScheme(org.hisp.dhis.common.IdScheme) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Example 53 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class AdxPeriod method parse.

public static Period parse(String periodString) throws AdxException {
    String[] tokens = periodString.split("/");
    if (tokens.length != 2) {
        throw new AdxException(periodString + " not in valid <date>/<duration> format");
    }
    try {
        Period period = null;
        PeriodType periodType = null;
        Date startDate = DateUtils.getMediumDate(tokens[0]);
        Calendar cal = Calendar.getInstance();
        cal.setTime(startDate);
        Duration duration = Duration.valueOf(tokens[1]);
        switch(duration) {
            case P1D:
                periodType = new DailyPeriodType();
                break;
            case P7D:
                periodType = new WeeklyPeriodType();
                break;
            case P1M:
                periodType = new MonthlyPeriodType();
                break;
            case P2M:
                periodType = new BiMonthlyPeriodType();
                break;
            case P1Q:
                periodType = new QuarterlyPeriodType();
                break;
            case P6M:
                switch(cal.get(Calendar.MONTH)) {
                    case 0:
                        periodType = new SixMonthlyPeriodType();
                        break;
                    case 6:
                        periodType = new SixMonthlyAprilPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + "is invalid sixmonthly type");
                }
            case P1Y:
                switch(cal.get(Calendar.MONTH)) {
                    case 0:
                        periodType = new YearlyPeriodType();
                        break;
                    case 3:
                        periodType = new FinancialAprilPeriodType();
                        break;
                    case 6:
                        periodType = new FinancialJulyPeriodType();
                        break;
                    case 9:
                        periodType = new FinancialOctoberPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + "is invalid yearly type");
                }
        }
        if (periodType != null) {
            period = periodType.createPeriod(startDate);
        } else {
            throw new AdxException("Failed to create period type from " + duration);
        }
        return period;
    } catch (IllegalArgumentException ex) {
        throw new AdxException(tokens[1] + " is not a supported duration type");
    }
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) Calendar(java.util.Calendar) Period(org.hisp.dhis.period.Period) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Date(java.util.Date) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType)

Example 54 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class HibernatePeriodStore method reloadPeriodType.

@Override
public PeriodType reloadPeriodType(PeriodType periodType) {
    Session session = sessionFactory.getCurrentSession();
    if (periodType == null || session.contains(periodType)) {
        return periodType;
    }
    PeriodType reloadedPeriodType = getPeriodType(periodType.getClass());
    if (reloadedPeriodType == null) {
        throw new InvalidIdentifierReferenceException("The PeriodType referenced by the Period is not in database: " + periodType.getName());
    }
    return reloadedPeriodType;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException) Session(org.hibernate.Session)

Example 55 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class ChartStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
    // ---------------------------------------------------------------------
    // Indicator
    // ---------------------------------------------------------------------
    IndicatorType indicatorType = createIndicatorType('A');
    indicatorA = createIndicator('A', indicatorType);
    indicatorB = createIndicator('B', indicatorType);
    indicatorC = createIndicator('C', indicatorType);
    indicatorService.addIndicatorType(indicatorType);
    indicatorService.addIndicator(indicatorA);
    indicatorService.addIndicator(indicatorB);
    indicatorService.addIndicator(indicatorC);
    List<Indicator> indicators = new ArrayList<>();
    indicators.add(indicatorA);
    indicators.add(indicatorB);
    indicators.add(indicatorC);
    // ---------------------------------------------------------------------
    // Period
    // ---------------------------------------------------------------------
    PeriodType periodType = new MonthlyPeriodType();
    periodA = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 1, 2));
    periodB = createPeriod(periodType, getDate(2000, 1, 3), getDate(2000, 1, 4));
    periodC = createPeriod(periodType, getDate(2000, 1, 5), getDate(2000, 1, 6));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    periodService.addPeriod(periodC);
    List<Period> periods = new ArrayList<>();
    periods.add(periodA);
    periods.add(periodB);
    periods.add(periodC);
    // ---------------------------------------------------------------------
    // OrganisationUnit
    // ---------------------------------------------------------------------
    unitA = createOrganisationUnit('A');
    unitB = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(unitA);
    organisationUnitService.addOrganisationUnit(unitB);
    List<OrganisationUnit> units = new ArrayList<>();
    units.add(unitA);
    units.add(unitB);
    // units.add( unitC );
    chartA = createChart('A', indicators, periods, units);
    chartB = createChart('B', indicators, periods, units);
    chartC = createChart('C', indicators, periods, units);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IndicatorType(org.hisp.dhis.indicator.IndicatorType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Indicator(org.hisp.dhis.indicator.Indicator)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)67 Period (org.hisp.dhis.period.Period)21 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)13 ArrayList (java.util.ArrayList)12 DataSet (org.hisp.dhis.dataset.DataSet)12 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)6 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)6 ProgramStage (org.hisp.dhis.program.ProgramStage)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4