← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18050: tracker capture - saving lat & lng values for events

 

------------------------------------------------------------
revno: 18050
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-01-19 16:36:42 +0100
message:
  tracker capture - saving lat & lng values for events
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2015-01-14 11:21:15 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2015-01-19 15:36:42 +0000
@@ -316,7 +316,12 @@
             if(prStDe.allowProvidedElsewhere){
                 $scope.allowProvidedElsewhereExists = true;                
             }
-        });
+        });        
+        
+        if($scope.currentStage.captureCoordinates){
+            $scope.currentEvent.coordinate = {latitude: $scope.currentEvent.coordinate.latitude ? $scope.currentEvent.coordinate.latitude : '',
+                                     longitude: $scope.currentEvent.coordinate.longitude ? $scope.currentEvent.coordinate.longitude : ''};
+        }
         
         angular.forEach($scope.currentEvent.dataValues, function(dataValue){
             var val = dataValue.value;
@@ -389,6 +394,7 @@
                          };
                 DHIS2EventFactory.updateForSingleValue(ev).then(function(response){
                     $scope.currentElement.saved = true;
+                    $scope.currentEventOriginal = angular.copy($scope.currentEvent);
                 });
             }
         }
@@ -493,6 +499,39 @@
                       
     };
     
+    $scope.saveCoordinate = function(type){
+        
+        if(type === 'LAT'){
+            $scope.latitudeSaved = false;
+        }
+        else{
+            $scope.longitudeSaved = false;
+        }
+        
+        if( type === 'LAT' && $scope.outerForm.latitude.$invalid  || 
+            type === 'LNG' && $scope.outerForm.longitude.$invalid ){//invalid coordinate            
+            return;            
+        }
+        
+        if( type === 'LAT' && $scope.currentEvent.coordinate.latitude === $scope.currentEventOriginal.coordinate.latitude  || 
+            type === 'LNG' && $scope.currentEvent.coordinate.longitude === $scope.currentEventOriginal.coordinate.longitude){//no change            
+            return;            
+        }
+        
+        //valid coordinate(s), proceed with the saving
+        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage, $scope.optionSets);
+        
+        DHIS2EventFactory.update(dhis2Event).then(function(response){            
+            $scope.currentEventOriginal = angular.copy($scope.currentEvent);
+            if(type === 'LAT'){
+                $scope.latitudeSaved = true;
+            }
+            else{
+                $scope.longitudeSaved = true;
+            }
+        });
+    };
+    
     $scope.addNote = function(){
         if(!angular.isUndefined($scope.note) && $scope.note !== ""){
             var newNote = {value: $scope.note};
@@ -550,7 +589,7 @@
     
     $scope.completeIncompleteEvent = function(){
         var modalOptions;
-        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage);        
+        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage, $scope.optionSets);        
         if($scope.currentEvent.status === 'COMPLETED'){//activiate event
             modalOptions = {
                 closeButtonText: 'cancel',
@@ -594,7 +633,7 @@
     
     $scope.skipUnskipEvent = function(){
         var modalOptions;
-        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage);   
+        var dhis2Event = EventUtils.reconstruct($scope.currentEvent, $scope.currentStage, $scope.optionSets);   
 
         if($scope.currentEvent.status === 'SKIPPED'){//unskip event
             modalOptions = {

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2015-01-05 17:09:17 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2015-01-19 15:36:42 +0000
@@ -32,7 +32,6 @@
                 <tbody>
                     <tr>
                         <td class="inline-block" ng-repeat="dhis2Event in dhis2Events | orderBy:'sortingDate':reverse">
-                            <!--<span class="block align-center">{{dhis2Event.eventOrgUnitName}}</span> -->
                             <span class="stage-container" ng-class='getEventStyle(dhis2Event, false)' ng-click="showDataEntry(dhis2Event, false)">
                                 {{dhis2Event.name}}<br/>
                                 {{dhis2Event.sortingDate}}         
@@ -50,8 +49,7 @@
             <table class="table-borderless">
                 <tbody>
                     <tr>
-                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents| orderBy:'sortingDate':reverse">
-                            <!--<span class="block align-center">{{dhis2Event.eventOrgUnitName}}</span>-->                                              
+                        <td class="inline-block" ng-repeat="dummyEvent in dummyEvents| orderBy:'sortingDate':reverse">                                 
                             <span class="stage-container" ng-class='getEventStyle(dummyEvent, true)' ng-click="showDummyEventCreation(dummyEvent)">
                                 {{dummyEvent.name}}<br/>
                                 {{dummyEvent.dueDate}}         
@@ -83,70 +81,106 @@
             </form>
         </div>        
 
-        <div ng-if="currentEvent && !showEventCreationDiv">
-            <div class="row">
-                <div class="col-md-6">
-                    {{currentEvent.reportDateDescription}}
-                    <input type="text"
-                           placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
-                           class="form-control" 
-                           ng-class="{'input-success': eventDateSaved}"
-                           d2-date 
-                           ng-model="currentEvent.eventDate"
-                           ng-disabled="currentEvent.status === 'SKIPPED' || currentEvent.enrollmentStatus === 'COMPLETED'"    
-                           ng-required="true"
-                           blur-or-change="saveEventDate()"/>
-                    <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>
-                </div>
-                <div class="col-md-6">
-                    <span ng-if="currentEvent.eventDate || currentEvent.status === 'SKIPPED'">
-                        {{'due_date'| translate}}
-                    </span>
-                    <span ng-if="!currentEvent.eventDate && currentEvent.status !== 'SKIPPED'">
-                        <a href ng-click="enableRescheduling()" title="{{ schedulingEnabled ? 'disable_rescheduling' : 'enable_rescheduling' | translate}}"><span class="text-primary bold">{{'reschedule_duedate'| translate}}</span></a>                        
-                    </span>                    
-                    <input type="text" 
-                           placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
-                           class="form-control"
-                           ng-class="{'input-success': dueDateSaved}"
-                           d2-date 
-                           ng-model="currentEvent.dueDate"
-                           blur-or-change="saveDueDate()" 
-                           ng-disabled="currentEvent.eventDate || !schedulingEnabled || currentEvent.enrollmentStatus === 'COMPLETED'"/>
-                    <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>
-                </div>                        
-            </div>
-            <div ng-if="currentEvent.eventDate">                            
-                <div ng-if="customForm">
-                    <a href ng-click="switchDataEntryForm()" title="{{displayCustomForm ? 'default_form' : 'custom_form'| translate}}"><span class="primary pull-right"><i class="fa fa-file-text fa-2x"></i></span></a>                
-                </div>
-                <div class="clear vertical-spacing" ng-if="displayCustomForm" ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>  
-                <div class="clear vertical-spacing" ng-if="!displayCustomForm" ng-include="'components/dataentry/default-form.html'"></div>
-            </div>            
-
-            <div class="form-group">
-                <div class='row'><hr></div>
-                <a href ng-click="completeIncompleteEvent()" 
-                   class="btn btn-warning" 
-                   ng-disabled="currentEvent.enrollmentStatus === 'COMPLETED'"
-                   ng-if="currentEvent.eventDate && ( currentEvent.status === 'SCHEDULE' || currentEvent.status === 'ACTIVE' || currentEvent.status === 'VISITED')">{{'complete'| translate}}</a>
-                <a href ng-click="completeIncompleteEvent()" 
-                   class="btn btn-warning"
-                   ng-disabled="currentEvent.enrollmentStatus === 'COMPLETED'"
-                   ng-if="currentEvent.eventDate && currentEvent.status === 'COMPLETED'">{{'incomplete'| translate}}</a>                       
-                <a href ng-click="validateEvent()" 
-                   class="btn btn-info" 
-                   ng-disabled="true || currentEvent.enrollmentStatus === 'COMPLETED'" 
-                   ng-if="currentEvent.eventDate">{{'validate'| translate}}</a>                        
-                <a href ng-click="skipUnskipEvent()" 
-                   class="btn btn-warning" 
-                   ng-disabled="currentEvent.enrollmentStatus === 'COMPLETED'"
-                   ng-if="!currentEvent.eventDate">{{currentEvent.status === 'SKIPPED' ? 'unskip' : 'skip'| translate}}</a>
-                <a href ng-click="deleteEvent()" 
-                   ng-disabled="currentEvent.enrollmentStatus === 'COMPLETED'"
-                   class="btn btn-danger">{{'delete'| translate}}</a>
-            </div>
-        </div>
+        <form name="outerForm" novalidate>
+            <div ng-if="currentEvent && !showEventCreationDiv">
+                <!-- event dates begin -->
+                <div class="row">
+                    <div class="col-md-6">
+                        {{currentEvent.reportDateDescription}}
+                        <input type="text"
+                               placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
+                               class="form-control" 
+                               ng-class="{'input-success': eventDateSaved}"
+                               d2-date 
+                               ng-model="currentEvent.eventDate"
+                               ng-disabled="currentEvent.status === 'SKIPPED' || currentEvent.enrollmentStatus === 'COMPLETED'"    
+                               ng-required="true"
+                               blur-or-change="saveEventDate()"/>
+                        <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>
+                    </div>
+                    <div class="col-md-6">
+                        <span ng-if="currentEvent.eventDate || currentEvent.status === 'SKIPPED'">
+                            {{'due_date'| translate}}
+                        </span>
+                        <span ng-if="!currentEvent.eventDate && currentEvent.status !== 'SKIPPED'">
+                            <a href ng-click="enableRescheduling()" title="{{ schedulingEnabled ? 'disable_rescheduling' : 'enable_rescheduling' | translate}}"><span class="text-primary bold">{{'reschedule_duedate'| translate}}</span></a>                        
+                        </span>                    
+                        <input type="text" 
+                               placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
+                               class="form-control"
+                               ng-class="{'input-success': dueDateSaved}"
+                               d2-date 
+                               ng-model="currentEvent.dueDate"
+                               blur-or-change="saveDueDate()" 
+                               ng-disabled="currentEvent.eventDate || !schedulingEnabled || currentEvent.enrollmentStatus === 'COMPLETED'"/>
+                        <span ng-if="invalidDate" class="error">{{'date_required'| translate}}</span>
+                    </div>                        
+                </div>
+                <!-- event dates end -->
+
+                <!-- coordinates begin -->
+                <div class="row" ng-if="currentStage.captureCoordinates && currentEvent.eventDate">
+                    <div class="col-md-6">
+                        {{'latitude'| translate}}
+                        <input type="number"
+                               ng-model="currentEvent.coordinate.latitude"     
+                               class="form-control" 
+                               ng-class="{'input-success': latitudeSaved}" 
+                               name="latitude"
+                               min="-90"
+                               max="90"
+                               ng-blur="saveCoordinate('LAT')"
+                               ng-required="false"/>
+                        <span ng-show="outerForm.latitude.$invalid" class="required">{{'value_must_be_between'| translate}} [-90 ... 90]</span>
+                    </div>
+                    <div class="col-md-6">
+                        {{'longitude'| translate}}                    
+                        <input type="number"  
+                               ng-model="currentEvent.coordinate.longitude"     
+                               class="form-control" 
+                               ng-class="{'input-success': longitudeSaved}"
+                               name="longitude" 
+                               min="-180"
+                               max="180"
+                               ng-blur="saveCoordinate('LNG')"
+                               ng-required="false"/>
+                        <span ng-show="outerForm.longitude.$invalid" class="required">{{'value_must_be_between'| translate}}[-180 ... 180]</span>
+                    </div>                        
+                </div>
+                <!-- coordinates begin -->
+
+                <div ng-if="currentEvent.eventDate">                            
+                    <div ng-if="customForm">
+                        <a href ng-click="switchDataEntryForm()" title="{{displayCustomForm ? 'default_form' : 'custom_form'| translate}}"><span class="primary pull-right"><i class="fa fa-file-text fa-2x"></i></span></a>                
+                    </div>
+                    <div class="clear vertical-spacing" ng-if="displayCustomForm" ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>  
+                    <div class="clear vertical-spacing" ng-if="!displayCustomForm" ng-include="'components/dataentry/default-form.html'"></div>
+                </div>            
+
+                <div class="form-group">
+                    <div class='row'><hr></div>
+                    <a href ng-click="completeIncompleteEvent()" 
+                       class="btn btn-warning" 
+                       ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE'"
+                       ng-if="currentEvent.eventDate && ( currentEvent.status === 'SCHEDULE' || currentEvent.status === 'ACTIVE' || currentEvent.status === 'VISITED')">{{'complete'| translate}}</a>
+                    <a href ng-click="completeIncompleteEvent()" 
+                       class="btn btn-warning"
+                       ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE'"
+                       ng-if="currentEvent.eventDate && currentEvent.status === 'COMPLETED'">{{'incomplete'| translate}}</a>                       
+                    <a href ng-click="validateEvent()" 
+                       class="btn btn-info" 
+                       ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE'" 
+                       ng-if="currentEvent.eventDate">{{'validate'| translate}}</a>                        
+                    <a href ng-click="skipUnskipEvent()" 
+                       class="btn btn-warning" 
+                       ng-disabled="currentEvent.enrollmentStatus !== 'ACTIVE'"
+                       ng-if="!currentEvent.eventDate">{{currentEvent.status === 'SKIPPED' ? 'unskip' : 'skip'| translate}}</a>
+                    <a href ng-click="deleteEvent()" 
+                       ng-disabled="currentEvent.enrollmentStatus === 'COMPLETED'"
+                       class="btn btn-danger">{{'delete'| translate}}</a>
+                </div>
+            </div>
+        </form>
 
         <div ng-show="currentEvent && !showEventCreationDiv" class='remove-default-padding overflow-ellipsis'>
             <div class='row'><hr></div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties	2015-01-05 11:39:25 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties	2015-01-19 15:36:42 +0000
@@ -265,4 +265,11 @@
 missing_translation_file=Missing Translation File
 missing_translation_using_default=No translation file is found for the selected locale. Using default translation (English).
 loading_tree=Loading orgunit tree
-loading_metadata=Loading meta-data
\ No newline at end of file
+loading_metadata=Loading meta-data
+latitude=Latitude
+longitude=Longitude
+lat_lng=[Latitude Longitude]
+get_from_map=Get from map
+capture=Capture
+point_and_click_for_coordinate=Point and click for coordinate
+value_must_be_between=Value must be between
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-01-17 10:50:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-01-19 15:36:42 +0000
@@ -296,7 +296,6 @@
             return promise;
         },
         update: function( enrollment ){
-            console.log('the enrollment I got is:  ', enrollment);
             var promise = $http.put( '../api/enrollments/' + enrollment.enrollment , enrollment).then(function(response){
                 return response.data;
             });
@@ -547,11 +546,11 @@
             angular.forEach(attributes, function(att){
                 if(att.valueType === 'trueOnly'){
                     if(att.value){
+                        registrationAttributes.push({attribute: att.id, value: 'true'});
+                    }
+                    else{
                         registrationAttributes.push({attribute: att.id, value: ''});
                     }
-                    else{
-                        registrationAttributes.push({attribute: att.id, value: 'true'});
-                    }
                     
                     formEmpty = false;
                 }            
@@ -581,12 +580,12 @@
             var formEmpty = true;
             angular.forEach(attributes, function(att){            
                 if(att.valueType === 'trueOnly'){ 
-                    if(!tei[att.id]){
-                        registrationAttributes.push({attribute: att.id, value: ''});
+                    if(tei[att.id]){
+                        registrationAttributes.push({attribute: att.id, value: 'true'});
                         formEmpty = false;                    
                     }
                     else{
-                        registrationAttributes.push({attribute: att.id, value: 'true'});
+                        registrationAttributes.push({attribute: att.id, value: ''});
                         formEmpty = false;
                     }
                 }            
@@ -1112,7 +1111,7 @@
     };
 })
 
-.service('EventUtils', function(DateUtils, CalendarService, OrgUnitService, $filter, orderByFilter){
+.service('EventUtils', function(DateUtils, CalendarService, OptionSetService, OrgUnitService, $filter, orderByFilter){
     return {
         createDummyEvent: function(events, programStage, orgUnit, enrollment){            
             var today = DateUtils.getToday();    
@@ -1125,6 +1124,11 @@
                               name: programStage.name,
                               reportDateDescription: programStage.reportDateDescription,
                               status: 'SCHEDULED'};
+            
+            if(programStage.captureCoordinates){
+                dummyEvent.coordinate = {};
+            }
+            
             dummyEvent.statusColor = 'alert alert-warning';//'stage-on-time';
             if(moment(today).isAfter(dummyEvent.dueDate)){
                 dummyEvent.statusColor = 'alert alert-danger';//'stage-overdue';
@@ -1208,7 +1212,7 @@
                 }); 
             }
         },
-        reconstruct: function(dhis2Event, programStage){
+        reconstruct: function(dhis2Event, programStage, optionSets){
             
             var e = {dataValues: [], 
                     event: dhis2Event.event, 
@@ -1217,19 +1221,45 @@
                     orgUnit: dhis2Event.orgUnit, 
                     trackedEntityInstance: dhis2Event.trackedEntityInstance,
                     status: dhis2Event.status,
-                    dueDate: dhis2Event.dueDate
+                    dueDate: DateUtils.formatFromUserToApi(dhis2Event.dueDate)
                 };
                 
             angular.forEach(programStage.programStageDataElements, function(prStDe){
-                if(dhis2Event[prStDe.dataElement.id]){
-                    var val = {value: dhis2Event[prStDe.dataElement.id], dataElement: prStDe.dataElement.id};
+                if(dhis2Event[prStDe.dataElement.id]){                    
+                    var value = dhis2Event[prStDe.dataElement.id];
+                    
+                    if( value && prStDe.dataElement.type === 'string' && prStDe.dataElement.optionSet && optionSets[prStDe.dataElement.optionSet.id]){
+                        value = OptionSetService.getCode(optionSets[prStDe.dataElement.optionSet.id].options, value);
+                    }                    
+                    if( value && prStDe.dataElement.type === 'date'){
+                        value = DateUtils.formatFromUserToApi(value);
+                    }
+                    if( prStDe.dataElement.type === 'trueOnly' ){
+                        if(value){
+                            value = 'true';
+                        }
+                        else{
+                            value = '';
+                        }
+                    }
+                    
+                    var val = {value: value, dataElement: prStDe.dataElement.id};
                     if(dhis2Event.providedElsewhere[prStDe.dataElement.id]){
                         val.providedElsewhere = dhis2Event.providedElsewhere[prStDe.dataElement.id];
                     }
                     e.dataValues.push(val);
                 }                                
             });
-                     
+            
+            if(programStage.captureCoordinates){
+                e.coordinate = {latitude: dhis2Event.coordinate.latitude ? dhis2Event.coordinate.latitude : 0,
+                                longitude: dhis2Event.coordinate.longitude ? dhis2Event.coordinate.longitude : 0};
+            }
+            
+            if(dhis2Event.eventDate){
+                e.eventDate = DateUtils.formatFromUserToApi(dhis2Event.eventDate);
+            }
+            
             return e;
         }
     };