Search in sources :

Example 1 with NodeId

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;
    }
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) JsonPathQueryResult(org.ehrbase.aql.containment.JsonPathQueryResult) Cache(org.springframework.cache.Cache) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TemplateMetaData(org.ehrbase.ehr.knowledge.TemplateMetaData) LoggerFactory(org.slf4j.LoggerFactory) TreeSet(java.util.TreeSet) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CacheOptions(org.ehrbase.cache.CacheOptions) NodeId(org.ehrbase.webtemplate.parser.NodeId) Value(org.springframework.beans.factory.annotation.Value) ByteArrayInputStream(java.io.ByteArrayInputStream) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) StateConflictException(org.ehrbase.api.exception.StateConflictException) TemplateIdAqlTuple(org.ehrbase.aql.containment.TemplateIdAqlTuple) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) Logger(org.slf4j.Logger) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) ItemInfo(org.ehrbase.aql.sql.queryimpl.ItemInfo) List(java.util.List) XmlException(org.apache.xmlbeans.XmlException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) Optional(java.util.Optional) I_KnowledgeCache(org.ehrbase.ehr.knowledge.I_KnowledgeCache) TemplateIdQueryTuple(org.ehrbase.aql.containment.TemplateIdQueryTuple) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) Collections(java.util.Collections) TemplateUtils(org.ehrbase.util.TemplateUtils) Transactional(org.springframework.transaction.annotation.Transactional) JsonPathQueryResult(org.ehrbase.aql.containment.JsonPathQueryResult) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) ArrayList(java.util.ArrayList) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) TreeSet(java.util.TreeSet) NodeId(org.ehrbase.webtemplate.parser.NodeId) ArrayList(java.util.ArrayList) List(java.util.List) TemplateIdQueryTuple(org.ehrbase.aql.containment.TemplateIdQueryTuple)

Example 2 with NodeId

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());
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NodeId(org.ehrbase.webtemplate.parser.NodeId) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with NodeId

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);
}
Also used : NodeId(org.ehrbase.webtemplate.parser.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) NodeId(org.ehrbase.webtemplate.parser.NodeId) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) RMObject(com.nedap.archie.rm.RMObject) Locatable(com.nedap.archie.rm.archetyped.Locatable) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID)

Example 4 with NodeId

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) NodeId(org.ehrbase.webtemplate.parser.NodeId)

Example 5 with NodeId

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();
}
Also used : JsonPathQueryResult(org.ehrbase.aql.containment.JsonPathQueryResult) NodeId(org.ehrbase.webtemplate.parser.NodeId) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NodeId (org.ehrbase.webtemplate.parser.NodeId)6 ArrayList (java.util.ArrayList)4 List (java.util.List)2 Set (java.util.Set)2 JsonPathQueryResult (org.ehrbase.aql.containment.JsonPathQueryResult)2 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)2 RMObject (com.nedap.archie.rm.RMObject)1 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)1 Locatable (com.nedap.archie.rm.archetyped.Locatable)1 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)1 ArchetypeID (com.nedap.archie.rm.support.identification.ArchetypeID)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MessageFormat (java.text.MessageFormat)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1