diff --git a/fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/JDBCParameterBuildingVisitor.java b/fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/JDBCParameterBuildingVisitor.java index a593d1edfba..7846623c64a 100644 --- a/fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/JDBCParameterBuildingVisitor.java +++ b/fhir-persistence-jdbc/src/main/java/com/ibm/fhir/persistence/jdbc/util/JDBCParameterBuildingVisitor.java @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corp. 2017,2020 + * (C) Copyright IBM Corp. 2017, 2021 * * SPDX-License-Identifier: Apache-2.0 */ @@ -56,6 +56,7 @@ import com.ibm.fhir.persistence.jdbc.dto.StringParmVal; import com.ibm.fhir.persistence.jdbc.dto.TokenParmVal; import com.ibm.fhir.persistence.jdbc.util.type.NumberParmBehaviorUtil; +import com.ibm.fhir.search.SearchConstants; import com.ibm.fhir.search.date.DateTimeHandler; import com.ibm.fhir.search.exception.FHIRSearchException; import com.ibm.fhir.search.util.ReferenceUtil; @@ -608,12 +609,22 @@ public boolean visit(java.lang.String elementName, int elementIndex, Reference r try { final String baseUrl = ReferenceUtil.getBaseUrl(null); ReferenceValue refValue = ReferenceUtil.createReferenceValueFrom(reference, baseUrl); - if (refValue.getType() != ReferenceType.INVALID && refValue.getType() != ReferenceType.DISPLAY_ONLY) { + if (refValue.getType() != ReferenceType.LOGICAL && refValue.getType() != ReferenceType.INVALID && refValue.getType() != ReferenceType.DISPLAY_ONLY) { ReferenceParmVal p = new ReferenceParmVal(); p.setRefValue(refValue); p.setName(searchParamCode); result.add(p); } + Identifier identifier = reference.getIdentifier(); + if (identifier != null && identifier.getValue() != null) { + TokenParmVal p = new TokenParmVal(); + p.setName(searchParamCode + SearchConstants.IDENTIFIER_MODIFIER_SUFFIX); + if (identifier.getSystem() != null) { + p.setValueSystem(identifier.getSystem().getValue()); + } + p.setValueCode(identifier.getValue().getValue()); + result.add(p); + } } catch (FHIRSearchException x) { // Log the error, but skip it because we're not supposed to throw exceptions here log.log(Level.WARNING, "Error processing reference", x); diff --git a/fhir-persistence-jdbc/src/test/java/com/ibm/fhir/persistence/jdbc/test/util/ParameterExtractionTest.java b/fhir-persistence-jdbc/src/test/java/com/ibm/fhir/persistence/jdbc/test/util/ParameterExtractionTest.java index b218837aab1..0c24951802e 100644 --- a/fhir-persistence-jdbc/src/test/java/com/ibm/fhir/persistence/jdbc/test/util/ParameterExtractionTest.java +++ b/fhir-persistence-jdbc/src/test/java/com/ibm/fhir/persistence/jdbc/test/util/ParameterExtractionTest.java @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corp. 2019, 2020 + * (C) Copyright IBM Corp. 2019, 2021 * * SPDX-License-Identifier: Apache-2.0 */ @@ -64,6 +64,7 @@ import com.ibm.fhir.persistence.jdbc.dto.StringParmVal; import com.ibm.fhir.persistence.jdbc.dto.TokenParmVal; import com.ibm.fhir.persistence.jdbc.util.JDBCParameterBuildingVisitor; +import com.ibm.fhir.search.SearchConstants; /** * Tests all valid combinations of search paramter types and data types @@ -79,6 +80,7 @@ public class ParameterExtractionTest { private static final String SAMPLE_DATE_START = "2016-01-01T00:00:00.000000Z"; private static final String SAMPLE_DATE_END = "2016-01-02T00:00:00.000000Z"; private static final String UNITSOFMEASURE = "http://unitsofmeasure.org"; + private static final String SEARCH_PARAM_CODE_VALUE = "value"; private static final Extension SAMPLE_EXTENSION = Extension.builder().url(SAMPLE_URI).build(); @@ -94,7 +96,7 @@ public class ParameterExtractionTest { .name(string("test-param")) .status(PublicationStatus.DRAFT) .description(Markdown.of("#Test Parameter")) - .code(Code.of("value")) + .code(Code.of(SEARCH_PARAM_CODE_VALUE)) .base(ResourceType.BASIC); private static final SearchParameter numberSearchParam = searchParamBuilder.type(SearchParamType.NUMBER).build(); private static final SearchParameter dateSearchParam = searchParamBuilder.type(SearchParamType.DATE).build(); @@ -649,12 +651,20 @@ public void testReference() throws FHIRPersistenceProcessorException { JDBCParameterBuildingVisitor parameterBuilder = new JDBCParameterBuildingVisitor(referenceSearchParam); Reference.builder() .reference(string(SAMPLE_REF)) + .identifier(Identifier.builder() + .system(Uri.of(SAMPLE_URI)) + .value(string(SAMPLE_STRING)) + .build()) .build() .accept(parameterBuilder); List params = parameterBuilder.getResult(); - assertEquals(params.size(), 1, "Number of extracted parameters"); + assertEquals(params.size(), 2, "Number of extracted parameters"); + assertEquals(((ReferenceParmVal) params.get(0)).getName(), SEARCH_PARAM_CODE_VALUE); assertEquals(((ReferenceParmVal) params.get(0)).getRefValue().getValue(), SAMPLE_REF_ID); assertEquals(((ReferenceParmVal) params.get(0)).getRefValue().getTargetResourceType(), SAMPLE_REF_RESOURCE_TYPE); + assertEquals(((TokenParmVal) params.get(1)).getName(), SEARCH_PARAM_CODE_VALUE + SearchConstants.IDENTIFIER_MODIFIER_SUFFIX); + assertEquals(((TokenParmVal) params.get(1)).getValueSystem(), SAMPLE_URI); + assertEquals(((TokenParmVal) params.get(1)).getValueCode(), SAMPLE_STRING); } @Test diff --git a/fhir-search/src/main/java/com/ibm/fhir/search/SearchConstants.java b/fhir-search/src/main/java/com/ibm/fhir/search/SearchConstants.java index 69de6b654bf..debbd1698e4 100644 --- a/fhir-search/src/main/java/com/ibm/fhir/search/SearchConstants.java +++ b/fhir-search/src/main/java/com/ibm/fhir/search/SearchConstants.java @@ -97,6 +97,9 @@ private SearchConstants() { public static final String BASE_SYSTEM_EXT_URL = "http://ibm.com/fhir/extension/"; public static final String IMPLICIT_SYSTEM_EXT_URL = BASE_SYSTEM_EXT_URL + "implicit-system"; + // Extracted search parameter suffix for :identifier modifier + public static final String IDENTIFIER_MODIFIER_SUFFIX = ":identifier"; + // set as unmodifiable public static final Set SEARCH_RESULT_PARAMETER_NAMES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(SORT, COUNT, PAGE, INCLUDE, REVINCLUDE, ELEMENTS, SUMMARY, TOTAL)));