Search in sources :

Example 21 with FHIRPathEngine

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

the class SnapShotGenerationXTests method test.

@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String id, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
    version = test.version;
    this.context = context;
    if (fp == null)
        fp = new FHIRPathEngine(UtilitiesXTests.context(version));
    fp.setHostServices(context);
    messages = new ArrayList<ValidationMessage>();
    if (test.isFail()) {
        try {
            if (test.isGen())
                testGen(true, test);
            else
                testSort(test);
            Assertions.assertTrue(false, "Should have failed");
        } catch (Throwable e) {
            System.out.println("Error running test: " + e.getMessage());
            if (!Utilities.noString(test.regex)) {
                Assertions.assertTrue(e.getMessage().matches(test.regex), "correct error message");
            } else if ("Should have failed".equals(e.getMessage())) {
                throw e;
            } else {
                Assertions.assertTrue(true, "all ok");
            }
        }
    } else if (test.isGen())
        testGen(false, test);
    else
        testSort(test);
    for (Rule r : test.getRules()) {
        StructureDefinition sdn = new StructureDefinition();
        boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
        Assertions.assertTrue(ok, r.description);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) TypeDerivationRule(org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with FHIRPathEngine

use of org.hl7.fhir.r4b.utils.FHIRPathEngine in project kindling by HL7.

the class ExampleInspector method prepare.

public void prepare() throws Exception {
    validator = new InstanceValidator(context, hostServices, null);
    validator.setSuppressLoincSnomedMessages(true);
    validator.setResourceIdRule(IdStatus.REQUIRED);
    validator.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning);
    validator.getExtensionDomains().add("http://hl7.org/fhir/us");
    validator.setFetcher(this);
    validator.setAllowExamples(true);
    validator.setDebug(false);
    xml = new XmlValidator(errorsInt, loadSchemas(), loadTransforms());
    if (VALIDATE_BY_JSON_SCHEMA) {
        String source = TextFile.fileToString(Utilities.path(rootDir, "fhir.schema.json"));
        JSONObject rawSchema = new JSONObject(new JSONTokener(source));
        jschema = SchemaLoader.load(rawSchema);
    }
    if (VALIDATE_RDF) {
        shex = new ShExValidator(Utilities.path(rootDir, "fhir.shex"));
    }
    fpe = new FHIRPathEngine(context);
    checkJsonLd();
}
Also used : JSONTokener(org.json.JSONTokener) InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator) XmlValidator(org.hl7.fhir.definitions.validation.XmlValidator) JSONObject(org.json.JSONObject) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) ShExValidator(org.hl7.fhir.rdf.ShExValidator)

Example 23 with FHIRPathEngine

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

the class CDARoundTripTests 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 24 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(String location, byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationRecord> record) throws FHIRException, IOException, EOperationOutcome, SAXException {
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    if (doNative) {
        SchemaValidator.validateSchema(location, cntType, messages);
    }
    InstanceValidator validator = getValidator(cntType);
    validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
    if (showTimes) {
        System.out.println(location + ": " + validator.reportTimes());
    }
    if (record != null) {
        record.add(new ValidationRecord(location, messages));
    }
    return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
Also used : InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 25 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(String location, byte[] source, FhirFormat cntType, List<String> profiles, IdStatus resourceIdRule, boolean anyExtensionsAllowed, BestPracticeWarningLevel bpWarnings, CheckDisplayOption displayOption) throws FHIRException, IOException, EOperationOutcome, SAXException {
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    if (doNative) {
        SchemaValidator.validateSchema(location, cntType, messages);
    }
    InstanceValidator validator = getValidator(cntType);
    validator.setResourceIdRule(resourceIdRule);
    validator.setBestPracticeWarningLevel(bpWarnings);
    validator.setCheckDisplay(displayOption);
    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) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

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