Merge branch 'master' of github.com:jamesagnew/hapi-fhir
This commit is contained in:
commit
90da9dc013
|
@ -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 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 ContainedResources myContainedResources;
|
||||||
private boolean myEncodeElementsAppliesToChildResourcesOnly;
|
private boolean myEncodeElementsAppliesToChildResourcesOnly;
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
@ -161,7 +163,7 @@ public abstract class BaseParser implements IParser {
|
||||||
*/
|
*/
|
||||||
if (myNext.getDef().getElementName().equals("id")) {
|
if (myNext.getDef().getElementName().equals("id")) {
|
||||||
myNext = null;
|
myNext = null;
|
||||||
} else if (!myNext.shouldBeEncoded()) {
|
} else if (!myNext.shouldBeEncoded(theContainedResource)) {
|
||||||
myNext = null;
|
myNext = null;
|
||||||
} else if (isSummaryMode() && !myNext.getDef().isSummary()) {
|
} else if (isSummaryMode() && !myNext.getDef().isSummary()) {
|
||||||
myNext = null;
|
myNext = null;
|
||||||
|
@ -176,7 +178,6 @@ public abstract class BaseParser implements IParser {
|
||||||
myNext = null;
|
myNext = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (myNext == null);
|
} while (myNext == null);
|
||||||
|
|
||||||
myHasNext = true;
|
myHasNext = true;
|
||||||
|
@ -1157,7 +1158,7 @@ public abstract class BaseParser implements IParser {
|
||||||
return myParent;
|
return myParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldBeEncoded() {
|
public boolean shouldBeEncoded(boolean theContainedResource) {
|
||||||
boolean retVal = true;
|
boolean retVal = true;
|
||||||
if (myEncodeElements != null) {
|
if (myEncodeElements != null) {
|
||||||
retVal = checkIfParentShouldBeEncodedAndBuildPath();
|
retVal = checkIfParentShouldBeEncodedAndBuildPath();
|
||||||
|
@ -1165,6 +1166,9 @@ public abstract class BaseParser implements IParser {
|
||||||
if (retVal && myDontEncodeElements != null) {
|
if (retVal && myDontEncodeElements != null) {
|
||||||
retVal = !checkIfParentShouldNotBeEncodedAndBuildPath();
|
retVal = !checkIfParentShouldNotBeEncodedAndBuildPath();
|
||||||
}
|
}
|
||||||
|
if (theContainedResource) {
|
||||||
|
retVal = !notEncodeForContainedResource.contains(myDef.getElementName());
|
||||||
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.BundleEntryComponent;
|
||||||
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
||||||
import org.hl7.fhir.dstu3.model.CapabilityStatement.UnknownContentCode;
|
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.Enumeration;
|
||||||
|
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
|
||||||
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
|
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
|
||||||
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
|
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
|
||||||
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
|
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.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isNull;
|
import static org.mockito.Matchers.isNull;
|
||||||
|
import static org.mockito.Mockito.nullable;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class JsonParserDstu3Test {
|
public class JsonParserDstu3Test {
|
||||||
|
@ -2384,6 +2385,45 @@ public class JsonParserDstu3Test {
|
||||||
assertTrue(result.isSuccessful());
|
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
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -506,6 +506,10 @@
|
||||||
<developer>
|
<developer>
|
||||||
<id>zilin375</id>
|
<id>zilin375</id>
|
||||||
</developer>
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>basecade</id>
|
||||||
|
<name>Anders Havn</name>
|
||||||
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
|
|
|
@ -217,6 +217,10 @@
|
||||||
The HAPI FHIR CLI was unable to start a server in R4 mode in HAPI FHIR 3.7.0.
|
The HAPI FHIR CLI was unable to start a server in R4 mode in HAPI FHIR 3.7.0.
|
||||||
This has been corrected.
|
This has been corrected.
|
||||||
</action>
|
</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>
|
||||||
<release version="3.7.0" date="2019-02-06" description="Gale">
|
<release version="3.7.0" date="2019-02-06" description="Gale">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
|
Loading…
Reference in New Issue