use of org.ehrbase.serialisation.walker.Context in project openEHR_SDK by ehrbase.
the class PathMatcher method matchesPath.
String matchesPath(Context<?> context, WebTemplateNode child, Map.Entry<String, ?> e) {
String aqlPath = FlatPath.removeStart(new FlatPath(child.getAqlPath()), new FlatPath(context.getNodeDeque().peek().getAqlPath())).toString();
if (StringUtils.startsWith(e.getKey(), aqlPath)) {
return remove(e, aqlPath, child);
} else {
FlatPath childPath = new FlatPath(aqlPath);
FlatPath pathLast = childPath.getLast();
FlatPath pathWithoutLastName = FlatPath.addEnd(FlatPath.removeEnd(childPath, pathLast), new FlatPath(pathLast.format(false)));
if (StringUtils.startsWith(e.getKey(), pathWithoutLastName.toString()) && context.getNodeDeque().peek().getChildren().stream().filter(n -> Objects.equals(n.getNodeId(), child.getNodeId())).count() == 1) {
logger.warn("name/value not set in dto for {}", child.getAqlPath());
return remove(e, pathWithoutLastName.toString(), child);
} else {
return null;
}
}
}
use of org.ehrbase.serialisation.walker.Context in project openEHR_SDK by ehrbase.
the class StdToCompositionWalker method isMatchingNode.
private boolean isMatchingNode(Map<FlatPathDto, String> subValues, Context<Map<FlatPathDto, String>> context, WebTemplateNode child, FlatPathDto currentFlatPath) {
if (child.getRmType().equals("POINT_EVENT")) {
return subValues.entrySet().stream().allMatch((e -> !e.getKey().getLast().getName().equals("width")));
} else if (child.getRmType().equals("INTERVAL_EVENT")) {
return subValues.entrySet().stream().anyMatch((e -> e.getKey().getLast().getName().equals("width")));
} else if (visitChildren(child)) {
for (WebTemplateNode n : child.getChildren()) {
context.getNodeDeque().push(n);
String path = context.getFlatHelper().buildNamePath(context, true);
context.getNodeDeque().remove();
subValues = subValues.entrySet().stream().filter(e -> !e.getKey().startsWith(path)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
return subValues.isEmpty();
} else if (child.getRmType().equals(DV_CODED_TEXT)) {
return subValues.keySet().stream().anyMatch(e -> "code".equals(e.getLast().getAttributeName()) && currentFlatPath.getLast().getName().equals(e.getLast().getName()));
} else if (child.getRmType().equals(DV_TEXT)) {
return subValues.keySet().stream().allMatch((e -> !("code".equals(e.getLast().getAttributeName()) && currentFlatPath.getLast().getName().equals(e.getLast().getName()))));
} else {
// End Nodes which are Choice always have unique flat paths
return true;
}
}
use of org.ehrbase.serialisation.walker.Context in project openEHR_SDK by ehrbase.
the class StdToCompositionWalker method extract.
@Override
protected Map<FlatPathDto, String> extract(Context<Map<FlatPathDto, String>> context, WebTemplateNode child, boolean isChoice, Integer count) {
context.getNodeDeque().push(child);
Integer oldCount = null;
if (count != null) {
oldCount = context.getCountMap().get(new NodeId(child));
context.getCountMap().put(new NodeId(child), count);
}
String path;
path = buildNamePathWithElementHandling(context);
context.getNodeDeque().remove();
context.getCountMap().remove(new NodeId(child));
if (oldCount != null) {
context.getCountMap().put(new NodeId(child), oldCount);
}
Map<FlatPathDto, String> subValues = context.getObjectDeque().peek().entrySet().stream().filter(e -> e.getKey().startsWith(path)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (isChoice && !isMatchingNode(subValues, context, child, new FlatPathDto(path))) {
subValues = Collections.emptyMap();
}
if (!subValues.isEmpty()) {
return subValues;
} else {
return null;
}
}
use of org.ehrbase.serialisation.walker.Context in project openEHR_SDK by ehrbase.
the class StdToCompositionWalker method calculateSize.
@Override
protected int calculateSize(Context<Map<FlatPathDto, String>> context, WebTemplateNode childNode) {
Integer oldCount = context.getCountMap().get(new NodeId(childNode));
String namePath = context.getFlatHelper().buildNamePath(context, true);
String finalNamePath = namePath;
Integer count = context.getObjectDeque().peek().keySet().stream().filter(s -> s.startsWith(finalNamePath)).map(s -> FlatPathDto.removeStart(s, new FlatPathDto(finalNamePath))).filter(n -> n != null && n.getName().equals(childNode.getId())).map(n -> Optional.ofNullable(n.getCount()).orElse(0)).sorted().reduce((first, second) -> second).map(i -> i + 1).orElse(0);
if (oldCount != null) {
context.getCountMap().put(new NodeId(childNode), oldCount);
}
return count;
}
use of org.ehrbase.serialisation.walker.Context in project openEHR_SDK by ehrbase.
the class StdToCompositionWalker method preHandle.
@Override
protected void preHandle(Context<Map<FlatPathDto, String>> context) {
// Handle if at an End-Node
if (!isRaw(context) && !visitChildren(context.getNodeDeque().peek()) && !context.getFlatHelper().skip(context)) {
if (context.getRmObjectDeque().peek().getClass().isAssignableFrom(DvCodedText.class) && context.getObjectDeque().peek().keySet().stream().anyMatch(k -> "other".equals(k.getLast().getAttributeName()))) {
replaceRmObject(context, new DvText());
}
RMUnmarshaller rmUnmarshaller = findRMUnmarshaller(context.getRmObjectDeque().peek().getClass());
String namePath = buildNamePathWithElementHandling(context);
rmUnmarshaller.handle(namePath, context.getRmObjectDeque().peek(), context.getObjectDeque().peek(), context, consumedPaths);
}
}
Aggregations