Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James Agnew 2019-05-22 17:23:27 -04:00
commit 90da9dc013
4 changed files with 56 additions and 4 deletions

View File

@ -47,6 +47,8 @@ public abstract class BaseParser implements IParser {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseParser.class);
private static final Set<String> notEncodeForContainedResource = new HashSet<>(Arrays.asList("security", "versionId", "lastUpdated"));
private ContainedResources myContainedResources;
private boolean myEncodeElementsAppliesToChildResourcesOnly;
private FhirContext myContext;
@ -161,7 +163,7 @@ public abstract class BaseParser implements IParser {
*/
if (myNext.getDef().getElementName().equals("id")) {
myNext = null;
} else if (!myNext.shouldBeEncoded()) {
} else if (!myNext.shouldBeEncoded(theContainedResource)) {
myNext = null;
} else if (isSummaryMode() && !myNext.getDef().isSummary()) {
myNext = null;
@ -176,7 +178,6 @@ public abstract class BaseParser implements IParser {
myNext = null;
}
}
} while (myNext == null);
myHasNext = true;
@ -1157,7 +1158,7 @@ public abstract class BaseParser implements IParser {
return myParent;
}
public boolean shouldBeEncoded() {
public boolean shouldBeEncoded(boolean theContainedResource) {
boolean retVal = true;
if (myEncodeElements != null) {
retVal = checkIfParentShouldBeEncodedAndBuildPath();
@ -1165,6 +1166,9 @@ public abstract class BaseParser implements IParser {
if (retVal && myDontEncodeElements != null) {
retVal = !checkIfParentShouldNotBeEncodedAndBuildPath();
}
if (theContainedResource) {
retVal = !notEncodeForContainedResource.contains(myDef.getElementName());
}
return retVal;
}

View File

@ -24,8 +24,8 @@ import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.CapabilityStatement.UnknownContentCode;
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu3.model.Enumeration;
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
@ -48,6 +48,7 @@ import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.nullable;
import static org.mockito.Mockito.*;
public class JsonParserDstu3Test {
@ -2384,6 +2385,45 @@ public class JsonParserDstu3Test {
assertTrue(result.isSuccessful());
}
@Test
public void encodeResourceToString_withEXCLUDE_ELEMENTS_IN_ENCODED_metaKeptInContainedResource() {
// Arrange
Organization containedOrganization = new Organization();
containedOrganization.getMeta().addProfile(UUID.randomUUID().toString());
containedOrganization.getMeta().setLastUpdated(new Date());
containedOrganization.getMeta().setVersionId(UUID.randomUUID().toString());
containedOrganization.getMeta().setSecurity(Arrays.asList(new Coding(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString())));
containedOrganization.getMeta().setTag(Arrays.asList(new Coding(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString())));
Patient patient = new Patient();
patient.setId(UUID.randomUUID().toString());
patient.getMeta().addProfile(UUID.randomUUID().toString());
patient.setGeneralPractitioner(Arrays.asList(new Reference(containedOrganization)));
HashSet<String> excludeElementsInEncoded = new HashSet<>(); // ResourceMetaParams.EXCLUDE_ELEMENTS_IN_ENCODED
excludeElementsInEncoded.add("id");
excludeElementsInEncoded.add("*.meta");
IParser parser = ourCtx.newJsonParser();
parser.setDontEncodeElements(excludeElementsInEncoded);
// Act
String encodedPatient = parser.encodeResourceToString(patient);
// Assert
Patient parsedPatient = (Patient) parser.parseResource(encodedPatient);
assertNull(parsedPatient.getId());
assertTrue(parsedPatient.getMeta().isEmpty());
Resource containedResource = parsedPatient.getContained().get(0);
assertNotNull(containedResource.getMeta());
assertNull(containedResource.getMeta().getVersionId());
assertNull(containedResource.getMeta().getLastUpdated());
assertTrue(containedResource.getMeta().getSecurity().isEmpty());
assertEquals(1, containedResource.getMeta().getProfile().size());
assertEquals(1, containedResource.getMeta().getTag().size());
}
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();

View File

@ -506,6 +506,10 @@
<developer>
<id>zilin375</id>
</developer>
<developer>
<id>basecade</id>
<name>Anders Havn</name>
</developer>
</developers>
<licenses>

View File

@ -217,6 +217,10 @@
The HAPI FHIR CLI was unable to start a server in R4 mode in HAPI FHIR 3.7.0.
This has been corrected.
</action>
<action type="fix" issue="1311">
When encoding resources, profile declarations on contained resources will now be
preserved. Thanks to Anders Havn for the pull request!
</action>
</release>
<release version="3.7.0" date="2019-02-06" description="Gale">
<action type="add">