Search in sources :

Example 6 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 = TestingUtilities.getWorkerContext(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.r5.model.StructureDefinition) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with FHIRPathEngine

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

the class ValidationEngine method validate.

// testing entry point
public OperationOutcome validate(FhirFormat format, InputStream stream, List<String> profiles) throws FHIRException, IOException, EOperationOutcome {
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    InstanceValidator validator = getValidator(format);
    validator.validate(null, messages, stream, format, asSdList(profiles));
    return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
Also used : InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 8 with FHIRPathEngine

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

the class ValidationEngine method initContext.

protected void initContext(TimeTracker tt) throws IOException {
    context.setCanNoTS(true);
    context.setCacheId(UUID.randomUUID().toString());
    // because of Forge
    context.setAllowLoadingDuplicates(true);
    context.setExpansionProfile(makeExpProfile());
    if (tt != null) {
        context.setClock(tt);
    }
    NpmPackage npmX = getPcm().loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
    context.loadFromPackage(npmX, null);
    this.fhirPathEngine = new FHIRPathEngine(context);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine)

Example 9 with FHIRPathEngine

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

the class ValidationEngine method evaluateFhirPath.

public String evaluateFhirPath(String source, String expression) throws FHIRException, IOException {
    Content cnt = igLoader.loadContent(source, "validate", false);
    FHIRPathEngine fpe = this.getValidator(null).getFHIRPathEngine();
    Element e = Manager.parseSingle(context, new ByteArrayInputStream(cnt.focus), cnt.cntType);
    ExpressionNode exp = fpe.parse(expression);
    return fpe.evaluateToString(new ValidatorHostContext(context, e), e, e, e, exp);
}
Also used : FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) Element(org.hl7.fhir.r5.elementmodel.Element) ValidatorHostContext(org.hl7.fhir.validation.instance.utils.ValidatorHostContext)

Example 10 with FHIRPathEngine

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

the class ValidationEngine method validate.

public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
    InstanceValidator validator = getValidator(cntType);
    validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
    return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
Also used : InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator)

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