Skip to content

feat: Open Wearables integration proof-of-concept#345

Draft
travis-sauer-oltech wants to merge 9 commits intomainfrom
feat/ow-poc
Draft

feat: Open Wearables integration proof-of-concept#345
travis-sauer-oltech wants to merge 9 commits intomainfrom
feat/ow-poc

Conversation

@travis-sauer-oltech
Copy link
Copy Markdown
Member

Summary

Adds a complete proof-of-concept integration between JupyterHealth Exchange (JHE) and Open Wearables (OW), enabling patients to connect wearable devices (Oura, Garmin, etc.) through JHE's existing invite-link flow.

What Changed

Backend - Proxy API (core/views/ow.py)

Endpoint Method Purpose
/api/v1/ow/users POST Creates/finds OW user for authenticated JHE user; stores ow:<user_id> in JHE identifier field
/api/v1/ow/providers GET Proxies OW provider list (enabled, cloud-API providers with icons)
/api/v1/ow/oauth/<provider>/authorize GET Generates OAuth authorization URL for any OW provider
/api/v1/oauth/<provider>/callback GET Proxies OAuth callback from provider back to OW for token exchange

Config is read from JheSetting DB records (ow_api_base_url, ow_api_key).

Frontend - Client Flow (core/static/js/)

  • common.js - New shared utilities: parseInvitationCode(), exchangeCodeForToken(), base64UrlEncode()
  • ow-client.js - Full client-side orchestration:
    1. Parse invite link and exchange auth code for JHE token
    2. Fetch user profile + study consents from JHE
    3. Create OW user via proxy (seamless, no separate login)
    4. Fetch and display available wearable providers
    5. Cross-reference JHE study data sources with OW providers
    6. Render provider picker grid with provider icons
    7. Handle OAuth redirect to provider and completion

Templates

  • base_ow_client.html - Base template with Bootstrap 4, Bootstrap Icons, common scripts
  • launch.html - Landing page with status spinner, provider picker grid, integration log panel
  • complete.html - Success page after OAuth completion

URL Routes

  • /ow/ - Launch page (invite link entry point)
  • /ow/complete - Post-OAuth completion page

Integration Log Panel

Terminal-style debug panel rendered during the flow showing:

  • Token exchange status
  • Study enrollment and consent details
  • Data source/device cross-reference with OW providers
  • Provider availability

End-to-End Flow

  1. Patient visits /ow/?code=<invitation_code>
  2. JS parses invite code, exchanges for JHE access token
  3. Fetches profile + study consents, creates OW user
  4. Displays provider picker grid
  5. Patient selects provider -> redirected to provider OAuth
  6. Provider redirects back -> JHE proxies callback to OW
  7. Success page confirms device is connected
  8. OW handles ongoing data sync in background

Test Coverage

  • tests/test_ow_integration.py - 257 lines covering:
    • User creation (auth, conflicts, error handling)
    • Provider authorization (missing account, custom redirect_uri)
    • Config validation (missing/partial settings)
    • All endpoints return proper error codes for edge cases

Files Changed

File Change
core/views/ow.py New - proxy endpoints
core/static/js/ow-client.js New - client orchestration
core/static/js/common.js New - shared utilities
core/templates/ow_client/launch.html New - launch page
core/templates/ow_client/complete.html New - completion page
core/templates/partials/base_ow_client.html New - base template
core/templates/partials/base.html Modified - minor updates
core/urls.py Modified - added OW routes
core/views/common.py Modified - added view functions
tests/test_ow_integration.py New - integration tests

s1monj and others added 9 commits March 30, 2026 16:17
- POST /api/v1/ow/users: create/find user in Open Wearables, store OW user_id
- GET /api/v1/ow/oauth/oura/authorize: proxy Oura OAuth through OW
- ow-client.js: implement steps 1-8 (parse invite, token exchange, OW user
  creation, Oura auth redirect)
- common.js: extract parseInvitationCode and exchangeCodeForToken utilities
- launch.html: replace TODO comments with actual implementation

Ref #331
Add 16 unit tests covering:
- TestCreateOwUser: auth, settings validation, user creation, conflict handling, error cases
- TestOuraAuthorize: auth, user validation, settings, URL retrieval, redirect_uri, errors
- TestOwConfig: missing/partial settings

All tests pass with DRF camelCase response rendering.
… names in OW client JS

- common.js: Use window.location.origin for token endpoint instead of bare
  host (which lacks protocol prefix)
- ow-client.js: Use /auth/callback redirect_uri to match Grant's stored URI
- ow-client.js: Use camelCase property names (owUserId, authorizationUrl) to
  match DRF CamelCaseJSONRenderer output
- Add provider picker grid UI in launch.html
- Generalize oura_authorize → provider_authorize (any provider)
- Add list_providers proxy endpoint
- Add provider_callback_proxy for any provider
- Update complete.html with success UI
- Update ow-client.js with provider grid rendering and selection
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