Search in sources :

Example 21 with EGraphQLException

use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method checkDirectives.

private boolean checkDirectives(List<Directive> directives) throws EGraphQLException {
    Directive skip = null;
    Directive include = null;
    for (Directive dir : directives) {
        if (dir.getName().equals("skip")) {
            if ((skip == null))
                skip = dir;
            else
                throw new EGraphQLException("Duplicate @skip directives");
        } else if (dir.getName().equals("include")) {
            if ((include == null))
                include = dir;
            else
                throw new EGraphQLException("Duplicate @include directives");
        } else if (!Utilities.existsInList(dir.getName(), "flatten", "first", "singleton", "slice"))
            throw new EGraphQLException("Directive \"" + dir.getName() + "\" instanceof not recognised");
    }
    if ((skip != null && include != null))
        throw new EGraphQLException("Cannot mix @skip and @include directives");
    if (skip != null)
        return !checkBooleanDirective(skip);
    else if (include != null)
        return checkBooleanDirective(include);
    else
        return true;
}
Also used : Directive(org.hl7.fhir.utilities.graphql.Directive) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 22 with EGraphQLException

use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processReverseReferenceSearch.

private void processReverseReferenceSearch(Resource source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    List<Argument> params = new ArrayList<Argument>();
    Argument parg = null;
    for (Argument a : field.getArguments()) if (!(a.getName().equals("_reference")))
        params.add(a);
    else if ((parg == null))
        parg = a;
    else
        throw new EGraphQLException("Duplicate parameter _reference");
    if (parg == null)
        throw new EGraphQLException("Missing parameter _reference");
    Argument arg = new Argument();
    params.add(arg);
    arg.setName(getSingleValue(parg));
    arg.addValue(new StringValue(source.fhirType() + "/" + source.getId()));
    Bundle bnd = (Bundle) services.search(appInfo, field.getName().substring(0, field.getName().length() - 10), params);
    Base bndWrapper = new SearchWrapper(field.getName(), bnd);
    arg = target.addField(field.getAlias() + suffix, listStatus(field, false));
    ObjectValue obj = new ObjectValue();
    arg.addValue(obj);
    processObject(null, bndWrapper, obj, field.getSelectionSet(), inheritedList, suffix);
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) Bundle(org.hl7.fhir.r4b.model.Bundle) ArrayList(java.util.ArrayList) StringValue(org.hl7.fhir.utilities.graphql.StringValue) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException) Base(org.hl7.fhir.r4b.model.Base)

Example 23 with EGraphQLException

use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method filterResources.

private List<Resource> filterResources(Argument fhirpath, List<IBaseResource> list) throws EGraphQLException, FHIRException {
    List<Resource> result = new ArrayList<Resource>();
    if (list.size() > 0) {
        if ((fhirpath == null))
            for (IBaseResource v : list) result.add((Resource) v);
        else {
            FHIRPathEngine fpe = new FHIRPathEngine(context);
            ExpressionNode node = fpe.parse(getSingleValue(fhirpath));
            for (IBaseResource v : list) if (fpe.evaluateToBoolean(null, (Resource) v, (Base) v, node))
                result.add((Resource) v);
        }
    }
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode) Resource(org.hl7.fhir.r4b.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) ArrayList(java.util.ArrayList) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4b.model.Base)

Example 24 with EGraphQLException

use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processSearchSingle.

private void processSearchSingle(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    String id = "";
    for (Argument arg : field.getArguments()) if ((arg.getName().equals("id")))
        id = getSingleValue(arg);
    else
        throw new EGraphQLException("Unknown/invalid parameter " + arg.getName());
    if (Utilities.noString(id))
        throw new EGraphQLException("No id found");
    Resource res = (Resource) services.lookup(appInfo, field.getName(), id);
    if (res == null)
        throw new EGraphQLException("Resource " + field.getName() + "/" + id + " not found");
    Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, false));
    ObjectValue obj = new ObjectValue();
    arg.addValue(obj);
    processObject(res, res, obj, field.getSelectionSet(), inheritedList, suffix);
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) Resource(org.hl7.fhir.r4b.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DomainResource(org.hl7.fhir.r4b.model.DomainResource) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 25 with EGraphQLException

use of org.hl7.fhir.utilities.graphql.EGraphQLException in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method resolveValues.

private List<Value> resolveValues(Argument arg, int max, String vars) throws EGraphQLException {
    List<Value> result = new ArrayList<Value>();
    for (Value v : arg.getValues()) {
        if (!(v instanceof VariableValue))
            result.add(v);
        else {
            if (vars.contains(":" + v.toString() + ":"))
                throw new EGraphQLException("Recursive reference to variable " + v.toString());
            Argument a = workingVariables.get(v.toString());
            if (a == null)
                throw new EGraphQLException("No value found for variable \"" + v.toString() + "\" in \"" + arg.getName() + "\"");
            List<Value> vl = resolveValues(a, -1, vars + ":" + v.toString() + ":");
            result.addAll(vl);
        }
    }
    if ((max != -1 && result.size() > max))
        throw new EGraphQLException("Only " + Integer.toString(max) + " values are allowed for \"" + arg.getName() + "\", but " + Integer.toString(result.size()) + " enoucntered");
    return result;
}
Also used : Argument(org.hl7.fhir.utilities.graphql.Argument) VariableValue(org.hl7.fhir.utilities.graphql.VariableValue) StringValue(org.hl7.fhir.utilities.graphql.StringValue) ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) VariableValue(org.hl7.fhir.utilities.graphql.VariableValue) Value(org.hl7.fhir.utilities.graphql.Value) NameValue(org.hl7.fhir.utilities.graphql.NameValue) NumberValue(org.hl7.fhir.utilities.graphql.NumberValue) ArrayList(java.util.ArrayList) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Aggregations

EGraphQLException (org.hl7.fhir.utilities.graphql.EGraphQLException)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)21 Argument (org.hl7.fhir.utilities.graphql.Argument)20 ObjectValue (org.hl7.fhir.utilities.graphql.ObjectValue)20 ArrayList (java.util.ArrayList)16 StringValue (org.hl7.fhir.utilities.graphql.StringValue)12 ReferenceResolution (org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)8 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 DomainResource (org.hl7.fhir.r4b.model.DomainResource)5 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)5 Resource (org.hl7.fhir.r4b.model.Resource)5 Base (org.hl7.fhir.r4b.model.Base)4 Directive (org.hl7.fhir.utilities.graphql.Directive)4 NameValue (org.hl7.fhir.utilities.graphql.NameValue)4 NumberValue (org.hl7.fhir.utilities.graphql.NumberValue)4 Value (org.hl7.fhir.utilities.graphql.Value)4 VariableValue (org.hl7.fhir.utilities.graphql.VariableValue)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3