DSTU2

43 views
Skip to first unread message

Abu Huraira

unread,
Jul 16, 2021, 2:35:17 AM7/16/21
to FHIR DOTNET
Hi!
FhirXmlSerializer serilizer = new FhirXmlSerializer()
serilizer.SerializeToBytes(practitioner)           //this converts the Resource to bytes


 FhirXmlParser xmlParser = new FhirXmlParser();
            xmlParser.Parse(bytesArr);             //but this method require Base object
How can I get Resource back from bytes array in DSTU2.
Other Question is.


DocumentReference document = new DocumentReference();
            
            document.Subject = new ResourceReference();
            document.Subject.Reference = $"Patient/{res.patient}";
            document.Type = new CodeableConcept();
            document.Type.Coding = new List<Coding>();
            document.Type.Coding.Add(new Coding()
            {
                System = "http://loinc.org",
                Code = "11488-4",
            });
            document.Author = new List<ResourceReference>();
            document.Author.Add(new ResourceReference()
            {
                Reference = $"Practitioner/{res.user}",
            });
            document.Indexed = DateTimeOffset.Now;
            document.Content = new List<DocumentReference.ContentComponent>();
            document.Content.Add(new DocumentReference.ContentComponent()
            {
                Attachment = new Attachment()
                {
                    ContentType = "application/xhtml+xml;charset=utf-8",
                   Data = data,
                   Title="Summary Notes",
                   Creation= "2020-01-15T14:35:29.000Z",
                }
            });
            document.Context = new DocumentReference.ContextComponent();
            document.Context.Encounter = new ResourceReference();
            document.Context.Encounter.Reference = $"Encounter/{res.encounter}";
            document.Context.Period = new Period();
            document.Context.Period.Start = "2021-07-01T00:00:00.000Z";
            document.Context.Period.End = "2021-07-15T01:00:00.000Z";
            
            document.Status = DocumentReferenceStatus.Current;
            
            document.DocStatus = new CodeableConcept();
            document.DocStatus.Text ="final";

 var responce = fhirClient.Create<DocumentReference>(document);

i am creating DocumentReference but this gives me the 400 bad request Exception.
What I am missing?


REGARDS

Mirjam Baltus

unread,
Jul 16, 2021, 11:49:33 AM7/16/21
to FHIR DOTNET
You have to convert your bytes to a string first, so you can use the parser to parse it. For example:
```
  xmlParser.Parse(System.Text.Encoding.UTF8.GetString(bytesArr));
```
After that you can check the TypeName of the object to see which resource type it is, and cast your object to that if you want. Or, if you already know the resource type before you parse, add the resource type to the Parse method, resulting in an object of that type instead of Base:
```
  xmlParser.Parse<Practitioner>(System.Text.Encoding.UTF8.GetString(bytesArr));
```

For your second question, you will have to inspect the OperationOutcome details that the server has sent back. This should list why the request was not correct.

Op vrijdag 16 juli 2021 om 08:35:17 UTC+2 schreef abouhur...@gmail.com:

Abu Huraira

unread,
Jul 16, 2021, 12:57:08 PM7/16/21
to FHIR DOTNET
Hi Mirjam,
Thanks for your response.

We're evaluating firely .NET SDK for one of our project and currently facing some issues with DocumentReference. Do you have any code snippets to share with us? We're using cerner sandbox just so if it's helpful. 

Request from Postman works as expected

Mirjam Baltus

unread,
Jul 16, 2021, 1:19:27 PM7/16/21
to FHIR DOTNET
Your code works if I use for example http://hapi.fhir.org/baseDstu2 as the endpoint. So I would assume it is something that the Cerner service does not allow or finds wrong/incomplete with the request. Please look at the OperationOutcome for the details of why the request failed. If you do not understand what the error is, please post the text here so we can take a look.

Op vrijdag 16 juli 2021 om 18:57:08 UTC+2 schreef abouhur...@gmail.com:
Reply all
Reply to author
Forward
0 new messages