Deploy a tidymodel
In my previous articles, I developed a xgboost-model using tidymodels. This model predicted the time from the beginning of one operation until the beginning of the next operation, patient to patient (p2p). This model serves as a basic for the scheduling of patients in our hand surgery operation center. From October, I scheduled all patients based on the data of the model as shown here:
I have developed the model, therefore it’s easy for me to get the prediction every day. I needed to make the model useable for my colleagues, who are hand surgeons like me, with no knowledge of programming and R. Here is my way.
Vetiver model
The Xgboost model from part4 finalizes with:
boosting_test_results <-
xgb_wf %>%
finalize_workflow(best_results) %>%
last_fit(split = fall_split)
Tune extract-workflow gets the workflow from boosting_test_results.
wz_wf_model <- extract_workflow(boosting_test_results)
Vetiver creates a model
library(vetiver)
v <- vetiver_model(wz_wf_model,"wartezeit")
vetiver_pin_write pins to a model_board(locally)
library(pins)
model_board <- board_folder("../data/")
model_board %>% vetiver_pin_write(v)
RStudio Server
I then installed R and RStudio Server Open Source on an Ubuntu Server in our local hospital environment.
I defined one user with a password for my colleagues. I transferred the model board with the vetiver model to the Ubuntu server.
Quarto-document and workflow
Next, I build a Quarto document (QD) which handled all steps of file-loading, preprocessing, prediction, and output generation. It must predict the p2p time from the daily operation plan
The plan is an excel export from our hospital information system. This file contains the data of the patients, the surgeon and textual information of the operation.
To make the input simple, I use a shiny widget within the QD. The widget captures the file name and the weekday of the operation.
---
title: "planung_wartezeit"
author: "Peter Hahn"
date: "2022-09-22"
output: html_document
params:
tag:
label: "Wochentag"
value: NULL
choices: [Mo,Di,Mi,Do,Fr]
selected: Mi
input: select
data:
label: "OP-Plan auswählen"
value: op-plan.xls
accept: ".xls"
input: file
---
Preparing the excel file
The QD prepares the excel file for prediction of the p2p using the vetiver model.
model_board <- board_folder("../data/")
v1 <- vetiver_pin_read(model_board, "wartezeit")
The QD then adds the p2p times at the associated rows and writes the file to the server.
Using the export function of RStudio, we save the file locally for further revision and distribution.
The Quarto document controls the entire process. It limits the user interaction to knit with parameters and filling the widgets.
Conclusion
By the combination of Studio Server and a Quarto document, I established a working environment, which my surgical collaborators can use without special knowledge.
The steps are:
- Login to the server
- Knit with parameters
- Export the resulting excel
- Change the excel locally
Results
We used the p2p time to schedule all patients from the beginning of October 2022. As a result, we reduced the time from appearance in the hospital until the beginning of the operation (waiting time). The median of the time decreased from 130 minutes to 100 minutes.