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);
}
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();
}
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");
}
}
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;
}
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);
}
Aggregations