nazareno / covid-icu-monitor

Web service for tracking ICU statistics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

This is a web service for enabling ICU physicians in Ecuador to report statistics about bed availability, patients, personnel, and equipment/medicine. The hope is that this can help provide more up-to-date data for governing agencies to deal with the current Covid-19 pandemic.

Most of the fields in this web service are hard-coded for the requirements agreed upon with a number of leading ICU physicians in Ecuador, but it should be fairly simple to adapt to other use cases. See the instructions below on how to install and deploy this service.

Design

High-level diagram

The following diagram describes the system at a high level. CovidUCI design

Hospital administrators

The idea is that each hospital has a designated admin which is in charge of updating the statistics for their hospital on a regular basis. This is in part to reduce load on the server, but also to reduce the likelihood of incorrect data entry. The page for modifying hospital data looks something like this (data utilized is fake): Hospital update form

Ministry view

The ministry of health will then have access to a list of all registered hospitals: List of hospitals

and an aggregated view of the data for all the hospitals, with the most critical elements at the top: Complete hospital data

Chosen fields

The fields we have chosen to report are:

  • Patient statistics:
    • Number of admitted patients
    • Number of discharged patients
    • Number of deceased patients
  • Bed statistics:
    • Total number of beds in the ICU
    • Number of used beds
    • Number of unmet requests for beds
  • Personnel statistics (for physicians, nurses, auxiliaries, and respiratory therapists):
    • Number active
    • Number quarantined
    • Number tested positive for Covid-19
  • Supplies statistics, possible values are "Adequate", "Medium", "Critical", "Unavailable" (i.e. they ran out), and "No information available":
    • Respirators
    • ETT Tubes
    • Face masks
    • Personal Protective Equipment
  • Medicine statistics, same categories as for supplies. Lists the main medicines used in caring for patients.

Deploying your own

If you would like to deploy your own service, follow the instructions below. Some caveats before detailing the instructions:

  • This is not necessarily the best way to design such a service, but I wanted to be able to bring something up in a week's time, which thankfully I was able to do.
  • Given that this is meant for Ecuador (a Spanish speaking country), but I typically program in English, a lot of the code and comments are in "Spanglish".
  • The fields listed above are hardcoded, so you will have to update them for your specific use-case and language.

