Observations of lab results

Hello everybody,
I need to search in Postman for the lab results that I introduce manually in openEMR, it is supposed to appear in the Observation resource.
But when I use http://localhost/openemr/apis/default/fhir/Observation and I only get the information from the Vitals.
How can I obtain lab results and social history from the FHIR API ?

Currently using chrome in windows (may change later) version 6.1 of openEMR.

One question I would ask is if you are doing this with a specific patient (using the patient/Observation.read) context or doing this with a user permission (user/Observation.read). I wonder if part of your problem is that mismatched user id problem you were having on your other forum posts. If you are bound to a single patient (patient/Observation.read) it will remove any Observation results that are not linked up to that patient. If you try using the api as a clinical user (user/Observation.read), do you get different results?

So social history currently pulls back just the smoking cessation value so that should be populated if you are trying to get that result. You can specifically grab social history observations by making a request to
/fhir/Observation?category=social-history

Lab results are returned with the following request:
/fhir/Observation?category=laboratory

You have to have entries in your procedure_report table (meaning the lab result has come back or been manually entered) in order for those observations to be returned. You can see the following query is used to grab lab results (and parse them into FHIR resources):

SELECT
                    porder.order_uuid
                    ,porder.order_provider_id
                    ,porder.order_activity
                    ,porder.order_diagnosis
                    ,porder.order_encounter_id
                    ,porder.order_lab_id
     
                    ,preport.report_date
                    ,preport.procedure_report_id
                    ,preport.report_uuid
                    ,preport.report_notes
       
                    ,presult.procedure_result_id
                    ,presult.result_uuid 
                    ,presult.result_code
                    ,presult.result_text
                    ,presult.result_units
                    ,presult.result_result
                    ,presult.result_range
                    ,presult.result_abnormal
                    ,presult.result_comments
                    ,presult.result_status
     
                    ,order_codes.procedure_name
                    ,order_codes.procedure_code
                    ,order_codes.procedure_type
     
                    ,pcode_types.standard_code

                    ,labs.lab_id
                    ,labs.lab_uuid
                    ,labs.lab_npi
                    ,labs.lab_name
     
                    ,patients.puuid
                    ,patients.pid

                    ,encounters.eid
                    ,encounters.euuid
                    ,encounters.encounter_date

                    ,docs.doc_id
                    ,docs.doc_uuid
                    
                    ,provider.provider_uuid
                    ,provider.provider_id
                    ,provider.provider_fname
                    ,provider.provider_mname
                    ,provider.provider_lname
                    ,provider.provider_npi
                FROM (
                    SELECT
                        date_report AS report_date
                        ,procedure_report_id
                        ,procedure_order_id
                        ,procedure_order_seq
                        ,uuid AS report_uuid
                        ,report_notes
                    FROM
                    procedure_report
                ) preport
                LEFT JOIN (
                    SELECT 
                        procedure_result_id
                         ,procedure_report_id
                         ,uuid AS result_uuid
                        ,result AS result_quantity
                        ,result AS result_string
                        ,result AS result_result
                        ,units AS result_units
                        ,result_status
                        ,result_code
                        ,result_text
                        ,result_data_type
                        ,`range` AS result_range
                        ,`abnormal` AS result_abnormal
                        ,`comments` AS result_comments
                        ,`document_id` AS result_document_id
                    FROM
                        `procedure_result`
                ) presult
                ON 
                    preport.procedure_report_id = presult.procedure_report_id
                LEFT JOIN (
                    SELECT 
                        procedure_order_id
                        ,uuid AS order_uuid
                        ,provider_id AS order_provider_id
                        ,encounter_id AS order_encounter_id
                        ,activity AS order_activity
                        ,order_diagnosis
                        ,lab_id as order_lab_id
                        ,procedure_order_id AS order_id
                        ,patient_id AS order_patient_id
                        ,provider_id
                    FROM
                        procedure_order
                ) porder
                ON 
                    porder.procedure_order_id = preport.procedure_order_id
                LEFT JOIN
                (
                     select
                        encounter AS eid
                        ,uuid AS euuid
                        ,`date` AS encounter_date
                    FROM
                        form_encounter
                ) encounters ON porder.order_encounter_id = encounters.eid
                LEFT JOIN
                    (
                        SELECT
                               ppid AS lab_id
                               ,uuid AS lab_uuid
                               ,npi AS lab_npi
                               ,`name` AS lab_name
                               ,`active` AS lab_active
                        FROM 
                             procedure_providers
                    ) labs
                ON 
                    labs.lab_id = porder.order_lab_id
                LEFT JOIN 
                    (
                        select
                            procedure_order_id
                        ,procedure_order_seq
                        ,procedure_code
                        ,procedure_name
                        -- we exclude the legacy procedure_type and use procedure_order_title
                        ,procedure_order_title AS procedure_type
                        FROM procedure_order_code
                    )
                    order_codes
                ON 
                    order_codes.procedure_order_id = porder.procedure_order_id AND order_codes.procedure_order_seq = preport.procedure_order_seq
                LEFT JOIN (
                    select
                        standard_code,
                        procedure_code AS proc_code
                    FROM procedure_type
                ) pcode_types ON order_codes.procedure_code = pcode_types.proc_code
                LEFT JOIN (
                    select 
                        pid
                        ,uuid AS puuid
                    FROM
                        patient_data
                ) patients
                ON 
                    patients.pid = porder.order_patient_id 
                
                LEFT JOIN (
                    select 
                       id AS doc_id
                       ,uuid AS doc_uuid
                    FROM
                        documents
                ) docs ON presult.result_document_id = docs.doc_id
                LEFT JOIN (
                    SELECT
                        users.uuid AS provider_uuid
                        ,users.id AS provider_id
                        ,users.fname AS provider_fname
                        ,users.mname AS provider_mname
                        ,users.lname AS provider_lname
                        ,users.npi AS provider_npi
                    FROM users
                    WHERE npi IS NOT NULL AND npi != ''
                ) provider ON provider.provider_id = porder.provider_id 

This comes from openemr/ProcedureService.php at 619db1d7d7bf5e6a31e7d0489c068998bc9e9327 · openemr/openemr · GitHub

Wow… what a beautiful query!!!

1 Like