Properly add include resources

This commit is contained in:
James Agnew 2016-08-30 16:38:09 -04:00
parent 906bcfb803
commit 98e0753b93
10 changed files with 244 additions and 127 deletions

View File

@ -1996,7 +1996,7 @@ class ParserState<T> {
terser.visit(myInstance, new IModelVisitor() {
@Override
public void acceptElement(IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
public void acceptElement(IBaseResource theResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
if (theElement instanceof BaseResourceReferenceDt) {
BaseResourceReferenceDt nextRef = (BaseResourceReferenceDt) theElement;
String ref = nextRef.getReference().getValue();
@ -2027,11 +2027,6 @@ class ParserState<T> {
}
}
}
@Override
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt) {
acceptElement(theNextExt.getValue(), null, null, null);
}
});
}

View File

@ -21,36 +21,13 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
* limitations under the License.
* #L%
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import java.util.*;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.instance.model.api.*;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.*;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeChildChoiceDefinition;
import ca.uhn.fhir.context.RuntimeChildDirectResource;
import ca.uhn.fhir.context.RuntimeExtensionDtDefinition;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
@ -78,40 +55,6 @@ public class FhirTerser {
return newList;
}
private void addUndeclaredExtensions(IBase theElement, BaseRuntimeElementDefinition<?> theDefinition, BaseRuntimeChildDefinition theChildDefinition, IModelVisitor theCallback) {
if (theElement instanceof ISupportsUndeclaredExtensions) {
ISupportsUndeclaredExtensions containingElement = (ISupportsUndeclaredExtensions) theElement;
for (ExtensionDt nextExt : containingElement.getUndeclaredExtensions()) {
if (nextExt == null) {
continue;
}
theCallback.acceptUndeclaredExtension(containingElement, null, theChildDefinition, theDefinition, nextExt);
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
// Commented out because FhirTerserDstu3Test#testGetResourceReferenceInExtension
// if (theElement instanceof IBaseHasExtensions) {
// for (IBaseExtension<?, ?> nextExt : ((IBaseHasExtensions)theElement).getExtension()) {
// if (nextExt == null) {
// continue;
// }
// theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition);
// addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
// }
// }
if (theElement instanceof IBaseHasModifierExtensions) {
for (IBaseExtension<?, ?> nextExt : ((IBaseHasModifierExtensions)theElement).getModifierExtension()) {
if (nextExt == null) {
continue;
}
theCallback.acceptElement(nextExt.getValue(), null, theChildDefinition, theDefinition);
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
}
/**
* Clones all values from a source object into the equivalent fields in a target object
@ -185,10 +128,10 @@ public class FhirTerser {
public <T extends IBase> List<T> getAllPopulatedChildElementsOfType(IBaseResource theResource, final Class<T> theType) {
final ArrayList<T> retVal = new ArrayList<T>();
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
visit(new IdentityHashMap<Object, Object>(), theResource, null, null, def, new IModelVisitor() {
visit(new IdentityHashMap<Object, Object>(), theResource, theResource, null, null, def, new IModelVisitor() {
@SuppressWarnings("unchecked")
@Override
public void acceptElement(IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
public void acceptElement(IBaseResource theOuterResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
if (theElement == null || theElement.isEmpty()) {
return;
}
@ -197,12 +140,6 @@ public class FhirTerser {
retVal.add((T) theElement);
}
}
@Override
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition,
BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt) {
// nothing
}
});
return retVal;
}
@ -210,22 +147,16 @@ public class FhirTerser {
public List<ResourceReferenceInfo> getAllResourceReferences(final IBaseResource theResource) {
final ArrayList<ResourceReferenceInfo> retVal = new ArrayList<ResourceReferenceInfo>();
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
visit(new IdentityHashMap<Object, Object>(),theResource, null, null, def, new IModelVisitor() {
visit(new IdentityHashMap<Object, Object>(), theResource, theResource, null, null, def, new IModelVisitor() {
@Override
public void acceptElement(IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
public void acceptElement(IBaseResource theOuterResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) {
if (theElement == null || theElement.isEmpty()) {
return;
}
if (IBaseReference.class.isAssignableFrom(theElement.getClass())) {
retVal.add(new ResourceReferenceInfo(myContext, theResource, thePathToElement, (IBaseReference) theElement));
retVal.add(new ResourceReferenceInfo(myContext, theOuterResource, thePathToElement, (IBaseReference) theElement));
}
}
@Override
public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition,
BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt) {
// nothing
}
});
return retVal;
}
@ -519,7 +450,7 @@ public class FhirTerser {
*/
public void visit(IBaseResource theResource, IModelVisitor theVisitor) {
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
visit(new IdentityHashMap<Object, Object>(), theResource, null, null, def, theVisitor);
visit(new IdentityHashMap<Object, Object>(), theResource, theResource, null, null, def, theVisitor);
}
/**
@ -542,7 +473,7 @@ public class FhirTerser {
visit(theResource, null, def, theVisitor, new ArrayList<IBase>(), new ArrayList<BaseRuntimeChildDefinition>(), new ArrayList<BaseRuntimeElementDefinition<?>>());
}
private void visit(IdentityHashMap<Object, Object> theStack, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition,
private void visit(IdentityHashMap<Object, Object> theStack, IBaseResource theResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition,
BaseRuntimeElementDefinition<?> theDefinition, IModelVisitor theCallback) {
List<String> pathToElement = addNameToList(thePathToElement, theChildDefinition);
@ -550,14 +481,23 @@ public class FhirTerser {
return;
}
theCallback.acceptElement(theElement, pathToElement, theChildDefinition, theDefinition);
addUndeclaredExtensions(theElement, theDefinition, theChildDefinition, theCallback);
theCallback.acceptElement(theResource, theElement, pathToElement, theChildDefinition, theDefinition);
BaseRuntimeElementDefinition<?> def = theDefinition;
if (def.getChildType() == ChildTypeEnum.CONTAINED_RESOURCE_LIST) {
def = myContext.getElementDefinition(theElement.getClass());
}
if (theElement instanceof IBaseReference) {
IBaseResource target = ((IBaseReference)theElement).getResource();
if (target != null) {
if (target.getIdElement().hasIdPart() == false || target.getIdElement().isLocal()) {
RuntimeResourceDefinition targetDef = myContext.getResourceDefinition(target);
visit(theStack, target, target, pathToElement, null, targetDef, theCallback);
}
}
}
switch (def.getChildType()) {
case ID_DATATYPE:
case PRIMITIVE_XHTML_HL7ORG:
@ -596,9 +536,9 @@ public class FhirTerser {
if (nextChild instanceof RuntimeChildDirectResource) {
// Don't descend into embedded resources
theCallback.acceptElement(nextValue, null, nextChild, childElementDef);
theCallback.acceptElement(theResource, nextValue, null, nextChild, childElementDef);
} else {
visit(theStack, nextValue, pathToElement, nextChild, childElementDef, theCallback);
visit(theStack, theResource, nextValue, pathToElement, nextChild, childElementDef, theCallback);
}
}
}
@ -609,7 +549,7 @@ public class FhirTerser {
BaseContainedDt value = (BaseContainedDt) theElement;
for (IResource next : value.getContainedResources()) {
def = myContext.getResourceDefinition(next);
visit(theStack, next, pathToElement, null, def, theCallback);
visit(theStack, next, next, pathToElement, null, def, theCallback);
}
break;
}

View File

@ -10,7 +10,7 @@ package ca.uhn.fhir.util;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -36,20 +36,15 @@ import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
public interface IModelVisitor {
/**
*
* @param theResource
* The resource being visited (note that generally this will be the resource upon which
* visit was originally called, but in the case of descending into contained resources this will be the contained resource instead)
* @param theElement
* @param theChildDefinition May be null if this is a root element
* The element
* @param theChildDefinition
* May be null if this is a root element
* @param theDefinition
*/
void acceptElement(IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition);
/**
* @deprecated As of HAPI FHIR 1.5, this method is not recommended to be used. It will be removed from
* this interface in HAPI FHIR 2.0. Previously, undeclared extensions were handled differently but as of 1.5
* they will also be called back via {@link #acceptElement(IBase, List, BaseRuntimeChildDefinition, BaseRuntimeElementDefinition)}
* like any other child.
*/
@Deprecated
void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition, ExtensionDt theNextExt);
void acceptElement(IBaseResource theResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition);
}

View File

@ -30,6 +30,8 @@ import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.Include;
/**
@ -39,9 +41,10 @@ public class ResourceReferenceInfo {
private String myOwningResource;
private String myName;
private IBaseReference myResource;
private FhirContext myContext;
public ResourceReferenceInfo(FhirContext theContext, IBaseResource theOwningResource, List<String> thePathToElement, IBaseReference theElement) {
myContext = theContext;
myOwningResource = theContext.getResourceDefinition(theOwningResource).getName();
myResource = theElement;
@ -89,9 +92,20 @@ public class ResourceReferenceInfo {
if (theInclude.getValue().equals("*")) {
return true;
}
if (theInclude.getValue().indexOf(':') != -1) {
// DSTU2 style
return (theInclude.getValue().equals(myOwningResource + ':' + myName));
int colonIndex = theInclude.getValue().indexOf(':');
if (colonIndex != -1) {
// DSTU2+ style
String paramName = theInclude.getValue().substring(colonIndex + 1);
RuntimeResourceDefinition resourceDef = myContext.getResourceDefinition(myOwningResource);
if (resourceDef != null) {
RuntimeSearchParam searchParamDef = resourceDef.getSearchParam(paramName);
if (searchParamDef!=null) {
if (searchParamDef.getPathsSplit().contains(resourceDef.getName() + "." + myName)) {
return true;
}
}
}
return false;
} else {
// DSTU1 style
return (theInclude.getValue().equals(myOwningResource + '.' + myName));

View File

@ -35,13 +35,10 @@ import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent;
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.Bundle.SearchEntryMode;
import org.hl7.fhir.instance.model.api.*;
import org.hl7.fhir.dstu3.model.DomainResource;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Include;
@ -91,11 +88,11 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory {
}
}
List<BaseResourceReferenceDt> references = myContext.newTerser().getAllPopulatedChildElementsOfType(next, BaseResourceReferenceDt.class);
List<IBaseReference> references = myContext.newTerser().getAllPopulatedChildElementsOfType(next, IBaseReference.class);
do {
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
for (BaseResourceReferenceDt nextRef : references) {
for (IBaseReference nextRef : references) {
IAnyResource nextRes = (IAnyResource) nextRef.getResource();
if (nextRes != null) {
if (nextRes.getIdElement().hasIdPart()) {
@ -120,9 +117,9 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory {
}
// Linked resources may themselves have linked resources
references = new ArrayList<BaseResourceReferenceDt>();
references = new ArrayList<IBaseReference>();
for (IAnyResource iResource : addedResourcesThisPass) {
List<BaseResourceReferenceDt> newReferences = myContext.newTerser().getAllPopulatedChildElementsOfType(iResource, BaseResourceReferenceDt.class);
List<IBaseReference> newReferences = myContext.newTerser().getAllPopulatedChildElementsOfType(iResource, IBaseReference.class);
references.addAll(newReferences);
}
@ -185,8 +182,9 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory {
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
for (ResourceReferenceInfo nextRefInfo : references) {
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes))
continue;
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
continue;
}
IAnyResource nextRes = (IAnyResource) nextRefInfo.getResourceReference().getResource();
if (nextRes != null) {

View File

@ -76,6 +76,37 @@ public class XmlParserDstu3Test {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testEncodeChainedContainedResourcer() {
Organization gp = new Organization();
gp.setName("grandparent");
Organization parent = new Organization();
parent.setName("parent");
parent.getPartOf().setResource(gp);
Organization child = new Organization();
child.setName("child");
child.getPartOf().setResource(parent);
Patient patient = new Patient();
patient.getManagingOrganization().setResource(child);
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded);
patient = ourCtx.newXmlParser().parseResource(Patient.class, encoded);
child = (Organization) patient.getManagingOrganization().getResource();
assertEquals("child", child.getName());
parent = (Organization) child.getPartOf().getResource();
assertEquals("parent", parent.getName());
gp = (Organization)parent.getPartOf().getResource();
assertEquals("grandparent", gp.getName());
}
/**
* If a contained resource refers to a contained resource that comes after it, it should still be successfully
* woven together.
@ -646,9 +677,9 @@ public class XmlParserDstu3Test {
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
List<UriType> gotLabels = parsed.getMeta().getProfile();
assertEquals(2, gotLabels.size());
UriType label = (UriType) gotLabels.get(0);
UriType label = gotLabels.get(0);
assertEquals("http://foo/Profile1", label.getValue());
label = (UriType) gotLabels.get(1);
label = gotLabels.get(1);
assertEquals("http://foo/Profile2", label.getValue());
List<Coding> tagList = parsed.getMeta().getTag();
@ -841,13 +872,13 @@ public class XmlParserDstu3Test {
assertEquals(2, gotLabels.size());
Coding label = (Coding) gotLabels.get(0);
Coding label = gotLabels.get(0);
assertEquals("SYSTEM1", label.getSystem());
assertEquals("CODE1", label.getCode());
assertEquals("DISPLAY1", label.getDisplay());
assertEquals("VERSION1", label.getVersion());
label = (Coding) gotLabels.get(1);
label = gotLabels.get(1);
assertEquals("SYSTEM2", label.getSystem());
assertEquals("CODE2", label.getCode());
assertEquals("DISPLAY2", label.getDisplay());
@ -1953,7 +1984,7 @@ public class XmlParserDstu3Test {
@Test
@Ignore
public void testParseAndEncodeBundle() throws Exception {
String content = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle-example.xml"));
String content = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle-example.xml"), StandardCharsets.UTF_8);
Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, content);
assertEquals("Bundle/example/_history/1", parsed.getIdElement().getValue());
@ -1989,7 +2020,7 @@ public class XmlParserDstu3Test {
@Test
@Ignore
public void testParseAndEncodeBundleNewStyle() throws Exception {
String content = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle-example.xml"));
String content = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle-example.xml"), StandardCharsets.UTF_8);
IParser newXmlParser = ourCtx.newXmlParser();
Bundle parsed = newXmlParser.parseResource(Bundle.class, content);
@ -2641,7 +2672,7 @@ public class XmlParserDstu3Test {
*/
@Test
public void testParseBundleWithLinksOfUnknownRelation() throws Exception {
String input = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle_orion.xml"));
String input = IOUtils.toString(XmlParserDstu3Test.class.getResourceAsStream("/bundle_orion.xml"), StandardCharsets.UTF_8);
Bundle parsed = ourCtx.newXmlParser().parseResource(Bundle.class, input);
BundleLinkComponent link = parsed.getLink().get(0);

View File

@ -0,0 +1,138 @@
package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.HumanName;
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.annotation.IncludeParam;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
public class SearchWithIncludesDstu3Test {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu3();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchWithIncludesDstu3Test.class);
private static int ourPort;
private static Server ourServer;
@Test
public void testSearchIncludesReferences() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_pretty=true&_include=Patient:organization&_include=Organization:" + Organization.SP_PARTOF);
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
// Response should include both the patient, and the organization that was referred to
// by a linked resource
assertThat(responseContent, containsString("<name value=\"child\"/>"));
assertThat(responseContent, containsString("<name value=\"parent\"/>"));
assertThat(responseContent, containsString("<name value=\"grandparent\"/>"));
assertThat(responseContent, containsString("<mode value=\"include\"/>"));
}
@AfterClass
public static void afterClassClearContext() throws Exception {
ourServer.stop();
TestUtil.clearAllStaticFieldsForUnitTest();
}
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setPagingProvider(new FifoMemoryPagingProvider(10));
servlet.setResourceProviders(patientProvider);
ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler);
ourServer.start();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
ourClient = builder.build();
}
public static class DummyPatientResourceProvider implements IResourceProvider {
@Override
public Class<? extends IBaseResource> getResourceType() {
return Patient.class;
}
//@formatter:off
@Search()
public List<Patient> search(@IncludeParam() Set<Include> theIncludes) {
ourLog.info("Includes: {}", theIncludes);
// Grandparent has ID, other orgs don't
Organization gp = new Organization();
gp.setId("Organization/GP");
gp.setName("grandparent");
Organization parent = new Organization();
parent.setName("parent");
parent.getPartOf().setResource(gp);
Organization child = new Organization();
child.setName("child");
child.getPartOf().setResource(parent);
Patient patient = new Patient();
patient.setId("Patient/FOO");
patient.getManagingOrganization().setResource(child);
ArrayList<Patient> retVal = new ArrayList<Patient>();
retVal.add(patient);
return retVal;
}
//@formatter:on
}
}

