How to handle the unknown profiles

84 views
Skip to first unread message

Armin Shafiee

unread,
Oct 19, 2022, 6:52:00 AM10/19/22
to HAPI FHIR
Hello,

I use a ValidationSupportChain that also includes NpmPackageValidationSupport. Now, I intend to build a logic that rejects a validation for the unknown ProfileURLs (i.e. only validates the sources with a certain ProfileURL, e.g. "https://gematik.de/fhir/isik/v2/Basismodul/StructureDefinition/ISiKPatient"). 

On this way, I have found the following two methods.
1) isErrorForUnknownProfiles() from class FhirInstanceValidator 
2) addProfile(String theProfileUri) from class ValidationOptions

But I do not know exactly how best to use these methods for my purpose mentioned above. Or is there another better solution that I do not know yet?

Here is the code snippet where I am trying to build the logic right now:

public ValidationResult validateResource(IBaseResource resource) throws IOException {

FhirContext hapiFhirContext = pegFhirContext.getHapiFhirContext();

CachingValidationSupport validationSupport = pegFhirContext.getConfig().getValidationSupport(hapiFhirContext);

FhirInstanceValidator module = new FhirInstanceValidator(validationSupport);
module.setErrorForUnknownProfiles(true);
ValidationOptions options = new ValidationOptions();
options.addProfile("https://gematik.de/fhir/isik/v2/Basismodul/StructureDefinition/ISiKPatient");
FhirValidator validator = hapiFhirContext.newValidator();
validator.registerValidatorModule(module);
return validator.validateWithResult(resource, options);
}

I would like to know if anyone could help me with this.

Thanks in advance! 

Best regards,
Armin Shafiee
Reply all
Reply to author
Forward
0 new messages