proknow.CustomMetrics

CustomMetrics

class proknow.CustomMetrics.CustomMetrics(proknow, requestor)

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

create(name, context, type)

Creates a new custom metric.

Parameters:
  • name (str) – The custom metric name.

  • context (str) – The custom metric context.

  • type (dict) – The custom metric type.

Returns:

A representation of the created custom metric.

Return type:

proknow.CustomMetrics.CustomMetricItem

Raises:

Example

This example creates three new custom metrics, demonstrating each of the available custom metric types:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
pk.custom_metrics.create('Genetic Type', "patient", {
    "enum": {
        "values": ["Type I", "Type II", "Type III", "Type IV"]
    }
})
pk.custom_metrics.create('Physician Name', "patient", {
    "string": {}
})
pk.custom_metrics.create('Toxicity of Larynx (1-4)', "patient", {
    "number": {}
})
delete(custom_metric_id)

Deletes a custom metric by id.

Parameters:

custom_metric_id (str) – The id of the custom metric to delete.

Raises:

Example

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

from proknow import ProKnow

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

Finds the first custom metric 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 custom metrics. Once it has a cache of custom metrics, it will use that cache until the proknow.CustomMetrics.CustomMetrics.query() method is called to refresh the cache. If you wish to make your code resilient to custom metric changes (i.e., new custom metrics, renamed custom metrics, deleted custom metrics, etc.) while your script is running, you should call the proknow.CustomMetrics.CustomMetrics.query() method before this method. In most use cases, this is not necessary.

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

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

Returns:

A representation of the matching custom metric.

Return type:

proknow.CustomMetrics.CustomMetricItem

Raises:

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

query()

Queries for custom metrics.

Note

This method refreshes the custom metric cache.

Returns:

A list of proknow.CustomMetrics.CustomMetricItem objects, each representing a custom metric in the organization.

Return type:

list

Raises:

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

Example

This example queries the custom metrics and prints the name of each custom metric:

from proknow import ProKnow

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

Resolves a metric by id or name.

Parameters:

custom_metric (str) – The metric id or name.

Returns:

A representation of the resolved custom metric.

Return type:

proknow.CustomMetrics.CustomMetricItem

Raises:
resolve_by_id(custom_metric_id)

Resolves a custom metric id to a custom metric.

Parameters:

custom_metric_id (str) – The custom metric id.

Returns:

A representation of the resolved custom metric.

Return type:

proknow.CustomMetrics.CustomMetricItem

Raises:
resolve_by_name(name)

Resolves a custom metric name to a custom metric in a case insensitive manner.

Parameters:

name (str) – The custom metric name.

Returns:

A representation of the resolved custom metric.

Return type:

proknow.CustomMetrics.CustomMetricItem

Raises:

CustomMetricItem

class proknow.CustomMetrics.CustomMetricItem(custom_metrics, custom_metric)

This class represents a custom metric. It’s instantiated by the proknow.CustomMetrics.CustomMetrics class to represent each of the custom metrics in a query result and a created custom metric.

id

The id of the custom metric (readonly).

Type:

str

data

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

Type:

dict

name

The name of the custom metric.

Type:

str

context

The context of the custom metric.

Type:

str

type

The type of the custom metric (readonly).

Type:

dict

delete()

Deletes the custom metric.

Raises:

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

Example

The following example shows how to find a custom metric by its name and delete it:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
metric = pk.custom_metric.find(name='Type')
metric.delete()
save()

Saves the changes made to a custom metric.

Raises:

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

Example

The following example shows how to find a custom metric by its name, change the name, and save it:

from proknow import ProKnow

pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json")
metric = pk.custom_metric.find(name='Type')
metric.name = "Genetic Type"
metric.save()