knitr::opts_chunk$set(fig.width=6, fig.height = 4) 

medinetparser is a package meant to facilitate analysis of schedules generated by the Medinet Scheduling system, developed by Medical Networks Scandinavia AB, for analysis in R, aiding scheduling and follow up. This project is in no way connected to the developers of Medinet.

Installing the medinetparser Package

Chances are you will already have finished installing the medinetparser package, as you are reading this vignette. But just as a quick recap, this is how you install the package from GitHub.

  1. Install devtools
install.packages('devtools', repos = 'https://cloud.r-project.org/')
  1. Load devtools
library(devtools)
  1. Install medinetparser
install_github('JonasEngstrom/medinetparser', build_vignettes = TRUE)
  1. Load medinetparser
library(medinetparser)

Get Started Using the Medinet Parser

Medinet Parser currently does not support scraping data directly from Medinet, as this would require handling login credentials. Therefore data must first be downloaded manually, by following the subsequent steps.

  1. Go to the Medinet Website.

  2. Log in.

  3. If you work in several departments, you will be prompted to choose one at this point. If not, skip ahead to the next step.

  4. Click Schema.

  5. Make sure Schemavy is set to Vecka vs användare.

  6. Choose the weeks you are interested in analyzing.

  7. Use the web brower’s save command.

  8. Save the page in HTML format. This will be your input file to Medinet Parser.

Loading Schedule in R

To load a Medinet schedule in R, use the function load_tidy_schedule(). It takes a file path as an argument and returns a tibble.

example_schedule <- load_tidy_schedule('./medinetschedule.html')

The tibble can then be used with all the standard tidverse functions.

Data Serving Suggestions

All of the examples below assumes that the tibble example_schedule has been loaded using the load_tidy_schedule() function.

Load Additional Packages for Analysis

library(ggplot2)
library(lubridate)
library(tidyverse)

Tallying Shifts

To quickly get an overview of the distribution of shifts per doctor the tally_shifts()function can be used to return a tally table.

example_schedule %>%
  tally_shifts()

How Many Shifts Does Dr. Karl Johansson Work in March of 2022?

To plot a bar graph essentially showing the same information as the tally table above but on a population level, the plot_shift_type_by_frequency() function can be used. This function is likely more useful on a subset of the data.

example_schedule %>%
  filter(date %within% ('2022-03-01' %--% '2022-03-31'),
         doctor_name == 'Johansson, Karl') %>%
  plot_shift_type_by_frequency() +
  ggtitle('Shift Distribution for Dr. Karl Johansson')

Who Works the Most On-Call?

Use the plot_shifts_per_doctor() function to plot a stacked bar graph of the shift distribution of the different doctors compared to each other. Bars are stacked by type of shift and their length represents the total number of shifts worked by a doctor.

on_call_shifts <- c('Pjour', 'Mjour', 'Bjour')

example_schedule %>%
  filter(shift_type %in% on_call_shifts) %>%
  plot_shifts_per_doctor() +
  ggtitle('On-Call Shifts Per Doctor')

Who Works More Than Average during Weekends?

Use the plot_difference_from_mean() to plot the number of shifts a doctor works as a difference from the mean number of shifts all doctors work. The length of the bars represent the shift number delta between the number of shifts worked by a doctor and the arithmetic mean number of shifts worked by all doctors.

time_off <- c('Ej J', 'Tjl', 'JK', 'Övr', 'FL', 'Utb', 'Rnd')

example_schedule %>%
  filter(wday(date, week_start = 1) %in% c(6,7),
         !(shift_type %in% time_off)) %>%
  plot_difference_from_mean() +
  ggtitle('Difference from Mean Number of Weekend Shifts')

Bonus: What are the First and Last Dates in the Current Schedule?

The function get_min_max_dates() is mainly meant to be used for generating titles in the plotting functions in the package, but could pontentially be used in generating reports et cetera. It is therefore described at the end of this vignette.

example_schedule %>%
  get_min_max_dates()


JonasEngstrom/medinetparser documentation built on April 20, 2024, 12:41 a.m.