Need help to POST any document to Cerner using the DocumentReference FHIR resource & the LOINC.

739 views
Skip to first unread message

Sandip Dhage

unread,
Aug 24, 2016, 3:17:25 AM8/24/16
to Cerner FHIR Developers
Hello Team,

I want to POST any document to Cerner using the DocumentReference FHIR resource & the LOINC of “78280" using c# code.

Can you help me to have sample code to achieve it?

Waiting for your favorable response. It would be great help to go ahead with my requirement.

Thanks in advance.

Kevin Shekleton

unread,
Aug 24, 2016, 4:26:38 PM8/24/16
to Cerner FHIR Developers
Hi Sandip!

Ewout Kramer, one of the FHIR core team members, maintains the FHIR .NET library that will be of interest to you. I would encourage you to play with that C# code and if you run into any specific errors that you are not able to figure out, please let us know.

Additionally, I would encourage you to check out the FHIR Zulip chat over at https://chat.fhir.org. There are lots of other FHIR developers who monitor that medium and I'm sure you'll find other C# developers to collaborate with. 

Regards,
Kevin

Jenni Syed

unread,
Aug 24, 2016, 4:54:01 PM8/24/16
to Cerner FHIR Developers
In addition to what Kevin mentioned, there is a valid example on our documentation if you're wanting the JSON structure [1]. It does NOT include the base64 XHTML document (that's snipped since it's long), but if your XHTML passes an XHTML validator (eg [2]), it should work.



On Wednesday, August 24, 2016 at 2:17:25 AM UTC-5, Sandip Dhage wrote:

Sandip Dhage

unread,
Aug 30, 2016, 5:58:20 AM8/30/16
to Cerner FHIR Developers
Thanks Kevin for your response.

I tried further for implementation, I added below sample code to post the document using DocumentReference FHIR resource. BUT at line client.Create below, I can see exception like "An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotAcceptable. OperationOutcome: Error: Endpoint returned a body with contentType 'text/plain', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?"

Below is the code snippet -

           var cernerEhrSourceId = "d075cf8b-3261-481d-97e5-ba6c48d3b41f";
            var url = $"https://fhir-open.sandboxcernerpowerchart.com/dstu2/{cernerEhrSourceId}/";

            var client = new EpreopFhirClient(url);
            client.VerifyFhirVersion = true;
            //client.OnBeforeRequest += ClientOnOnBeforeRequest;
            client.UseFormatParam = true;

            var documentReference = new DocumentReference();
            documentReference.Status = DocumentReferenceStatus.Current;
            documentReference.Type = new CodeableConcept("http://loinc.org", "78280-5");

            DocumentReference.ContentComponent contentItem = new DocumentReference.ContentComponent();
            contentItem.Attachment = new Attachment();
            contentItem.Attachment.ContentType = "application / xhtml + xml; charset = utf - 8";
            //contentItem.Attachment.ContentType = "xml/json";
            contentItem.Attachment.Data = new byte[10]; //TODO

            documentReference.Description = "";
            documentReference.Content.Add(contentItem);
            var result = client.Create<DocumentReference>(documentReference);

Can you help me out here, whats wrong I am doing here...

Sandip Dhage

unread,
Aug 30, 2016, 5:58:47 AM8/30/16
to Cerner FHIR Developers
Thanks Jenni for your response.


I tried further for implementation, I added below sample code to post the document using DocumentReference FHIR resource. BUT at line client.Create below, I can see exception like "An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotAcceptable. OperationOutcome: Error: Endpoint returned a body with contentType 'text/plain', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?"

Below is the code snippet -

           var cernerEhrSourceId = "d075cf8b-3261-481d-97e5-ba6c48d3b41f";
            var url = $"https://fhir-open.sandboxcernerpowerchart.com/dstu2/{cernerEhrSourceId}/";

            var client = new EpreopFhirClient(url);
            client.VerifyFhirVersion = true;
            //client.OnBeforeRequest += ClientOnOnBeforeRequest;
            client.UseFormatParam = true;

            var documentReference = new DocumentReference();
            documentReference.Status = DocumentReferenceStatus.Current;
            documentReference.Type = new CodeableConcept("http://loinc.org", "78280-5");

            DocumentReference.ContentComponent contentItem = new DocumentReference.ContentComponent();
            contentItem.Attachment = new Attachment();
            contentItem.Attachment.ContentType = "application / xhtml + xml; charset = utf - 8";
            //contentItem.Attachment.ContentType = "xml/json";
            contentItem.Attachment.Data = new byte[10]; //TODO

            documentReference.Description = "";
            documentReference.Content.Add(contentItem);
            var result = client.Create<DocumentReference>(documentReference);

Can you help me out here, whats wrong I am doing here...

Sandip Dhage

unread,
Aug 30, 2016, 5:59:50 AM8/30/16
to Cerner FHIR Developers
Thanks Kevin, Jenni for your response.


I tried further for implementation, I added below sample code to post the document using DocumentReference FHIR resource. BUT at line client.Create below, I can see exception like "An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotAcceptable. OperationOutcome: Error: Endpoint returned a body with contentType 'text/plain', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?"

