ensure to use resourceType properly when it is explicitly provided in a
chained reference parameter
This commit is contained in:
parent
6da0809284
commit
b277693106
|
@ -104,12 +104,16 @@ public class ReferenceParam extends BaseParam /*implements IQueryParameterType*/
|
|||
void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
|
||||
String q = theQualifier;
|
||||
String resourceType = null;
|
||||
boolean skipSetValue = false;
|
||||
if (isNotBlank(q)) {
|
||||
if (q.startsWith(":")) {
|
||||
int nextIdx = q.indexOf('.');
|
||||
if (nextIdx != -1) {
|
||||
resourceType = q.substring(1, nextIdx);
|
||||
myChain = q.substring(nextIdx + 1);
|
||||
// type is explicitly defined so use it
|
||||
myId.setParts(null, resourceType, theValue, null);
|
||||
skipSetValue = true;
|
||||
} else {
|
||||
resourceType = q.substring(1);
|
||||
}
|
||||
|
@ -118,10 +122,12 @@ public class ReferenceParam extends BaseParam /*implements IQueryParameterType*/
|
|||
}
|
||||
}
|
||||
|
||||
setValue(theValue);
|
||||
if (!skipSetValue) {
|
||||
setValue(theValue);
|
||||
|
||||
if (isNotBlank(resourceType) && isBlank(getResourceType())) {
|
||||
setValue(resourceType + '/' + theValue);
|
||||
if (isNotBlank(resourceType) && isBlank(getResourceType())) {
|
||||
setValue(resourceType + '/' + theValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public class ReferenceParamTest {
|
|||
rp.setValueAsQueryToken(ourCtx, null, null, "Location/123");
|
||||
assertEquals("Location", rp.getResourceType());
|
||||
assertEquals("123", rp.getIdPart());
|
||||
assertEquals("Location/123", rp.getValue());
|
||||
assertEquals(null, rp.getQueryParameterQualifier());
|
||||
|
||||
}
|
||||
|
@ -30,6 +31,7 @@ public class ReferenceParamTest {
|
|||
rp.setValueAsQueryToken(ourCtx, null, ":Location", "123");
|
||||
assertEquals("Location", rp.getResourceType());
|
||||
assertEquals("123", rp.getIdPart());
|
||||
assertEquals("Location/123", rp.getValue());
|
||||
assertEquals(null, rp.getQueryParameterQualifier());
|
||||
|
||||
}
|
||||
|
@ -42,11 +44,51 @@ public class ReferenceParamTest {
|
|||
rp.setValueAsQueryToken(ourCtx, null, ":Location.name", "FOO");
|
||||
assertEquals("Location", rp.getResourceType());
|
||||
assertEquals("FOO", rp.getIdPart());
|
||||
assertEquals("Location/FOO", rp.getValue());
|
||||
assertEquals(":Location.name", rp.getQueryParameterQualifier());
|
||||
assertEquals("name", rp.getChain());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceTypeAsQualifierAndChain_IdentifierUrlAndValue() {
|
||||
|
||||
ReferenceParam rp = new ReferenceParam();
|
||||
rp.setValueAsQueryToken(ourCtx, null, ":Patient.identifier", "http://hey.there/a/b|123");
|
||||
assertEquals("Patient", rp.getResourceType());
|
||||
assertEquals("http://hey.there/a/b|123", rp.getIdPart());
|
||||
assertEquals("Patient/http://hey.there/a/b|123", rp.getValue());
|
||||
assertEquals(":Patient.identifier", rp.getQueryParameterQualifier());
|
||||
assertEquals("identifier", rp.getChain());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceTypeAsQualifierAndChain_IdentifierUrlOnly() {
|
||||
|
||||
ReferenceParam rp = new ReferenceParam();
|
||||
rp.setValueAsQueryToken(ourCtx, null, ":Patient.identifier", "http://hey.there/a/b|");
|
||||
assertEquals("Patient", rp.getResourceType());
|
||||
assertEquals("http://hey.there/a/b|", rp.getIdPart());
|
||||
assertEquals("Patient/http://hey.there/a/b|", rp.getValue());
|
||||
assertEquals(":Patient.identifier", rp.getQueryParameterQualifier());
|
||||
assertEquals("identifier", rp.getChain());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceTypeAsQualifierAndChain_ValueOnlyNoUrl() {
|
||||
|
||||
ReferenceParam rp = new ReferenceParam();
|
||||
rp.setValueAsQueryToken(ourCtx, null, ":Patient.identifier", "|abc");
|
||||
assertEquals("Patient", rp.getResourceType());
|
||||
assertEquals("|abc", rp.getIdPart());
|
||||
assertEquals("Patient/|abc", rp.getValue());
|
||||
assertEquals(":Patient.identifier", rp.getQueryParameterQualifier());
|
||||
assertEquals("identifier", rp.getChain());
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
Loading…
Reference in New Issue