Search in sources :

Example 31 with FHIRPathEngine

use of org.hl7.fhir.dstu2016may.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method filterResources.

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

Example 32 with FHIRPathEngine

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

Example 33 with FHIRPathEngine

use of org.hl7.fhir.dstu2016may.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method filterResources.

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

Example 34 with FHIRPathEngine

use of org.hl7.fhir.dstu2016may.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.

the class FluentPathTests method testBoolean.

@SuppressWarnings("deprecation")
private void testBoolean(Resource resource, Base focus, String focusType, String expression, boolean value) throws FileNotFoundException, IOException, FHIRException {
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
    ExpressionNode node = fp.parse(expression);
    fp.check(null, resource == null ? null : resource.getResourceType().toString(), focusType, node);
    List<Base> outcome = fp.evaluate(null, resource, focus, node);
    if (fp.hasLog())
        System.out.println(fp.takeLog());
    Assertions.assertEquals(fp.convertToBoolean(outcome), value, "Wrong answer");
}
Also used : FHIRPathEngine(org.hl7.fhir.dstu2016may.utils.FHIRPathEngine) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 35 with FHIRPathEngine

use of org.hl7.fhir.dstu2016may.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.

the class FluentPathTests method testBoolean.

@SuppressWarnings("deprecation")
private void testBoolean(Resource resource, String expression, boolean value) throws FileNotFoundException, IOException, FHIRException {
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
    ExpressionNode node = fp.parse(expression);
    fp.check(null, null, resource.getResourceType().toString(), node);
    List<Base> outcome = fp.evaluate(null, null, resource, node);
    if (fp.hasLog())
        System.out.println(fp.takeLog());
    Assertions.assertEquals(fp.convertToBoolean(outcome), value, "Wrong answer");
}
Also used : FHIRPathEngine(org.hl7.fhir.dstu2016may.utils.FHIRPathEngine) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) Base(org.hl7.fhir.dstu2016may.model.Base)

Aggregations

ArrayList (java.util.ArrayList)9 FHIRPathEngine (org.hl7.fhir.r5.utils.FHIRPathEngine)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)7 InstanceValidator (org.hl7.fhir.validation.instance.InstanceValidator)6 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)4 FHIRPathEngine (org.hl7.fhir.dstu2016may.utils.FHIRPathEngine)4 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)4 IOException (java.io.IOException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)3 FileNotFoundException (java.io.FileNotFoundException)2 Base (org.hl7.fhir.dstu2016may.model.Base)2 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)2 DomainResource (org.hl7.fhir.r4b.model.DomainResource)2 Resource (org.hl7.fhir.r4b.model.Resource)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2 FHIRPathEngine (org.hl7.fhir.r4b.utils.FHIRPathEngine)2