Add test, add changelog, fix bug (#3494)

* Add test, add changelog, fix bug

* Test fix

* Fix some more test artifacts
This commit is contained in:
Tadgh 2022-03-26 20:34:43 -04:00 committed by GitHub
parent 5b413a9135
commit b1e2d7c104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 5 deletions

View File

@ -1249,8 +1249,8 @@ class ParserState<T> {
public void wereBack() {
super.wereBack();
if (getCurrentElement() instanceof IDomainResource) {
IDomainResource elem = (IDomainResource) getCurrentElement();
if (getCurrentElement() instanceof IBaseResource) {
IBaseResource elem = (IBaseResource) getCurrentElement();
String resourceName = myContext.getResourceType(elem);
String versionId = elem.getMeta().getVersionId();
if (StringUtils.isBlank(elem.getIdElement().getIdPart())) {

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 3493
title: "Previously the Fhir parser would only set the resource type on the resource ID for resources which implemented `IDomainResource`. This caused a few resource types
to be missed. This has been corrected, and resource type is now set on the id element for all `IBaseResource` instances instead."

View File

@ -791,7 +791,7 @@ public class GenericJaxRsClientDstu3Test {
org.hl7.fhir.dstu3.model.Bundle responseBundle = (org.hl7.fhir.dstu3.model.Bundle) outParams.getParameter().get(0).getResource();
// Print the response bundle
assertEquals("8cef5f2a-0ba9-43a5-be26-c8dde9ff0e19", responseBundle.getId());
assertEquals("Bundle/8cef5f2a-0ba9-43a5-be26-c8dde9ff0e19", responseBundle.getId());
}
@Test

View File

@ -561,7 +561,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid
});
Bundle response = myClient.search().forResource(Patient.class).count(1).returnBundle(Bundle.class).execute();
String searchId = response.getId();
String searchId = response.getIdElement().getIdPart();
// 2 results returned, but no total since it's stripped
assertEquals(1, response.getEntry().size());
@ -616,7 +616,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid
myClient.create().resource(new Patient().setGender(Enumerations.AdministrativeGender.FEMALE).addName(new HumanName().setFamily("3"))).execute();
Bundle response = myClient.search().forResource(Patient.class).count(1).returnBundle(Bundle.class).execute();
String searchId = response.getId();
String searchId = response.getIdElement().getIdPart();
assertEquals(1, response.getEntry().size());
assertNull(response.getTotalElement().getValue());

View File

@ -13,6 +13,7 @@ import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullWriter;
import org.apache.commons.lang.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.AuditEvent;
import org.hl7.fhir.r4.model.Basic;
import org.hl7.fhir.r4.model.Binary;
@ -59,6 +60,9 @@ import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -87,6 +91,27 @@ public class JsonParserR4Test extends BaseTest {
ourCtx.getParserOptions().setAutoContainReferenceTargetsWithNoId(true);
}
@Test
public void testNonDomainResourcesHaveIdResourceTypeParsed() {
//Test a non-domain resource
String binaryPayload = "{\n" +
" \"resourceType\": \"Binary\",\n" +
" \"id\": \"b123\"\n" +
"}\n";
IBaseResource iBaseResource = ourCtx.newJsonParser().parseResource(binaryPayload);
String resourceType = iBaseResource.getIdElement().getResourceType();
assertThat(resourceType, is(equalTo("Binary")));
//Test a domain resource.
String observationPayload = "{\n" +
" \"resourceType\": \"Observation\",\n" +
" \"id\": \"o123\"\n" +
"}\n";
IBaseResource obs = ourCtx.newJsonParser().parseResource(observationPayload);
resourceType = obs.getIdElement().getResourceType();
assertThat(resourceType, is(equalTo("Observation")));
}
@Test
public void testEntitiesNotConverted() throws IOException {
Device input = loadResource(ourCtx, Device.class, "/entities-from-cerner.json");