← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20345: tracker-capture: registering tracker associate - WIP

 

------------------------------------------------------------
revno: 20345
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-24 14:19:33 +0200
message:
  tracker-capture: registering tracker associate - WIP
removed:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/search.html
added:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/registration.html
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add.html
  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/views/advanced-search.html


--
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/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-09-23 15:04:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-09-24 12:19:33 +0000
@@ -96,13 +96,6 @@
             $scope.selectedEnrollment = args.enrollment;
         }
         
-        if($scope.registrationMode === 'RELATIONSHIP'){
-            $scope.mainTei = args.mainTei;
-            $scope.selectedTei = {};
-            $scope.tei = {};
-            $scope.selectedProgram = args.relativeProgram;
-        }
-        
         $scope.getAttributes($scope.registrationMode);
     });
         
@@ -120,14 +113,6 @@
                 $scope.trackedEntityForm.displayIncidentDate = $scope.selectedProgram.displayIncidentDate;
                 $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, mode);
             }
-            
-            if(mode === 'RELATIONSHIP'){
-                angular.forEach($scope.attributes, function(att){
-                    if(att.inherit && $scope.mainTei[att.id]){
-                        $scope.selectedTei[att.id] = $scope.mainTei[att.id];
-                    }
-                });
-            }
         });
     }; 
     
@@ -140,23 +125,7 @@
         if(destination === 'DASHBOARD') {
             $location.path('/dashboard').search({tei: teiId,                                            
                                     program: $scope.selectedProgram ? $scope.selectedProgram.id: null});
-        }            
-        else if(destination === 'RELATIONSHIP' ){
-            if($scope.tei){
-                angular.forEach($scope.tei.attributes, function(att){
-                    $scope.tei[att.attribute] = att.value;
-                });
-
-                $scope.tei.orgUnitName = $scope.selectedOrgUnit.name;
-                $scope.tei.created = DateUtils.formatFromApiToUser(new Date());
-
-                CurrentSelection.setRelationshipInfo({tei: $scope.tei});
-
-                $timeout(function() { 
-                    $rootScope.$broadcast('relationship', {result: 'SUCCESS'});
-                }, 200);
-            }
-        }
+        }        
     };
     
     var reloadProfileWidget = function(){
@@ -262,13 +231,7 @@
             return false;
         }        
         performRegistration(destination);
