Skip to content

Commit

Permalink
Issue #1734 - match only on system+code
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schroeder <mschroed@us.ibm.com>
  • Loading branch information
michaelwschroeder committed Mar 30, 2021
1 parent cdbcf58 commit 9adbff4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import com.ibm.fhir.model.util.ModelSupport;
import com.ibm.fhir.persistence.exception.FHIRPersistenceException;
import com.ibm.fhir.persistence.exception.FHIRPersistenceNotSupportedException;
import com.ibm.fhir.persistence.jdbc.JDBCConstants;
import com.ibm.fhir.persistence.jdbc.connection.QueryHints;
import com.ibm.fhir.persistence.jdbc.dao.api.JDBCIdentityCache;
import com.ibm.fhir.persistence.jdbc.dao.api.ParameterDAO;
Expand Down Expand Up @@ -1962,8 +1961,7 @@ private void populateValueSetCodesSubSegment(StringBuilder whereClauseSegment, S
log.entering(CLASSNAME, METHODNAME, parameterValue);

String tokenValuePredicateString = parameterTableAlias + DOT + TOKEN_VALUE + IN + LEFT_PAREN;
String codeSystemIdPredicateString = parameterTableAlias + DOT + CODE_SYSTEM_ID + IN + LEFT_PAREN;
String defaultCodeSystemId = nullCheck(identityCache.getCodeSystemId(JDBCConstants.DEFAULT_TOKEN_SYSTEM));
String codeSystemIdPredicateString = parameterTableAlias + DOT + CODE_SYSTEM_ID + EQ;
boolean codeSystemProcessed = false;

// Note: validation that the value set exists and is expandable was done when the
Expand All @@ -1983,16 +1981,16 @@ private void populateValueSetCodesSubSegment(StringBuilder whereClauseSegment, S
whereClauseSegment.append(OR);
}

// TODO: investigate if we can use COMMON_TOKEN_VALUES support

// <parameterTableAlias>.TOKEN_VALUE IN (...)
whereClauseSegment.append(tokenValuePredicateString)
.append("'").append(String.join("','", codes)).append("'")
.append(RIGHT_PAREN);

// AND <parameterTableAlias>.CODE_SYSTEM_ID IN ({n}, {default-code-system-id})
// AND <parameterTableAlias>.CODE_SYSTEM_ID = {n}
whereClauseSegment.append(AND).append(codeSystemIdPredicateString)
.append(nullCheck(identityCache.getCodeSystemId(codeSetUrl)))
.append(COMMA).append(defaultCodeSystemId)
.append(RIGHT_PAREN);
.append(nullCheck(identityCache.getCodeSystemId(codeSetUrl)));

codeSystemProcessed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ public void testSearchToken_code_chained_missing() throws Exception {

@Test
public void testSearchToken_code_in() throws Exception {
assertSearchReturnsSavedResource("code:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("code:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("missing-code:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("code:in", "http://hl7.org/fhir/ValueSet/observation-category");
}

@Test
public void testSearchToken_code_not_in() throws Exception {
assertSearchDoesntReturnSavedResource("code:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("code:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("missing-code:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("code:not-in", "http://hl7.org/fhir/ValueSet/observation-category");
}
Expand Down Expand Up @@ -382,13 +382,13 @@ public void testSearchToken_Coding_not_in() throws Exception {

@Test
public void testSearchToken_Coding_NoSystem_in() throws Exception {
assertSearchReturnsSavedResource("Coding-noSystem:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("Coding-noSystem:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("Coding-noSystem:in", "http://hl7.org/fhir/ValueSet/observation-category");
}

@Test
public void testSearchToken_Coding_NoSystem_not_in() throws Exception {
assertSearchDoesntReturnSavedResource("Coding-noSystem:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("Coding-noSystem:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("Coding-noSystem:not-in", "http://hl7.org/fhir/ValueSet/observation-category");
}

Expand Down Expand Up @@ -478,13 +478,13 @@ public void testSearchToken_Identifier_not_in() throws Exception {

@Test
public void testSearchToken_Identifier_NoSystem_in() throws Exception {
assertSearchReturnsSavedResource("Identifier-noSystem:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("Identifier-noSystem:in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchDoesntReturnSavedResource("Identifier-noSystem:in", "http://hl7.org/fhir/ValueSet/observation-category");
}

@Test
public void testSearchToken_Identifier_NoSystem_not_in() throws Exception {
assertSearchDoesntReturnSavedResource("Identifier-noSystem:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("Identifier-noSystem:not-in", "http://hl7.org/fhir/ValueSet/concept-property-type");
assertSearchReturnsSavedResource("Identifier-noSystem:not-in", "http://hl7.org/fhir/ValueSet/observation-category");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public void testCreateOrganization() throws Exception {
// Build a new Organization and then call the 'create' API.
Organization organization = TestUtil.getMinimalResource(ResourceType.ORGANIZATION, Format.JSON);

organization = organization.toBuilder().name(com.ibm.fhir.model.type.String.of("test")).build();
organization = organization.toBuilder()
.name(com.ibm.fhir.model.type.String.of("test"))
.type(CodeableConcept.builder().coding(Coding.builder().code(Code.of("dept")).build()).build())
.build();
Entity<Organization> entity =
Entity.entity(organization, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response =
Expand Down Expand Up @@ -1955,4 +1958,37 @@ public void testSearchAllergyIntoleranceWithClinicalStatusNotInNotFound() {
assertTrue(bundle.getEntry().isEmpty());
}

@Test(groups = { "server-search" }, dependsOnMethods = { "testCreateAllergyIntolerance" })
public void testSearchAllergyIntoleranceWithImplicitCodeSystemIn() {
WebTarget target = getWebTarget();
Response response = target.path("AllergyIntolerance")
.queryParam("_id", allergyIntoleranceId)
.queryParam("category:in", "http://hl7.org/fhir/ValueSet/allergy-intolerance-category")
.request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", tenantName)
.header("X-FHIR-DSID", dataStoreId)
.get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
assertTrue(bundle.getEntry().size() == 1);
assertEquals(allergyIntoleranceId, bundle.getEntry().get(0).getResource().getId());
}

@Test(groups = { "server-search" }, dependsOnMethods = { "testCreateOrganization" })
public void testSearchOrganizationWithNoCodeSystemIn() {
WebTarget target = getWebTarget();
Response response = target.path("Organization")
.queryParam("_id", organizationId)
.queryParam("type:in", "http://hl7.org/fhir/ValueSet/organization-type")
.request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", tenantName)
.header("X-FHIR-DSID", dataStoreId)
.get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
assertTrue(bundle.getEntry().isEmpty());
}

}

0 comments on commit 9adbff4

Please sign in to comment.