Search in sources :

Example 11 with FHIRPathEngine

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;
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) EOperationOutcome(org.hl7.fhir.r5.utils.EOperationOutcome) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 12 with FHIRPathEngine

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;
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ArrayList(java.util.ArrayList) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 13 with FHIRPathEngine

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);
        }
    }
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) FHIRPathEngine(org.hl7.fhir.r4b.utils.FHIRPathEngine) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 14 with FHIRPathEngine

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;
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 15 with FHIRPathEngine

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());
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) Base(org.hl7.fhir.dstu3.model.Base) Test(org.junit.jupiter.api.Test)

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