Skip to content

Commit

Permalink
Merge pull request #4069 from QuantiModo/feature/getVariableCategory
Browse files Browse the repository at this point in the history
variableCategoryHelper
  • Loading branch information
mikepsinn authored Sep 28, 2020
2 parents a4d35ff + 9b95e39 commit 97aad62
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 183 deletions.
88 changes: 51 additions & 37 deletions src/js/controllers/measurementAddCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
showVariableCategorySelector: false,
showUnits: false,
unitCategories: [],
variableCategoryName: getVariableCategoryName(),
variableCategoryObject: getVariableCategory(),
helpText: getVariableCategory().helpText,
unitAbbreviatedName: '',
measurement: {},
searchedUnits: [],
Expand All @@ -30,6 +27,16 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
qmService.navBar.showNavigationMenuIfHideUrlParamNotSet();
qmService.rootScope.setProperty('bloodPressure', {systolicValue: null, diastolicValue: null, show: false});
$scope.state.title = 'Record a Measurement';
setupMeasurement();
var cat = getVariableCategory();
if(cat){setupVariableCategory(cat);}
});
$scope.$on('$ionicView.enter', function(e){
qmLogService.debug('$ionicView.enter ' + $state.current.name);
qmService.hideLoader();
qmLog.info("$ionicView.enter $scope.state.measurement is ", $scope.state.measurement);
});
function setupMeasurement() {
$scope.state.selectedDate = moment();
$scope.state.units = qm.unitHelper.getNonAdvancedUnits();
var reminderFromUrl = qm.urlHelper.getParam('trackingReminderObject', window.location.href, true);
Expand All @@ -39,33 +46,34 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
var v = $stateParams.variableObject;
var n = $stateParams.reminderNotification;
var id = qm.urlHelper.getParam('measurementId', location.href, true);
if(tr){
if (tr) {
setupTrackingByReminder(tr);
}else if(m){
} else if (m) {
setupTrackingByMeasurement(m);
}else if(measurementFromUrl){
} else if (measurementFromUrl) {
setupTrackingByMeasurement(JSON.parse(measurementFromUrl));
}else if(v){
} else if (v) {
setupFromVariable(v);
}else if(reminderFromUrl){
} else if (reminderFromUrl) {
setupTrackingByReminder(JSON.parse(reminderFromUrl));
}else if(n){
} else if (n) {
setupTrackingByReminder(n);
}else if(id){
setMeasurementVariablesByMeasurementId(id).then(function(){
if(!$scope.state.measurementIsSetup){$scope.goBack();}
} else if (id) {
setMeasurementVariablesByMeasurementId(id).then(function () {
if (!$scope.state.measurementIsSetup) {
$scope.goBack();
}
});
}else if($stateParams.variableName){
} else if ($stateParams.variableName) {
setupFromVariableName($stateParams.variableName);
}
if(!$scope.state.measurementIsSetup){setupFromUrlParameters();}
if(!$scope.state.measurementIsSetup){setupFromVariable(qm.getPrimaryOutcomeVariable());}
});
$scope.$on('$ionicView.enter', function(e){
qmLogService.debug('$ionicView.enter ' + $state.current.name);
qmService.hideLoader();
qmLog.info("$ionicView.enter $scope.state.measurement is ", $scope.state.measurement);
});
if (!$scope.state.measurementIsSetup) {
setupFromUrlParameters();
}
if (!$scope.state.measurementIsSetup) {
setupFromVariable(qm.getPrimaryOutcomeVariable());
}
}
var trackBloodPressure = function(){
if(!$rootScope.bloodPressure.diastolicValue || !$rootScope.bloodPressure.systolicValue){
qmService.validationFailure('Please enter both values for blood pressure.', $scope.state.measurement);
Expand Down Expand Up @@ -142,16 +150,20 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
}
};
$scope.variableCategorySelectorChange = function(variableCategoryName){
var cat = qmService.getVariableCategoryInfo(variableCategoryName);
var cat = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
setupUnit(cat.defaultUnitAbbreviatedName);
$scope.state.defaultValuePlaceholderText = 'Enter a value';
$scope.state.defaultValueLabel = 'Value';
setupVariableCategory(variableCategoryName);
};
var setupVariableCategory = function(variableCategoryName){
var cat = getVariableCategory(variableCategoryName);
qmLogService.debug($state.current.name + ': ' + 'variableCategoryName is ' + variableCategoryName);
$scope.state.measurement.variableCategoryName = variableCategoryName;
var cat = getVariableCategory();
if($scope.state.measurement){
$scope.state.measurement.variableCategoryName = cat.name;
}
$scope.state.variableCategoryObject = cat;
$scope.state.helpText = cat.helpText;
$scope.state.title = "Add Measurement";
$scope.state.measurementSynonymSingularLowercase = cat.measurementSynonymSingularLowercase;
if(cat.defaultValueLabel){$scope.state.defaultValueLabel = cat.defaultValueLabel;}
Expand Down Expand Up @@ -246,7 +258,7 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
if(v.unitAbbreviatedName){
setupUnit(v.unitAbbreviatedName, v.valence);
}else if(v.variableCategoryName){
var category = qmService.getVariableCategoryInfo(v.variableCategoryName);
var category = qm.variableCategoryHelper.findVariableCategory(v);
setupUnit(category.defaultUnitAbbreviatedName, v.valence);
}
var m = qm.measurements.newMeasurement(v);
Expand Down Expand Up @@ -390,18 +402,20 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
hideSheet();
}, 20000);
});
function getVariableCategoryName(object){
var name;
if(object && object.variableCategoryName){name = object.variableCategoryName;}
if(!name && $scope.state && $scope.state.measurement && $scope.state.measurement.variableCategoryName){
name = $scope.state.measurement.variableCategoryName;
}
if(!name){name = $stateParams.variableCategoryName;}
if(!name){name = qm.urlHelper.getParam('variableCategoryName');}
if(!name && $stateParams.variableObject){name = $stateParams.variableObject.variableCategoryName;}
return name;
function getVariableCategoryName(obj){
var cat = getVariableCategory(obj);
if(!cat){return null;}
return cat.name;
}
function getVariableCategory(){
return qmService.getVariableCategoryInfo(getVariableCategoryName());
function getVariableCategory(obj){
var cat;
if(obj){cat = qm.variableCategoryHelper.findVariableCategory(obj);}
if(!cat && $scope.state){cat = qm.variableCategoryHelper.findVariableCategory($scope.state);}
if(!cat){cat = qm.variableCategoryHelper.findVariableCategory($stateParams);}
if(!cat){
qmLog.debug("No variable category name from getVariableCategory")
return null;
}
return cat;
}
}]);
8 changes: 3 additions & 5 deletions src/js/controllers/reminderAddCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
$scope.state.trackingReminder.id = $stateParams.trackingReminderId;
}
$scope.state.savingText = 'Save';
qm.variableCategoryHelper.getVariableCategoriesFromGlobalsOrApi(function(variableCategories){
$scope.state.variableCategories = variableCategories;
});
$scope.state.variableCategories = qm.variableCategoryHelper.getVariableCategories();
qmService.navBar.showNavigationMenuIfHideUrlParamNotSet();
qmService.login.sendToLoginIfNecessaryAndComeBack("beforeEnter in " + $state.current.name);
$stateParams.variableCategoryName = getVariableCategoryName();
Expand Down Expand Up @@ -419,7 +417,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
setHideDefaultValueField();
};
$scope.variableCategorySelectorChange = function(variableCategoryName){
$scope.state.variableCategoryObject = qmService.getVariableCategoryInfo(variableCategoryName);
$scope.state.variableCategoryObject = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
$scope.state.trackingReminder.unitAbbreviatedName = $scope.state.variableCategoryObject.defaultUnitAbbreviatedName;
$scope.state.defaultValuePlaceholderText = 'Enter most common value';
$scope.state.defaultValueLabel = 'Default Value';
Expand All @@ -440,7 +438,7 @@ angular.module('starter').controller('ReminderAddCtrl', ["$scope", "$state", "$s
}
var r = $scope.state.trackingReminder;
r.variableCategoryName = variableCategoryName;
$scope.state.variableCategoryObject = qmService.getVariableCategoryInfo(variableCategoryName);
$scope.state.variableCategoryObject = qm.variableCategoryHelper.findVariableCategory(variableCategoryName);
if(!r.unitAbbreviatedName){
r.unitAbbreviatedName = $scope.state.variableCategoryObject.defaultUnitAbbreviatedName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/controllers/remindersManageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ angular.module('starter').controller('RemindersManageCtrl', ["$scope", "$state",
}else{
$scope.state.noRemindersTitle = "Add " + cat;
$scope.state.noRemindersText = "You haven't saved any " + cat.toLowerCase() + " favorites or reminders here, yet.";
$scope.state.noRemindersIcon = qmService.getVariableCategoryInfo(cat).ionIcon;
$scope.state.noRemindersIcon = qm.variableCategoryHelper.findVariableCategory(cat).ionIcon;
$scope.stateParams.title = document.title = cat;
if(!$scope.stateParams.addButtonText){
$scope.stateParams.addButtonText = 'Add New ' + pluralize($filter('wordAliases')(cat), 1) + " Reminder";
Expand Down
2 changes: 1 addition & 1 deletion src/js/controllers/variableSearchCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ angular.module('starter').controller('VariableSearchCtrl',
}
function getVariableCategory(){
var name = getVariableCategoryName();
if(name){return qm.variableCategoryHelper.getByNameOrId(name);}
if(name){return qm.variableCategoryHelper.findVariableCategory(name);}
return null;
}
function getVariableCategoryName(){
Expand Down
Loading

0 comments on commit 97aad62

Please sign in to comment.