Smile CDR v2024.05.PRE
On this page:

9.7.1Java Repository Validation Bean

 

More granular validation support can be provided by adding your own implementation(s) of IValidationSupport to the Repository Validation Chain.

For example, if you needed to add custom code handling for a specific code system, you could write a class like the following.

package com.example.fhir;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.ConceptValidationOptions;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext;
import org.springframework.beans.factory.annotation.Autowired;

public class CustomValidator implements IValidationSupport {
	public static FhirContext ourFhirContext = FhirContext.forR4Cached();
	public static String SYSTEM = "http://example.com/system";
	public static String GOOD_CODE = "123";
	public static String GOOD_DISPLAY = "code display";
	public static String WARNING_CODE = "456";
	public static String WARNING_MESSAGE = "this code should not be used";
	public static String FATAL_CODE = "789";


   @Autowired
   private FhirContext myFhirContext;

   @Override
   public FhirContext getFhirContext() {
      return myFhirContext;
   }

   @Override
   public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) {
      return SYSTEM.equals(theSystem);
   }

   @Override
   public CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
      if (SYSTEM.equals(theCodeSystem)) {
         if (GOOD_CODE.equals(theCode)) {
            return new IValidationSupport.CodeValidationResult()
               .setCode(theCode)
               .setDisplay(GOOD_DISPLAY);
         } else if (WARNING_CODE.equals(theCode)) {
            return new IValidationSupport.CodeValidationResult()
               .setSeverity(IssueSeverity.WARNING)
               .setMessage(WARNING_MESSAGE);
         } else if (FATAL_CODE.equals(theCode)) {
            return new IValidationSupport.CodeValidationResult()
               .setSeverity(IssueSeverity.FATAL);
         }
      }
      return null;
   }
}

You may register these validator beans with the Storage Module in the same way as Storage Interceptors are registered: Compile the validator classes into a jar file and copy that jar file into the customerlib folder. See the "Registering An Interceptor" section on the Interceptors page for more details.

The only difference between registering a custom interceptor and registering a custom validator is the custom validator is registered using the "validator_bean_types" config key in the properties file

module.persistence.config.validator_bean_types=com.example.fhir.CustomValidator

More than one validator can be specified in a comma-separated list.

This config can also be managed in the Web Admin Console in the "Repository Validation" section of a Relational Storage Module.