001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2023 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.validation;
021
022import ca.uhn.fhir.context.FhirContext;
023import ca.uhn.fhir.context.support.IValidationSupport;
024import ca.uhn.fhir.jpa.packages.NpmJpaValidationSupport;
025import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc;
026import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
027import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService;
028import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport;
029import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport;
030import org.hl7.fhir.common.hapi.validation.support.UnknownCodeSystemWarningValidationSupport;
031import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
032import org.springframework.beans.factory.annotation.Autowired;
033import org.springframework.beans.factory.annotation.Qualifier;
034
035import javax.annotation.PostConstruct;
036import javax.annotation.PreDestroy;
037
038public class JpaValidationSupportChain extends ValidationSupportChain {
039
040        private final FhirContext myFhirContext;
041
042        @Autowired
043        @Qualifier("myJpaValidationSupport")
044        public IValidationSupport myJpaValidationSupport;
045
046        @Qualifier("myDefaultProfileValidationSupport")
047        @Autowired
048        private IValidationSupport myDefaultProfileValidationSupport;
049
050        @Autowired
051        private ITermReadSvc myTerminologyService;
052
053        @Autowired
054        private NpmJpaValidationSupport myNpmJpaValidationSupport;
055
056        @Autowired
057        private ITermConceptMappingSvc myConceptMappingSvc;
058
059        @Autowired
060        private UnknownCodeSystemWarningValidationSupport myUnknownCodeSystemWarningValidationSupport;
061
062        /**
063         * Constructor
064         */
065        public JpaValidationSupportChain(FhirContext theFhirContext) {
066                myFhirContext = theFhirContext;
067        }
068
069        @Override
070        public FhirContext getFhirContext() {
071                return myFhirContext;
072        }
073
074        @PreDestroy
075        public void flush() {
076                invalidateCaches();
077        }
078
079        @PostConstruct
080        public void postConstruct() {
081                addValidationSupport(myDefaultProfileValidationSupport);
082                addValidationSupport(myJpaValidationSupport);
083                addValidationSupport(myTerminologyService);
084                addValidationSupport(new SnapshotGeneratingValidationSupport(myFhirContext));
085                addValidationSupport(new InMemoryTerminologyServerValidationSupport(myFhirContext));
086                addValidationSupport(myNpmJpaValidationSupport);
087                addValidationSupport(new CommonCodeSystemsTerminologyService(myFhirContext));
088                addValidationSupport(myConceptMappingSvc);
089
090                // This needs to be last in the chain, it was designed for that
091                addValidationSupport(myUnknownCodeSystemWarningValidationSupport);
092        }
093}