Diagnostic Report FHIR API

Hello everyone,

I am using the FHIR API to get the Diagnostic report for a specific patient. When I insert in the openEMR it’s correctly linked to the patient but when I make a GET request in postman of a Diagnostic Report for a specific patient I get a Diagnostic Report linked to another patient. The Diagnostic Report is correct but the subject patient is linked to another patient.
Bellow you have a block of the FHIR Diagnostic Report where the bold ID is the wrong patient uuid.
“subject”: {
“reference”: “Patient/95e5b540”,
“type”: “Patient”

I’m using OpenEMR version 6.1 in Chrome in Windows.

How are you generating the diagnostic report inside OpenEMR? Are you directly inserting this via the database? Through the GUI? To have a wrong subject patient seems very, very odd. What kind of DiagnosticReport are you doing here? Is this a lab report? Or is this a Clinical Notes Diagnostic Report?

Hi @adunsulag, I am inserting via Clinical Notes in the openEMR through the GUI. In the GUI the Diagnostic Report is well linked to the patient but when I get the Diagnostic Report for the same patient it’s not returning the correct one.

That definitely sounds like a bug as we shouldn’t be matching reports to different patients. If you’re not dealing with live data is there any chance you can put a screenshot of a copy of your form_clinical_notes table here as well as a copy of the entire DiagnosticReport FHIR endpoint result that is giving you the mismatched patient? That’d be helpful to try and isolate why this is happening for you.

Also please give me a screenshot after executing the following query for the form table which will show the patient ids for the specific form_clinical_notes table.

                    id AS form_id,
                    ,pid AS form_pid
                    forms WHERE forms.id IN (SELECT DISTINCT form_id FROM form_clinical_notes)
1 Like

Hi @adunsulag, I am demonstrating with Herman Romero. (I covered info from other patients)
Here is a copy of my table form_clinical_notes.

In openEMR I created a clinical note for Herman Romero:

The uuid for Herman that we are getting in get patient is (we deleted some inside parts to show the name and id together):

Then I tried to get that diagreport using his uuid I get zero reports:

When I make a get for all diagnostic reports for all the patients I receive the diagnostic report that is in the Herman Romero page in the OpenEMR linked to other uuid (I have no other clinical note with “Hello World 2” ):

The ID that I get is linked to another patient as you can see in the next picture, we have the response and the patient_data table (red square is the id that I should have in the response):

Also the screenshot of the select that you asked for:

Please feel free to ask for more info if you need anything else to understand this problem.

Thank you for the data screenshots. You can see in that last report posted that the form_pid is going to a patient with the id of 4 but in your form_clinical_notes the pid id is going to 6. I suspect your Herman Romero user is the one with the pid id of 6. What I find odd and concerning is why the forms table (which holds an individual record for each encounter based form linked to a patient) is being linked up to a different patient that has an id of 4.

I’ll try to dig into the clinical notes saving code and see why. I’m surprised the form data is even pulling up for your patient in the GUI. I wonder if the form_pid and encounter id are being transposed somehow. The form_pid in that last screenshot you show should be a 6 which is why its appearing incorrectly in FHIR linked to the wrong patient.

1 Like

Sara, I’ve looked at the code and done some tests on my own and I’m not able to recreate the problem you are having. The form_pid value gets populated from the PHP SESSION using the currently selected patient in the GUI. If you create clinical notes for another test patient do you get the same problem (IE the pid is mismatched in the forms table versus whats in the form_clinical_notes table)?

If not, I’m wondering if you by chance had multiple tabs opened inside OpenEMR and you were editing two patients at the same time? I’m just finding it really odd that there would be a mismatch between the form patient id and the form_clinical_notes patient id.

Edited to fix Sara’s name.

Hello Stephen,

I have done a fresh installation of the openEMR. I inserted one patient and a visit for that patient with a clinic note. Everything works fine for the first one. Then I insert another patient (with all the tabs closed) and a visit with a clinical note.
When I do a GET request in postman for all the Diagnostic Reports I get all of them linked to the first patient.
I inserted a third patient with a visit and clinical note, and it was linked to the second one.
Bellow is the table forms with the result of the select (The same statement as you request previously ).

I don’t know what is happening, but this error keeps happening in my machine. Do you have more suggestions to solve my problem ?

@sjpadgett I know your kneck deep in the CQM stuff but do you think this problem could be a session writing problem on Windows (since the pid comes from $_SESSION)? I’m on linux and not experiencing the problem that Sara is running into. I wonder if you’ve seen anything similar on Windows in saving the clinical notes? You can see in her above screenshot that her second patient’s clinical note is being linked to the first patient, and the third patient’s form is being linked to the 3rd patient. That just seems really odd.

1 Like

Another reason for me to get off windows!:slight_smile: Kidding of course.
I’ll look into but in the meantime recommend @srrg try on Firefox. Chrome keeps messing with cookie management so worth a shot.

1 Like

I can’t recreate either! Followed your test exactly on Chrome except not a new install but a clean database.

As Stephen said, This sounds related to a session issue which we spent considerable time addressing in v6.1.

Is this very repeatable on your system? Sounds like it…

Are you running this in Docker on Windows? Is this a multi-site installation? Have you tried using one of the OpenEMR demo environments OpenEMR Demo to see if you get the same issue? If you get the same result on the demo environment then its something related to your browser. If the problem doesn’t reproduce on the demo then it has to be an issue with the way your local environment is executing. Either way I’d like to make sure we get this resolved as we definitely don’t want patient data being linked up incorrectly to the wrong patients.

@sjpadgett I tried in Firefox and it is still linking the clinical notes to a different/wrong patient.
@adunsulag I am using Xampp in my local machine. I tried the demo and I got the same result (linked clinical notes for wrong patients).

Hi @srrg its strange that we can’t reproduce this problem you are having. I’ll try to dive deeper into this once I’ve finished my current contract for our ONC certification work. At this point you (or someone else) will essentially have to setup a debugger and put a breakpoint in the interface/forms/clinical_notes/save.php file to see why for some reason you are getting the wrong $_SESSION[‘pid’] value from your browser session.

Hi there! Just following up on this post to see if there have been any additional developments/resolutions to this issue. I am running into this same issue with the FHIR Diagnostic Report API in addition to the FHIR Document Reference API.

Similar to the original poster, the clinical notes appear under the correct patient and encounter when viewed in the GUI. However, when attempting to use the FHIR DocumentReference or FHIR DiagnosticReport APIs via Postman to retrieve the relevant note by patient uuid they are not included in the response. Viewing all DocumentReferences/DiagnosticReports reveals that they have a different patient associated with them from the one on the GUI.

For reference, I have been working in the AWS Express Edition of OpenEMR 7.0.0 in Google Chrome on Windows.