Search in sources :

Example 1 with DefaultProfileValidationSupport

use of ca.uhn.fhir.context.support.DefaultProfileValidationSupport in project fhir-bridge by ehrbase.

the class FhirValidationConfiguration method validationSupport.

public IValidationSupport validationSupport() {
    ValidationSupportChain validationSupportChain = new ValidationSupportChain();
    // Validates core structure definitions
    DefaultProfileValidationSupport defaultProfileValidationSupport = new DefaultProfileValidationSupport(fhirContext);
    defaultProfileValidationSupport.fetchAllStructureDefinitions();
    defaultProfileValidationSupport.fetchCodeSystem("");
    validationSupportChain.addValidationSupport(defaultProfileValidationSupport);
    // Validates custom profiles (loaded from classpath)
    PrePopulatedValidationSupport prePopulatedValidationSupport = new PrePopulatedValidationSupport(fhirContext);
    IParser parser = fhirContext.newXmlParser();
    try {
        for (Resource resource : applicationContext.getResources("classpath:/profiles/*")) {
            StructureDefinition profile = parser.parseResource(StructureDefinition.class, resource.getInputStream());
            if (properties.isOptionalIdentifier()) {
                modifyProfile(profile);
            }
            prePopulatedValidationSupport.addStructureDefinition(profile);
        }
    } catch (IOException e) {
        throw new FhirBridgeException("An I/O exception occurred while loading custom profiles");
    }
    validationSupportChain.fetchAllStructureDefinitions();
    defaultProfileValidationSupport.fetchCodeSystem("");
    validationSupportChain.addValidationSupport(prePopulatedValidationSupport);
    // Validates terminology: CodeSystems and ValueSets (using the internal and/or remote terminology service)
    if (isTerminologyValidationEnabled()) {
        TerminologyValidationMode mode = properties.getTerminology().getMode();
        if (mode == TerminologyValidationMode.REMOTE || mode == TerminologyValidationMode.MIXED) {
            RemoteTerminologyServiceValidationSupport remoteTerminologyServerValidationSupport = new RemoteTerminologyServiceValidationSupport(fhirContext);
            remoteTerminologyServerValidationSupport.setBaseUrl(properties.getTerminology().getServerBaseUrl());
            validationSupportChain.addValidationSupport(remoteTerminologyServerValidationSupport);
        }
        if (mode == TerminologyValidationMode.INTERNAL || mode == TerminologyValidationMode.MIXED) {
            validationSupportChain.addValidationSupport(new InMemoryTerminologyServerValidationSupport(fhirContext));
            validationSupportChain.addValidationSupport(new CommonCodeSystemsTerminologyService(fhirContext));
        }
    }
    return new CachingValidationSupport(validationSupportChain);
}
Also used : PrePopulatedValidationSupport(org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport) RemoteTerminologyServiceValidationSupport(org.hl7.fhir.common.hapi.validation.support.RemoteTerminologyServiceValidationSupport) Resource(org.springframework.core.io.Resource) FhirBridgeException(org.ehrbase.fhirbridge.FhirBridgeException) IOException(java.io.IOException) DefaultProfileValidationSupport(ca.uhn.fhir.context.support.DefaultProfileValidationSupport) CommonCodeSystemsTerminologyService(org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) InMemoryTerminologyServerValidationSupport(org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport) ValidationSupportChain(org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain) TerminologyValidationMode(org.ehrbase.fhirbridge.fhir.common.validation.TerminologyValidationMode) CachingValidationSupport(org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport) IParser(ca.uhn.fhir.parser.IParser)

Example 2 with DefaultProfileValidationSupport

use of ca.uhn.fhir.context.support.DefaultProfileValidationSupport in project synthea by synthetichealth.

the class ValidationResources method initializeSTU3.

private void initializeSTU3() {
    FhirContext ctx = FhirStu3.getContext();
    FhirInstanceValidator instanceValidator = new FhirInstanceValidator(ctx);
    ValidationSupportChain chain = new ValidationSupportChain(new ValidationSupportSTU3(ctx), new DefaultProfileValidationSupport(ctx), new InMemoryTerminologyServerValidationSupport(ctx), new CommonCodeSystemsTerminologyService(ctx));
    instanceValidator.setValidationSupport(chain);
    instanceValidator.setAnyExtensionsAllowed(true);
    instanceValidator.setErrorForUnknownProfiles(false);
    validatorSTU3 = ctx.newValidator().registerValidatorModule(instanceValidator);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) InMemoryTerminologyServerValidationSupport(org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport) ValidationSupportChain(org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain) FhirInstanceValidator(org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator) DefaultProfileValidationSupport(ca.uhn.fhir.context.support.DefaultProfileValidationSupport) CommonCodeSystemsTerminologyService(org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService)

Example 3 with DefaultProfileValidationSupport

use of ca.uhn.fhir.context.support.DefaultProfileValidationSupport in project synthea by synthetichealth.

the class ValidationResources method initializeR4.

private void initializeR4() {
    FhirContext ctx = FhirR4.getContext();
    FhirInstanceValidator instanceValidator = new FhirInstanceValidator(ctx);
    ValidationSupportChain chain = new ValidationSupportChain(new ValidationSupportR4(ctx), new DefaultProfileValidationSupport(ctx), new InMemoryTerminologyServerValidationSupport(ctx), new CommonCodeSystemsTerminologyService(ctx));
    instanceValidator.setValidationSupport(chain);
    instanceValidator.setAnyExtensionsAllowed(true);
    instanceValidator.setErrorForUnknownProfiles(false);
    validatorR4 = ctx.newValidator().registerValidatorModule(instanceValidator);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) InMemoryTerminologyServerValidationSupport(org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport) ValidationSupportChain(org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain) FhirInstanceValidator(org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator) DefaultProfileValidationSupport(ca.uhn.fhir.context.support.DefaultProfileValidationSupport) CommonCodeSystemsTerminologyService(org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService)

Aggregations

DefaultProfileValidationSupport (ca.uhn.fhir.context.support.DefaultProfileValidationSupport)3 CommonCodeSystemsTerminologyService (org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService)3 InMemoryTerminologyServerValidationSupport (org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport)3 ValidationSupportChain (org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 FhirInstanceValidator (org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator)2 IParser (ca.uhn.fhir.parser.IParser)1 IOException (java.io.IOException)1 FhirBridgeException (org.ehrbase.fhirbridge.FhirBridgeException)1 TerminologyValidationMode (org.ehrbase.fhirbridge.fhir.common.validation.TerminologyValidationMode)1 CachingValidationSupport (org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport)1 PrePopulatedValidationSupport (org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport)1 RemoteTerminologyServiceValidationSupport (org.hl7.fhir.common.hapi.validation.support.RemoteTerminologyServiceValidationSupport)1 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)1 Resource (org.springframework.core.io.Resource)1