Tutor notes - module 1
Overview
This is the second course for the Programming in Healthcare series. It is for students that have some experience with coding. Module 0 should have prepared most, if not all, students for module 1.
You will still need to provide a lot of hand holding, as these are still fairly new topics for the students. This course has been designed to take things at a slow pace, with plenty of time to work through the coding practices. Please be patient with our students, and give them the time and teachings they need. As you may know, there is a high attrition rate for people who start out trying to code. We need to help them over this initial hump, so we can help as many as possible to start out in this exciting world of coding.
We will be using Codespace from Github as the teaching environment. All students will need to have a Github account. It is also recommended to not use a NHS computer, as some IT departments block access to GitHub.
Code for the coding sessions can be found here.
Session info for students
We will be using hackMD to store information for the session (eg tutor group allocation). This stops the need to repeatedly copy and paste details into the chat. A markdown template for the HackMD can be found here.
Timings
Example timings for evening session.
Start 7pm End 10pm
6:30 pm - Open zoom for tutors and set up breakout rooms. Test all functionality.
7:00 pm - Open room to students
7:05 pm - Talk - 1-introduction.html
7:10 pm - Talk - 2-coding-environment.html
7:15 pm - Talk - 3-python.html
7:25 pm - Hands-on - lesson_1.py
7:45 pm - Talk - 4-lets-build.html
7:55 pm - Hands-on - lesson_2.py (& lesson_3.py)
9:00 pm - Talk - Short stop to see how everyone is doing
9:05 pm - Hands-on - back to lesson_2.py (& lesson_3.py)
9:50 pm - Talk - 5-session-close.html
10:00 pm - Close
First hour
In the first hour of this course we will introduce classes and libraries.
Second and Third Hour
For the rest of the module, we will be building a basic clinical calculator in Streamlit.
Common pit falls
- Cannot connect to GitHub website - Most likely due to hospital/GP practice IT restrictions. Try a non-hospital/GP practice computer and try outside of the hospital/GP practice network.
- Cannot open an instance of Codespace - Check that the student has not already created a Codespace instance for the repo that we are using. GitHub only allows one instance of Codespace per GitHub account per repo.
Answers (rebuild)
lesson_1.exercise_1.py
import random
= random.randint(1, 10)
random_number print(random_number)
lesson_1.exercise_2.py
class Patient:
def __init__(self, name, age, diagnosis):
self.name = name
self.age = age
self.diagnosis = diagnosis
self.is_admitted = False
def admit(self):
if not self.is_admitted:
print(
f"Admitting {self.name} to the hospital with diagnosis: {self.diagnosis}"
)self.is_admitted = True
else:
print(f"{self.name} is already admitted")
def discharge(self):
if self.is_admitted:
print(f"Discharging {self.name} from the hospital")
self.is_admitted = False
else:
print(f"{self.name} is not currently admitted")
= Patient("John Doe", 45, "Pneumonia")
patient_1 = Patient("Jane Smith", 30, "Appendicitis")
patient_2
patient_1.admit()
patient_2.admit()
patient_1.discharge() patient_2.discharge()
- Note, the answers for each exercise in lesson 2 are in the subsequent exercise.
lesson_2.exercise_8.py
def calculate_egfr(creatinine, age, gender, race):
"""Calculate the Estimated Glomerular Filtration Rate (egfr)
Calculate the estimated glomerular filtration rate (eGFR) using the CKD-EPI formula.
Args:
creatinine (int): Creatinine level
age (int): Age of patient
gender (str): "Male" or "Female"
race (str): "Afro-Caribbean" or "other"
Returns:
int: Estimated glomerular filtration rate (eGFR)
"""
if gender == "Male":
= 1
gender_factor elif gender == "Female":
= 0.742
gender_factor else:
raise ValueError(
"Invalid gender. Please specify 'Male' for male or 'Female' for female."
)
if race == "Afro-Caribbean":
= 1.212
race_factor elif race == "other":
= 1
race_factor else:
raise ValueError(
"Invalid race. Please specify 'Afro-Caribbean' or 'other'."
)
= (
egfr 175
* ((creatinine * 0.011312) ** (-1.154))
* (age ** (-0.203))
* gender_factor
* race_factor
)return int(egfr)
def get_ckd_stage(egfr):
"""Get CKD stage
Determine the stage of chronic kidney disease (CKD) based on estimated glomerular filtration rate (eGFR).
Args:
egfr: Estimated glomerular filtration rate (eGFR)
Returns:
str: CKD stage
"""
if egfr > 90:
return "1"
elif 60 <= egfr <= 90:
return "2"
elif 45 <= egfr <= 59:
return "3a"
elif 30 <= egfr <= 44:
return "3b"
elif 15 <= egfr <= 29:
return "4"
else:
return "5"
def main():
"""The main Streamlit code
Runs the Streamlit web app
"""
"eGFR calculator")
st.title(
= st.number_input("Creatinine:", step=1)
creatinine = st.number_input("Age:", step=1)
age = st.selectbox("Gender:", ["", "Male", "Female"])
gender = st.selectbox("Race:", ["", "Afro-Caribbean", "other"])
race
try:
= calculate_egfr(creatinine, age, gender, race)
egfr except Exception as e:
f"Awaiting appropriate inputs")
st.write(else:
f"eGFR: { egfr }")
st.write(= get_ckd_stage(egfr)
ckd_stage f"CKD stage { ckd_stage }")
st.write(
return
if __name__ == "__main__":
main()