use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class LoadFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return INPUT;
}
FormType formType = dataSet.getFormType();
if (formType.isCustom() && dataSet.hasDataEntryForm()) {
dataEntryForm = dataSet.getDataEntryForm();
customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
return formType.toString();
}
// ---------------------------------------------------------------------
// Section / default form
// ---------------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
if (dataElements.isEmpty()) {
return INPUT;
}
Collections.sort(dataElements);
orderedDataElements = ListMap.getListMap(dataElements, de -> de.getCategoryCombo(dataSet));
orderedCategoryCombos = getDataElementCategoryCombos(dataElements, dataSet);
for (DataElementCategoryCombo categoryCombo : orderedCategoryCombos) {
List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
// -----------------------------------------------------------------
// Perform ordering of categories and their options so that they
// could be displayed as in the paper form. Note that the total
// number of entry cells to be generated are the multiple of options
// from each category.
// -----------------------------------------------------------------
numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
Map<Integer, List<DataElementCategoryOption>> optionsMap = new HashMap<>();
for (DataElementCategory category : categoryCombo.getCategories()) {
optionsMap.put(category.getId(), category.getCategoryOptions());
}
orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
// -----------------------------------------------------------------
// Calculating the number of times each category should be repeated
// -----------------------------------------------------------------
Map<Integer, Integer> catRepeat = new HashMap<>();
Map<Integer, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (DataElementCategory cat : categoryCombo.getCategories()) {
int categoryOptionSize = cat.getCategoryOptions().size();
if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
catColSpan = catColSpan / categoryOptionSize;
int total = optionCombos.size() / (catColSpan * categoryOptionSize);
Collection<Integer> cols = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
cols.add(i);
}
colRepeat.put(cat.getId(), cols);
catRepeat.put(cat.getId(), catColSpan);
}
}
catColRepeat.put(categoryCombo.getId(), colRepeat);
}
// ---------------------------------------------------------------------
// Get data entry form
// ---------------------------------------------------------------------
DataSet dsOriginal = dataSet;
if (dataSet.getFormType().isDefault()) {
DataSet dataSetCopy = new DataSet();
dataSetCopy.setUid(dataSet.getUid());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSet = dataSetCopy;
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
DataElementCategoryCombo categoryCombo = orderedCategoryCombos.get(i);
String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
Section section = new Section();
section.setUid(CodeGenerator.generateUid());
section.setId(i);
section.setName(name);
section.setSortOrder(i);
section.setDataSet(dataSetCopy);
dataSetCopy.getSections().add(section);
section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
formType = FormType.SECTION;
}
if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (child.getDataSets().contains(dsOriginal)) {
organisationUnitChildren.add(child);
}
}
Collections.sort(organisationUnitChildren);
organisationUnits.addAll(organisationUnitChildren);
getSectionForm(dataElements, dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataElements, dataSet);
return formType.toString();
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class GetDataValuesForDataSetAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
// ---------------------------------------------------------------------
// Validation
// ---------------------------------------------------------------------
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
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo 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(organisationUnit, period, dataSet.getDataElements(), attributeOptionCombo));
} else {
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
dataValues.addAll(dataValueService.getDataValues(ou, period, dataSet.getDataElements(), 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 = true;
date = registration.getDate();
storedBy = registration.getStoredBy();
}
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
} else {
complete = true;
for (OrganisationUnit ou : children) {
if (ou.getDataSets().contains(dataSet)) {
locked = dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null);
if (locked) {
break;
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, ou, attributeOptionCombo);
if (complete && registration == null) {
complete = false;
}
}
}
}
return SUCCESS;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class ValidationAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
DataSet dataSet = dataSetService.getDataSet(ds);
Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
attributeOptionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
}
if (selectedPeriod == null || orgUnit == null || (multiOu && !orgUnit.hasChild())) {
return SUCCESS;
}
Period period = periodService.getPeriod(selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedPeriod.getPeriodType());
List<OrganisationUnit> organisationUnits = new ArrayList<>();
if (!multiOu) {
organisationUnits.add(orgUnit);
} else {
organisationUnits.addAll(orgUnit.getChildren());
}
Collections.sort(organisationUnits);
Date from = new DateTime(period.getStartDate()).minusYears(2).toDate();
for (OrganisationUnit organisationUnit : organisationUnits) {
List<DeflatedDataValue> values = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataSet.getDataElements(), Sets.newHashSet(period), null, from));
if (!values.isEmpty()) {
dataValues.put(organisationUnit.getUid(), values);
}
List<ValidationResult> results = new ArrayList<>(validationService.startInteractiveValidationAnalysis(dataSet, period, organisationUnit, attributeOptionCombo));
if (!results.isEmpty()) {
validationResults.put(organisationUnit.getUid(), results);
}
List<DataElementOperand> violations = validationService.validateRequiredComments(dataSet, period, organisationUnit, attributeOptionCombo);
if (!violations.isEmpty()) {
commentViolations.put(organisationUnit.getUid(), violations);
}
}
return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class GetOrganisationUnitsAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
organisationUnits = formUtils.getSortedOrganisationUnitsForCurrentUser();
try {
if (organisationUnits.size() == 1) {
for (OrganisationUnit organisationUnit : organisationUnits) {
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (// >0
child.getDataSets().size() > 0) {
return SUCCESS;
}
}
}
organisationUnitId = organisationUnits.get(0).getId();
List<DataSet> dataSets = formUtils.getDataSetsForCurrentUser(organisationUnitId);
if (dataSets.size() > 1) {
return "selectDataSet";
}
dataSetId = dataSets.get(0).getId();
return "selectPeriod";
}
} catch (Exception e) {
}
return SUCCESS;
}
use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.
the class MarkComplete method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Validate.notNull(organisationUnitId);
Validate.notNull(isoPeriod);
Validate.notNull(dataSetId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Period period = periodService.getPeriod(isoPeriod);
DataSet dataSet = dataSetService.getDataSet(dataSetId);
//TODO
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
if (registration == null) {
registration = new CompleteDataSetRegistration();
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(organisationUnit);
registration.setDate(new Date());
registration.setStoredBy(currentUserService.getCurrentUsername());
registrationService.saveCompleteDataSetRegistration(registration);
}
return SUCCESS;
}
Aggregations