← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10754: Add a function to assign an program for orgunit groups

 

------------------------------------------------------------
revno: 10754
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-03 14:36:17 +0700
message:
  Add a function to assign an program for orgunit groups
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/DefineProgramAssociationsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/GetProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programAssociations.vm


--
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-api/src/main/java/org/hisp/dhis/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-04-18 06:45:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-05-03 07:36:17 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
 import org.hisp.dhis.patient.PatientIdentifierType;
@@ -121,9 +122,14 @@
     private Boolean remindCompleted = false;
 
     private Set<PatientReminder> patientReminders = new HashSet<PatientReminder>();
-    
+
     private Boolean disableRegistrationFields = false;
-    
+
+    /**
+     * All OrganisationUnitGroup that register data with this program.
+     */
+    private Set<OrganisationUnitGroup> organisationUnitGroups = new HashSet<OrganisationUnitGroup>();
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -515,4 +521,13 @@
         this.disableRegistrationFields = disableRegistrationFields;
     }
 
+    public Set<OrganisationUnitGroup> getOrganisationUnitGroups()
+    {
+        return organisationUnitGroups;
+    }
+
+    public void setOrganisationUnitGroups( Set<OrganisationUnitGroup> organisationUnitGroups )
+    {
+        this.organisationUnitGroups = organisationUnitGroups;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2013-03-14 09:06:32 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2013-05-03 07:36:17 +0000
@@ -29,6 +29,7 @@
 
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -104,6 +105,14 @@
 
         for ( Program program : getAllPrograms() )
         {
+            Set<OrganisationUnitGroup> orgunitGroups = program.getOrganisationUnitGroups();
+            for( OrganisationUnitGroup orgunitGroup : orgunitGroups )
+            {
+                if( orgunitGroup.getMembers().contains( organisationUnit ))
+                {
+                    programs.add( program );
+                }
+            }
             if ( program.getOrganisationUnits().contains( organisationUnit ) )
             {
                 programs.add( program );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-04-19 03:50:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml	2013-05-03 07:36:17 +0000
@@ -83,6 +83,11 @@
     
     <property name="disableRegistrationFields" />
     
+    <set name="organisationUnitGroups" table="orgunitgroupprograms">
+	  <key column="programid" />
+	  <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="orgunitgroupid"/>
+	</set>
+	
 	<!-- Access properties -->
 	
     <many-to-one name="user" class="org.hisp.dhis.user.User" column="userid" foreign-key="fk_program_userid" />

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-05-02 03:31:45 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-05-03 07:36:17 +0000
@@ -639,4 +639,5 @@
 filter_on_section = Filter on section
 dataelementname = Data element
 categoryoptioncomboname = Category option combo
-organisationunitname = Organisation unit
\ No newline at end of file
+organisationunitname = Organisation unit
+orgunit_group = Organisation unit group
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/DefineProgramAssociationsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/DefineProgramAssociationsAction.java	2012-01-11 05:31:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/DefineProgramAssociationsAction.java	2013-05-03 07:36:17 +0000
@@ -32,6 +32,8 @@
 import java.util.Set;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
@@ -51,6 +53,13 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
     private SelectionTreeManager selectionTreeManager;
 
     public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
@@ -76,6 +85,13 @@
         this.id = id;
     }
 
+    private Collection<Integer> orgunitGroupIds = new HashSet<Integer>();
+
+    public void setOrgunitGroupIds( Collection<Integer> orgunitGroupIds )
+    {
+        this.orgunitGroupIds = orgunitGroupIds;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -83,7 +99,6 @@
     public String execute()
         throws Exception
     {
-
         Collection<OrganisationUnit> rootUnits = selectionTreeManager.getRootOrganisationUnits();
 
         Set<OrganisationUnit> unitsInTheTree = new HashSet<OrganisationUnit>();
@@ -96,12 +111,23 @@
 
         assignedUnits.removeAll( convert( unitsInTheTree ) );
 
-        Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager.getReloadedSelectedOrganisationUnits();
+        Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager
+            .getReloadedSelectedOrganisationUnits();
 
         assignedUnits.addAll( convert( selectedOrganisationUnits ) );
 
         program.setOrganisationUnits( assignedUnits );
-
+        
+        if ( orgunitGroupIds != null )
+        {
+            Set<OrganisationUnitGroup> orgunitGroups = new HashSet<OrganisationUnitGroup>();
+            for ( Integer orgunitGroupId : orgunitGroupIds )
+            {
+                orgunitGroups.add( organisationUnitGroupService.getOrganisationUnitGroup( orgunitGroupId ) );
+            }
+            program.setOrganisationUnitGroups( orgunitGroups );
+        }
+        
         programService.updateProgram( program );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/GetProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/GetProgramAction.java	2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/GetProgramAction.java	2013-05-03 07:36:17 +0000
@@ -27,9 +27,11 @@
 
 package org.hisp.dhis.patient.action.program;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.program.Program;
@@ -48,20 +50,27 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
     private ProgramService programService;
 
     public void setProgramService( ProgramService programService )
     {
         this.programService = programService;
     }
-    
+
     private SelectionTreeManager selectionTreeManager;
 
     public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
     {
         this.selectionTreeManager = selectionTreeManager;
     }
-    
+
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -123,6 +132,13 @@
         this.organisationUnitGroupId = organisationUnitGroupId;
     }
 
+    private List<OrganisationUnitGroup> availableOrgunitGroups = new ArrayList<OrganisationUnitGroup>();
+
+    public List<OrganisationUnitGroup> getAvailableOrgunitGroups()
+    {
+        return availableOrgunitGroups;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -132,8 +148,11 @@
     {
         program = programService.getProgram( id );
         
+        availableOrgunitGroups = new ArrayList<OrganisationUnitGroup>(organisationUnitGroupService.getAllOrganisationUnitGroups());
+        availableOrgunitGroups.removeAll( program.getOrganisationUnitGroups() );
+
         selectionTreeManager.setSelectedOrganisationUnits( program.getOrganisationUnits() );
-        
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-05-02 09:43:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-05-03 07:36:17 +0000
@@ -181,6 +181,8 @@
 
 	<bean id="org.hisp.dhis.patient.action.program.GetProgramAction"
 		class="org.hisp.dhis.patient.action.program.GetProgramAction" scope="prototype">
+		<property name="organisationUnitGroupService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="selectionTreeManager"
 			ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
@@ -252,6 +254,8 @@
 		id="org.hisp.dhis.patient.action.program.DefineProgramAssociationsAction"
 		class="org.hisp.dhis.patient.action.program.DefineProgramAssociationsAction"
 		scope="prototype">
+		<property name="organisationUnitGroupService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
 		<property name="selectionTreeManager"
 			ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
@@ -1102,7 +1106,8 @@
 		id="org.hisp.dhis.patient.action.programtindicator.GetProgramIndicatorListAction"
 		class="org.hisp.dhis.patient.action.programtindicator.GetProgramIndicatorListAction"
 		scope="prototype">
-		<property name="programIndicatorService" ref="org.hisp.dhis.program.ProgramIndicatorService" />
+		<property name="programIndicatorService"
+			ref="org.hisp.dhis.program.ProgramIndicatorService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 	</bean>
 
@@ -1114,7 +1119,7 @@
 			<ref bean="org.hisp.dhis.program.ProgramIndicatorService" />
 		</property>
 	</bean>
-	
+
 	<bean
 		id="org.hisp.dhis.patient.action.programtindicator.ValidateProgramIndicatorAction"
 		class="org.hisp.dhis.patient.action.programtindicator.ValidateProgramIndicatorAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programAssociations.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programAssociations.vm	2013-01-23 10:27:28 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/programAssociations.vm	2013-05-03 07:36:17 +0000
@@ -3,29 +3,68 @@
 
 <h4>$encoder.htmlEncode( $program.displayName )</h4>
 
+
 <form id="defineProgramAssociationsForm" action="defineProgramAssociations.action" method="post">
-  <div style="display:inline">
-	<input type="hidden" name="id" value="$program.id">
-  </div>
-  <table id="selectionTable">
-	<tr>
-	  <td>
-		#organisationUnitSelectionTree( false, true, false )
-	  </td>
-    </tr>
-	<tr>
-      <td>
-        <input type="submit" id="submitButton" value="$i18n.getString( "save" )" style="width:10em"><input type="button"
-            onclick="window.location.href='program.action'" value="$i18n.getString( "cancel" )" style="width:10em">
-      </td>
-    </tr>
-  </table>
-
+  
+  <div id="tabs">
+	<ul>
+		<li><a href="#tab-1">$i18n.getString("orgunit")</a></li>
+		<li><a href="#tab-2">$i18n.getString( "orgunit_group" )</a></li>
+	</ul>	
+	<div id="tab-1">
+	  <div style="display:inline">
+		<input type="hidden" name="id" value="$program.id">
+	  </div>
+	  <table id="selectionTable">
+		<tr>
+		  <td>
+			#organisationUnitSelectionTree( false, true, false )
+		  </td>
+		</tr>
+	  </table>
+	</div>
+	<div id="tab-2">
+		<table>
+			<thead>
+				<tr>
+					<th>$i18n.getString( "available" )</th>
+					<th>$i18n.getString( "filter" )</th>
+					<th>$i18n.getString( "selected" )</th>
+				</tr>
+			</thead>
+			<tr>
+				<td>
+					<select multiple id='orgunitGroupAvailable' size='10' ondblclick="moveSelectedById( 'orgunitGroupAvailable', 'orgunitGroupIds' )">
+					#foreach($group in $availableOrgunitGroups)
+						<option value='$group.id'>$encoder.htmlEncode($group.name)</option>
+					#end
+					</select>
+				</td>
+				<td>
+					<input type="button" style="width:40px" value="&gt;" title="$i18n.getString( 'add_selected' )" style="width:120px" onclick="moveSelectedById( 'orgunitGroupAvailable', 'orgunitGroupIds' )" /><br>
+					<input type="button" style="width:40px" value="&gt;&gt;" title="$i18n.getString( 'add_all' )" style="width:120px" onclick="moveAllById( 'orgunitGroupAvailable', 'orgunitGroupIds' )" /><br>
+					<input type="button" style="width:40px" value="&gt;" title="$i18n.getString( 'remove_selected' )" style="width:120px" onclick="moveSelectedById( 'orgunitGroupIds', 'orgunitGroupAvailable' )" /><br>
+					<input type="button" style="width:40px" value="&gt;&gt;" title="$i18n.getString( 'remove_all' )" style="width:120px" onclick="moveAllById( 'orgunitGroupIds', 'orgunitGroupAvailable' )" />
+				</td>
+				<td>
+					<select multiple id='orgunitGroupIds' name='orgunitGroupIds' size='10' ondblclick="moveSelectedById( 'orgunitGroupIds', 'orgunitGroupAvailable' )">
+					#foreach($group in $program.organisationUnitGroups)
+						<option value='$group.id'>$encoder.htmlEncode($group.name)</option>
+					#end
+					</select>
+				</td>
+			</tr>
+		</table>
+	</div>
+	
+	<p style='padding-left:20px'>
+		<input type="submit" id="submitButton" value="$i18n.getString( "save" )" style="width:10em">
+		<input type="button" onclick="window.location.href='program.action'" value="$i18n.getString( "cancel" )" style="width:10em">
+	</p>
 </form>
 
 <script type="text/javascript">
-
   var levelMustBeInt = '$encoder.jsEncode( $i18n.getString( "level_must_be_int" ) )';
   var i18n_loading = '$encoder.jsEncode( $i18n.getString( "loading" ) )';
-
+  $('#tabs').tabs();
 </script>