← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11627: Add authority to limit the scope of the search to include only persons registered in organization...

 

------------------------------------------------------------
revno: 11627
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-08-12 13:23:01 +0700
message:
  Add authority to limit the scope of the search to include only persons registered in organizational units the user is allowed to see.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsToListAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
  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/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
  dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java


--
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/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2013-08-02 04:53:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2013-08-12 06:23:01 +0000
@@ -208,19 +208,19 @@
 
     void removeErollmentPrograms( Program program );
 
-    Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
-
-    int countSearchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup );
-
-    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Integer min, Integer max );
-
-    List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Integer min, Integer max );
-
-    Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup, Integer min,
-        Integer max, I18n i18n );
+    Collection<Patient> searchPatients( List<String> searchKeys, Collection<OrganisationUnit> orgunit,
+        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
+
+    int countSearchPatients( List<String> searchKeys, Collection<OrganisationUnit> orgunit, Boolean followup );
+
+    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, Collection<OrganisationUnit> orgunit,
+        Boolean followup, Integer min, Integer max );
+
+    List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunit,
+        Boolean followup, Integer min, Integer max );
+
+    Grid getScheduledEventsReport( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup,
+        Integer min, Integer max, I18n i18n );
 
     Collection<Patient> getPatientsByPhone( String phoneNumber, Integer min, Integer max );
 
@@ -228,7 +228,7 @@
 
     Collection<Integer> getRegistrationOrgunitIds( Date startDate, Date endDate );
 
-    Grid getTrackingEventsReport( Program program, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        I18n i18n );
+    Grid getTrackingEventsReport( Program program, List<String> searchKeys, Collection<OrganisationUnit> orgunit,
+        Boolean followup, I18n i18n );
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-08-02 04:53:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-08-12 06:23:01 +0000
@@ -68,7 +68,7 @@
 
     void removeErollmentPrograms( Program program );
 
-    int countSearch( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup );
+    int countSearch( List<String> searchKeys, Collection<OrganisationUnit> orgunit, Boolean followup );
 
     Collection<Patient> getByPhoneNumber( String phoneNumber, Integer min, Integer max );
 
@@ -76,18 +76,19 @@
 
     Collection<Integer> getRegistrationOrgunitIds( Date startDate, Date endDate );
 
-    Collection<Patient> search( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
-
-    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
-
-    Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
-        Integer max );
-
-    List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
-        Integer max );
+    Collection<Patient> search( List<String> searchKeys, Collection<OrganisationUnit> orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
+
+    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
+
+    Grid getPatientEventReport( Grid grid, List<String> searchKeys, Collection<OrganisationUnit> orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
+        Integer max );
+
+    List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
+        Integer max );
+
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-08-02 04:53:58 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-08-12 06:23:01 +0000
@@ -523,27 +523,27 @@
         patientStore.removeErollmentPrograms( program );
     }
 
-    public Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
-    {
-        return patientStore.search( searchKeys, orgunit, followup, patientAttributes, min, max );
-    }
-
-    public int countSearchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup )
-    {
-        return patientStore.countSearch( searchKeys, orgunit, followup );
-    }
-
-    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit,
-        Boolean followup, Integer min, Integer max )
-    {
-        return patientStore.getPatientPhoneNumbers( searchKeys, orgunit, followup, null, min, max );
-    }
-
-    public List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Integer min, Integer max )
-    {
-        return patientStore.getProgramStageInstances( searchKeys, orgunit, followup, null, null, min, max );
+    public Collection<Patient> searchPatients( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+    {
+        return patientStore.search( searchKeys, orgunits, followup, patientAttributes, min, max );
+    }
+
+    public int countSearchPatients( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup )
+    {
+        return patientStore.countSearch( searchKeys, orgunits, followup );
+    }
+
+    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Integer min, Integer max )
+    {
+        return patientStore.getPatientPhoneNumbers( searchKeys, orgunits, followup, null, min, max );
+    }
+
+    public List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Integer min, Integer max )
+    {
+        return patientStore.getProgramStageInstances( searchKeys, orgunits, followup, null, null, min, max );
     }
 
     @Override
@@ -553,8 +553,8 @@
     }
 
     @Override
