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

Address expiry of studies from clinicaltrials.gov #157

Merged
merged 4 commits into from
Jan 9, 2024

Conversation

machinehum
Copy link
Contributor

Added a task to un-publish trials that are no longer in the list of recruiting trials for the location that is being used to pull from clinicaltrials.gov.

  • Refactored ctgov connector nct_ids_for_location method to use current ct.gov API. Also uses recursion without passing arrays of IDs into a new method invocation for memory benefits.
  • In same method, include filter for only recruiting studies at location.
  • Allow cleanup_stray_trials and stray_trials to accept an argument of an array of IDs that should be considered "still recruiting"; this can be leveraged for testing bc there isn't a great way to mock ct.gov API responses given the current state of coupling in the connector.
  • Tests for these updates.

Added a task to un-publish trials that are no longer in the list of recruiting trials for the location that is being used to pull from clinicaltrials.gov.

- Refactored ctgov connector nct_ids_for_location method to use current ct.gov API. Also uses recursion without passing arrays of IDs into a new method invocation for memory benefits.
- In same method, include filter for only recruiting studies at location.
- Allow cleanup_stray_trials and stray_trials to accept an argument of an array of IDs that should be considered "still recruiting"; this can be leveraged for testing bc there isn't a great way to mock ct.gov API responses given the current state of coupling in the connector.
- Tests for these updates.
@machinehum machinehum requested a review from cdinger December 19, 2023 23:02
Comment on lines 39 to 43
ctgov.cleanup_stray_trials(remaining_ids)
will_hide.reload

expect(will_hide.visible).to be_falsey
expect(wont_hide_2.visible).to be_truthy
Copy link

Choose a reason for hiding this comment

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

If you need to reload will_hide to ensure .visible is falsey, shouldn't you also need to reload wont_hide_2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe so, because trials in wont_hide_2 aren't being changed. Only those in will_hide.

Comment on lines +40 to +42
trials = connector.cleanup_stray_trials
puts "Have un-published (system_ids): "
puts trials.map{ |e| " #{e.system_id}\n" }
Copy link

Choose a reason for hiding this comment

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

connector.cleanup_stray_trials returns the result of calling update(visible: true on stray trials. Since update will return the record(s) regardless of whether the update actually succeeded, would you need to do any final checking in this rake task to ensure what you are printing actually includes successfully updated records?

There's only a single validation I saw for Trial, so the likelihood of the update failing is probably minimal. And you aren't actually manipulating the returned data, so maybe this doesn't matter much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point. Updated to use update! so we get an error alert if there's an issue.

response_ids = Array(JSON.parse(response.body || "{}").dig("StudyFieldsResponse").dig("StudyFields")).map do |result|
Array(result.dig("NCTId")).first
response_ids = Array(payload.dig("studies")).map do |result|
result.dig("protocolSection").dig("identificationModule").dig("nctId")
Copy link
Member

Choose a reason for hiding this comment

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

Wonky indentation


def extract_zip
dirname = "#{Rails.root}/tmp/"
unless File.directory?(dirname)
Copy link
Member

@cdinger cdinger Jan 8, 2024

Choose a reason for hiding this comment

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

FileUtils.mkdir_p doesn't fail if a directory already exists. These checks are probably not needed.

end

unless File.directory?("#{dirname}trials/")
FileUtils.mkdir_p("#{dirname}trials/")
Copy link
Member

Choose a reason for hiding this comment

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

There's Dir.mktmpdir that might be appropriate here. It looks kind of like Tempfile but without the built-in cleanup hook I think.

private

def extract_zip
dirname = "#{Rails.root}/tmp/"
Copy link
Member

Choose a reason for hiding this comment

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

Not using File.join and friends here is screaming to my eyeballs, but I don't think it's strictly necessary anymore (i.e. forward slashes work on both *nix and Windows now).

This was introduced solely for testing -- replace with stubbing :site_nct_ids in the spec.
@machinehum machinehum merged commit 0a17cbe into master Jan 9, 2024
1 check passed
@machinehum machinehum deleted the ctgov-connector-study-expiry branch July 11, 2024 16:50
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.

3 participants