Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Guide to Bonnie Rake Tasks

Ashok Dongare edited this page Mar 13, 2020 · 61 revisions

General

Rails rake tasks are by default run against the development database; to run a rake task against a different environment such as production add RAILS_ENV=<environment>, for example

bundle exec rake bonnie:db:resave_measures RAILS_ENV=production 

Granting and Revoking Access

Rake tasks can be used to grant and revoke access to the admin role (used for administering the site), the portfolio role (used for creating sets of test patients across measures, such as for Cypress test decks), the dashboard role (which makes the complexity and change dashboard available to a user) and the dashboard_set role (which makes all measures loaded in a user account available on the complexity and change dashboard). The various tasks include

bundle exec rake bonnie:users:grant_admin EMAIL="<user-email>"
bundle exec rake bonnie:users:revoke_admin EMAIL="<user-email>"

bundle exec rake bonnie:users:grant_portfolio EMAIL="<user-email>"
bundle exec rake bonnie:users:revoke_portfolio EMAIL="<user-email>"

bundle exec rake bonnie:users:grant_dashboard EMAIL="<user-email>"
bundle exec rake bonnie:users:revoke_dashboard EMAIL="<user-email>"

bundle exec rake bonnie:users:grant_dashboard_set EMAIL="<user-email>"
bundle exec rake bonnie:users:revoke_dashboard_set EMAIL="<user-email>"

Moving Measures Between Accounts

It's possible to move a measure from one user account to another, moving all test patient records and copying all value sets:

bundle exec rake bonnie:users:move_measure SOURCE_EMAIL="<source-user-email>" DEST_EMAIL="<destination-user-email>" CMS_ID="<measure-cms-id>"

Copying Patients between Measures and (optionally) Accounts

This will copy (not move) patients from one measure on one user account to the same (or another) measure on another account (optionally the same account).

bundle exec rake bonnie:patients:copy_measure_patients SOURCE_EMAIL="<source-user-email>" DEST_EMAIL="<destination-user-email>" SOURCE_HQMF_SET_ID="<source-measure-hqmf-set-id>" DEST_HQMF_SET_ID="<destination-measure-hqmf-set-id>"

Copying test cases (e.g. patients) between Bonnie instances(a.k.a. Patient Transfers)

  1. First export the patients from source server, something like:

    bundle exec rake bonnie:patients:export_patients EMAIL=<user_email> HQMF_SET_ID=93F3479F-75D8-4731-9A3F-B7749D8BCD37 FILENAME=CMS72_patients.json

    Substitute in the appropriate email, HQMF set id, and a unique filename. Note: on the AHRQ-hosted sites you must also include the flag RAILS_ENV=production

  2. Test locally, and after there are no issues, import patients into destination server, something like:

    bundle exec rake bonnie:patients:import_patients EMAIL=<user_email> HQMF_SET_ID=93F3479F-75D8-4731-9A3F-B7749D8BCD37 FILENAME=CMS72_patients.json

Exporting Users Test Patient Record Spreadsheets

Users can export their test patient data with corresponding calculation results in excel format using the web interface; there's a rake task that allows the same spreadsheets to be generated for users accounts, one spreadsheet per measure. First, add the list of accounts whose measures you would like to export excel files for to the ACCOUNTS variable in lib/tasks/bonnie_run_once.rake, then run:

bundle exec rake bonnie:patients:super_user_excel

The measures are exported into files with the name <measure-cms-id>.xlsx

Resetting a Database and Loading Basic Data

For development or demonstration purposes it can be useful to reset a Bonnie database and populate it with some basic data:

bundle exec rake bonnie:db:reset

This can be limited to a smaller set of data by using the DEMO flag

bundle exec rake bonnie:db:reset DEMO=true

This task clears all existing data and populates the database with a single user account with some measures loaded:

Username: [email protected]
Password: b0nn13p455

Backup the Bonnie Database

The contents of a Bonnie MongoDB database can be dumped to a backup file using

