5 Using the Package as an API (PRISM)

PRISM (Programmable Interface for Simulation/Statistical Models) is a package which provides a user-friendly API interface in R for clinical prediction and decision analytics models hosted on UBC PRISM cloud.

For more information, the PRISM package can be found on GitHub at PRISM on GitHub.

5.1 PRISM API in Excel

One of the primary goals of PRISM is making prediction models accessible to a wide range of audiences, including those with less programming experience. The Excel API is targetted towards users who are less familiar with programming, or users who are familiar with programming and would like an easy way to extract the data quickly.

To use the model, you will need to have Excel installed on your computer. Currently, the Excel API only works in Windows (PC), although we are working on developing a version for Mac (OS X) as well.

Downloading the Spreadsheet

To get started, you will need to go to:

PRISM Model Repository.

In the row that has the ACCEPT model, go to the column labelled Excel Interface and click on the link ACCEPT Excel (PC). This will download the Excel Interface for the ACCEPT model.

Setting the Inputs

Once you have downloaded the Excel Interface, you can open it in Excel. You will notice there are two sheets, labelled Model and Settings. Click on the Model tab.

You will notice several tables. The top two tables are input tables, which means that these are values you can change. For each package, we will provide details on what values are allowed. For example, Gender can be either Male or Female.

Plot Options

The first table is Plot Options. You may change these if you like, or leave the default values:


Patient Characteristics

The second table applies to the patient. You can use the default patient inputs, or change them:


Running the Model

To run the model, you need to connect to the model first.

  1. Click on the Output - Main Outcomes sheet.
  2. There is a button at the top of the page which says Connect to Model. Click on that button. On the bottom left of the Excel window, you should see the text “Connecting to model…”
  3. Click on the Run button.
  4. Click on the Disconnect from Model button once it has finished running.

Results

Once you have run the model, there are several graphs which will be plotted in the same sheet to visualize the results.

5.2 API in R/Javascript/Python/Bash

To get started, you will need to install a few packages:

brew install curl sudo apt install curl
install.packages("devtools")
devtools::install_github("resplab/prism")
pip3 install requests

The next step is to get an API key. For now, we will be giving out API keys on a case-by-case basis, so please email either:

Amin Adibi:

Mohsen Sadatsafavi:

Setting the Input

To run the model, you can either use the default input, or set your own input. To see what the default input is, you can use the following POST call:

curl -X POST -H "Content-Type: application/json" -d '{"api_key":["YOUR_API_KEY"],"func":["get_default_input"]}'
http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json
curl -X POST -H "Content-Type: application/json" -d '{"api_key":["YOUR_API_KEY"],"func":["get_default_input"]}'
http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json

let arguments = JSON.stringify({
api_key: 'YOUR_API_KEY',
func: ["get_default_input"]
});

request = new XMLHttpRequest();
request.open('POST', 'http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json');
request.setRequestHeader('Content-Type', 'application/json');
request.send(arguments);
let results = request.response;
library(prism)
connect_to_model('acceptPrism', api_key = YOUR_API_KEY)
input = get_default_input()
import json
import requests
api_key = 'YOUR_API_KEY'
response = requests.post("http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json",
json = {"api_key":[api_key],
"func": ["get_default_input"]})
print(response)
results = json.loads(response.text)
print(results)

Running the Model

To run the model with the default input, you can use the following POST call:

curl -X POST -H "Content-Type: application/json" -d '{"api_key":["YOUR_API_KEY"],"func":["prism_model_run"],
"model_input":[{}]}' http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json
curl -X POST -H "Content-Type: application/json" -d '{"api_key":["YOUR_API_KEY"],"func":["prism_model_run"],
"model_input":[{}]}' http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json

}]}' http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json
curl -Body '{"api_key":["YOUR_API_KEY"],"func":["prism_model_run"],"model_input":[{}]}' -Method POST -uri http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json -Headers @{"Content-type"="application/json"}
let postData = JSON.stringify({
"api_key": "YOUR_API_KEY",
"func": ["prism_model_run"],
"model_input": [{}]
});
request.open('POST', 'http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json');
request.setRequestHeader('Content-Type', 'application/json');
request.send(postData);
let results = request.response;
library(prism)
connect_to_model('acceptPrism', api_key = YOUR_API_KEY)
results = model_run()
api_key = 'YOUR_API_KEY'
modelInput = [{}]
response = requests.post("http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json",
json = {"api_key":[api_key],
"func": ["prism_model_run"],
"model_input": modelInput})
print(response)
results = json.loads(response.text)
print(results)

To set your own input:

