Skip to content

Healthcare system with Raspberry Pi, PostgreSQL, Docker, Flask, GraphQL, and Flutter.

License

Notifications You must be signed in to change notification settings

david-slatinek/kf34

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project logo

Table of Contents

About

Healthcare system with Raspberry Pi, PostgreSQL, Docker, Flask, GraphQL, and Flutter.

The project consists of 4 main components:

  • Data capture from the sensors using Raspberry Pi
  • Database for data storage
  • API for storing and retrieving data
  • Mobile app for displaying the values

Project infrastructure: Project infrastructure

Project units

Raspberry Pi

Raspberry Pi Python

Raspberry Pi is responsible for getting the data from the DHT22 sensor (temperature, humidity) every 15 minutes - using cron. After that, it uploads data to the API by calling an appropriate mutation:

mutation AddData($value: Float!, $device_type: DeviceType!) {
    addData(value: $value, device_type: $device_type) {
        success
        error
    }
}

In case of errors, the LED is turned on. In addition, Raspberry Pi also sends an email, and thus notifies the system admin about the occurred error with the following syntax:

Error: <error>
Date: <date of error>

Sensor schematic:

Raspberry Pi wiring

In addition, the system uses the following sensors:

  • MAX30102 - heart rate and oxygen level
  • AD8232 - ECG
  • MAX30205 - body temperature

More circuit design images can be seen here.

Database

PostgreSQL diagrams.net

For the relational database management system, we choose PostgreSQL. In the database, we are storing information about the device and data capture.

ER diagram can be seen in the following image:

ER diagram

API

Docker Shell Script Heroku Bash Python Flask JSON GraphQL Curl Postman

The API was made with a python framework flask with GraphQL and returns data in JSON format. The API is hosted on Heroku and runs inside a docker container. To make the API production-ready, we used the gunicorn server.

We use API keys along with the HTTPS protocol - provided by Heroku to prevent unauthorized access.

Main method:

def valid():
    return False if request.headers.get('X-API-Key') != app.config["KEY"] else True

def invalid_req(message, code):
    return jsonify({'error': message, 'success': False}), code

@app.route("/graphql", methods=["POST"])
def graphql_server():
    if not valid():
        return invalid_req('api key not given or invalid', 401)

    data = request.get_json()
    
    success, result = graphql_sync(
        schema,
        data,
        context_value=request,
        debug=app.debug
    )
    return jsonify(result), 200 if success else 400

App

Flutter Dart

The mobile app was made with Flutter and Dart. The main app functionality is getting data from the API and displaying it.

The app features the latest, average, median, standard deviation, all today's values along with maximum and minimum values. It also includes a graph with all today's values. It can also download a PDF file with data for a given measurement.

More images can be seen here.

App video

Large-scale infrastructure

Large-scale project infrastructure

Further reading

This project is a part of my thesis. The entire document is available here.