-    };
-    
-    $scope.cancelRelativeRegistration = function(){
-        $timeout(function() { 
-            $rootScope.$broadcast('relationship', {result: 'CANCEL'});
-        }, 200);
-    };   
+    }; 
    
     
     var processRuleEffect = function(){        

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2015-09-21 15:01:55 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2015-09-24 12:19:33 +0000
@@ -63,11 +63,6 @@
                 <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="showRegistration()">{{'cancel'| translate}}</button>
             </div>
 
-            <div ng-if="registrationMode === 'RELATIONSHIP'" class="vertical-spacing">
-                <button type="button" class="btn btn-primary small-horizonal-spacing" ng-click="registerEntity('RELATIONSHIP')">{{'save'| translate}}</button>        
-                <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="cancelRelativeRegistration()">{{'cancel'| translate}}</button>
-            </div>
-
         </form>
         <!--registration form ends -->
     </div>

=== added file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/registration.html	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/registration.html	2015-09-24 12:19:33 +0000
@@ -0,0 +1,60 @@
+<div ng-controller="TEIRegistrationController">    
+    
+    <!--registration form starts -->
+    <form name="outerForm" novalidate>
+
+        <!-- Entity type begins -->
+        <div ng-if="!selectedProgram">
+            <h3>{{'category'| translate}}</h3>
+            <table class="dhis2-list-table-striped dhis2-table-hover">
+                <tr>
+                    <td>
+                        {{'entity_type'| translate}}
+                    </td>
+                    <td>
+                        <select class="form-control" ng-model="trackedEntities.selected" ng-options="trackedEntity.name for trackedEntity in trackedEntities.available | orderBy: 'name'">                                
+                        </select>                            
+                    </td>
+                </tr>                   
+            </table>
+            <hr>
+        </div>
+        <!-- Entity type ends -->        
+
+        <!--custom registration form begins -->
+        <div class="vertical-spacing" ng-if="customFormExists">
+
+            <!-- enrollment and incidence dates begin -->
+            <div ng-if="selectedProgram && !customForm.hasProgramDate">
+                <div ng-include="'components/registration/enrollment-dates-form.html'"></div>
+            </div>
+            <!-- enrollment and incidence dates end -->
+
+            <div ng-include="'../dhis-web-commons/angular-forms/custom-form.html'"></div>
+
+        </div>
+        <!-- custom registration form ends-->
+
+        <!-- default registration form begins -->
+        <div class="vertical-spacing" ng-if="!customFormExists">            
+            <div ng-if="selectedProgram" ng-include="'components/registration/enrollment-dates-form.html'"></div>
+            <div ng-include="'components/registration/default-registration-form.html'"></div>
+        </div>
+        <!-- default registration form ends -->
+
+        <div ng-if="formEmpty && outerForm.submitted">
+            <div class="alert alert-warning">{{'form_is_empty_fill_at_least_one'| translate}}</div> 
+        </div>
+
+        <button type="button" class="btn btn-primary small-horizonal-spacing" ng-click="registerEntity()">{{'save'| translate}}</button>        
+        <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="showRegistration()">{{'cancel'| translate}}</button>
+
+    </form>
+    <!--registration form ends -->
+  
+
+    <div ng-if="warningMessages.length > 0">
+        <div ng-include="'views/warnings.html'"></div>
+    </div>
+        
+  </div>
\ No newline at end of file

=== removed file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/search.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/search.html	2015-09-23 14:06:13 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/search.html	1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
-<div class="advanced-search-container-main">
-    <div class="advanced-search-container">    
-        <table data-stop-propagation="true" class="table-borderless table-striped">
-            <tr>
-                <td>{{orgUnitLabel}}</td>
-                <td>                    
-                    <label><input type="radio" ng-model="selectedOuMode.name" name="selected" value="SELECTED"> {{'SELECTED'| translate}}</label><br/>
-                    <label><input type="radio" ng-model="selectedOuMode.name" name="children" value="CHILDREN"> {{'CHILDREN'| translate}}</label><br/>
-                    <label><input type="radio" ng-model="selectedOuMode.name" name="descendants" value="DESCENDANTS"> {{'DESCENDANTS'| translate}}</label><br/>
-                    <label><input type="radio" ng-model="selectedOuMode.name" name="accessible" value="ACCESSIBLE"> {{'ACCESSIBLE'| translate}}</label>
-                </td>
-            </tr>            
-            <tr ng-if="selectedProgramForRelative">
-                <td>{{'enrollment_date'| translate}}</td>
-                <td>
-                    <div class="dataelement-filter">
-                        <div class="filter-operator">
-                            <select ng-model="enrollment.operator" class="form-control-select2" ng-options="operator | translate for operator in defaultOperators">
-                            </select>
-                        </div>
-                        <div class="filter-value" ng-show="enrollment.operator === defaultOperators[0]">
-                            <input type="text" placeholder="{{'exact_date'| translate}}" class="form-control-select2" d2-date ng-model="enrollment.programExactDate"/>
-                        </div>
-                        <div class="filter-value" ng-show="enrollment.operator === defaultOperators[1]">
-                            <div class="container-1-2">
-                                <input type="text" placeholder="{{'start_date'| translate}}" class="form-control-select2" d2-date ng-model="enrollment.programStartDate"/>
-                            </div>
-                            <div class="container-1-2">
-                                <input type="text" placeholder="{{'end_date'| translate}}" class="form-control-select2" d2-date ng-model="enrollment.programEndDate"/>                
-                            </div>
-                        </div>                    
-                    </div>                
-                </td>
-            </tr>
-            <tr ng-repeat="attribute in attributes">
-                <td>
-                    {{attribute.name}}
-                </td>
-                <td>
-                    <div ng-if="attribute.optionSetValue">
-                        <select multiple ui-select2  ng-model="attribute.value" data-placeholder="{{'please_select'| translate}}" style="width:100%;">
-                            <option ng-repeat="option in attribute.optionSet.options" value="{{option.code}}">{{option.name}}</option>
-                        </select>
-                    </div>
-                    <div ng-if="!attribute.optionSetValue" ng-switch="attribute.valueType">
-                        <div ng-switch-when="NUMBER">
-                            <div class="dataelement-filter">                                                
-                                <div class="filter-operator">
-                                    <select ng-model="attribute.operator" class="form-control-select2" ng-options="operator | translate for operator in defaultOperators">
-                                    </select>
-                                </div>
-                                <div class="filter-value" ng-show="attribute.operator === defaultOperators[0]">
-                                    <input type="number" placeholder="{{'exact_value'| translate}}" class="form-control-select2" ng-model="attribute.exactValue"/>
-                                </div>
-                                <div class="filter-value" ng-show="attribute.operator === defaultOperators[1]">
-                                    <div class="container-1-2">
-                                        <input type="number" placeholder="{{'from'| translate}}" class="form-control-select2" ng-model="attribute.startValue"/>
-                                    </div>
-                                    <div class="container-1-2">
-                                        <input type="number" placeholder="{{'to'| translate}}" class="form-control-select2" ng-model="attribute.endValue"/>                
-                                    </div>
-                                </div>                            
-                            </div>                        
-                        </div>
-                        <div ng-switch-when="DATE">
-                            <div class="dataelement-filter">
-                                <div class="filter-operator">
-                                    <select ng-model="attribute.operator" class="form-control-select2" ng-options="operator | translate for operator in defaultOperators">
-                                    </select>
-                                </div>
-                                <div class="filter-value" ng-show="attribute.operator === defaultOperators[0]">
-                                    <input type="text" placeholder="{{'exact_date'| translate}}" class="form-control-select2" d2-date ng-model="attribute.exactValue"/>
-                                </div>
-                                <div class="filter-value" ng-show="attribute.operator === defaultOperators[1]">
-                                    <div class="container-1-2">
-                                        <input type="text" placeholder="{{'start_date'| translate}}" class="form-control-select2" d2-date ng-model="attribute.startValue"/>
-                                    </div>
-                                    <div class="container-1-2">
-                                        <input type="text" placeholder="{{'end_date'| translate}}" class="form-control-select2" d2-date ng-model="attribute.endValue"/>                
-                                    </div>
-                                </div>                            
-                            </div> 
-                        </div>                        
-                        <div ng-switch-when="BOOLEAN">
-                            <select multiple ui-select2  ng-model="attribute.value" data-placeholder="{{'please_select'| translate}}" style="width:100%;">
-                                <option ng-repeat="option in boolOperators" value="{{option}}">{{option| translate}}</option>
-                            </select>
-                        </div> 
-                        <div ng-switch-default>
-                            <input type="text" class="form-control-select2" ng-model="attribute.value" /> 
-                        </div>
-                    </div>
-                </td>
-            </tr>         
-        </table>
-    </div>
-
-    <div class="horizonal-spacing">
-        <button type="button"
-                class="btn btn-primary"
-                ng-click="search(searchMode.attributeBased)">
-            {{'search'| translate}}
-        </button>
-        <button type="button" 
-                class="btn btn-success small-horizonal-spacing" 
-                ng-click="search(searchMode.listAll)">
-            {{'list_all'| translate}}
-        </button>
-        <button type="button" 
-                class="btn btn-default small-horizonal-spacing" 
-                ng-click="showHideSearch()">
-            {{'cancel'| translate}}
-        </button>
-    </div>
-</div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js	2015-09-23 15:27:14 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js	2015-09-24 12:19:33 +0000
@@ -4,7 +4,7 @@
     function($scope, 
             $rootScope,
             $translate,
-            $timeout,
+            $modalInstance, 
             DateUtils,
             CurrentSelection,
             OperatorFactory,
@@ -12,12 +12,12 @@
             EntityQueryFactory,
             OrgUnitFactory,
             ProgramFactory,
+            MetaDataFactory,
             TEIService,
             TEIGridService,
             DialogService,
             Paginator,
             SessionStorageService,
-            $modalInstance, 
             relationshipTypes,
             selectedProgram,
             relatedProgramRelationship,
@@ -26,6 +26,31 @@
             addingRelationship,
             selectedTei){
     
+    $scope.attributesById = CurrentSelection.getAttributesById();
+    if(!$scope.attributesById){
+        $scope.attributesById = [];
+        AttributesFactory.getAll().then(function(atts){
+            angular.forEach(atts, function(att){
+                $scope.attributesById[att.id] = att;
+            });
+            
+            CurrentSelection.setAttributesById($scope.attributesById);
+        });
+    }    
+    
+    $scope.optionSets = CurrentSelection.getOptionSets();        
+    if(!$scope.optionSets){
+        $scope.optionSets = [];
+        MetaDataFactory.getAll('optionSets').then(function(optionSets){
+            angular.forEach(optionSets, function(optionSet){                        
+                $scope.optionSets[optionSet.id] = optionSet;
+            });
+
+            CurrentSelection.setOptionSets($scope.optionSets);
+        });
+    }
+    
+    $scope.today = DateUtils.getToday();
     $scope.relationshipTypes = relationshipTypes;
     $scope.addingRelationship = addingRelationship;
     $scope.selectedAttribute = selectedAttribute;
@@ -48,10 +73,12 @@
             invalidTeis.push(rel.trackedEntityInstanceB);
         });
     }    