curl -X POST -H "Content-Type: application/json" -d '{
"api_key":["YOUR_API_KEY"],
"func":["prism_model_run"],
"model_input": {
"patient_data": {
"ID": "10001",
"male": 1,
"age": 70,
"smoker": 1,
"oxygen": 1,
"statin": 1,
"LAMA": 1,
"LABA": 1,
"ICS": 1,
"FEV1": 33,
"BMI": 25,
"SGRQ": 50,
"LastYrExacCount": 2,
"LastYrSevExacCount": 1,
"randomized_azithromycin": 0,
"randomized_statin": 0,
"randomized_LAMA": 0,
"randomized_LABA": 0,
"randomized_ICS": 0
},
"random_sampling_N": 1000,
"calculate_CIs": true,
"random_distribution_iteration": 20000}}' http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json
curl -X POST -H "Content-Type: application/json" -d '{
"api_key":["YOUR_API_KEY"],
"func":["prism_model_run"],
"model_input": {
"patient_data": {
"ID": "10001",
"male": 1,
"age": 70,
"smoker": 1,
"oxygen": 1,
"statin": 1,
"LAMA": 1,
"LABA": 1,
"ICS": 1,
"FEV1": 33,
"BMI": 25,
"SGRQ": 50,
"LastYrExacCount": 2,
"LastYrSevExacCount": 1,
"randomized_azithromycin": 0,
"randomized_statin": 0,
"randomized_LAMA": 0,
"randomized_LABA": 0,
"randomized_ICS": 0
},
"random_sampling_N": 1000,
"calculate_CIs": true,
"random_distribution_iteration": 20000}}' http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json
curl -Body '{
"api_key":["YOUR_API_KEY"],
"func":["prism_model_run"],
"model_input": {
"patient_data": {
"ID": "10001",
"male": 1,
"age": 70,
"smoker": 1,
"oxygen": 1,
"statin": 1,
"LAMA": 1,
"LABA": 1,
"ICS": 1,
"FEV1": 33,
"BMI": 25,
"SGRQ": 50,
"LastYrExacCount": 2,
"LastYrSevExacCount": 1,
"randomized_azithromycin": 0,
"randomized_statin": 0,
"randomized_LAMA": 0,
"randomized_LABA": 0,
"randomized_ICS": 0
},
"random_sampling_N": 1000,
"calculate_CIs": true,
"random_distribution_iteration": 20000}}' -Method POST -uri http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json -Headers @{"Content-type"="application/json"}
let postData = JSON.stringify({
"api_key":["YOUR_API_KEY"],
"func":["prism_model_run"],
"model_input": {
"patient_data": {
"ID": "10001",
"male": 1,
"age": 70,
"smoker": 1,
"oxygen": 1,
"statin": 1,
"LAMA": 1,
"LABA": 1,
"ICS": 1,
"FEV1": 33,
"BMI": 25,
"SGRQ": 50,
"LastYrExacCount": 2,
"LastYrSevExacCount": 1,
"randomized_azithromycin": 0,
"randomized_statin": 0,
"randomized_LAMA": 0,
"randomized_LABA": 0,
"randomized_ICS": 0
},
"random_sampling_N": 1000,
"calculate_CIs": true,
"random_distribution_iteration": 20000}});
request.open('POST', 'http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json');
request.setRequestHeader('Content-Type', 'application/json');
request.send(postData);
let results = request.response;
library(prism)
connect_to_model('acceptPrism', api_key = YOUR_API_KEY)
model_input = list(patient_data = samplePatients)
model_input$random_sampling_N = 1000
model_input$random_distribution_iteration = 20000
model_input$calculate_CIs = TRUE
model_run(model_input)
results = model_run(model_input)
api_key = 'YOUR_API_KEY'
modelInput = {
"patient_data": {
"ID": "10001",
"male": 1,
"age": 70,
"smoker": 1,
"oxygen": 1,
"statin": 1,
"LAMA": 1,
"LABA": 1,
"ICS": 1,
"FEV1": 33,
"BMI": 25,
"SGRQ": 50,
"LastYrExacCount": 2,
"LastYrSevExacCount": 1,
"randomized_azithromycin": 0,
"randomized_statin": 0,
"randomized_LAMA": 0,
"randomized_LABA": 0,
"randomized_ICS": 0
},
"random_sampling_N": 1000,
"calculate_CIs": True,
"random_distribution_iteration": 20000
}
response = requests.post("http://prism.resp.core.ubc.ca/ocpu/library/acceptPrism/R/gateway/json",
json = {"api_key":[api_key],
"func": ["prism_model_run"],
"model_input": modelInput})
print(response)
results = json.loads(response.text)
print(results)