Repository navigation
Conversation
|
Closing and reopening to rerun CI: the ubuntu job failed on a transient curl error while installing dependencies (macOS and Windows passed). |
|
For the record, the "Check for spelling errors" failure is not from this PR: codespell flags words inside |
The drug era example script on the SQL Scripts page now lives in inst/sql/sql_server/OMOP_CDM_drug_era.sql, unchanged, and the page includes it from there (engine: knitr, so the page renders the sql chunk without Jupyter). buildDrugEra() renders that script for a CDM schema, translates it with SqlRender and runs it with DatabaseConnector, like executeDdl(). The tests run it on a SQLite CDM for every supported CDM version with the scenarios from OHDSI#761 and check the era dates and exposure counts. docs/sqlScripts.html only has the changes from re-rendering the page.
days_exposed and the era length both counted the days between two dates, while drug exposure start and end dates are inclusive, so every sub-exposure lost a day and gap_days came out too high. Both now add 1, as agreed in OHDSI#761. The buildDrugEra() tests now check gap_days as well; without this change they fail for every CDM version (7 instead of 5 gap days in the first scenario, 1 instead of 0 for consecutive exposures).
|
Thanks, will do. I have both ready locally. The first moves the script into its own file without touching the SQL and adds Before I push: |
fcb5aa2 to
cb9c15b
Compare
|
Pushed both. #824 moves the drug era script into |
Fixes #761
Second of two stacked PRs: this one depends on #824, which moves the drug era script into
inst/sql/sql_server/OMOP_CDM_drug_era.sqlunchanged and addsbuildDrugEra(). Until #824 is merged, the diff here also shows its commit; the change in this PR is the last commit only.The drug era script on the SQL Scripts page computes
days_exposedand the era length asdatediff(day, start, end), which counts an exposure from day 1 to day 5 as 4 days. Every sub-exposure in an era therefore contributes one spurious gap day: for the four exposures in the issue (days 1-5, 3-7, 11-13, 16-20) the script reportsgap_days = 7instead of 5, and two back-to-back exposures (days 1-5 and 6-10) reportgap_days = 1although the person is exposed every day.Change
inst/sql/sql_server/OMOP_CDM_drug_era.sql: the two+ 1changes agreed in Drug era calculation gap_days calculation #761 (days_exposedand the era length are now counted inclusively). Nothing else in the script changes.docs/sqlScripts.html: the same two lines, from re-rendering the page.tests/testthat/test-buildDrugEra.R: thebuildDrugEra()tests from Move the drug era script into its own SQL file and add buildDrugEra() #824 now also checkgap_days(5 for the four exposures, 0 for back-to-back exposures, 0 for the single-exposure eras). Without the fix they fail for every CDM version, with 7 instead of 5 and 1 instead of 0.The fallback end date
dateadd(day, days_supply, start), used whendrug_exposure_end_dateis NULL, is still exclusive. I left it alone to keep to the agreed fix.Testing