001package ca.uhn.fhir.jpa.term.api;
002
003import ca.uhn.fhir.context.support.ConceptValidationOptions;
004import ca.uhn.fhir.context.support.IValidationSupport;
005import ca.uhn.fhir.context.support.ValueSetExpansionOptions;
006import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
007import ca.uhn.fhir.jpa.entity.TermConcept;
008import ca.uhn.fhir.jpa.entity.TermValueSet;
009import ca.uhn.fhir.jpa.model.entity.ResourceTable;
010import ca.uhn.fhir.jpa.term.IValueSetConceptAccumulator;
011import ca.uhn.fhir.rest.api.server.RequestDetails;
012import ca.uhn.fhir.util.FhirVersionIndependentConcept;
013import org.hl7.fhir.instance.model.api.IBaseCoding;
014import org.hl7.fhir.instance.model.api.IBaseDatatype;
015import org.hl7.fhir.instance.model.api.IBaseResource;
016import org.hl7.fhir.instance.model.api.IIdType;
017import org.hl7.fhir.instance.model.api.IPrimitiveType;
018import org.hl7.fhir.r4.model.CodeSystem;
019import org.hl7.fhir.r4.model.ValueSet;
020
021import javax.annotation.Nonnull;
022import javax.annotation.Nullable;
023import javax.transaction.Transactional;
024import java.util.List;
025import java.util.Optional;
026import java.util.Set;
027
028/*
029 * #%L
030 * HAPI FHIR JPA Server
031 * %%
032 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
033 * %%
034 * Licensed under the Apache License, Version 2.0 (the "License");
035 * you may not use this file except in compliance with the License.
036 * You may obtain a copy of the License at
037 *
038 *      http://www.apache.org/licenses/LICENSE-2.0
039 *
040 * Unless required by applicable law or agreed to in writing, software
041 * distributed under the License is distributed on an "AS IS" BASIS,
042 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
043 * See the License for the specific language governing permissions and
044 * limitations under the License.
045 * #L%
046 */
047
048/**
049 * This interface is the "read" interface for the terminology service. It handles things like
050 * lookups, code validations, expansions, concept mappings, etc.
051 * <p>
052 * It is intended to only handle read operations, leaving various write operations to
053 * other services within the terminology service APIs.
054 * (Note that at present, a few write operations remain here- they should be moved but haven't
055 * been moved yet)
056 * </p>
057 */
058public interface ITermReadSvc extends IValidationSupport {
059
060        ValueSet expandValueSet(@Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull String theValueSetCanonicalUrl);
061
062        ValueSet expandValueSet(@Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull ValueSet theValueSetToExpand);
063
064        void expandValueSet(@Nullable ValueSetExpansionOptions theExpansionOptions, ValueSet theValueSetToExpand, IValueSetConceptAccumulator theValueSetCodeAccumulator);
065
066        /**
067         * Version independent
068         */
069        IBaseResource expandValueSet(@Nullable ValueSetExpansionOptions theExpansionOptions, IBaseResource theValueSetToExpand);
070
071        void expandValueSet(@Nullable ValueSetExpansionOptions theExpansionOptions, IBaseResource theValueSetToExpand, IValueSetConceptAccumulator theValueSetCodeAccumulator);
072
073        List<FhirVersionIndependentConcept> expandValueSetIntoConceptList(ValueSetExpansionOptions theExpansionOptions, String theValueSetCanonicalUrl);
074
075        Optional<TermConcept> findCode(String theCodeSystem, String theCode);
076
077        List<TermConcept> findCodes(String theCodeSystem, List<String> theCodes);
078
079        Set<TermConcept> findCodesAbove(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersionPid, String theCode);
080
081        List<FhirVersionIndependentConcept> findCodesAbove(String theSystem, String theCode);
082
083        List<FhirVersionIndependentConcept> findCodesAboveUsingBuiltInSystems(String theSystem, String theCode);
084
085        Set<TermConcept> findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersionPid, String theCode);
086
087        List<FhirVersionIndependentConcept> findCodesBelow(String theSystem, String theCode);
088
089        List<FhirVersionIndependentConcept> findCodesBelowUsingBuiltInSystems(String theSystem, String theCode);
090
091        CodeSystem fetchCanonicalCodeSystemFromCompleteContext(String theSystem);
092
093        void deleteValueSetAndChildren(ResourceTable theResourceTable);
094
095        void storeTermValueSet(ResourceTable theResourceTable, ValueSet theValueSet);
096
097        IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType<String> theCodeA, IPrimitiveType<String> theCodeB, IPrimitiveType<String> theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB);
098
099        void preExpandDeferredValueSetsToTerminologyTables();
100
101        /**
102         * Version independent
103         */
104        CodeValidationResult validateCode(ConceptValidationOptions theOptions, IIdType theValueSetId, String theValueSetUrl, String theSystem, String theCode, String theDisplay, IBaseDatatype theCoding, IBaseDatatype theCodeableConcept);
105
106        /**
107         * Version independent
108         */
109        @Transactional()
110        CodeValidationResult validateCodeIsInPreExpandedValueSet(ConceptValidationOptions theOptions, IBaseResource theValueSet, String theSystem, String theCode, String theDisplay, IBaseDatatype theCoding, IBaseDatatype theCodeableConcept);
111
112        boolean isValueSetPreExpandedForCodeValidation(ValueSet theValueSet);
113
114        /**
115         * Version independent
116         */
117        boolean isValueSetPreExpandedForCodeValidation(IBaseResource theValueSet);
118
119        /**
120         * Version independent
121         */
122        CodeValidationResult codeSystemValidateCode(IIdType theCodeSystemId, String theValueSetUrl, String theVersion, String theCode, String theDisplay, IBaseDatatype theCoding, IBaseDatatype theCodeableConcept);
123
124        String invalidatePreCalculatedExpansion(IIdType theValueSetId, RequestDetails theRequestDetails);
125
126        /**
127         * Version independent
128         */
129        Optional<TermValueSet> findCurrentTermValueSet(String theUrl);
130
131        /**
132         * Version independent
133         */
134        Optional<IBaseResource> readCodeSystemByForcedId(String theForcedId);
135
136        /**
137         * Version independent
138         * Recreates freetext indexes for TermConcept and nested TermConceptProperty
139         */
140        ReindexTerminologyResult reindexTerminology() throws InterruptedException;
141
142}