Restful server can handle multiple fhircontext versions #2406
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.
I am currently trying to work with multiple fhir versions simultaneously by using
one fhir servlet with R4 FhirContext and a resource provider for R4 and an
additional interceptor which converts incoming R3 resources into R4 and the same for outgoing resources.
This is working more or less.
However, for the outgoing resources there is a problem when the parser needs some non-standard properties:
At the very end of the call stack the RestfulServerUtils class is used for transforming
the Resource into a String. In order to do so, it needs a
FhirContext
.However, the context of the server here is of course R4 while R3 is needed.
The utils class then creates a new default context in the
getNewParser
method using thegetContextForVersion
.In order to make the new
FhirContext
aware of necessary configurations onecould either trying to copy the configuration from the R4 configuration to the R3 context.
Alternatively one could open the backing
Map<FhirVersionEnum, FhirContext>
by e.g. adding a methodThis alternative has the advantage that the configuration is explicit and does not depend
on some implicit conversion which might even run into incompatibilities between R3 and R4.
A cleaner and more powerful way for doing this, would probably be to add this structure to
the
RestfulServer
and access it via theIRestfulServerDefaults
I have explored the latter in this patch which adds a new data structure to the RestfulServer
FhirVersionEnums
toFhirContext
- which is then used by theRestfulServerUtils
when serializing a resource.