This is a RESTful API to utilize an internationally recognized set of diagnosis codes built with Django, DRF, Docker and Postgres as the main database.
- Docker
- Docker Compose
-
Clone the repository into a folder of your choice:
git clone https://github.com/jayjaychukwu/diagnosis-test.git
-
Create a .env file in the project root directory and set the following environment variables, please adjust the values to fit your environment:
SECRET_KEY=<random-secret-key> DEBUG=True DB_NAME=<a-database-name> DB_USER=postgres DB_PASSWORD=postgres
-
Spin up the project using Docker Compose:
Either you use
docker-compose up
and spin up another terminal to run the next set of commands or you run it in the background using
docker-compose up -d --build
-
Create a database with the same value as in environment variable, DB_NAME
obtain the name of the database container running using the command:
docker ps
it should be something like <project_name>_db_1. Example: "diagnosis-test_db_1".
Then run this command to create the database
docker exec -it <postgres-container-name> createdb -U postgres <db-name>
You can ensure the database was created by running
docker exec -it <my_postgres_container> psql -U postgres -c '\l'
and check if the database name is in the list of databases.
-
Restart the web service for the update to take effect
docker stop <project_name>_web_1 docker start <project_name>_web_1
or you could just stop all the services and spin it up again
docker-compose down docker-compose up -d --build
-
Make migrations for the dx app and migrate
docker-compose run web python manage.py makemigrations dx docker-compose run web python manage.py migrate
-
You can populate the database with DiagnosisCode records using a valid ICD-10 csv file. There is an example in the project root, testicd.csv, you can use the "createdata" command with "-f" or "--file" arguments with the path to the file. Example:
docker-compose run web python manage.py createdata --file testicd.csv
-
To create a superuser for the admin dashboard, run the following command:
docker-compose run web python manage.py createsuperuser
Follow the prompts to create a superuser account. Access the admin dashboard at
http://localhost:8000/admin/
and log in using your superuser credentials. -
Run tests for the project using the following command:
docker-compose run web python manage.py test
- Swagger Docs:
http://localhost:8000/
- ReDoc:
http://localhost:8000/redoc/
The project follows a Django architecture and utilizes the Django REST Framework for building the API. Docker is used for containerization, providing an isolated and consistent environment for development and deployment.
Caching has been implemented in the project using Django's caching mechanisms. Decorators such as cache_page have been applied to specific endpoints, such as list and retrieve operations, to improve performance by storing the response data in memory. This helps reduce the need for executing the same expensive database queries or computations repeatedly, resulting in faster response times for subsequent requests.
The project leverages the transaction.atomic() method provided by Django's database API to ensure atomicity and improve performance. By encapsulating a block of code for uploading CSV files within transaction.atomic(), all database operations within that block are executed as a single transaction. This approach reduces the number of round trips between the application and the database server, leading to improved performance and efficiency. Additionally, it helps maintain data consistency and integrity by rolling back the entire transaction if any operation within the block fails, preventing partial updates and keeping the database in a consistent state.
By employing caching and utilizing transaction atomicity, the project optimizes performance, reduces database round trips, and ensures the reliability and integrity of data operations.
- Remember to always spin down your docker containers after you are done because they can consume a lot of memory.
Please feel free to reach out to me or raise an Issue if you run into any problems running this project.