← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15967: tracker capture - enrollment and registrtaion during relationship assignment

 

------------------------------------------------------------
revno: 15967
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Fri 2014-07-04 23:04:49 +0200
message:
  tracker capture - enrollment and registrtaion during relationship assignment
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json
  dhis-2/dhis-web/dhis-web-tracker-capture/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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-06-11 15:01:05 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-07-04 21:04:49 +0000
@@ -125,15 +125,17 @@
         {
             org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship = new org.hisp.dhis.dxf2.events.trackedentity.Relationship();
             relationship.setDisplayName( entityRelationship.getRelationshipType().getDisplayName() );
+            relationship.setTrackedEntityInstanceA( entityRelationship.getEntityInstanceA().getUid() );
+            relationship.setTrackedEntityInstanceB( entityRelationship.getEntityInstanceB().getUid() );
 
-            if ( entityInstance.getUid().equals( entityRelationship.getEntityInstanceA().getUid() ) )
+            /*if ( entityInstance.getUid().equals( entityRelationship.getEntityInstanceA().getUid() ) )
             {
                 relationship.setTrackedEntityInstance( entityRelationship.getEntityInstanceB().getUid() );
             }
             else
             {
                 relationship.setTrackedEntityInstance( entityRelationship.getEntityInstanceA().getUid() );
-            }
+            }*/
 
             relationship.setRelationship( entityRelationship.getRelationshipType().getUid() );
 
@@ -387,12 +389,20 @@
                     + relationship.getRelationship() ) );
             }
 
-            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstance() );
-
-            if ( entityInstance == null )
-            {
-                importConflicts.add( new ImportConflict( "Relationship.trackedEntityInstance", "Invalid trackedEntityInstance "
-                    + relationship.getTrackedEntityInstance() ) );
+            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA() );
+
+            if ( entityInstanceA == null )
+            {
+                importConflicts.add( new ImportConflict( "Relationship.trackedEntityInstance", "Invalid trackedEntityInstance "
+                    + relationship.getTrackedEntityInstanceA() ) );
+            }
+            
+            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB() );
+
+            if ( entityInstanceB == null )
+            {
+                importConflicts.add( new ImportConflict( "Relationship.trackedEntityInstance", "Invalid trackedEntityInstance "
+                    + relationship.getTrackedEntityInstanceB() ) );
             }
         }
 
@@ -422,11 +432,13 @@
     {
         for ( org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship : trackedEntityInstance.getRelationships() )
         {
-            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstance() );
+            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA() );
+            org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB() );
+            
             RelationshipType relationshipType = manager.get( RelationshipType.class, relationship.getRelationship() );
 
             Relationship entityRelationship = new Relationship();
