This proxy handles the OAuth authentication for the JS embedded widgets when they communicate with the FHIR API.
cp .env.example .env
Once you have copied the example, go into .env
and replace the environment variables with valid values from your Canvas instance.
Note that you should register your patient app as a third-party app associated with your canvas instance. The CLIENT_ID
and CLIENT_SECRET
needed in your .env
file is from your created third-party app. Here are instructions on how to register a new app.
With Docker
If you're building the docker containers for the first time, or if you know a dependency has been added (e.g., ruby gem), run this:
docker-compose build
Once the containers have been built, starting the app is just:
docker-compose up
# And a shortcut for rebuilding containers while spinning them up at the same time:
docker-compose up --build
# Set up the test database
docker-compose run --rm -e RAILS_ENV=test app ./bin/rails db:create db:migrate
# Run specs
docker-compose run --rm app rspec
# Run specs while checking coverage
docker-compose run --rm -e COVERAGE=1 app rspec
# Check for exceptions:
bundle exec rubocop
# Let Rubocop autocorrect things
bundle exec rubocop -A
Running Locally
-
If you have
asdf
installed,.tool-versions
is set up for the Ruby version. -
Redis
-
Check for existing Redis by running
redis-server --version
-
If Redis isn't installed, install it! If on macOS, with Homebrew installed (above) run
brew install redis # have launchd start Redis now and restart at login brew services start redis # confirm that Redis started successfully brew services ls
-
If you don't have Bundler installed for Ruby:
gem install bundler
Install dependencies:
# Install Ruby gems:
bundle install
bundle exec rails server
Then open http://localhost:3000 with your favorite internet browser.
bundle exec rspec
Optionally, run the suite and check coverage:
COVERAGE=1 bundle exec rspec
# wait for specs to run, and then:
open coverage/index.html
# Check for exceptions:
bundle exec rubocop
# Let Rubocop autocorrect things
bundle exec rubocop -A
To deploy:
We recommend using Aptible to deploy your proxy app. Aptible uses the resulting Docker Image to run Containers for your App. Everything you need to deploy this proxy to Aptible is in this /proxy directory. All you need to do is:
- From
/proxy
rungit init
- In
proxy/config/environments/development.rb
uncommentconfig.hosts << "yourproxyurl.com"
and add the url for your proxy. git commit -m "init commit"
- Follow the steps in this Aptible Ruby quick start guide to create a new app within an existing Aptible environment.
- Make sure to set the app config in this step with your environmental variables in .env.
- Once you deploy, you can add an endpoint with a specific CNAME.
Your proxy will then be available using the url endpoint you just created.
If you would like to deploy your proxy using another service that requires a file upload, you can run the following to produce a zip file to upload:
mkdir deploy
zip -r deploy/deploy_proxy.zip .
In order to retrieve the patient_key
required for all FHIR API requests:
- Call the
/Auth
endpoint withkey
andpatient
parameterskey
is the API key stored as an environment variable on the proxy which is then provided to the customer.patient
is the patient's ID.- This would look like http://your-proxy-url.com/Auth?key=YOUR_API_KEY_HERE&patient=YOUR_PATIENT_ID_HERE, with
YOUR_API_KEY_HERE
andYOUR_PATIENT_ID_HERE
replaced. - Assuming a valid API key, this endpoint will return a response with a body like
{"patient_key":"YOUR_PATIENT_KEY_HERE"}
whereYOUR_PATIENT_KEY_HERE
is what you will need for thepatient_key
parameter for all your other requests.