MDM expansion doesn't work when using the :mdm qualifier in query string (#5803)

* wip

* cleaning up test

* adding changelog and passing spotless.

---------

Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
Etienne Poirier 2024-03-27 10:12:50 -04:00 committed by GitHub
parent 4d4d8b25d4
commit 2f9693a1e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 17 deletions

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.api.Constants;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@ -147,18 +148,22 @@ public class TokenParam extends BaseParam /*implements IQueryParameterType*/ {
@Override
void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theParameter) {
setModifier(null);
setSystem(null);
if (theQualifier != null) {
if (Constants.PARAMQUALIFIER_MDM.equals(theQualifier)) {
setMdmExpand(true);
}
TokenParamModifier modifier = TokenParamModifier.forValue(theQualifier);
setModifier(modifier);
if (modifier == TokenParamModifier.TEXT) {
setSystem(null);
setValue(ParameterUtil.unescape(theParameter));
return;
}
}
setSystem(null);
if (theParameter == null) {
setValue(null);
} else {

View File

@ -2,6 +2,7 @@ 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 ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
@ -132,6 +133,23 @@ public class StringParamTest {
assertNicknameWarningLogged(false);
}
@Test
public void testNameNickname() {
StringParam param = new StringParam();
assertFalse(param.isNicknameExpand());
param.setValueAsQueryToken(myContext, "name", Constants.PARAMQUALIFIER_NICKNAME, "kenny");
assertTrue(param.isNicknameExpand());
}
@Test
public void testGivenNickname() {
StringParam param = new StringParam();
assertFalse(param.isNicknameExpand());
param.setValueAsQueryToken(myContext, "given", Constants.PARAMQUALIFIER_NICKNAME, "kenny");
assertTrue(param.isNicknameExpand());
}
private void assertNicknameQualifierSearchParameterIsValid(StringParam theStringParam, String theExpectedValue){
assertTrue(theStringParam.isNicknameExpand());
assertFalse(theStringParam.isExact());
@ -164,5 +182,5 @@ public class StringParamTest {
assertTrue(warningLogs.isEmpty());
}
}
}

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5802
title: "Previously, using the ':mdm' qualifier with the '_id' search parameter would not included expanded resources in
search result. This issue has been fixed."

View File

@ -2,14 +2,13 @@ package ca.uhn.fhir.rest.param;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class TokenParamTest {
private static final FhirContext ourCtx = FhirContext.forR4Cached();
@ -51,19 +50,16 @@ public class TokenParamTest {
}
@Test
public void testNameNickname() {
StringParam param = new StringParam();
assertFalse(param.isNicknameExpand());
param.setValueAsQueryToken(ourCtx, "name", Constants.PARAMQUALIFIER_NICKNAME, "kenny");
assertTrue(param.isNicknameExpand());
public void testMdmQualifier() {
final String value = "Patient/PJANE1";
TokenParam param = new TokenParam();
param.setValueAsQueryToken(ourCtx, "_id", Constants.PARAMQUALIFIER_MDM, value);
assertNull(param.getModifier());
assertNull(param.getSystem());
assertTrue(param.isMdmExpand());
assertEquals(value, param.getValue());
}
@Test
public void testGivenNickname() {
StringParam param = new StringParam();
assertFalse(param.isNicknameExpand());
param.setValueAsQueryToken(ourCtx, "given", Constants.PARAMQUALIFIER_NICKNAME, "kenny");
assertTrue(param.isNicknameExpand());
}
}