Originally posted here on the Oracle/Cerner forum, but it's been a week with no answers and I'm stuck and hoping someone here will see the problem. It's not specific to Cerner as FHIR is a bigger healthcare standard.
I have a system app with C#, using the Cerner server that requires authentication and it works great for reading and getting data. Now, I'm trying to add a document to a patient. I'm sure there is something simple that I'm doing wrong and appreciate any help.
Here's the request uri:
AbsoluteUri: "https://fhir-ehr-code.cerner.com/r4/ec2458f2-1e24-41c8-b71b-0e701af7583d/DocumentReference"
I get a fresh access token right before trying to save the file. These are my requested scopes:
request.AddParameter("scope", "system/Patient.read system/Patient.write system/DiagnosticReport.read system/DiagnosticReport.write system/Binary.read system/Binary.write system/Condition.read system/Encounter.read system/Encounter.write system/Location.read system/DocumentReference.read system/DocumentReference.write");
I copied the JSON below from Cerner's R4 example here and replaced a couple things like using a valid patient id and encounter id:
Here's my relevant code.
using HttpClient client = _httpClientFactory.CreateClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
client.DefaultRequestHeaders.Add("Accept", "application/fhir+json");
client.DefaultRequestHeaders.Add("Prefer", "respond-async");
Uri uri = new Uri($"{_fhirSettings.FHIRServer}{_fhirSettings.ServerId}/DocumentReference");
string jsonPayload = @"{
""resourceType"": ""DocumentReference"",
""status"": ""current"",
""docStatus"": ""final"",
""type"": {
""coding"": [
{
""system"": ""https://fhir.cerner.com/ec2458f2-1e24-41c8-b71b-0e701af7583d/codeSet/72"",
""code"": ""2820507"",
""display"": ""Admission Note Physician"",
""userSelected"": true
}
],
""text"": ""Summary document""
},
""subject"": {
""reference"": ""Patient/12742418""
},
""content"": [
{
""attachment"": {
""contentType"": ""application/xml;charset=utf-8"",
""data"": ""PGh0bWw+Cjx0aXRsZT4gVGVzdCBEb2N1bWVudCA8L3RpdGxlPgoKRG9jdW1lbnQgY29udGVudCEKCjwvaHRtbD4="",
""title"": ""Height Weight Allergy Rule"",
""creation"": ""2024-01-29T21:02:04.000Z""
}
}
],
""context"": {
""encounter"": [
{
""reference"": ""Encounter/98001628""
}
],
""period"": {
""start"": ""2023-10-20T13:45:00.000Z"",
""end"": ""2023-10-21T13:45:00.000Z""
}
}
}";
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(uri, content).Result;
Any help is appreciated.
The possible scopes that your access token could have are determined by the permitted scopes for your app in your app registration. Since you are requesting a certain set of scopes but not getting all of those from the token call, that's a sign that your app registration needs to be updated to include all the desired scopes.
You should log into the Cerner Code Console and go to My Applications. Open the applicable app and in the API Access section, verify you have all the needed scopes checked (or check the boxes if there are ones that need to be enabled). Not sure if there's a delay in the change rolling out to the sandbox, so you may want to wait a few hours if the change doesn't take effect quickly.