fix: set Content-Type to application/fhir+json for PATCH requests (Fixes #155)#156
Open
rtmalikian wants to merge 1 commit into
Open
fix: set Content-Type to application/fhir+json for PATCH requests (Fixes #155)#156rtmalikian wants to merge 1 commit into
rtmalikian wants to merge 1 commit into
Conversation
HAPI FHIR rejects PATCH requests with Content-Type: application/json (HAPI-1965). Set Content-Type to application/fhir+json when the HTTP method is PATCH, matching the FHIR specification requirement. Fixes beda-software#155 Signed-off-by: Raphael Malikian <rtmalikian@gmail.com>
Author
|
Friendly ping — this PR is ready for review when you have a chance. Happy to address any feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #155
Summary
PATCH operations fail against HAPI FHIR servers with:
The
_do_requestmethod usesrequests.request(method, url, json=data)which automatically setsContent-Type: application/json. HAPI FHIR rejects this for PATCH operations per the FHIR specification.Solution
Set
Content-Type: application/fhir+jsonfor PATCH requests in both sync (lib_sync.py) and async (lib_async.py)_do_requestimplementations. This matches the FHIR specification requirement that PATCH requests useapplication/fhir+jsoncontent type.The fix is applied at the
_do_requestlevel so it covers all PATCH code paths:client.patch()— direct PATCH by resource type + IDresource.save(fields=[...])— partial update via field selection (uses PATCH internally)Verification
python3 -c "import ast; ast.parse(open('fhirpy/base/lib_sync.py').read())"— passesChangelog
Files Changed
fhirpy/base/lib_sync.py— Add Content-Type header for PATCH in SyncClient._do_requestfhirpy/base/lib_async.py— Add Content-Type header for PATCH in AsyncClient._do_requestVerification
About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.
📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a
Disclosure: This code was developed with assistance from mimo-v2.5-pro (xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.