<dependency>
<groupId>ca.uhn.hapi.fhir</groupId><artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>6.10.5</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>6.10.5</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation</artifactId>
<version>6.10.5</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
<version>6.10.5</version>
</dependency>
private boolean validateFhirRequest(
final String fhirRequestMessage
)
throws Exception
{
// Create a FhirContext for the desired FHIR version (e.g., DSTU3, R4).
final FhirContext fhirContext = FhirContext.forDstu3();
// Create NpmPackageValidationSupport to load your TGZ package.
final NpmPackageValidationSupport npmPackageSupport = new NpmPackageValidationSupport(fhirContext);
try
{
// Load the TGZ package from the classpath.
// Ensure the TGZ file is accessible on the classpath (e.g., in resources folder).
npmPackageSupport.loadPackageFromClasspath(this.eClaimsTgzFileClassPath);
}
catch (IOException ioe)
{
throw new Exception("Failed to load TGZ file.");
}
// Create a ValidationSupportChain
// Include DefaultProfileValidationSupport for core FHIR definitions and SnapshotGeneratingValidationSupport
// for generating snapshots if your IG profiles require them.
final ValidationSupportChain validationSupportChain = new ValidationSupportChain(
npmPackageSupport,
new DefaultProfileValidationSupport(fhirContext),
new CommonCodeSystemsTerminologyService(fhirContext),
new InMemoryTerminologyServerValidationSupport(fhirContext),
new SnapshotGeneratingValidationSupport(fhirContext)
);
// Create the FhirValidator from the current context.
final FhirValidator fhirValidator = fhirContext.newValidator();
fhirValidator.setConcurrentBundleValidation(false);
fhirValidator.setValidateAgainstStandardSchema(true);
final FhirInstanceValidator fhirInstanceValidator = new FhirInstanceValidator(validationSupportChain);
fhirInstanceValidator.setAnyExtensionsAllowed(true);
// fhirInstanceValidator.setAssumeValidRestReferences(true);
// fhirInstanceValidator.setCustomExtensionDomains("");
fhirInstanceValidator.setErrorForUnknownProfiles(false);
// fhirInstanceValidator.setNoBindingMsgSuppressed(true);
// fhirInstanceValidator.setNoExtensibleWarnings(true);
fhirInstanceValidator.setNoTerminologyChecks(true);
// fhirInstanceValidator.setValidatorPolicyAdvisor(null);
// fhirInstanceValidator.setValidatorResourceFetcher(null);
// Register the validation-support-chain.
fhirValidator.registerValidatorModule(fhirInstanceValidator);
try
{
final ValidationResult validationResult = fhirValidator.validateWithResult(fhirRequestMessage);
if (validationResult.isSuccessful())
{
return true;
}
System.out.println("\nRaw resource string is invalid. Validation messages:");
boolean errorsFound = false;
for (SingleValidationMessage next : validationResult.getMessages())
{
if (
(next.getSeverity() != ResultSeverityEnum.ERROR)
&&
(next.getSeverity() != ResultSeverityEnum.FATAL)
)
{
continue;
}
errorsFound = true;
System.out.println("\t - " + next.getMessage());
}
return !errorsFound;
}
catch (final Throwable thrown)
{
throw new Exception(thrown);
}
}
Error Thrown
HAPI-1758: Unable to find classpath resource: /org/hl7/fhir/dstu3/model/schema/fhir-single.xsd
--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/4ddc6f71-1738-44da-bb6e-15ab44004426n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/5feda921-27ee-4cb1-8a22-4d2aad5ba85en%40googlegroups.com.