+    
+    $scope.selectedOrgUnit = SessionStorageService.get('SELECTED_OU');
+    $scope.selectedEnrollment = {enrollmentDate: $scope.today, incidentDate: $scope.today, orgUnitName: $scope.selectedOrgUnit.name};
 
     //Selections
     $scope.selectedOrgUnit = SessionStorageService.get('SELECTED_OU');
-    $scope.optionSets = selections.optionSets;
     $scope.selectedTeiForDisplay = angular.copy($scope.selectedTei);
     $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
     $scope.selectedOuMode = $scope.ouModes[0];
@@ -314,37 +341,19 @@
     };   
     
     $scope.showHideSearch = function(simpleSearch){
-        if(simpleSearch){
-            $scope.showAdvancedSearchDiv = false;
-        }
-        else{
-            $scope.showAdvancedSearchDiv = !$scope.showAdvancedSearchDiv;
-        }
-        
-        if($scope.showAdvancedSearchDiv){
-            $scope.showTrackedEntityDiv = false;
-        }
-        else{
-            $scope.showTrackedEntityDiv = true;
-        }
+        $scope.showAdvancedSearchDiv = simpleSearch ? false : !$scope.showAdvancedSearchDiv;
+        $scope.showTrackedEntityDiv = !$scope.showAdvancedSearchDiv;        
     };
     
     $scope.showRegistration = function(){
-        $scope.showRegistrationDiv = !$scope.showRegistrationDiv;
-        
-        if($scope.showRegistrationDiv){
-            $scope.showTrackedEntityDiv = false;
-            $timeout(function() {
-                var mainTei = angular.copy($scope.selectedTei); 
-                angular.forEach(mainTei.attributes, function(att){
-                    mainTei[att.attribute] = att.value;
-                });
-                $rootScope.$broadcast('registrationWidget', {registrationMode: 'RELATIONSHIP', mainTei: mainTei, relativeProgram: $scope.selectedProgramForRelative});
-            }, 200);
+        $scope.showRegistrationDiv = !$scope.showRegistrationDiv;        
+        $scope.showTrackedEntityDiv = !$scope.showRegistrationDiv;
+        if($scope.addingRelationship){
+            CurrentSelection.setRelationshipOwner($scope.selectedTei);
         }
         else{
-            $scope.showTrackedEntityDiv = true;            
-        }        
+            CurrentSelection.setRelationshipOwner({});
+        }
     };
     
     $scope.close = function () {
@@ -380,8 +389,7 @@
                 relationship.relationship = $scope.relationship.selected.id;
                 relationship.displayName = $scope.relationship.selected.name;
                 relationship.relative = {};
-
-
+                
                 relationship.trackedEntityInstanceA = $scope.selectedRelationship.aIsToB === $scope.relationship.selected.aIsToB ? $scope.selectedTei.trackedEntityInstance : $scope.teiForRelationship.id;
                 relationship.trackedEntityInstanceB = $scope.selectedRelationship.bIsToA === $scope.relationship.selected.bIsToA ? $scope.teiForRelationship.id : $scope.selectedTei.trackedEntityInstance;
 
@@ -472,4 +480,225 @@
     $scope.setSelectedSearchingOrgUnit = function(orgUnit){    
         $scope.selectedSearchingOrgUnit = orgUnit;
     };
+})
+
+.controller('TEIRegistrationController', 
+        function($rootScope,
+                $scope,
+                $timeout,
+                AttributesFactory,
+                MetaDataFactory,
+                TrackerRulesFactory,
+                CustomFormService,
+                TEService,
+                TEIService,
+                EnrollmentService,
+                DialogService,
+                CurrentSelection,
+                OptionSetService,
+                DateUtils,
+                SessionStorageService) {
+    $scope.selectedOrgUnit = SessionStorageService.get('SELECTED_OU');
+    $scope.enrollment = {enrollmentDate: '', incidentDate: ''};    
+    $scope.attributesById = CurrentSelection.getAttributesById();
+    
+    var selections = CurrentSelection.get();
+    $scope.programs = selections.prs;    
+    
+    $scope.attributesById = CurrentSelection.getAttributesById();
+    if(!$scope.attributesById){
+        $scope.attributesById = [];
+        AttributesFactory.getAll().then(function(atts){
+            angular.forEach(atts, function(att){
+                $scope.attributesById[att.id] = att;
+            });
+            
+            CurrentSelection.setAttributesById($scope.attributesById);
+        });
+    }    
+    
+    $scope.optionSets = CurrentSelection.getOptionSets();        
+    if(!$scope.optionSets){
+        $scope.optionSets = [];
+        MetaDataFactory.getAll('optionSets').then(function(optionSets){
+            angular.forEach(optionSets, function(optionSet){                        
+                $scope.optionSets[optionSet.id] = optionSet;
+            });
+
+            CurrentSelection.setOptionSets($scope.optionSets);
+            
+            console.log('the option sets:  ', $scope.optionSets);
+        });
+    }
+  
+    if(angular.isObject($scope.programs) && $scope.programs.length === 1){
+        $scope.selectedProgramForRelative = $scope.programs[0];
+        AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
+            $scope.attributes = atts;
+        });
+    }  
+    
+    //watch for selection of program
+    $scope.$watch('selectedProgramForRelative', function() {        
+        $scope.trackedEntityForm = null;
+        $scope.customForm = null;
+        $scope.customFormExists = false;
+        
+        if(angular.isObject($scope.selectedProgramForRelative)){
+            AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
+                $scope.attributes = atts;                        
+                if($scope.selectedProgramForRelative && $scope.selectedProgramForRelative.id && $scope.selectedProgramForRelative.dataEntryForm && $scope.selectedProgramForRelative.dataEntryForm.htmlCode){
+                    $scope.customFormExists = true;
+                    $scope.trackedEntityForm = $scope.selectedProgramForRelative.dataEntryForm;  
+                    $scope.trackedEntityForm.attributes = $scope.attributes;
+                    $scope.trackedEntityForm.selectIncidentDatesInFuture = $scope.selectedProgramForRelative.selectIncidentDatesInFuture;
+                    $scope.trackedEntityForm.selectEnrollmentDatesInFuture = $scope.selectedProgramForRelative.selectEnrollmentDatesInFuture;
+                    $scope.trackedEntityForm.displayIncidentDate = $scope.selectedProgramForRelative.displayIncidentDate;
+                    $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'RELATIONSHIP');
+                }
+
+                if($scope.addingRelationship){
+                    var mainTei = CurrentSelection.getRelationshipOwner();
+                    angular.forEach($scope.attributes, function(att){
+                        if(att.inherit && mainTei[att.id]){
+                            $scope.selectedTei[att.id] = mainTei[att.id];
+                        }
+                    });
+                }
+
+                $scope.allProgramRules = {constants: [], programIndicators: {}, programValidations: [], programVariables: [], programRules: []};
+                if( angular.isObject($scope.selectedProgramForRelative) && $scope.selectedProgramForRelative.id ){
+                    TrackerRulesFactory.getRules($scope.selectedProgramForRelative.id).then(function(rules){                    
+                        $scope.allProgramRules = rules;
+                    });
+                }
+            });
+        }
+    }); 
+            
+    $scope.trackedEntities = {available: []};
+    TEService.getAll().then(function(entities){
+        $scope.trackedEntities.available = entities;   
+        $scope.trackedEntities.selected = $scope.trackedEntities.available[0];
+    });
+    
+    $scope.registerEntity = function(){
+        
+        //check for form validity
+        $scope.outerForm.submitted = true;        
+        if( $scope.outerForm.$invalid ){
+            return false;
+        }
+        
+        //form is valid, continue the registration
+        //get selected entity
+        var selectedTrackedEntity = $scope.trackedEntities.selected.id; 
+        if($scope.selectedProgramForRelative){
+            selectedTrackedEntity = $scope.selectedProgramForRelative.trackedEntity.id;
+        }
+        
+        //get tei attributes and their values
+        //but there could be a case where attributes are non-mandatory and
+        //registration form comes empty, in this case enforce at least one value
+        $scope.valueExists = false;
+        var registrationAttributes = [];    
+        angular.forEach($scope.attributes, function(attribute){
+            var val = attribute.value;
+            if(!angular.isUndefined(val)){                
+                if(attribute.valueType === 'date'){
+                    val = DateUtils.formatFromUserToApi(val);
+                }
+                if(attribute.optionSetValue &&
+                        attribute.optionSet &&
+                        attribute.optionSet.id &&                
+                        $scope.optionSets[attribute.optionSet.id] &&
+                        $scope.optionSets[attribute.optionSet.id].options ){  
+                    
+                    val = OptionSetService.getCode($scope.optionSets[attribute.optionSet.id].options, val);
+                }
+                registrationAttributes.push({attribute: attribute.id, value: val});
+                $scope.valueExists = true;
+            } 
+        });       
+        
+        if(!$scope.valueExists){
+            //registration form is empty
+            return false;
+        }
+        
+        //prepare tei model and do registration
+        $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: registrationAttributes };   
+        var teiId = '';
+
+        TEIService.register($scope.tei, $scope.optionSets, $scope.attributesById).then(function(registrationResponse){            
+            var reg = registrationResponse.response && registrationResponse.response.importSummaries && registrationResponse.response.importSummaries[0] ? registrationResponse.response.importSummaries[0] : {};
+            if(reg.reference && reg.status === 'SUCCESS'){                
+                teiId = reg.reference;                
+                //registration is successful and check for enrollment
+                if($scope.selectedProgramForRelative){    
+                    //enroll TEI
+                    var enrollment = {trackedEntityInstance: teiId,
+                                program: $scope.selectedProgramForRelative.id,
+                                status: 'ACTIVE',
+                                dateOfEnrollment: DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate),
+                                dateOfIncident: $scope.enrollment.incidentDate === '' ? DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate) : DateUtils.formatFromUserToApi($scope.enrollment.incidentDate)
+                            };
+                    EnrollmentService.enroll(enrollment).then(function(enrollmentResponse){
+                        var en = enrollmentResponse.response && enrollmentResponse.response.importSummaries && enrollmentResponse.response.importSummaries[0] ? enrollmentResponse.response.importSummaries[0] : {};
+                        if(en.reference && en.status === 'SUCCESS'){
+                            //enrollment has failed
+                            var dialogOptions = {
+                                    headerText: 'enrollment_error',
+                                    bodyText: enrollmentResponse.message
+                                };
+                            DialogService.showDialog({}, dialogOptions);
+                            return;
+                        }
+                    });
+                }
+            }
+            else{
+                //registration has failed
+                var dialogOptions = {
+                        headerText: 'registration_error',
+                        bodyText: registrationResponse.message
+                    };
+                DialogService.showDialog({}, dialogOptions);
+                return;
+            }
+            
+            $timeout(function() { 
+                //reset form
+                angular.forEach($scope.attributes, function(attribute){
+                    delete attribute.value;                
+                });            
+
+                $scope.enrollment.enrollmentDate = '';
+                $scope.enrollment.incidentDate =  '';
+                $scope.outerForm.submitted = false; 
+                
+                $scope.tei.id = teiId;
+                $scope.broadCastSelections();
+                
+            }, 100);        
+            
+        });
+    };
+    
+    $scope.broadCastSelections = function(){
+        if($scope.tei){
+            angular.forEach($scope.tei.attributes, function(att){
+                $scope.tei[att.attribute] = att.value;
+            });
+
+            $scope.tei.orgUnitName = $scope.selectedOrgUnit.name;
+            $scope.tei.created = DateUtils.formatFromApiToUser(new Date());
+            
+            CurrentSelection.setRelationshipInfo({tei: $scope.tei});
+            
+            $timeout(function() { 
+                $rootScope.$broadcast('relationship', {});
+            }, 100);
+        }        
+    };
 });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add.html	2015-09-23 15:04:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add.html	2015-09-24 12:19:33 +0000
