Patient Flags Patch Submission

237 views
Skip to first unread message

Jose Holguin-Veras

unread,
Feb 27, 2019, 11:30:20 AM2/27/19
to drchrono Medical Healthcare API SDK
Hi all,

I have a C# application which integrates to the DrChrono API, but I've hit a snag when it comes to Patient Flags. I just can't seem to get anything to add a flag to a patient. I can successfully create a flag via api/patient_flag_types and when I try to use that ID and create a payload to send I get the following:

IsSuccessStatusCode: true
    ReasonPhrase: "No Content"
    RequestMessage: {Method: PATCH, RequestUri: 'https://drchrono.com/api/patients/79500821', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Authorization: Bearer rZcIoejN2YPgFjRETgzCJawDMUV6rT
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 219
}

I understand C# support is limited, and as much as I would love a c# sample code that dealt with the additions of patient flags, I'll access code in any language, so I can figure out what content I need to send.

My biggest questions in trying to resolve this are:

1) whats the difference between Patient_Flags and Patient_Flags_Attached. I see that the ID of Patient_Flag corresponds to the Flag_type of Patient_Flags_Attached which corresponds to the ID of a created Patient_Flag_Type.
2) Do I need to submit two different serialized json objects, one for Patient_flags and another for Patient_Flags_Attached?
3) Since I'm doing Patch to an existing patient record (using URI like: https://drchrono.com/api/patients/79500821) , do I need to include Patient in the payload?

If it helps, here's my current code:

            string url = "https://drchrono.com/api/patients/" + MRN;


            try
            {
                Patient_Flags_Attached AddFlagTypes = new Patient_Flags_Attached(); //obj definition from https://app.drchrono.com/api-docs/popup/v4/patient_flags
                AddFlagTypes.flag_type = EHRFlagTypeID; 
                AddFlagTypes.flag_text = "Patient Flag Test";
                var obj = new JavaScriptSerializer().Serialize(AddFlagTypes);

                Patient_Flag_Types AddFlags = new Patient_Flag_Types(); //obj definition from https://app.drchrono.com/api-docs/popup/v4/patient_flags
                AddFlags.id = EHRFlagTypeID;
                AddFlags.doctor = Convert.ToInt32(MRNProviderRefID);
                AddFlags.priority = 1;
                AddFlags.color = "#71E785";
                var obj2 = new JavaScriptSerializer().Serialize(AddFlags);


                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);

                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StringContent(MRN), "patient");
                content.Add(new StringContent(obj), "patient_flags_attached");
                content.Add(new StringContent(obj2), "patient_flags");

                var response = await client.PatchAsync(url, content);  // Blocking call!

                if (response.IsSuccessStatusCode)
                {
                    var dataObject = response.Content.ReadAsStringAsync().Result;
                }
            }
            catch (Exception)
            {
                throw;
            }

Any help would be much appreciated. As an aside, I've used similar code to create appointments, upload documents, and create the flag types, so I can't quite figure out where I've gone wrong other than the actual content.

Thanks!

-Jose

Denis Malinovskiy

unread,
Feb 27, 2019, 11:31:40 AM2/27/19
to drchro...@googlegroups.com
By the way, I hope your access token is no longer valid, you included it in your code sample.  If it's valid, please revoke it ASAP.

--
You received this message because you are subscribed to the Google Groups "drchrono Medical Healthcare API SDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drchrono-api...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Denis Malinovskiy
Software Engineer, drchrono

Jian Gong

unread,
Feb 27, 2019, 4:32:02 PM2/27/19
to drchrono Medical Healthcare API SDK
Hi Jose,

1) whats the difference between Patient_Flags and Patient_Flags_Attached. I see that the ID of Patient_Flag corresponds to the Flag_type of Patient_Flags_Attached which corresponds to the ID of a created Patient_Flag_Type.
`patient_flags` indicates the options of flags that could be attached to the patient, and `patient_flags_attached` indicates the flags that are attached to the current patient.

2) Do I need to submit two different serialized json objects, one for Patient_flags and another for Patient_Flags_Attached?
`patient_flags` is read-only. When writing to `patient_flags_attached`, you can pass in a list of objects, you can find the format from https://app.drchrono.com/api-docs/popup/v4/patient_flags

3) Since I'm doing Patch to an existing patient record (using URI like: https://drchrono.com/api/patients/79500821) , do I need to include Patient in the payload?
And when you do patch, as you already indicated the patient ID in URL, you can only include desired fields in request body.

