14.6.1Validation Examples

 

14.6.1.1Generate a Snapshot profile from a Differential

The following code can be used to generate a Snapshot Profile (StructureDefinition) when all you have is a differential.

// Create a validation support chain that includes default validation support 
// and a snapshot generator
DefaultProfileValidationSupport defaultSupport = new DefaultProfileValidationSupport();
SnapshotGeneratingValidationSupport snapshotGenerator = new SnapshotGeneratingValidationSupport(myFhirCtx, defaultSupport);
ValidationSupportChain chain = new ValidationSupportChain(defaultSupport, snapshotGenerator);

// Generate the snapshot
StructureDefinition snapshot = chain.generateSnapshot(differential, "http://foo", null, "THE BEST PROFILE");

14.6.1.2Validate a Resource with Cross Version Extensions

The following code can be used to validate a resource using FHIR Cross Version Extensions.

Note that you must have the hl7.fhir.xver-extensions-0.0.11.tgz package available in your classpath.

// Create a validation support chain that includes default validation support
// and support from the hl7.fhir.xver-extensions NPM pacakage. 
NpmPackageValidationSupport npmPackageSupport = new NpmPackageValidationSupport(myFhirCtx);
npmPackageSupport.loadPackageFromClasspath("classpath:package/hl7.fhir.xver-extensions-0.0.11.tgz");

myFhirCtx.setValidationSupport(new ValidationSupportChain(
        new DefaultProfileValidationSupport(myFhirCtx),
        npmPackageSupport
   ));
    
FhirInstanceValidator instanceValidator = new FhirInstanceValidator(myFhirCtx);
	
FhirValidator validator = myFhirCtx.newValidator();
validator.registerValidatorModule(instanceValidator);

// Validate theResource
ValidationResult validationResult = validator.validateWithResult(theResource);