diff --git a/config.xml b/config.xml index 23141fc7..17536ffb 100644 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + LiveWell An application for bipolar disorder @@ -16,9 +16,8 @@ - + - - - + + diff --git a/package.json b/package.json index e465f971..5ac6fa78 100644 --- a/package.json +++ b/package.json @@ -1,51 +1,65 @@ { - "name": "LiveWell", - "version": "0.0.1", - "description": "LiveWell application, expert system and notifications for bipolar intervention", - "author": "Mark Begale", - "contributors": [ - { - "name": "Mark Begale", - "email": "m-begale@northwestern.edu" + "name": "LiveWell", + "version": "0.0.1", + "description": "LiveWell application, expert system and notifications for bipolar intervention", + "author": "Mark Begale", + "contributors": [ + { + "name": "Mark Begale", + "email": "m-begale@northwestern.edu" + } + ], + "dependencies": { + "angular": "^1.4.0", + "angular-resource": "^1.4.0", + "angular-route": "^1.4.0", + "cordova": "5.3.1", + "cordova-android": "^6.2.3", + "cordova-plugin-device": "~1.1.4", + "cordova-plugin-whitelist": "~1.3.1", + "font-awesome": "^4.3.0", + "moment": "^2.10.2", + "phonegap-plugin-push": "~1.9.2" + }, + "devDependencies": { + "angular-mocks": "^1.4.0", + "chai": "^2.1.2", + "chai-as-promised": "^5.0.0", + "eslint": "^1.3.1", + "mocha": "^2.2.1", + "sinon": "^1.14.1", + "testem": "^0.8.0-0", + "wd": "^0.3.11" + }, + "keywords": [ + "bipolar" + ], + "scripts": { + "init": "npm install && npm_config_env=test npm_config_server=http://127.0.0.1:3000 npm run set_endpoint && npm run set_endpoint && npm run build:prepare && npm run browser:add_platform && npm run android:add_platform && npm run add_plugins", + "set_endpoint": "echo \"{\\\"environment\\\":\\\"$npm_config_env\\\",\\\"server\\\":\\\"$npm_config_server\\\"}\" > src/config.json && sed s%ACCESS_ORIGIN%$npm_config_server%g config > config.xml", + "android:add_platform": "./node_modules/.bin/cordova platform remove android && ./node_modules/.bin/cordova platform add android@4.0.0", + "android:build": "npm run build:prepare && ./node_modules/.bin/cordova build android", + "android:simulator": "npm run android:build && ./node_modules/.bin/cordova run android", + "browser:add_platform": "./node_modules/.bin/cordova platform remove browser && ./node_modules/.bin/cordova platform add browser && npm run add_plugins", + "add_plugins": "", + "browser:build": "npm run build:prepare && ./node_modules/.bin/cordova build browser", + "browser:simulator": "npm run browser:build && ./node_modules/.bin/cordova run browser", + "build:all": "npm run browser:build && npm run android:build", + "build:clean": "rm -rf www && mkdir -p www/js www/css", + "build:prepare": "npm run build:clean && cp -r src/* www/", + "eslint": "./node_modules/.bin/eslint src && ./node_modules/.bin/eslint test", + "eslint:src": "./node_modules/.bin/eslint src", + "eslint:test": "./node_modules/.bin/eslint test", + "serve": "npm run build:prepare && ./node_modules/.bin/cordova run browser" + }, + "cordova": { + "plugins": { + "cordova-plugin-device": {}, + "cordova-plugin-whitelist": {}, + "phonegap-plugin-push": {} + }, + "platforms": [ + "android" + ] } - ], - "dependencies": { - "angular": "^1.4.0", - "angular-resource": "^1.4.0", - "angular-route": "^1.4.0", - "cordova": "5.3.1", - "font-awesome": "^4.3.0", - "moment": "^2.10.2" - }, - "devDependencies": { - "angular-mocks": "^1.4.0", - "chai": "^2.1.2", - "chai-as-promised": "^5.0.0", - "eslint": "^1.3.1", - "mocha": "^2.2.1", - "sinon": "^1.14.1", - "testem": "^0.8.0-0", - "wd": "^0.3.11" - }, - "keywords": [ - "bipolar" - ], - "scripts": { - "init": "npm install && npm_config_env=test npm_config_server=http://127.0.0.1:3000 npm run set_endpoint && npm run set_endpoint && npm run build:prepare && npm run browser:add_platform && npm run android:add_platform && npm run add_plugins", - "set_endpoint": "echo \"{\\\"environment\\\":\\\"$npm_config_env\\\",\\\"server\\\":\\\"$npm_config_server\\\"}\" > src/config.json && sed s%ACCESS_ORIGIN%$npm_config_server%g config > config.xml", - "android:add_platform": "./node_modules/.bin/cordova platform remove android && ./node_modules/.bin/cordova platform add android@4.0.0", - "android:build": "npm run build:prepare && ./node_modules/.bin/cordova build android", - "android:simulator": "npm run android:build && ./node_modules/.bin/cordova run android", - "browser:add_platform": "./node_modules/.bin/cordova platform remove browser && ./node_modules/.bin/cordova platform add browser && npm run add_plugins", - "add_plugins": "", - "browser:build": "npm run build:prepare && ./node_modules/.bin/cordova build browser", - "browser:simulator": "npm run browser:build && ./node_modules/.bin/cordova run browser", - "build:all": "npm run browser:build && npm run android:build", - "build:clean": "rm -rf www && mkdir -p www/js www/css", - "build:prepare": "npm run build:clean && cp -r src/* www/", - "eslint": "./node_modules/.bin/eslint src && ./node_modules/.bin/eslint test", - "eslint:src": "./node_modules/.bin/eslint src", - "eslint:test": "./node_modules/.bin/eslint test", - "serve": "npm run build:prepare && ./node_modules/.bin/cordova run browser" - } -} +} \ No newline at end of file diff --git a/plugins/android.json b/plugins/android.json index 956289db..ba7b578b 100644 --- a/plugins/android.json +++ b/plugins/android.json @@ -7,17 +7,17 @@ "files": {} }, "installed_plugins": { - "cordova-plugin-whitelist": { + "cordova-plugin-app-version": { "PACKAGE_NAME": "edu.northwestern.cbits.livewell" }, "cordova-plugin-device": { "PACKAGE_NAME": "edu.northwestern.cbits.livewell" }, - "phonegap-plugin-push": { - "SENDER_ID": "334078391843", + "cordova-plugin-whitelist": { "PACKAGE_NAME": "edu.northwestern.cbits.livewell" }, - "cordova-plugin-app-version": { + "phonegap-plugin-push": { + "SENDER_ID": "334078391843", "PACKAGE_NAME": "edu.northwestern.cbits.livewell" } }, diff --git a/www/scripts/controllers/daily_review.js b/www/scripts/controllers/daily_review.js index 0cf756b4..9ba5f1e9 100644 --- a/www/scripts/controllers/daily_review.js +++ b/www/scripts/controllers/daily_review.js @@ -56,9 +56,15 @@ angular.module('livewellApp').controller('DailyReviewCtrl', function($scope, $ro dailyCount = parseInt(localStorage['dailyCheckInCount']); } - if (dailyCount >= 4) { + var toReport = null; + + if (dailyCount >= 5) { $scope.updatedClinicalStatus = ClinicalStatusUpdate.execute(); + + toReport = $scope.updatedClinicalStatus; } else { + + toReport = ClinicalStatusUpdate.noExecute(); // console.log('4 OR FEWER RESPONSES -- NOT UPDATING STATUS CODE'); } @@ -79,7 +85,7 @@ angular.module('livewellApp').controller('DailyReviewCtrl', function($scope, $ro (new PurpleRobot()).emitReading('livewell_clinicalstatus', { sessionGUID: sessionID, - status: $scope.updatedClinicalStatus, + status: toReport, clinicalStatus: clinicalStatus }).execute(); diff --git a/www/scripts/controllers/ews.js b/www/scripts/controllers/ews.js index 2be86186..0baefa81 100644 --- a/www/scripts/controllers/ews.js +++ b/www/scripts/controllers/ews.js @@ -8,40 +8,50 @@ * Controller of the livewellApp */ angular.module('livewellApp') - .controller('EwsCtrl', function ($scope,$location,UserData,UserDetails,Guid) { - $scope.pageTitle = "Weekly Check In"; - - $scope.ews = UserData.query('ews'); - - $scope.onClick=function() { - var responses = $('form').serializeArray(); - - console.log('EWS RESPONSE LENGTH: ' + responses.length); - - if (responses.length > 0) { - var el = JSON.stringify(responses || {name:'ews', value:null}); - - var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); - - var sessionID = Guid.create(); - - var payload = { - userId: UserDetails.find, - survey: 'ews', - questionDataLabel: 'ews', - questionValue: el, - sessionGUID: sessionID, - savedAt: new Date(), - clinicalStatus: clinicalStatus - }; - - console.log('EWS RESPONSE: ' + JSON.stringify(payload)); - - (new PurpleRobot()).emitReading('livewell_survey_data',payload).execute(); - - $location.path('/ews2'); - } else { - alert('Please choose at least one answer to continue. Select "None" if no other answer applies.'); - } - } + .controller('EwsCtrl', function ($scope,$location,UserData,UserDetails,Guid) { + $scope.pageTitle = "Weekly Check In"; + + $scope.ews = UserData.query('ews'); + + $scope.onClick=function() { + var responses = $('form').serializeArray(); + + if (responses.length > 0) { + var hasNone = false; + + for (var i = 0; i < responses.length; i++) { + if (responses[i]['value'] == 'None') { + hasNone = true; + } + } + + if (hasNone && responses.length > 1) { + alert('"None" cannot be selected with other options.'); + } else { + var el = JSON.stringify(responses || {name:'ews', value:null}); + + var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); + + var sessionID = Guid.create(); + + var payload = { + userId: UserDetails.find, + survey: 'ews', + questionDataLabel: 'ews', + questionValue: el, + sessionGUID: sessionID, + savedAt: new Date(), + clinicalStatus: clinicalStatus + }; + + console.log('EWS RESPONSE: ' + JSON.stringify(payload)); + + (new PurpleRobot()).emitReading('livewell_survey_data',payload).execute(); + + $location.path('/ews2'); + } + } else { + alert('Please choose at least one answer to continue. Select "None" if no other answer applies.'); + } + }; }); diff --git a/www/scripts/controllers/ews2.js b/www/scripts/controllers/ews2.js index 6024c10a..eba350ae 100644 --- a/www/scripts/controllers/ews2.js +++ b/www/scripts/controllers/ews2.js @@ -15,28 +15,38 @@ angular.module('livewellApp') $scope.onClick=function(){ var responses = $('form').serializeArray(); - console.log('EWS RESPONSE LENGTH: ' + responses.length); - if (responses.length > 0) { - var el = JSON.stringify(responses || {name:'ews', value:null}); - var sessionID = Guid.create(); - - var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); - - var payload = { - userId: UserDetails.find, - survey: 'ews2', - questionDataLabel: 'ews2', - questionValue: el, - sessionGUID: sessionID, - savedAt: new Date(), - clinicalStatus: clinicalStatus - }; - - (new PurpleRobot()).emitReading('livewell_survey_data',payload).execute(); - console.log(JSON.stringify(payload)); - - $location.path('/'); + var hasNone = false; + + for (var i = 0; i < responses.length; i++) { + if (responses[i]['value'] == 'None') { + hasNone = true; + } + } + + if (hasNone && responses.length > 1) { + alert('"None" cannot be selected with other options.'); + } else { + var el = JSON.stringify(responses || {name:'ews', value:null}); + var sessionID = Guid.create(); + + var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); + + var payload = { + userId: UserDetails.find, + survey: 'ews2', + questionDataLabel: 'ews2', + questionValue: el, + sessionGUID: sessionID, + savedAt: new Date(), + clinicalStatus: clinicalStatus + }; + + (new PurpleRobot()).emitReading('livewell_survey_data',payload).execute(); + console.log(JSON.stringify(payload)); + + $location.path('/'); + } } else { alert('Please choose at least one answer to continue. Select "None" if no other answer applies.'); } diff --git a/www/scripts/controllers/fetch_content.js b/www/scripts/controllers/fetch_content.js index 206edfe2..079b4369 100644 --- a/www/scripts/controllers/fetch_content.js +++ b/www/scripts/controllers/fetch_content.js @@ -78,6 +78,8 @@ angular.module('livewellApp').controller('FetchContentCtrl', function ($scope,$h if (oldVersion == undefined || newVersion > oldVersion) { localStorage[el.route] = JSON.stringify(newStatus); + + // TODO } } } diff --git a/www/scripts/controllers/weekly_check_in.js b/www/scripts/controllers/weekly_check_in.js index 4433edec..305ff936 100644 --- a/www/scripts/controllers/weekly_check_in.js +++ b/www/scripts/controllers/weekly_check_in.js @@ -23,113 +23,112 @@ angular.module('livewellApp').controller('WeeklyCheckInCtrl', function($scope, $ //overrides questiongroup default submit action to send data to PR $scope.submit = function() { + var _SAVE_LOCATION = 'livewell_survey_data'; - var _SAVE_LOCATION = 'livewell_survey_data'; + $scope.responseArray[$scope.currentIndex] = $('form').serializeArray()[0]; - $scope.responseArray[$scope.currentIndex] = $('form').serializeArray()[0]; + var responses = _.flatten($scope.responseArray); - var responses = _.flatten($scope.responseArray); + var sessionID = Guid.create(); - var sessionID = Guid.create(); - - var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); + var clinicalStatus = JSON.parse(localStorage['clinicalStatus']); - _.each(responses, function(el) { - var payload = { - userId: UserDetails.find, - survey: $scope.pageTitle, - questionDataLabel: el.name, - questionValue: el.value, - sessionGUID: sessionID, - savedAt: new Date(), - clinicalStatus: clinicalStatus + _.each(responses, function(el) { + var payload = { + userId: UserDetails.find, + survey: $scope.pageTitle, + questionDataLabel: el.name, + questionValue: el.value, + sessionGUID: sessionID, + savedAt: new Date(), + clinicalStatus: clinicalStatus + }; + + (new PurpleRobot()).emitReading(_SAVE_LOCATION, payload).execute(); + console.log(payload); + }); + + var responsePayload = { + sessionID: sessionID, + responses: responses }; - (new PurpleRobot()).emitReading(_SAVE_LOCATION, payload).execute(); - console.log(payload); - }); - - var responsePayload = { - sessionID: sessionID, - responses: responses - }; - - Pound.add('weeklyCheckIn', responsePayload); - - var lWR = responses; - var phq8Sum = parseInt(lWR[0].value) + parseInt(lWR[1].value) + parseInt(lWR[2].value) + parseInt(lWR[3].value) + parseInt(lWR[4].value) + parseInt(lWR[5].value) + parseInt(lWR[6].value) + parseInt(lWR[7].value); - var amrsSum = parseInt(lWR[8].value) + parseInt(lWR[9].value) + parseInt(lWR[10].value) + parseInt(lWR[11].value) + parseInt(lWR[12].value); - - if (_.where(JSON.parse(localStorage.team, { role: 'Psychiatrist' })[0] != undefined)) { - $scope.psychiatristEmail = _.where(JSON.parse(localStorage.team), { - role: 'Psychiatrist' - })[0].email; - } else { - $scope.psychiatristEmail = ''; - } - - if (_.where(JSON.parse(localStorage.team), { role: 'Coach' })[0] != undefined) { - $scope.coachEmail = _.where(JSON.parse(localStorage.team), { - role: 'Coach' - })[0].email; - } else { - $scope.coachEmail = '' - } - - if (amrsSum >= 10) { - (new PurpleRobot()).emitReading('livewell_clinicalreachout', { - call: 'coach', - message: 'Altman Mania Rating Scale >= 10', - clinicalStatus: clinicalStatus - }).execute(); + Pound.add('weeklyCheckIn', responsePayload); + + var lWR = responses; + var phq8Sum = parseInt(lWR[0].value) + parseInt(lWR[1].value) + parseInt(lWR[2].value) + parseInt(lWR[3].value) + parseInt(lWR[4].value) + parseInt(lWR[5].value) + parseInt(lWR[6].value) + parseInt(lWR[7].value); + var amrsSum = parseInt(lWR[8].value) + parseInt(lWR[9].value) + parseInt(lWR[10].value) + parseInt(lWR[11].value) + parseInt(lWR[12].value); + + if (_.where(JSON.parse(localStorage.team, { role: 'Psychiatrist' })[0] != undefined)) { + $scope.psychiatristEmail = _.where(JSON.parse(localStorage.team), { + role: 'Psychiatrist' + })[0].email; + } else { + $scope.psychiatristEmail = ''; + } + + if (_.where(JSON.parse(localStorage.team), { role: 'Coach' })[0] != undefined) { + $scope.coachEmail = _.where(JSON.parse(localStorage.team), { + role: 'Coach' + })[0].email; + } else { + $scope.coachEmail = '' + } + + if (amrsSum >= 10) { + (new PurpleRobot()).emitReading('livewell_clinicalreachout', { + call: 'coach', + message: 'Altman Mania Rating Scale >= 10', + clinicalStatus: clinicalStatus + }).execute(); - (new PurpleRobot()).emitReading('livewell_email', { - coachEmail: $scope.coachEmail, - message: 'Altman Mania Rating Scale >= 10', - clinicalStatus: clinicalStatus - }).execute(); - } - if (amrsSum >= 16) { - (new PurpleRobot()).emitReading('livewell_clinicalreachout', { - call: 'psychiatrist', - message: 'Altman Mania Rating Scale >= 16', - clinicalStatus: clinicalStatus - }).execute(); - - (new PurpleRobot()).emitReading('livewell_email', { - psychiatristEmail: $scope.psychiatristEmail, - message: 'Altman Mania Rating Scale >= 16', - clinicalStatus: clinicalStatus - }).execute(); - } - - if (phq8Sum >= 15) { - (new PurpleRobot()).emitReading('livewell_clinicalreachout', { - call: 'coach', - message: 'PHQ8 >= 15', - clinicalStatus: clinicalStatus - }).execute(); - - (new PurpleRobot()).emitReading('livewell_email', { - coachEmail: $scope.coachEmail, - message: 'PHQ8 >= 15', - clinicalStatus: clinicalStatus - }).execute(); - } - if (phq8Sum >= 20) { - (new PurpleRobot()).emitReading('livewell_clinicalreachout', { - call: 'psychiatrist', - message: 'PHQ8 >= 20', - clinicalStatus: clinicalStatus - }).execute(); - - (new PurpleRobot()).emitReading('livewell_email', { - psychiatristEmail: $scope.psychiatristEmail, - message: 'PHQ8 >= 20', - clinicalStatus: clinicalStatus - }).execute(); - } - - $location.path("/ews"); + (new PurpleRobot()).emitReading('livewell_email', { + coachEmail: $scope.coachEmail, + message: 'Altman Mania Rating Scale >= 10', + clinicalStatus: clinicalStatus + }).execute(); + } + if (amrsSum >= 16) { + (new PurpleRobot()).emitReading('livewell_clinicalreachout', { + call: 'psychiatrist', + message: 'Altman Mania Rating Scale >= 16', + clinicalStatus: clinicalStatus + }).execute(); + + (new PurpleRobot()).emitReading('livewell_email', { + psychiatristEmail: $scope.psychiatristEmail, + message: 'Altman Mania Rating Scale >= 16', + clinicalStatus: clinicalStatus + }).execute(); + } + + if (phq8Sum >= 15) { + (new PurpleRobot()).emitReading('livewell_clinicalreachout', { + call: 'coach', + message: 'PHQ8 >= 15', + clinicalStatus: clinicalStatus + }).execute(); + + (new PurpleRobot()).emitReading('livewell_email', { + coachEmail: $scope.coachEmail, + message: 'PHQ8 >= 15', + clinicalStatus: clinicalStatus + }).execute(); + } + if (phq8Sum >= 20) { + (new PurpleRobot()).emitReading('livewell_clinicalreachout', { + call: 'psychiatrist', + message: 'PHQ8 >= 20', + clinicalStatus: clinicalStatus + }).execute(); + + (new PurpleRobot()).emitReading('livewell_email', { + psychiatristEmail: $scope.psychiatristEmail, + message: 'PHQ8 >= 20', + clinicalStatus: clinicalStatus + }).execute(); + } + + $location.path("/ews"); } }); \ No newline at end of file diff --git a/www/scripts/services/clinicalstatusupdate.js b/www/scripts/services/clinicalstatusupdate.js index 1b914047..1c728e69 100644 --- a/www/scripts/services/clinicalstatusupdate.js +++ b/www/scripts/services/clinicalstatusupdate.js @@ -9,10 +9,12 @@ angular.module('livewellApp').service('ClinicalStatusUpdate', function(Pound, UserData) { // AngularJS will instantiate a singleton by calling "new" on this function var contents = {}; + + var currentClinicalStatusCode = function() { + return UserData.query('clinicalStatus').currentCode + }; + contents.execute = function() { - var currentClinicalStatusCode = function() { - return UserData.query('clinicalStatus').currentCode - }; //"[{"code":1,"label":"well"},{"code":2,"label":"prodromal"},{"code":3,"label":"recovering"},{"code":4,"label":"unwell"}]" var dailyReviewResponses = Pound.find('dailyCheckIn'); @@ -157,5 +159,60 @@ angular.module('livewellApp').service('ClinicalStatusUpdate', function(Pound, Us return returnStatus } + contents.noExecute = function() { + var returnStatus = {}; + + var dailyReviewResponses = Pound.find('dailyCheckIn'); + + var intensityCount = { + 0: 0, + 1: 0, + 2: 0, + 3: 0, + 4: 0 + }; + + for (var i = dailyReviewResponses.length - 1; i > dailyReviewResponses.length - 8; i--) { + var aWV = 0; + + if (dailyReviewResponses[i] != undefined) { + aWV = Math.abs(parseInt(dailyReviewResponses[i].wellness)); + } + + console.log(aWV); + + if (aWV == 0) { + intensityCount[0] = intensityCount[0] + 1 + } else if (aWV == 1) { + intensityCount[1] = intensityCount[1] + 1 + } else if (aWV == 2) { + intensityCount[2] = intensityCount[2] + 1 + } else if (aWV == 3) { + intensityCount[3] = intensityCount[3] + 1 + } else if (aWV == 4) { + intensityCount[4] = intensityCount[4] + 1 + } + } + + returnStatus.intensityCount = intensityCount; + + var weeklyReviewResponses = Pound.find('weeklyCheckIn'); + + if (weeklyReviewResponses[weeklyReviewResponses.length - 1] != undefined){ + var lWR = weeklyReviewResponses[weeklyReviewResponses.length - 1].responses; + + var phq8Sum = parseInt(lWR[0].value) + parseInt(lWR[1].value) + parseInt(lWR[2].value) + parseInt(lWR[3].value) + parseInt(lWR[4].value) + parseInt(lWR[5].value) + parseInt(lWR[6].value) + parseInt(lWR[7].value); + var amrsSum = parseInt(lWR[8].value) + parseInt(lWR[9].value) + parseInt(lWR[10].value) + parseInt(lWR[11].value) + parseInt(lWR[12].value); + + returnStatus.amrsSum = amrsSum; + returnStatus.phq8Sum = phq8Sum; + } + + returnStatus.oldStatus = currentClinicalStatusCode(); + returnStatus.newStatus = currentClinicalStatusCode(); + + return returnStatus + } + return contents; }); \ No newline at end of file diff --git a/www/views/ews.html b/www/views/ews.html index e74d9e11..07f21b54 100644 --- a/www/views/ews.html +++ b/www/views/ews.html @@ -11,7 +11,6 @@

Check all warning signs of mania you experienced in the past week. If none, -
Next