Search in sources :

Example 1 with Period

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;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Period(org.hisp.dhis.period.Period)

Example 2 with Period

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();
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period) Session(org.hibernate.Session)

Example 3 with Period

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();
}
Also used : ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Session(org.hibernate.Session)

Example 4 with Period

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;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Period

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Period (org.hisp.dhis.period.Period)341 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)167 ArrayList (java.util.ArrayList)87 DataElement (org.hisp.dhis.dataelement.DataElement)80 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)72 Date (java.util.Date)68 Test (org.junit.jupiter.api.Test)67 DataSet (org.hisp.dhis.dataset.DataSet)59 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)45 DataValue (org.hisp.dhis.datavalue.DataValue)41 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)35 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)34 PeriodType (org.hisp.dhis.period.PeriodType)34 User (org.hisp.dhis.user.User)34 List (java.util.List)27 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)27 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)26 HashMap (java.util.HashMap)23 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22