diff --git a/www/js/app.js b/www/js/app.js index 90b5ee9..1c92034 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -153,10 +153,12 @@ angular.module('app', ['ionic', 'firebase', 'app.controllers', 'app.routes', 'ap Patient.setAttribute("token", response.token) Patient.setAttribute("uid", response.uid) - if ($rootScope.modal) - $rootScope.modal.remove().then(function() { - $rootScope.$broadcast(onpoint.env.data.refresh); - }) + $ionicHistory.clearCache().then(function() { + if ($rootScope.modal) + $rootScope.modal.remove().then(function() { + $rootScope.$broadcast(onpoint.env.data.refresh); + }) + }) }) $rootScope.$on(onpoint.env.auth.failure, function(event, data) { diff --git a/www/js/controllers/medicationIdentificationCtrl.js b/www/js/controllers/medicationIdentificationCtrl.js index e308b13..4617937 100644 --- a/www/js/controllers/medicationIdentificationCtrl.js +++ b/www/js/controllers/medicationIdentificationCtrl.js @@ -105,18 +105,31 @@ angular.module('app.controllers') }) -.controller('medicationsListCtrl', function($scope, $state, Patient, Medication, MedicationSchedule) { +.controller('medicationsListCtrl', function($scope, $state, Patient, Medication, MedicationSchedule, $ionicLoading) { $scope.scheduledMedications = Medication.get(); $scope.completeMedicationIdentification = function() { - Medication.setDefaultMeds() - - var ref = Patient.ref().child('onboarding'); - ref.set({'medication_identification':true}).then(function(response) { - onboarding = Patient.get().onboarding - onboarding.medication_identification = true - Patient.setAttribute("onboarding", onboarding) - $state.go("medication_scheduling.welcome") + $ionicLoading.show(); + + console.log("Completing...") + Medication.setDefaultMeds().then(function(response) { + + console.log(response) + + MedicationSchedule.setDefaultSchedule().then(function(response) { + + var ref = Patient.ref().child('onboarding'); + ref.set({'medication_identification':true}).then(function(response) { + onboarding = Patient.get().onboarding + onboarding.medication_identification = true + Patient.setAttribute("onboarding", onboarding) + + $ionicLoading.hide(); + + $state.go("medication_scheduling.welcome") + }) + + }) }) } diff --git a/www/js/controllers/medicationSchedulingCtrl.js b/www/js/controllers/medicationSchedulingCtrl.js index f7c7270..7d52c30 100644 --- a/www/js/controllers/medicationSchedulingCtrl.js +++ b/www/js/controllers/medicationSchedulingCtrl.js @@ -11,11 +11,7 @@ angular.module('app.controllers') $scope.showError = false; $scope.medication = {} - $scope.$on("$ionicView.loaded", function() { - if ($scope.schedule.length == 0) { - MedicationSchedule.setDefaultSchedule() - } - }) + console.log(Patient.getToken()) $scope.sortSchedule = function() { $scope.schedule.sort(function(a, b){var dat1 = a.time.split(":"); var dat2 = b.time.split(":"); diff --git a/www/js/services/medication.js b/www/js/services/medication.js index 0cd11c4..a99d40e 100644 --- a/www/js/services/medication.js +++ b/www/js/services/medication.js @@ -1,6 +1,6 @@ angular.module('app.services') -.factory('Medication',["Patient","$firebaseObject", "$firebaseArray", function(Patient, $firebaseObject,$firebaseArray) { +.factory('Medication',["Patient","$firebaseObject", "$firebaseArray", "$http", function(Patient, $firebaseObject,$firebaseArray, $http) { /* * These are default medcations set/instructions for testing purposes * TODO: delete id field @@ -15,15 +15,6 @@ angular.module('app.services') {id: 6, name: "metformin", trade_name: "Riomet", instructions: "Take orally, twice daily, with meals", purpose: "Used to treat Type 2 Diabetes.", dose: 40, tablets: 6, required: false, img:"riomet.png"}, {id: 7, name: "statin", trade_name: "Lipitor", instructions: "TODO: Add instructions here", purpose: "It can treat high cholesterol and triglyceride levels.", dose: 40, tablets: 7, required: false, img:"lipitor.png"} ] - var defaultMeds = [ - {id: 1, name: "furomeside", trade_name: "Lasix", instructions: "Take twice daily; First in morning and then 6-8 hours later", purpose: "Treats salt and fluid retention and swelling caused by heart failure.", dose: 40, tablets: 1, required: false, img:"lasix.png"}, - {id: 2, name: "metoprolol", trade_name: "Toprol XL", instructions: "TODO: Add instructions here", purpose: "Used to treat chest pain (angina), heart failure, and high blood pressure.", dose: 500, tablets: 2, required: true, img:"toprol.png"}, - {id: 3, name: "lisinopril", trade_name: "Zestril", instructions: "TODO: Add instructions here", purpose: "Zestril is used to treat high blood pressure (hypertension) or congestive heart failure.", dose: 40, tablets: 3, required: false, img:"zestril.png"}, - {id: 4, name: "warfarin", trade_name: "Coumadin", instructions: "Take orally once a day in the morning", purpose: "Treats and prevents blood clots by acting as a blood thinner.", dose: 500, tablets: 4, required: true, img:"coumadin.png"}, - {id: 5, name: "losartan", trade_name: "Cozaar", instructions: "TODO: Add instructions here", purpose: "It can treat high blood pressure.", dose: 40, tablets: 5, required: false, img:"cozaar.png"}, - {id: 6, name: "metformin", trade_name: "Riomet", instructions: "Take orally, twice daily, with meals", purpose: "Used to treat Type 2 Diabetes.", dose: 40, tablets: 6, required: false, img:"riomet.png"}, - {id: 7, name: "statin", trade_name: "Lipitor", instructions: "TODO: Add instructions here", purpose: "It can treat high cholesterol and triglyceride levels.", dose: 40, tablets: 7, required: false, img:"lipitor.png"} - ] input_medications = []; return { @@ -44,12 +35,13 @@ angular.module('app.services') * Temporary method for clinician testing */ setDefaultMeds: function() { - ref = this.ref(); - console.log(defaultMeds) - for(var i = 0; i < defaultMeds.length; i++) { - console.log(defaultMeds[i]) - ref.push(defaultMeds[i]); //Each Med will have its own unique ID generated by FB! - } + return $http({ + method: "POST", + url: onpoint.env.serverURL + "medications", + headers: { + "Authorization": "Bearer " + Patient.getToken() + } + }) }, ref: function() { diff --git a/www/js/services/medication_schedule.js b/www/js/services/medication_schedule.js index fb27e21..437b5bd 100644 --- a/www/js/services/medication_schedule.js +++ b/www/js/services/medication_schedule.js @@ -3,47 +3,19 @@ angular.module('app.services') // This factory is responsible for defining a Medication Schedule // that the patient usually adheres to. -.factory('MedicationSchedule', ["Medication", "Patient","$firebaseObject", "$firebaseArray", function(Medication, Patient, $firebaseObject,$firebaseArray) { - /* - * This is default schedule for testing purposes - * TODO: (much later) delete this. - */ - schedule = [ - { - time: "08:00", - name: "Morning", - days: [true, true, true, true, true, true, true], //array descirbing days of week to do this action - medications: ["Lasix", "Toprol XL", "Zestril", "Coumadin", "Riomet"] - }, - { - time: "13:00", - name: "Afternoon", - days: [true, true, true, true, true, true, true], //array descirbing days of week to do this action, - medications: ["Lasix", "Toprol XL", "Zestril", "Riomet"] - }, - { - time: "19:00", - name: "Evening", - days: [true, true, true, true, true, true, true], //array descirbing days of week to do this action, - medications: ["Lipitor"] - } - ] - +.factory('MedicationSchedule', ["Medication", "Patient","$firebaseObject", "$firebaseArray", "$http", function(Medication, Patient, $firebaseObject,$firebaseArray, $http) { return { /* * Temporary method for clinician testing */ setDefaultSchedule: function() { - // var ref = this.ref().child("default") - var ref = this.ref() - ref.once("value", function(snapshot) { - if (!snapshot.exists()) { //only push default schedule once. - for(var i = 0; i < schedule.length; i++) { - ref.push(schedule[i]); - } + return $http({ + method: "POST", + url: onpoint.env.serverURL + "medication_schedule", + headers: { + "Authorization": "Bearer " + Patient.getToken() } }) - }, ref: function() { @@ -59,7 +31,29 @@ angular.module('app.services') get: function() { // var ref = this.ref().child("default"); var ref = this.ref() - return $firebaseArray(ref); + return $firebaseArray(ref) + + // .$loaded().then(function(response) { + // console.log(response) + // return response + + // med_names = [] + // + // var uid = Patient.uid(); + // query = Patient.ref(uid).child("medications") + // query.once("value").then(function(snapshot) { + // + // snapshot.forEach(function(childSnapshot) { + // // key will be "ada" the first time and "alan" the second time + // var key = childSnapshot.key; + // // console.log(key) + // // childData will be the actual contents of the child + // var childData = childSnapshot.val(); + // if (childData) + // med_names = childData.map(function(med) { return med.trade_name}) + // }); + // }) + // }); }, /* diff --git a/www/templates/login.html b/www/templates/login.html index 0e190af..48d58f8 100644 --- a/www/templates/login.html +++ b/www/templates/login.html @@ -1,5 +1,5 @@ - +