metadata
title: MediCode
sdk: docker
pinned: false
Medicode
Getting started
Prerequisites
- ffmpeg for audio processing in Bumblebee's speech-to-text serving:
brew install ffmpeg
. - Postgres and pgvector for storing data and vector embeddings:
brew install pgvector
.
Running the server
To start your Phoenix server:
- Run
mix setup
to install and setup dependencies - Run
mix build_code_vectors
to download the ICD-9 codelist, precompute vectors, and store the results in the database. - PDF generation is managed with ChromicPDF which assumes an executable is available at these locations. If you are having trouble getting Chrome to launch, this StackExchange was useful.
- Start Phoenix endpoint with
mix phx.server
or inside IEx withiex -S mix phx.server
Now you can visit localhost:4000
from your browser.
Ready to run in production? Please check our deployment guides.
Deployment
The app is configured to deploy to Fly.io via a fly.toml
file. To deploy, run fly deploy
within the app's directory.
Precomputing code vectors
To build the code vectors for the ICD-9 codelist for the deployed environment:
- Connect to the server with
fly ssh console
. - Run
/app/bin/medicode eval Medicode.Release.precompute_code_vectors
. This will prepare the vectors in the database if they are not present.
Livebook
In addition to connecting to the deployed application via iex
, Livebook supports connecting to the running application. Connecting a Livebook instance to the deployed application involves the following:
- Install and setup Wireguard with a peer connection for Fly.io: Step by Step
- Install and start Livebook: Livebook.dev
- Connecting Livebook to a Production App requires a node name and cookie value:
- Node name:
medicode@myipfromfly
("myipfromfly" can be retrieved withfly ips private --app medical-transcription-cpu
) - Cookie value:
0gfxcPtwryKxI2O1N0eFAg9p4MJGC-oUGShgj_wgvNEGiba5EDEJFA==
(this value is set infly.toml
)
Run in Docker
- Create a local volume:
docker volume create ml-data
- Ensure the volume is writeable:
docker run --rm -v ml-data:/data busybox /bin/sh -c 'touch /data/.initialized && chmod 1777 /data'
. More background:
- What the initial
1
forchmod
means: https://www.linuxnix.com/sticky-bit-set-linux/ - How to update the permissions of a mounted volume: https://serverfault.com/a/984599
- Build the image with:
docker build . -t headwayio/medicode
- Run a container with:
docker run --env-file ./.env -p 4000:4000 headwayio/medicode
Caveats
You may need to make a few changes to get the app running in Docker at the moment:
- In
lib/medicode/application.ex
, comment out theDNSCluster
child spec. - In
rel/env.sh.eex
, comment out theERL_AFLAGS
,RELEASE_DISTRIBUTION
, andRELEASE_NODE
environment variables.
Learn more
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix