@@ -9,9 +9,6 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
99 showVariableCategorySelector : false ,
1010 showUnits : false ,
1111 unitCategories : [ ] ,
12- variableCategoryName : getVariableCategoryName ( ) ,
13- variableCategoryObject : getVariableCategory ( ) ,
14- helpText : getVariableCategory ( ) . helpText ,
1512 unitAbbreviatedName : '' ,
1613 measurement : { } ,
1714 searchedUnits : [ ] ,
@@ -30,6 +27,16 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
3027 qmService . navBar . showNavigationMenuIfHideUrlParamNotSet ( ) ;
3128 qmService . rootScope . setProperty ( 'bloodPressure' , { systolicValue : null , diastolicValue : null , show : false } ) ;
3229 $scope . state . title = 'Record a Measurement' ;
30+ setupMeasurement ( ) ;
31+ var cat = getVariableCategory ( ) ;
32+ if ( cat ) { setupVariableCategory ( cat ) ; }
33+ } ) ;
34+ $scope . $on ( '$ionicView.enter' , function ( e ) {
35+ qmLogService . debug ( '$ionicView.enter ' + $state . current . name ) ;
36+ qmService . hideLoader ( ) ;
37+ qmLog . info ( "$ionicView.enter $scope.state.measurement is " , $scope . state . measurement ) ;
38+ } ) ;
39+ function setupMeasurement ( ) {
3340 $scope . state . selectedDate = moment ( ) ;
3441 $scope . state . units = qm . unitHelper . getNonAdvancedUnits ( ) ;
3542 var reminderFromUrl = qm . urlHelper . getParam ( 'trackingReminderObject' , window . location . href , true ) ;
@@ -39,33 +46,34 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
3946 var v = $stateParams . variableObject ;
4047 var n = $stateParams . reminderNotification ;
4148 var id = qm . urlHelper . getParam ( 'measurementId' , location . href , true ) ;
42- if ( tr ) {
49+ if ( tr ) {
4350 setupTrackingByReminder ( tr ) ;
44- } else if ( m ) {
51+ } else if ( m ) {
4552 setupTrackingByMeasurement ( m ) ;
46- } else if ( measurementFromUrl ) {
53+ } else if ( measurementFromUrl ) {
4754 setupTrackingByMeasurement ( JSON . parse ( measurementFromUrl ) ) ;
48- } else if ( v ) {
55+ } else if ( v ) {
4956 setupFromVariable ( v ) ;
50- } else if ( reminderFromUrl ) {
57+ } else if ( reminderFromUrl ) {
5158 setupTrackingByReminder ( JSON . parse ( reminderFromUrl ) ) ;
52- } else if ( n ) {
59+ } else if ( n ) {
5360 setupTrackingByReminder ( n ) ;
54- } else if ( id ) {
55- setMeasurementVariablesByMeasurementId ( id ) . then ( function ( ) {
56- if ( ! $scope . state . measurementIsSetup ) { $scope . goBack ( ) ; }
61+ } else if ( id ) {
62+ setMeasurementVariablesByMeasurementId ( id ) . then ( function ( ) {
63+ if ( ! $scope . state . measurementIsSetup ) {
64+ $scope . goBack ( ) ;
65+ }
5766 } ) ;
58- } else if ( $stateParams . variableName ) {
67+ } else if ( $stateParams . variableName ) {
5968 setupFromVariableName ( $stateParams . variableName ) ;
6069 }
61- if ( ! $scope . state . measurementIsSetup ) { setupFromUrlParameters ( ) ; }
62- if ( ! $scope . state . measurementIsSetup ) { setupFromVariable ( qm . getPrimaryOutcomeVariable ( ) ) ; }
63- } ) ;
64- $scope . $on ( '$ionicView.enter' , function ( e ) {
65- qmLogService . debug ( '$ionicView.enter ' + $state . current . name ) ;
66- qmService . hideLoader ( ) ;
67- qmLog . info ( "$ionicView.enter $scope.state.measurement is " , $scope . state . measurement ) ;
68- } ) ;
70+ if ( ! $scope . state . measurementIsSetup ) {
71+ setupFromUrlParameters ( ) ;
72+ }
73+ if ( ! $scope . state . measurementIsSetup ) {
74+ setupFromVariable ( qm . getPrimaryOutcomeVariable ( ) ) ;
75+ }
76+ }
6977 var trackBloodPressure = function ( ) {
7078 if ( ! $rootScope . bloodPressure . diastolicValue || ! $rootScope . bloodPressure . systolicValue ) {
7179 qmService . validationFailure ( 'Please enter both values for blood pressure.' , $scope . state . measurement ) ;
@@ -149,9 +157,13 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
149157 setupVariableCategory ( variableCategoryName ) ;
150158 } ;
151159 var setupVariableCategory = function ( variableCategoryName ) {
160+ var cat = getVariableCategory ( variableCategoryName ) ;
152161 qmLogService . debug ( $state . current . name + ': ' + 'variableCategoryName is ' + variableCategoryName ) ;
153- $scope . state . measurement . variableCategoryName = variableCategoryName ;
154- var cat = getVariableCategory ( ) ;
162+ if ( $scope . state . measurement ) {
163+ $scope . state . measurement . variableCategoryName = cat . name ;
164+ }
165+ $scope . state . variableCategoryObject = cat ;
166+ $scope . state . helpText = cat . helpText ;
155167 $scope . state . title = "Add Measurement" ;
156168 $scope . state . measurementSynonymSingularLowercase = cat . measurementSynonymSingularLowercase ;
157169 if ( cat . defaultValueLabel ) { $scope . state . defaultValueLabel = cat . defaultValueLabel ; }
@@ -401,7 +413,7 @@ angular.module('starter').controller('MeasurementAddCtrl', ["$scope", "$q", "$ti
401413 if ( ! cat && $scope . state ) { cat = qm . variableCategoryHelper . findVariableCategory ( $scope . state ) ; }
402414 if ( ! cat ) { cat = qm . variableCategoryHelper . findVariableCategory ( $stateParams ) ; }
403415 if ( ! cat ) {
404- qmLog . error ( "No variable category name from getVariableCategory" )
416+ qmLog . debug ( "No variable category name from getVariableCategory" )
405417 return null ;
406418 }
407419 return cat ;
0 commit comments