use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryCombo.
/**
* @param categoryComboUniqueIdentifier A unique character to identify the
* category option combo.
* @param categories the categories
* category options.
* @return DataElementCategoryOptionCombo
*/
public static DataElementCategoryCombo createCategoryCombo(char categoryComboUniqueIdentifier, DataElementCategory... categories) {
DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo("CategoryCombo" + categoryComboUniqueIdentifier, DataDimensionType.DISAGGREGATION);
categoryCombo.setAutoFields();
for (DataElementCategory category : categories) {
categoryCombo.getCategories().add(category);
}
return categoryCombo;
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class ExpressionStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
DataElement dataElementA = createDataElement('A');
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
DataElement dataElementD = createDataElement('D');
dataElementIdA = dataElementService.addDataElement(dataElementA);
dataElementIdB = dataElementService.addDataElement(dataElementB);
dataElementIdC = dataElementService.addDataElement(dataElementC);
dataElementIdD = dataElementService.addDataElement(dataElementD);
DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryComboByName(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
DataElementCategoryOptionCombo categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
expressionA = "[" + dataElementIdA + "] + [" + dataElementIdB + "]";
expressionB = "[" + dataElementIdC + "] - [" + dataElementIdD + "]";
descriptionA = "Expression A";
descriptionB = "Expression B";
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DataSetController method getCategoryCombinations.
@RequestMapping(value = "/{uid}/categoryCombos", method = RequestMethod.GET)
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
setUserContext(translateParams);
DataSet dataSet = manager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist: " + uid));
}
List<DataElementCategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
Collections.sort(categoryCombos);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.filter(DataElementCategoryCombo.class, categoryCombos, fields));
return rootNode;
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalByCategoryOptionCombos.
@RequestMapping(value = APPROVALS_PATH + "/categoryOptionCombos", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalByCategoryOptionCombos(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam(required = false) String ou, HttpServletResponse response) throws IOException, WebMessageException {
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit != null && orgUnit.isRoot()) {
// Look for all org units.
orgUnit = null;
}
SetMap<DataApprovalWorkflow, DataElementCategoryCombo> workflowCategoryComboMap = new SetMap<>();
for (DataSet dataSet : dataSets) {
workflowCategoryComboMap.putValue(dataSet.getWorkflow(), dataSet.getCategoryCombo());
}
List<DataApprovalStatus> statusList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflowCategoryComboMap.keySet()) {
for (DataElementCategoryCombo attributeCombo : workflowCategoryComboMap.get(workflow)) {
statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (DataApprovalStatus status : statusList) {
Map<String, Object> item = new HashMap<>();
Map<String, String> approvalLevel = new HashMap<>();
if (status.getApprovedLevel() != null) {
approvalLevel.put("id", status.getApprovedLevel().getUid());
approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
}
item.put("id", status.getAttributeOptionComboUid());
item.put("level", approvalLevel);
item.put("ou", status.getOrganisationUnitUid());
item.put("ouName", status.getOrganisationUnitName());
item.put("accepted", status.isAccepted());
item.put("permissions", status.getPermissions());
list.add(item);
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), list);
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getDefaultDataSetReport.
@Override
public List<Grid> getDefaultDataSetReport(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n) {
ListMap<DataElementCategoryCombo, DataElement> map = new ListMap<>();
for (DataSetElement element : dataSet.getDataSetElements()) {
map.putValue(element.getResolvedCategoryCombo(), element.getDataElement());
}
DataSet tmpDataSet = new DataSet(dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType());
tmpDataSet.setDataSetElements(dataSet.getDataSetElements());
for (DataElementCategoryCombo categoryCombo : map.keySet()) {
List<DataElement> dataElements = map.get(categoryCombo);
String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName();
Section section = new Section(name, dataSet, dataElements, null);
tmpDataSet.getSections().add(section);
}
return getSectionDataSetReport(tmpDataSet, period, unit, dimensions, selectedUnitOnly, format, i18n);
}
Aggregations