-    public Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Integer min, Integer max, I18n i18n )
+    public Grid getScheduledEventsReport( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Integer min, Integer max, I18n i18n )
     {
         String startDate = "";
         String endDate = "";
@@ -593,14 +593,14 @@
         grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
         grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
 
-        return patientStore.getPatientEventReport( grid, searchKeys, orgunit, followup, patientAttributes, null, min,
+        return patientStore.getPatientEventReport( grid, searchKeys, orgunits, followup, patientAttributes, null, min,
             max );
 
     }
 
     @Override
-    public Grid getTrackingEventsReport( Program program, List<String> searchKeys, OrganisationUnit orgunit,
-        Boolean followup, I18n i18n )
+    public Grid getTrackingEventsReport( Program program, List<String> searchKeys,
+        Collection<OrganisationUnit> orgunits, Boolean followup, I18n i18n )
     {
         String startDate = "";
         String endDate = "";
@@ -638,7 +638,7 @@
         grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
         grid.addHeader( new GridHeader( i18n.getString( "risk" ), false, true ) );
 
-        return patientStore.getPatientEventReport( grid, searchKeys, orgunit, followup, null, patientIdentifierTypes,
+        return patientStore.getPatientEventReport( grid, searchKeys, orgunits, followup, null, patientIdentifierTypes,
             null, null );
 
     }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-08-02 05:53:34 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-08-12 06:23:01 +0000
@@ -255,10 +255,10 @@
     }
 
     @Override
-    public Collection<Patient> search( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+    public Collection<Patient> search( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, null, min, max );
+        String sql = searchPatientSql( false, searchKeys, orgunits, followup, patientAttributes, null, min, max );
         Collection<Patient> patients = new HashSet<Patient>();
         try
         {
@@ -279,10 +279,10 @@
     }
 
     @Override
-    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit,
+    public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
         Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, null, min, max );
+        String sql = searchPatientSql( false, searchKeys, orgunits, followup, patientAttributes, null, min, max );
         Collection<String> phoneNumbers = new HashSet<String>();
         try
         {
@@ -304,11 +304,11 @@
     }
 
     @Override
-    public List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
-        Integer max )
+    public List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Collection<PatientAttribute> patientAttributes,
+        Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, identifierTypes, min,
+        String sql = searchPatientSql( false, searchKeys, orgunits, followup, patientAttributes, identifierTypes, min,
             max );
         List<Integer> programStageInstanceIds = new ArrayList<Integer>();
         try
@@ -330,21 +330,23 @@
         return programStageInstanceIds;
     }
 
-    public int countSearch( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup )
+    public int countSearch( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup )
     {
-        String sql = searchPatientSql( true, searchKeys, orgunit, followup, null, null, null, null );
+        String sql = searchPatientSql( true, searchKeys, orgunits, followup, null, null, null, null );
         return jdbcTemplate.queryForObject( sql, Integer.class );
     }
 
     @Override
-    public Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
+    public Grid getPatientEventReport( Grid grid, List<String> searchKeys, Collection<OrganisationUnit> orgunits,
+        Boolean followup, Collection<PatientAttribute> patientAttributes,
+        Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
     {
         // ---------------------------------------------------------------------
         // Get SQL and build grid
         // ---------------------------------------------------------------------
 
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, identifierTypes, null, null );
+        String sql = searchPatientSql( false, searchKeys, orgunits, followup, patientAttributes, identifierTypes, null,
+            null );
 
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
 
@@ -357,7 +359,7 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private String searchPatientSql( boolean count, List<String> searchKeys, OrganisationUnit orgunit,
+    private String searchPatientSql( boolean count, List<String> searchKeys, Collection<OrganisationUnit> orgunits,
         Boolean followup, Collection<PatientAttribute> patientAttributes,
         Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
     {
@@ -371,11 +373,15 @@
             for ( PatientIdentifierType identifierType : identifierTypes )
             {
                 sql += "(select identifier from patientidentifier where patientid=p.patientid and patientidentifiertypeid="
-                    + identifierType.getId() + " ) as " + Patient.PREFIX_IDENTIFIER_TYPE + "_" + identifierType.getId()
+                    + identifierType.getId()
+                    + " ) as "
+                    + Patient.PREFIX_IDENTIFIER_TYPE
+                    + "_"
+                    + identifierType.getId()
                     + " ,";
             }
         }
-        
+
         if ( patientAttributes != null )
         {
             for ( PatientAttribute patientAttribute : patientAttributes )
@@ -386,7 +392,6 @@
             }
         }
 
-
         String patientWhere = "";
         String patientOperator = " where ";
         String patientGroupBy = " GROUP BY  p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber ";
@@ -396,7 +401,7 @@
         boolean hasIdentifier = false;
         boolean isSearchEvent = false;
         boolean isPriorityEvent = false;
-        Collection<Integer> orgunitChilrenIds = getOrgunitChildren( orgunit );
+        Collection<Integer> orgunitChilrenIds = getOrgunitChildren( orgunits );
 
         for ( String searchKey : searchKeys )
         {
@@ -609,11 +614,12 @@
             }
         }
 
-        if ( orgunit != null && !isSearchEvent )
+        if ( orgunits != null && !isSearchEvent )
         {
-            sql += "(select organisationunitid from patient where patientid=p.patientid and organisationunitid = "
-                + orgunit.getId() + " ) as orgunitid,";
-            otherWhere += operator + "orgunitid=" + orgunit.getId();
+            sql += "(select organisationunitid from patient where patientid=p.patientid and organisationunitid in ( "
+                + TextUtils.getCommaDelimitedString( getOrganisationUnitIds( orgunits ) ) + " ) ) as orgunitid,";
+            otherWhere += operator + "orgunitid in ( "
+                + TextUtils.getCommaDelimitedString( getOrganisationUnitIds( orgunits ) ) + " ) ";
         }
 
         sql = sql.substring( 0, sql.length() - 1 ) + " "; // Removing last comma
@@ -664,7 +670,7 @@
         {
             sql += statementBuilder.limitRecord( min, max );
         }
-       
+        
         return sql;
     }
 