-            entityRelationship.setEntityInstanceA( entityInstance );
+            entityRelationship.setEntityInstanceA( entityInstanceA );
             entityRelationship.setEntityInstanceB( entityInstanceB );
             entityRelationship.setRelationshipType( relationshipType );
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java	2014-06-11 12:43:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/Relationship.java	2014-07-04 21:04:49 +0000
@@ -41,7 +41,9 @@
 {
     private String displayName;
 
-    private String trackedEntityInstance;
+    private String trackedEntityInstanceA;
+    
+    private String trackedEntityInstanceB;
 
     private String relationship;
 
@@ -63,14 +65,26 @@
 
     @JsonProperty
     @JacksonXmlProperty( isAttribute = true )
-    public String getTrackedEntityInstance()
-    {
-        return trackedEntityInstance;
-    }
-
-    public void setTrackedEntityInstance( String trackedEntityInstance )
-    {
-        this.trackedEntityInstance = trackedEntityInstance;
+    public String getTrackedEntityInstanceA()
+    {
+        return trackedEntityInstanceA;
+    }
+
+    public void setTrackedEntityInstanceA( String trackedEntityInstanceA )
+    {
+        this.trackedEntityInstanceA = trackedEntityInstanceA;
+    }
+    
+    @JsonProperty
+    @JacksonXmlProperty( isAttribute = true )
+    public String getTrackedEntityInstanceB()
+    {
+        return trackedEntityInstanceB;
+    }
+
+    public void setTrackedEntityInstanceB( String trackedEntityInstanceB )
+    {
+        this.trackedEntityInstanceB = trackedEntityInstanceB;
     }
 
     @JsonProperty
@@ -94,7 +108,9 @@
         Relationship that = (Relationship) o;
 
         if ( displayName != null ? !displayName.equals( that.displayName ) : that.displayName != null ) return false;
-        if ( trackedEntityInstance != null ? !trackedEntityInstance.equals( that.trackedEntityInstance ) : that.trackedEntityInstance != null )
+        if ( trackedEntityInstanceA != null ? !trackedEntityInstanceA.equals( that.trackedEntityInstanceA ) : that.trackedEntityInstanceA != null )
+            return false;
+        if ( trackedEntityInstanceB != null ? !trackedEntityInstanceB.equals( that.trackedEntityInstanceB ) : that.trackedEntityInstanceB != null )
             return false;
         if ( relationship != null ? !relationship.equals( that.relationship ) : that.relationship != null ) return false;
 
@@ -105,7 +121,8 @@
     public int hashCode()
     {
         int result = displayName != null ? displayName.hashCode() : 0;
-        result = 31 * result + (trackedEntityInstance != null ? trackedEntityInstance.hashCode() : 0);
+        result = 31 * result + (trackedEntityInstanceA != null ? trackedEntityInstanceA.hashCode() : 0);
+        result = 31 * result + (trackedEntityInstanceB != null ? trackedEntityInstanceB.hashCode() : 0);
         result = 31 * result + (relationship != null ? relationship.hashCode() : 0);
         return result;
     }
@@ -115,7 +132,8 @@
     {
         return "Relationship{" +
             "displayName='" + displayName + '\'' +
-            ", trackedEntityInstance='" + trackedEntityInstance + '\'' +
+            ", trackedEntityInstanceA='" + trackedEntityInstanceA + '\'' +
+            ", trackedEntityInstanceB='" + trackedEntityInstanceB + '\'' +
             ", relationship='" + relationship + '\'' +
             '}';
     }

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-07-03 11:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-07-04 21:04:49 +0000
@@ -14,7 +14,7 @@
 
     //do translation of the dashboard page
     TranslationService.translate();    
-    
+ 
     //dashboard items   
     $rootScope.biggerDashboardWidgets = [];
     $rootScope.smallerDashboardWidgets = [];//{bigger: [], smaller: []};       
@@ -32,19 +32,50 @@
     $rootScope.smallerDashboardWidgets.push($rootScope.relationshipWidget);
     $rootScope.smallerDashboardWidgets.push($rootScope.notesWidget);
     
-    //selections
-    $scope.selectedTeiId = null;
-    $scope.selectedProgramId = null;
-    
+    //selections  
     $scope.selectedTeiId = ($location.search()).tei; 
     $scope.selectedProgramId = ($location.search()).program; 
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
-    $scope.selectedProgram;
-    $scope.programs = []; 
-    $scope.selectedTei;
-        
-    if( $scope.selectedTeiId ){
-        
+    $scope.selectedProgram;    
+    $scope.selectedTei;    
+    
+    $scope.$on('fromRelationship', function(event, args) { 
+        $scope.selectedTeiId = args.teiId;        
+        
+        if( $scope.selectedTeiId ){        
+            
+            //Fetch the selected entity
+            TEIService.get($scope.selectedTeiId).then(function(data){
+                $scope.selectedTei = data;
+
+                //get the entity type
+                TEService.get($scope.selectedTei.trackedEntity).then(function(te){
+                    $scope.trackedEntity = te;
+
+                    ProgramFactory.getAll().then(function(programs){  
+                        $scope.programs = []; 
+                        //get programs valid for the selected ou and tei
+                        angular.forEach(programs, function(program){
+                            if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) &&
+                               program.trackedEntity.id === $scope.selectedTei.trackedEntity){
+                                $scope.programs.push(program);
+                            }
+
+                            if($scope.selectedProgramId && program.id === $scope.selectedProgramId){
+                                $scope.selectedProgram = program;
+                            }
+                        });
+
+                        //broadcast selected items for dashboard controllers
+                        CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: null});
+                        $scope.broadCastSelections();                                    
+                    });
+                });            
+            });      
+        }
+    });
+    
+    if($scope.selectedTeiId){
         //Fetch the selected entity
         TEIService.get($scope.selectedTeiId).then(function(data){
             $scope.selectedTei = data;
@@ -54,7 +85,8 @@
                 $scope.trackedEntity = te;
                 
                 ProgramFactory.getAll().then(function(programs){  
-            
+                    
+                    $scope.programs = []; 
                     //get programs valid for the selected ou and tei
                     angular.forEach(programs, function(program){
                         if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) &&
@@ -72,7 +104,7 @@
                     $scope.broadCastSelections();                                    
                 });
             });            
-        });       
+        });      
     }
     
     $scope.broadCastSelections = function(){
@@ -85,8 +117,7 @@
         $timeout(function() { 
             $rootScope.$broadcast('selectedItems', {programExists: $scope.programs.length > 0});            
         }, 100); 
-    };
-     
+    };     
     
     $scope.back = function(){
         $location.path('/');
@@ -114,4 +145,8 @@
         modalInstance.result.then(function () {
         });
     };
