Search in sources :

Example 6 with Argument

use of org.hl7.fhir.utilities.graphql.Argument 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<>();
    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, (Resource) v, node))
                result.add((Resource) v);
        }
    }
    return result;
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ArrayList(java.util.ArrayList) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 7 with Argument

use of org.hl7.fhir.utilities.graphql.Argument 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 : ArrayList(java.util.ArrayList) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 8 with Argument

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

the class GraphQLEngineTests method testResource.

private void testResource(Resource resource, String output, String source) throws IOException, EGraphEngine, EGraphQLException {
    GraphQLEngine gql = new GraphQLEngine(TestingUtilities.context());
    gql.setServices(this);
    if (resource != null) {
        gql.setFocus(resource);
    }
    gql.setGraphQL(Parser.parseFile(TestingUtilities.resourceNameToFile("graphql", source)));
    gql.getGraphQL().setOperationName(null);
    gql.getGraphQL().getVariables().add(new Argument("var", new NameValue("true")));
    boolean ok = false;
    String msg = null;
    try {
        gql.execute();
        ok = true;
    } catch (Exception e) {
        if (!output.equals("$error"))
            e.printStackTrace();
        ok = false;
        msg = e.getMessage();
    }
    if (ok) {
        Assertions.assertTrue(!output.equals("$error"), "Expected to fail, but didn't");
        StringBuilder str = new StringBuilder();
        gql.getOutput().setWriteWrapper(false);
        gql.getOutput().write(str, 0);
        TextFile.stringToFile(str.toString(), TestingUtilities.resourceNameToFile("graphql", output + ".out"));
        msg = TestingUtilities.checkJsonIsSame(TestingUtilities.resourceNameToFile("graphql", output + ".out"), TestingUtilities.resourceNameToFile("graphql", output));
        Assertions.assertTrue(Utilities.noString(msg), msg);
    } else
        Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
Also used : GraphQLEngine(org.hl7.fhir.r4.utils.GraphQLEngine) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 9 with Argument

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

the class GraphQLEngineTests method search.

@Override
public Bundle search(Object appInfo, String type, List<Argument> searchParams) throws FHIRException {
    try {
        Bundle bnd = new Bundle();
        BundleLinkComponent bl = bnd.addLink();
        bl.setRelation("next");
        bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=50&_count=50");
        bl = bnd.addLink();
        bl.setRelation("self");
        bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=0&_count=50");
        BundleEntryComponent be = bnd.addEntry();
        be.setFullUrl("http://hl7.org/fhir/Patient/example");
        be.setResource(new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.resourceNameToFile("patient-example.xml")))));
        be = bnd.addEntry();
        be.setFullUrl("http://hl7.org/fhir/Patient/example");
        be.setResource(new XmlParser().parse(new FileInputStream(Utilities.path(TestingUtilities.resourceNameToFile("patient-example-xds.xml")))));
        be.getSearch().setScore(0.5);
        be.getSearch().setMode(SearchEntryMode.MATCH);
        bnd.setTotal(50);
        return bnd;
    } catch (Exception e) {
        throw new FHIRException(e);
    }
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException) BundleLinkComponent(org.hl7.fhir.r4.model.Bundle.BundleLinkComponent)

Example 10 with Argument

use of org.hl7.fhir.utilities.graphql.Argument 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) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringValue(org.hl7.fhir.utilities.graphql.StringValue) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Aggregations

Argument (org.hl7.fhir.utilities.graphql.Argument)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)22 ArrayList (java.util.ArrayList)21 EGraphQLException (org.hl7.fhir.utilities.graphql.EGraphQLException)20 ObjectValue (org.hl7.fhir.utilities.graphql.ObjectValue)20 StringValue (org.hl7.fhir.utilities.graphql.StringValue)16 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 ReferenceResolution (org.hl7.fhir.utilities.graphql.IGraphQLStorageServices.ReferenceResolution)8 IOException (java.io.IOException)7 List (java.util.List)6 Resource (org.hl7.fhir.r4b.model.Resource)6 NameValue (org.hl7.fhir.utilities.graphql.NameValue)6 NumberValue (org.hl7.fhir.utilities.graphql.NumberValue)6 DomainResource (org.hl7.fhir.r4b.model.DomainResource)5 Nonnull (javax.annotation.Nonnull)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Row (org.apache.spark.sql.Row)4 SAXException (org.xml.sax.SAXException)4 FhirPath (au.csiro.pathling.fhirpath.FhirPath)3 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)3