-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2366) * Issue #1329 - validate conditional references in ValidationSupport Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - update copyright header Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - conditional reference support for transaction bundles Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - updated getConditionalReferences Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - update server integration test Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - updated server integration test and test data Signed-off-by: John T.E. Timm <johntimm@us.ibm.com> * Issue #1329 - updated error messages per PR feedback Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>
- Loading branch information
Showing
5 changed files
with
310 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
fhir-server-test/src/test/java/com/ibm/fhir/server/test/ConditionalReferenceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.server.test; | ||
|
||
import static com.ibm.fhir.model.type.String.string; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.util.Collections; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.core.FHIRMediaType; | ||
import com.ibm.fhir.model.resource.Bundle; | ||
import com.ibm.fhir.model.resource.Bundle.Entry; | ||
import com.ibm.fhir.model.resource.Observation; | ||
import com.ibm.fhir.model.resource.OperationOutcome; | ||
import com.ibm.fhir.model.resource.Patient; | ||
import com.ibm.fhir.model.test.TestUtil; | ||
import com.ibm.fhir.model.type.HumanName; | ||
import com.ibm.fhir.model.type.Identifier; | ||
import com.ibm.fhir.model.type.Reference; | ||
import com.ibm.fhir.model.type.Uri; | ||
import com.ibm.fhir.model.type.code.IssueType; | ||
|
||
public class ConditionalReferenceTest extends FHIRServerTestBase { | ||
@Test | ||
public void testCreatePatients() { | ||
Patient patient = buildPatient(); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.path("Patient").path("12345") | ||
.request() | ||
.put(Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
int status = response.getStatus(); | ||
assertTrue(status == Response.Status.CREATED.getStatusCode() || status == Response.Status.OK.getStatusCode()); | ||
|
||
patient = patient.toBuilder() | ||
.id("54321") | ||
.identifier(Collections.singletonList(Identifier.builder() | ||
.system(Uri.of("http://ibm.com/fhir/patient-id")) | ||
.value(string("54321")) | ||
.build())) | ||
.build(); | ||
|
||
response = target.path("Patient").path("54321") | ||
.request() | ||
.put(Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
status = response.getStatus(); | ||
assertTrue(status == Response.Status.CREATED.getStatusCode() || status == Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
@Test(dependsOnMethods = { "testCreatePatients" }) | ||
public void testBundleTransactionConditionalReference() throws Exception { | ||
Bundle bundle = TestUtil.readLocalResource("testdata/conditional-reference-bundle.json"); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.request() | ||
.post(Entity.entity(bundle, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
assertResponse(response, Response.Status.OK.getStatusCode()); | ||
|
||
response = target.path("Observation/67890").request(FHIRMediaType.APPLICATION_FHIR_JSON).get(); | ||
assertResponse(response, Response.Status.OK.getStatusCode()); | ||
|
||
Observation observation = response.readEntity(Observation.class); | ||
assertEquals(observation.getSubject().getReference().getValue(), "Patient/12345"); | ||
} | ||
|
||
@Test(dependsOnMethods = { "testCreatePatients" }) | ||
public void testBundleTransactionInvalidConditionalReferenceNoQueryParameters() throws Exception { | ||
Bundle bundle = TestUtil.readLocalResource("testdata/conditional-reference-bundle.json"); | ||
|
||
Entry entry = bundle.getEntry().get(0); | ||
entry = entry.toBuilder() | ||
.resource(entry.getResource().as(Observation.class).toBuilder() | ||
.subject(Reference.builder() | ||
.reference(string("Patient?")) | ||
.build()) | ||
.build()) | ||
.build(); | ||
|
||
bundle = bundle.toBuilder() | ||
.entry(Collections.singletonList(entry)) | ||
.build(); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.request() | ||
.post(Entity.entity(bundle, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
assertResponse(response, Response.Status.BAD_REQUEST.getStatusCode()); | ||
|
||
OperationOutcome outcome = response.readEntity(OperationOutcome.class); | ||
assertEquals(outcome.getIssue().get(0).getCode(), IssueType.INVALID); | ||
assertEquals(outcome.getIssue().get(0).getDetails().getText().getValue(), "Invalid conditional reference: no query parameters found"); | ||
} | ||
|
||
@Test(dependsOnMethods = { "testCreatePatients" }) | ||
public void testBundleTransactionInvalidConditionalReferenceResultParameter() throws Exception { | ||
Bundle bundle = TestUtil.readLocalResource("testdata/conditional-reference-bundle.json"); | ||
|
||
Entry entry = bundle.getEntry().get(0); | ||
entry = entry.toBuilder() | ||
.resource(entry.getResource().as(Observation.class).toBuilder() | ||
.subject(Reference.builder() | ||
.reference(string("Patient?_count=1")) | ||
.build()) | ||
.build()) | ||
.build(); | ||
|
||
bundle = bundle.toBuilder() | ||
.entry(Collections.singletonList(entry)) | ||
.build(); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.request() | ||
.post(Entity.entity(bundle, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
assertResponse(response, Response.Status.BAD_REQUEST.getStatusCode()); | ||
|
||
OperationOutcome outcome = response.readEntity(OperationOutcome.class); | ||
assertEquals(outcome.getIssue().get(0).getCode(), IssueType.INVALID); | ||
assertEquals(outcome.getIssue().get(0).getDetails().getText().getValue(), "Invalid conditional reference: only filtering parameters are allowed"); | ||
} | ||
|
||
@Test(dependsOnMethods = { "testCreatePatients" }) | ||
public void testBundleTransactionConditionalReferenceNoResult() throws Exception { | ||
Bundle bundle = TestUtil.readLocalResource("testdata/conditional-reference-bundle.json"); | ||
|
||
Entry entry = bundle.getEntry().get(0); | ||
entry = entry.toBuilder() | ||
.resource(entry.getResource().as(Observation.class).toBuilder() | ||
.subject(Reference.builder() | ||
.reference(string("Patient?identifier=___invalid___")) | ||
.build()) | ||
.build()) | ||
.build(); | ||
|
||
bundle = bundle.toBuilder() | ||
.entry(Collections.singletonList(entry)) | ||
.build(); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.request() | ||
.post(Entity.entity(bundle, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
assertResponse(response, Response.Status.BAD_REQUEST.getStatusCode()); | ||
|
||
OperationOutcome outcome = response.readEntity(OperationOutcome.class); | ||
assertEquals(outcome.getIssue().get(0).getCode(), IssueType.NOT_FOUND); | ||
assertEquals(outcome.getIssue().get(0).getDetails().getText().getValue(), "Error resolving conditional reference: search returned no results"); | ||
} | ||
|
||
@Test(dependsOnMethods = { "testCreatePatients" }) | ||
public void testBundleTransactionConditionalReferenceMultipleMatches() throws Exception { | ||
Bundle bundle = TestUtil.readLocalResource("testdata/conditional-reference-bundle.json"); | ||
|
||
Entry entry = bundle.getEntry().get(0); | ||
entry = entry.toBuilder() | ||
.resource(entry.getResource().as(Observation.class).toBuilder() | ||
.subject(Reference.builder() | ||
.reference(string("Patient?family=Doe&given=John")) | ||
.build()) | ||
.build()) | ||
.build(); | ||
|
||
bundle = bundle.toBuilder() | ||
.entry(Collections.singletonList(entry)) | ||
.build(); | ||
|
||
WebTarget target = getWebTarget(); | ||
|
||
Response response = target.request() | ||
.post(Entity.entity(bundle, FHIRMediaType.APPLICATION_FHIR_JSON)); | ||
assertResponse(response, Response.Status.BAD_REQUEST.getStatusCode()); | ||
|
||
OperationOutcome outcome = response.readEntity(OperationOutcome.class); | ||
assertEquals(outcome.getIssue().get(0).getCode(), IssueType.MULTIPLE_MATCHES); | ||
assertEquals(outcome.getIssue().get(0).getDetails().getText().getValue(), "Error resolving conditional reference: search returned multiple results"); | ||
} | ||
|
||
private Patient buildPatient() { | ||
return Patient.builder() | ||
.id("12345") | ||
.identifier(Identifier.builder() | ||
.system(Uri.of("http://ibm.com/fhir/patient-id")) | ||
.value(string("12345")) | ||
.build()) | ||
.name(HumanName.builder() | ||
.family(string("Doe")) | ||
.given(string("John")) | ||
.build()) | ||
.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
fhir-server-test/src/test/java/com/ibm/fhir/server/test/RemoteTermServiceProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
fhir-server-test/src/test/resources/testdata/conditional-reference-bundle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"resourceType": "Bundle", | ||
"id": "20160113160203", | ||
"type": "transaction", | ||
"entry": [ | ||
{ | ||
"fullUrl": "urn:uuid:c72aa430-2ddc-456e-7a09-dea8264671d8", | ||
"resource": { | ||
"resourceType": "Observation", | ||
"id": "67890", | ||
"status": "final", | ||
"code": { | ||
"text": "test" | ||
}, | ||
"subject": { | ||
"reference": "Patient?identifier=http://ibm.com/fhir/patient-id|12345" | ||
} | ||
}, | ||
"request": { | ||
"method": "PUT", | ||
"url": "Observation/67890" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters