mere-medical logo

mere-medical

cfu288/mere-medical

An offline-first, self-hosted web app to aggregate and sync all of your medical records from your patient portals in one place.

330stars +2 this week TypeScript MIT last commit 3 days, 12 hours ago
README.md

Mere Medical

A personal health record to aggregate and sync all of your medical records from multiple patient portals in one place. Currently supports thousands of hospitals and clinics and major electronic medical record systems. Self-hosted, privacy-focused, and offline-first.

Deploy to DO

Build Status licence release docker image size sponsor

What is Mere Medical

Mere Medical is a self-hosted web app to aggregate and sync all of your medical records from all your doctor and hospital visits in one place. See everything in a timeline view or quickly summarize your records.

[!NOTE]
Mere is currently pre-release software: updates may break backwards compatibility. Mere has been "pre-release software" since 2022. That probably says more about my fear of committing to an official release than a reflection of Mere. Will avoid breaking backwards compatibility where reasonable.

This project is supported by a single developer who is also a full-time medical resident. If you would like to support this project, please consider donating to help with hosting costs or help by tackling one of the open issues.

Getting Started

Here are some ways to get Mere Medical running on your local computer

Docker Compose

services:
  app:
    image: cfu288/mere-medical:latest
    ports:
      - '4200:8080'
    environment:
      - ONPATIENT_CLIENT_ID=${ONPATIENT_CLIENT_ID}
      - ONPATIENT_CLIENT_SECRET=${ONPATIENT_CLIENT_SECRET}
      - EPIC_CLIENT_ID=${EPIC_CLIENT_ID}
      - EPIC_CLIENT_ID_DSTU2=${EPIC_CLIENT_ID_DSTU2}
      - EPIC_CLIENT_ID_R4=${EPIC_CLIENT_ID_R4}
      - EPIC_SANDBOX_CLIENT_ID=${EPIC_SANDBOX_CLIENT_ID}
      - EPIC_SANDBOX_CLIENT_ID_DSTU2=${EPIC_SANDBOX_CLIENT_ID_DSTU2}
      - EPIC_SANDBOX_CLIENT_ID_R4=${EPIC_SANDBOX_CLIENT_ID_R4}
      - CERNER_CLIENT_ID=${CERNER_CLIENT_ID}
      - VERADIGM_CLIENT_ID=${VERADIGM_CLIENT_ID}
      - VA_CLIENT_ID=${VA_CLIENT_ID}
      - HEALOW_CLIENT_ID=${HEALOW_CLIENT_ID}
      - HEALOW_CLIENT_SECRET=${HEALOW_CLIENT_SECRET}
      - ATHENA_CLIENT_ID=${ATHENA_CLIENT_ID}
      - ATHENA_SANDBOX_CLIENT_ID=${ATHENA_SANDBOX_CLIENT_ID}
      - NEXTGEN_CLIENT_ID=${NEXTGEN_CLIENT_ID}
      - NEXTGEN_CLIENT_SECRET=${NEXTGEN_CLIENT_SECRET}
      - APP_KEY=${APP_KEY}
      - ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS=${ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS}
      - PUBLIC_URL=${PUBLIC_URL}

(back to top)

Local Development

Prerequisites

  • npm
  • nvm
  • Docker
  • nx

Installation

  1. Clone the repo

    git clone https://github.com/cfu288/mere-medical.git
    
  2. Set up NPM and install NPM packages

    nvm install v26.7.0
    nvm use
    npm install
    
  3. If Nx is not installed, install it

    npm i nx -g
    

    if you are prompted to run migrations, run the following:

    npx nx migrate --run-migrations
    
  4. Create .env files for each project to run and fill with values

    cp apps/api/.example.env apps/api/.env
    
    vim apps/web/src/environments/config.json
    
  5. Generate localhost ssl certs

    mkdir -p .dev/certs
    mkcert -key-file .dev/certs/localhost-key.pem -cert-file .dev/certs/localhost.pem localhost
    mkcert -install
    
  6. Serve each one on its own:

    npx nx serve web
    npx nx serve api
    

    or together as a full app:

    npx nx run-many --target=serve --projects=api,web --output-style=stream
    
  7. Run e2e tests

    npx nx run web-e2e:e2e
    
  8. Build and serve in docker container:

    docker build -t mere-medical .
    docker run -p 4200:8080 -i -t \
      --name mere-medical \
      -e ONPATIENT_CLIENT_ID=<ID_HERE> \
      -e ONPATIENT_CLIENT_SECRET=<ID_HERE> \
      -e EPIC_CLIENT_ID=<ID_HERE> \
      -e EPIC_CLIENT_ID_DSTU2=<ID_HERE> \
      -e EPIC_CLIENT_ID_R4=<ID_HERE> \
      -e EPIC_SANDBOX_CLIENT_ID=<ID_HERE> \
      -e EPIC_SANDBOX_CLIENT_ID_DSTU2=<ID_HERE> \
      -e EPIC_SANDBOX_CLIENT_ID_R4=<ID_HERE> \
      -e CERNER_CLIENT_ID=<ID_HERE> \
      -e VERADIGM_CLIENT_ID=<ID_HERE> \
      -e VA_CLIENT_ID=<ID_HERE> \
      -e HEALOW_CLIENT_ID=<ID_HERE> \
      -e HEALOW_CLIENT_SECRET=<SECRET_HERE> \
      -e ATHENA_CLIENT_ID=<ID_HERE> \
      -e ATHENA_SANDBOX_CLIENT_ID=<ID_HERE> \
      -e NEXTGEN_CLIENT_ID=<ID_HERE> \
      -e NEXTGEN_CLIENT_SECRET=<SECRET_HERE> \
      -e APP_KEY=<KEY_HERE> \
      -e PUBLIC_URL=https://localhost:4200 \
      mere-medical:latest
    

    Note the following environment variables can be provided:

Variable Required Description Example
PUBLIC_URL Yes Full URL where Mere Medical is accessible. Must include protocol (https:// or http://). https://app.meremedical.co
ONPATIENT_CLIENT_ID No Client ID for OnPatient/DrChrono See OnPatient setup
ONPATIENT_CLIENT_SECRET No Client secret for OnPatient/DrChrono See OnPatient setup
EPIC_CLIENT_ID_R4 No Client ID for Epic MyChart production (recommended) See Epic setup
EPIC_SANDBOX_CLIENT_ID_R4 No Client ID for Epic MyChart sandbox (recommended) See Epic setup
EPIC_CLIENT_ID No Client ID for Epic MyChart production (legacy DSTU2, for backwards compatibility) See Epic setup
EPIC_CLIENT_ID_DSTU2 No Client ID for Epic MyChart production (legacy DSTU2) See Epic setup
EPIC_SANDBOX_CLIENT_ID No Client ID for Epic MyChart sandbox (legacy DSTU2, for backwards compatibility) See Epic setup
EPIC_SANDBOX_CLIENT_ID_DSTU2 No Client ID for Epic MyChart sandbox (legacy DSTU2) See Epic setup
CERNER_CLIENT_ID No Client ID for Cerner Health (supports both R4 and DSTU2) See Cerner setup
VERADIGM_CLIENT_ID No Client ID for Veradigm
VA_CLIENT_ID No Client ID for VA (Veterans Affairs). Only works with the VA sandbox, not production access at this time.
HEALOW_CLIENT_ID No Client ID for Healow (eClinicalWorks) See Healow setup
HEALOW_CLIENT_SECRET No Client secret for Healow confidential client (enables refresh tokens) See Healow setup
ATHENA_CLIENT_ID No Client ID for Athena Health production See Athena setup
ATHENA_SANDBOX_CLIENT_ID No Client ID for Athena Health sandbox (Preview) See Athena setup
NEXTGEN_CLIENT_ID No Client ID for NextGen Enterprise See NextGen setup
NEXTGEN_CLIENT_SECRET No Client secret for NextGen Enterprise. Required alongside the client ID. The server keeps it. See NextGen setup
APP_KEY If you set a client secret Private secret that signs the registration token in invite links. Exactly the 32 characters generate-app-key prints. Never share it. See App key
APP_CONTACT No Who users should ask for an invite link, such as an email address. Shown in the app when a registration token is missing or refused. admin@example.com
ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS No Set to true to run those routes without a registration token. See App key

(back to top)

App key

If you run Healow, NextGen, or OnPatient with its client secret, the API refuses to start until you also set APP_KEY or ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS=true. Since when running the API these endpoints are public, this prevents untrusted third-party applications utilizing your app registrations without your consent to avoid abuse. If you do not mind third-party applications potentially using your app registration, you can set ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS=true instead.

To set an APP_KEY, follow these steps.

  1. Generate a key with docker compose run --rm app generate-app-key, or npm run generate-app-key in a source checkout.
  2. Add the line it prints to .env, add APP_KEY to the environment list of your compose file, then recreate the container.
  3. Print the invite link with docker compose run --rm app generate-invite-link, or npm run generate-invite-link in a source checkout. This should return something along the lines of Invite link: https://mere.example.com/#registration-token=3ebnq9Avix4S-QZ4rLC47V-crei4F3IT7PqAOFSlCeA. The link carries a registration token signed with your key, not the key itself.
  4. Send that invite link to each person you would like to grant access to your Healow, NextGen, or OnPatient registration for your instance. Opening the link saves the registration token in their browser. Without it, the app blocks those connections. Never share APP_KEY itself.

To issue a new registration token via invite link, set a new APP_KEY via the CLI and recreate the container. Then re-share the new link from generate-invite-link with your app users. If you would like to skip the app-key creation process for new users, you can set ALLOW_PUBLIC_CONFIDENTIAL_CLIENTS=true instead. See the app key docs.

Design Goals

  1. Respect user autonomy and user control.
  2. Prioritize privacy/security and UX - if those are in conflict, ask the user what they would prefer but default to security.
  3. Be transparent about decisions on data storage, handling, and usage.
  4. Where feasible, build features to be local first (run on the users device). This essentially means client side/offline first. Mere's core functionality should continue to work without any internet connection.
  5. For features that cannot be client-side, enable users to self-host server side functionality where feasible. This means that the user should be able to run Mere on their own server and not rely on a third party.
  6. Optionally fall back to third party services when self-hosting is not feasible. Should only apply to features that are not core functionality and should always be opt-in.

(back to top)