Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 22 additions & 9 deletions www/js/controllers/medicationIdentificationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

})
})
}

Expand Down
6 changes: 1 addition & 5 deletions www/js/controllers/medicationSchedulingCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand Down
24 changes: 8 additions & 16 deletions www/js/services/medication.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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() {
Expand Down
64 changes: 29 additions & 35 deletions www/js/services/medication_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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})
// });
// })
// });
},

/*
Expand Down
2 changes: 1 addition & 1 deletion www/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ion-modal-view class="login-modal" ng-controller="loginCtrl">
<ion-content has-bouncing="false" class="login-view" scroll="false">
<ion-content has-bouncing="false" class="login-view" scroll="true">

<div class="error-box" ng-if="state.error">
<p>{{state.error}}</p>
Expand Down
4 changes: 2 additions & 2 deletions www/templates/medication_scheduling/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</ion-item>

<div dnd-list="dateSchedule.medications" dnd-allowed-types="['medType']" dnd-drop="dropCallback(event, index, item, external, type, 'itemType', dateSchedule, dateSchedule.medications == null)" class="itemlist">
<ion-item class="item-icon-left">
<i class="icon ion-ios-plus balanced" ng-click="addMedicationModal(dateSchedule.$id)"></i>
<ion-item class="item-icon-left" ng-click="addMedicationModal(dateSchedule.$id)">
<i class="icon ion-ios-plus balanced"></i>
Add a medication
</ion-item>

Expand Down