diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/2843-revert-treat-canonicals-as-local.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/2843-revert-treat-canonicals-as-local.yaml new file mode 100644 index 00000000000..47e9bb8b859 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/2843-revert-treat-canonicals-as-local.yaml @@ -0,0 +1,6 @@ +--- +type: change +issue: 2843 +title: "Reverting the change to treat canonical references as local when setting the flag `getTreatBaseUrlsAsLocal()`. This +was added to address a limitation in `_include` that did not process references by canonical URLs. +The `_include` search operation now includes canonical references without special configuration." diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java index e55f240382a..1bfa13d10d0 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java @@ -20,7 +20,6 @@ package ca.uhn.fhir.jpa.searchparam.extractor; * #L% */ -import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.BaseRuntimeElementDefinition; @@ -28,6 +27,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.model.entity.ModelConfig; @@ -1415,11 +1415,6 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor } } - private boolean isOrCanBeTreatedAsLocal(IIdType theId) { - boolean acceptableAsLocalReference = !theId.isAbsolute() || myModelConfig.getTreatBaseUrlsAsLocal().contains(theId.getBaseUrl()); - return acceptableAsLocalReference; - } - public PathAndRef get(IBase theValue, String thePath) { extract(new SearchParamSet<>(), new RuntimeSearchParam(null, null, "Reference", null, null, null, null, null, null, null), diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java index 1292eb11d47..6d3b7c58010 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseStorageDao.java @@ -20,7 +20,6 @@ package ca.uhn.fhir.jpa.dao; * #L% */ -import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.i18n.Msg; @@ -70,7 +69,6 @@ import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.InstantType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Propagation; @@ -174,9 +172,7 @@ public abstract class BaseStorageDao { verifyBundleTypeIsAppropriateForStorage(theResource); if(!getConfig().getTreatBaseUrlsAsLocal().isEmpty()) { - FhirTerser terser = myFhirContext.newTerser(); - replaceAbsoluteReferencesWithRelative(theResource, terser); - replaceAbsoluteUrisWithRelative(theResource, terser); + replaceAbsoluteReferencesWithRelative(theResource, myFhirContext.newTerser()); } performAutoVersioning(theResource, thePerformIndexing); @@ -235,27 +231,6 @@ public abstract class BaseStorageDao { } } - /** - * Replace Canonical URI's with local references, if we find that the canonical should be treated as local. - */ - private void replaceAbsoluteUrisWithRelative(IBaseResource theResource, FhirTerser theTerser) { - - BaseRuntimeElementDefinition canonicalElementDefinition = myFhirContext.getElementDefinition("canonical"); - if (canonicalElementDefinition != null) { - Class> canonicalType = (Class>) canonicalElementDefinition.getImplementingClass(); - List> canonicals = theTerser.getAllPopulatedChildElementsOfType(theResource, canonicalType); - - //TODO GGG this is pretty inefficient if there are many baseUrls, and many canonicals. Consider improving. - for (String baseUrl : myModelConfig.getTreatBaseUrlsAsLocal()) { - for (IPrimitiveType canonical : canonicals) { - if (canonical.getValue().startsWith(baseUrl)) { - canonical.setValue(canonical.getValue().substring(baseUrl.length() + 1)); - } - } - } - } - } - /** * Handle {@link ModelConfig#getAutoVersionReferenceAtPaths() auto-populate-versions} *