you are at bobd.tech

Crunching Hospital wait times with AI in 15 minutes

Also published on: medium.com

A year and a half ago I wrote a little scraper to pull the local children’s hospital (CHEO) wait times. We were visiting somewhat frequently, and the wait times seemed all over the place… and they had an API!

This short piece discusses my foray into automatically collecting and storing the data, and using AI to analyze it. I am not a data scientist nor do I have any experience in health care, I’m just throwing up what I’ve found as a guy who would prefer his family and friends spend less time in waiting rooms.

In 2022 I did a twitter post after a month of collecting data with my findings, and it was modestly interesting. Nothing earth shattering was uncovered, it basically confirmed our suspicions; if you have any flexibility at all, go first thing in the morning.

It was a little serverless app. And as any conscientious developer does when they deploy something, I forgot about it and left it there to run forever. Having visited that hospital again recently and seen some mega (15+ hours) wait times, I thought I’d see if it was still cooking… it has been! And even more surprisingly, the api has not changed, and I now have a year and a half of data.

And you know what else? AI is insane now. Lets see what we can do.

I started by walking my default tracks, I generated a graph in Google Sheets that took me a little less than 10 minutes to create manually:

A Google Sheets produced graph of Hospital wait times.

Analyzing this, wait times have not become fundamentally worse but haven’t gotten much better either.

I fed that graph to ChatGPT and it told me this (feel free to skip reading it when your eyes start glossing over);

The graph you’ve provided plots three different data sets over a year and a half period, showing the average number of patients waiting, the average longest wait time, and the average wait time at a children’s hospital. Here are the top 5 insights that can be inferred from this data:

1. **Variability and Trends**: All three metrics show variability over time, with some peaks and troughs. This could indicate that there are fluctuations in demand or service availability, which could be due to seasonal factors, epidemics, or other external events.

2. **Correlation Between Wait Times and Patients Waiting**: There appears to be a correlation between the number of patients waiting and the wait times. Generally, as the number of patients increases, the wait times also tend to increase. This suggests that the hospital’s capacity may influence wait times.

3. **Distinct Patterns**: Each metric appears to have its own distinct pattern. The average number of patients waiting seems less volatile than the wait times, indicating that while the number of patients can be relatively stable, their wait times can vary more significantly.

4. **Periods of High Demand**: There are points where all three metrics peak, suggesting periods of high demand or strain on the hospital. This might be an area for the hospital to investigate further to understand what causes these peaks and how to better manage them.

5. **Comparison of Average and Longest Wait Times**: The longest wait times are consistently higher than the average wait times, which is expected. However, the gap between these metrics can indicate how well the outliers (those waiting the longest) are being managed. In some parts of the graph where the longest wait time spikes significantly away from the average, it shows that a few patients are waiting a lot longer than most others.

To provide more detailed insights, statistical analysis could be done to measure correlations, identify the average growth rates or decline rates, seasonal patterns, and perhaps day of the week effects if the data is granular enough. It would also be helpful to understand the context behind any interventions or policy changes made by the hospital during this period, which could explain some of the fluctuations seen in the graph.

Cool, but not mind blowing.

Then a very in the know friend of mine suggested using Code Interpreter, a feature of OpenAI’s assistant. I logged in to the Assistant, enabled Code Interpreter, uploaded the 4.2MB file and about 5 minutes later, had a few nice graphs with some detailed explanations.

A screenshot from OpenAI assistant with graphs of hospital wait times and analysis of findings.

I wouldn’t have even thought about doing that correlation chart, cool! And looking at the data points separate makes a ton more sense.

What else can I do? The obvious next questions in my head are how does this look by week days, and how does this look by hours of the day?

I’ve always been “just ok” at spreadsheets. In a pinch, I can do a pivot chart to extract some stuff. And I think I’d need one for that… luckily, I no longer need to work on that skill, possibly ever again!!!

An OpenAI assistant produced screenshot of the hospital wait times by hour of day.

An OpenAI assistant produced screenshot of wait times by days of week.

Amazing. The main thing that jumps out is how overnight the wait times rise like crazy even though the patient count ramps down, and then everything recovers when the work day begins.

I want more though. Ask for by month, no problem.

An OpenAI assistant produced screenshot by month of year.

Super interesting — things peak in May and October, almost double of August.

Then I asked what it could do to help me understand things based on day of week and hour of day.

An OpenAI assistant produced screenshot of wait time data by day of week and hour of day.

And similar, for longest wait times — oh, and use hours please, minutes are a pain to interpret.

Another OpenAI assistant produced screenshot of wait time data by day of week and hour of day.

This chart I absolutely love. You need to stare at it for a minute, but the hotspots really jump out. As do the weekends as well as Friday’s — its not much, but Friday daytimes are the lightest days by quite a bit!

After spending about 15 minutes to get this far, I took a step back and soaked it up. I was able to crunch so much data in such little time and I was kind of blown away. It would have taken me hours to do this, and I wouldn’t have even considered the illuminating multi-dimensional view.

I shared these results with some friends, they concurred it was pretty neat. I’ve never had so much raw data of potential interest, of anything somewhat interesting to play with. I slept on it.

I came back yesterday and decided to play some more, and then publish this piece. Well… things didn’t go quite as planned.

In short, some of the results seemed to be actually wrong (data values were clipped or maybe it removed too many outliers), and then eventually the tool just kept erroring out. Maybe my asks got too sophisticated, but it was a much more underwhelming experience.

I guess I shouldn’t forget how to do pivot charts so fast after all.

The other thing, this isn’t free; LOTS of tokens, SO MANY tokens. The last round of play was over 270k tokens, which is about $5 worth of play. Not breaking the bank, but if I spent a few hours going back and forth and generating graphs it definitely would creep up.

So, in a nutshell – cool tech, cool data. It should give non data scientists access to visuals they otherwise might have had to ask for someone else to help with. But given the reliability and robustness, not taking anyone’s jobs quite yet. This seems to be the case with most things that requires accuracy… AI can generate encouraging results, but nothing final.

Art on the other hand… that’s a piece for another day!!

If you’re interested in the code or have any questions or interpretations at all I’d love to chat about it!