-
Hi, I'd like to identify consecutive outpatient appointments and the corresponding mode of appointment. I tried the method here: https://docs.opensafely.org/study-def-tricks/ where I defined a function for the date and a function for the mode of appointment but it doesn't seem to like the section defining mode of appointment as the returning variable isn't a date. Is it possible to identify this information or would I need to go to summary data e.g. mode of latest appointment within periods of time? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
In order to idenitfy both the consecutive appointments and the corresponding mode, I think you'd need to define two variables for each consecutive date, one to return the date, and one to return the corresponding mode. Something like this should work (note there's an extra
|
Beta Was this translation helpful? Give feedback.
-
Thank you, that looks like what I need. Could I check what I need to put lower down in the script to return the variables. I have added the above to the top of the script: def op_appt_dates_and_mode_X(name, index_date, n, return_expectations):
and then lower down in the study definition: **op_appt_dates_and_mode_X( But it says "op_appt_dates_and_mode_X() got an unexpected keyword argument 'on_or_after'" I can't figure out why? Also, is there any documentation, or anywhere I can find out more about defining functions? |
Beta Was this translation helpful? Give feedback.
-
Ok, thank you very much, I've got it working. |
Beta Was this translation helpful? Give feedback.
In order to idenitfy both the consecutive appointments and the corresponding mode, I think you'd need to define two variables for each consecutive date, one to return the date, and one to return the corresponding mode.
Something like this should work (note there's an extra
returning
parameter in thevar_signature()
function, so that you can use the same function to return the variable for the date and the appointment type.