PHP Classes

Health Measures: Record body measures and render graphs of changes

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 181 All time: 8,707 This week: 455Up
Version License PHP version Categories
healthmeasures 1.0.0The PHP License5PHP 5, Databases, Graphics, Biology, H...
Description 

Author

This package can record body measures and render graphs of changes.

It has a class for creating new measure unite with a given a name like for instance the weight in pounds or kilos. The units can be saved them to a database.

The class can record measurement values in a given unit in a database.

The package can also generate graphs with measurement statistics information.

Innovation Award
PHP Programming Innovation award nominee
February 2017
Number 11
Nutritionists and other health experts often need to keep track of the patients body measures such as weight, waist length, etc.

This package provides means to keep track of as many health measures as necessary in a database.

It stores the measure values and dates, so it can render evolution charts to see how the patient evolved.

Manuel Lemos
Picture of Lucia Figueroa
Name: Lucia Figueroa <contact>
Classes: 1 package by
Country: Uruguay Uruguay
Age: ???
All time rank: 42078 in Uruguay Uruguay
Week rank: 192 Up1 in Uruguay Uruguay Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

error_reporting
(E_ALL);
ini_set('display_errors', 1);

require_once
__DIR__ . '/../vendor/autoload.php';
use
Healthmeasures\Measurement\Measure;
use
Healthmeasures\Measurement\Value;
use
Healthmeasures\Measurement\Stats;

$mm = new Measure("cintura", "cms", "es");
$mm->save();
$vv = new Value();

$mm2 = new Measure("imc", "kg/m2", "es");
$mm2->save();
$mm3 = new Measure("systole", "", "en");
$mm3->save();


// 'owner_id' => '1',
// 'measure_id' => '2577a46ca60e3ff293ccb0113e6a59c0',
// 'created_at' => '2016-12-30 08:00:00',
// 'value' => '98',

$vv2 = new Value(1, '1ecf550e3e22e6f96cb9c1d8105118d2', '2016-12-30 08:00:00', 98);
$vv2->save();

$mm->getMeasuresByLang('es');

$mm->getAll();

Measure::setDefaultLanguage('es');
$mm->bulkConstructor(__DIR__ . '/CSV/Measure.csv');
$vv->bulkConstructor(__DIR__ . '/CSV/Value.csv');

$v = new Value();
$vals = $v->getValuesByDate(1, '2577a46ca60e3ff293ccb0113e6a59c0', "2016-01-01");
$stats = new Stats($vals);
$stats->image_path = "linear_bar.jpg";
if (!
file_exists("linear_bar.jpg")) {
   
$stats->generateDateMeasureGraph(Stats::GRAPH_LINEAR);
}

echo
$stats->getHtmlReport();



Details

Health Measures

towerhousestudio

  • This library gives you the ability to generate health measures given a name and a unit, for instance: weight / pound or kilo.
  • You can configure where to store them and them gather to collect their values by date given a username or other identifier.
  • The library gives you the ability to generate graphs or other stats information. It's totally configurable, methods are well documented and comes with unit testing.

Tech

