Replies: 2 comments
-
Hello! OpenSAFELY was designed initially to return data in the form of one row per patient. This was because it met the early, urgent needs of using the data during the pandemic, and also minimised the amount of data returned, which is another layer of privacy protection. However since then we've started using it for more complex studies where event level data like that you describe would be useful. There are plans to implement this functionality at some point in the future, but I'm not sure of the timescale. In the mean time, there's an imperfect but okay workaround we've developed to return multiple events, where you end up with wide data rather than long. It involves:
This is fine if you're only expecting a small number of events, but if you need more then a few tens it will take a long time to run the query and return an enormous output file. To write it less laboriously you can do it in a loop (example here). P.S. cohortextractor is due to be deprecated within the next few months, and we expect all new studies will use it's new, more flexible and better designed cousin ehrQL, which will hopefully eventually have a better way of working with event level data. |
Beta Was this translation helpful? Give feedback.
-
Hi Alex
I’d thought about that work around but decided it would be a burdensome.
When you point to the loop do you mean:
**{
f"sick_note_{n}_duration_months": patients.with_these_clinical_events(
codelist(["Y08c2"], system="ctv3"),
between=[f"sick_note_{n}_date", f"sick_note_{n}_date"],
returning="numeric_value",
return_expectations={
"incidence": 0.9,
"float": {"distribution": "normal", "mean": 21, "stddev": 5},
},
)
for n in range(1, 6)
},
**covariates,
I assume this will create variables that get given a similar name from 1-6?
If so this would be very useful to as a temporary fix – thank you.
I’ll explore the ehrQL<https://protect-au.mimecast.com/s/0Vr7COMxVEHAzRBlOik_SLc?domain=docs.opensafely.org/> tool a bit more – are the some GitHub examples with its use yet?
Thanks in advance.
Kind regards,
Paulie
From: Alex Walker ***@***.***>
Sent: Wednesday, September 6, 2023 5:03 AM
To: opensafely/documentation ***@***.***>
Cc: Paulina Stehlik ***@***.***>; Author ***@***.***>
Subject: Re: [opensafely/documentation] cohortgenerator- extract all vaccine dates as a string of dates (Discussion #1323)
Hello! OpenSAFELY was designed initially to return data in the form of one row per patient. This was because it met the early, urgent needs of using the data during the pandemic, and also minimised the amount of data returned, which is another layer of privacy protection. However since then we've started using it for more complex studies where event level data like that you describe would be useful. There are plans to implement this functionality at some point in the future, but I'm not sure of the timescale.
In the mean time, there's an imperfect but okay workaround we've developed to return multiple events, where you end up with wide data rather than long. It involves:
1. selecting the first event of interest
2. using the date of that first event to find the next event (using on_or_after in cohortextractor)
3. using the date of that second event to find the next one
4. and so on...
This is fine if you're only expecting a small number of events, but if you need more then a few tens it will take a long time to run the query and return an enormous output file. To write it less laboriously you can do it in a loop (example here<https://protect-au.mimecast.com/s/TGiDCQnzZNU6MAwgRHrvQl1?domain=github.com>).
P.S. cohortextractor <https://protect-au.mimecast.com/s/i2ZwCNLwQEiNDlgJ6i4iYU5?domain=docs.opensafely.org/> is due to be deprecated within the next few months, and we expect all new studies will use it's new, more flexible and better designed cousin ehrQL<https://protect-au.mimecast.com/s/0Vr7COMxVEHAzRBlOik_SLc?domain=docs.opensafely.org/>, which will hopefully eventually have a better way of working with event level data.
—
Reply to this email directly, view it on GitHub<https://protect-au.mimecast.com/s/IulxCP7yXMc48GL96tjkEIz?domain=github.com>, or unsubscribe<https://protect-au.mimecast.com/s/1zHWCROA2Mfrjm3oOToNmEa?domain=github.com>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
Beta Was this translation helpful? Give feedback.
-
Hi OpenSafely peeps
I'm wanting to extract all the dates of a patients previous COVID vaccinations and positive test results and classify their immunity level according to these.
Is there a way to do this with the cohortgenerator?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions