starting implementing check if only one Composition is returned

This commit is contained in:
patrick-werner 2018-06-20 16:12:58 +02:00
parent b76ad6870f
commit f9a19c4b1f
3 changed files with 40 additions and 10 deletions

View File

@ -54,7 +54,6 @@ public class FhirResourceDaoCompositionDstu3 extends FhirResourceDaoDstu3<Compos
if (theId != null) {
paramMap.add("_id", new StringParam(theId.getIdPart()));
}
//TODO: check if the search actually only returns one Composition, otherwise throw error
IBundleProvider bundleProvider = search(paramMap);
return bundleProvider;
}

View File

@ -17,6 +17,7 @@ import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import javax.print.attribute.standard.Severity;
import java.util.ArrayList;
import java.util.List;
@ -75,9 +76,19 @@ public class BaseJpaResourceProviderCompositionDstu3 extends JpaResourceProvider
try {
IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theLastUpdated, theSortSpec, theRequestDetails);
List<IBaseResource> resourceList = bundleProvider.getResources(0, bundleProvider.size());
boolean foundCompositionResource = false;
Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT);
for (IBaseResource resource : resourceList)
for (IBaseResource resource : resourceList) {
bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
if (((Resource) resource).getResourceType() == ResourceType.Composition) {
if (foundCompositionResource == true) {
OperationOutcome operationOutcome = new OperationOutcome().addIssue(new OperationOutcome.OperationOutcomeIssueComponent().setSeverity(OperationOutcome.IssueSeverity.ERROR).setCode(OperationOutcome.IssueType.PROCESSING));
throw new InvalidRequestException("$document can only be applied to a single Composition Resource", operationOutcome);
}
foundCompositionResource = true;
}
}
return bundle;
} finally {
endRequest(theServletRequest);

View File

@ -93,19 +93,37 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test
composition.addSection().addEntry(new Reference(obsId));
}
compId = ourClient.create().resource(composition).execute().getId().toUnqualifiedVersionless().getValue();
Composition composition2 = new Composition();
composition.setSubject(new Reference(patId));
}
@Test
public void testDocumentBundleReturnedCorrect() throws Exception {
// myDaoConfig.setEverythingIncludesFetchPageSize(1);
String theUrl = ourServerBase + "/" + compId + "/$document?_format=json";
public void testDocumentBundleMultipleCompositions() throws Exception {
String theUrl = ourServerBase + "/Composition?patient=" + patId + "/$document?_format=json";
System.out.println(theUrl);
Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON);
assertNull(bundle.getLink("next"));
Set<String> actual = new TreeSet<String>();
Set<String> actual = new HashSet<>();
for (BundleEntryComponent nextEntry : bundle.getEntry()) {
actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
}
}
@Test
public void testDocumentBundleReturnedCorrect() throws IOException {
// myDaoConfig.setEverythingIncludesFetchPageSize(1);
String theUrl = ourServerBase + "/" + compId + "/$document?_format=json";
Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON);
assertNull(bundle.getLink("next"));
Set<String> actual = new HashSet<>();
for (BundleEntryComponent nextEntry : bundle.getEntry()) {
actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
}
@ -123,8 +141,10 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test
HttpGet get = new HttpGet(theUrl);
CloseableHttpResponse resp = ourHttpClient.execute(get);
try {
assertEquals(theEncoding.getResourceContentTypeNonLegacy(), resp.getFirstHeader(ca.uhn.fhir.rest.api.Constants.HEADER_CONTENT_TYPE).getValue().replaceAll(";.*", ""));
bundle = theEncoding.newParser(myFhirCtx).parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8));
// assertEquals(theEncoding.getResourceContentTypeNonLegacy(), resp.getFirstHeader(ca.uhn.fhir.rest.api.Constants.HEADER_CONTENT_TYPE).getValue().replaceAll(";.*", ""));
String resourceString = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
System.out.println(resourceString);
bundle = theEncoding.newParser(myFhirCtx).parseResource(Bundle.class, resourceString);
} finally {
IOUtils.closeQuietly(resp);
}