Installation instructions

  1. Start a new project or open an existing one on Google Cloud Platform.

  2. Make sure you have billing enabled in the Billing dashboard.

  3. Create a new VM instance in the Compute Engine dashboard.

  4. Choose machine type (the meatier, the more you'll get charged).

  5. Change Boot disk to Ubuntu 18.04 LTS.

  6. Select to allow both HTTP and HTTPS traffic.

  7. Once created, take note of the External IP. We will refer to this as ${IP} from now on.

  8. In Firewall rules, make sure you have rules allowing connections on ports tcp:80, tcp:8989 (HTTP) and tcp:443 (HTTPS) (with IP ranges: 0.0.0.0/0 in Filters).

  9. Connect to the device via ssh either by web ssh or using the gcloud command.

  10. Once connected to the machine, get the link from Miniconda, download it, and run it . For example:

    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    chmod +x Miniconda3-latest-Linux-x86_64.sh
    ./Miniconda3-latest-Linux-x86_64.sh
    
  11. Close and re-open your shell to make sure path variables are updated.

  12. Create a new conda environment and activate it:

    conda create -n coviduci python=3.7
    conda activate coviduci
    
  13. Once in the conda environment, run:

    git clone https://github.com/psc-g/coviduci-ec.git
    
  14. Run the following set of commands:

    cd coviduci-ec
    pip install -r requirements.txt
    pip install -e .
    
  15. Run mkdir ~/resources and copy the files ~/coviduci-ec/resources/coviduci.toml and ~/coviduci-ec/resources/coviduci.env to ~/resources, and modify the values appropriately.

  16. Run the script to populate the database. In addition to creating the hospitales, insumos, and medicaciones tables, this script will also prompt you to create display names and passwords for the administrator account, as well as an account for viewing aggregated hospital data (for example, for the ministry of health):

    python scripts/initialize_db.py --config=/home/${USER}/resources/coviduci.toml --dotenv_path=/home/${USER}/resources/coviduci.env
    
  17. It's a good idea to create a test copy of the config file and database (you can keep them in the same directory):

    cp ~/resources/coviduci.toml ~/resources/test.toml
    cp ~/resources/coviduci.db ~/resources/test.db
    

    In test.toml, update the value of sqlite_path to point to test.db.

  18. Run the test server:

    cd /home/${USER}/coviduci-ec
    python /home/${USER}/coviduci-ec/scripts/run_server.py --port 8989 --dotenv_path=/home/${USER}/resources/coviduci.env --config=/home/${USER}/resources/test.toml
    

    In your browser, go to http://${IP}:8989.

  19. Log in as the administrator. If you go to "Lista de hospitales" you will see that the admin and ministry accounts are listed as hospitals. To exclude these, modify the TEST_HOSPITALS variable in coviduci/www/handlers/admin.py.

  20. When logged in as the admin, click on "Agregar hospital" and add a new hospital. It's a good idea to add some fake tests ones to try out the system (and update TEST_HOSPITALS accordingly, as indicated above). Log out (by clicking on "Salir") and try logging in with the new hospital. If all of this works, we're ready to try to deploy the real server!

  21. Install certbot, instructions here, select Nginx for Software, and Ubuntu 18.04 LTS for System. Instructions will look something like:

    sudo apt-get update
    sudo apt-get install software-properties-common
    sudo add-apt-repository universe
    sudo add-apt-repository ppa:certbot/certbot
    sudo apt-get update
    sudo apt-get install certbot python-certbot-nginx
    
  22. Copy the nginx configuration files and modify them accordingly.

    sudo cp ~/coviduci-ec/resources/www.coviduci.com /etc/nginx/sites-available
    sudo ln -s /etc/nginx/sites-available/www.coviduci.com /etc/nginx/sites-enabled/www.coviduci.com
    
  23. Run sudo certbot --nginx and select www.coviduci.com (or whatever server name you chose). Once this is done, uncomment the ssl_certificate lines in /etc/nginx/sites-available/www.coviduci.com.

    • Note that for this to work, you need to have a registered domain name, and the IP mapping for this domain name needs to be the one for your virtual machine, otherwise certbot will fail.
  24. Copy the file ~/coviduci-ec/resources/coviduci.service to /lib/systemd/system/coviduci.service (you will need to run this as sudo). Modify the paths appropriately, to match your username.

  25. Ensure nginx is running (you should see a green "active (running)" line in the output:

    sudo systemctl status nginx
    
  26. Start your server!

    sudo systemctl status coviduci
    
  27. Once your site is up, it's probably best to test your changes by running the test server (see instructions above), and then restarting the real server. A useful way of restarting your server and seeing the output logs:

    sudo systemctl restart coviduci &&  tail /var/log/syslog  -n 100 -f-f
    
  28. Good luck!

Internationalization

Based on the tutorials of Alexey Evseev and Matt Layman.

To work on the i18n, you need to install gettext.

You also need to install Transifex client.

source <your-virtual-env-folder>/bin/activate
pip install transifex-client
  1. All text strings must be written in English.
  2. Use the following code to create an alias function to make strings translatable:
from tornado import locale

user_locale = locale.get()
_ = user_locale.translate
  1. Make strings translatable using the alias function _:
_('Example of translatable string')
_('Close the underscore function first. A {number}').format(number=42)

Strings from templates also need to be wrapped by the alias function:

{{ _('Example of translatable string') }} 
  1. Extract messages to messages.pot:
git pull
cd scripts/
chmod a+x ./make-pot.sh
./make-pot.sh
  1. Push POT to Transifex
tx push -st

At this point, you need to wait translations to be ready on Transifex.

  1. Pull translations from Transifex
tx push -a
  1. Compile the PO files
./compile-po.sh

About

Web service for tracking ICU statistics

License:Apache License 2.0


Languages

Language:HTML 62.1%Language:Python 33.6%Language:CSS 1.8%Language:JavaScript 1.2%Language:DIGITAL Command Language 0.7%Language:Shell 0.6%