Benedetti code

@ruby | $php | javaScript;

Personal Physical Therapy application

Case Study

Personal Physical Therapy is a Node.js prototype.
Purpose: an introduction to a prospective software to measure the progress of a personal physical therapy


Welcome to my case study! Here is a brief introduction with some of the reasons that led me to develop it: during my work years for a medical device company, I realised implied and essential aspects of the healthcare sector, for instance a reliable traceability of the events, the carefulness towards the sensitive data privacy, or even the pursuit of the best balance between innovative options and sustainable technological solutions… But first of all the culture of the patient's health care and the communication among the medical industry professionals and their patients, the subject of this case study.


The prototype code of this case study and all the other related information must be intended as a good starting point, even if they remain hypothetical and not exhaustive of a real development.

Software Requirements Specification

This might be intended as the core part of a wider collection of the User Functional Requirements:

  • Application for patients of physiotherapists who need a sports preparation or postural gymnastics

The physiotherapist can
  • create a tailored program to assign to the patient
  • edit the tasks that compose the tailored program
The patient can
  • access the complete tailored program
  • record the completion of the tasks
  • export the program results in pdf to share it with other people, i.e. his coach, his family doctor, the physiotherapist himself and so on
The system must
  • allow a role-based access to the application
  • collect and display the tailored program and its task completion
  • collect the progress of each tailored program along with notes such as potential encountered issues for a therapy optimisation purpose

Design and Development notes

It is a web application with restricted access to preset user roles: physiotherapist and patient.
The user management depends on the intended use of this software, some sample:
  • is it intended to be distributed to a set of clinics? The clinic staff can assign roles to the users through a dedicated administrative area
  • is it an open system? Users can register on a self-service website/app

Database schema

MongoDB database schema


Table of the CRUD operations with permissions per role

  Physiotherapist Patient
  C R U D C R U D
User   ✔️       ✔️    
Therapy Program ✔️ ✔️ ✔️ ✔️   ✔️    
Task ✔️ ✔️ ✔️ ✔️   ✔️    
Completion         ✔️ ✔️ ✔️ ✔️
  C R U D
User   ✔️    
Therapy Program ✔️ ✔️ ✔️ ✔️
Task ✔️ ✔️ ✔️ ✔️

  C R U D
User   ✔️    
Therapy Program   ✔️    
Task   ✔️    
Completion ✔️ ✔️ ✔️ ✔️


router.get('/', ensureAuthenticated, (req, res) => { ... })

router.get('/login', (req, res) => { ... })'/login', (req, res, next) => { ... })
router.get('/logout', (req, res) => { ... })

// THERAPY PROGRAM'/therapyprograms/new', ensureAuthenticated, (req, res) => { ... })'/therapyprograms/:id/update', ensureAuthenticated, (req, res) => { ... })
router.delete('/therapyprograms/:id/delete', ensureAuthenticated, (req, res) => { ... })'/therapyprograms/:id/export', ensureAuthenticated, (req, res) => { ... })

// TASK'/tasks/new', ensureAuthenticated, (req, res) => { ... })'/tasks/:id/update', ensureAuthenticated, (req, res) => { ... })
router.delete('/tasks/:id/delete', ensureAuthenticated, (req, res) => { ... })

// COMPLETION'/completions/new', ensureAuthenticated, (req, res) => { ... })'/completions/:id/update', ensureAuthenticated, (req, res) => { ... })
router.delete('/completions/:id/delete', ensureAuthenticated, (req, res) => { ... })

Applicative and Modelling aspects

Therapy program with multiple tasks: with a preliminary JSON field would be more than enough.
For instance I would have considered a plugin like Alpaca forms in jQuery.
But in the view of a wider development, I opted for a classical structured data related to the task completion level registration just here below…

A task can be completed multiple times. A deep dive into the model of a task completion: I wanted to take advantage of the polymorphism of MongoDB, so instead of a simple boolean status like "done", I chose to use a discriminator because it gives an extensible structure and allows to collect different kind of information according to a task type:
  • the user that did it
  • when the user did it
  • potential notes such as issues encountered during the task (a note field is a usual request!)
  • completion info according to the task type: intensity level in case of an exercise task
const ExerciseCompletion = Completion.discriminator(constants.COMPLETION_TYPES.exercise, Schema({
        intensity: { type: constants.EXERCISE_INTENSITY_LEVELS, required: false }

In order to export the program results I quickly built a report with a HTML-to-PDF conversion, choosing the light node-html-pdf which uses Phantom. For more complex and cross platform needs I may consider the super powerful and versatile jsreport.

PS: proposals and potential extensions

  • description fields editing through a RichTextEditor like TinyMCE
  • replace the role-based access permissions with the features of the MongoDB Stitch platform
  • an automatic report with the customisation of the notification levels, frequencies and list of the recipients as per the patient's preferences
  • sending the therapy results to external existing systems such as a training database or a clinical data software
  • a native mobile app to better exploit the device native features such as push notifications and integration with other distributed apps such as Apple Health and Google Fit

Do you have further proposals and you want to realise or extend this application?
If I can help you, I would be happy to hear from you.

FREE source code

If you want to send me your requests and get the FREE source code of the prototype just write to

About the author

Ciao, I am Valentina Benedetti author of this code, I work as a freelance Programmer and help entrepreneurs, web designers and developers to create Custom Web site and Applications, especially in Ruby on Rails, Laravel, Node.js.