Search in sources :

Example 21 with MonthlyPeriodType

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

the class ReportController method getReport.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getReport(HttpServletRequest request, HttpServletResponse response, String uid, String organisationUnitUid, String isoPeriod, Date date, String type, String contentType, boolean attachment) throws Exception {
    Report report = reportService.getReport(uid);
    if (report == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
    }
    if (organisationUnitUid == null && report.hasReportTable() && report.getReportTable().hasReportParams() && report.getReportTable().getReportParams().isOrganisationUnitSet()) {
        organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
    }
    if (report.isTypeHtml()) {
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, report.getCacheStrategy());
        reportService.renderHtmlReport(response.getWriter(), uid, date, organisationUnitUid);
    } else {
        date = date != null ? date : new DateTime().minusMonths(1).toDate();
        Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString(isoPeriod) : new MonthlyPeriodType().createPeriod(date);
        String filename = CodecUtils.filenameEncode(report.getName()) + "." + type;
        contextUtils.configureResponse(response, contentType, report.getCacheStrategy(), filename, attachment);
        JasperPrint print = reportService.renderReport(response.getOutputStream(), uid, period, organisationUnitUid, type);
        if ("html".equals(type)) {
            request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
        }
    }
}
Also used : Report(org.hisp.dhis.report.Report) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Period(org.hisp.dhis.period.Period) DateTime(org.joda.time.DateTime)

Example 22 with MonthlyPeriodType

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

the class EventQueryParamsTest method testReplacePeriodsWithStartEndDates.

@Test
public void testReplacePeriodsWithStartEndDates() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 5, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 6, 1, 0, 0).toDate()));
    EventQueryParams params = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, periods)).build();
    assertNull(params.getStartDate());
    assertNull(params.getEndDate());
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    assertEquals(new DateTime(2014, 4, 1, 0, 0).toDate(), params.getStartDate());
    assertEquals(new DateTime(2014, 6, 30, 0, 0).toDate(), params.getEndDate());
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 23 with MonthlyPeriodType

use of org.hisp.dhis.period.MonthlyPeriodType 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 24 with MonthlyPeriodType

use of org.hisp.dhis.period.MonthlyPeriodType 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 25 with MonthlyPeriodType

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

the class DhisConvenienceTest method createDataSet.

/**
     * @param uniqueCharacter A unique character to identify the object.
     */
public static DataSet createDataSet(char uniqueCharacter) {
    DataSet dataSet = createDataSet(uniqueCharacter, null);
    dataSet.setPeriodType(new MonthlyPeriodType());
    return dataSet;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType)

Aggregations

MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)33 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)12 Test (org.junit.Test)12 Period (org.hisp.dhis.period.Period)11 PeriodType (org.hisp.dhis.period.PeriodType)11 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)10 DataSet (org.hisp.dhis.dataset.DataSet)8 ArrayList (java.util.ArrayList)7 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)6 DateTime (org.joda.time.DateTime)5 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)2 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)2 Indicator (org.hisp.dhis.indicator.Indicator)2