use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataQueryParams method getFirstDataElementGroup.
/**
* Returns the first data element group in this query, meaning the first
* group item within the first data element group set dimension, if any.
* Returns null if no dimension or item exists.
*/
public DataElementGroup getFirstDataElementGroup() {
if (!getDataElementGroupSets().isEmpty()) {
DimensionalObject degs = getDataElementGroupSets().get(0);
DimensionalItemObject deg = degs.hasItems() ? degs.getItems().get(0) : null;
return (DataElementGroup) deg;
}
return null;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataElementGroupResolverTest method setUp.
@BeforeEach
public void setUp() {
uid1 = CodeGenerator.generateUid();
uid2 = CodeGenerator.generateUid();
uid3 = CodeGenerator.generateUid();
de1 = createDataElement('X');
de2 = createDataElement('Y');
de3 = createDataElement('Z');
DataElementGroup dataElementGroup = createDataElementGroup('A');
dataElementGroup.addDataElement(de1);
dataElementGroup.addDataElement(de2);
dataElementGroup.addDataElement(de3);
resolver = new DataElementGroupResolver(expressionService, dataElementGroupStore);
when(dataElementGroupStore.getByUid(anyString())).thenReturn(dataElementGroup);
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataElementGroupResolver method resolve.
@Override
public String resolve(String expression) {
Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
for (DimensionalItemId id : dimItemIds) {
if (id.getItem() != null && id.getId0() != null && id.getId0().startsWith(DATA_ELEMENT_GROUP_PREFIX)) {
DataElementGroup deGroup = dataElementGroupStore.getByUid(id.getId0().replace(DATA_ELEMENT_GROUP_PREFIX, EMPTY_STRING));
if (deGroup != null) {
List<String> resolved = deGroup.getMembers().stream().map(de -> id.getItem().replace(id.getId0(), de.getUid())).collect(Collectors.toList());
expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
}
}
}
return expression;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DhisConvenienceTest method createDataElementGroup.
/**
* @param uniqueCharacter A unique character to identify the object.
*/
public static DataElementGroup createDataElementGroup(char uniqueCharacter) {
DataElementGroup group = new DataElementGroup();
group.setAutoFields();
group.setUid(BASE_UID + uniqueCharacter);
group.setName("DataElementGroup" + uniqueCharacter);
group.setShortName("DataElementGroup" + uniqueCharacter);
group.setCode("DataElementCode" + uniqueCharacter);
return group;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataElementGroupController method getOperandsByQuery.
@GetMapping("/{uid}/operands/query/{q}")
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList();
for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
dataElementOperands.add(dataElementOperand);
}
}
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
Aggregations