public LiquidEngine(IWorkerContext context, IEvaluationContext hostServices) { super(); this.externalHostServices = hostServices; engine = new FHIRPathEngine(context); engine.setHostServices(this); }
private List<Resource> filterResources(Argument fhirpath, List<Resource> list) throws EGraphQLException, FHIRException { List<Resource> result = new ArrayList<Resource>(); if (list.size() > 0) { if ((fhirpath == null)) for (Resource v : list) result.add(v); else { FHIRPathEngine fpe = new FHIRPathEngine(context); ExpressionNode node = fpe.parse(getSingleValue(fhirpath)); for (Resource v : list) if (fpe.evaluateToBoolean(null, v, v, node)) result.add(v); } } return result; }
/** * evaluate a path and return true or false (e.g. for an invariant) * * @param base - the object against which the path is being evaluated * @return * @throws FHIRException * @ */ public boolean evaluateToBoolean(Base resource, Base base, ExpressionNode node) throws FHIRException { return convertToBoolean(evaluate(null, resource, base, node)); }
/** * evaluate a path and a string containing the outcome (for display) * * @param base - the object against which the path is being evaluated * @param path - the FHIR Path statement to use * @return * @throws FHIRException * @ */ public String evaluateToString(Base base, String path) throws FHIRException { return convertToString(evaluate(base, path)); }
protected List<Object> extractValues(String thePaths, IBaseResource theResource) { IWorkerContext worker = new org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext(getContext(), myValidationSupport); FHIRPathEngine fp = new FHIRPathEngine(worker); fp.setHostServices(new SearchParamExtractorR4HostServices()); List<Base> allValues; try { allValues = fp.evaluate((Base) theResource, nextPath); } catch (FHIRException e) { String msg = getContext().getLocalizer().getMessage(BaseSearchParamExtractor.class, "failedToExtractPaths", nextPath, e.toString());
@Override public void evaluate(StringBuilder b, Resource resource, LiquidEngineContext ctxt) throws FHIRException { if (compiled == null) compiled = engine.parse(condition); boolean ok = engine.evaluateToBoolean(ctxt, resource, resource, compiled); List<LiquidNode> list = ok ? thenBody : elseBody; for (LiquidNode n : list) { n.evaluate(b, resource, ctxt); } } }
@Override public void evaluate(StringBuilder b, Resource resource, LiquidEngineContext ctxt) throws FHIRException { if (compiled == null) compiled = engine.parse(condition); List<Base> list = engine.evaluate(ctxt, resource, resource, compiled); LiquidEngineContext lctxt = new LiquidEngineContext(ctxt); for (Base o : list) { lctxt.vars.put(varName, o); for (LiquidNode n : body) { n.evaluate(b, resource, lctxt); } } } }
FHIRPathEngine fhirPathEngine = new FHIRPathEngine(new HapiWorkerContext(theContext, VALIDATION_SUPPORT)); try { fhirPathEngine.parse(theExpression); } catch (FHIRLexer.FHIRLexerException e) { throw new UnprocessableEntityException("Invalid SearchParameter.expression value \"" + theExpression + "\": " + e.getMessage());
/** * Parse a path for later use using execute * * @param path * @return * @throws PathEngineException * @throws Exception */ public ExpressionNode parse(String path) throws FHIRLexerException { return parse(path, null); }
if (rule(errors, IssueType.BUSINESSRULE, profile.getId()+"::"+ed.getPath()+"::"+inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression ("+inv.getXpath()+")")) { try { new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression()); // , inv.hasXpath() && inv.getXpath().startsWith("@value") } catch (Exception e) {
long t = System.nanoTime(); try { n = fpe.parse(inv.getExpression()); } catch (FHIRLexerException e) { throw new FHIRException("Problem processing expression "+inv.getExpression() +" in profile " + profile.getUrl() + " path " + path + ": " + e.getMessage()); try { long t = System.nanoTime(); ok = fpe.evaluateToBoolean(hostContext, resource, element, n); fpeTime = fpeTime + (System.nanoTime() - t); msg = fpe.forLog(); } catch (Exception ex) { ok = false;
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_SEARCH_EXPRESSION); if (expr == null) { expr = fpe.parse(src.getElement()); src.setUserData(MAP_SEARCH_EXPRESSION, expr); String search = fpe.evaluateToString(vars, null, new StringType(), expr); // string is a holder of nothing to ensure that variables are processed correctly items = services.performSearch(context.appInfo, search); } else { ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION); if (expr == null) { expr = fpe.parse(src.getCondition()); if (!fpe.evaluateToBoolean(vars, null, item, expr)) { log(indent+" condition ["+src.getCondition()+"] for "+item.toString()+" : false"); remove.add(item); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_CHECK); if (expr == null) { expr = fpe.parse(src.getCheck()); if (!fpe.evaluateToBoolean(vars, null, item, expr)) throw new FHIRException("Rule \""+ruleId+"\": Check condition failed"); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_LOG); if (expr == null) { expr = fpe.parse(src.getLogMessage()); b.appendIfNotNull(fpe.evaluateToString(vars, null, item, expr));
@Override public void evaluate(StringBuilder b, Resource resource, LiquidEngineContext ctxt) throws FHIRException { if (compiled == null) compiled = engine.parse(statement); b.append(engine.evaluateToString(ctxt, resource, resource, compiled)); } }
public FluentPathR4(FhirContext theCtx) { if (!(theCtx.getValidationSupport() instanceof IValidationSupport)) { throw new IllegalStateException("Validation support module configured on context appears to be for the wrong FHIR version- Does not extend " + IValidationSupport.class.getName()); } IValidationSupport validationSupport = (IValidationSupport) theCtx.getValidationSupport(); myEngine = new FHIRPathEngine(new HapiWorkerContext(theCtx, validationSupport)); }
/** * evaluate a path and return the matching elements * * @param base - the object against which the path is being evaluated * @param path - the FHIR Path statement to use * @return * @throws FHIRException * @ */ public List<Base> evaluate(Object appContext, Resource resource, Base base, String path) throws FHIRException { ExpressionNode exp = parse(path); List<Base> list = new ArrayList<Base>(); if (base != null) list.add(base); log = new StringBuilder(); return execute(new ExecutionContext(appContext, resource, base, null, base), list, exp, true); }
ExpressionNode expr = fpe.parse(discriminator); long t2 = System.nanoTime(); ElementDefinition ed = fpe.evaluateDefinition(expr, profile, element); sdTime = sdTime + (System.nanoTime() - t2); return ed;
sd = fetchStructureByType(element); if (sd == null) throw new DefinitionException("Problem with use of resolve() - profile '"+element.getType().get(0).getProfile()+"' on "+element.getId()+" could not be resolved"); if (tailMatches(t, expr.getName())) { focus = t; break; return focus; else return evaluateDefinition(expr.getInner(), sd, focus);
public boolean evaluateSlicingExpression(ValidatorHostContext hostContext, Element element, String path, StructureDefinition profile, ExpressionNode n) throws FHIRException { String msg; boolean ok; try { long t = System.nanoTime(); ok = fpe.evaluateToBoolean(hostContext, hostContext.resource, element, n); fpeTime = fpeTime + (System.nanoTime() - t); msg = fpe.forLog(); } catch (Exception ex) { ex.printStackTrace(); throw new FHIRException("Problem evaluating slicing expression for element in profile " + profile.getUrl() + " path " + path + " (fhirPath = "+n+"): " + ex.getMessage()); } return ok; }
@SuppressWarnings("unchecked") @Override public <T extends IBase> List<T> evaluate(IBase theInput, String thePath, Class<T> theReturnType) { List<Base> result; try { result = myEngine.evaluate((Base) theInput, thePath); } catch (FHIRException e) { throw new FluentPathExecutionException(e); } for (Base next : result) { if (!theReturnType.isAssignableFrom(next.getClass())) { throw new FluentPathExecutionException("FluentPath expression \"" + thePath + "\" returned unexpected type " + next.getClass().getSimpleName() + " - Expected " + theReturnType.getName()); } } return (List<T>) result; }