I am trying to get Allergy data from a public testing “sandbox”.
The above works and I get below which I would like to parse:
<id
…
you can get entire response by doing your own cURL if needed.
I am using Visual Studio 2019 C# code:
using System.Net.Http;
using System.Net.Http.Headers;
using Hl7.Fhir.Model;
using System.Xml;
using System.Xml.Linq;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Rest;
private async void DoHTMLstuffAllergy()
{
var url = “https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/AllergyIntolerance? patient=Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB”;
Hl7.Fhir.Rest.FhirClient fhirClient = new FhirClient(url);
This fhirClient seems to be empty;
if followed by:
Resource result = await fhirClient.GetAsync(url);
I get error:
Inner Exception 1:
FormatException: Type checking the data: Encountered unknown element ‘recordedDate’ at location ‘Bundle.entry[0].resource[0].recordedDate[0]’ while parsing
If I use a HttpCient instead:
using var client = new HttpClient();
var result = await client.GetAsync(url);
var content = await result.Content.ReadAsStringAsync();
then try to parse:
FhirXmlParser fhirXmlParser = new FhirXmlParser();
Hl7.Fhir.Model.Bundle bund = fhirXmlParser.Parse<Hl7.Fhir.Model.Bundle>(result.ToString());
I get this error:
Inner Exception 1:
FormatException: Invalid Xml encountered. Details: Data at the root level is invalid. Line 1, position 1.
Inner Exception 2:
XmlException: Data at the root level is invalid. Line 1, position 1.
Can anyone help me parse out the 3 Allergies from the Bundle?