diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6283-remove-unneeded-fields-from-resource-table.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6283-remove-unneeded-fields-from-resource-table.yaml new file mode 100644 index 00000000000..a1e871a8656 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6283-remove-unneeded-fields-from-resource-table.yaml @@ -0,0 +1,10 @@ +--- +type: remove +issue: 6283 +title: "Hibernate Search Fulltext fields which were unused + have been removed from indexing. + This will reduce storage usage in Lucene and Elasticsearch. + The fields that were removed are: `myNarrativeTextEdgeNGram`, + `myNarrativeTextNGram`, `myNarrativeTextPhonetic`, `myContentTextEdgeNGram`, + `myContentTextNGram`, `myContentTextPhonetic`. +" diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceTable.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceTable.java index e897ae71786..6163011eeb4 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceTable.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceTable.java @@ -119,21 +119,6 @@ public class ResourceTable extends BaseHasResource implements Serializable, IBas searchable = Searchable.YES, projectable = Projectable.YES, analyzer = "standardAnalyzer") - @FullTextField( - name = "myContentTextEdgeNGram", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompleteEdgeAnalyzer") - @FullTextField( - name = "myContentTextNGram", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompleteNGramAnalyzer") - @FullTextField( - name = "myContentTextPhonetic", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompletePhoneticAnalyzer") @OptimisticLock(excluded = true) @IndexingDependency(derivedFrom = @ObjectPath(@PropertyValue(propertyName = "myVersion"))) private String myContentText; @@ -171,21 +156,6 @@ public class ResourceTable extends BaseHasResource implements Serializable, IBas searchable = Searchable.YES, projectable = Projectable.YES, analyzer = "standardAnalyzer") - @FullTextField( - name = "myNarrativeTextEdgeNGram", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompleteEdgeAnalyzer") - @FullTextField( - name = "myNarrativeTextNGram", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompleteNGramAnalyzer") - @FullTextField( - name = "myNarrativeTextPhonetic", - searchable = Searchable.YES, - projectable = Projectable.NO, - analyzer = "autocompletePhoneticAnalyzer") @OptimisticLock(excluded = true) @IndexingDependency(derivedFrom = @ObjectPath(@PropertyValue(propertyName = "myVersion"))) private String myNarrativeText; diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ISearchParamExtractor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ISearchParamExtractor.java index 77a43ddc2e5..e8d1755c780 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ISearchParamExtractor.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ISearchParamExtractor.java @@ -44,13 +44,13 @@ public interface ISearchParamExtractor { /** * Constant for the {@literal theSearchParamFilter} parameters on this interface - * indicating that all search parameters should be indexed. + * indicating that all search parameters should be extracted. */ ISearchParamFilter ALL_PARAMS = t -> t; /** * Constant for the {@literal theSearchParamFilter} parameters on this interface - * indicating that no search parameters should be indexed. + * indicating that no search parameters should be extracted. */ ISearchParamFilter NO_PARAMS = t -> Collections.emptyList(); @@ -155,7 +155,7 @@ public interface ISearchParamExtractor { interface ISearchParamFilter { /** - * Given the list of search parameters for indexing, an implementation of this + * Given the list of search parameters for extracting, an implementation of this * interface may selectively remove any that it wants to remove (or can add if desired). *

* Implementations must not modify the list that is passed in. If changes are diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplCurrentVersionR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplCurrentVersionR4Test.java index 3eb62d47179..11d7cb3b767 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplCurrentVersionR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplCurrentVersionR4Test.java @@ -1,9 +1,8 @@ package ca.uhn.fhir.jpa.term; -import static org.junit.jupiter.api.Assertions.assertNull; import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.LookupCodeRequest; +import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.config.JpaConfig; import ca.uhn.fhir.jpa.entity.TermCodeSystem; @@ -20,9 +19,10 @@ import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import jakarta.persistence.EntityManager; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.IdType; @@ -40,8 +40,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.io.ClassPathResource; -import jakarta.persistence.EntityManager; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -82,14 +80,12 @@ import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_UPLOAD_ import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_XML_FILE; import static java.util.stream.Collectors.joining; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; import static org.hl7.fhir.common.hapi.validation.support.ValidationConstants.LOINC_ALL_VALUESET_ID; import static org.hl7.fhir.common.hapi.validation.support.ValidationConstants.LOINC_LOW; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; - import static org.mockito.Mockito.when; /** @@ -141,9 +137,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { @Autowired private Batch2JobHelper myBatchJobHelper; - - private ZipCollectionBuilder myFiles; - private ServletRequestDetails myRequestDetails = new ServletRequestDetails(); + private final ServletRequestDetails myRequestDetails = new ServletRequestDetails(); private Properties uploadProperties; private IFhirResourceDao myValueSetIFhirResourceDao; @@ -182,17 +176,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { private void validateValidateCode(String theCurrentVersion, Collection allVersions) { - IValidationSupport.CodeValidationResult resultNoVersioned = myCodeSystemDao.validateCode(null, - new UriType(BASE_LOINC_URL), null, new CodeType(VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE), - null, null, null, null); - assertNotNull(resultNoVersioned); - assertEquals(prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), resultNoVersioned.getDisplay()); - - IValidationSupport.CodeValidationResult resultVersioned = myCodeSystemDao.validateCode(null, - new UriType(BASE_LOINC_URL), null, new CodeType(VS_VERSIONED_ON_UPLOAD_FIRST_CODE), - null, null, null, null); - assertNotNull(resultVersioned); - assertEquals(prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), resultVersioned.getDisplay()); + validateValidateCodeForVersion(theCurrentVersion); allVersions.forEach(this::validateValidateCodeForVersion); } @@ -215,13 +199,15 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { private void validateValueLookup(String theCurrentVersion, Collection allVersions) { IValidationSupport.LookupCodeResult resultNoVer = myValidationSupport.lookupCode( - new ValidationSupportContext(myValidationSupport), new LookupCodeRequest(BASE_LOINC_URL, VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE)); + new ValidationSupportContext(myValidationSupport), + new LookupCodeRequest(BASE_LOINC_URL, VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE)); assertNotNull(resultNoVer); String expectedNoVer = prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY); assertEquals(expectedNoVer, resultNoVer.getCodeDisplay()); IValidationSupport.LookupCodeResult resultWithVer = myValidationSupport.lookupCode( - new ValidationSupportContext(myValidationSupport), new LookupCodeRequest(BASE_LOINC_URL, VS_VERSIONED_ON_UPLOAD_FIRST_CODE)); + new ValidationSupportContext(myValidationSupport), + new LookupCodeRequest(BASE_LOINC_URL, VS_VERSIONED_ON_UPLOAD_FIRST_CODE)); assertNotNull(resultWithVer); String expectedWithVer = prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY); assertEquals(expectedWithVer, resultWithVer.getCodeDisplay()); @@ -278,42 +264,28 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { private void validateExpandedTermConcepts(String theCurrentVersion, Collection theAllVersions) { runInTransaction(() -> { - TermConcept termConceptNoVerCsvNoVer = (TermConcept) myEntityManager.createQuery( - "select tc from TermConcept tc join fetch tc.myCodeSystem tcsv where tc.myCode = '" + - VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId is null").getSingleResult(); - assertNotNull(termConceptNoVerCsvNoVer); - // data should have version because it was loaded with a version - assertEquals(prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptNoVerCsvNoVer.getDisplay()); - - TermConcept termConceptVerCsvNoVer = (TermConcept) myEntityManager.createQuery( - "select tc from TermConcept tc join fetch tc.myCodeSystem tcsv where tc.myCode = '" + - VS_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId is null").getSingleResult(); - assertNotNull(termConceptVerCsvNoVer); - // data should have version because it was loaded with a version - assertEquals(prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptVerCsvNoVer.getDisplay()); - - if (theCurrentVersion != null) { - TermConcept termConceptNoVerCsvVer = (TermConcept) myEntityManager.createQuery( + TermConcept termConceptNoVerCsvNoVer = (TermConcept) myEntityManager.createQuery( "select tc from TermConcept tc join fetch tc.myCodeSystem tcsv where tc.myCode = '" + - VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId = '" + theCurrentVersion + "'").getSingleResult(); - assertNotNull(termConceptNoVerCsvVer); + VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId is null").getSingleResult(); + assertNotNull(termConceptNoVerCsvNoVer); // data should have version because it was loaded with a version - assertEquals(prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptNoVerCsvVer.getDisplay()); + assertEquals(prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptNoVerCsvNoVer.getDisplay()); - TermConcept termConceptVerCsvVer = (TermConcept) myEntityManager.createQuery( + TermConcept termConceptVerCsvNoVer = (TermConcept) myEntityManager.createQuery( "select tc from TermConcept tc join fetch tc.myCodeSystem tcsv where tc.myCode = '" + - VS_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId = '" + theCurrentVersion + "'").getSingleResult(); - assertNotNull(termConceptVerCsvVer); + VS_VERSIONED_ON_UPLOAD_FIRST_CODE + "' and tcsv.myCodeSystemVersionId is null").getSingleResult(); + assertNotNull(termConceptVerCsvNoVer); // data should have version because it was loaded with a version - assertEquals(prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptVerCsvVer.getDisplay()); - } + assertEquals(prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), termConceptVerCsvNoVer.getDisplay()); - theAllVersions.forEach(this::validateExpandedTermConceptsForVersion); + if (theCurrentVersion != null) { + validateExpandedTermConceptsForVersion(theCurrentVersion); + } + theAllVersions.forEach(this::validateExpandedTermConceptsForVersion); }); } - private void validateExpandedTermConceptsForVersion(String theVersion) { TermConcept termConceptNoVer = (TermConcept) myEntityManager.createQuery( "select tc from TermConcept tc join fetch tc.myCodeSystem tcsv where tc.myCode = '" + @@ -384,7 +356,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { * no the CodeSystem version. */ private void validateValueSetSearchForVersion(String theVersion) { - // for no versioned VS (VS version, different than CS version) + // for no versioned VS (VS version, different from CS version) SearchParameterMap paramsUploadNoVer = new SearchParameterMap("url", new UriParam(VS_NO_VERSIONED_ON_UPLOAD)); paramsUploadNoVer.add("version", new TokenParam(theVersion)); @@ -398,7 +370,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { assertEquals(expectedLoadNoVersionUnqualifiedId, loadNoVersionValueSet.getIdElement().getIdPart()); - // versioned VS (VS version, different than CS version) + // versioned VS (VS version, different from CS version) SearchParameterMap paramsUploadVer = new SearchParameterMap("url", new UriParam(VS_VERSIONED_ON_UPLOAD)); paramsUploadVer.add("version", new TokenParam(VS_ANSWER_LIST_VERSION + "-" + theVersion)); @@ -437,8 +409,8 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { Set theExpectedIdVersionsPlusNull = Sets.newHashSet(theExpectedIdVersions); theExpectedIdVersionsPlusNull.add(null); - assertThat(theExpectedIdVersionsPlusNull).containsExactlyInAnyOrderElementsOf(theValueSets.stream().map(r -> ((ValueSet) r).getVersion()).toList()); - + List valueSetVersions = theValueSets.stream().map(r -> ((ValueSet) r).getVersion()).toList(); + assertThat(valueSetVersions).containsExactlyInAnyOrderElementsOf(theExpectedIdVersionsPlusNull); } @@ -455,14 +427,13 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { // for CodeSystem: // _ current CS is present and has no version - CodeSystem codeSystem = myCodeSystemDao.read(new IdType(LOINC_LOW)); + CodeSystem codeSystem = myCodeSystemDao.read(new IdType(LOINC_LOW), myRequestDetails); String csString = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(codeSystem); - ourLog.info("CodeSystem:\n" + csString); + ourLog.info("CodeSystem:\n {}", csString); HashSet shouldNotBePresentVersions = new HashSet<>(possibleVersions); theAllVersions.forEach(shouldNotBePresentVersions::remove); - shouldNotBePresentVersions.forEach(vv -> assertFalse(csString.contains(vv), - "Found version string: '" + vv + "' in CodeSystem: " + csString)); + assertThat(shouldNotBePresentVersions).noneSatisfy(vv -> assertThat(vv).isEqualTo(codeSystem.getVersion())); // same reading it from term service CodeSystem cs = myITermReadSvc.fetchCanonicalCodeSystemFromCompleteContext(BASE_LOINC_URL); @@ -501,7 +472,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { @Test() public void uploadCurrentNoVersion() throws Exception { - IIdType csId = uploadLoincCodeSystem(null, true); + uploadLoincCodeSystem(null, true); runCommonValidations(Collections.emptyList()); @@ -516,7 +487,7 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { @Test() public void uploadWithVersion() throws Exception { String ver = "2.67"; - IIdType csId = uploadLoincCodeSystem(ver, true); + uploadLoincCodeSystem(ver, true); runCommonValidations(Collections.singletonList(ver)); @@ -637,25 +608,6 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { assertThat(vsContainsDisplay).contains(expectedDisplay); } - - private void validateValidateCodeLoincAllVS(String theCurrentVersion, Collection allVersions) { - IValidationSupport.CodeValidationResult resultNoVersioned = myCodeSystemDao.validateCode(null, - new UriType(BASE_LOINC_URL), null, new CodeType(VS_NO_VERSIONED_ON_UPLOAD_FIRST_CODE), - null, null, null, null); - assertNotNull(resultNoVersioned); - assertEquals(prefixWithVersion(theCurrentVersion, VS_NO_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), resultNoVersioned.getDisplay()); - - IValidationSupport.CodeValidationResult resultVersioned = myCodeSystemDao.validateCode(null, - new UriType(BASE_LOINC_URL), null, new CodeType(VS_VERSIONED_ON_UPLOAD_FIRST_CODE), - null, null, null, null); - assertNotNull(resultVersioned); - assertEquals(prefixWithVersion(theCurrentVersion, VS_VERSIONED_ON_UPLOAD_FIRST_DISPLAY), resultVersioned.getDisplay()); - - allVersions.forEach(this::validateValidateCodeForVersion); - } - - - private void validateValueExpandLoincAllVsForVersion(String theVersion) { ValueSet vs = myValueSetDao.expandByIdentifier(LOINC_ALL_VS_URL + "|" + theVersion, null); assertThat(vs.getExpansion().getContains()).hasSize(ALL_VS_QTY); @@ -664,7 +616,6 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { checkContainsElementVersion(vs, theVersion); } - /** * Validates TermConcepts were created in the sequence indicated by the parameters * and their displays match the expected versions @@ -735,8 +686,8 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { } - private IIdType uploadLoincCodeSystem(String theVersion, boolean theMakeItCurrent) throws Exception { - myFiles = new ZipCollectionBuilder(); + private void uploadLoincCodeSystem(String theVersion, boolean theMakeItCurrent) throws Exception { + ZipCollectionBuilder files = new ZipCollectionBuilder(); myRequestDetails.getUserData().put(LOINC_CODESYSTEM_MAKE_CURRENT, theMakeItCurrent); uploadProperties.put(LOINC_CODESYSTEM_MAKE_CURRENT.getCode(), Boolean.toString(theMakeItCurrent)); @@ -749,12 +700,10 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { uploadProperties.put(LOINC_CODESYSTEM_VERSION.getCode(), theVersion); } - addLoincMandatoryFilesToZip(myFiles, theVersion); + addLoincMandatoryFilesToZip(files, theVersion); - UploadStatistics stats = myTermLoaderSvc.loadLoinc(myFiles.getFiles(), mySrd); + myTermLoaderSvc.loadLoinc(files.getFiles(), mySrd); myTerminologyDeferredStorageSvc.saveAllDeferred(); - - return stats.getTarget(); } @@ -787,10 +736,12 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { private TermCodeSystemVersion fetchCurrentCodeSystemVersion() { runInTransaction(() -> { + @SuppressWarnings("unchecked") List tcsList = myEntityManager.createQuery("from TermCodeSystem").getResultList(); + @SuppressWarnings("unchecked") List tcsvList = myEntityManager.createQuery("from TermCodeSystemVersion").getResultList(); - ourLog.error("tcslist: {}", tcsList.stream().map(tcs -> tcs.toString()).collect(joining("\n", "\n", ""))); - ourLog.error("tcsvlist: {}", tcsvList.stream().map(v -> v.toString()).collect(joining("\n", "\n", ""))); + ourLog.error("tcslist: {}", tcsList.stream().map(TermCodeSystem::toString).collect(joining("\n", "\n", ""))); + ourLog.error("tcsvlist: {}", tcsvList.stream().map(TermCodeSystemVersion::toString).collect(joining("\n", "\n", ""))); if (tcsList.size() != 1) { throw new IllegalStateException("More than one TCS: " + @@ -807,8 +758,9 @@ public class TerminologySvcImplCurrentVersionR4Test extends BaseJpaR4Test { } - private static void addBaseLoincMandatoryFilesToZip( - ZipCollectionBuilder theFiles, Boolean theIncludeTop2000, String theClassPathPrefix) throws IOException { + private static void addBaseLoincMandatoryFilesToZip(ZipCollectionBuilder theFiles, + @SuppressWarnings("SameParameterValue") Boolean theIncludeTop2000, + String theClassPathPrefix) throws IOException { theFiles.addFileZip(theClassPathPrefix, LOINC_XML_FILE.getCode()); theFiles.addFileZip(theClassPathPrefix, LOINC_GROUP_FILE_DEFAULT.getCode()); theFiles.addFileZip(theClassPathPrefix, LOINC_GROUP_TERMS_FILE_DEFAULT.getCode()); diff --git a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/common/RepositoryFactoryForRepositoryInterface.java b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/common/RepositoryFactoryForRepositoryInterface.java index 64fdc0016b2..a01f5736000 100644 --- a/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/common/RepositoryFactoryForRepositoryInterface.java +++ b/hapi-fhir-storage-cr/src/main/java/ca/uhn/fhir/cr/common/RepositoryFactoryForRepositoryInterface.java @@ -25,6 +25,7 @@ import org.opencds.cqf.fhir.api.Repository; /** * Factory interface to return a {@link Repository} from a {@link RequestDetails} */ +@FunctionalInterface public interface RepositoryFactoryForRepositoryInterface { Repository create(RequestDetails theRequestDetails); } diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/RestServerR4Helper.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/RestServerR4Helper.java index 5ac8aa67343..435d000939c 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/RestServerR4Helper.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/RestServerR4Helper.java @@ -221,6 +221,28 @@ public class RestServerR4Helper extends BaseRestServerHelper implements BeforeEa myRestServer.setConceptMapResourceProvider(theResourceProvider); } + public HashMapResourceProvider getResourceProvider(Class theResourceType) { + @SuppressWarnings("unchecked") + HashMapResourceProvider resourceProvider = (HashMapResourceProvider) myRestServer.myResourceProvidersMap.get(theResourceType); + assert resourceProvider != null : "No resource provider defined for resource type: '" + theResourceType + "'" ; + return resourceProvider; + } + + public void setResourceProvider(HashMapResourceProvider theResourceProvider) { + assert theResourceProvider.getResourceType() != null : "resourceProvider doesn't have a resourceType"; + @SuppressWarnings("unchecked") + HashMapResourceProvider resourceProvider = (HashMapResourceProvider) myRestServer.myResourceProvidersMap.get(theResourceProvider.getResourceType()); + + if (resourceProvider != null) { + resourceProvider.getStoredResources().forEach(theResourceProvider::store); + myRestServer.unregisterProvider(resourceProvider); + } + + registerProvider(theResourceProvider); + myRestServer.myResourceProvidersMap.put(theResourceProvider.getResourceType(), theResourceProvider); + } + + public void setPagingProvider(IPagingProvider thePagingProvider) { myPagingProvider = thePagingProvider; } @@ -295,6 +317,8 @@ public class RestServerR4Helper extends BaseRestServerHelper implements BeforeEa private HashMapResourceProvider myConceptMapResourceProvider; private RestServerDstu3Helper.MyPlainProvider myPlainProvider; + private final Map, HashMapResourceProvider> myResourceProvidersMap = new HashMap<>(); + private final boolean myInitialTransactionLatchEnabled; private PagingHttpMethodEnum myPagingHttpMethod = PagingHttpMethodEnum.GET;