Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Calabrese committed Jan 14, 2015
2 parents ba84cfd + 1055a59 commit 649ecba
Show file tree
Hide file tree
Showing 21 changed files with 1,250 additions and 684 deletions.
6 changes: 1 addition & 5 deletions COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@

We track contributions on a per-patch basis using git.
Please see our published git log:
* https://github.com/nightscout/cgm-remote-monitor/commits/master

Copyright (C) 2015 The Nightscout Foundation, http://www.nightscoutfoundation.org
123 changes: 80 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
cgm-remote-monitor (a.k.a. NightScout)
cgm-remote-monitor (a.k.a. Nightscout)
======================================

[![Build Status](https://travis-ci.org/nightscout/cgm-remote-monitor.png)](https://travis-ci.org/nightscout/cgm-remote-monitor)
[![Dependency Status](https://david-dm.org/nightscout/cgm-remote-monitor.png)](https://david-dm.org/nightscout/cgm-remote-monitor)
[![Gitter chat](https://badges.gitter.im/nightscout.png)](https://gitter.im/nightscout/public)
[![Stories in Ready](https://badge.waffle.io/nightscout/cgm-remote-monitor.png?label=ready&title=Ready)](https://waffle.io/nightscout/cgm-remote-monitor)
[![Stories in Progress](https://badge.waffle.io/nightscout/cgm-remote-monitor.png?label=in+progress&title=In+Progress)](https://waffle.io/nightscout/cgm-remote-monitor)

[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

This acts as a web-based CGM (Continuous Glucose Montinor) to allow
multiple caregivers to remotely view a patients glucose data in
realtime. The server reads a MongoDB which is intended to be data
This acts as a web-based CGM (Continuous Glucose Monitor) to allow
multiple caregivers to remotely view a patient's glucose data in
real time. The server reads a MongoDB which is intended to be data
from a physical CGM, where it sends new SGV (sensor glucose values) as
the data becomes available. The data is then displayed graphically
and blood glucose values are predicted 0.5 hours ahead using a
and blood glucose values are predicted 0.5 hours ahead using an
autoregressive second order model. Alarms are generated for high and
low values, which can be cleared by any watcher of the data.

Expand All @@ -32,23 +34,6 @@ Clone this repo then install dependencies into the root of the project:
$ npm install
```

### Vagrant install

Optionally, use [Vagrant](https://www.vagrantup.com/) with the
included `Vagrantfile` and `setup.sh` to install OS and node packages to
a virtual machine.

```bash
host$ vagrant up
host$ vagrant ssh
vm$ setup.sh
```

The setup script will install OS packages then run `npm install`.

The Vagrant VM serves to your host machine only on 192.168.33.10, you can access
the web interface on [http://192.168.33.10:1337](http://192.168.33.10:1337)

Usage
---------------

Expand All @@ -61,50 +46,104 @@ ready, just host your web app on your service of choice.

[mongodb]: https://mongolab.com
[json]: https://github.com/rnpenguin/cgm-remote-monitor/blob/master/database_configuration.json
[autoconfigure]: http://nightscout.github.io/pages/configure/
[mongostring]: http://nightscout.github.io/pages/mongostring/
[update-fork]: http://nightscout.github.io/pages/update-fork/

### Updating my version?
The easiest way to update your version of cgm-remote-monitor to our latest
recommended version is to use the [update my fork tool][update-fork]. It even
gives out stars if you are up to date.

### What is my mongo string?

Try the [what is my mongo string tool][mongostring] to get a good idea of your
mongo string. You can copy and paste the text in the gray box into your
`MONGO_CONNECTION` environment variable.

### Configure my uploader to match

Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config.


### Environment
You can use the default null `database_configuration.json`
config if you set the following environment variables instead.
(Hosting providers often make this easy, and this allows you to avoid
editing anything.)

* `CUSTOMCONNSTR_mongo` - the mongo connection string, corresponds to
`DB.url`.
* `CUSTOMCONNSTR_mongo_collection` - the mongo collection to use,
corresponds to `DB.collection`.
`VARIABLE` (default) - description

#### Required

* `MONGO_CONNECTION` - Your mongo uri, for example: `mongodb://sally:[email protected]:99999/nightscout`

#### Features/Labs

* `ENABLE` - Used to enable optional features, currently supports: `careportal`
* `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal
* `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent
* `BG_TARGET_TOP` (`180`) - must be set using mg/dl units; the top of the target range, also used to draw the line on the chart
* `BG_TARGET_BOTTOM` (`80`) - must be set using mg/dl units; the bottom of the target range, also used to draw the line on the chart
* `BG_LOW` (`55`) - must be set using mg/dl units; the low BG outside the target range that is considered urgent
* `ALARM_TYPES` (`simple` if any `BG_`* ENV's are set, otherwise `predict`) - currently 2 alarm types are supported, and can be used independently or combined. The `simple` alarm type only compares the current BG to `BG_` thresholds above, the `predict` alarm type uses highly tuned formula that forecasts where the BG is going based on it's trend. `predict` **DOES NOT** currently use any of the `BG_`* ENV's
* `PUSHOVER_API_TOKEN` - Used to enable pushover notifications for Care Portal treatments, this token is specific to the application you create from in [Pushover](https://pushover.net/)
* `PUSHOVER_USER_KEY` - Your Pushover user key, can be found in the top left of the [Pushover](https://pushover.net/) site


#### Core

* `DISPLAY_UNITS` (`mg/dl`) - Choices: `mg/dl` and `mmol`. Setting to `mmol` puts the entire server into `mmol` mode by default, no further settings needed.
* `MONGO_COLLECTION` (`entries`) - The collection used to store SGV, MBG, and CAL records from your CGM device
* `MONGO_TREATMENTS_COLLECTION` (`treatments`) -The collection used to store treatments entered in the Care Portal, see the `ENABLE` env var above
* `MONGO_DEVICESTATUS_COLLECTION`(`devicestatus`) - The collection used to store device status information such as uploader battery
* `PORT` (`1337`) - The port that the node.js application will listen on.
* `SSL_KEY` - Path to your ssl key file, so that ssl(https) can be enabled directly in node.js
* `SSL_CERT` - Path to your ssl cert file, so that ssl(https) can be enabled directly in node.js
* `SSL_CA` - Path to your ssl ca file, so that ssl(https) can be enabled directly in node.js

## Setting environment variables
Easy to emulate on the commandline:

```bash
echo 'CUSTOMCONNSTR_mongo="mongodb://sally:[email protected]/db"' >> my.env
echo 'CUSTOMCONNSTR_mongo_collection="sallyCGMCollection"' >> my.env
echo 'MONGO_CONNECTION="mongodb://sally:[email protected]:99999/nightscout"' >> my.env
```

From now on you can run using
```bash
$ env $(cat my.env) PORT=1337 node server.js
$ env $(cat my.env) PORT=1337 node server.js
```

Your hosting provider probably has a way to set these through their
GUI.
Your hosting provider probably has a way to set these through their GUI.

### Vagrant install

Optionally, use [Vagrant](https://www.vagrantup.com/) with the
included `Vagrantfile` and `setup.sh` to install OS and node packages to
a virtual machine.

```bash
host$ vagrant up
host$ vagrant ssh
vm$ setup.sh
```

The setup script will install OS packages then run `npm install`.

The Vagrant VM serves to your host machine only on 192.168.33.10, you can access
the web interface on [http://192.168.33.10:1337](http://192.168.33.10:1337)

More questions?
---------------

Feel free to [post an issue][issues], but read the [wiki][wiki] first.

[issues]: https://github.com/rnpenguin/cgm-remote-monitor/issues
[wiki]: https://github.com/rnpenguin/cgm-remote-monitor/wiki
[issues]: https://github.com/nightscout/cgm-remote-monitor/issues
[wiki]: https://github.com/nightscout/cgm-remote-monitor/wiki

License
---------------

[agpl-3]: http://www.gnu.org/licenses/agpl-3.0.txt

cgm-remote-monitor - web app to broadcast cgm readings
Copyright (C) 2014 Nightscout contributors. See the COPYRIGHT file
at the root directory of this distribution and at
https://github.com/nightscout/cgm-remote-monitor/blob/master/COPYRIGHT
Copyright (C) 2015 The Nightscout Foundation, http://www.nightscoutfoundation.org.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
Expand All @@ -118,5 +157,3 @@ License

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.


27 changes: 24 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@
"repository": "https://github.com/nightscout/cgm-remote-monitor",
"env": {
"MONGO_COLLECTION": {
"description": "The mongo collection to connect to.",
"value": "nightscout"
"description": "The mongo collection for CGM data. Most users should leave this as default.",
"value": "entries",
"required": true
},
"API_SECRET": {
"description": "User generated password required for REST API and other features (12 character minimum).",
"value": "",
"required": true
},
"ENABLE": {
"description": "Space delimited list of optional features to enable. Leave blank for a default site.",
"value": "",
"required": false
},
"PUSHOVER_API_TOKEN": {
"description": "Pushover API token, required for Pushover notifications. Leave blank for a default site.",
"value": "",
"required": false
},
"PUSHOVER_USER_KEY": {
"description": "Pushover user key, required for Pushover notifications. Leave blank for a default site.",
"value": "",
"required": false
}
},
"addons": [
"mongolab"
"mongolab:sandbox"
]
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "0.5.1",
"version": "0.6.0",
"dependencies": {
"angularjs": "1.3.0-beta.19",
"bootstrap": "~3.2.0",
Expand Down
55 changes: 55 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var env = { };
var crypto = require('crypto');
var consts = require('./lib/constants');
var fs = require('fs');
// Module to constrain all config and environment parsing to one spot.
function config ( ) {

Expand Down Expand Up @@ -43,6 +44,19 @@ function config ( ) {
env.devicestatus_collection = readENV('MONGO_DEVICESTATUS_COLLECTION', 'devicestatus');

env.enable = readENV('ENABLE');
env.SSL_KEY = readENV('SSL_KEY');
env.SSL_CERT = readENV('SSL_CERT');
env.SSL_CA = readENV('SSL_CA');
env.ssl = false;
if (env.SSL_KEY && env.SSL_CERT) {
env.ssl = {
key: fs.readFileSync(env.SSL_KEY)
, cert: fs.readFileSync(env.SSL_CERT)
};
if (env.SSL_CA) {
env.ca = fs.readFileSync(env.SSL_CA);
}
}

var shasum = crypto.createHash('sha1');

Expand All @@ -64,6 +78,43 @@ function config ( ) {
env.api_secret = shasum.digest('hex');
}

env.thresholds = {
bg_high: readIntENV('BG_HIGH', 260)
, bg_target_top: readIntENV('BG_TARGET_TOP', 180)
, bg_target_bottom: readIntENV('BG_TARGET_BOTTOM', 80)
, bg_low: readIntENV('BG_LOW', 55)
};

//NOTE: using +/- 1 here to make the thresholds look visibly wrong in the UI
// if all thresholds were set to the same value you should see 4 lines stacked right on top of each other
if (env.thresholds.bg_target_bottom >= env.thresholds.bg_target_top) {
console.warn('BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ') was >= BG_TARGET_TOP(' + env.thresholds.bg_target_top + ')');
env.thresholds.bg_target_bottom = env.thresholds.bg_target_top - 1;
console.warn('BG_TARGET_BOTTOM is now ' + env.thresholds.bg_target_bottom);
}

if (env.thresholds.bg_target_top <= env.thresholds.bg_target_bottom) {
console.warn('BG_TARGET_TOP(' + env.thresholds.bg_target_top + ') was <= BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ')');
env.thresholds.bg_target_top = env.thresholds.bg_target_bottom + 1;
console.warn('BG_TARGET_TOP is now ' + env.thresholds.bg_target_top);
}

if (env.thresholds.bg_low >= env.thresholds.bg_target_bottom) {
console.warn('BG_LOW(' + env.thresholds.bg_low + ') was >= BG_TARGET_BOTTOM(' + env.thresholds.bg_target_bottom + ')');
env.thresholds.bg_low = env.thresholds.bg_target_bottom - 1;
console.warn('BG_LOW is now ' + env.thresholds.bg_low);
}

if (env.thresholds.bg_high <= env.thresholds.bg_target_top) {
console.warn('BG_HIGH(' + env.thresholds.bg_high + ') was <= BG_TARGET_TOP(' + env.thresholds.bg_target_top + ')');
env.thresholds.bg_high = env.thresholds.bg_target_top + 1;
console.warn('BG_HIGH is now ' + env.thresholds.bg_high);
}

//if any of the BG_* thresholds are set, default to "simple" otherwise default to "predict" to preserve current behavior
var thresholdsSet = readIntENV('BG_HIGH') || readIntENV('BG_TARGET_TOP') || readIntENV('BG_TARGET_BOTTOM') || readIntENV('BG_LOW');
env.alarm_types = readENV('ALARM_TYPES') || (thresholdsSet ? "simple" : "predict");

// For pushing notifications to Pushover.
env.pushover_api_token = readENV('PUSHOVER_API_TOKEN');
env.pushover_user_key = readENV('PUSHOVER_USER_KEY') || readENV('PUSHOVER_GROUP_KEY');
Expand All @@ -83,6 +134,10 @@ function config ( ) {
return env;
}

function readIntENV(varName, defaultValue) {
return parseInt(readENV(varName)) || defaultValue;
}

function readENV(varName, defaultValue) {
//for some reason Azure uses this prefix, maybe there is a good reason
var value = process.env['CUSTOMCONNSTR_' + varName]
Expand Down
Empty file removed lib/api/entries/middleware.js
Empty file.
3 changes: 3 additions & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function create (env, entries, settings, treatments, devicestatus) {

app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));

app.thresholds = env.thresholds;
app.alarm_types = env.alarm_types;

// Start setting up routes
if (app.enabled('api')) {
// experiments
Expand Down
2 changes: 2 additions & 0 deletions lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function configure (app, wares) {
, units: app.get('units')
, head: wares.get_head( )
, version: app.get('version')
, thresholds: app.thresholds
, alarm_types: app.alarm_types
, name: app.get('name')};
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';
return res.format({
Expand Down
2 changes: 1 addition & 1 deletion lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function configure (app, wares, treatments) {

// List settings available
api.get('/treatments/', function(req, res) {
treatments.list(function (err, profiles) {
treatments.list({}, function (err, profiles) {
return res.json(profiles);
});
});
Expand Down
Loading

0 comments on commit 649ecba

Please sign in to comment.