use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getDataSetForLocale.
@Override
public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return null;
}
DataSet ds = new DataSet();
ds.setId(dataSet.getId());
String name = StringUtils.defaultIfEmpty(dataSet.getName(), dataSet.getShortName());
ds.setName(name);
ds.setVersion(1);
Integer version = dataSet.getVersion();
if (version != null) {
ds.setVersion(version);
}
ds.setPeriodType(dataSet.getPeriodType().getName());
List<Section> sectionList = new ArrayList<>();
ds.setSections(sectionList);
Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
if (sections == null || sections.size() == 0) {
List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
// Fake section to store data elements
Section section = new Section();
section.setId(0);
section.setName("");
section.setDataElements(getDataElements(locale, dataElements));
sectionList.add(section);
} else {
for (org.hisp.dhis.dataset.Section sec : sections) {
Section section = new Section();
section.setId(sec.getId());
section.setName(sec.getName());
List<org.hisp.dhis.dataelement.DataElement> des = new ArrayList<>(sec.getDataElements());
// Remove grey fields in order to not display them on mobile
List<DataElement> dataElementList = getDataElements(locale, des);
List<DataElement> dataElementListFinal = new ArrayList<>(dataElementList);
int tempI = 0;
for (int i = 0; i < dataElementList.size(); i++) {
List<Model> categoryOptionCombos = dataElementList.get(i).getCategoryOptionCombos().getModels();
List<Model> newCategoryOptionCombos = new ArrayList<>();
for (int j = 0; j < categoryOptionCombos.size(); j++) {
if (!isGreyField(sec, dataElementList.get(i).getId(), categoryOptionCombos.get(j).getId())) {
newCategoryOptionCombos.add(categoryOptionCombos.get(j));
}
}
if (newCategoryOptionCombos.isEmpty()) {
dataElementListFinal.remove(i - tempI);
tempI++;
} else {
dataElementListFinal.get(i - tempI).getCategoryOptionCombos().setModels(newCategoryOptionCombos);
}
}
section.setDataElements(dataElementListFinal);
sectionList.add(section);
}
}
return ds;
}
use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getMobileDataSetsForUnit.
// -------------------------------------------------------------------------
// Service methods
// -------------------------------------------------------------------------
@Override
public List<DataSet> getMobileDataSetsForUnit(OrganisationUnit unit, String localeString) {
List<DataSet> datasets = new ArrayList<>();
Locale locale = LocaleUtil.getLocale(localeString);
if (DEBUG)
log.debug("Getting data sets for unit " + unit.getName());
for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile(unit)) {
PeriodType periodType = dataSet.getPeriodType();
if (periodType instanceof DailyPeriodType || periodType instanceof WeeklyPeriodType || periodType instanceof MonthlyPeriodType || periodType instanceof YearlyPeriodType || periodType instanceof QuarterlyPeriodType) {
if (DEBUG)
log.debug("Found data set " + dataSet.getName());
datasets.add(getDataSetForLocale(dataSet.getId(), locale));
} else {
log.warn("Dataset '" + dataSet.getName() + "' set to be reported from mobile, but not of a supported period type: " + periodType.getName());
}
}
return datasets;
}
use of org.hisp.dhis.api.mobile.model.DataSet 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.api.mobile.model.DataSet in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getUpdatedDataSet.
@Override
public DataSetList getUpdatedDataSet(DataSetList dataSetList, OrganisationUnit unit, String locale) {
if (DEBUG)
log.debug("Checking updated datasets for org unit " + unit.getName());
DataSetList updatedDataSetList = new DataSetList();
List<DataSet> dataSets = this.getMobileDataSetsForUnit(unit, locale);
List<DataSet> currentDataSets = dataSetList.getCurrentDataSets();
// check added dataset
for (DataSet dataSet : dataSets) {
if (!currentDataSets.contains(dataSet)) {
if (updatedDataSetList.getAddedDataSets() == null)
updatedDataSetList.setAddedDataSets(new ArrayList<>());
updatedDataSetList.getAddedDataSets().add(dataSet);
currentDataSets.add(dataSet);
}
}
// check deleted dataset
for (DataSet dataSet : currentDataSets) {
if (!dataSets.contains(dataSet)) {
if (updatedDataSetList.getDeletedDataSets() == null)
updatedDataSetList.setDeletedDataSets(new ArrayList<>());
updatedDataSetList.getDeletedDataSets().add(new DataSet(dataSet));
}
}
if (updatedDataSetList.getDeletedDataSets() != null) {
for (DataSet dataSet : updatedDataSetList.getDeletedDataSets()) {
currentDataSets.remove(dataSet);
}
}
// check modified dataset
Collections.sort(dataSets);
Collections.sort(currentDataSets);
for (int i = 0; i < dataSets.size(); i++) {
if (dataSets.get(i).getVersion() != currentDataSets.get(i).getVersion()) {
if (updatedDataSetList.getModifiedDataSets() == null)
updatedDataSetList.setModifiedDataSets(new ArrayList<>());
updatedDataSetList.getModifiedDataSets().add(dataSets.get(i));
}
}
if (DEBUG)
log.debug("Returning updated datasets for org unit " + unit.getName());
return updatedDataSetList;
}
use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getDataSetsForLocale.
@Override
public DataSetList getDataSetsForLocale(OrganisationUnit unit, String locale) {
DataSetList dataSetList = new DataSetList();
List<DataSet> dataSets = getMobileDataSetsForUnit(unit, locale);
dataSetList.setModifiedDataSets(dataSets);
return dataSetList;
}
Aggregations