Automating Residency Work Hour Tracking
Time to complete: 20–30 minutes. No coding is required.
Throughout medical school, I manually tracked my time each day with Google Sheets and Jupyter Notebooks to gain insights into where my efforts were going. While a fun way to develop my programming skills, it was also a bit tedious, so I do not plan on continuing the project throughout my ENT residency. However, I need to track my duty hours each month during residency. I used IFTTT, Google Sheets, ChatGPT, Python, and Render to automate the process.
This project uses location tracking through your phone to automatically create a row in a Google Sheet when you arrive at and leave the hospital or clinic. It then processes the data to sum your duty hours for the time you specify and presents it in a dashboard with four graphs (My screenshot got cut off below).
Here is a link to a demo of the dashboard. I use the free version of render so it takes a few seconds to load.
Steps
IFTTT
- Download IFTTT app for your phone in the app store.
If you only need to track one location (ie. you only cover one hospital) you can do this project for free. Otherwise, you may need to upgrade to Pro for ~$3/month.
Find and modify IFTTT applet
- Go to this applet and connect it.
- Sync with Google Sheets
- Once it is connected set your desired area and save.
- Now select Settings and Edit in the “Then” box.
- Select “Make it your own to edit this field” under “Formatted row”
- Delete =IMAGE(“{{LocationMapImageUrl}}”;1) and type the name of the location. ex SNGH. This will allow you to filter your graphs by your location.
- “Formatted row” should look like this when you are done.
{{OccurredAt}} ||| =IF("{{EnteredOrExited}}"="entered","Arrived at location","Left location") ||| {{Address}} ||| YourLocation
- Change the name of the spreadsheet to the location it references.
- If you have a specific folder you want to save it in within Google Sheets, specify. Otherwise, it will create a new folder titled IFTT. Then select update.
- Select update again.
- Edit the title of your applet to the location it references
- Repeat this process for all of the locations you cover
Turn on location tracking on your phone
- Settings > IFTTT > Location > Set to Always
- IFTTT app > Profile > Sync Option > Turn on Location assist syncing
Set Up GitHub
GitHub is where your code will live.
- Create GitHub account
- Go to my project repository on GitHub
- Download the zip file of my repository
- Unzip the file locally
- Create your own repository and upload the files from the zip folder to it.
Deploy with Render
Render is a web hosting service that allows you to publish your app to the web with a unique URL.
- Log into Render using your GitHub account.
- Create new web service
- Link GitHub account and select your repository
- Update the settings to match below
Build Command
pip install -r requirements.txt
Start Command
gunicorn -b 0.0.0.0:$PORT app:server
IMPORTANT: the data that will appear on the dashboard is not your data yet. There is one more step to complete.
- Select deploy
After Render has run the app. You should get a message on your Dashboard screen that your service is live. At that point, click the link for your unique URL at the top left of the screen and you should be able to see a Dashboard. Bookmark this link so that you can access it whenever you want. This is test data!
Execute Your Unique Code
You will not be able to complete this step until the IFTTT applet(s) have triggered (ie you have entered into the GPS radius of the hospital/clinic). At the point the applet has run, a new folder and file will be created by IFTTT in your Google Drive.
- In the Google Sheet File > Share > Publish to Web > Make sure “Entire Document” and “Microsoft Excel File” are selected.
- Copy the link
- Go to your GitHub repository
- Go to the file named “app.py”
- Edit the file for lines 28–29 by inserting the URL of the Google Sheet. Make sure that the URL is surrounded by parentheses.
urls = [
#Location 1
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTz4epfxR7gbMC6koJ70b7ntJrKNR8gabRnc8-Fxh2icdp_QGVax2-QafWt57FSUDd7yincCSK3xBYx/pub?output=xlsx"
]
- If you have multiple locations that you are covering, separate each of the URLs to the Google sheet with a comma. You can label each location within the code without affecting its execution by using a hashtag before the text on a different line. See below.
urls = [
#Location 1
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTz4epfxR7gbMC6koJ70b7ntJrKNR8gabRnc8-Fxh2icdp_QGVax2-QafWt57FSUDd7yincCSK3xBYx/pub?output=xlsx",
#Location 2
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTz4epfxR7gbMC6koJ70b7ntJrKNR8gabRnc8-Fxh2icdp_QGVax2-QafWt57FSUDd7yincCSK3xBYx/pub?output=xlsx"
]
- Select commit on the top right of the screen
Render should automatically try to rerun your code whenever you add a new commit to GitHub. To make sure it runs, go back to your Render dashboard. If the new commit is not running, on the top right of your screen select Manual Deploy > Deploy latest commit. Once your service is live, it will show up at your unique URL.
Functionality
Your unique dashboard will default to the first and last date that data is available. You can adjust these dates as you see fit. The data is portrayed as total hours in the date range, hours per day in the date range, hours per week in the date range, and total hours per location in the date range.
All done! I hope this makes keeping track of your duty hours a little easier throughout residency!