+    
+    $scope.test = function(){
+        console.log('test');
+    };
 });

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html	2014-07-04 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html	2014-07-04 21:04:49 +0000
@@ -4,19 +4,19 @@
 <div class="modal-body">
     <div class='row'>
         <div class='col-md-12'>
-            <select ng-model="selectedRelationshipType"
+            <select ng-model="relationship.selected"
                     class="form-control"
-                    ng-options="relationshipType as relationshipType.name for relationshipType in relationshipTypes | orderBy: 'name'">
+                    ng-options="rel as rel.name for rel in relationshipTypes | orderBy: 'name'">
                 <option value="">{{'please_select_a_relationship'| translate}}</option>
             </select>
         </div>
     </div>
 
-    <div class="row" ng-show="selectedRelationshipType">
+    <div class="row" ng-show="relationship.selected">
         <hr>
         <div class="row col-md-12">
             <div class="col-md-5">
-                <div class='align-center bold'>{{selectedRelationshipType.aIsToB}}</div>
+                <div class='align-center bold'>{{relationship.selected.aIsToB}}</div>
                 <div class='relationship-container'>
                     <table class="table table-striped table-compact table-borderless">
                         <tr ng-repeat="attribute in selectedTei.attributes">
@@ -31,7 +31,7 @@
                 </div>
             </div>
             <div class="col-md-7">
-                <div class='align-center bold'>{{selectedRelationshipType.bIsToA}}</div>
+                <div class='align-center bold'>{{relationship.selected.bIsToA}}</div>
                 <div class='relationship-container' ng-show="teiForRelationship">
                     <table class="table table-striped table-compact table-borderless">
                         <tr ng-repeat="gridColumn in gridColumns">
@@ -76,7 +76,6 @@
                     </div>
                     <!--- Error display for search ends -->
                     
-                    <pre>source - {{selectedRelationshipSource.value}}</pre>
                     <div ng-show="selectedRelationshipSource.value === 'register_new'">
                         <div ng-include="'components/relationship/registration.html'"></div>
                         <span>&nbsp;</span>
@@ -87,6 +86,6 @@
     </div>
 </div>
 <div class="modal-footer">        
-    <button class="btn btn-primary trim" data-ng-click="add()" >{{'add'| translate}}</button>
+    <button class="btn btn-primary trim" data-ng-click="addRelationship()" ng-disabled='!teiForRelationship'>{{'save_relationship'| translate}}</button>
     <button class="btn btn-default" data-ng-click="close()">{{'close'| translate}}</button>    
 </div> 
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-07-04 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-07-04 21:04:49 +0000
@@ -1,6 +1,8 @@
 trackerCapture.controller('RelationshipController',
         function($scope,
-                $modal,
+                $modal,                
+                $rootScope,
+                $timeout,
                 CurrentSelection,
                 RelationshipFactory,
                 TranslationService) {
@@ -8,9 +10,12 @@
     TranslationService.translate();        
 
     $scope.relationshipTypes = []; 
-    
+    $scope.relationships = [];
     RelationshipFactory.getAll().then(function(rels){
         $scope.relationshipTypes = rels;    
+        angular.forEach(rels, function(rel){
+            $scope.relationships[rel.id] = rel;
+        });
     });    
     
     //listen for the selected entity       
@@ -42,6 +47,12 @@
             $scope.selectedTei.relationships = relationships;
         });
     };    
+    
+    $scope.showDashboard = function(teiId){
+        $timeout(function() { 
+            $rootScope.$broadcast('fromRelationship', {teiId: teiId});
+        }, 100);
+    };
 })
 
 //Controller for adding new relationship
@@ -54,6 +65,7 @@
             ProgramFactory,
             TEIService,
             TEIGridService,
+            DialogService,
             Paginator,
             storage,
             $modalInstance, 
