Fix HasParam#doGetQueryParameterQualifier() (#2460)

* Fix HasParam#doGetQueryParameterQualifier(); add changelog entry

* Fix bad test in SearchParameterMapTest
This commit is contained in:
Diederik Muylwyk 2021-03-09 06:28:40 -05:00 committed by GitHub
parent 62df320ceb
commit 6cc8a5ce4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View File

@ -1,5 +1,10 @@
package ca.uhn.fhir.rest.param;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import static org.apache.commons.lang3.StringUtils.defaultString;
/*
@ -22,11 +27,6 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
/**
* Implementation of the _has method parameter
*/
@ -55,7 +55,7 @@ public class HasParam extends BaseParam implements IQueryParameterType {
@Override
String doGetQueryParameterQualifier() {
return myTargetResourceType + ':' + myParameterName + ':' + myParameterValue;
return ':' + myTargetResourceType + ':' + myReferenceFieldName + ':' + myParameterName;
}
@Override

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 2458
title: "`HasParam#doGetQueryParameterQualifier()` returned a malformed modifier. For example, the modifier for
`_has:Observation:patient:code=123` was returned as `Observation:code:123` when it should be
`:Observation:patient:code`. This has been corrected."

View File

@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.dao.r4;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.test.BaseTest;
import org.junit.jupiter.api.Test;
@ -19,6 +18,6 @@ public class SearchParameterMapTest extends BaseTest {
SearchParameterMap params = new SearchParameterMap();
params.add("_has", new HasParam("Observation", "subject", "identifier", "urn:system|FOO"));
String criteria = params.toNormalizedQueryString(myContext);
assertEquals(criteria, "?_has:Observation:identifier:urn:system|FOO=urn%3Asystem%7CFOO");
assertEquals(criteria, "?_has:Observation:subject:identifier=urn%3Asystem%7CFOO");
}
}

View File

@ -413,10 +413,6 @@ public class SearchParameterMap implements Serializable {
IQueryParameterType firstValue = nextValuesAnd.get(0);
b.append(UrlUtil.escapeUrlParam(nextKey));
if (nextKey.equals(Constants.PARAM_HAS)) {
b.append(':');
}
if (firstValue.getMissing() != null) {
b.append(Constants.PARAMQUALIFIER_MISSING);
b.append('=');