use of org.ehrbase.webtemplate.parser.NodeId in project ehrbase by ehrbase.
the class KnowledgeCacheService method resolveForTemplate.
@Override
public JsonPathQueryResult resolveForTemplate(String templateId, Collection<NodeId> nodeIds) {
TemplateIdQueryTuple key = new TemplateIdQueryTuple(templateId, nodeIds);
JsonPathQueryResult jsonPathQueryResult = jsonPathQueryResultCache.get(key, JsonPathQueryResult.class);
if (jsonPathQueryResult == null) {
WebTemplate webTemplate = getQueryOptMetaData(templateId);
List<WebTemplateNode> webTemplateNodeList = new ArrayList<>();
webTemplateNodeList.add(webTemplate.getTree());
for (NodeId nodeId : nodeIds) {
webTemplateNodeList = webTemplateNodeList.stream().map(n -> n.findMatching(f -> {
if (f.getNodeId() == null) {
return false;
} else // compere only classname
if (nodeId.getNodeId() == null) {
return nodeId.getClassName().equals(new NodeId(f.getNodeId()).getClassName());
} else {
return nodeId.equals(new NodeId(f.getNodeId()));
}
})).flatMap(List::stream).collect(Collectors.toList());
}
Set<String> uniquePaths = new TreeSet<>();
webTemplateNodeList.stream().map(n -> n.getAqlPath(false)).forEach(uniquePaths::add);
if (!uniquePaths.isEmpty()) {
jsonPathQueryResult = new JsonPathQueryResult(templateId, uniquePaths);
} else {
// dummy result since null can not be path of a cache
jsonPathQueryResult = new JsonPathQueryResult(null, Collections.emptyMap());
}
jsonPathQueryResultCache.put(key, jsonPathQueryResult);
}
if (jsonPathQueryResult.getTemplateId() != null) {
return jsonPathQueryResult;
} else // Is dummy result
{
return null;
}
}
use of org.ehrbase.webtemplate.parser.NodeId in project ehrbase by ehrbase.
the class Containments method resolveContainers.
public void resolveContainers(String templateId) {
// traverse the list from the last containment and resolve the ones with path
List<Object> containmentList = new ArrayList<>();
containmentList.addAll(containmentSet);
for (int i = 0; i < containmentList.size(); i++) {
if (containmentList.get(i) instanceof Containment) {
Containment containment = (Containment) containmentList.get(i);
if (containment.getClassName().equals("COMPOSITION") && containment.getArchetypeId() == null) {
continue;
}
if (containment.getPath(templateId) == null) {
List sublist = containmentList.subList(i, containmentList.size());
// build the jsonpath expression up to this containment
List<NodeId> jsonQuery = new JsonPathQueryBuilder(sublist).assemble();
// get the path for this template
JsonPathQueryResult jsonPathQueryResult = new Templates(knowledgeCacheService).resolveForTemplate(templateId, jsonQuery);
if (jsonPathQueryResult != null) {
containment.setPath(templateId, jsonPathQueryResult.getAqlPath());
}
}
}
}
}
use of org.ehrbase.webtemplate.parser.NodeId in project openEHR_SDK by ehrbase.
the class ToCompositionWalker method postHandle.
@Override
protected void postHandle(Context<T> context) {
RMObject currentRM = context.getRmObjectDeque().peek();
WebTemplateNode currentNode = context.getNodeDeque().peek();
if (currentRM instanceof Locatable) {
org.ehrbase.webtemplate.parser.NodeId nodeId = new NodeId(currentNode.getNodeId());
if (nodeId.isArchetypeId()) {
Archetyped archetyped = new Archetyped();
archetyped.setArchetypeId(new ArchetypeID(nodeId.getNodeId()));
archetyped.setRmVersion(RM_VERSION_1_4_0);
TemplateId templateId = new TemplateId();
templateId.setValue(context.getTemplateId());
archetyped.setTemplateId(templateId);
((Locatable) currentRM).setArchetypeDetails(archetyped);
((Locatable) currentRM).setArchetypeNodeId(nodeId.getNodeId());
}
}
normalise(currentRM);
}
use of org.ehrbase.webtemplate.parser.NodeId in project openEHR_SDK by ehrbase.
the class WebTemplate method findAllContainmentCombinations.
private Set<Set<NodeId>> findAllContainmentCombinations(WebTemplateNode tree) {
Set<Set<NodeId>> containments = new LinkedHashSet<>();
final NodeId currentContainment;
if (tree.getNodeId() != null && new NodeId(tree.getNodeId()).isArchetypeId()) {
currentContainment = new NodeId(tree.getNodeId());
containments.add(new LinkedHashSet<>(Set.of(currentContainment)));
} else {
currentContainment = null;
}
for (WebTemplateNode child : tree.getChildren()) {
Set<Set<NodeId>> subSets = findAllContainmentCombinations(child);
containments.addAll(subSets);
if (currentContainment != null) {
containments.addAll(subSets.stream().map(s -> {
Set<NodeId> list = new LinkedHashSet<>(Set.of(currentContainment));
list.addAll(s);
return list;
}).collect(Collectors.toSet()));
}
}
return containments;
}
use of org.ehrbase.webtemplate.parser.NodeId in project ehrbase by ehrbase.
the class KnowledgeCacheServiceTest method testNonUniqueAqlPathsTemplateId.
@Test
public void testNonUniqueAqlPathsTemplateId() throws Exception {
KnowledgeCacheService knowledge = buildKnowledgeCache(testFolder, cacheRule);
knowledge.addOperationalTemplate(IOUtils.toByteArray(TemplateTestData.NON_UNIQUE_AQL_PATH.getStream()));
// a node with two paths
NodeId nodeId = new NodeId("ACTION", "openEHR-EHR-ACTION.procedure.v1");
List<NodeId> nodeIds = new ArrayList<>();
nodeIds.add(nodeId);
// resolve
JsonPathQueryResult jsonPathQueryResult = knowledge.resolveForTemplate("non_unique_aql_paths", nodeIds);
assertThat(jsonPathQueryResult).isNotNull();
}
Aggregations