FhirSerializer.SerializeResourceToXml not serializing Extensions (old version of Hl7.Net library)

67 views
Skip to first unread message

Benson Lott

unread,
Jul 10, 2019, 6:27:20 PM7/10/19
to FHIR DOTNET
I am calling


string fhirString = FhirSerializer.SerializeResourceToXml(fhirBundle, Hl7.Fhir.Rest.SummaryType.True);



in the `fhirBundle` object, there is a Communication resource entry which I have added extensions to, like so:

            communication.AddExtension(Constants.ThxExtReplyTo,
               
new ResourceReference()
               
{
                   
Reference = Constants.CdxPractitionerUrl + senderPractId,
                   
Extension = new List<Extension>()
                   
{
                       
// this is the on-behalf-of sub extension
                       
new Extension()
                       
{
                           
Url = Constants.ThxExtOnBehalfof,
                           
Value = new ResourceReference()
                           
{
                               
Reference = Constants.CdxOrganizationUrl + senderOrgId
                           
}
                       
}
                   
}
               
}
           
);


When debugging, I can see the fhirBundle/Communication entry.Resource does contain the extensions, but after serialization, they are not in the resulting XML.

In contrast, in the Communication/recipient element, I am able to add and extension and it works -- for example:

                var recipRef = new ResourceReference();
               
if (recip.providerType.Equals("Primary"))
               
{
                    recipRef
.AddExtension(Constants.ThxExtPrimaryRecipient, new FhirBoolean(true));
               
}
                recipRef
.AddExtension(Constants.ThxExtOnBehalfof, new ResourceReference()
               
{
                   
//Url = new Uri(Constants.ThxExtOnBehalfof),
                   
Reference = Constants.CdxOrganizationUrl + recip.providerLocation.GetLocationKey()
                   
//Value = new FhirString(Constants.CdxOrganizationUrl + recip.providerLocation.GetLocationKey())
               
});
                communication
.Recipient.Add(recipRef);


This is an OLD version of the .Net library, so I realize it's done a little differently now, but is there some knowledge out there to indicate what I might be doing wrong. Extensions ARE working in other places, but in many I cannot get them to work. I have no choice in teh version that we are using since this is beyond my control.


Here is the complete Communication XML that results from using the code above:

<Communication>
<id value="495e2bc8-3d9f-47c2-a4c8-a59650dd9d0a" />
<meta>
<security>
<code value="R" />
<display value="restricted" />
</security>
<tag>
<code value="SUBSETTED" />
</tag>
</meta>
<identifier>
<system value="urn:ietf:rfc3986" />
<value value="urn:uuid:495e2bc8-3d9f-47c2-a4c8-a59650dd9d0a" />
</identifier>
<category>
<coding>
<code value="consult" />
</coding>
</category>
<recipient>
<valueBoolean value="true" />
</extension>
<valueReference>
</valueReference>
</extension>
</recipient>
<payload>
<contentAttachment>
<contentType value="application/pdf" />
<url value="f634504b-79a2-e911-a96d-0050568c55a6" />
<size value="84110" />
<title value=".pdf" />
</contentAttachment>
</payload>
<status value="in-progress" />
<sent value="2019-07-10T15:14:46-07:00" />
<subject>
<reference value="Patient/1a49fa2d-6a76-4862-9cb9-694d173276df" />
</subject>
</Communication>

Benson Lott

unread,
Jul 11, 2019, 2:00:24 PM7/11/19
to FHIR DOTNET
I figured out what's going on: I needed to user Hl7.Fhir.Rest.SummaryType.False However, this introduced another problem as I'm getting "Data root element is invalid". I imagine that means my Entry Components are not valid or missing some data. I was able to strip them out one by one and find the one that does serialize, but I can't see the difference.

Any clues on how to tell what might be missing or broken from the Serializer's perspective?
Reply all
Reply to author
Forward
0 new messages