Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotApplicable fix for measureConditionEraCompleteness #527

Merged
merged 9 commits into from
Jul 12, 2024

Conversation

MaximMoinat
Copy link
Collaborator

@MaximMoinat MaximMoinat commented Feb 13, 2024

Fixes #526, by having an exception for measureConditionEraCompleteness check; it will be NA when condition occurrence table is missing or empty.

To be able to make the fix, I had to refactor the NA status code. While doing that, I also moved the logic to a separate function.

As a reminder when/if we add measureDrugEraCompleteness, I have added some code for that already but commented it out for now.

TODO:

  • Investigate failing unit tests
  • Add tests for .calculateNAstatus

@MaximMoinat
Copy link
Collaborator Author

I see the checks ar failing, I will investigate and fix this.

@katy-sadowski
Copy link
Collaborator

Thanks @MaximMoinat ! Love the initiative. I'll wait to do a deep review til you've sorted out the failing checks. I'd also recommend to add some unit tests for the code. I know there weren't any test specific to NA before, but now that they're in their own function and we're refactoring a bit, it feels like the right time.

Might need to get a bit crafty to test this though :) off the top of my head, I'm picturing truncating a table in Eunomia and then seeing if related checks are marked NA. Happy to help brainstorm further on that.

@MaximMoinat
Copy link
Collaborator Author

I like the idea of adding tests, will look into that.

Might need to get a bit crafty to test this though :) off the top of my head, I'm picturing truncating a table in Eunomia and then seeing if related checks are marked NA. Happy to help brainstorm further on that.

That is exactly the test I did locally already: run with truncated condition occurrence (expecting NA) and with truncated condition era (expecting fail). This passed for me, but would indeed be good to have this integrated into the test suite.

@MaximMoinat
Copy link
Collaborator Author

@katy-sadowski Tests are fixed and new tests added. Note that these are in a separate file "test-calculateNotApplicableStatus.R", although they do not test the .calculateNotApplicableStatus function in isolation, but by running the full executeDqChecks.

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 88.46%. Comparing base (1c48fcb) to head (a75e984).
Report is 47 commits behind head on develop.

❗ Current head a75e984 differs from pull request most recent head 4586a77. Consider uploading reports for the commit 4586a77 to get more accurate results

Files Patch % Lines
R/calculateNotApplicableStatus.R 95.83% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #527      +/-   ##
===========================================
+ Coverage    86.48%   88.46%   +1.98%     
===========================================
  Files           16       17       +1     
  Lines          888      954      +66     
===========================================
+ Hits           768      844      +76     
+ Misses         120      110      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@katy-sadowski katy-sadowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SORRY for the delay!!! This looks good to me. Just a couple minor comments. Thanks so much for adding this!

R/calculateNotApplicableStatus.R Outdated Show resolved Hide resolved
R/calculateNotApplicableStatus.R Outdated Show resolved Hide resolved
R/calculateNotApplicableStatus.R Outdated Show resolved Hide resolved
tests/testthat/test-calculateNotApplicableStatus.R Outdated Show resolved Hide resolved
on.exit(unlink(outputFolder, recursive = TRUE))

# Remove records from Condition Occurrence
connection <- DatabaseConnector::connect(connectionDetailsEunomia)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be safer to create a separate eunomia DB just for these tests. i believe testthat runs the test files in parallel so we might run into weird issues if we're modifying the same DB here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an issue. If I open a Eunomia connection in two R sessions, clearing a table in one session does not affect the other session.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe tests are all being run in the same R session though. And I checked:

> cd <- Eunomia::getEunomiaConnectionDetails()
attempting to download GiBleed
trying URL 'https://raw.githubusercontent.com/OHDSI/EunomiaDatasets/main/datasets/GiBleed/GiBleed_5.3.zip'
Content type 'application/zip' length 6861852 bytes (6.5 MB)
==================================================
downloaded 6.5 MB

attempting to extract and load: /var/folders/l2/3d9d5v9s197_2nkdvgrljv4c0000gn/T//RtmpM53RnU/GiBleed_5.3.zip to: /var/folders/l2/3d9d5v9s197_2nkdvgrljv4c0000gn/T//RtmpM53RnU/GiBleed_5.3.sqlite
                                                                                                                    
> con <- DatabaseConnector::connect(cd)
Connecting using SQLite driver
> p <- DatabaseConnector::querySql(con, "select * from person")
> nrow(p)
[1] 2694
> DatabaseConnector::executeSql(con, "delete from person")
  |=======================================================================| 100%
Executing SQL took 0.0128 secs
> nrow(p)
[1] 0
> con2 <- DatabaseConnector::connect(cd)
Connecting using SQLite driver
> p2 <- DatabaseConnector::querySql(con, "select * from person")
> nrow(p2)
[1] 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaximMoinat I think this got lost in the shuffle - let me know what you think and if you're OK creating new connection details for these tests. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have now added a separate NaChecks cd object for these tests. This seems to work as expected:

> connectionDetailsEunomiaNaChecks <-  Eunomia::getEunomiaConnectionDetails()
...
attempting to extract and load: /Users/maxim/eunomia_data/GiBleed_5.3.zip to: /Users/maxim/eunomia_data/GiBleed_5.3.sqlite
> connection <- DatabaseConnector::connect(connectionDetailsEunomia)
Connecting using SQLite driver
> DatabaseConnector::executeSql(connection, "DELETE FROM CONDITION_OCCURRENCE;")
> DatabaseConnector::querySql(connection, "select count(*) from condition_occurrence;")
  COUNT(*)
1        0
> DatabaseConnector::disconnect(connection)
> connectionDetailsEunomia <- Eunomia::getEunomiaConnectionDetails()
...
attempting to extract and load: /Users/maxim/eunomia_data/GiBleed_5.3.zip to: /Users/maxim/eunomia_data/GiBleed_5.3.sqlite
                                                                             
> connection <- DatabaseConnector::connect(connectionDetailsEunomia)
Connecting using SQLite driver
> DatabaseConnector::querySql(connection, "select count(*) from condition_occurrence;")
  COUNT(*)
1    65332
> DatabaseConnector::disconnect(connection)
> connection <- DatabaseConnector::connect(connectionDetailsEunomiaNaChecks)
Connecting using SQLite driver
> DatabaseConnector::querySql(connection, "select count(*) from condition_occurrence;")
  COUNT(*)
1        0
> DatabaseConnector::disconnect(connection)

@MaximMoinat
Copy link
Collaborator Author

Thanks for your comments Katy. I agree with your suggestions and will implement these.

@MaximMoinat
Copy link
Collaborator Author

@katy-sadowski Implemented the requested changes, except for the one on the test. See my comment.

@katy-sadowski katy-sadowski merged commit db05f43 into develop Jul 12, 2024
8 checks passed
@MaximMoinat MaximMoinat deleted the na-status-refactor branch July 12, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants