use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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");
}
use of org.hl7.fhir.r4b.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");
}
Aggregations