Stream: dotnet
Topic: How to get XML/JSON from FHIR Client
Yunwei Wang (Apr 19 2016 at 17:59):
I am using .NET FHIR Client. Instead of parsed resource, how can I get raw xml/json from response?
Theo Stolker (Apr 19 2016 at 19:20):
Serialize the output again, and you have the raw xml/json!
Josh Mandel (Apr 19 2016 at 19:49):
Well, you have something semantically equivalent - but not the actual raw response. That distinction may or may not be important, depending on your goals
Yunwei Wang (Apr 19 2016 at 21:05):
The issue I have now is that the resource xml received is not valid. So the FHIR parser throws exception. But I don't quite care about those elements in error. Or say I don't need the whole resource but only small portions. So if I can get the raw xml w/o parsing, then I can hand pick the element that I need using XML reader (or xpath).
Brian Postlethwaite (Apr 19 2016 at 21:40):
If the parser is not reading the content, then it likely isn't valid FHIR xml, so question reading the content manually. There could be content in there that you aren't expecting, like modifier extensions.
Yunwei Wang (Apr 19 2016 at 22:40):
Yes. I know the content is not a valid FHIR xml. While waiting for the content issuer to fix the problems, I would like to continue working on it. For example, if I only need patient's ID and name, then I don't care if patient's address is in valid format or not. I can write my own HTTP client to send request. But since I am already using FHIR client everywhere else, I would like to keep consistency.
Brian Postlethwaite (Apr 20 2016 at 01:22):
Not my favourite bit of code, but there is the LastBodyAsText
property on the fhirclient that has just that. This may or may not work, need to be careful and test it well, as it is reading from the LastRequest, and not sure when this is disposed of and could cause a ObjectDisposedException.
Also, if you are sharing the fhirclient object across threads, can be overwritten.
Brian Postlethwaite (Apr 20 2016 at 01:22):
Think that covers the disclaimers ;)
Ewout Kramer (Apr 20 2016 at 09:00):
And you can override OnAfterResponse, which has the raw body as a parameter
Brian Postlethwaite (Apr 20 2016 at 10:15):
Yes Ewout, I think this is the preferred way to do it, as it won't have been disposed here.
Yunwei Wang (Apr 23 2016 at 13:27):
Ewout: That sounds a solution. I will try it.
Last updated: Apr 12 2022 at 19:14 UTC