Health Measures uses a number of open source projects to work properly:

  • [PHP] - <= 5.3
  • [illuminate/config] - 5 . This is the config handler that environments like laravel 4.2 used to have.
  • [amenadiel/jpgraph"] - ^3.6 . This guy ported all the jpgraph library to packagist, thank you.

Installation

  • composer require towerhouse/healthmeasures
  • Include the autoloader.
  • A file on the test's folder test-creation.php will give you a quick review of what the library does.
  • Merge the values from .env.example you want to use in your env or just rename the example to .env.
  • This package should work standalone.

Example of use

Select your storage method on the .env file

Enter your measures one by one or using the bulk method

//One by one
$mm = new Measure("waist", "cm", "en");
$mm->save();
$mm2 = new Measure("imc", "kg/m2", "es");
$mm2->save();
$mm3 = new Measure("systole", "", "en");
$mm3->save();

//Using the bulk method with a CSV file that has a header
//Don't worry about duplicates

Measure::setDefaultLanguage('es'); //All my csv measures are in spanish
$mm->bulkConstructor(__DIR__ . '/CSV/Measure.csv');

Example of content in Measure.csv

name,unit
sistole,	
diastole,
pulso,
peso,kilo
altura,cm
azucar en sangre,mg/dl
Saturación de oxígeno en sangre,SaO2
temperatura,ºC

Now enter your values, it's the same as measures so, for simplicity we will use the bulk method

$v = new Value();
$v->bulkConstructor(__DIR__ . '/CSV/Value.csv');
//Again, don't worry about duplicates

Example of content in Value.csv

measure_id,value,owner_id,created_at
2577a46ca60e3ff293ccb0113e6a59c0,97,1,2016-12-29 07:00:00
2577a46ca60e3ff293ccb0113e6a59c0,98,1,2016-12-30 08:00:00
2577a46ca60e3ff293ccb0113e6a59c0,98,1,2016-12-31 06:30:00
2577a46ca60e3ff293ccb0113e6a59c0,98,1,2017-01-01 07:00:00
2577a46ca60e3ff293ccb0113e6a59c0,98,1,2017-01-02 07:00:00
2577a46ca60e3ff293ccb0113e6a59c0,95,1,2017-01-10 11:00:00
2577a46ca60e3ff293ccb0113e6a59c0,95,1,2017-01-15 07:00:00
2577a46ca60e3ff293ccb0113e6a59c0,97,1,2017-01-25 11:00:00

Notice that the owner_id comes from an external system, while measure_id belongs to Healthmeasures. In this case measure_id "2577a46ca60e3ff293ccb0113e6a59c0" it's the id for the measure "waist".

Finally we retrieve all the values that the person with identifier 1 had for his waist starting from "2016-01-01" and ending in the most recent date (that would be today, otherwise you specify it on another last parameter)

$vals = $v->getValuesByDate(1, '2577a46ca60e3ff293ccb0113e6a59c0', "2016-01-01");

Let's create a Stats object and pass the values to generate a linear graph. You can specify a path and the picture will be saved there, otherwise it will be rendered to the client through the browser.

$stats = new Stats($vals);
$stats->image_path = "linear_sample.jpg";
$stats->generateDateMeasureGraph(Stats::GRAPH_LINEAR);

Finally, you can render a nice and simple html report to your browser with all the details

$stats = new Stats($vals);
$stats->image_path = "linear_bar.jpg";
if (!file_exists("linear_bar.jpg")) {
    $stats->generateDateMeasureGraph(Stats::GRAPH_LINEAR);
}
echo $stats->getHtmlReport();

This is a pdf I took from the html page. https://github.com/towerhouse/Healthmeasures/tree/master/test/report.pdf

...and this is the image of the graph Alt text

Unit testing

There is an article about unit testing I wrote for this library documented here: https://www.linkedin.com/pulse/unit-testing-activity-annoys-programmers-lucia-figueroa-tasca


  Files folder image Files (23)  
File Role Description
Files folder imageconfig (2 files)
Files folder imagesrc (1 directory)
Files folder imagetest (6 files, 2 directories)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (23)  /  config  
File Role Description
  Accessible without login Plain text file database.php Conf. Configuration script
  Accessible without login Plain text file htmlReport.php Conf. Configuration script

  Files folder image Files (23)  /  src  
File Role Description
Files folder imageHealthmeasures (2 directories)

  Files folder image Files (23)  /  src  /  Healthmeasures  
File Role Description
Files folder imageConfiguration (2 files)
Files folder imageMeasurement (4 files)

  Files folder image Files (23)  /  src  /  Healthmeasures  /  Configuration  
File Role Description
  Plain text file Application.php Class Class source
  Plain text file Config.php Class Class source

  Files folder image Files (23)  /  src  /  Healthmeasures  /  Measurement  
File Role Description
  Plain text file Measure.php Class Class source
  Plain text file Persistance.php Class Class source
  Plain text file Stats.php Class Class source
  Plain text file Value.php Class Class source

  Files folder image Files (23)  /  test  
File Role Description
Files folder imageCSV (3 files)
Files folder imageMeasurement (3 files)
  Accessible without login Plain text file quick.php Example Example script
  Accessible without login Plain text file report.pdf Data Auxiliary data
  Accessible without login Plain text file sample-bar-graph.php Example Example script
  Accessible without login Plain text file sample-graph.php Example Example script
  Accessible without login Image file sample-linear-graph.jpg Data Auxiliary data
  Accessible without login Plain text file sample-pie-graph.php Example Example script

  Files folder image Files (23)  /  test  /  CSV  
File Role Description
  Accessible without login Plain text file Measure.csv Data Auxiliary data
  Accessible without login Plain text file StatsValues.csv Data Auxiliary data
  Accessible without login Plain text file Value.csv Data Auxiliary data

  Files folder image Files (23)  /  test  /  Measurement  
File Role Description
  Plain text file MeasureTest.php Class Class source
  Plain text file StatsTest.php Class Class source
  Plain text file ValueTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:181
This week:0
All time:8,707
This week:455Up