AugMed is a web application, built for the UNC-Chapel Hill DHEP Lab, that allows the lab to collect data from participants in a user-friendly way. The app is designed to be used on any devices, and it allows participants to answer questions about their judgements for cases with potential Colorectal Cancer (CRC). The app is built using React, and the backend API is built using Flask and Python.
Clone the repository if you haven't done so already, then follow these steps to set up your local environment:
-
Install Python
Use the following command to install Python:
brew install [email protected]
After installation, verify the new version by running:
python3 --version
-
Install Pipenv
Pipenv is used to manage dependencies as it can automatically generate the
Pipfile.lock
, unlikevirtualenv
which requires manual generation ofrequirements.txt
.pip install pipenv
For installing further dependencies, use
pipenv install <package>
instead ofpip install <package>
to manage the dependencies efficiently. -
Docker
Ensure Docker is installed and running locally on your machine.
-
Python Path
In the root path of the project, set the
PYTHONPATH
by running:export PYTHONPATH=$(pwd)
To run the application locally, follow these steps:
Note: Ensure you have activated your pipenv shell by running
pipenv shell
.
- Ensure all dependencies are installed using Pipenv.
pipenv install
- Start your Docker containers if the application requires any external services like databases.
- Use the following command to run the application under the
src
directory:Adjust the command based on your application's entry point if different.flask run
- Alternatively, run the following command to start the application, at the root path of the project if there is any port conflict on your machine:
flask run --host=127.0.0.1 --port=5001
NOTE: If your frontend is also running, ensure it is configured to communicate with this backend API. You may need to set the API URL in your frontend configuration. Also, you might need to use CORS (Cross-Origin Resource Sharing) if your frontend and backend are served from different origins. You can use the
flask-cors
package to handle this:pipenv install flask-corsThen, in
src/__init__.py
, add:from flask_cors import CORS # Then, after declaring `app` in the same file: CORS(app, origins=["http://localhost:3000"], supports_credentials=True, expose_headers=["Authorization"],)This will allow your frontend to make requests to the backend without running into CORS issues.
Pytest discovers tests following these naming conventions:
test_*.py
*_test.py
For more details, visit pytest documentation.
Execute your tests by running:
pytest
Ensure you are in the project's root directory or specify the tests' path.
To maintain code quality and consistency, run linting tools such as flake8 or pylint. Install your chosen linter via pipenv, then run it across your project. For example, with flake8:
pipenv install flake8
flake8 src
To set up the local database, firstly export the var in .env
to local. Then run:
docker-compose up -d
And add a .env file in the root follow the .env_example
Database migration scripts are managed with Flask-Alembic under the src/migrations
folder.
To modify the schema, use the following commands under the src
:
flask db init # Only needed the first time to create the migration repository.
flask db migrate -m "Create user table"
flask db upgrade # Execute this if you pull new changes that alter the schema remotely.
Configure your local hooks as follows:
git config core.hooksPath .githooks
This will ensure that your local git hooks are used instead of the default ones. You can find the hooks in the .githooks
directory.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.