review feedback: javadoc
This commit is contained in:
parent
5b5ef08500
commit
705735b9c0
|
@ -40,7 +40,7 @@ import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage;
|
|||
import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
||||
import ca.uhn.fhir.jpa.searchparam.util.DistanceHelper;
|
||||
import ca.uhn.fhir.jpa.searchparam.util.Dstu3DistanceHelper;
|
||||
import ca.uhn.fhir.jpa.util.*;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -163,7 +163,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
|
||||
// For DSTU3, pull out near-distance first so when it comes time to evaluate near, we already know the distance
|
||||
if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
||||
DistanceHelper.setNearDistance(myResourceType, theParams);
|
||||
Dstu3DistanceHelper.setNearDistance(myResourceType, theParams);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -5,7 +5,7 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
|||
import ca.uhn.fhir.jpa.config.TestDstu3Config;
|
||||
import ca.uhn.fhir.jpa.dao.BaseJpaTest;
|
||||
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
||||
import ca.uhn.fhir.jpa.searchparam.util.DistanceHelper;
|
||||
import ca.uhn.fhir.jpa.searchparam.util.Dstu3DistanceHelper;
|
||||
import ca.uhn.fhir.rest.param.QuantityParam;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
@ -59,7 +59,7 @@ public class MatchUrlServiceTest extends BaseJpaTest {
|
|||
Location.SP_NEAR + "=1000.0:2000.0" +
|
||||
"&" +
|
||||
Location.SP_NEAR_DISTANCE + "=" + kmDistance + "|http://unitsofmeasure.org|km", ourCtx.getResourceDefinition("Location"));
|
||||
DistanceHelper.setNearDistance(Location.class, map);
|
||||
Dstu3DistanceHelper.setNearDistance(Location.class, map);
|
||||
|
||||
QuantityParam nearDistanceParam = map.getNearDistanceParam();
|
||||
assertEquals(1, map.size());
|
||||
|
@ -76,7 +76,7 @@ public class MatchUrlServiceTest extends BaseJpaTest {
|
|||
"&" +
|
||||
Location.SP_NEAR_DISTANCE + "=2|http://unitsofmeasure.org|km",
|
||||
ourCtx.getResourceDefinition("Location"));
|
||||
DistanceHelper.setNearDistance(Location.class, map);
|
||||
Dstu3DistanceHelper.setNearDistance(Location.class, map);
|
||||
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -93,7 +93,7 @@ public class MatchUrlServiceTest extends BaseJpaTest {
|
|||
"," +
|
||||
"2|http://unitsofmeasure.org|km",
|
||||
ourCtx.getResourceDefinition("Location"));
|
||||
DistanceHelper.setNearDistance(Location.class, map);
|
||||
Dstu3DistanceHelper.setNearDistance(Location.class, map);
|
||||
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -9,7 +9,15 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class DistanceHelper {
|
||||
|
||||
/**
|
||||
* In DSTU3, the near-distance search parameter is separate from near. In this utility method,
|
||||
* we search for near-distance search parameters and if we find any, remove them from the list
|
||||
* of search parameters and store it in a dedicated field in {@link SearchParameterMap}. This is so that
|
||||
* when the "near" search parameter is processed, we have access to this near-distance value.
|
||||
* This requires at most one near-distance parameter. If more are found, we throw an {@link IllegalArgumentException}.
|
||||
*/
|
||||
public class Dstu3DistanceHelper {
|
||||
public static void setNearDistance(Class<? extends IBaseResource> theResourceType, SearchParameterMap theParams) {
|
||||
if (theResourceType == Location.class && theParams.containsKey(Location.SP_NEAR_DISTANCE)) {
|
||||
List<List<IQueryParameterType>> paramAndList = theParams.get(Location.SP_NEAR_DISTANCE);
|
||||
|
@ -38,7 +46,7 @@ public class DistanceHelper {
|
|||
ReferenceParam referenceParam = (ReferenceParam) param;
|
||||
if (Location.SP_NEAR_DISTANCE.equals(referenceParam.getChain())) {
|
||||
if (retval != null) {
|
||||
throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
} else {
|
||||
retval = referenceParam;
|
||||
orParamToRemove = param;
|
||||
|
@ -64,14 +72,14 @@ public class DistanceHelper {
|
|||
return null;
|
||||
}
|
||||
if (theParamAndList.size() > 1) {
|
||||
throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
}
|
||||
List<IQueryParameterType> paramOrList = theParamAndList.get(0);
|
||||
if (paramOrList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (paramOrList.size() > 1) {
|
||||
throw new IllegalArgumentException("Only one " + ca.uhn.fhir.model.dstu2.resource.Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
throw new IllegalArgumentException("Only one " + Location.SP_NEAR_DISTANCE + " parameter may be present");
|
||||
}
|
||||
return (QuantityParam) paramOrList.get(0);
|
||||
}
|
Loading…
Reference in New Issue