I am using the library fhir-net-api dstu2 to parse incoming FHIR JSON from a Restful web service to XML in a biztalk pipeline component and then passing it to the XML disassembler for debatching in BizTalk. Most message go through without an issue but I am getting the following error on the occasional message.
"Invalid character in the given encoding. Line 1, position 12700.".
I have inspected the messages and cannot see any difference in the incoming JSON that would cause this error.
Looking at the character position given in the error message, the XML output from the fhir-net-api shows the issue below. For some reason the library cuts the location short and puts in a bundle tag. <Bundle xmlns="http://hl7.org/fhir"><total value="9" />
Any thought on what is going on here or how to go about troubleshooting?
I cannot post the full messages but here are snippet of the problem area.
Input JSON snippet
"hospitalization": {"dischargeDiagnosis": [ {
"reference": "#Reason",
"display": "DWA-Discharged with Approval"
}]},
"location": [{"location": {"display": "SPH 4th Bunny Dr’s Clinic"}}],
"serviceProvider": {"display": "FOO"}
}},
{"resource": {
"resourceType": "Encounter",
"id": "FOO0009-394a-4c51",
"extension": [
Output XML snippet
<hospitalization>
<dischargeDiagnosis>
<reference value="#Reason" />
<display value="DWA-Discharged with Approval" />
</dischargeDiagnosis>
</hospitalization>
<location>
<location>
<display value="SPH 4<Bundle xmlns="http://hl7.org/fhir">
<total value="9" />
<entry>
<resource>
<Encounter>
EDIT - I isolated the problem resource and de-identified the message. Here is the full JSON message that causes the error above. I tried the FHIR JSON to XML notepad++ plugin and it serializes the message correctly.
Here is the code from the pipeline component.
Hl7.Fhir.Serialization.ResourceReader resourceReader = new Hl7.Fhir.Serialization.ResourceReader(FhirJsonParser.CreateFhirReader(json), ParserSettings.Default);
string resourceXmlString = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(resourceReader.Deserialize());
Here is the JSON that causes the issue
{
"resourceType": "Bundle",
"total": 1,
"entry": [
{"resource": {
"resourceType": "Encounter",
"id": "10000000-0000-0000-000-200000000",
"extension": [
{
"url": "https://foo.org/documents/fhir/extensions/encounter-facility",
"valueString": "St. Foo Hospital"
},
{
"url": "https://foo.org/documents/fhir/extensions/encounter-service",
"valueString": "Foo PROGRAM/Foo ECHOCARDIOLOGY"
},
{
"url": "https://foo.org/documents/fhir/extensions/encounter-patienttype",
"valueString": "Diagnostic - Outpatient"
},
{
"url": "https://foo.org/documents/fhir/extensions/encounter-documentcount",
"valueInteger": 0
},
{
"url": "https://foo.org/documents/fhir/extensions/encounter-entitysourcesystem",
"valueString": "CDR"
},
{
"url": "https://foo.org/documents/fhir/extensions/encounter-mrnid",
"valueString": "10000000"
}
],
"identifier": [
{
"use": "official",
"value": "1000000-5420-0000-0000-00000"
},
{
"use": "secondary",
"value": "100000000000"
}
],
"patient": {"reference": "Patient/000000000"},
"participant": [
{
"type": [ {
"coding": [ {
"system": "http://hl7.org/fhir/v3/ParticipationType",
"code": "PRCP"
}],
"text": "Primary Care Physician"
}],
"individual": {"display": "Foo, Guy"}
},
{
"type": [ {
"coding": [ {
"system": "http://hl7.org/fhir/v3/ParticipationType",
"code": "ATND"
}],
"text": "Attending Physician"
}],
"individual": {"display": "RFoo, JFoo L"}
}
],
"period": {
"start": "2015-10-27T13:59:00+00:00",
"end": "2017-02-17T09:39:07+00:00"
},
"reason": [ {
"coding": [ {
"system": "http://www.ihtsdo.org/snomed-ct",
"code": "33962009"
}],
"text": "ECHOCARDIOGRAM"
}],
"hospitalization": {"dischargeDiagnosis": [ {
"reference": "#Reason",
"display": "DWA-Discharged with Approval"
}]},
"location": [{"location": {"display": "SPH 4th Foo Dr’s Clinic"}}],
"serviceProvider": {"display": "Foo_foo"}
}}
]
}