@@ -84,6 +84,7 @@
                             <button class="btn btn-primary without-border-radius trim" type="button" title="{{'search'| translate}}" ng-click="search(searchMode.freeText)"><i class="fa fa-search"></i></button>                            
                             <button class="btn btn-default without-border-radius trim" type="button" title="{{'list_all'| translate}}" ng-disabled="showRegistrationDiv" ng-click="search(searchMode.listAll)"><i class="fa fa-list"></i></button>
                             <button class="btn btn-success trim" type="button" title="{{'register'| translate}}" ng-click="showRegistration()"><i class="fa fa-plus-square"></i></button>                            
+                            
                         </div>                
                     </div>                    
                 </div>
@@ -107,8 +108,7 @@
                 <!--- Error display for search ends -->
                 
                 <div ng-show="showRegistrationDiv">
-                    <!--<div ng-include="'components/relationship/registration.html'"></div>-->
-                    <div ng-include="'components/registration/registration.html'"></div>
+                    <div ng-include="'components/teiadd/registration.html'"></div>
                     <span>&nbsp;</span>
                 </div>
             </div>

=== 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-09-21 15:01:55 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-09-24 12:19:33 +0000
@@ -1351,6 +1351,7 @@
     this.ouLevels = null;
     this.sortedTeiIds = [];
     this.selectedTeiEvents = null;
+    this.relationshipOwner = {};
     
     this.set = function(currentSelection){  
         this.currentSelection = currentSelection;        
@@ -1400,6 +1401,13 @@
     this.getSelectedTeiEvents = function(){
         return this.selectedTeiEvents;
     };
+    
+    this.setRelationshipOwner = function(relationshipOwner){
+        this.relationshipOwner = relationshipOwner;
+    };
+    this.getRelationshipOwner = function(){
+        return this.relationshipOwner;
+    };
 })
 
 .service('TEIGridService', function(OrgUnitService, OptionSetService, CurrentSelection, DateUtils, $translate){

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/advanced-search.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/advanced-search.html	2015-09-15 13:51:19 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/views/advanced-search.html	2015-09-24 12:19:33 +0000
@@ -41,6 +41,7 @@
                 </td>
                 <td>
                     <div ng-if="attribute.optionSetValue">
+                        The length...{{opionSets.length}}
                         <select multiple ui-select2  ng-model="attribute.value" data-placeholder="{{'please_select'| translate}}" style="width:100%;">
                             <option ng-repeat="option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:100" value="{{option.code}}">{{option.name}}</option>
                         </select>