@@ -730,14 +736,35 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private Collection<Integer> getOrgunitChildren( OrganisationUnit orgunit )
-    {
-        Collection<Integer> orgunitIds = new HashSet<Integer>();
-        if ( orgunit != null )
-        {
-            orgunitIds.addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
-            orgunitIds.remove( orgunit.getId() );
-        }
+    private Collection<Integer> getOrgunitChildren( Collection<OrganisationUnit> orgunits )
+    {
+        Collection<Integer> orgunitIds = new HashSet<Integer>();
+        if ( orgunits != null )
+        {
+            for ( OrganisationUnit orgunit : orgunits )
+            {
+
+                orgunitIds
+                    .addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
+                orgunitIds.remove( orgunit.getId() );
+            }
+        }
+
+        if ( orgunitIds.size() == 0 )
+        {
+            orgunitIds.add( 0 );
+        }
+        return orgunitIds;
+    }
+
+    private Collection<Integer> getOrganisationUnitIds( Collection<OrganisationUnit> orgunits )
+    {
+        Collection<Integer> orgunitIds = new HashSet<Integer>();
+        for ( OrganisationUnit orgunit : orgunits )
+        {
+            orgunitIds.add( orgunit.getId() );
+        }
+
         if ( orgunitIds.size() == 0 )
         {
             orgunitIds.add( 0 );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2013-08-02 04:53:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2013-08-12 06:23:01 +0000
@@ -31,8 +31,10 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
@@ -219,6 +221,9 @@
     {
         OrganisationUnit orgunit = selectedStateManager.getSelectedOrganisationUnit();
 
+        Collection<OrganisationUnit> orgunits = new HashSet<OrganisationUnit>();
+        orgunits.add( orgunit );
+        
         if ( programId != null )
         {
             program = programService.getProgram( programId );
@@ -235,10 +240,10 @@
 
                 Collections.sort( patientAttributes, IdentifiableObjectNameComparator.INSTANCE );
 
-                total = patientService.countSearchPatients( searchTexts, orgunit, followup );
+                total = patientService.countSearchPatients( searchTexts, orgunits, followup );
                 this.paging = createPaging( total );
 
-                List<Integer> stageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunit,
+                List<Integer> stageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunits,
                     followup, paging.getStartPos(), paging.getPageSize() );
 
                 for ( Integer stageInstanceId : stageInstanceIds )
@@ -268,11 +273,11 @@
             }
             else if(trackingReport != null && trackingReport )
             {
-                grid = patientService.getTrackingEventsReport( program, searchTexts, orgunit, followup, i18n );
+                grid = patientService.getTrackingEventsReport( program, searchTexts, orgunits, followup, i18n );
             }
             else
             {
-                grid = patientService.getScheduledEventsReport( searchTexts, orgunit, followup, null, null, i18n );
+                grid = patientService.getScheduledEventsReport( searchTexts, orgunits, followup, null, null, i18n );
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java	2013-05-28 09:04:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java	2013-08-12 06:23:01 +0000
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -41,6 +42,7 @@
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.user.CurrentUserService;
 
 /**
  * @author Abyot Asalefew Gizaw
@@ -59,6 +61,8 @@
 
     private ProgramService programService;
 
+    private CurrentUserService currentUserService;
+
     // -------------------------------------------------------------------------
     // Input/output
     // -------------------------------------------------------------------------
@@ -67,6 +71,8 @@
 
     private Boolean searchBySelectedOrgunit;
 
+    private Boolean searchByUserOrgunits;
+
     private boolean listAll;
 
     private Collection<Patient> patients = new ArrayList<Patient>();
@@ -75,11 +81,21 @@
     // Getters && Setters
     // -------------------------------------------------------------------------
 
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
     public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
     {
         this.selectionManager = selectionManager;
     }
 
+    public void setSearchByUserOrgunits( Boolean searchByUserOrgunits )
+    {
+        this.searchByUserOrgunits = searchByUserOrgunits;
+    }
+
     public void setProgramService( ProgramService programService )
     {
         this.programService = programService;
@@ -150,6 +166,8 @@
     public String execute()
         throws Exception
     {
+        Collection<OrganisationUnit> orgunits = new HashSet<OrganisationUnit>();
+
         OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
 
         // List all patients
@@ -164,14 +182,26 @@
         // search patients
         else if ( searchTexts.size() > 0 )
         {
-            organisationUnit = (searchBySelectedOrgunit) ? organisationUnit : null;
+            if ( searchByUserOrgunits )
+            {
+                Collection<OrganisationUnit> userOrgunits = currentUserService.getCurrentUser().getOrganisationUnits();
+                orgunits.addAll( userOrgunits );
+            }
+            else if ( searchBySelectedOrgunit )
+            {
+                orgunits.add( organisationUnit );
+            }
+            else
+            {
+                organisationUnit = null;
+            }
 
-            total = patientService.countSearchPatients( searchTexts, organisationUnit, null );
+            total = patientService.countSearchPatients( searchTexts, orgunits, null );
             this.paging = createPaging( total );
-            patients = patientService.searchPatients( searchTexts, organisationUnit, null, null, paging.getStartPos(),
+            patients = patientService.searchPatients( searchTexts, orgunits, null, null, paging.getStartPos(),
                 paging.getPageSize() );
 
-            if ( !searchBySelectedOrgunit )
+            if ( !searchBySelectedOrgunit || searchByUserOrgunits )
             {
                 for ( Patient patient : patients )
                 {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsToListAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsToListAction.java	2013-08-12 03:29:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsToListAction.java	2013-08-12 06:23:01 +0000
@@ -62,7 +62,7 @@
     private PatientService patientService;
 
     private SmsSender smsSender;
-    
+
     private ProgramStageInstanceService programStageInstanceService;
 
     private CurrentUserService currentUserService;
@@ -77,6 +77,8 @@
 
     private Boolean searchBySelectedOrgunit;
 
+    private Boolean searchByUserOrgunits;
+
     private Boolean followup;
 
     // -------------------------------------------------------------------------
@@ -118,6 +120,11 @@
         this.searchBySelectedOrgunit = searchBySelectedOrgunit;
     }
 
+    public void setSearchByUserOrgunits( Boolean searchByUserOrgunits )
+    {
+        this.searchByUserOrgunits = searchByUserOrgunits;
+    }
+
     public void setPatientService( PatientService patientService )
     {
         this.patientService = patientService;
@@ -128,10 +135,6 @@
         this.searchTexts = searchTexts;
     }
 
-    // -------------------------------------------------------------------------
-    // Input & Output
-    // -------------------------------------------------------------------------
-
     private String msg;
 
     public void setMsg( String msg )
@@ -154,14 +157,29 @@
     public String execute()
         throws Exception
     {
-        OrganisationUnit organisationUnit = (searchBySelectedOrgunit) ? selectionManager.getSelectedOrganisationUnit()
-            : null;
-
-        Collection<Integer> programStageInstanceIds = patientService.getProgramStageInstances( searchTexts,
-            organisationUnit, followup, null, null );
+        OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
+        Collection<OrganisationUnit> orgunits = new HashSet<OrganisationUnit>();
+
+        if ( searchByUserOrgunits )
+        {
+            Collection<OrganisationUnit> userOrgunits = currentUserService.getCurrentUser().getOrganisationUnits();
+            orgunits.addAll( userOrgunits );
+        }
+        else if ( searchBySelectedOrgunit )
+        {
+            orgunits.add( organisationUnit );
+        }
+
+        else
+        {
+            organisationUnit = null;
+        }
+
+        Collection<Integer> programStageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunits,
+            followup, null, null );
 
         Set<String> phoneNumberList = new HashSet<String>( patientService.getPatientPhoneNumbers( searchTexts,
-            organisationUnit, followup, null, null ) );
+            orgunits, followup, null, null ) );
         try
         {
             OutboundSms outboundSms = new OutboundSms();
@@ -182,5 +200,4 @@
 
         return SUCCESS;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-08-12 03:29:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-08-12 06:23:01 +0000
@@ -31,6 +31,7 @@
 			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
+		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 	</bean>
 
 	<bean

=== 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-08-08 06:20:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-08-12 06:23:01 +0000
@@ -673,4 +673,5 @@
 scheduled = Scheduled
 event_registration = Event registration
 add_patient_related_the_seleced_event = Add person related to the selected event
-related_patient = Related person
\ No newline at end of file
+related_patient = Related person
+search_by_user_orgunits = Search by user orgunits
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-08-07 08:46:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2013-08-12 06:23:01 +0000
@@ -36,6 +36,12 @@
       <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
       <param name="requiredAuthorities">F_SEARCH_PATIENT_IN_ALL_FACILITIES</param>
     </action>
+    
+     <action name="searchByUserFacilities"
+      class="org.hisp.dhis.caseentry.action.NoAction">
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <param name="requiredAuthorities">F_SEARCH_PATIENT_IN_USER_FACILITIES</param>
+    </action>
 
     <action name="searchPatient"
       class="org.hisp.dhis.caseentry.action.patient.SearchPatientAction">
@@ -71,14 +77,19 @@
       <result name="success" type="velocity-json">/dhis-web-caseentry/jsonProgramStageInstance.vm</result>
     </action>
     
-    <action name="dataentryform"
+    <action name="editDataEntryForm"
+      class="org.hisp.dhis.caseentry.action.NoAction">
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <param name="requiredAuthorities">F_PATIENT_DATAVALUE_ADD,F_PATIENT_DATAVALUE_DELETE</param>
+    </action>
+	
+	<action name="dataentryform"
       class="org.hisp.dhis.caseentry.action.caseentry.LoadDataEntryAction">
       <result name="success" type="velocity">/content.vm</result>
       <param name="page">/dhis-web-caseentry/dataEntryForm.vm</param>
       <param name="stylesheets">style/style.css</param>
-      <param name="requiredAuthorities">F_PATIENT_DATAVALUE_ADD,F_PATIENT_DATAVALUE_DELETE</param>
     </action>
-
+    
     <action name="completeDataEntry"
       class="org.hisp.dhis.caseentry.action.caseentry.CompleteDataEntryAction">
       <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-08-06 03:47:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2013-08-12 06:23:01 +0000
@@ -37,10 +37,10 @@
 		<tr id='entryPostComment'>
 			<th class='coordinates1'><label for="postComment">$i18n.getString('post_comment'):</label></th>
 			<th colspan='3'>
-				<input type="text" class="{validate:{maxlength:160}} criteria" id="commentInput"
+				<input type="text" class="{validate:{maxlength:160}} criteria" id="commentInput" name='commentInput'
                         style="width:380px;#if($programStage.captureCoordinates=='false') margin-left:11px; padding-left: 2px;  #end "
                        onkeypress="keypressOnComment( event, this );">
-				<input id="commentButton" type="button" style='width:40px' value="$i18n.getString('add')" onclick='addComment( byId("commentInput"), $programStageInstance.id )'>
+				<input id="commentButton" name='commentButton' type="button" style='width:40px' value="$i18n.getString('add')" onclick='addComment( byId("commentInput"), $programStageInstance.id )'>
 			</th>
 		</tr>
 
@@ -111,8 +111,16 @@
 	var i18n_incomplete_confirm_message = '$encoder.jsEscape( $i18n.getString( "incomplete_confirm_message" ) , "'" )';
 	var i18n_add_patient_related_the_selected_event = '$encoder.jsEscape( $i18n.getString( "add_patient_related_the_selected_event" ) , "'" )';
 	
-	if(getFieldValue('completed')=='true' && getFieldValue('blockEntryForm')=='true'){
+	var editDataEntryForm = eval($auth.hasAccess( "dhis-web-caseentry", "editDataEntryForm" ));
+	if( (getFieldValue('completed')=='true' && getFieldValue('blockEntryForm')=='true' ) 
+		||  !editDataEntryForm) {
 		blockEntryForm();
+		if(!editDataEntryForm){
+			disable('executionDate');
+			disable('completeBtn');
+			disable('uncompleteBtn');
+			disable('validateBtn');
+		}
 	}
 					
 	#if($programStage.relatedPatient=='true')

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-08-08 06:29:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-08-12 06:23:01 +0000
@@ -281,6 +281,10 @@
 	});
 		
 	params += '&listAll=false';
+	
+	var searchByUserOrgunits = byId('searchByUserOrgunits').checked ? true : false;
+	params += '&searchByUserOrgunits=' + searchByUserOrgunits;
+	
 	if( getFieldValue('searchByProgramStage') == "false"){
 		var searchInAllFacility = byId('searchInAllFacility').checked;
 		params += '&searchBySelectedOrgunit=' + !searchInAllFacility;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-08-08 06:20:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/patient.js	2013-08-12 06:23:01 +0000
@@ -352,36 +352,47 @@
 			programStageInstanceId: programStageInstanceId
 		},function( )
 		{
-			var executionDate = jQuery('#executionDate').val();
-			var completed = jQuery('#entryFormContainer input[id=completed]').val();
-			var irregular = jQuery('#entryFormContainer input[id=irregular]').val();
-			var reportDateDes = jQuery("#ps_" + programStageInstanceId).attr("reportDateDes");
-			setInnerHTML('reportDateDescriptionField',reportDateDes);
-			enable('validationBtn');
-			if( executionDate == '' )
-			{
-				disable('validationBtn');
-			}
-			else if( executionDate != ''){
-				if ( completed == 'false' ){
-					disableCompletedButton(false);
-				}
-				else if( completed == 'true' ){
-					disableCompletedButton(true);
-				}
-			}
-			
-			var linkedEvent = jQuery(".stage-object-selected").attr("linkedEvent");
-			if( linkedEvent=='true' ) {
+			var editDataEntryForm = getFieldValue('editDataEntryForm');
+			if(editDataEntryForm=='true')
+			{
+				var executionDate = jQuery('#executionDate').val();
+				var completed = jQuery('#entryFormContainer input[id=completed]').val();
+				var irregular = jQuery('#entryFormContainer input[id=irregular]').val();
+				var reportDateDes = jQuery("#ps_" + programStageInstanceId).attr("reportDateDes");
+				setInnerHTML('reportDateDescriptionField',reportDateDes);
+				enable('validationBtn');
+				if( executionDate == '' )
+				{
+					disable('validationBtn');
+				}
+				else if( executionDate != ''){
+					if ( completed == 'false' ){
+						disableCompletedButton(false);
+					}
+					else if( completed == 'true' ){
+						disableCompletedButton(true);
+					}
+				}
+				
+				var linkedEvent = jQuery(".stage-object-selected").attr("linkedEvent");
+				if( linkedEvent=='true' ) {
+					blockEntryForm();
+					disable('executionDate');
+				}
+				else{
+					enable('executionDate');
+				}
+				$(window).scrollTop(200);
+			}
+			else
+			{
 				blockEntryForm();
 				disable('executionDate');
-			}
-			else{
-				enable('executionDate');
-			}
+				hideById('inputCriteriaDiv');
+			}
+			
 			resize();
 			hideLoader();
 			hideById('contentDiv');
-			$(window).scrollTop(200);
 		} );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm	2013-05-30 06:42:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programEnrollmentForm.vm	2013-08-12 06:23:01 +0000
@@ -5,6 +5,8 @@
 <input type='hidden' id='programStageInstanceId' name='programStageInstanceId' value='0'>
 <input type='hidden' id='patientId' name='patientId' value='$programInstance.patient.id' />
 <input type='hidden' id='hasDataEntry' name='hasDataEntry' value='$hasDataEntry' />
+<input type='hidden' name='editDataEntryForm' id='editDataEntryForm' value='$auth.hasAccess( "dhis-web-caseentry", "editDataEntryForm" )'>
+
 <div id="tabs">
 	<ul>
 		#if( $hasDataEntry == 'true' )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-08-02 04:53:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-08-12 06:23:01 +0000
@@ -71,16 +71,27 @@
 
 <div id='advanced-search' name='advanced-search' class='hidden advanced-search'>
 	<table>	
-		#if( $auth.hasAccess( "dhis-web-caseentry", "searchAllFacilities" ) )
 			<tr id='searchBySelectedUnitTD'>
-				<td>
-					$i18n.getString('search_in_all_facilities') 
-					<input type='checkbox' id='searchInAllFacility' name='searchInAllFacility' />&nbsp;&nbsp;&nbsp;
-				</td>
+				#if( $auth.hasAccess( "dhis-web-caseentry", "searchAllFacilities" ) )
+					<td>
+						$i18n.getString('search_in_all_facilities') 
+						<input type='checkbox' id='searchInAllFacility' name='searchInAllFacility' />&nbsp;&nbsp;&nbsp;
+					</td>
+				#else
+					<input type='checkbox' class='hidden' id='searchInAllFacility' name='searchInAllFacility' />
+				#end
+				
+				#if( $auth.hasAccess( "dhis-web-caseentry", "searchByUserFacilities" ) )
+					<td>
+						$i18n.getString('search_by_user_orgunits') 
+						<input type='checkbox' id='searchByUserOrgunits' name='searchByUserOrgunits' />&nbsp;&nbsp;&nbsp;
+					</td>
+				#else
+					<input type='checkbox' class='hidden' id='searchByUserOrgunits' name='searchByUserOrgunits' />
+				#end
 			</tr>
-		#else
-			<input type='checkbox' class='hidden' id='searchInAllFacility' name='searchInAllFacility' />
-		#end
+		
+		
 		<tr id='dueDateTR' class='hidden'>
 			<td>$i18n.getString('due_date_from_to')</td>
 			<td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-07-31 06:51:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-08-12 06:23:01 +0000
@@ -449,4 +449,4 @@
 default_form_name = Default form name
 custom_form_name = Custom form name
 allow_select_enrollment_dates_in_future = Allow seleting enrollment dates in future
-related_patient = Related patient
\ No newline at end of file
+related_patient = Related person
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2013-07-26 03:52:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2013-08-12 06:23:01 +0000
@@ -128,6 +128,7 @@
 F_ADD_PROGRAM_INDICATOR = Add/Update Program Indicator
 F_PATIENT_CHANGE_LOCATION = Change Person Location
 F_SEARCH_PATIENT_IN_ALL_FACILITIES = Search Person In All Facilities
+F_SEARCH_PATIENT_IN_USER_FACILITIES = Search Person In User Facilities
 F_ADD_PATIENT_REGISTRATION_FORM=Add Person Registration Form
 F_PROGRAM_INSTANCE_MANAGEMENT = Program Event Management
 F_PROGRAM_INSTANCE_DELETE = Delete Program Enrollment

=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java'
--- dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java	2013-05-29 04:13:57 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java	2013-08-12 06:23:01 +0000
@@ -40,6 +40,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -135,7 +136,8 @@
         throws Exception
     {
         OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
-
+        Collection<OrganisationUnit> orgunits = new HashSet<OrganisationUnit>();
+        
         // List all patients
         if ( listAll )
         {
@@ -150,10 +152,14 @@
         else if ( searchTexts.size() > 0 )
         {
             organisationUnit = (searchBySelectedOrgunit) ? organisationUnit : null;
+            if( organisationUnit != null )
+            {
+                orgunits.add( organisationUnit );
+            }
 
-            total = patientService.countSearchPatients( searchTexts, organisationUnit, null );
+            total = patientService.countSearchPatients( searchTexts, orgunits, null );
             this.paging = createPaging( total );
-            patients = patientService.searchPatients( searchTexts, organisationUnit, null, null, paging.getStartPos(), paging
+            patients = patientService.searchPatients( searchTexts, orgunits, null, null, paging.getStartPos(), paging
                 .getPageSize() );
 
             if ( !searchBySelectedOrgunit )