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