opensafely-core / ehrql

ehrQL: the electronic health record query language for OpenSAFELY
https://docs.opensafely.org/ehrql/
Other
7 stars 3 forks source link

Allow users to do a quiz by filling in gaps in an incomplete file #2221

Closed inglesp closed 4 days ago

inglesp commented 1 week ago

This is an alternative to #2168.

We can provide a quiz-like experience by giving users an incomplete file with gaps for them to fill in. The file would look something like this:

from ehrql import quiz
from ehrql.tables.core import patients, clinical_events, medications

# Question 0: find the age of each patient on 1st January 2024
quiz.questions[0].check(patients.age_on("2024-01-01"))

# Question 1: find the number of medications given to each patient
quiz.questions[1].check(...)

# ...

quiz.summarise()

When they run the file, they would see output like:

Question 0: ☑
Question 1: ☒ The patient series you have provided has the wrong values for the following patients: 1, 3, 6
Question 2: ☐
Question 3: ☐

You have answered 1 question correctly, 1 incorrectly, and left 2 unanswered.

There is one line of output for every call to .check(), and one line from the call to .summarise().

The incomplete file can be included in the tutorial repo, so that users can do the quiz after they've done the tutorial.

To run the file, we should provide a VS Code command for users to run from the command palette and/or a button they can click on.

We should add a script to the scripts directory that produces the incomplete file, based on a list of questions that looks something like this, and which uses the answer-checking functionality in #2214.

questions = [
    Question(
        "find the age of each patient on 1st January 2024",
        patients.age_on("2024-01-01"),
    ),
    ...
]

Writing real questions is out of scope for this ticket.

alarthast commented 1 week ago

Slack conversation

Crude steps / thoughts towards implementing this (branch): Command

Functionality

Things to think about:

alarthast commented 4 days ago

Closed by #2241