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 GetDataValuesForDataSetAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
// ---------------------------------------------------------------------
// Validation
// ---------------------------------------------------------------------
User currentUser = currentUserService.getCurrentUser();
DataSet dataSet = dataSetService.getDataSet(dataSetId);
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
if (organisationUnit == null || period == null || dataSet == null) {
log.warn("Illegal input, org unit: " + organisationUnit + ", period: " + period + ", data set: " + dataSet);
return SUCCESS;
}
Set<OrganisationUnit> children = organisationUnit.getChildren();
// ---------------------------------------------------------------------
// Attributes
// ---------------------------------------------------------------------
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
// ---------------------------------------------------------------------
// Data values & Min-max data elements
// ---------------------------------------------------------------------
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(organisationUnit, dataSet.getDataElements()));
if (!multiOrganisationUnit) {
dataValues.addAll(dataValueService.getDataValues(new DataExportParams().setDataElements(dataSet.getDataElements()).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(organisationUnit)).setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo))));
} else {
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
dataValues.addAll(dataValueService.getDataValues(new DataExportParams().setDataElements(dataSet.getDataElements()).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(ou)).setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo))));
minMaxDataElements.addAll(minMaxDataElementService.getMinMaxDataElements(ou, dataSet.getDataElements()));
}
}
}
// ---------------------------------------------------------------------
// File resource meta-data
// ---------------------------------------------------------------------
List<String> fileResourceUids = dataValues.stream().filter(dv -> dv.getDataElement().isFileType()).map(DataValue::getValue).collect(Collectors.toList());
dataValueFileResourceMap.putAll(fileResourceService.getFileResources(fileResourceUids).stream().collect(Collectors.toMap(BaseIdentifiableObject::getUid, f -> f)));
if (!multiOrganisationUnit) {
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, attributeOptionCombo);
if (registration != null) {
complete = registration.getCompleted();
date = registration.getDate();
storedBy = registration.getStoredBy();
lastUpdatedBy = registration.getLastUpdatedBy();
}
locked = dataSetService.getLockStatus(currentUser, dataSet, period, organisationUnit, attributeOptionCombo, null);
} else {
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
locked = dataSetService.getLockStatus(currentUser, dataSet, period, ou, attributeOptionCombo, null);
if (!locked.isOpen()) {
break;
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, ou, attributeOptionCombo);
if (registration != null) {
complete = registration.getCompleted();
lastUpdatedBy = registration.getLastUpdatedBy();
}
}
}
}
return SUCCESS;
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class DefaultAdxDataService method getFromUrl.
// -------------------------------------------------------------------------
// Public methods
// -------------------------------------------------------------------------
@Override
public DataExportParams getFromUrl(DataValueSetQueryParams urlParams) {
IdSchemes outputIdSchemes = urlParams.getOutputIdSchemes();
outputIdSchemes.setDefaultIdScheme(IdScheme.CODE);
DataExportParams params = new DataExportParams();
if (!isEmpty(urlParams.getDataSet())) {
params.getDataSets().addAll(getByUidOrCode(DataSet.class, urlParams.getDataSet()));
}
if (!isEmpty(urlParams.getPeriod())) {
params.getPeriods().addAll(periodService.reloadIsoPeriods(new ArrayList<>(urlParams.getPeriod())));
} else if (urlParams.getStartDate() != null && urlParams.getEndDate() != null) {
params.setStartDate(urlParams.getStartDate());
params.setEndDate(urlParams.getEndDate());
}
if (!isEmpty(urlParams.getOrgUnit())) {
params.getOrganisationUnits().addAll(getByUidOrCode(OrganisationUnit.class, urlParams.getOrgUnit()));
}
if (!isEmpty(urlParams.getOrgUnitGroup())) {
params.getOrganisationUnitGroups().addAll(getByUidOrCode(OrganisationUnitGroup.class, urlParams.getOrgUnitGroup()));
}
if (!isEmpty(urlParams.getAttributeOptionCombo())) {
params.getAttributeOptionCombos().addAll(getByUidOrCode(CategoryOptionCombo.class, urlParams.getAttributeOptionCombo()));
}
params.setIncludeDescendants(urlParams.isChildren());
params.setIncludeDeleted(urlParams.isIncludeDeleted());
params.setLastUpdated(urlParams.getLastUpdated());
params.setLastUpdatedDuration(urlParams.getLastUpdatedDuration());
params.setLimit(urlParams.getLimit());
params.setOutputIdSchemes(outputIdSchemes);
return params;
}
use of org.hisp.dhis.datavalue.DataExportParams in project dhis2-core by dhis2.
the class DefaultAdxDataService method writeDataValueSet.
@Override
public void writeDataValueSet(DataExportParams params, OutputStream out) throws AdxException {
dataValueSetService.decideAccess(params);
dataValueSetService.validate(params);
XMLWriter adxWriter = XMLFactory.getXMLWriter(out);
adxWriter.openElement(AdxDataService.ROOT);
adxWriter.writeAttribute("xmlns", AdxDataService.NAMESPACE);
IdSchemes idSchemes = params.getOutputIdSchemes();
IdScheme ouScheme = idSchemes.getOrgUnitIdScheme();
IdScheme dsScheme = idSchemes.getDataSetIdScheme();
IdScheme deScheme = idSchemes.getDataElementIdScheme();
for (DataSet dataSet : params.getDataSets()) {
AdxDataSetMetadata metadata = new AdxDataSetMetadata(dataSet, idSchemes);
for (CategoryOptionCombo aoc : getAttribuetOptionCombos(dataSet, params)) {
Map<String, String> attributeDimensions = metadata.getExplodedCategoryAttributes(aoc.getId());
for (OrganisationUnit orgUnit : params.getAllOrganisationUnits()) {
Period currentPeriod = null;
OrganisationUnit currentOrgUnit = null;
DataExportParams queryParams = new DataExportParams().setDataElements(dataSet.getDataElements()).setOrganisationUnits(Sets.newHashSet(orgUnit)).setIncludeDescendants(params.isIncludeDescendants()).setIncludeDeleted(params.isIncludeDeleted()).setLastUpdated(params.getLastUpdated()).setLastUpdatedDuration(params.getLastUpdatedDuration()).setPeriods(params.getPeriods()).setStartDate(params.getStartDate()).setEndDate(params.getEndDate()).setAttributeOptionCombos(Sets.newHashSet(aoc)).setOrderByOrgUnitPath(true).setOrderByPeriod(true);
for (DataValue dv : dataValueService.getDataValues(queryParams)) {
if (!dv.getPeriod().equals(currentPeriod) || !dv.getSource().equals(currentOrgUnit)) {
if (currentPeriod != null) {
// GROUP
adxWriter.closeElement();
}
currentPeriod = dv.getPeriod();
currentOrgUnit = dv.getSource();
adxWriter.openElement(AdxDataService.GROUP);
adxWriter.writeAttribute(AdxDataService.DATASET, dataSet.getPropertyValue(dsScheme));
adxWriter.writeAttribute(AdxDataService.PERIOD, AdxPeriod.serialize(currentPeriod));
adxWriter.writeAttribute(AdxDataService.ORGUNIT, currentOrgUnit.getPropertyValue(ouScheme));
for (Map.Entry<String, String> e : attributeDimensions.entrySet()) {
adxWriter.writeAttribute(e.getKey(), e.getValue());
}
}
adxWriter.openElement(AdxDataService.DATAVALUE);
adxWriter.writeAttribute(AdxDataService.DATAELEMENT, dv.getDataElement().getPropertyValue(deScheme));
CategoryOptionCombo coc = dv.getCategoryOptionCombo();
Map<String, String> categoryDimensions = metadata.getExplodedCategoryAttributes(coc.getId());
for (Map.Entry<String, String> e : categoryDimensions.entrySet()) {
adxWriter.writeAttribute(e.getKey(), e.getValue());
}
if (dv.getDataElement().getValueType().isNumeric()) {
adxWriter.writeAttribute(AdxDataService.VALUE, dv.getValue());
} else {
adxWriter.writeAttribute(AdxDataService.VALUE, "0");
adxWriter.openElement(AdxDataService.ANNOTATION);
adxWriter.writeCharacters(dv.getValue());
// ANNOTATION
adxWriter.closeElement();
}
// DATAVALUE
adxWriter.closeElement();
}
if (currentPeriod != null) {
// GROUP
adxWriter.closeElement();
}
}
}
}
// ADX
adxWriter.closeElement();
adxWriter.closeWriter();
}
Aggregations