Search in sources :

Example 16 with EGraphQLException

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

the class GraphQLEngine method processReference.

private void processReference(Resource context, Base source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (!(source instanceof Reference))
        throw new EGraphQLException("Not done yet");
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    Reference ref = (Reference) source;
    ReferenceResolution res = services.lookup(appInfo, context, ref);
    if (res != null) {
        if (targetTypeOk(field.getArguments(), res.getTarget())) {
            Argument arg = target.addField(field.getAlias() + suffix, listStatus(field, inheritedList));
            ObjectValue obj = new ObjectValue();
            arg.addValue(obj);
            processObject((Resource) res.getTargetContext(), (Base) res.getTarget(), obj, field.getSelectionSet(), inheritedList, suffix);
        }
    } else if (!hasArgument(field.getArguments(), "optional", "true"))
        throw new EGraphQLException("Unable to resolve reference to " + ref.getReference());
}
Also used : ReferenceResolution(org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)

Example 17 with EGraphQLException

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

the class GraphQLEngine method processReverseReferenceList.

private void processReverseReferenceList(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<IBaseResource> list = new ArrayList<>();
    List<Argument> params = new ArrayList<>();
    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.getIdPart()));
    services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), params, list);
    arg = null;
    ObjectValue obj = null;
    List<Resource> vl = filterResources(field.argument("fhirpath"), list);
    if (!vl.isEmpty()) {
        arg = target.addField(field.getAlias() + suffix, listStatus(field, true));
        for (Resource v : vl) {
            obj = new ObjectValue();
            arg.addValue(obj);
            processObject(v, v, obj, field.getSelectionSet(), inheritedList, suffix);
        }
    }
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) 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) DomainResource(org.hl7.fhir.r4b.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringValue(org.hl7.fhir.utilities.graphql.StringValue) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 18 with EGraphQLException

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

the class GraphQLEngine method execute.

@Override
public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
    if (graphQL == null)
        throw new EGraphEngine("Unable to process graphql - graphql document missing");
    fpe = new FHIRPathEngine(this.context);
    magicExpression = new ExpressionNode(0);
    output = new GraphQLResponse();
    Operation op = null;
    // todo: initial conditions
    if (!Utilities.noString(graphQL.getOperationName())) {
        op = graphQL.getDocument().operation(graphQL.getOperationName());
        if (op == null)
            throw new EGraphEngine("Unable to find operation \"" + graphQL.getOperationName() + "\"");
    } else if ((graphQL.getDocument().getOperations().size() == 1))
        op = graphQL.getDocument().getOperations().get(0);
    else
        throw new EGraphQLException("No operation name provided, so expected to find a single operation");
    if (op.getOperationType() == OperationType.qglotMutation)
        throw new EGraphQLException("Mutation operations are not supported (yet)");
    checkNoDirectives(op.getDirectives());
    processVariables(op);
    if (focus == null)
        processSearch(output, op.getSelectionSet(), false, "");
    else
        processObject(focus, focus, output, op.getSelectionSet(), false, "");
}
Also used : EGraphEngine(org.hl7.fhir.utilities.graphql.EGraphEngine) ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode) GraphQLResponse(org.hl7.fhir.utilities.graphql.GraphQLResponse) Operation(org.hl7.fhir.utilities.graphql.Operation) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 19 with EGraphQLException

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

the class GraphQLEngine method processSearchSimple.

private void processSearchSimple(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    List<IBaseResource> list = new ArrayList<>();
    services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), field.getArguments(), list);
    Argument arg = null;
    ObjectValue obj = null;
    List<Resource> vl = filterResources(field.argument("fhirpath"), list);
    if (!vl.isEmpty()) {
        arg = target.addField(field.getAlias() + suffix, listStatus(field, true));
        for (Resource v : vl) {
            obj = new ObjectValue();
            arg.addValue(obj);
            processObject(v, v, obj, field.getSelectionSet(), inheritedList, suffix);
        }
    }
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) 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) DomainResource(org.hl7.fhir.r4b.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 20 with EGraphQLException

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

the class GraphQLEngine method processSearchFull.

private void processSearchFull(ObjectValue target, Field field, 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 carg = null;
    for (Argument arg : field.getArguments()) if (arg.getName().equals("cursor"))
        carg = arg;
    else
        params.add(arg);
    if ((carg != null)) {
        params.clear();
        ;
        String[] parts = getSingleValue(carg).split(":");
        params.add(new Argument("search-id", new StringValue(parts[0])));
        params.add(new Argument("search-offset", new StringValue(parts[1])));
    }
    Bundle bnd = (Bundle) services.search(appInfo, field.getName().substring(0, field.getName().length() - 10), params);
    SearchWrapper bndWrapper = new SearchWrapper(field.getName(), bnd);
    Argument 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)

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