This project is a FastAPI-based REST API for managing patients and their medical measurements. It uses SQLite as the database and SQLAlchemy as the ORM. The API allows you to create, retrieve, and delete patients, as well as add and retrieve their measurements.
- Python 3.11 or newer
- pip
- Clone the repository:
git clone <your-repo-url> cd tech-assessment-backend
- Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
Start the FastAPI server with:
uvicorn main:app --reloadThe API will be available at http://127.0.0.1:8000
To run all tests and check your implementation:
pytestYour task is to fix all broken tests and implement the average calculation for the measurements endpoint. Specifically:
- Create your own branch from
mainto work on the task. - Run the tests using
pytestto identify which tests are failing and why. - Run the test in
test_measurments.py - Implement the logic for the
/patients/{patient_id}/measurementsendpoint so that when a new measurement is added, the response includes the average of the last three measurements of the same type for that patient (as shown in the tests). - Make sure our backend supports only two types of measurements:
weightandheight. If a different type is provided, the API should return a 400 status code. - Run the test in
test_logs.py - Implement a custom logging system that logs all API requests and responses to a file named
app.log. It should include request duration (seetest_logs_createdfor details). - (Optional) Run the tests in
test_patient_functionality.py - Commit your changes and push your branch to the repo.
Tip: Review the test files for detailed requirements and expected behaviors.
In the second part imagine that you are doing a code review for a colleague who has implemented that project. Add your comments and suggestions to the codebase (refactor, code improvements, etc).
Note: If you notice any areas for improvement while working on the codebase, feel free to add your comments and code suggestions as you go.
- The database file (
test.db) and log file (app.log) are ignored by git (see.gitignore). - Foreign key constraints must be enforced in SQLite.
Good luck! If you have any questions, please ask your interviewer.