FHIR API to get upcoming Appointments or filter by date range

Hello!

Is there a way to filter on upcoming appointments or use FHIR api to list appointments by selecting a date/time range?

I want to use FHIR or API to get upcoming appointments and also able to filter then over a date range.
Any help appreciated!

This works but for a running production instance of OpenEMR instance with large number of appointments, it will try to return all appointments and could cause performance issues.

import json
import requests
import urllib3
urllib3.disable_warnings()

with open('./new_api_config.json') as ecf:
    client_app = json.load(ecf)

with open('./rpi_openemr.json') as ecf:
    emr_config = json.load(ecf)

ec = {
    "base_url":emr_config['emr_host'],
    "client_name": client_app['client_name'],
    "client_id": client_app['client_id'],
    "client_user": "admin",
    "client_pass": "pass",
    "contact": client_app['contacts'],
    "scope": client_app['scope']
}

session = requests.Session()

session.headers.update({
    'Accept': 'application/json',
    "Content-Type": "application/x-www-form-urlencoded"
})

payload = {
    "client_id": ec['client_id'],
    "grant_type": "password",
    "user_role" : "users",
    "username": ec['client_user'],
    "password": ec['client_pass'],
    "scope": ec['scope']
}

token = session.post(
    url = str('https://' + ec['base_url'] + '/oauth2/default/token'),
    data = payload,
    verify=False
).json()

appointment_url = f"https://{emr_config['emr_host']}/apis/default/fhir/Appointment"

headersList = {
 "Content-Type": "application/json",
 "Authorization": f"Bearer {token['access_token']}"
}

payload = {}

response = requests.request("GET", appointment_url, data=payload, headers=headersList, verify=False)

response.json()


Regards,
Atul

Any recommendations on creating “read-only” database user with permissions for openemr.openemr_postcalendar_events table?

It would be easier to use SQL query with to find appointments for the date or a date range.

Need help with Database schema but couldn’t find documentation about table column names and relationships.

Hi @chaudhariatul Is this a patient app or system client app?

Hi @bmukheja it’s a patient app.

Kindly review my SQL statement

    SELECT
        e.pc_title, 
        e.pc_time,  
        e.pc_eventDate, 
        e.pc_duration, 
        e.pc_startTime, 
        e.pc_endTime, 
        p.title ,
        p.fname,
        p.lname,
        p.phone_home,
        f.street,
        f.city,
        f.state,
        f.postal_code
    FROM openemr_postcalendar_events as e
    INNER JOIN patient_data as p
    INNER JOIN facility as f
    ON e.pc_pid=p.pid AND e.pc_facility=f.id
    WHERE e.pc_eventDate BETWEEN '2024-01-1' AND '2024-01-31';

I’m using pid column from patient_data table to compare with pc_pid column from openemr_postcalendar_events table.

Is there a table that can be used for details of the pc_catid?

pc_catid = {
    2: "In Office",
    5: "Office Visit",
    10: "New Patient",
    13: "Preventive Care Services"
}