Regards,
Jian Gong

On Wed, Feb 27, 2019 at 8:30 AM Jose Holguin-Veras <jholgu...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "drchrono Medical Healthcare API SDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drchrono-api...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Jian Gong
Software Engineer, drchrono

Jose Holguin-Veras

unread,
Feb 28, 2019, 3:05:02 PM2/28/19
to drchro...@googlegroups.com
Hi Jian,

Thank you for your response. I've been trying several more things since my post and your response but it doesn't feel any closer than before.

I did confirm that I can modify the patient (name for example), with a Patch, so at least that confirms that I can access the correct patient, and supply the contents correctly.

I have some follow up questions to help narrow this down:

1) Since patient_flags is read-only, I'll focus on only passing data to patient_flags_attached. The object definition for patient_flags_attached according to the documentation is only 2 fields (flag_text and flag_type). Are these the only two fields we can manipulate through the API? ie what about Priority/Color or are these only a by-product of the parent patient_flag_type?

2) In what format should I submit the patient_flags_attached object? Currently, I'm serializing the json into a string and then adding it to the content I submit for "patient_flags_attached".

var obj = JsonConvert.SerializeObject(AddFlagTypes, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
content.Add(new StringContent(obj), "patient_flags_attached");

Is there some other way I should be submitting it?

If I were to do:

content.Add(new StringContent("Mary Poppins"), "nick_name");

it does work and does correctly update nick_name.

I'm kinda pulling my hair out at how close I am and simultaneously how far away I seem to be.

thanks,

Jose

You received this message because you are subscribed to a topic in the Google Groups "drchrono Medical Healthcare API SDK" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drchrono-api/dIvTXWwcgmI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drchrono-api...@googlegroups.com.

Jian Gong

unread,
Mar 1, 2019, 3:10:59 PM3/1/19
to drchrono Medical Healthcare API SDK
Jose,

1) Since patient_flags is read-only, I'll focus on only passing data to patient_flags_attached. The object definition for patient_flags_attached according to the documentation is only 2 fields (flag_text and flag_type). Are these the only two fields we can manipulate through the API? ie what about Priority/Color or are these only a by-product of the parent patient_flag_type?
You don't need priority/color etc when you attach flags to patients. "Priority" or "color" are attributes of "flag types", and when you attach patient flags, you will only need to indicate which flag you want to add and an additional description of it.

2) In what format should I submit the patient_flags_attached object? Currently, I'm serializing the json into a string and then adding it to the content I submit for "patient_flags_attached".
I think you need to indicate "Content-Type" in your request headers


Jose Holguin-Veras

unread,
Mar 4, 2019, 4:37:37 AM3/4/19
to drchro...@googlegroups.com
Hi Jian,

Thanks again for your help, I've been troubleshooting this over the weekend and I've now found the right way to do this but I have a couple of final questions remaining to wrap this up:

1) When I do PATCH Patient, it overwrites existing flags on the patient instead of adding the new one. Is this intended behavior?
2) How can I remove a flag? There are two scenarios I need clarification on:
A) Patient has a single Patient_flags_attached ID 12345, and I must remove it.
B) Patient has Patient_flags_attached {12345, 67890, 13579} and I must remove 67890. Is there a way to archive it, or should I do PATCH and submit the remaining flags?

For future C# Devs, here's the key additions I made:

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PatchAsync(url, new StringContent(obj, Encoding.UTF8, "application/json"));  // Blocking call!

Originally, I was trying to pass the json stream as the value to "patient_flags_attached" or "data" or "json", but I finally figured out I could just pass the entire Patient object (as json) directly.

thanks in advance!

Jian Gong

unread,
Mar 5, 2019, 1:04:23 PM3/5/19
to drchrono Medical Healthcare API SDK
Hi Jose,

1) When I do PATCH Patient, it overwrites existing flags on the patient instead of adding the new one. Is this intended behavior?
Yes, in a PATCH request, we will remove older ones, and treat the passed in patient flags list as the ones needed.

2) How can I remove a flag? There are two scenarios I need clarification on:
A) Patient has a single Patient_flags_attached ID 12345, and I must remove it.
If this is the only flag, you can do PATCH with `patient_flags_attached` equal to an empty array/list.
B) Patient has Patient_flags_attached {12345, 67890, 13579} and I must remove 67890. Is there a way to archive it, or should I do PATCH and submit the remaining flags?
In this case, you can do PATCH with `patient_flags_attached` equal to list of [`12345`, `13579`].

