Skip to content

Commit

Permalink
Issue #773 - Extract identifier field of reference elements
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Mar 17, 2021
1 parent 7ccfdf5 commit 227852a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2017,2020
* (C) Copyright IBM Corp. 2017, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019, 2020
* (C) Copyright IBM Corp. 2019, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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<ExtractedParameterValue> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> SEARCH_RESULT_PARAMETER_NAMES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(SORT, COUNT, PAGE, INCLUDE, REVINCLUDE, ELEMENTS, SUMMARY, TOTAL)));
Expand Down

0 comments on commit 227852a

Please sign in to comment.