welkin.client

Client.

This module provides a Client object to interface with the Welkin Health API.

Module Contents

Classes

Client

Welkin Health Client.

TimeoutHTTPAdapter

The built-in HTTP Adapter for urllib3.

Attributes

logger

welkin.client.logger
class welkin.client.Client(tenant, instance, api_client, secret_key, timeout=5, total=5, backoff_factor=0.5)

Bases: requests.Session

Welkin Health Client.

Constructs a requests.Session for Welkin Health API requests with authorization, base URL, request timeouts, and request retries.

Parameters:
  • tenant (str) – Name of the organization.

  • instance (str) – Name of the database inside a customer space.

  • api_client (str) – API client name.

  • secret_key (str) – API client secret key.

  • timeout (int, optional) – TimeoutHTTPAdapter timeout value. Defaults to 5.

  • total (int, optional) – Retry total value. Defaults to 5.

  • backoff_factor (float, optional) – Retry backoff_factor value. Defaults to 0.5.

Usage:

from welkin import Client

welkin = Client(
    tenant="gh",
    instance="sb-demo",
    api_client="VBOPNRYRWJIP",
    secret_key="+}B{KGTG6#zG%P;tQm0C",
)


### Patient methods
patient = welkin.Patient(firstName="Foo", lastName="Bar").create()  # Create

patient = welkin.Patient(id="6801d498-26f4-4aee-961b-5daffcf193c8").get()  # Read
patients = welkin.Patients().get()  # Read all/list

patient.update(firstName="Baz")  # Update
patient.delete()  # Delete

### User methods
user = client.User(username="bar", email="bar@foo.com").create()  # Create

user = welkin.User(id="301b2895-cbf0-4cac-b4cf-1d082faee95c").get()  # Read
users = welkin.Users().get()  # Read all/list
uasers = welkin.Users().get(
    search="foo", region="east-coast", seat_assigned=True, user_state="ACTIVE"
)  # Filtered read all/list

user.update(firstName="Baz")  # Update
user.delete()  # Delete
Assessment
AssessmentRecord
AssessmentRecordAnswers
AssessmentRecords
Assessments
CalendarEvent
CalendarEvents
CarePlan
CarePlanOverview
CDT
CDTRecordsExport
CDTs
Chat
Chats
DocumentSummaries
DocumentSummary
DocumentSummaryFile
DocumentSummaryFiles
Email
Emails
Encounter
EncounterDisposition
Encounters
Formation
Patient
PatientProgram
PatientPrograms
Patients
ProgramPhase
ProgramPhases
Schedules
SearchChats
SMS
SMSes
User
Users
WorkHours
prepare_request(request)

Constructs a PreparedRequest for transmission and returns it. The PreparedRequest has settings merged from the Request instance and those of the Session.

Parameters:

requestRequest instance to prepare with this session’s settings.

Return type:

requests.PreparedRequest

request(method: str, path: str, meta_key: str | None = None, meta_dict: dict | None = None, *args, **kwargs)

Override Session request method to add retries and output JSON.

Parameters:
  • method (str) – Method for the new Request object.

  • path (str) – Path from host for the new Request object.

  • meta_key (str | None, optional) – Key for metadata in the response JSON. Defaults to None.

  • meta_dict (dict | None, optional) – Metadata dictionary for the response JSON. Defaults to None.

  • *args – Arguments to pass to Session.request.

  • **kwargs – Keyword arguments to pass to Session.request.

Returns:

Response JSON

Return type:

dict

get_token() dict
class welkin.client.TimeoutHTTPAdapter(timeout, *args, **kwargs)

Bases: requests.adapters.HTTPAdapter

The built-in HTTP Adapter for urllib3.

Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the Session class under the covers.

Parameters:
  • pool_connections – The number of urllib3 connection pools to cache.

  • pool_maxsize – The maximum number of connections to save in the pool.

  • max_retries – The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3’s Retry class and pass that instead.

  • pool_block – Whether the connection pool should block for connections.

Usage:

>>> import requests
>>> s = requests.Session()
>>> a = requests.adapters.HTTPAdapter(max_retries=3)
>>> s.mount('http://', a)
send(request, **kwargs)

Override HTTPAdapter send method to add a default timeout.