bundle exec rake bonnie:db:dump

This can be used for creating snapshots for, say, debugging or as part of a regular backup process. If used as part of a regular backup process there's a companion rake task that prunes the database dumps, keeping daily snapshots for the most recent month but deleting older files so as to only keep weekly snapshots for older backups:

bundle exec rake bonnie:db:prune_dumps

Working with VSAC

Value sets are sets of codes (ICD-9, ICD-10, SNOMED, LOINC, etc) grouped together to represent a single concept for use in the context of a measure, and represented by an OID (Object IDentifier). Bonnie loads value set information from VSAC (the NLM Value Set Authority Center, at https://vsac.nlm.nih.gov/). There are two rake tasks for working with value sets. The first allows the contents of a value set to be looked up given the OID:

bundle exec rake bonnie:vsac:lookup_oid OID=<oid> USERNAME=<vsac-username> PASSWORD=<vsac-password>

The second retrieves the current listing of VSAC expansion profiles from VSAC. Expansion profiles (ie "MU2 Update 2015-05-01") are a type of versioning, needed to allow different sets of codes to be present in value sets at different times. Retrieve the list of these using

bundle exec rake bonnie:vsac:get_profile_names USERNAME=<vsac-username> PASSWORD=<vsac-password>

Fixture Export Tool

The fixture export tool will create test-ready fixtures from an extant database. Before using this tool, make sure to load a copy of the desired database and set the database property in config/mongoid.yml

The fixture export task can be run from the command line as follows:

bundle exec rake bonnie:fixtures:generate_backend_cqm_fixtures

This command takes the following arguments:

cms_hqmf: Use cms or hqmf id.
   values: cms, hqmf
path: Fixture path.
user_email: email of user to export
measure_id: id of measuer to export

Ex: bundle exec rake bonnie:fixtures:generate_backend_cqm_fixtures[cms,test/CMS55v5,fake@fake,CMS55v5]

It is also possible to generate frontend fixtures using this tool using:

bundle exec rake HDS:test:generate_frontend_cqm_fixtures

With the arguments

cms_hqmf: Use cms or hqmf id.
   values: cms, hqmf
path: Fixture path.
user_email: email of user to export
measure_id: id of measure to export

Ex: bundle exec rake bonnie:fixtures:generate_frontend_cqm_fixtures[cms,test/CMS55v5,initialLoad,fake@fake,CMS55v5]

Generating VCR Cassettes

VCR cassettes allow you to replay the network traffic for unit tests, useful for when you need to upload a measure in a unit test. They are stored in bonnie/test/fixtures/vcr_cassettes.

First, go on outernet, turn on alwaysonsuspend, and reset your http_proxy and https_proxy environmental variables.

To generate them, wrap the code you want to use the cassette in this:

VCR.use_cassette("valid_vsac_response_<unique_name_here>") do
  post :create, {vsac_date: '11/07/2017 <CHANGE ME>', include_draft: true, measure_file: measure_file, measure_type: 'ep', calculation_type: 'patient', vsac_username: ENV['VSAC_USERNAME'], vsac_password: ENV['VSAC_PASSWORD']}
   ...
end

Note you need to change the vsac_date to be the date of the creation of the cassette.

When you run the test, it will generate the .yml file that is the cassette. You may need to comment out all other tests in order to get around proxy issues, but that may not be necessary if it doesn't need to use the JAR.

You have to pass in your VSAC credentials in the command line like this:

$ bundle exec rake test TEST=test/functional/measures_controller_test.rb VSAC_USERNAME=<your username here> VSAC_PASSWORD=<your password here>

Update the .yml file to remove your username and password, replacing the line with:

string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>

You should verify that they do not appear there before committing the cassette to github. Also, clear your BASH history (history -c on mac) or at least remove the line containing your password.

For an example see test "measure show with period or special chars in key" in bonnie/test/functional/measures_controller_test.rb