guideexamples.pathway.simple_cli

This Example demonstrates interaction with the Pathway, Patient, Care Team, and Worklist APIs.

The CLI utilizes the requests library to make HTTP requests to the Carium API.

The CLI is organized into classes for each API, with a main class to run the CLI.

Main functionality demonstrated includes:

Functionality

Description

Login to the Carium API

Authenticates the user to the Carium API.

Get organization ID

Retrieves and displays the organization ID.

Show pathways

Displays information about available pathways.

Enroll patient

Enrolls a patient in a pathway.

Show patients

Displays information about patients.

Show care team

Displays information about the care team.

Show worklist

Displays information about the worklist.

Complete worklist

Marks the worklist item as completed.

Update worklist

Updates worklist details (due date, assignment to care team, completion).

To run the CLI, execute the following command:

# run the CLI
python guideexamples/pathway/simple_cli.py

Functions

main()

Main function to run the Simple CLI

Classes

Api(cli)

A class to wrap python requests method to include Carium API headers.

CareTeam(cli)

A class to interact with the Care Team API

Organization(cli)

A class to interact with the Organization API

Pathway(cli)

A class to interact with the Pathway API

Patient(cli)

A class to interact with the Patient API

SimpleCli()

A simple CLI to interact with the Carium API

Worklist(cli)

A class to interact with the Worklist API

class Api(cli: SimpleCli)[source]

A class to wrap python requests method to include Carium API headers. It also includes a method to login to the API

Parameters:

cli (SimpleCli) –

get(url: str, params: dict) Response[source]

Make a GET request to the API

Parameters:
  • url (str) – str: http url for the GET API

  • params (dict) – dict: query parameters for the GET API

Returns:

The response from the GET request

Return type:

Response

list_with_paging(url: str, params: dict, limit: int | None = None) Generator[list[dict], None, None][source]

Get data from the API with paging, prompt the user to page more data if available

Parameters:
  • url (str) – str: http url for the GET API

  • params (dict) – dict: query parameters for the GET API

  • limit (int | None) – Optional[int]: maxium number of records to return in a single request

Returns:

A generator of list of dict results from the GET API

Return type:

Generator[list[dict], None, None]

login()[source]

Login to the Carium API

Raises: RuntimeError: If the login fails

patch(url: str, json: dict) Response[source]

Make a PATCH request to the API

Parameters:
  • url (str) – str: http url for the PATCH API

  • json (dict) – dict: request body for the PATCH API

Returns:

The response from the PATCH request

Return type:

Response

post(url: str, json: dict) Response[source]

Make a POST request to the API

Parameters:
  • url (str) – str: http url for the POST API

  • json (dict) – dict: request body for the POST API

Returns:

The response from the POST request.

Return type:

Response

class CareTeam(cli: SimpleCli)[source]

A class to interact with the Care Team API

Parameters:

cli (SimpleCli) –

classmethod menu() str[source]

Print the care team menu and return the user’s choice

Returns:

The user’s choice

Return type:

str

run()[source]

Show the care team menu

show_care_team()[source]

Show the care team in the organization

Displays the care team ID and name.

class Organization(cli: SimpleCli)[source]

A class to interact with the Organization API

Parameters:

cli (SimpleCli) –

get_organization_id() str[source]

Get the organization ID from the user, by asking for the organization name (prefix)

Returns:

The organization ID

Return type:

str

class Pathway(cli: SimpleCli)[source]

A class to interact with the Pathway API

Parameters:

cli (SimpleCli) –

enroll_patient()[source]

Enroll a patient in a pathway

Steps:
  1. Prompt the user for the pathway version ID.

  2. Get the stages for the pathway version.

  3. Prompt the user to choose a stage to enroll the patient.

  4. Enroll the patient in the chosen stage

classmethod menu() str[source]

Print the pathway menu and return the user’s choice

Returns:

The user’s choice

Return type:

str

run()[source]

Prompt the user for the patient ID and show the pathway menu

show_pathways()[source]

Show the pathways available in the organization, or optionally filter by patient ID

Displays the pathway ID, name, description, version, and version ID.

class Patient(cli: SimpleCli)[source]

A class to interact with the Patient API

Parameters:

cli (SimpleCli) –

classmethod menu() str[source]

Print the patient menu and return the user’s choice

Returns:

The user’s choice

Return type:

str

run()[source]

Show the patient menu

show_patients()[source]

Show the patients in the organization

Displays the patient ID, first name, last name, and email.

class SimpleCli[source]

A simple CLI to interact with the Carium API

classmethod create_table(fields: list[str]) PrettyTable[source]

Create a table with the given fields, will append an ‘Index’ to column field headers

Parameters:

fields (list[str]) – list[str]: List of column names for the table

Returns:

An instance of the PrettyTable class.

Return type:

PrettyTable

classmethod menu() str[source]

Print the main menu and return the user’s choice

Return type:

str

classmethod print_table(table: PrettyTable, data: Generator[list[dict], None, None], data_fields: list[str], mapper: Callable)[source]

Print the table with the data, using the mapper to map the data to the fields

Parameters:
  • table (PrettyTable) – PrettyTable: table with the column headers

  • data (Generator[list[dict], None, None]) – Generator[list[dict], None, None]: List of dict results from the GET API

  • data_fields (list[str]) – list[str]: response attribute names in the same order as the create_table fields

  • mapper (Callable) – Callable: function to map the API response data to the fields

run()[source]

Run the main loop of the CLI

class Worklist(cli: SimpleCli)[source]

A class to interact with the Worklist API

Parameters:

cli (SimpleCli) –

assign_to_care_team(worklist_id: str)[source]

Assign a worklist entry to a care team

Steps:
  1. Prompt the user for the care team ID

  2. Assign the worklist entry to the care team

Parameters:

worklist_id (str) – str: worklist ID to update

complete_worklist()[source]

Complete a worklist entry

Steps:
  1. Prompt the user for the worklist ID to complete

  2. Mark the worklist as completed

classmethod menu() str[source]

Print the worklist menu and return the user’s choice

Return type:

str

run()[source]

Show the worklist menu

show_worklist()[source]

Show the worklist in the organization

Displays the worklist ID, text, created-at, done, care-team, care-team-id, assigned-at, and due-time.

update_due_time(worklist_id: str)[source]

Update the due date of a worklist entry

Steps:
  1. Prompt the user for the due date

  2. Update the due date of the worklist entry

Parameters:

worklist_id (str) – str: worklist ID to update

update_worklist()[source]

Update a worklist entry

Steps:
  1. Prompt the user for the worklist ID to update

  2. Show the update worklist menu

classmethod validate_date_format(date_string: str) bool[source]

Validate the date format

Parameters:

date_string (str) – str: datetime string to validate

Returns:

True if the date string is in the correct format, False otherwise

Return type:

bool

main()[source]

Main function to run the Simple CLI