Skip to content

Commit

Permalink
Merge pull request #970 from nightscout/wip/reports
Browse files Browse the repository at this point in the history
Make reports available to all
  • Loading branch information
jasoncalabrese committed Sep 7, 2015
2 parents af35230 + de1f000 commit 4d8c698
Show file tree
Hide file tree
Showing 38 changed files with 3,415 additions and 72 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `ENABLE` - Used to enable optional features, expects a space delimited list, such as: `careportal rawbg iob`, see [plugins](#plugins) below
* `DISABLE` - Used to disable default features, expects a space delimited list, such as: `direction upbat`, see [plugins](#plugins) below
* `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
* `TREATMENTS_AUTH` (`off`) - possible values `on` or `off`. When on device must be authenticated by entering `API_SECRET` to create treatments


### Alarms
Expand Down
2 changes: 2 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"jQuery-Storage-API": "~1.7.2",
"tipsy-jmalonzo": "~1.0.1",
"jquery-ui": "~1.11.3",
"jquery-flot": "0.8.3",
"simple-statistics": "0.7.0",
"swagger-ui": "~2.1.2"
},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
client: require('../lib/client')
, units: require('../lib/units')()
, plugins: require('../lib/plugins/')().registerClientDefaults()
, report_plugins: require('../lib/report_plugins/')()
};

console.info('Nightscout bundle ready');
Expand Down
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function config ( ) {
setMongo();
updateSettings();

// require authorization for entering treatments
env.treatments_auth = readENV('TREATMENTS_AUTH',false);

return env;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function create (env, ctx) {

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

app.set('treatments_auth', env.treatments_auth);

// Start setting up routes
if (app.enabled('api')) {
// experiments
Expand Down
28 changes: 27 additions & 1 deletion lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,43 @@ function configure (app, wares, ctx) {

function config_authed (app, api, wares, ctx) {

api.post('/treatments/', /*TODO: auth disabled for now, need to get login figured out... wares.verifyAuthorization, */ function(req, res) {
function post_response(req, res) {
var treatment = req.body;
ctx.treatments.create(treatment, function (err, created) {
if (err) {
console.log('Error adding treatment');
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
} else {
console.log('Treatment created');
res.json(created);
}
});
}
if (app.settings.treatments_auth) {
api.post('/treatments/', wares.verifyAuthorization, post_response);
} else {
api.post('/treatments/', post_response);
}
api.delete('/treatments/:_id', wares.verifyAuthorization, function(req, res) {
ctx.treatments.remove(req.params._id, function ( ) {
res.json({ });
});
});

// update record
api.put('/treatments/', wares.verifyAuthorization, function(req, res) {
var data = req.body;
ctx.treatments.save(data, function (err, created) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(created);
console.log('Treatment saved', data);
}
});
});
}

if (app.enabled('api') && app.enabled('careportal')) {
Expand Down
36 changes: 34 additions & 2 deletions lib/client/careportal.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use strict';

var moment = require('moment-timezone');
var _ = require('lodash');

function init (client, $) {
var careportal = { };

var translate = client.translate;
var storage = $.localStorage;

careportal.events = [
{ val: 'BG Check', name: 'BG Check' }
, { val: 'Snack Bolus', name: 'Snack Bolus' }
, { val: 'Meal Bolus', name: 'Meal Bolus' }
, { val: 'Correction Bolus', name: 'Correction Bolus' }
, { val: 'Carb Correction', name: 'Carb Correction' }
, { val: 'Announcement', name: 'Announcement' }
, { val: 'Note', name: 'Note' }
, { val: 'Question', name: 'Question' }
, { val: 'Exercise', name: 'Exercise' }
, { val: 'Site Change', name: 'Pump Site Change' }
, { val: 'Sensor Start', name: 'Dexcom Sensor Start' }
, { val: 'Sensor Change', name: 'Dexcom Sensor Change' }
, { val: 'Insulin Change', name: 'Insulin Cartridge Change' }
, { val: 'D.A.D. Alert', name: 'D.A.D. Alert' }
];

var eventTime = $('#eventTimeValue');
var eventDate = $('#eventDateValue');

Expand All @@ -32,7 +50,15 @@ function init (client, $) {
}
}

careportal.prepareEvents = function prepareEvents ( ) {
$('#eventType').empty();
_.each(careportal.events, function eachEvent(event) {
$('#eventType').append('<option value="' + event.val+ '">' + translate(event.name) + '</option>');
});
};

careportal.prepare = function prepare ( ) {
careportal.prepareEvents();
$('#eventType').val('BG Check');
$('#glucoseValue').val('').attr('placeholder', translate('Value in') + ' ' + client.settings.units);
$('#meter').prop('checked', true);
Expand Down Expand Up @@ -100,10 +126,16 @@ function init (client, $) {
if (window.confirm(buildConfirmText(data))) {
$.ajax({
method: 'POST',
url: '/api/v1/treatments/',
data: data
url: '/api/v1/treatments/'
, headers: {
'api-secret': client.hashauth.hash()
}
, data: data
}).done(function treatmentSaved (response) {
console.info('treatment saved', response);
}).fail(function treatmentSaveFail (response) {
console.info('treatment saved', response);
alert(translate('Entering record failed') + '. ' + translate('Status') + ': ' + response.status);
});

storage.set('enteredBy', data.enteredBy);
Expand Down
16 changes: 0 additions & 16 deletions lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,6 @@ function init() {
,fi: 'Merkinnät sisältävät'
,nb: 'Notater inneholder'
}
,'Event type contains' : {
cs: 'Typ události obsahuje'
,de: 'Ereignis-Typ beinhaltet'
,es: 'Contenido del tipo de evento'
,fr: 'Type d\'événement contient'
,pt: 'Tipo de evento contém'
,ro: 'Conținut tip de eveniment'
,bg: 'Типа събитие включва'
,hr: 'Sadržaj vrste događaja'
,sv: 'Händelsen innehåller'
,it: 'Contiene evento'
,dk: 'Hændelsen indeholder'
,fi: 'Tapahtuman tyyppi sisältää'
,nb: 'Hendelsen inneholder'
}
,'Target bg range bottom' : {
cs: 'Cílová glykémie spodní'
,de: 'Untergrenze des Blutzuckerzielbereiches'
Expand Down Expand Up @@ -3920,7 +3905,6 @@ function init() {
}
,'Update' : { // Update button
cs: 'Aktualizovat'
,fi: 'Päivitys'
}

};
Expand Down
6 changes: 5 additions & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ function walk_prop (prop, typer) {
}

function parseRegEx (str) {
return new RegExp(str);
var regtest = /\/(.*)\/(.*)/.exec(str);
if (regtest) {
return new RegExp(regtest[1],regtest[2]);
}
return str;
}

// attach helpers and utilities to main function for testing
Expand Down
Loading

0 comments on commit 4d8c698

Please sign in to comment.