View File

@ -6,6 +6,13 @@
<title>HAPI FHIR Changelog</title>
</properties>
<body>
<release version="2.1" date="TBD">
<action type="fix">
In server, when returning a list of resources, the server sometimes failed to add
<![CDATA[<code>_include</code>]]> resources to the response bundle if they were
referred to by a contained reosurce. Thanks to Neal Acharya for reporting!
</action>
</release>
<release version="2.0" date="2016-08-30">
<action type="fix">
JSON parsing in HAPI FHIR has been switched from using JSR353 (javax.json) to

View File

@ -242,7 +242,7 @@ public DaoConfig daoConfig() {
<!--
alter table hfj_res_link ALTER COLUMN "TARGET_RESOURCE_ID" NULL;
--select sp_index_status, count(*) from hfj_resource group by sp_index_status
select sp_index_status, count(*) from hfj_resource group by sp_index_status
delete from hfj_history_tag where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_res_tag where res_id in (select res_id from hfj_resource where sp_index_status = 2);
delete from hfj_spidx_coords where res_id in (select res_id from hfj_resource where sp_index_status = 2);

View File

@ -580,8 +580,7 @@ patient.setGender(AdministrativeGenderEnum.MALE);]]></source>
Both XML and JSON encoding are suported natively using a simple API
to pick between them. XML support is built on top of the lightning-fast
<a href="http://docs.oracle.com/javase/tutorial/jaxp/stax/why.html">STaX/JSR 173</a>
API, and JSON support is provided using the new
<a href="https://jcp.org/en/jsr/detail?id=353">javax.json/JSR-353</a> API.
API, and JSON support is provided using <a href="https://github.com/google/gson">Google Gson</a>.
</p>
<source><![CDATA[FhirContext ctx = FhirContext.forDstu2();