Populate Bundle.entry.fullUrl
This commit is contained in:
parent
6a2045fe12
commit
ae177b52e8
|
@ -90,6 +90,7 @@ import ca.uhn.fhir.model.dstu2.valueset.AnswerFormatEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.EncounterStateEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.EncounterStateEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
||||||
|
import ca.uhn.fhir.model.dstu2.valueset.SearchEntryModeEnum;
|
||||||
import ca.uhn.fhir.model.primitive.DateDt;
|
import ca.uhn.fhir.model.primitive.DateDt;
|
||||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
|
@ -827,10 +828,21 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
p2.addName().addFamily("testSearchByIdentifierFamily01").addGiven("testSearchByIdentifierGiven02");
|
p2.addName().addFamily("testSearchByIdentifierFamily01").addGiven("testSearchByIdentifierGiven02");
|
||||||
ourClient.create().resource(p2).execute().getId();
|
ourClient.create().resource(p2).execute().getId();
|
||||||
|
|
||||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testSearchByIdentifier01")).encodedJson().prettyPrint().execute();
|
//@formatter:off
|
||||||
assertEquals(1, actual.size());
|
ca.uhn.fhir.model.dstu2.resource.Bundle actual = ourClient
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
.search()
|
||||||
assertEquals(BundleEntrySearchModeEnum.MATCH, actual.getEntries().get(0).getSearchMode().getValueAsEnum());
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testSearchByIdentifier01"))
|
||||||
|
.encodedJson()
|
||||||
|
.prettyPrint()
|
||||||
|
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
|
assertEquals(1, actual.getEntry().size());
|
||||||
|
assertEquals(ourServerBase + "/Patient/" + p1Id.getIdPart(), actual.getEntry().get(0).getFullUrl());
|
||||||
|
assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getId().getIdPart());
|
||||||
|
assertEquals(SearchEntryModeEnum.MATCH, actual.getEntry().get(0).getSearch().getModeElement().getValueAsEnum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Dstu2BundleFactory.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Dstu2BundleFactory.class);
|
||||||
private Bundle myBundle;
|
private Bundle myBundle;
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
private String myBase;
|
||||||
|
|
||||||
public Dstu2BundleFactory(FhirContext theContext) {
|
public Dstu2BundleFactory(FhirContext theContext) {
|
||||||
myContext = theContext;
|
myContext = theContext;
|
||||||
|
@ -237,9 +238,7 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
} while (references.isEmpty() == false);
|
} while (references.isEmpty() == false);
|
||||||
|
|
||||||
Entry entry = myBundle.addEntry().setResource(next);
|
Entry entry = myBundle.addEntry().setResource(next);
|
||||||
if (next.getId().hasBaseUrl()) {
|
populateBundleEntryFullUrl(next, entry);
|
||||||
entry.setFullUrl(next.getId().getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next);
|
BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next);
|
||||||
if (searchMode != null) {
|
if (searchMode != null) {
|
||||||
|
@ -253,16 +252,28 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
for (IResource next : includedResources) {
|
for (IResource next : includedResources) {
|
||||||
Entry entry = myBundle.addEntry();
|
Entry entry = myBundle.addEntry();
|
||||||
entry.setResource(next).getSearch().setMode(SearchEntryModeEnum.INCLUDE);
|
entry.setResource(next).getSearch().setMode(SearchEntryModeEnum.INCLUDE);
|
||||||
if (next.getId().hasBaseUrl()) {
|
populateBundleEntryFullUrl(next, entry);
|
||||||
entry.setFullUrl(next.getId().getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void populateBundleEntryFullUrl(IResource next, Entry entry) {
|
||||||
|
if (next.getId().hasBaseUrl()) {
|
||||||
|
entry.setFullUrl(next.getId().toVersionless().getValue());
|
||||||
|
} else {
|
||||||
|
if (isNotBlank(myBase) && next.getId().hasIdPart()) {
|
||||||
|
IdDt id = next.getId().toVersionless();
|
||||||
|
id = id.withServerBase(myBase, myContext.getResourceDefinition(next).getName());
|
||||||
|
entry.setFullUrl(id.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theCompleteUrl, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) {
|
public void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theCompleteUrl, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) {
|
||||||
|
|
||||||
|
myBase = theServerBase;
|
||||||
|
|
||||||
if (myBundle.getId().isEmpty()) {
|
if (myBundle.getId().isEmpty()) {
|
||||||
myBundle.setId(UUID.randomUUID().toString());
|
myBundle.setId(UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
@ -306,6 +317,8 @@ public class Dstu2BundleFactory implements IVersionSpecificBundleFactory {
|
||||||
@Override
|
@Override
|
||||||
public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl,
|
public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl,
|
||||||
boolean thePrettyPrint, int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType, Set<Include> theIncludes) {
|
boolean thePrettyPrint, int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType, Set<Include> theIncludes) {
|
||||||
|
myBase = theServerBase;
|
||||||
|
|
||||||
int numToReturn;
|
int numToReturn;
|
||||||
String searchId = null;
|
String searchId = null;
|
||||||
List<IBaseResource> resourceList;
|
List<IBaseResource> resourceList;
|
||||||
|
|
|
@ -19,7 +19,8 @@ package ca.uhn.fhir.rest.server.provider.dstu2hl7org;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.apache.commons.lang3.StringUtils.*;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -64,15 +65,15 @@ import ca.uhn.fhir.util.ResourceReferenceInfo;
|
||||||
|
|
||||||
public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory {
|
public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory {
|
||||||
|
|
||||||
private String myBase;
|
private String myBase;
|
||||||
private Bundle myBundle;
|
private Bundle myBundle;
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
|
||||||
public Dstu2Hl7OrgBundleFactory(FhirContext theContext) {
|
public Dstu2Hl7OrgBundleFactory(FhirContext theContext) {
|
||||||
myContext = theContext;
|
myContext = theContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addResourcesForSearch(List<? extends IBaseResource> theResult) {
|
private void addResourcesForSearch(List<? extends IBaseResource> theResult) {
|
||||||
List<IBaseResource> includedResources = new ArrayList<IBaseResource>();
|
List<IBaseResource> includedResources = new ArrayList<IBaseResource>();
|
||||||
Set<IIdType> addedResourceIds = new HashSet<IIdType>();
|
Set<IIdType> addedResourceIds = new HashSet<IIdType>();
|
||||||
|
|
||||||
|
@ -131,290 +132,310 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory {
|
||||||
} while (references.isEmpty() == false);
|
} while (references.isEmpty() == false);
|
||||||
|
|
||||||
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next);
|
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next);
|
||||||
IdType nextId = (IdType) next.getIdElement();
|
populateBundleEntryFullUrl(next, entry);
|
||||||
if (isNotBlank(myBase) && isNotBlank(nextId.getResourceType())) {
|
|
||||||
entry.setFullUrlElement(nextId.withServerBase(myBase, nextId.getResourceType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actually add the resources to the bundle
|
* Actually add the resources to the bundle
|
||||||
*/
|
*/
|
||||||
for (IBaseResource next : includedResources) {
|
for (IBaseResource next : includedResources) {
|
||||||
myBundle.addEntry().setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE);
|
BundleEntryComponent entry = myBundle.addEntry();
|
||||||
|
entry.setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE);
|
||||||
|
populateBundleEntryFullUrl(next, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void populateBundleEntryFullUrl(IBaseResource next, BundleEntryComponent entry) {
|
||||||
public void addResourcesToBundle(List<IBaseResource> theResult, BundleTypeEnum theBundleType, String theServerBase, BundleInclusionRule theBundleInclusionRule, Set<Include> theIncludes) {
|
if (next.getIdElement().hasBaseUrl()) {
|
||||||
if (myBundle == null) {
|
entry.setFullUrl(next.getIdElement().toVersionless().getValue());
|
||||||
myBundle = new Bundle();
|
} else {
|
||||||
}
|
if (isNotBlank(myBase) && next.getIdElement().hasIdPart()) {
|
||||||
|
IIdType id = next.getIdElement().toVersionless();
|
||||||
|
id = id.withServerBase(myBase, myContext.getResourceDefinition(next).getName());
|
||||||
|
entry.setFullUrl(id.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<IBaseResource> includedResources = new ArrayList<IBaseResource>();
|
@Override
|
||||||
Set<IIdType> addedResourceIds = new HashSet<IIdType>();
|
public void addResourcesToBundle(List<IBaseResource> theResult, BundleTypeEnum theBundleType, String theServerBase,
|
||||||
|
BundleInclusionRule theBundleInclusionRule, Set<Include> theIncludes) {
|
||||||
|
if (myBundle == null) {
|
||||||
|
myBundle = new Bundle();
|
||||||
|
}
|
||||||
|
|
||||||
for (IBaseResource next : theResult) {
|
List<IBaseResource> includedResources = new ArrayList<IBaseResource>();
|
||||||
if (next.getIdElement().isEmpty() == false) {
|
Set<IIdType> addedResourceIds = new HashSet<IIdType>();
|
||||||
addedResourceIds.add(next.getIdElement());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IBaseResource next : theResult) {
|
for (IBaseResource next : theResult) {
|
||||||
|
if (next.getIdElement().isEmpty() == false) {
|
||||||
|
addedResourceIds.add(next.getIdElement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<? extends IAnyResource> contained;
|
for (IBaseResource next : theResult) {
|
||||||
if (next instanceof IDomainResource) {
|
|
||||||
IDomainResource nextDomain = (IDomainResource) next;
|
|
||||||
contained = nextDomain.getContained();
|
|
||||||
} else {
|
|
||||||
contained = Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> containedIds = new HashSet<String>();
|
List<? extends IAnyResource> contained;
|
||||||
for (IAnyResource nextContained : contained) {
|
if (next instanceof IDomainResource) {
|
||||||
if (nextContained.getId().isEmpty() == false) {
|
IDomainResource nextDomain = (IDomainResource) next;
|
||||||
containedIds.add(nextContained.getIdElement().getValue());
|
contained = nextDomain.getContained();
|
||||||
}
|
} else {
|
||||||
}
|
contained = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
List<ResourceReferenceInfo> references = myContext.newTerser().getAllResourceReferences(next);
|
Set<String> containedIds = new HashSet<String>();
|
||||||
do {
|
for (IAnyResource nextContained : contained) {
|
||||||
List<IBaseResource> addedResourcesThisPass = new ArrayList<IBaseResource>();
|
if (nextContained.getId().isEmpty() == false) {
|
||||||
|
containedIds.add(nextContained.getIdElement().getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ResourceReferenceInfo nextRefInfo : references) {
|
List<ResourceReferenceInfo> references = myContext.newTerser().getAllResourceReferences(next);
|
||||||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes))
|
do {
|
||||||
continue;
|
List<IBaseResource> addedResourcesThisPass = new ArrayList<IBaseResource>();
|
||||||
|
|
||||||
IBaseResource nextRes = (IBaseResource) nextRefInfo.getResourceReference().getResource();
|
for (ResourceReferenceInfo nextRefInfo : references) {
|
||||||
if (nextRes != null) {
|
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes))
|
||||||
if (nextRes.getIdElement().hasIdPart()) {
|
continue;
|
||||||
if (containedIds.contains(nextRes.getIdElement().getValue())) {
|
|
||||||
// Don't add contained IDs as top level resources
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
IdType id = (IdType) nextRes.getIdElement();
|
IBaseResource nextRes = (IBaseResource) nextRefInfo.getResourceReference().getResource();
|
||||||
if (id.hasResourceType() == false) {
|
if (nextRes != null) {
|
||||||
String resName = myContext.getResourceDefinition(nextRes).getName();
|
if (nextRes.getIdElement().hasIdPart()) {
|
||||||
id = id.withResourceType(resName);
|
if (containedIds.contains(nextRes.getIdElement().getValue())) {
|
||||||
}
|
// Don't add contained IDs as top level resources
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!addedResourceIds.contains(id)) {
|
IdType id = (IdType) nextRes.getIdElement();
|
||||||
addedResourceIds.add(id);
|
if (id.hasResourceType() == false) {
|
||||||
addedResourcesThisPass.add(nextRes);
|
String resName = myContext.getResourceDefinition(nextRes).getName();
|
||||||
}
|
id = id.withResourceType(resName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (!addedResourceIds.contains(id)) {
|
||||||
}
|
addedResourceIds.add(id);
|
||||||
}
|
addedResourcesThisPass.add(nextRes);
|
||||||
|
}
|
||||||
|
|
||||||
includedResources.addAll(addedResourcesThisPass);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Linked resources may themselves have linked resources
|
includedResources.addAll(addedResourcesThisPass);
|
||||||
references = new ArrayList<ResourceReferenceInfo>();
|
|
||||||
for (IBaseResource iResource : addedResourcesThisPass) {
|
|
||||||
List<ResourceReferenceInfo> newReferences = myContext.newTerser().getAllResourceReferences(iResource);
|
|
||||||
references.addAll(newReferences);
|
|
||||||
}
|
|
||||||
} while (references.isEmpty() == false);
|
|
||||||
|
|
||||||
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next);
|
// Linked resources may themselves have linked resources
|
||||||
|
references = new ArrayList<ResourceReferenceInfo>();
|
||||||
|
for (IBaseResource iResource : addedResourcesThisPass) {
|
||||||
|
List<ResourceReferenceInfo> newReferences = myContext.newTerser().getAllResourceReferences(iResource);
|
||||||
|
references.addAll(newReferences);
|
||||||
|
}
|
||||||
|
} while (references.isEmpty() == false);
|
||||||
|
|
||||||
// BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next);
|
BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next);
|
||||||
// if (searchMode != null) {
|
|
||||||
// entry.getSearch().getModeElement().setValue(searchMode.getCode());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
// BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next);
|
||||||
* Actually add the resources to the bundle
|
// if (searchMode != null) {
|
||||||
*/
|
// entry.getSearch().getModeElement().setValue(searchMode.getCode());
|
||||||
for (IBaseResource next : includedResources) {
|
// }
|
||||||
myBundle.addEntry().setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
/*
|
||||||
|
* Actually add the resources to the bundle
|
||||||
|
*/
|
||||||
|
for (IBaseResource next : includedResources) {
|
||||||
|
myBundle.addEntry().setResource((Resource) next).getSearch().setMode(SearchEntryMode.INCLUDE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theCompleteUrl, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) {
|
|
||||||
|
|
||||||
if (isBlank(myBundle.getId())) {
|
@Override
|
||||||
myBundle.setId(UUID.randomUUID().toString());
|
public void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theCompleteUrl,
|
||||||
}
|
Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated) {
|
||||||
|
|
||||||
if (myBundle.getMeta().getLastUpdated() == null) {
|
if (isBlank(myBundle.getId())) {
|
||||||
InstantType instantType = new InstantType();
|
myBundle.setId(UUID.randomUUID().toString());
|
||||||
instantType.setValueAsString(theLastUpdated.getValueAsString());
|
}
|
||||||
myBundle.getMeta().setLastUpdatedElement(instantType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theCompleteUrl)) {
|
if (myBundle.getMeta().getLastUpdated() == null) {
|
||||||
myBundle.addLink().setRelation("self").setUrl(theCompleteUrl);
|
InstantType instantType = new InstantType();
|
||||||
}
|
instantType.setValueAsString(theLastUpdated.getValueAsString());
|
||||||
|
myBundle.getMeta().setLastUpdatedElement(instantType);
|
||||||
|
}
|
||||||
|
|
||||||
myBase = theServerBase;
|
if (!hasLink(Constants.LINK_SELF, myBundle) && isNotBlank(theCompleteUrl)) {
|
||||||
|
myBundle.addLink().setRelation("self").setUrl(theCompleteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (myBundle.getTypeElement().isEmpty() && theBundleType != null) {
|
myBase = theServerBase;
|
||||||
myBundle.getTypeElement().setValueAsString(theBundleType.getCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) {
|
if (myBundle.getTypeElement().isEmpty() && theBundleType != null) {
|
||||||
myBundle.getTotalElement().setValue(theTotalResults);
|
myBundle.getTypeElement().setValueAsString(theBundleType.getCode());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (myBundle.getTotalElement().isEmpty() && theTotalResults != null) {
|
||||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
myBundle.getTotalElement().setValue(theTotalResults);
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaseResource getResourceBundle() {
|
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
||||||
return myBundle;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasLink(String theLinkType, Bundle theBundle) {
|
@Override
|
||||||
for (BundleLinkComponent next : theBundle.getLink()) {
|
public IBaseResource getResourceBundle() {
|
||||||
if (theLinkType.equals(next.getRelation())) {
|
return myBundle;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private boolean hasLink(String theLinkType, Bundle theBundle) {
|
||||||
public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl, boolean thePrettyPrint, int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType,
|
for (BundleLinkComponent next : theBundle.getLink()) {
|
||||||
Set<Include> theIncludes) {
|
if (theLinkType.equals(next.getRelation())) {
|
||||||
int numToReturn;
|
return true;
|
||||||
String searchId = null;
|
}
|
||||||
List<IBaseResource> resourceList;
|
}
|
||||||
if (theServer.getPagingProvider() == null) {
|
return false;
|
||||||
numToReturn = theResult.size();
|
}
|
||||||
if (numToReturn == 0) {
|
|
||||||
resourceList = Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
resourceList = theResult.getResources(0, numToReturn);
|
|
||||||
RestfulServerUtils.validateResourceListNotNull(resourceList);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
IPagingProvider pagingProvider = theServer.getPagingProvider();
|
|
||||||
if (theLimit == null) {
|
|
||||||
numToReturn = pagingProvider.getDefaultPageSize();
|
|
||||||
} else {
|
|
||||||
numToReturn = Math.min(pagingProvider.getMaximumPageSize(), theLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
numToReturn = Math.min(numToReturn, theResult.size() - theOffset);
|
@Override
|
||||||
resourceList = theResult.getResources(theOffset, numToReturn + theOffset);
|
public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult,
|
||||||
RestfulServerUtils.validateResourceListNotNull(resourceList);
|
EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl, boolean thePrettyPrint,
|
||||||
|
int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType, Set<Include> theIncludes) {
|
||||||
|
myBase = theServerBase;
|
||||||
|
int numToReturn;
|
||||||
|
String searchId = null;
|
||||||
|
List<IBaseResource> resourceList;
|
||||||
|
if (theServer.getPagingProvider() == null) {
|
||||||
|
numToReturn = theResult.size();
|
||||||
|
if (numToReturn == 0) {
|
||||||
|
resourceList = Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
resourceList = theResult.getResources(0, numToReturn);
|
||||||
|
RestfulServerUtils.validateResourceListNotNull(resourceList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IPagingProvider pagingProvider = theServer.getPagingProvider();
|
||||||
|
if (theLimit == null) {
|
||||||
|
numToReturn = pagingProvider.getDefaultPageSize();
|
||||||
|
} else {
|
||||||
|
numToReturn = Math.min(pagingProvider.getMaximumPageSize(), theLimit);
|
||||||
|
}
|
||||||
|
|
||||||
if (theSearchId != null) {
|
numToReturn = Math.min(numToReturn, theResult.size() - theOffset);
|
||||||
searchId = theSearchId;
|
resourceList = theResult.getResources(theOffset, numToReturn + theOffset);
|
||||||
} else {
|
RestfulServerUtils.validateResourceListNotNull(resourceList);
|
||||||
if (theResult.size() > numToReturn) {
|
|
||||||
searchId = pagingProvider.storeResultList(theResult);
|
|
||||||
Validate.notNull(searchId, "Paging provider returned null searchId");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IBaseResource next : resourceList) {
|
if (theSearchId != null) {
|
||||||
if (next.getIdElement() == null || next.getIdElement().isEmpty()) {
|
searchId = theSearchId;
|
||||||
if (!(next instanceof OperationOutcome)) {
|
} else {
|
||||||
throw new InternalErrorException("Server method returned resource of type[" + next.getClass().getSimpleName() + "] with no ID specified (IBaseResource#setId(IdDt) must be called)");
|
if (theResult.size() > numToReturn) {
|
||||||
}
|
searchId = pagingProvider.storeResultList(theResult);
|
||||||
}
|
Validate.notNull(searchId, "Paging provider returned null searchId");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (theServer.getAddProfileTag() != AddProfileTagEnum.NEVER) {
|
for (IBaseResource next : resourceList) {
|
||||||
for (IBaseResource nextRes : resourceList) {
|
if (next.getIdElement() == null || next.getIdElement().isEmpty()) {
|
||||||
RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(nextRes);
|
if (!(next instanceof OperationOutcome)) {
|
||||||
if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) {
|
throw new InternalErrorException("Server method returned resource of type[" + next.getClass().getSimpleName()
|
||||||
RestfulServerUtils.addProfileToBundleEntry(theServer.getFhirContext(), nextRes, theServerBase);
|
+ "] with no ID specified (IBaseResource#setId(IdDt) must be called)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addResourcesToBundle(resourceList, theBundleType, theServerBase, theServer.getBundleInclusionRule(), theIncludes);
|
if (theServer.getAddProfileTag() != AddProfileTagEnum.NEVER) {
|
||||||
addRootPropertiesToBundle(null, theServerBase, theCompleteUrl, theResult.size(), theBundleType, theResult.getPublished());
|
for (IBaseResource nextRes : resourceList) {
|
||||||
|
RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(nextRes);
|
||||||
|
if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) {
|
||||||
|
RestfulServerUtils.addProfileToBundleEntry(theServer.getFhirContext(), nextRes, theServerBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (theServer.getPagingProvider() != null) {
|
addResourcesToBundle(resourceList, theBundleType, theServerBase, theServer.getBundleInclusionRule(), theIncludes);
|
||||||
int limit;
|
addRootPropertiesToBundle(null, theServerBase, theCompleteUrl, theResult.size(), theBundleType,
|
||||||
limit = theLimit != null ? theLimit : theServer.getPagingProvider().getDefaultPageSize();
|
theResult.getPublished());
|
||||||
limit = Math.min(limit, theServer.getPagingProvider().getMaximumPageSize());
|
|
||||||
|
|
||||||
if (searchId != null) {
|
if (theServer.getPagingProvider() != null) {
|
||||||
if (theOffset + numToReturn < theResult.size()) {
|
int limit;
|
||||||
myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint));
|
limit = theLimit != null ? theLimit : theServer.getPagingProvider().getDefaultPageSize();
|
||||||
}
|
limit = Math.min(limit, theServer.getPagingProvider().getMaximumPageSize());
|
||||||
if (theOffset > 0) {
|
|
||||||
int start = Math.max(0, theOffset - limit);
|
|
||||||
myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (searchId != null) {
|
||||||
public void initializeBundleFromResourceList(String theAuthor, List<? extends IBaseResource> theResources, String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType) {
|
if (theOffset + numToReturn < theResult.size()) {
|
||||||
myBundle = new Bundle();
|
myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(RestfulServerUtils.createPagingLink(theIncludes,
|
||||||
|
theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint));
|
||||||
|
}
|
||||||
|
if (theOffset > 0) {
|
||||||
|
int start = Math.max(0, theOffset - limit);
|
||||||
|
myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(RestfulServerUtils.createPagingLink(
|
||||||
|
theIncludes, theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
myBundle.setId(UUID.randomUUID().toString());
|
@Override
|
||||||
|
public void initializeBundleFromResourceList(String theAuthor, List<? extends IBaseResource> theResources,
|
||||||
|
String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType) {
|
||||||
|
myBundle = new Bundle();
|
||||||
|
|
||||||
myBundle.getMeta().setLastUpdatedElement(InstantType.withCurrentTime());
|
myBundle.setId(UUID.randomUUID().toString());
|
||||||
|
|
||||||
myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase);
|
myBundle.getMeta().setLastUpdatedElement(InstantType.withCurrentTime());
|
||||||
myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl);
|
|
||||||
myBundle.getTypeElement().setValueAsString(theBundleType.getCode());
|
|
||||||
|
|
||||||
if (theBundleType.equals(BundleTypeEnum.TRANSACTION)) {
|
myBundle.addLink().setRelation(Constants.LINK_FHIR_BASE).setUrl(theServerBase);
|
||||||
for (IBaseResource nextBaseRes : theResources) {
|
myBundle.addLink().setRelation(Constants.LINK_SELF).setUrl(theCompleteUrl);
|
||||||
IBaseResource next = (IBaseResource) nextBaseRes;
|
myBundle.getTypeElement().setValueAsString(theBundleType.getCode());
|
||||||
BundleEntryComponent nextEntry = myBundle.addEntry();
|
|
||||||
|
|
||||||
nextEntry.setResource((Resource) next);
|
if (theBundleType.equals(BundleTypeEnum.TRANSACTION)) {
|
||||||
if (next.getIdElement().isEmpty()) {
|
for (IBaseResource nextBaseRes : theResources) {
|
||||||
nextEntry.getRequest().setMethod(HTTPVerb.POST);
|
IBaseResource next = (IBaseResource) nextBaseRes;
|
||||||
} else {
|
BundleEntryComponent nextEntry = myBundle.addEntry();
|
||||||
nextEntry.getRequest().setMethod(HTTPVerb.PUT);
|
|
||||||
if (next.getIdElement().isAbsolute()) {
|
|
||||||
nextEntry.getRequest().setUrl(next.getIdElement().getValue());
|
|
||||||
} else {
|
|
||||||
String resourceType = myContext.getResourceDefinition(next).getName();
|
|
||||||
nextEntry.getRequest().setUrl(new IdType(theServerBase, resourceType, next.getIdElement().getIdPart(), next.getIdElement().getVersionIdPart()).getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addResourcesForSearch(theResources);
|
|
||||||
}
|
|
||||||
|
|
||||||
myBundle.getTotalElement().setValue(theTotalResults);
|
nextEntry.setResource((Resource) next);
|
||||||
}
|
if (next.getIdElement().isEmpty()) {
|
||||||
|
nextEntry.getRequest().setMethod(HTTPVerb.POST);
|
||||||
|
} else {
|
||||||
|
nextEntry.getRequest().setMethod(HTTPVerb.PUT);
|
||||||
|
if (next.getIdElement().isAbsolute()) {
|
||||||
|
nextEntry.getRequest().setUrl(next.getIdElement().getValue());
|
||||||
|
} else {
|
||||||
|
String resourceType = myContext.getResourceDefinition(next).getName();
|
||||||
|
nextEntry.getRequest().setUrl(new IdType(theServerBase, resourceType, next.getIdElement().getIdPart(),
|
||||||
|
next.getIdElement().getVersionIdPart()).getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addResourcesForSearch(theResources);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
myBundle.getTotalElement().setValue(theTotalResults);
|
||||||
public void initializeWithBundleResource(IBaseResource theBundle) {
|
}
|
||||||
myBundle = (Bundle) theBundle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IBaseResource> toListOfResources() {
|
public void initializeWithBundleResource(IBaseResource theBundle) {
|
||||||
ArrayList<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
myBundle = (Bundle) theBundle;
|
||||||
for (BundleEntryComponent next : myBundle.getEntry()) {
|
}
|
||||||
if (next.getResource() != null) {
|
|
||||||
retVal.add(next.getResource());
|
@Override
|
||||||
} else if (next.getResponse().getLocationElement().isEmpty() == false) {
|
public List<IBaseResource> toListOfResources() {
|
||||||
IdType id = new IdType(next.getResponse().getLocation());
|
ArrayList<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||||
String resourceType = id.getResourceType();
|
for (BundleEntryComponent next : myBundle.getEntry()) {
|
||||||
if (isNotBlank(resourceType)) {
|
if (next.getResource() != null) {
|
||||||
IBaseResource res = (IBaseResource) myContext.getResourceDefinition(resourceType).newInstance();
|
retVal.add(next.getResource());
|
||||||
res.setId(id);
|
} else if (next.getResponse().getLocationElement().isEmpty() == false) {
|
||||||
retVal.add(res);
|
IdType id = new IdType(next.getResponse().getLocation());
|
||||||
}
|
String resourceType = id.getResourceType();
|
||||||
}
|
if (isNotBlank(resourceType)) {
|
||||||
}
|
IBaseResource res = (IBaseResource) myContext.getResourceDefinition(resourceType).newInstance();
|
||||||
return retVal;
|
res.setId(id);
|
||||||
}
|
retVal.add(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,10 @@
|
||||||
Instance $meta operations on JPA server did not previously return the
|
Instance $meta operations on JPA server did not previously return the
|
||||||
resource version and lastUpdated time
|
resource version and lastUpdated time
|
||||||
</action>
|
</action>
|
||||||
|
<action type="fix">
|
||||||
|
Server responses populate Bundle.entry.fullUrl if possible. Thanks
|
||||||
|
to Bill de Beaubien for reporting!
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="1.1" date="2015-07-13">
|
<release version="1.1" date="2015-07-13">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
|
Loading…
Reference in New Issue