Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary read: wrong extraction of the contained data when accepting a FHIR MIME type #6630

Open
qligier opened this issue Jan 17, 2025 · 0 comments

Comments

@qligier
Copy link

qligier commented Jan 17, 2025

Describe the bug
When reading a Binary that contains a FHIR resource and setting the Accept header to the value of Binary.contentType, HAPI returns the contained resource instead of the Binary resource. It should return the Binary resource instead of extracting the contained resource.

To Reproduce
An example with the following Binary resource, containing a JSON Patient resource, created on https://hapi.fhir.org/baseR4/ (running HAPI FHIR 7.7.15-SNAPSHOT):

{
  "resourceType": "Binary",
  "contentType": "application/fhir+json",
  "data": "[Patient resource]"
}

When reading the resource with Accept: application/fhir+json, the server returns the contained resource (Patient):

GET /baseR4/Binary/45848035 HTTP/1.1
Accept: application/fhir+json
 
HTTP/1.1 200 OK
Content-Type: application/fhir+json
 
{
  "resourceType": "Patient",
  // ...
}

When requesting the resource with the XML MIME type, it returns the BInary instead:

GET /baseR4/Binary/45848035 HTTP/1.1
Accept: application/fhir+xml
 
HTTP/1.1 200 OK
Content-Type: application/fhir+xml;charset=utf-8
 
<Binary xmlns="http://hl7.org/fhir">
  <contentType value="application/fhir+json"/>
  <data value="..."/>
</Binary>

Expected behavior
In both cases, the server shall return the Binary resource, as specified in the FHIR specification:

When a read request is made with a FHIR type in the Accept header (e.g. "application/fhir+xml" or "application/fhir+json") the Binary resource is returned in the requested FHIR format. This applies even when the binary data itself has a FHIR mime type

It seems HAPI checks whether the requested MIME type is the same as the Binary.contentType before processing the special case with "application/fhir+xml" and "application/fhir+json".

Environment (please complete the following information):

Additional context
I checked the behaviour when no Accept header is specified; in that case, the contained resource is returned. While that case is not explicitly described in the spec, it seems coherent with the stated intent:

However, the intent is that unless specifically requested, the FHIR XML/JSON representation is not returned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant