proknow.Workspaces

Workspaces

class proknow.Workspaces.Workspaces(proknow, requestor)

This class should be used to interact with the workspaces in a ProKnow organization. It is instantiated for you as an attribute of the proknow.ProKnow.ProKnow class.

create(slug, name, protected=True)

Creates a new workspace.

Parameters:
  • slug (str) – The workspace slug. A string with a maximum length of 40 that matches the regular expression ^[a-z0-9][a-z0-9]*(-[a-z0-9]+)*$.

  • name (str) – The workspace name. A string with a maximum length of 80.

  • protected (bool, optional) – Indicates whether the workspace should be protected from accidental deletion.

Returns:

A representation of the created workspace.

Return type:

proknow.Workspaces.WorkspaceItem

Raises:

Example

This example creates a new workspace with the slug “research” and the name “Research”. The protected argument is not provided, so it will default to True:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
pk.workspaces.create('research', 'Research')
delete(workspace_id)

Deletes a workspace.

Parameters:

workspace_id (str) – The id of the workspace to delete.

Raises:

Example

If you know the workspace id, you can delete the workspace directly using this method:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
pk.workspaces.delete('5c463a6c040040f1efda74db75c1b121')
find(predicate=None, **props)

Finds the first workspace that matches the input paramters.

Note

For more information on how to use this method, see Using Find Methods.

Note

This method utilizes a cache of workspaces. Once it has a cache of workspaces, it will use that cache until the proknow.Workspaces.Workspaces.query() method is called to refresh the cache. If you wish to make your code resilient to workspaces changes (i.e., new workspaces, renamed workspaces, deleted workspaces, etc.) while your script is running, you should call the proknow.Workspaces.Workspaces.query() method before this method. In most use cases, this is not necessary.

Parameters:
  • predicate (func) – A function that is passed a workspace as input and which should return a bool indicating whether the workspace is a match.

  • **props – A dictionary of keyword arguments that may include any workspace attribute. These arguments are considered in turn to find matching workspaces.

Returns:

A representation of the matching workspace.

Return type:

proknow.Workspaces.WorkspaceItem

Raises:

proknow.Exceptions.HttpError – If the HTTP request generated an error.

query()

Queries for workspaces.

Note

This method refreshes the workspaces cache.

Returns:

A list of proknow.Workspaces.WorkspaceItem objects, each representing a workspace in the organization.

Return type:

list

Raises:

proknow.Exceptions.HttpError – If the HTTP request generated an error.

Example

This example queries the workspaces and prints the name of each workspace:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
for workspace in pk.workspaces.query():
    print(workspace.name)
resolve(workspace)

Resolves a workspace by id or name.

Parameters:

workspace (str) – The workspace id or name.

Returns:

A representation of the resolved workspace.

Return type:

proknow.Workspaces.WorkspaceItem

Raises:
resolve_by_id(workspace_id)

Resolves a workspace id to a workspace.

Parameters:

workspace_id (str) – The workspace id.

Returns:

A representation of the resolved workspace.

Return type:

proknow.Workspaces.WorkspaceItem

Raises:
resolve_by_name(name)

Resolves a workspace name to a workspace in a case insensitive manner.

Parameters:

name (str) – The workspace name.

Returns:

A representation of the resolved workspace.

Return type:

proknow.Workspaces.WorkspaceItem

Raises:

WorkspaceItem

class proknow.Workspaces.WorkspaceItem(workspaces, workspace)

This class represents a workspace. It’s instantiated by the proknow.Workspaces.Workspaces class to represent each of the workspaces in a query result and a created workspace.

id

The id of the workspace (readonly).

Type:

str

data

The complete representation of the workspace as returned from the API (readonly).

Type:

dict

slug

The workspace slug. A string with a maximum length of 40 that matches the regular expression ^[a-z0-9][a-z0-9]*(-[a-z0-9]+)*$.

Type:

str

name

The workspace name. A string with a maximum length of 80.

Type:

str

protected

Indicates whether the workspace should be protected from accidental deletion.

Type:

bool

delete()

Deletes the workspace.

Raises:

proknow.Exceptions.HttpError – If the HTTP request generated an error.

Example

The following example shows how to find a workspace by its slug and delete it:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
research = pk.workspaces.find(slug='research')
research.delete()
save()

Saves the changes made to a workspace.

Raises:

proknow.Exceptions.HttpError – If the HTTP request generated an error.

Example

The following example shows how to find a workspace by its slug, modify the name, and save it:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
clinical = pk.workspaces.find(slug='clinical')
clinical.name = "Clinical Patients"
clinical.save()
update_entities(update, entities)

Updates common entity information for a set of entities.

Parameters:
Raises:
  • AttributeError – If a provided object is not an entity-like object.

  • proknow.Exceptions.HttpError – If the HTTP request generated an error.

Example

This example show how to update the frame of reference for a list of entities:

from proknow import ProKnow
pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
workspace = pk.workspaces.resolve('Clinical')
patients = pk.patients.lookup('Clinical', ['HNC-0522c0009'])
workspace.update_entities({
    "frame_of_referance": "1.3.6.1.4.1.22213.2.26558.1"
}, patient.find_entities(lambda entity: True))