use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class ValidatorUtils method messagesToOutcome.
protected static OperationOutcome messagesToOutcome(List<ValidationMessage> messages, SimpleWorkerContext context, FHIRPathEngine fpe) throws IOException, FHIRException, EOperationOutcome {
OperationOutcome op = new OperationOutcome();
for (ValidationMessage vm : filterMessages(messages)) {
try {
fpe.parse(vm.getLocation());
} catch (Exception e) {
System.out.println("Internal error in location for message: '" + e.getMessage() + "', loc = '" + vm.getLocation() + "', err = '" + vm.getMessage() + "'");
}
op.getIssue().add(OperationOutcomeUtilities.convertToIssue(vm, op));
}
if (!op.hasIssue()) {
op.addIssue().setSeverity(OperationOutcome.IssueSeverity.INFORMATION).setCode(OperationOutcome.IssueType.INFORMATIONAL).getDetails().setText(context.formatMessage(I18nConstants.ALL_OK));
}
RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, RenderingContext.ResourceRendererMode.END_USER);
RendererFactory.factory(op, rc).render(op);
return op;
}
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<>();
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;
}
use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project org.hl7.fhir.core by hapifhir.
the class XmlParserTests method setUp.
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
}
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 FhirPathTests method testFuncReplaceParamSize.
@Test
public void testFuncReplaceParamSize() {
FHIRPathEngine engine = Mockito.spy(new FHIRPathEngine(iWorkerContext));
ExpressionNode expressionNode = new ExpressionNode(0);
expressionNode.setKind(ExpressionNode.Kind.Function);
expressionNode.setFunction(ExpressionNode.Function.Replace);
ExpressionNode expressionNodeB = new ExpressionNode(1);
expressionNodeB.setKind(ExpressionNode.Kind.Function);
expressionNodeB.setFunction(ExpressionNode.Function.Empty);
ExpressionNode expressionNodeC = new ExpressionNode(2);
expressionNodeC.setKind(ExpressionNode.Kind.Function);
expressionNodeC.setFunction(ExpressionNode.Function.Empty);
expressionNode.getParameters().add(expressionNodeB);
expressionNode.getParameters().add(expressionNodeC);
List<Base> result = engine.evaluate(appContext, resource, base, expressionNode);
assertEquals(1, result.size());
Base onlyResult = result.get(0);
assertTrue(onlyResult instanceof StringType);
assertEquals("base", ((StringType) result.get(0)).asStringValue());
Mockito.verify(engine, times(2)).convertToString(any());
}
Aggregations