Skip to main content

An OpenEMR api connector

Project description

OpenEMR api connector in python

install

pip install openemr

How to use

1. Create oAuth2 client in OpenEMR

The easiest way to create a oAuth2 client in OpenEMR is to use the devtools on the OpenEMR webserver:

apk add jq
cd /root
wget https://raw.githubusercontent.com/openemr/openemr-devops/refs/heads/master/docker/openemr/flex-3.20/utilities/devtools
chmod +x devtools
./devtools register-oauth2-client

This will create a oAuth2 client in OpenEMR and return the client id and client secret.

For reference these are the commands in the devtools script, you can run them manually if you don't have access to the devtools or want to change some of the parameters:

echo "Registering a oauth2 client to site ${site}"
# collect scopes
scopes=`cat /var/www/localhost/htdocs/openemr/docker/library/api-scope-listing`
returnJson=`curl -X POST -k -H 'Content-Type: application/json' -s https://localhost/oauth2/${site}/registration --data "{
    \"application_type\": \"private\",
    \"redirect_uris\":
        [\"https://localhost:9300/swagger/oauth2-redirect.html\"],
    \"client_name\": \"A Private App\",
    \"token_endpoint_auth_method\": \"client_secret_post\",
    \"contacts\": [\"me@example.org\", \"them@example.org\"],
    \"scope\": \"${scopes}\"
    }"`
clientId=`echo $returnJson | jq '.client_id'`
clientSecret=`echo $returnJson | jq '.client_secret'`
echo "client id: ${clientId}"
echo "client secret: ${clientSecret}"

2. Enable the client

You need to enable the client in the OpenEMR web interface.

3. Use the client

The connection to openemr is done by creating a client, there is one this a bit different than the other clients. It requires a username and password, and a client id and client secret. This is to authenticate with the client and authorize as the user.

from openemr import Client as OpenEMRClient

config = {
    'base_url': 'https://localhost',
    'username': 'admin',
    'password': 'password',
    'client_id': 'client_id',
    'client_secret': 'client_secret'
}

def connect_to_openemr(config):
    """Create connection to OpenEMR instance"""
    print("Connecting to OpenEMR instance: ", config['base_url'])

    client = OpenEMRClient(
        username=config.get('username'),
        password=config.get('password'),
        base_url=config['base_url'],
        client_id=config.get('client_id'),
        client_secret=config.get('client_secret'),
    )
    return client

client = connect_to_openemr(config)
patients = client.get_patients()

print(len(patients))

Scopes

The scopes are the permissions that the client has been granted. By default we use the list below, if you want to use different scopes you can pass them as a list to the client constructor.

scopes = [
    "openid",
    "offline_access",
    "api:oemr",
    "api:fhir",
    "api:port",
    "user/appointment.read",
    "user/facility.read",
    "user/patient.read",
    "user/practitioner.read",
    "user/Encounter.read",
    "user/Location.read",
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openemr-0.2.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

openemr-0.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file openemr-0.2.1.tar.gz.

File metadata

  • Download URL: openemr-0.2.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for openemr-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8ec66b61e325d7d67fe148c5f6316ae7d920d102a69cf613886c9123a727c2dc
MD5 ef54c0c9347a58bd881cc1c71856d39d
BLAKE2b-256 febb4c40aa3a9a30efb3dea42fb39543914150ae9046ff0f158eebfe51fbda27

See more details on using hashes here.

File details

Details for the file openemr-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: openemr-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for openemr-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8a17aa7d4da5f955cb7edd76bba9e6aa7e3964a224be29ba269462ec2b54844
MD5 ac3eb84768ea18b8ceb0e9eb7878ad4b
BLAKE2b-256 7d99c22ff3b9da8658f89e728915181e8fa049d6420df6b0d05161ec91befed3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page