Smile CDR v2024.05.PRE
On this page:

9.6.1JavaScript Based Repository Validation

 

If you would prefer not to write Java code, you can also enable repository validation using a JavaScript callback script.

The script described below should be configured to execute on your FHIR Storage module, using one of the two following configuration properties:

9.6.2Function: repositoryValidationProvideRules(theRuleBuilder)

 

The repositoryValidationProvideRules function is called once during each startup of the FHIR Storage module. It is responsible

9.6.2.1Parameters

  • theRuleBuilder – This parameter is the JavaScript equivalent to the HAPI FHIR Repository Validating RuleBuilder and has the exact same API. See examples below to see how to use this rule builder in a callback script.

9.6.3Example: Require a Specific Profile

 

The following example shows a simple callback that declares that all Patient resources stored in the repository must declare conformance to the given profile.

/**
 * This function is a callback for Smile CDR Repository Validation.
 *
 * @param theRuleBuilder
 * @returns {*}
 */
function repositoryValidationProvideRules(theRuleBuilder) {

   // Require Patient resources to declare conformance to the US Core Patient Profile
   theRuleBuilder
      .forResourcesOfType("Patient")
      .requireAtLeastProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");

}

With this script in place, a Patient resource would be rejected from storage unless it contained the profile declaration shown in the example resource below. Other resource types would always be accepted, as there are no rules declared for any other resource types. Note that using the requireAtLeastProfile(..) rule means that resources are required to declare conformance to a profile, but does not actually check that they have actually correctly implemented the given profile. See the Require Profile and Validate example below to add a mandatory validation step that ensures correct conformance to the profile as well.

{
   "resourceType": "Patient",
   "id": "123",
   "meta": {
      "profile": [
         "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
      ]
   }
}

9.6.4Example: Allow Several Profiles for a Resource Type

 

If you wish to support several profiles in your repository, the following script requires any resources being stored to declare conformance to at least one of the profiles declared in the script (it is not required to declare conformance to all of them).

/**
 * This function is a callback for Smile CDR Repository Validation.
 *
 * @param theRuleBuilder
 * @returns {*}
 */
function repositoryValidationProvideRules(theRuleBuilder) {

   // Require Patient resources to declare conformance to either the
   // US Core Patient Profile, or the CARIN IG for Blue Button® Profile
   theRuleBuilder
      .forResourcesOfType("Patient")
      .requireAtLeastOneProfileOf(
         "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient",
         "http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Patient"
         );

}

9.6.5Example: Require Profile and Validate

 

The examples above only require resources to declare conformance to specific profiles, but do not actually test that the resources are actually conformant. The following script adds a validation step as well.

/**
 * This function is a callback for Smile CDR Repository Validation.
 *
 * @param theRuleBuilder
 * @returns {*}
 */
function repositoryValidationProvideRules(theRuleBuilder) {

   // Require Patient resources to declare conformance to either the
   // US Core Patient Profile, or the CARIN IG for Blue Button® Profile
   theRuleBuilder
      .forResourcesOfType("Patient")
      .requireAtLeastOneProfileOf(
         "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient",
         "http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Patient");

   // Also require that Patient resources successfully pass validation
   theRuleBuilder
      .forResourcesOfType("Patient")
      .requireValidationToDeclaredProfiles();

}

9.6.5.1Validation 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.