hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.02k stars 1.32k forks source link

r5 Schema Not Found #1491

Closed jtravan3 closed 4 years ago

jtravan3 commented 5 years ago

Describe the bug I'm using the HAPI FHIR framework to validate FHIR resources. I just recently added the r5 support but now I'm getting an error stating Schema not found.

Failed to instantiate [ca.uhn.fhir.validation.FhirValidator]: Factory method 
'r5Validator' threw exception; nested exception is 
ca.uhn.fhir.rest.server.exceptions.InternalErrorException: Schema not found. 
Note that as of HAPI FHIR 1.2, DSTU2 validation files are kept in a separate JAR 
(hapi-fhir-validation-resources-XXX.jar) which must be added to your classpath. 
See the HAPI FHIR download page for more information.

Below is my pom.xml dependencies. I upgraded to HAPI version 4.0.3.

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox.swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox.swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons.lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons.io.version}</version>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-base</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>org.hl7.fhir.dstu2016may</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>org.hl7.fhir.dstu2</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>org.hl7.fhir.dstu3</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>org.hl7.fhir.r4</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>org.hl7.fhir.r5</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-dstu2</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-dstu2.1</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-dstu3</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r4</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r5</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>

        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation-resources-dstu2.1</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation-resources-r4</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-validation-resources-r5</artifactId>
            <version>${hapi.fhir.version}</version>
        </dependency>

        <dependency>
            <groupId>io.sentry</groupId>
            <artifactId>sentry-spring</artifactId>
            <version>${sentry.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.newrelic.agent.java</groupId>
            <artifactId>newrelic-api</artifactId>
            <version>${newrelic.version}</version>
        </dependency>

    </dependencies>

The code that is blowing up when running mvn clean install is

@Bean
    public FhirValidator r5Validator(){
        FhirContext fhirContext = FhirContext.forR5();
        FhirValidator fhirValidator = fhirContext.newValidator();
        fhirValidator.registerValidatorModule(new org.hl7.fhir.r5.hapi.validation.FhirInstanceValidator());

        // Create the Schema module and register it
        fhirValidator.registerValidatorModule(new SchemaBaseValidator(fhirContext));

        // Hacky way to pre-initialize the validator on startup
        fhirValidator.validateWithResult(new org.hl7.fhir.r5.model.Observation());

        return fhirValidator;
    }

The line that calls validateWithResult is what causes the issue. I think it fails when it tries to load /org/hl7/fhir/r5/model/extension/extension-definitions.xml. I have similar code for each version (dstu2, dstu3, r4, and r5) and they load everything fine on the build.

Any help?

Expected behavior Successful build.

Environment (please complete the following information):

jtravan3 commented 4 years ago

I discovered the issue. I was using the Schematron validator which, according to the documentation, is not recommended for r5 resources. https://hapifhir.io/hapi-fhir/docs/validation/schema_validator.html Sorry about that!