Below is the code snippet -

           var cernerEhrSourceId = "d075cf8b-3261-481d-97e5-ba6c48d3b41f";
            var url = $"https://fhir-open.sandboxcernerpowerchart.com/dstu2/{cernerEhrSourceId}/";

            var client = new EpreopFhirClient(url);
            client.VerifyFhirVersion = true;
            //client.OnBeforeRequest += ClientOnOnBeforeRequest;
            client.UseFormatParam = true;

            var documentReference = new DocumentReference();
            documentReference.Status = DocumentReferenceStatus.Current;
            documentReference.Type = new CodeableConcept("http://loinc.org", "78280-5");

            DocumentReference.ContentComponent contentItem = new DocumentReference.ContentComponent();
            contentItem.Attachment = new Attachment();
            contentItem.Attachment.ContentType = "application / xhtml + xml; charset = utf - 8";
            //contentItem.Attachment.ContentType = "xml/json";
            contentItem.Attachment.Data = new byte[10]; //TODO

            documentReference.Description = "";
            documentReference.Content.Add(contentItem);
            var result = client.Create<DocumentReference>(documentReference);

Can you help me out here, whats wrong I am doing here...

Michele Mottini

unread,
Aug 30, 2016, 9:07:14 AM8/30/16
to Cerner FHIR Developers
Cerner requires JSON, I think the client library defaults to XML. Try adding:

client.PreferredFormat = FhirRest.ResourceFormat.Json;

  - Michele
  CareEvolution Inc

Sandip Dhage

unread,
Aug 30, 2016, 9:22:15 AM8/30/16
to Cerner FHIR Developers
Thanks Michele, it works & resolved the format related exception.

BUT now I am getting below exception. Can you have a look into the my code snippet provided above & update me what need to be taken care to resolve below exception??

An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotFound. Body is null

Thanks again for your quick resolution !!!

Michele Mottini

unread,
Aug 30, 2016, 9:58:39 AM8/30/16
to Cerner FHIR Developers
Sorry, no idea about this one. I guess the creation failed because something was missing from the supplied DocumentReference but the server should not return a NotFound in that case and it should supply some info in the body


  - Michele
  CareEvolution Inc

--
You received this message because you are subscribed to the Google Groups "Cerner FHIR Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cerner-fhir-developers+unsub...@googlegroups.com.
To post to this group, send email to cerner-fhir-developers@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerner-fhir-developers/88cd8806-adeb-4fe4-867b-4c205b216bf9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sandip Dhage

unread,
Aug 30, 2016, 10:36:02 AM8/30/16
to Cerner FHIR Developers
Ok.. Thanks Michele for your response.

Actually I am trying to supply different information But it doesn't work for me..

Not sure what I am missing here.


On Wednesday, 24 August 2016 12:47:25 UTC+5:30, Sandip Dhage wrote:

Sandip Dhage

unread,
Aug 30, 2016, 10:40:46 AM8/30/16
to Cerner FHIR Developers
Hi All,

Anyone have idea on this, what I need to be supply here to resolve the exception below??



An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotFound. Body is null


It would be great help for me..


On Tuesday, 30 August 2016 19:28:39 UTC+5:30, Michele Mottini wrote:
Sorry, no idea about this one. I guess the creation failed because something was missing from the supplied DocumentReference but the server should not return a NotFound in that case and it should supply some info in the body


  - Michele
  CareEvolution Inc
On Tue, Aug 30, 2016 at 9:22 AM, Sandip Dhage <> wrote:
Thanks Michele, it works & resolved the format related exception.

BUT now I am getting below exception. Can you have a look into the my code snippet provided above & update me what need to be taken care to resolve below exception??

An exception of type 'Hl7.Fhir.Rest.FhirOperationException' occurred in Hl7.Fhir.DSTU2.Core.dll but was not handled in user code

Additional information: Operation was unsuccessful, and returned status NotFound. Body is null


Thanks again for your quick resolution !!!

On Tuesday, 30 August 2016 18:37:14 UTC+5:30, Michele Mottini wrote:
Cerner requires JSON, I think the client library defaults to XML. Try adding:

client.PreferredFormat = FhirRest.ResourceFormat.Json;

  - Michele
  CareEvolution Inc

--
You received this message because you are subscribed to the Google Groups "Cerner FHIR Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cerner-fhir-developers+unsub...@googlegroups.com.
To post to this group, send email to cerner-fhir...@googlegroups.com.

Jenni Syed

unread,
Aug 30, 2016, 11:35:02 AM8/30/16
to Cerner FHIR Developers
Sandip,

It looks like the code is attempting to post to this URL: /dstu2/d075cf8b-3261-481d-97e5-ba6c48d3b41f/DocumentReference?_format=json

It's unusual to have query parameters on a POST url, and the _format parameter is intended to override the Accept header only: http://hl7.org/fhir/dstu2/http.html#mime-type

When writing, the content-type and accept headers should probably be set. We can look into if the server should support the _format parameter on POST, but as long as the headers are set on a POST, this should work.

Note: you shouldn't be building the FHIR URL, just configure the full server URL per client (if the app doesn't support a SMART launch). The FHIR URL may vary by more than that "source id" and the FHIR URL provided during app setup should be treated as opaque. We will be updating our fhir documentation to remove the explanation of the URL setup to help remove confusion about this.

Thanks,
Jenni


On Wednesday, August 24, 2016 at 2:17:25 AM UTC-5, Sandip Dhage wrote:

Jenni Syed

unread,
Aug 30, 2016, 12:01:18 PM8/30/16
to Cerner FHIR Developers
Also, we only support writes against our secure endpoint, and it looks like the code above is attempting to POST against our open endpoint. See this document for more information on how to register an application with our FHIR server in order to use the secure endpoint: http://fhir.cerner.com/dstu2/authorization/

Sandip Dhage

unread,
Aug 30, 2016, 12:31:15 PM8/30/16
to Cerner FHIR Developers

Thanks Jenni for your help & provide more details to understand more. I will check further to use the secure endpoint.
Reply all
Reply to author
Forward
0 new messages