Skip to content

dignio/tech-assessment-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tech-assessment-backend

Project Overview

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.

Setup Instructions

Prerequisites

  • Python 3.11 or newer
  • pip

Installation

  1. Clone the repository:
    git clone <your-repo-url>
    cd tech-assessment-backend
  2. Create a virtual environment (optional but recommended):
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt

Running the Application

Start the FastAPI server with:

uvicorn main:app --reload

The API will be available at http://127.0.0.1:8000

Running Tests

To run all tests and check your implementation:

pytest

Interview Task Description

First Part

Your task is to fix all broken tests and implement the average calculation for the measurements endpoint. Specifically:

  • Create your own branch from main to work on the task.
  • Run the tests using pytest to identify which tests are failing and why.
  • Run the test in test_measurments.py
  • Implement the logic for the /patients/{patient_id}/measurements endpoint 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: weight and height. 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 (see test_logs_created for 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.

Second Part (optional step if done in the first part)

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.

Notes

  • 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.

About

Private recruitment repository for candidate assessments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages