Issue 2377 missing entry full url in document (#3304)

* start with failing test

* wip

* add changelog

* Add implementation

* Fix DSTU3 impl

* Fix DSTU2 and R5
This commit is contained in:
Tadgh 2022-01-18 07:40:53 -08:00 committed by GitHub
parent b09b0f207b
commit 9f7c454c6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 32 deletions

View File

@ -27,6 +27,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -37,7 +38,7 @@ import java.util.Set;
*/ */
public interface IVersionSpecificBundleFactory { public interface IVersionSpecificBundleFactory {
void addResourcesToBundle(List<IBaseResource> theResult, BundleTypeEnum theBundleType, String theServerBase, BundleInclusionRule theBundleInclusionRule, Set<Include> theIncludes); void addResourcesToBundle(List<IBaseResource> theResult, BundleTypeEnum theBundleType, String theServerBase, @Nullable BundleInclusionRule theBundleInclusionRule, @Nullable Set<Include> theIncludes);
void addRootPropertiesToBundle(String theId, @Nonnull BundleLinks theBundleLinks, Integer theTotalResults, IPrimitiveType<Date> theLastUpdated); void addRootPropertiesToBundle(String theId, @Nonnull BundleLinks theBundleLinks, Integer theTotalResults, IPrimitiveType<Date> theLastUpdated);

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 2377
jira: SMILE-807
title: "Calling the `$document` operation previously omitted the fullUrl of the bundle entries. This has been corrected."

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.model.dstu2.resource.Composition; import ca.uhn.fhir.model.dstu2.resource.Composition;
import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseBundle;
/* /*
@ -33,16 +34,15 @@ public class BaseJpaResourceProviderCompositionDstu2 extends JpaResourceProvider
* Composition/123/$document * Composition/123/$document
*/ */
//@formatter:off //@formatter:off
@Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) @Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT)
public IBaseBundle getDocumentForComposition( public IBundleProvider getDocumentForComposition(
javax.servlet.http.HttpServletRequest theServletRequest) { javax.servlet.http.HttpServletRequest theServletRequest) {
//@formatter:on //@formatter:on
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
((IFhirResourceDaoComposition<Composition>)getDao()).getDocumentForComposition(theServletRequest, null, null, null, null, null, null); return ((IFhirResourceDaoComposition<Composition>)getDao()).getDocumentForComposition(theServletRequest, null, null, null, null, null, null);
return null;
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
} }

View File

@ -52,7 +52,7 @@ public class BaseJpaResourceProviderCompositionDstu3 extends JpaResourceProvider
*/ */
//@formatter:off //@formatter:off
@Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT) @Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT)
public IBaseBundle getDocumentForComposition( public IBundleProvider getDocumentForComposition(
javax.servlet.http.HttpServletRequest theServletRequest, javax.servlet.http.HttpServletRequest theServletRequest,
@ -81,14 +81,7 @@ public class BaseJpaResourceProviderCompositionDstu3 extends JpaResourceProvider
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails); IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails);
List<IBaseResource> resourceList = bundleProvider.getAllResources(); return bundleProvider;
boolean foundCompositionResource = false;
Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT);
for (IBaseResource resource : resourceList) {
bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
}
return bundle;
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
} }

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.provider.r4; package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.context.api.BundleInclusionRule;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoComposition; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoComposition;
import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
@ -8,19 +9,24 @@ import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.Sort; import ca.uhn.fhir.rest.annotation.Sort;
import ca.uhn.fhir.rest.api.BundleLinks;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.hapi.rest.server.R4BundleFactory;
import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Composition; import org.hl7.fhir.r4.model.Composition;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.UnsignedIntType; import org.hl7.fhir.r4.model.UnsignedIntType;
import java.util.Date;
import java.util.List; import java.util.List;
@ -50,7 +56,8 @@ public class BaseJpaResourceProviderCompositionR4 extends JpaResourceProviderR4<
* Composition/123/$document * Composition/123/$document
*/ */
@Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT) @Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT)
public IBaseBundle getDocumentForComposition( // public IBaseBundle getDocumentForComposition(
public IBundleProvider getDocumentForComposition(
javax.servlet.http.HttpServletRequest theServletRequest, javax.servlet.http.HttpServletRequest theServletRequest,
@ -78,14 +85,7 @@ public class BaseJpaResourceProviderCompositionR4 extends JpaResourceProviderR4<
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails); IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails);
List<IBaseResource> resourceList = bundleProvider.getAllResources(); return bundleProvider;
boolean foundCompositionResource = false;
Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT);
for (IBaseResource resource : resourceList) {
bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
}
return bundle;
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
} }

View File

@ -50,7 +50,7 @@ public class BaseJpaResourceProviderCompositionR5 extends JpaResourceProviderR5<
* Composition/123/$document * Composition/123/$document
*/ */
@Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT) @Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT)
public IBaseBundle getDocumentForComposition( public IBundleProvider getDocumentForComposition(
javax.servlet.http.HttpServletRequest theServletRequest, javax.servlet.http.HttpServletRequest theServletRequest,
@ -78,14 +78,7 @@ public class BaseJpaResourceProviderCompositionR5 extends JpaResourceProviderR5<
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails); IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails);
List<IBaseResource> resourceList = bundleProvider.getAllResources(); return bundleProvider;
boolean foundCompositionResource = false;
Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT);
for (IBaseResource resource : resourceList) {
bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
}
return bundle;
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
} }

View File

@ -32,8 +32,10 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test { public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test {
@ -117,6 +119,12 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test
String theUrl = ourServerBase + "/" + compId + "/$document?_format=json"; String theUrl = ourServerBase + "/" + compId + "/$document?_format=json";
Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON); Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON);
bundle.getEntry().stream()
.forEach(entry -> {
assertThat(entry.getFullUrl(), is(equalTo(entry.getResource().getIdElement().toVersionless().toString())));
});
assertThat(bundle.getType(), is(equalTo(Bundle.BundleType.DOCUMENT)));
assertNull(bundle.getLink("next")); assertNull(bundle.getLink("next"));
Set<String> actual = new HashSet<>(); Set<String> actual = new HashSet<>();

View File

@ -25,8 +25,10 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -115,7 +117,13 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test {
String theUrl = ourServerBase + "/" + compId + "/$document?_format=json"; String theUrl = ourServerBase + "/" + compId + "/$document?_format=json";
Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON); Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON);
//Ensure each entry has a URL.
assertThat(bundle.getType(), is(equalTo(Bundle.BundleType.DOCUMENT)));
bundle.getEntry().stream()
.forEach(entry -> {
assertThat(entry.getFullUrl(), is(equalTo(entry.getResource().getIdElement().toVersionless().toString())));
});
assertNull(bundle.getLink("next")); assertNull(bundle.getLink("next"));
Set<String> actual = new HashSet<>(); Set<String> actual = new HashSet<>();