Here’s a summary of my initial understanding of this undertaking for posterity and assistance in planning. Copied from a slack conversation so it looks pretty conversational.
I think this would be a very popular feature so I believe it would do well to be integrated into the core openemr codebase instead of as a module.
There’s a couple things that should need to happen to for an administrator to enable usage. Under Administration → Globals → Features menu you’d want to add a checkbox that says something like “enable fitbit via onsite patient portal”
That might initiate something like a popup directing them to the Administration → globals → portal menu and tell them to enable onsite portal access by clicking the checkbox and configuring the site address if they haven’t already.
You’ll want to add a setting which is autopopulated by the text from the onsite portal address followed by something like https://yourwebsite.com/openemr/portal/fitbitAuthentication you might need http instead of https based on their settings. Then provide instructions on how to have them register their clinic for access to fitbit’s web API. To do that see: 2. Register your application to get API client credentials.
https://dev.fitbit.com/build/reference/web-api/
They will need to create a fitbit account for their clinic.
To add the menu items/checkboxes you’ll probably want to see /openemr/interface/super/edit_globals.php @sunsetsystems appears to be the author of this file so you may want to ping him about adding a new feature to this screen.
Once the clinician has turned on the patient portal and said they’d like to enable fitbit access then you’ll want to focus on writing code to obtain patient permissions. Next you’ll want to look at code in the openemr/portal directory. @sjpadgett did a lot of work on the onsite patient portal so hopefully he can be a resource when integrating your code into the portal.
The way patient permission works is you have a patient click a link that directs them to a the fitbit’s login page where they select what information to share and they send back an access token via oauth to the site specified in the fitbit api access application they filled out earlier. There are some different permission options so you’ll want to store what fitbit data the user gave permissions for. E.g just sleep, everything but GPS data, etc. in a mySQL table somewhere along with the token. This exchange takes place via OAuth2.
There’s this repository called guzzle. I think it can handle some of the oauth stuff for you. I believe it’s located in openemr/phpfhir/vendor/guzzlehttp
However, there’s plenty of other example implementations of fitbit api authentication using php and javascript linked above.
To test authentication and access, you’ll need access to a fitbit account (ideally a physical fitbit,I have a spare and can enter data for you) and a public IP. If you put in a pull request on github and put your code in it, @brady.miller should be able to help you put an OpenEMR instance with your code online in the “demo farm”
https://www.open-emr.org/wiki/index.php/Development_5.0.2_Demo
https://community.open-emr.org/t/demo-farm-and-up-for-grabs-demos-are-back/8919
You’ll want to write code to pull the new data from the fitbit servers at some frequency, perhaps every day, every week, or maybe even a custom frequency per patient.
There is another option, called the fitbit subscriptions web API, this is where you “subscribe” to patient fitbit data and the fitbit server automatically tells you when there’s new data available. You can probably skip this unless it’s easier for you.
https://dev.fitbit.com/build/reference/web-api/subscriptions/
You’ll need to maintain a table of patients, their tokens, and data access permissions in the mySQL database along with different tables for their data referenced by patient ID(pid) I’m pretty good with MySQL and can help with this part.
For plotting of the data you import you can try chart.js. You can load it by importing globals.php it’s in directory openemr/interface/globals.php Your code will be running in openemr/portal/some other directory so you’ll need to go up a few directories to openemr and down into /interface to grab the what you need from globals.php. It and other repositories are stored in a directory openemr/public/assets
One you get the data in the fun part starts. You can make a new tab on the patient dashboard. Or maybe use the pre-existing external data tab.
The pictured image is generated by:
/openemr/interface/patient_file/summary/demographics.php
Hope this helps,
-Rachel