Search in sources :

Example 1 with GraphDefinitionLinkComponent

use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method processLinkTarget.

private void processLinkTarget(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
    check(link.getTarget().size() == 1, "If there is no path, there must be one and only one target at " + focusPath);
    check(link.getTarget().get(0).hasType(), "If there is no path, there must be type on the target at " + focusPath);
    check(link.getTarget().get(0).getParams().contains("{ref}"), "If there is no path, the target must have parameters that include a parameter using {ref} at " + focusPath);
    String path = focusPath + " -> " + link.getTarget().get(0).getType() + "?" + link.getTarget().get(0).getParams();
    List<IBaseResource> list = new ArrayList<>();
    List<Argument> params = new ArrayList<>();
    parseParams(params, link.getTarget().get(0).getParams(), focus);
    services.listResources(appInfo, link.getTarget().get(0).getType(), params, list);
    check(!validating || (list.size() >= (link.hasMin() ? link.getMin() : 0)), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + list.size());
    check(!validating || (list.size() <= (link.hasMax() && !link.getMax().equals("*") ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE)), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + list.size());
    for (IBaseResource res : list) {
        Resource r = (Resource) res;
        if (!isInBundle(r)) {
            addToBundle(r);
            // Grahame Grieve 17-06-2020: this seems wrong to me - why restart?
            for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
                processLink(start.fhirType(), start, l, depth + 1);
            }
        }
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent) Argument(org.hl7.fhir.utilities.graphql.Argument) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r4b.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 2 with GraphDefinitionLinkComponent

use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method processLinkPath.

private void processLinkPath(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
    String path = focusPath + " -> " + link.getPath();
    check(link.hasPath(), "Path is needed at " + path);
    check(!link.hasSliceName(), "SliceName is not yet supported at " + path);
    ExpressionNode node;
    if (link.getPathElement().hasUserData(TAG_NAME)) {
        node = (ExpressionNode) link.getPathElement().getUserData(TAG_NAME);
    } else {
        node = engine.parse(link.getPath());
        link.getPathElement().setUserData(TAG_NAME, node);
    }
    List<Base> matches = engine.evaluate(null, focus, focus, focus, node);
    check(!validating || matches.size() >= (link.hasMin() ? link.getMin() : 0), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + matches.size());
    check(!validating || matches.size() <= (link.hasMax() ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + matches.size());
    for (Base sel : matches) {
        // todo: should a URL be ok?
        check(sel.fhirType().equals("Reference"), "Selected node from an expression must be a Reference");
        ReferenceResolution res = services.lookup(appInfo, focus, (Reference) sel);
        if (res != null) {
            // todo
            check(res.getTargetContext() != focus, "how to handle contained resources is not yet resolved");
            for (GraphDefinitionLinkTargetComponent tl : link.getTarget()) {
                if (tl.getType().equals(res.getTarget().fhirType())) {
                    Resource r = (Resource) res.getTarget();
                    if (!isInBundle(r)) {
                        addToBundle(r);
                        for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
                            processLink(focus.fhirType(), r, l, depth + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent) ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode) ReferenceResolution(org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution) Resource(org.hl7.fhir.r4b.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) GraphDefinitionLinkTargetComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkTargetComponent) Base(org.hl7.fhir.r4b.model.Base)

Example 3 with GraphDefinitionLinkComponent

use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method processLinkPath.

private void processLinkPath(String focusPath, Resource focus, GraphDefinitionLinkComponent link, int depth) {
    String path = focusPath + " -> " + link.getPath();
    check(link.hasPath(), "Path is needed at " + path);
    check(!link.hasSliceName(), "SliceName is not yet supported at " + path);
    ExpressionNode node;
    if (link.getPathElement().hasUserData(TAG_NAME)) {
        node = (ExpressionNode) link.getPathElement().getUserData(TAG_NAME);
    } else {
        node = engine.parse(link.getPath());
        link.getPathElement().setUserData(TAG_NAME, node);
    }
    List<Base> matches = engine.evaluate(null, focus, focus, focus, node);
    check(!validating || matches.size() >= (link.hasMin() ? link.getMin() : 0), "Link at path " + path + " requires at least " + link.getMin() + " matches, but only found " + matches.size());
    check(!validating || matches.size() <= (link.hasMax() ? Integer.parseInt(link.getMax()) : Integer.MAX_VALUE), "Link at path " + path + " requires at most " + link.getMax() + " matches, but found " + matches.size());
    for (Base sel : matches) {
        // todo: should a URL be ok?
        check(sel.fhirType().equals("Reference"), "Selected node from an expression must be a Reference");
        ReferenceResolution res = services.lookup(appInfo, focus, (Reference) sel);
        if (res != null) {
            // todo
            check(res.getTargetContext() != focus, "how to handle contained resources is not yet resolved");
            for (GraphDefinitionLinkTargetComponent tl : link.getTarget()) {
                if (tl.getType().equals(res.getTarget().fhirType())) {
                    Resource r = (Resource) res.getTarget();
                    if (!isInBundle(r)) {
                        addToBundle(r);
                        for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
                            processLink(focus.fhirType(), r, l, depth + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent) ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode) ReferenceResolution(org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r5.model.Resource) GraphDefinitionLinkTargetComponent(org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkTargetComponent) Base(org.hl7.fhir.r5.model.Base)

Example 4 with GraphDefinitionLinkComponent

use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method execute.

public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
    assert services != null;
    assert start != null;
    assert bundle != null;
    assert baseURL != null;
    assert graphDefinition != null;
    graphDefinition.checkNoModifiers("definition", "Building graph from GraphDefinition");
    check(!start.fhirType().equals(graphDefinition.getStart()), "The Graph definition requires that the start (focus reosource) is " + graphDefinition.getStart() + ", but instead found " + start.fhirType());
    if (!isInBundle(start)) {
        addToBundle(start);
    }
    for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
        processLink(start.fhirType(), start, l, 1);
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent)

Example 5 with GraphDefinitionLinkComponent

use of org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method execute.

public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
    assert services != null;
    assert start != null;
    assert bundle != null;
    assert baseURL != null;
    assert graphDefinition != null;
    graphDefinition.checkNoModifiers("definition", "Building graph from GraphDefinition");
    check(!start.fhirType().equals(graphDefinition.getStart()), "The Graph definition requires that the start (focus reosource) is " + graphDefinition.getStart() + ", but instead found " + start.fhirType());
    if (!isInBundle(start)) {
        addToBundle(start);
    }
    for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
        processLink(start.fhirType(), start, l, 1);
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent)

Aggregations

IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)4 GraphDefinitionLinkComponent (org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent)3 GraphDefinitionLinkComponent (org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent)3 ArrayList (java.util.ArrayList)2 Resource (org.hl7.fhir.r4b.model.Resource)2 Resource (org.hl7.fhir.r5.model.Resource)2 Argument (org.hl7.fhir.utilities.graphql.Argument)2 ReferenceResolution (org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)2 Base (org.hl7.fhir.r4b.model.Base)1 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)1 GraphDefinitionLinkTargetComponent (org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkTargetComponent)1 Base (org.hl7.fhir.r5.model.Base)1 ExpressionNode (org.hl7.fhir.r5.model.ExpressionNode)1 GraphDefinitionLinkTargetComponent (org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkTargetComponent)1