001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.config; 021 022import ca.uhn.fhir.context.FhirContext; 023import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; 024import ca.uhn.fhir.context.support.IValidationSupport; 025import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; 026import ca.uhn.fhir.jpa.api.dao.DaoRegistry; 027import ca.uhn.fhir.jpa.dao.JpaPersistedResourceValidationSupport; 028import ca.uhn.fhir.jpa.validation.ValidatorPolicyAdvisor; 029import ca.uhn.fhir.jpa.validation.ValidatorResourceFetcher; 030import ca.uhn.fhir.validation.IInstanceValidatorModule; 031import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; 032import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; 033import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; 034import org.springframework.beans.factory.annotation.Autowired; 035import org.springframework.context.annotation.Bean; 036import org.springframework.context.annotation.Configuration; 037import org.springframework.context.annotation.Lazy; 038 039@Configuration 040public class ValidationSupportConfig { 041 042 @Autowired 043 private FhirContext myFhirContext; 044 045 @Bean(name = JpaConfig.DEFAULT_PROFILE_VALIDATION_SUPPORT) 046 public DefaultProfileValidationSupport defaultProfileValidationSupport() { 047 return new DefaultProfileValidationSupport(myFhirContext); 048 } 049 050 @Bean 051 public InMemoryTerminologyServerValidationSupport inMemoryTerminologyServerValidationSupport( 052 FhirContext theFhirContext, JpaStorageSettings theStorageSettings) { 053 InMemoryTerminologyServerValidationSupport retVal = 054 new InMemoryTerminologyServerValidationSupport(theFhirContext); 055 retVal.setIssueSeverityForCodeDisplayMismatch(theStorageSettings.getIssueSeverityForCodeDisplayMismatch()); 056 return retVal; 057 } 058 059 @Bean(name = JpaConfig.JPA_VALIDATION_SUPPORT) 060 public IValidationSupport jpaValidationSupport(FhirContext theFhirContext) { 061 return new JpaPersistedResourceValidationSupport(theFhirContext); 062 } 063 064 @Bean(name = "myInstanceValidator") 065 public IInstanceValidatorModule instanceValidator( 066 FhirContext theFhirContext, IValidationSupport theValidationSupportChain, DaoRegistry theDaoRegistry) { 067 FhirInstanceValidator val = new FhirInstanceValidator(theValidationSupportChain); 068 val.setValidatorResourceFetcher( 069 jpaValidatorResourceFetcher(theFhirContext, theValidationSupportChain, theDaoRegistry)); 070 val.setValidatorPolicyAdvisor(jpaValidatorPolicyAdvisor()); 071 val.setBestPracticeWarningLevel(BestPracticeWarningLevel.Warning); 072 return val; 073 } 074 075 @Bean 076 @Lazy 077 public ValidatorResourceFetcher jpaValidatorResourceFetcher( 078 FhirContext theFhirContext, IValidationSupport theValidationSupport, DaoRegistry theDaoRegistry) { 079 return new ValidatorResourceFetcher(theFhirContext, theValidationSupport, theDaoRegistry); 080 } 081 082 @Bean 083 @Lazy 084 public ValidatorPolicyAdvisor jpaValidatorPolicyAdvisor() { 085 return new ValidatorPolicyAdvisor(); 086 } 087}