|
|
@@ -1,5 +1,5 @@ |
|
|
|
|
|
-function websocket (env, server, entries, treatments) {
|
|
|
+function websocket (env, server, entries, treatments, profiles) {
|
|
|
"use strict";
|
|
|
// CONSTANTS
|
|
|
var ONE_HOUR = 3600000,
|
|
|
@@ -29,6 +29,7 @@ var dir2Char = { |
|
|
treatmentData = [],
|
|
|
mbgData = [],
|
|
|
calData = [],
|
|
|
+ profileData = [],
|
|
|
patientData = [];
|
|
|
|
|
|
function start ( ) {
|
|
|
@@ -146,6 +147,7 @@ function update() { |
|
|
cgmData = [];
|
|
|
treatmentData = [];
|
|
|
mbgData = [];
|
|
|
+ profileData = [];
|
|
|
var earliest_data = now - TWO_DAYS;
|
|
|
var q = { find: {"date": {"$gte": earliest_data}} };
|
|
|
entries.list(q, function (err, results) {
|
|
|
@@ -188,8 +190,19 @@ function update() { |
|
|
treatment.x = timestamp.getTime();
|
|
|
return treatment;
|
|
|
});
|
|
|
- // all done, do loadData
|
|
|
- loadData( );
|
|
|
+
|
|
|
+ profiles.list(function (err, results) {
|
|
|
+ // There should be only one document in the profile collection with a DIA. If there are multiple, use the last one.
|
|
|
+ results.forEach(function(element, index, array) {
|
|
|
+ if (element) {
|
|
|
+ if (element.dia) {
|
|
|
+ profileData[0] = element;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // all done, do loadData
|
|
|
+ loadData( );
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -237,6 +250,10 @@ function loadData() { |
|
|
});
|
|
|
}
|
|
|
|
|
|
+ if (profileData) {
|
|
|
+ var profile = profileData;
|
|
|
+ }
|
|
|
+
|
|
|
if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;
|
|
|
|
|
|
var actualLength = actual.length - 1;
|
|
|
@@ -271,7 +288,7 @@ function loadData() { |
|
|
|
|
|
// consolidate and send the data to the client
|
|
|
var shouldEmit = is_different(actual, predicted, mbg, treatment, cal);
|
|
|
- patientData = [actual, predicted, mbg, treatment, cal];
|
|
|
+ patientData = [actual, predicted, mbg, treatment, profile, cal];
|
|
|
console.log('patientData', patientData.length);
|
|
|
if (shouldEmit) {
|
|
|
emitData( );
|
|
|
|
Lines 197-198 could be simplified to
if (element && element.dia) {, correct?Also, consider a standard
forloop that goes backward from the end ofresults, and breaks when it findselement.dia.