Skip to content

Commit 2e7f790

Browse files
committed
Lbrary+viewer, not all types covered yet
0 parents  commit 2e7f790

22 files changed

+1590
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode
2+
js/freestylelibrelib.js
3+
node_modules
4+
typings

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Abbot FreeStyle Libre flash glucose meter Parser/Viewer
2+
3+
## Objective
4+
5+
Create a library to read and manage CSV files created by the FreeStyle libre app to better understand and visualize the report data
6+
7+
## How to install
8+
9+
`npm install`
10+
11+
## How to use the Viewer (user)
12+
13+
Mount a local web-server (for example using node's http-server) and browse to the `index.html` (for example http://127.0.0.1:8080/index.html) to open the main view that lets you import a csv file generated from the Abbott FreeStyle Libre app (or use the test.csv example file) and visualize the data in the HighChart chart.
14+
15+
## How to use the FreeStyleLibreLib (developer)
16+
17+
```javascript
18+
var reader = new FileReader();
19+
reader.readAsText(file);
20+
reader.onload = function() {
21+
var report = FreeStyleLibreLib.parseReport(reader.result);
22+
}
23+
```
24+
25+
## CSV File Format (actually separated by tabs)
26+
27+
- Line 1:
28+
- Patient Name **(is this line optional?)**
29+
- Line 2:
30+
- Headers
31+
- ID
32+
- Time **(is YYYY/MM/DD HH:mm the only possible date format?)**
33+
- Record Type
34+
- 0: Historic Glucose
35+
- 1: Scan Glucose
36+
- 2: **?**
37+
- 3: **?**
38+
- 4: Insulin (Need to read if Rapid-Acting Insulin (units) or Long-Acting Insulin (units) has data to know witch is witch, probably appies to the "non numeric" ones too, but is not tested)
39+
- 5: Food
40+
- 6: Date change (not implemented)
41+
- **Is there anything beyond type 6?**
42+
- Historic Glucose (mmol/L)
43+
- **Does the column name change if the meter units are not mmol/L?**
44+
- Scan Glucose (mmol/L)
45+
- **Does the column name change if the meter units are not mmol/L?**
46+
- Non-numeric Rapid-Acting Insulin
47+
- Rapid-Acting Insulin (units)
48+
- Non-numeric Food
49+
- Carbohydrates (grams)
50+
- Non-numeric Long-Acting Insulin
51+
- Long-Acting Insulin (units)
52+
- Notes
53+
- Strip Glucose (mmol/L)
54+
- **Does the column name change if the meter units are not mmol/L?**
55+
- Ketone (mmol/L)
56+
- **Does the column name change if the meter units are not mmol/L?**
57+
- Meal Insulin (units)
58+
- Correction Insulin (units)
59+
- User Change Insulin (units)
60+
- Previous Time
61+
- Updated Time
62+
- **Are these all the possible columns?**
63+
- **Can the columns have another name if the meter or app is set up in other language?**
64+
- Lines > 2
65+
- Data

css/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.chart {
2+
min-width: 310px;
3+
height: 600px;
4+
margin: 0 auto;
5+
}

index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Freestyle Libre Parser/Viewer</title>
8+
<link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
9+
<link href="css/index.css" rel="stylesheet">
10+
11+
<!--[if lt IE 9]>
12+
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
13+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
14+
<![endif]-->
15+
</head>
16+
<body>
17+
<h1>Abbot FreeStyle Libre flash glucose meter Parser/Viewer</h1>
18+
19+
<input type="file" id="file" name="file" />
20+
<span id="output"></span>
21+
<div id="container" class="chart"></div>
22+
23+
<script src="node_modules/jquery/dist/jquery.js"></script>
24+
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
25+
<script src="node_modules/highcharts/highstock.js"></script>
26+
<script src="node_modules/highcharts/highcharts-more.js"></script>
27+
<script src="node_modules/highcharts/modules/exporting.js"></script>
28+
<script src="node_modules/moment/moment.js"></script>
29+
<script src="js/freestylelibrelib.js"></script>
30+
<script src="js/index.js"></script>
31+
</body>
32+
</html>

js/index.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
(function() {
2+
'use strict';
3+
4+
// TODO: Make these values UI configurable
5+
var HIPO_LIMIT = 4.0;
6+
var HIPER_LIMIT = 10.0;
7+
8+
$('#file').change(function(evt) {
9+
var file = evt.target.files[0]; // FileList object
10+
var reader = new FileReader();
11+
reader.readAsText(file);
12+
reader.onload = function() {
13+
14+
// Create the report
15+
16+
var report = FreeStyleLibreLib.parseReport(reader.result);
17+
18+
// Define series and properties
19+
20+
var highchartsData = [
21+
{
22+
name: 'Glucose',
23+
color: '#FA5858',
24+
data: [],
25+
zones: [
26+
{
27+
color: '#FA5858',
28+
value: HIPO_LIMIT
29+
},
30+
{
31+
color: '#190707',
32+
value: HIPER_LIMIT
33+
},
34+
]
35+
},
36+
{
37+
name: 'Rapid-Actin Insulin',
38+
color: '#FAAC58',
39+
data: []
40+
},
41+
{
42+
name: 'Long-Actin Insulin',
43+
color: '#BE81F7',
44+
data: []
45+
},
46+
{
47+
name: 'Food',
48+
color: '#000099',
49+
data: [],
50+
lineWidth: 0,
51+
marker: {
52+
enabled: true,
53+
radius: 4
54+
}
55+
},
56+
{
57+
name: 'Rapid-Actin Insulin Injection',
58+
color: '#FAAC58',
59+
data: [],
60+
lineWidth: 0,
61+
marker: {
62+
enabled: true,
63+
radius: 4
64+
}
65+
},
66+
{
67+
name: 'Long-Actin Insulin Injection',
68+
color: '#BE81F7',
69+
data: [],
70+
lineWidth: 0,
71+
marker: {
72+
enabled: true,
73+
radius: 4
74+
}
75+
},
76+
{
77+
name: 'Hipo',
78+
color: '#F5A9A9',
79+
dashStyle: 'ShortDash',
80+
data: []
81+
},
82+
{
83+
name: 'Hiper',
84+
color: '#F5A9A9',
85+
dashStyle: 'ShortDash',
86+
data: []
87+
}
88+
];
89+
90+
// Add data points
91+
92+
report.glucose.forEach(function(element) {
93+
var value = element.glucose.getValueAsMmolPerL();
94+
highchartsData[0].data.push([element.date.valueOf(), value]);
95+
}, this);
96+
report.getSmoothRapidInsulin().forEach(function(element) {
97+
var value = element.units;
98+
highchartsData[1].data.push([element.date.valueOf(), value]);
99+
}, this);
100+
report.getSmoothLongInsulin().forEach(function(element) {
101+
var value = element.units;
102+
highchartsData[2].data.push([element.date.valueOf(), value]);
103+
}, this);
104+
report.food.forEach(function(element) {
105+
var value = element.carbs;
106+
highchartsData[3].data.push([element.date.valueOf(), (isNaN(value) ? 5 : value)]);
107+
}, this);
108+
report.insulin.forEach(function(element) {
109+
var value = element.units;
110+
if (element.insulinType == 0) {
111+
highchartsData[4].data.push([element.date.valueOf(), value]);
112+
}
113+
if (element.insulinType == 1) {
114+
highchartsData[5].data.push([element.date.valueOf(), value]);
115+
}
116+
}, this);
117+
highchartsData[6].data = [
118+
[report.start.valueOf(), HIPO_LIMIT],
119+
[report.end.valueOf(), HIPO_LIMIT]
120+
];
121+
highchartsData[7].data = [
122+
[report.start.valueOf(), HIPER_LIMIT],
123+
[report.end.valueOf(), HIPER_LIMIT]
124+
];
125+
126+
// Create the Highcharts chart
127+
128+
Highcharts.stockChart('container', {
129+
series: highchartsData,
130+
rangeSelector: {
131+
selected: 1,
132+
buttons: [{
133+
type: 'day',
134+
count: 1,
135+
text: '1d'
136+
}, {
137+
type: 'day',
138+
count: 3,
139+
text: '3d'
140+
}, {
141+
type: 'day',
142+
count: 7,
143+
text: '1w'
144+
}, {
145+
type: 'month',
146+
count: 1,
147+
text: '1m'
148+
}, {
149+
type: 'month',
150+
count: 1,
151+
text: '3m'
152+
}, {
153+
type: 'all',
154+
text: 'All'
155+
}]
156+
},
157+
legend: {
158+
enabled: true,
159+
layout: 'vertical',
160+
backgroundColor: '#FFFFFF',
161+
align: 'right',
162+
x: -30,
163+
y: 50,
164+
verticalAlign: 'top',
165+
floating: true,
166+
shadow: true
167+
},
168+
});
169+
};
170+
});
171+
})();

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "freestyle-libre-parser-viewer",
3+
"version": "1.0.0",
4+
"description": "A parser library and viewer for CSV generated by the Abbot Freestyle Libre flash glucose meter.",
5+
"main": "index.html",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/nahog/freestyle-libre-parser-viewer.git"
9+
},
10+
"scripts": {
11+
"postinstall": "typings install && tsc"
12+
},
13+
"author": "Nicolas Padula <nahog@msn.com>",
14+
"license": "MIT",
15+
"devDependencies": {
16+
"bootstrap": "^3.3.7",
17+
"highcharts": "^5.0.6",
18+
"jquery": "^3.1.1",
19+
"moment": "^2.17.1",
20+
"typescript": "^2.1.5",
21+
"typings": "^2.1.0"
22+
}
23+
}

0 commit comments

Comments
 (0)