use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class DefaultAdxDataService method getFromUrl.
// -------------------------------------------------------------------------
// Public methods
// -------------------------------------------------------------------------
@Override
public DataExportParams getFromUrl(Set<String> dataSets, Set<String> periods, Date startDate, Date endDate, Set<String> organisationUnits, boolean includeChildren, boolean includeDeleted, Date lastUpdated, Integer limit, IdSchemes outputIdSchemes) {
DataExportParams params = new DataExportParams();
if (dataSets != null) {
params.getDataSets().addAll(identifiableObjectManager.getByCode(DataSet.class, dataSets));
}
if (periods != null && !periods.isEmpty()) {
params.getPeriods().addAll(periodService.reloadIsoPeriods(new ArrayList<>(periods)));
} else if (startDate != null && endDate != null) {
params.setStartDate(startDate);
params.setEndDate(endDate);
}
if (organisationUnits != null) {
params.getOrganisationUnits().addAll(identifiableObjectManager.getByCode(OrganisationUnit.class, organisationUnits));
}
params.setIncludeChildren(includeChildren);
params.setIncludeDeleted(includeDeleted);
params.setLastUpdated(lastUpdated);
params.setLimit(limit);
params.setOutputIdSchemes(outputIdSchemes);
return params;
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getDataSetValues.
@Override
public DataSetValueList getDataSetValues(OrganisationUnit unit, DataSetList dataSetList) throws NotAllowedException {
DataSetValueList dataSetValueList = new DataSetValueList();
List<DataSet> dataSets = dataSetList.getCurrentDataSets();
for (DataSet dataSet : dataSets) {
log.info("Getting DataSetValue for: " + dataSet.getName());
org.hisp.dhis.dataset.DataSet apiDataSet = dataSetService.getDataSet(dataSet.getId());
Vector<String> periods = PeriodUtil.generatePeriods(dataSet.getPeriodType());
if (periods != null) {
for (int i = 0; i < periods.size(); i++) {
Period period = getPeriod(periods.elementAt(i), apiDataSet.getPeriodType());
if (period != null) {
Set<org.hisp.dhis.dataelement.DataElement> dataElements = apiDataSet.getDataElements();
Collection<org.hisp.dhis.datavalue.DataValue> dataValues = dataValueService.getDataValues(new DataExportParams().setDataElements(dataElements).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(unit)));
if (dataValues != null && !dataValues.isEmpty()) {
DataSetValue dataSetValue = new DataSetValue();
dataSetValue.setId(dataSet.getId());
dataSetValue.setName(dataSet.getName());
dataSetValue.setPeriodName(periods.elementAt(i));
dataSetValue.setCompleted(true);
for (org.hisp.dhis.datavalue.DataValue dataValue : dataValues) {
DataValue dv = new DataValue();
dv.setCategoryOptComboID(dataValue.getCategoryOptionCombo().getId());
dv.setClientVersion(dataSet.getClientVersion());
dv.setId(dataValue.getDataElement().getId());
dv.setValue(dataValue.getValue());
dataSetValue.getDataValues().add(dv);
}
dataSetValueList.getDataSetValues().add(dataSetValue);
}
}
}
}
}
log.info("Retrieved Data value set: " + unit.getName() + ", " + dataSetList.getName());
return dataSetValueList;
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class FormUtilsImpl method getDataValueMap.
@Override
public Map<String, String> getDataValueMap(OrganisationUnit organisationUnit, DataSet dataSet, Period period) {
Map<String, String> dataValueMap = new HashMap<>();
List<DataValue> values = dataValueService.getDataValues(new DataExportParams().setDataElements(dataSet.getDataElements()).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(organisationUnit)));
for (DataValue dataValue : values) {
DataElement dataElement = dataValue.getDataElement();
DataElementCategoryOptionCombo optionCombo = dataValue.getCategoryOptionCombo();
String key = String.format("DE%dOC%d", dataElement.getId(), optionCombo.getId());
String value = dataValue.getValue();
dataValueMap.put(key, value);
}
return dataValueMap;
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class HibernateDataValueStore method getDataValues.
// -------------------------------------------------------------------------
// Collections of DataValues
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public List<DataValue> getDataValues(DataExportParams params) {
Set<DataElement> dataElements = params.getAllDataElements();
Set<OrganisationUnit> organisationUnits = params.getAllOrganisationUnits();
// ---------------------------------------------------------------------
// HQL parameters
// ---------------------------------------------------------------------
String hql = "select dv from DataValue dv " + "inner join dv.dataElement de " + "inner join dv.period pe " + "inner join dv.source ou " + "inner join dv.categoryOptionCombo co " + "inner join dv.attributeOptionCombo ao " + "where de.id in (:dataElements) ";
if (params.hasPeriods()) {
hql += "and pe.id in (:periods) ";
} else if (params.hasStartEndDate()) {
hql += "and (pe.startDate >= :startDate and pe.endDate < :endDate) ";
}
if (params.isIncludeChildrenForOrganisationUnits()) {
hql += "and (";
for (OrganisationUnit unit : params.getOrganisationUnits()) {
hql += "ou.path like '" + unit.getPath() + "%' or ";
}
hql = TextUtils.removeLastOr(hql);
hql += ") ";
} else if (!organisationUnits.isEmpty()) {
hql += "and ou.id in (:orgUnits) ";
}
if (params.hasAttributeOptionCombos()) {
hql += "and ao.id in (:attributeOptionCombos) ";
}
if (params.hasLastUpdated()) {
hql += "and dv.lastUpdated >= :lastUpdated ";
}
if (!params.isIncludeDeleted()) {
hql += "and dv.deleted is false ";
}
// ---------------------------------------------------------------------
// Query parameters
// ---------------------------------------------------------------------
Query query = sessionFactory.getCurrentSession().createQuery(hql).setParameterList("dataElements", getIdentifiers(dataElements));
if (params.hasPeriods()) {
Set<Period> periods = params.getPeriods().stream().map(p -> periodStore.reloadPeriod(p)).collect(Collectors.toSet());
query.setParameterList("periods", getIdentifiers(periods));
} else if (params.hasStartEndDate()) {
query.setDate("startDate", params.getStartDate()).setDate("endDate", params.getEndDate());
}
if (!params.isIncludeChildrenForOrganisationUnits() && !organisationUnits.isEmpty()) {
query.setParameterList("orgUnits", getIdentifiers(organisationUnits));
}
if (params.hasAttributeOptionCombos()) {
query.setParameterList("attributeOptionCombos", getIdentifiers(params.getAttributeOptionCombos()));
}
if (params.hasLastUpdated()) {
query.setDate("lastUpdated", params.getLastUpdated());
}
if (params.hasLimit()) {
query.setMaxResults(params.getLimit());
}
return query.list();
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class SpringDataValueSetStore method writeDataValueSetJson.
@Override
public void writeDataValueSetJson(Date lastUpdated, OutputStream outputStream, IdSchemes idSchemes) {
String deScheme = idSchemes.getDataElementIdScheme().getIdentifiableString().toLowerCase();
String ouScheme = idSchemes.getOrgUnitIdScheme().getIdentifiableString().toLowerCase();
String ocScheme = idSchemes.getCategoryOptionComboIdScheme().getIdentifiableString().toLowerCase();
DataValueSet dataValueSet = new StreamingJsonDataValueSet(outputStream);
final String sql = "select de." + deScheme + " as deid, pe.startdate as pestart, pt.name as ptname, ou." + ouScheme + " as ouid, " + "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " + "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup, dv.deleted " + "from datavalue dv " + "join dataelement de on (dv.dataelementid=de.dataelementid) " + "join period pe on (dv.periodid=pe.periodid) " + "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " + "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " + "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " + "join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " + "where dv.lastupdated >= '" + DateUtils.getLongDateString(lastUpdated) + "'";
writeDataValueSet(sql, new DataExportParams(), null, dataValueSet);
}
Aggregations