Compare commits

...

5 Commits

Author SHA1 Message Date
James Agnew b9ffd07499 Spotless 2024-11-08 10:42:24 -05:00
jamesagnew 6d2bc81dcf Add header 2024-11-08 10:34:45 -05:00
James Agnew b0461ac240 Test fix 2024-11-08 10:32:26 -05:00
James Agnew bf2c634afc Fix signature issue 2024-11-08 05:50:38 -05:00
James Agnew 2265c53325 Resolve compile issues 2024-11-08 05:42:55 -05:00
6 changed files with 62 additions and 27 deletions

View File

@ -19,6 +19,7 @@
*/
package ca.uhn.fhir.rest.param;
import java.util.Collections;
import java.util.Map;
public class HistorySearchDateRangeParam extends DateRangeParam {
@ -28,7 +29,7 @@ public class HistorySearchDateRangeParam extends DateRangeParam {
* @since 8.0.0
*/
public HistorySearchDateRangeParam() {
this(Map.of(), new DateRangeParam(), null);
this(Collections.emptyMap(), new DateRangeParam(), null);
}
/**

View File

@ -412,7 +412,7 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
List<JpaPid> fulltextMatchIds = null;
int resultCount = 0;
if (myParams.isLastN()) {
fulltextMatchIds = executeLastNAgainstIndex(theRequest, theMaximumResults);
fulltextMatchIds = executeLastNAgainstIndex(theMaximumResults);
resultCount = fulltextMatchIds.size();
} else if (myParams.getEverythingMode() != null) {
fulltextMatchIds = queryHibernateSearchForEverythingPids(theRequest);
@ -541,7 +541,7 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
}
}
private List<JpaPid> executeLastNAgainstIndex(RequestDetails theRequestDetails, Integer theMaximumResults) {
private List<JpaPid> executeLastNAgainstIndex(Integer theMaximumResults) {
// Can we use our hibernate search generated index on resource to support lastN?:
if (myStorageSettings.isAdvancedHSearchIndexing()) {
if (myFulltextSearchSvc == null) {
@ -594,11 +594,8 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
/**
* Combs through the params for any _id parameters and extracts the PIDs for them
*
* @param theTargetPids
*/
// FIXME: remove theRequest
private void extractTargetPidsFromIdParams(RequestDetails theRequest, Set<JpaPid> theTargetPids) {
private void extractTargetPidsFromIdParams(Set<JpaPid> theTargetPids) {
// get all the IQueryParameterType objects
// for _id -> these should all be StringParam values
HashSet<String> ids = new HashSet<>();
@ -813,7 +810,7 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
Set<JpaPid> targetPids = new HashSet<>();
if (myParams.get(IAnyResource.SP_RES_ID) != null) {
extractTargetPidsFromIdParams(theRequest, targetPids);
extractTargetPidsFromIdParams(targetPids);
// add the target pids to our executors as the first
// results iterator to go through
@ -1172,10 +1169,33 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
}
// Load the resource bodies
Collection<ResourceHistoryTable> resourceSearchViewList =
List<ResourceHistoryTable> resourceSearchViewList =
myResourceHistoryTableDao.findCurrentVersionsByResourcePidsAndFetchResourceTable(
JpaPid.toLongList(versionlessPids));
/*
* If we have specific versions to load, replace the history entries with the
* correct ones
*
* TODO: this could definitely be made more efficient, probably by not loading the wrong
* version entity first, and by batching the fetches. But this is a fairly infrequently
* used feature, and loading history entities by PK is a very efficient query so it's
* not the end of the world
*/
if (resourcePidToVersion != null) {
for (int i = 0; i < resourceSearchViewList.size(); i++) {
ResourceHistoryTable next = resourceSearchViewList.get(i);
JpaPid resourceId = next.getPersistentId();
Long version = resourcePidToVersion.get(resourceId);
resourceId.setVersion(version);
if (version != null && !version.equals(next.getVersion())) {
ResourceHistoryTable replacement =
myResourceHistoryTableDao.findForIdAndVersion(next.getResourceId(), version);
resourceSearchViewList.set(i, replacement);
}
}
}
// -- preload all tags with tag definition if any
Map<JpaPid, Collection<BaseTag>> tagMap = getResourceTagMap(resourceSearchViewList);
@ -1189,19 +1209,9 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
JpaPid resourceId = next.getPersistentId();
/*
* If a specific version is requested via an include, we'll replace the current version
* with the specific desired version. This is not the most efficient thing, given that
* we're loading the current version and then turning around and throwing it away again.
* This could be optimized and probably should be, but it's not critical given that
* this only applies to includes, which don't tend to be massive in numbers.
*/
if (resourcePidToVersion != null) {
Long version = resourcePidToVersion.get(resourceId);
resourceId.setVersion(version);
if (version != null && !version.equals(next.getVersion())) {
next = myResourceHistoryTableDao.findForIdAndVersion(next.getResourceId(), version);
}
}
IBaseResource resource = null;
@ -1912,7 +1922,6 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
EntityManager theEntityManager,
HashSet<JpaPid> thePidsToInclude,
boolean theReverse) {
// FIXME: what calls this? Need a keep test? Should include partition ID?
StringBuilder sqlBuilder;
CanonicalUrlTargets canonicalUrlTargets =
calculateIndexUriIdentityHashesForResourceTypes(theRequestDetails, null, theReverse);

View File

@ -88,7 +88,7 @@ public class ResourceHistoryProvenancePredicateBuilder extends BaseJoiningPredic
case CONTAINS:
return createPredicateSourceContains(theStorageSetting, theSourceUri);
default:
throw new InvalidRequestException(Msg.code(2418)
throw new InvalidRequestException(Msg.code(2569)
+ String.format(
"Unsupported qualifier specified, qualifier=%s",
theQueryParameter.getQueryParameterQualifier()));
@ -117,7 +117,7 @@ public class ResourceHistoryProvenancePredicateBuilder extends BaseJoiningPredic
String containsLikeExpression = createLeftAndRightMatchLikeExpression(normalizedString);
return BinaryCondition.like(upperFunction, generatePlaceholder(containsLikeExpression));
} else {
throw new MethodNotAllowedException(Msg.code(2417) + ":contains modifier is disabled on this server");
throw new MethodNotAllowedException(Msg.code(2570) + ":contains modifier is disabled on this server");
}
}

View File

@ -127,9 +127,11 @@ public class ResourceHistoryTag extends BaseTag implements Serializable {
@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
b.append("id", getId());
if (getPartitionId() != null) {
b.append("partition", getPartitionId().getPartitionId());
b.append("partId", getPartitionId().getPartitionId());
}
b.append("versionId", myResourceHistoryPid);
b.append("resId", getResourceId());
b.append("tag", getTag().getId());
return b.build();

View File

@ -756,6 +756,9 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
observation.getSubject().setReference(patientId.withVersion("1").getValue());
IIdType observationId = myObservationDao.create(observation, mySrd).getId().toUnqualified();
logAllResourceVersions();
logAllResourceHistoryTags();
// Search - Non-Synchronous for *
{
myCaptureQueriesListener.clear();
@ -765,12 +768,13 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
assertEquals(5, myCaptureQueriesListener.logSelectQueries().size());
assertThat(resources).hasSize(2);
assertEquals(observationId.getValue(), resources.get(0).getIdElement().getValue());
assertEquals(patientId.withVersion("1").getValue(), resources.get(1).getIdElement().getValue());
assertThat(getTagCodes(resources.get(1))).asList().containsExactly("1");
ourLog.info("Patient: {}", myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(resources.get(1)));
IBaseResource patient = resources.get(1);
assertEquals(patientId.withVersion("1").getValue(), patient.getIdElement().getValue());
assertThat(getTagCodes(patient)).asList().containsExactly("1");
ourLog.info("Patient: {}", myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient));
}
// Search - Non Synchronous for named include
// Search - Non-Synchronous for named include
{
IBundleProvider outcome = myObservationDao.search(SearchParameterMap.newSynchronous().addInclude(Observation.INCLUDE_PATIENT), mySrd);
assertEquals(2, outcome.sizeOrThrowNpe());

View File

@ -1,3 +1,22 @@
/*-
* #%L
* HAPI FHIR JPA Server Test Utilities
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.jpa.util;
import ca.uhn.fhir.context.FhirContext;