use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class LoadFormAction method getSortedCategoryCombos.
private List<CategoryCombo> getSortedCategoryCombos(Set<CategoryCombo> categoryCombos) {
List<CategoryCombo> listCategoryCombos = new ArrayList<>(categoryCombos);
Collections.sort(listCategoryCombos, new CategoryComboSizeNameComparator());
return listCategoryCombos;
}
use of org.hisp.dhis.category.CategoryCombo 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.getDataElementCategoryCombo(dataSet));
orderedCategoryCombos = getCategoryCombos(dataElements, dataSet);
User currentUser = currentUserService.getCurrentUser();
for (CategoryCombo categoryCombo : orderedCategoryCombos) {
List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
addOptionAccess(currentUser, optionComboAccessMap, 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<Long, List<CategoryOption>> optionsMap = new HashMap<>();
for (Category 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<Long, Integer> catRepeat = new HashMap<>();
Map<Long, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (Category 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.setCode(dataSet.getCode());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSetCopy.setCompulsoryDataElementOperands(dataSet.getCompulsoryDataElementOperands());
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
CategoryCombo 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));
if (i == 0) {
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
}
dataSet = dataSetCopy;
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(dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataSet);
return formType.toString();
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class DefaultAdxDataService method parseAdxGroupToDxf.
// -------------------------------------------------------------------------
// Utility methods
// -------------------------------------------------------------------------
private List<ImportConflict> parseAdxGroupToDxf(XMLReader adxReader, XMLStreamWriter dxfWriter, ImportOptions importOptions, CachingMap<String, DataSet> dataSetMap, IdentifiableObjectCallable<DataSet> dataSetCallable, CachingMap<String, DataElement> dataElementMap, IdentifiableObjectCallable<DataElement> dataElementCallable) throws XMLStreamException, AdxException {
List<ImportConflict> adxConflicts = new LinkedList<>();
Map<String, String> groupAttributes = adxReader.readAttributes();
if (!groupAttributes.containsKey(AdxDataService.PERIOD)) {
throw new AdxException(AdxDataService.PERIOD + " attribute is required on 'group'");
}
if (!groupAttributes.containsKey(AdxDataService.ORGUNIT)) {
throw new AdxException(AdxDataService.ORGUNIT + " attribute is required on 'group'");
}
// translate ADX period to DXF
String periodStr = groupAttributes.get(AdxDataService.PERIOD);
groupAttributes.remove(AdxDataService.PERIOD);
Period period = AdxPeriod.parse(periodStr);
groupAttributes.put(AdxDataService.PERIOD, period.getIsoDate());
// process ADX group attributes
if (!groupAttributes.containsKey(AdxDataService.ATTOPTCOMBO) && groupAttributes.containsKey(AdxDataService.DATASET)) {
log.debug("No attribute option combo present, check data set for attribute category combo");
String dataSetStr = trimToNull(groupAttributes.get(AdxDataService.DATASET));
final DataSet dataSet = dataSetMap.get(dataSetStr, dataSetCallable.setId(dataSetStr));
if (dataSet == null) {
throw new AdxException("No data set matching " + dataSetCallable.getIdScheme().name().toLowerCase() + " '" + groupAttributes.get(AdxDataService.DATASET) + "'");
}
groupAttributes.put(AdxDataService.DATASET, dataSet.getUid());
CategoryCombo attributeCombo = dataSet.getCategoryCombo();
convertAttributesToDxf(groupAttributes, AdxDataService.ATTOPTCOMBO, attributeCombo, importOptions.getIdSchemes());
}
// process the dataValues
while (adxReader.moveToStartElement(AdxDataService.DATAVALUE, AdxDataService.GROUP)) {
try {
parseAdxDataValueToDxf(adxReader, dxfWriter, groupAttributes, importOptions, dataElementMap, dataElementCallable);
} catch (AdxException ex) {
adxConflicts.add(new ImportConflict(ex.getObject(), ex.getMessage()));
log.info("ADX data value conflict: {} {}", ex.getObject(), ex.getMessage());
}
}
return adxConflicts;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validateAocMatchesDataSetCc.
private static void validateAocMatchesDataSetCc(MetadataProperties mdProps) throws ImportConflictException {
// TODO MdCache?
CategoryCombo aocCC = mdProps.attrOptCombo.getCategoryCombo();
CategoryCombo dsCc = mdProps.dataSet.getCategoryCombo();
if (!aocCC.equals(dsCc)) {
throw new ImportConflictException(new ImportConflict(aocCC.getUid(), String.format("Attribute option combo: %s must have category combo: %s", aocCC.getUid(), dsCc.getUid())));
}
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method bind.
private CategoryOptionCombo bind(String key, ResultSet rs) throws SQLException {
CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
categoryOptionCombo.setId(rs.getLong(key));
categoryOptionCombo.setUid(rs.getString("uid"));
categoryOptionCombo.setCode(rs.getString("code"));
categoryOptionCombo.setIgnoreApproval(rs.getBoolean("ignoreapproval"));
categoryOptionCombo.setName(rs.getString("name"));
String cat_ids = rs.getString("cat_ids");
if (!ObjectUtils.isEmpty(cat_ids)) {
categoryOptionCombo.setCategoryOptions(Arrays.stream(cat_ids.split(",")).map(coid -> getCategoryOption(IdScheme.ID, coid)).collect(Collectors.toSet()));
}
CategoryCombo categoryCombo = new CategoryCombo();
categoryCombo.setUid(rs.getString("cc_uid"));
categoryCombo.setName(rs.getString("cc_name"));
categoryOptionCombo.setCategoryCombo(categoryCombo);
return categoryOptionCombo;
}
Aggregations