use of org.hisp.dhis.period.Period in project dhis2-core by dhis2.
the class ReportTable method getColumnName.
/**
* Generates a column name based on short-names of the argument objects.
* Null arguments are ignored in the name.
* <p/>
* The period column name must be static when on columns so it can be
* re-used in reports, hence the name property is used which will be formatted
* only when the period dimension is on rows.
*/
public static String getColumnName(List<DimensionalItemObject> objects) {
StringBuffer buffer = new StringBuffer();
for (DimensionalItemObject object : objects) {
if (object != null && object instanceof Period) {
buffer.append(object.getName()).append(SEPARATOR);
} else {
buffer.append(object != null ? (object.getShortName() + SEPARATOR) : EMPTY);
}
}
String column = columnEncode(buffer.toString());
return column.length() > 0 ? column.substring(0, column.lastIndexOf(SEPARATOR)) : TOTAL_COLUMN_NAME;
}
use of org.hisp.dhis.period.Period in project dhis2-core by dhis2.
the class HibernateDataValueStore method getDataValue.
@Override
public DataValue getDataValue(DataElement dataElement, Period period, OrganisationUnit source, DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo) {
Session session = sessionFactory.getCurrentSession();
Period storedPeriod = periodStore.reloadPeriod(period);
if (storedPeriod == null) {
return null;
}
return (DataValue) session.createCriteria(DataValue.class).add(Restrictions.eq("dataElement", dataElement)).add(Restrictions.eq("period", storedPeriod)).add(Restrictions.eq("source", source)).add(Restrictions.eq("categoryOptionCombo", categoryOptionCombo)).add(Restrictions.eq("attributeOptionCombo", attributeOptionCombo)).add(Restrictions.eq("deleted", false)).uniqueResult();
}
use of org.hisp.dhis.period.Period in project dhis2-core by dhis2.
the class HibernateDataValueStore method getDataValues.
@Override
@SuppressWarnings("unchecked")
public List<DataValue> getDataValues(OrganisationUnit source, Period period, Collection<DataElement> dataElements, DataElementCategoryOptionCombo attributeOptionCombo) {
Period storedPeriod = periodStore.reloadPeriod(period);
if (storedPeriod == null || dataElements == null || dataElements.isEmpty()) {
return new ArrayList<>();
}
Session session = sessionFactory.getCurrentSession();
return session.createCriteria(DataValue.class).add(Restrictions.in("dataElement", dataElements)).add(Restrictions.eq("period", storedPeriod)).add(Restrictions.eq("source", source)).add(Restrictions.eq("attributeOptionCombo", attributeOptionCombo)).add(Restrictions.eq("deleted", false)).list();
}
use of org.hisp.dhis.period.Period in project dhis2-core by dhis2.
the class AbstractDataSetCompletenessService method getDataSetCompleteness.
@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, Collection<Integer> organisationUnitIds, int dataSetId, Set<Integer> groupIds) {
final DataSet dataSet = dataSetService.getDataSet(dataSetId);
final Period period = periodService.getPeriod(periodId);
final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
final Map<Integer, OrganisationUnit> orgUnits = Maps.uniqueIndex(organisationUnitService.getOrganisationUnits(organisationUnitIds), OrganisationUnit::getId);
final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
final List<DataSetCompletenessResult> results = new ArrayList<>();
for (final Integer unitId : organisationUnitIds) {
final OrganisationUnit unit = orgUnits.get(unitId);
final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(unit.getId());
final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
final DataSetCompletenessResult result = getDataSetCompleteness(period, periodsBetweenDates, unit, relevantSources, dataSet);
if (result.getSources() > 0) {
results.add(result);
}
}
return results;
}
use of org.hisp.dhis.period.Period in project dhis2-core by dhis2.
the class InterpretationController method writeDataSetReportInterpretation.
@RequestMapping(value = "/dataSetReport/{uid}", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void writeDataSetReportInterpretation(@PathVariable("uid") String dataSetUid, @RequestParam("pe") String isoPeriod, @RequestParam("ou") String orgUnitUid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
DataSet dataSet = idObjectManager.get(DataSet.class, dataSetUid);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist or is not accessible: " + dataSetUid));
}
Period period = PeriodType.getPeriodFromIsoString(isoPeriod);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Period identifier not valid: " + isoPeriod));
}
OrganisationUnit orgUnit = idObjectManager.get(OrganisationUnit.class, orgUnitUid);
if (orgUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Organisation unit does not exist or is not accessible: " + orgUnitUid));
}
createIntepretation(new Interpretation(dataSet, period, orgUnit, text), request, response);
}
Aggregations