@@ -65,6 +77,7 @@
     $scope.selectedTei = selectedTei;
     $scope.relationshipSources = ['search_from_existing','register_new'];
     $scope.selectedRelationshipSource = {};   
+    $scope.relationship = {};
     
     //Selection
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
@@ -114,11 +127,7 @@
         }
     };
     
-    $scope.ouModes = [{name: 'SELECTED'}, 
-                    {name: 'CHILDREN'}, 
-                    {name: 'DESCENDANTS'},
-                    {name: 'ACCESSIBLE'}
-                  ];         
+    $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
     $scope.selectedOuMode = $scope.ouModes[0];
     
     //Paging
@@ -295,8 +304,34 @@
         $scope.teiForRelationship = selectedTei;
     };
     
-    $scope.add = function(){       
-        console.log('I will add new relationship');     
+    $scope.addRelationship = function(){
+        if($scope.selectedTei && $scope.teiForRelationship && $scope.relationship.selected){
+
+            var relationship = {relationship: $scope.relationship.selected.id, 
+                                displayName: $scope.relationship.selected.name, 
+                                trackedEntityInstanceA: $scope.selectedTei.trackedEntityInstance, 
+                                trackedEntityInstanceB: $scope.teiForRelationship.id};
+            
+            if($scope.selectedTei.relationships){
+                $scope.selectedTei.relationships.push(relationship);
+            }
+            else{
+                $scope.selectedTei.relationships = [relationship];
+            }
+            
+            TEIService.update($scope.selectedTei).then(function(response){
+                if(response.status !== 'SUCCESS'){//update has failed
+                    var dialogOptions = {
+                            headerText: 'update_error',
+                            bodyText: response.description
+                        };
+                    DialogService.showDialog({}, dialogOptions);
+                    return;
+                }
+                
+                $modalInstance.close($scope.selectedTei.relationships);                
+            });
+        }        
     };
 })
 
@@ -442,7 +477,7 @@
                 $scope.enrollment.incidentDate =  '';
                 $scope.outerForm.submitted = false; 
                 
-                $scope.tei.trackedEntityInstance = teiId;
+                $scope.tei.id = teiId;
                 $scope.broadCastSelections();
                 
             }, 100);        

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html	2014-07-03 11:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html	2014-07-04 21:04:49 +0000
@@ -15,12 +15,16 @@
     <div ng-show="relationshipWidget.expand" class="panel-body dashboard-element-container">
         <div ng-show="selectedTei && !selectedTei.relationships" class="alert alert-info">{{'no_relationship'| translate}}</div> 
         <div ng-show="!selectedTei" class="alert alert-info">{{'relationship_not_possible'| translate}}</div> 
-        <div ng-show="showAddRelationshipDiv">
-            <select ng-model="selectedRelationshipType"
-                    class="form-control"
-                    ng-options="relationshipType as relationshipType.name for relationshipType in relationshipTypes | orderBy: 'name'">
-                <option value="">{{'please_select_a_relationship'| translate}}</option>
-            </select>
+        
+        <div ng-show="selectedTei" class="remove-default-padding">
+            <table class="table table-striped dhis2-table-hover">
+                <tr ng-repeat="rel in selectedTei.relationships">
+                    <td>
+                        <span ng-click="showDashboard(rel.trackedEntityInstanceB)" ng-if="selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA">{{relationships[rel.relationship].bIsToA}}</span>
+                        <span ng-click="showDashboard(rel.trackedEntityInstanceA)" ng-if="selectedTei.trackedEntityInstance === rel.trackedEntityInstanceB">{{relationships[rel.relationship].aIsToB}}</span>
+                    </td> 
+                </tr>
+            </table>
         </div>
     </div>
 </div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-07-04 10:10:13 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-07-04 21:04:49 +0000
@@ -143,6 +143,7 @@
     "save_and_add_new": "Save and add new",
     "save_and_go_back": "Save and go back",
     "save_and_continue": "Save and continue",
+    "save_relationship": "Save relationship",
     "go_back": "Go back",
     "cancel": "Cancel",
     "more": "More",    

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-07-04 14:36:11 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-07-04 21:04:49 +0000
@@ -340,6 +340,8 @@
             
             var url = '../api/trackedEntityInstances';
             
+            console.log('the tei is:  ', tei);
+            
             var promise = $http.put( url + '/' + tei.trackedEntityInstance , tei).then(function(response){
                 return response.data;
             });