diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java index 98e2d8ccb51..b566562558b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java @@ -87,18 +87,19 @@ public class ElementsParameter implements IParameter { if (theExclude) { paramName = Constants.PARAM_ELEMENTS + Constants.PARAM_ELEMENTS_EXCLUDE_MODIFIER; } - String[] summary = theRequest.getParameters().get(paramName); + String[] elementsValues = theRequest.getParameters().get(paramName); - if (summary != null && summary.length > 0) { - Set retVal = new HashSet(); - for (String next : summary) { + if (elementsValues != null && elementsValues.length > 0) { + Set retVal = new HashSet<>(); + for (String next : elementsValues) { StringTokenizer tok = new StringTokenizer(next, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (isNotBlank(token)) { - if (token.contains(".") && standardMode) { - continue; - } + if (token.contains(".")) + if (standardMode) { + continue; + } retVal.add(token); } } @@ -107,11 +108,6 @@ public class ElementsParameter implements IParameter { return null; } - // Always include the meta element even for subsetted values - if (!theExclude) { - retVal.add("meta"); - } - return retVal; } return null; diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ElementsParamR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ElementsParamR4Test.java index 3bb22be9843..38104c562eb 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ElementsParamR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/ElementsParamR4Test.java @@ -62,7 +62,7 @@ public class ElementsParamR4Test { assertThat(responseContent, not(containsString("
THE DIV
"))); assertThat(responseContent, (containsString("family"))); assertThat(responseContent, (containsString("maritalStatus"))); - assertThat(ourLastElements, containsInAnyOrder("meta", "name", "maritalStatus")); + assertThat(ourLastElements, containsInAnyOrder("name", "maritalStatus")); } ); } @@ -77,7 +77,7 @@ public class ElementsParamR4Test { assertThat(responseContent, not(containsString("
THE DIV
"))); assertThat(responseContent, (containsString("family"))); assertThat(responseContent, not(containsString("maritalStatus"))); - assertThat(ourLastElements, containsInAnyOrder("meta", "name")); + assertThat(ourLastElements, containsInAnyOrder("name")); } ); } @@ -93,7 +93,7 @@ public class ElementsParamR4Test { assertThat(responseContent, not(containsString("THE DIV"))); assertThat(responseContent, containsString("family")); assertThat(responseContent, containsString("maritalStatus")); - assertThat(ourLastElements, containsInAnyOrder("meta", "name", "maritalStatus")); + assertThat(ourLastElements, containsInAnyOrder("name", "maritalStatus")); } ); } @@ -108,7 +108,7 @@ public class ElementsParamR4Test { assertThat(responseContent, containsString("THE DIV")); assertThat(responseContent, not(containsString("family"))); assertThat(responseContent, not(containsString("maritalStatus"))); - assertThat(ourLastElements, containsInAnyOrder("meta", "text")); + assertThat(ourLastElements, containsInAnyOrder( "text")); } ); } @@ -184,6 +184,34 @@ public class ElementsParamR4Test { }); } + /** + * A search on procedure, with only resource specific elements filters that are specifically + * on other resources but Procedure, should not affect the output of the procedure resource. + */ + @Test + public void testMultiResourceElementsFilterDoesntAffectFocalResource() throws IOException { + createProcedureWithLongChain(); + verifyXmlAndJson( + "http://localhost:" + ourPort + "/Procedure?_include=*&_elements=Observation.subject", + bundle -> { + Procedure procedure = (Procedure) bundle.getEntry().get(0).getResource(); + assertEquals(true, procedure.getMeta().isEmpty()); + assertEquals("REASON_CODE", procedure.getReasonCode().get(0).getCoding().get(0).getCode()); + assertEquals("USED_CODE", procedure.getUsedCode().get(0).getCoding().get(0).getCode()); + + DiagnosticReport dr = (DiagnosticReport) bundle.getEntry().get(1).getResource(); + assertEquals(true, dr.getMeta().isEmpty()); + assertEquals(1, dr.getResult().size()); + + Observation obs = (Observation ) bundle.getEntry().get(2).getResource(); + assertEquals("SUBSETTED", obs.getMeta().getTag().get(0).getCode()); + assertEquals(null, obs.getStatus()); + assertEquals(0, obs.getCode().getCoding().size()); + assertEquals(false, obs.hasValue()); + assertEquals("Patient/123", obs.getSubject().getReference()); + }); + } + @Test public void testMultiResourceElementsFilterWithMetadataExcludedStandardMode() throws IOException { ourServlet.setElementsSupport(ElementsSupportEnum.STANDARD);