Smile CDR v2024.08.PRE
On this page:

9.5.1Java Based Repository Validation


To enable Repository Validation using Java code, a custom interceptor class must be created and registered against the FHIR Storage module as described on the Interceptors Page.

This interceptor may apply any rules described in the HAPI FHIR Repository Validating Interceptor documentation.

The following example shows a simple repository validating interceptor usable within a Smile CDR FHIR Storage module.

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingInterceptor;
import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingRuleBuilder;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

 * This interceptor is intended to be registered against a Smile CDR FHIR Storage module.
public class DemoRepositoryValidatingInterceptor extends RepositoryValidatingInterceptor {

   private FhirContext myFhirContext;

   private ApplicationContext myApplicationContext;

    * This method will be called at startup time
   public void start() {

      // Ask the application context for a new Rule Builder
      RepositoryValidatingRuleBuilder ruleBuilder =

      // Here we will mandate only that any Patient resources stored in the repository
      // must declare conformance to the US Core profile, and must correctly validate.
      // You may add as many rules for as many resource types as you like here.

      // Resources of types other than Patient will not be subject to any rules by
      // this interceptor as it is, but more rules could be added here.

      // Create the ruleset and pass it to the interceptor
} and Best Practice Warnings

When ingesting HL7 v2.x and other data, it may be convenient to disable best-practice warnings. This can be done by appending .withBestPracticeWarningLevel("IGNORE") to one's .requireValidationToDeclaredProfiles() calls. It is worth noting that Smile CDR's HL7 v2.x data conversion is not guaranteed to produce resources that conform to anything other than the core FHIR spec.