Jose Holguin-Veras

unread,
Mar 25, 2019, 7:22:58 PM3/25/19
to drchrono Medical Healthcare API SDK
Hi Jian,

sorry to re-open this thread, I thought was done with it. Everything is working but we're getting an error that we did not notice before.

If I submit an empty array for Patient_flags_attached as follows:
"{\"patient_flags_attached\": []}";

It will not work but it will accept my submission. However, if I submit:

"{\"patient_flags_attached\": [{}]}";

It WILL work (all flags are removed), but it will error with the following:

    IsSuccessStatusCode: false
    ReasonPhrase: "Internal Server Error"
    RequestMessage: {Method: PATCH, RequestUri: 'https://drchrono.com/api/patients/(PatientID redacted)', Version: 1.1, Content: System.Net.Http.StringContent, Headers:

Do you have any recommendations? Should the empty string submission be done differently?

I've disabled production use until we identify the issue, so, please let me know if you need any additional info so we can get this resolved.

thanks for your help!

Hemant Patel

unread,
Jul 10, 2019, 5:28:18 PM7/10/19
to drchrono Medical Healthcare API SDK
Hi Denis,
Do you have an example of file upload in c# ?
To unsubscribe from this group and stop receiving emails from it, send an email to drchro...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Hemant Patel

unread,
Jul 10, 2019, 7:17:38 PM7/10/19
to drchrono Medical Healthcare API SDK
Hi Jose
Do you have an example of C# to upload files?

Jose Holguin-Veras

unread,
Jul 11, 2019, 2:23:54 AM7/11/19
to drchrono Medical Healthcare API SDK
Yes, I was able to get it working, here's the relevant code.

            string access_token = DrChrono_Access_Token_get(PracticeID); //retrieve access_token, I assume you already have this method coded.
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            foreach (var obj in Document_List) //this is optional, in my case, I wanted to be able to upload multiple documents at once through a single call of this method.
            { 
                if (!File.Exists(obj.file_path)) { return;}

                try
                {
                    byte[] pdfBytes = File.ReadAllBytes(obj.file_path);
                    HttpClient client = new HttpClient();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);

                    MultipartFormDataContent content = new MultipartFormDataContent();
                    content.Add(new StringContent(DoctorID), "doctor");
                    content.Add(new StringContent(PatientID), "patient");
                    content.Add(new StringContent(obj.file_desc), "description");

                    if (obj.file_data_tags != "") { content.Add(new StringContent(obj.file_data_tags), "metatags"); }//string metatags = "[\"tag1\", \"Tag2\"]"; //sample format for metatags
                    content.Add(new StringContent(Document_Date.ToString("yyyy-MM-dd")), "date");

                    content.Add(new ByteArrayContent(pdfBytes, 0, pdfBytes.Length), "document", Path.GetFileName(obj.file_path));


                    var response = Task.Run(() => client.PostAsync(url, content));
                    response.Wait();

                    if (response.Result.IsSuccessStatusCode)
                    {
                        var dataObject = response.Result.Content.ReadAsStringAsync().Result;

                    }

                }
                catch (Exception)
                {
                    throw;

Hemant Patel

unread,
Jul 11, 2019, 7:56:07 PM7/11/19
to drchrono Medical Healthcare API SDK
Thank Jose! This worked perfectly.

Timothy Gross

unread,
Nov 22, 2022, 10:26:22 AM11/22/22
to DrChrono API Developers
Bumping this one up. Is there a way to append flags vs. overwrite all existing flags when updating?

Jose Holguin-Veras

unread,
Nov 22, 2022, 1:02:18 PM11/22/22
to drchro...@googlegroups.com
It's been a very long time since I worked on this, but based on my recollection, there is no way. I remember having to cache all the flags and add new ones, instead of just appending a new one. It was a bit annoying but at least there's a way to do it via API.

--
You received this message because you are subscribed to a topic in the Google Groups "DrChrono API Developers" group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/drchrono-api/dIvTXWwcgmI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drchrono-api...@googlegroups.com.

Timothy Gross

unread,
Jan 23, 2024, 2:31:24 PM1/23/24
to DrChrono API Developers
Is there an easy way to retrieve all flags on a patient or be notified via webhook when a new flag is added to a patient?
Reply all
Reply to author
Forward
0 new messages