← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8297: Add search funtion for option set in single event form - web light

 

------------------------------------------------------------
revno: 8297
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-09-28 15:13:37 +0700
message:
  Add search funtion for option set in single event form - web light
added:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/FindSingleEventOptionSetAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventOptionSetFindForm.vm
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/FindBeneficiarytAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/GetSingleEventFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties
  dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventForm.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-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/FindBeneficiarytAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/FindBeneficiarytAction.java	2012-09-27 06:54:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/FindBeneficiarytAction.java	2012-09-28 08:13:37 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2009, University of Oslo
+  * Copyright (c) 2004-2009, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/FindSingleEventOptionSetAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/FindSingleEventOptionSetAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/FindSingleEventOptionSetAction.java	2012-09-28 08:13:37 +0000
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.light.singleevent.action;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.util.SessionUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Nguyen Kim Lai
+ * 
+ * @version $ FindOptionSetAction.java Sep 25, 2012 $
+ */
+public class FindSingleEventOptionSetAction
+    implements Action
+
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataElementService dataElementService;
+ 
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private String keyword;
+
+    public void setKeyword( String keyword )
+    {
+        this.keyword = keyword;
+    }
+
+    private int dataElementIdForSearching;
+
+    public void setDataElementIdForSearching( int dataElementIdForSearching )
+    {
+        this.dataElementIdForSearching = dataElementIdForSearching;
+    }
+    
+    public int getDataElementIdForSearching()
+    {
+        return dataElementIdForSearching;
+    }
+
+    private List<String> searchingResultList;
+    
+    public List<String> getSearchingResultList()
+    {
+        return searchingResultList;
+    }
+    
+    private Integer programId;
+
+    public Integer getProgramId()
+    {
+        return programId;
+    }
+
+    public void setProgramId( Integer programId )
+    {
+        this.programId = programId;
+    }
+
+    private Integer patientId;
+
+    public Integer getPatientId()
+    {
+        return patientId;
+    }
+
+    public void setPatientId( Integer patientId )
+    {
+        this.patientId = patientId;
+    }
+    
+    private Integer organisationUnitId;
+
+    public void setOrganisationUnitId( Integer organisationUnitId )
+    {
+        this.organisationUnitId = organisationUnitId;
+    }
+
+    public Integer getOrganisationUnitId()
+    {
+        return this.organisationUnitId;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+/*        this.test = (Map<String, String>) SessionUtils.getSessionVar( "test" );
+        System.out.println( "size: " + this.test.size() );
+        System.out.println( "Key word: " + this.keyword );
+        System.out.println( "ID: " + this.dataElementIdForSearching );
+        System.out.println( "program ID: " + this.programId);
+        System.out.println( "patient ID: " + this.patientId);
+        System.out.println( "org ID: " + this.organisationUnitId);*/
+        DataElement dataElement = dataElementService.getDataElement( this.dataElementIdForSearching );
+        
+        OptionSet optionSet = dataElement.getOptionSet();
+        
+        List<String> optionList = optionSet.getOptions();
+        
+        searchingResultList = new ArrayList<String>();
+        
+        for( String each: optionList )
+        {
+            if(each != null)
+            {
+                if( each.contains( this.keyword ) )
+                {
+                    this.searchingResultList.add( each );
+                }
+            }
+        }
+        return SUCCESS;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/GetSingleEventFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/GetSingleEventFormAction.java	2012-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/GetSingleEventFormAction.java	2012-09-28 08:13:37 +0000
@@ -31,10 +31,14 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.util.SessionUtils;
 
 public class GetSingleEventFormAction
     implements Action
@@ -136,10 +140,42 @@
         }
     };
 
+    private Map<String, String> prevDataValues = new HashMap<String, String>();
+
+    public Map<String, String> getPrevDataValues()
+    {
+        return prevDataValues;
+    }
+    
+    private String searchResult;
+    
+    public void setSearchResult( String searchResult )
+    {
+        this.searchResult = searchResult;
+    }
+    
+    private int dataElementIdForSearching;
+    
+    public void setDataElementIdForSearching( int dataElementIdForSearching )
+    {
+        this.dataElementIdForSearching = dataElementIdForSearching;
+    }
+    
     @Override
     public String execute()
         throws Exception
     {
+        System.out.println("searching Result: " + searchResult );
+        
+        if( SessionUtils.getSessionVar( "prevDataValues" ) != null )
+        {
+            this.prevDataValues = (Map<String, String>) SessionUtils.getSessionVar( "prevDataValues" );
+        }
+        if( searchResult != null)
+        {
+            this.prevDataValues.put( "DE"+this.dataElementIdForSearching, searchResult );
+        }
+        
         Program program = programService.getProgram( programId );
         eventName = program.getName();
         ProgramStage programStage = program.getProgramStages().iterator().next();

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java	2012-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/singleevent/action/SaveSingleEventAction.java	2012-09-28 08:13:37 +0000
@@ -57,6 +57,7 @@
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.util.ContextUtils;
+import org.hisp.dhis.util.SessionUtils;
 
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
@@ -64,6 +65,8 @@
 public class SaveSingleEventAction
     implements Action
 {
+    private static final String REDIRECT = "redirect";
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -271,6 +274,22 @@
             return i1.getSortOrder().compareTo( i2.getSortOrder() );
         }
     };
+    
+    private String keyword;
+    
+    public String getKeyword()
+    {
+        return keyword;
+    }
+    
+    private int dataElementIdForSearching;
+    
+    public int getDataElementIdForSearching()
+    {
+        return dataElementIdForSearching;
+    }
+    
+
 
     @Override
     public String execute()
@@ -289,11 +308,20 @@
         HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
             ServletActionContext.HTTP_REQUEST );
         Map<String, String> parameterMap = ContextUtils.getParameterMap( request );
-
+        
         typeViolations.clear();
 
         prevDataValues.clear();
-
+        
+        if( SessionUtils.getSessionVar( "prevDataValues" ) == null)
+        {
+            SessionUtils.setSessionVar( "prevDataValues", this.prevDataValues );
+        }
+        else
+        {
+            this.prevDataValues = (Map<String, String>) SessionUtils.getSessionVar( "prevDataValues" );
+        }
+        
         // -------------------------------------------------------------------------
         // Validation
         // -------------------------------------------------------------------------
@@ -337,7 +365,12 @@
         {
             return ERROR;
         }
-
+        
+        if( isSearching( parameterMap ) == true )
+        {    
+            return REDIRECT;
+        }
+        
         ProgramInstance programInstance = new ProgramInstance();
         programInstance.setEnrollmentDate( new Date() );
         programInstance.setDateOfIncident( new Date() );
@@ -375,8 +408,45 @@
 
             patientDataValueService.savePatientDataValue( patientDataValue );
         }
+        SessionUtils.removeSessionVar( "prevDataValues" );
 
         return SUCCESS;
     }
+    
+    public boolean isSearching( Map<String, String> parameterMap )
+    {
+        boolean isCorrect = false;
+        for( ProgramStageDataElement each : this.programStageDataElements)
+        {
+            DataElement dataElement = each.getDataElement();
+            
+            if( dataElement.getOptionSet() != null && dataElement.getOptionSet().getOptions().size() > 15)
+            {
+                System.out.println("truoc: "+parameterMap.get( "preDE"+dataElement.getId() ));
+                System.out.println("sau: "+parameterMap.get( "DE"+dataElement.getId() ));
+                
+                this.keyword = parameterMap.get( "DE"+dataElement.getId() ).trim();
+                
+                dataElementIdForSearching = dataElement.getId();
+
+                //if( !parameterMap.get( "preDE"+dataElement.getId() ).equals( parameterMap.get( "DE"+dataElement.getId() )))
+                for( String option: dataElement.getOptionSet().getOptions() )
+                {
+                    if( option != null )
+                    {
+                        if(option.equals( this.keyword ))
+                        {
+                            isCorrect = true;
+                        }
+                    }
+                }
+                if( isCorrect == false && !this.keyword.isEmpty())
+                    return true;
+                else
+                    isCorrect = false;
+            }
+        }
+        return false;
+    }
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2012-09-24 03:28:31 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2012-09-28 08:13:37 +0000
@@ -393,6 +393,10 @@
 		<property name="programStageDataElementService" ref="org.hisp.dhis.program.ProgramStageDataElementService" />
 	</bean>
 
+	
+	<bean id="org.hisp.dhis.light.singleevent.action.FindSingleEventOptionSetAction" class="org.hisp.dhis.light.singleevent.action.FindSingleEventOptionSetAction">
+		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+	</bean>
 	<!-- Dashboard -->
 
 	<bean id="org.hisp.dhis.light.dashboard.action.ProvideContentAction"
@@ -492,4 +496,5 @@
 		<property name="relationshipService"
 			ref="org.hisp.dhis.relationship.RelationshipService" />
 	</bean>
+
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2012-09-27 10:11:02 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2012-09-28 08:13:37 +0000
@@ -80,6 +80,7 @@
 program_list=Program List
 single_event=Single Event
 single_event_list=Single Event List
+back_single_event_form=Back To Single Event Form
 tracking=Tracking
 find_beneficiary=Find Person
 activity_plan=Activity Plan

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2012-09-24 03:28:31 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2012-09-28 08:13:37 +0000
@@ -303,7 +303,7 @@
     </action>
 
     <action name="showSingleEventForm"
-        class="org.hisp.dhis.light.singleevent.action.GetSingleEventFormAction">
+	class="org.hisp.dhis.light.singleevent.action.GetSingleEventFormAction">
       <result name="success" type="velocity">/dhis-web-light/main.vm</result>
       <param name="page">/dhis-web-light/singleevent/singleEventForm.vm</param>
     </action>
@@ -314,8 +314,17 @@
         /light/selectSingleEventBeneficiary.action?programId=${programId}&amp;organisationUnitId=${organisationUnitId}&amp;validated=true
       </result>
       <result name="error" type="velocity">/dhis-web-light/main.vm</result>
+      <result name="redirect" type="redirect">findSingleEventOptionSet.action?keyword=${keyword}&amp;dataElementIdForSearching=${dataElementIdForSearching}&amp;organisationUnitId=${organisationUnitId}&amp;patientId=${patientId}&amp;programId=${programId}</result>
       <param name="page">/dhis-web-light/singleevent/singleEventForm.vm</param>
     </action>
+    
+    <action name="findSingleEventOptionSet"
+    	class="org.hisp.dhis.light.singleevent.action.FindSingleEventOptionSetAction">
+    	<!--<result name="success" type="redirect">showSingleEventForm.action?organisationUnitId=559&amp;patientId=1149378&amp;programId=1149486</result>
+    	-->
+    	<result name="success" type="velocity">/dhis-web-light/main.vm</result>
+    	<param name="page">/dhis-web-light/singleevent/singleEventOptionSetFindForm.vm</param>
+    </action>
 
     <!-- Reports -->
 
@@ -424,5 +433,6 @@
       <result name="error" type="velocity">/dhis-web-light/main.vm</result>
       <param name="page">/dhis-web-light/anonymous/anonymousProgramForm.vm</param>
     </action>
+    
   </package>
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventForm.vm	2012-07-13 09:18:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventForm.vm	2012-09-28 08:13:37 +0000
@@ -35,14 +35,21 @@
 				<input type="text" name="$key" value="$!prevDataValues.get($key)" />
 			#end	
 		#elseif ($dataElement.getOptionSet())
-			#set( $options = $dataElement.getOptionSet().getOptions() )
-			<select type="text" name="$key" />
-				<option selected > $i18n.getString("select_option") </option>
-			#foreach ($option in $options)
-				<option value="$option" #if($prevDataValues.get($key) == $option) selected #end> $option </option>
+				#set( $options = $dataElement.getOptionSet().getOptions() )
+				
+				#if( $options.size() > 15 )
+					<input type="hidden" name="pre$key" style="height:20px" value="$!prevDataValues.get($key)"/>
+					<input type="text" name="$key" style="height:20px" value="$!prevDataValues.get($key)"/>
+					<input type="submit" style="width:100%" value="$i18n.getString('search')"/>
+				#else
+					<select type="text" name="$key" />
+						<option selected > $i18n.getString("select_option") </option>	
+					#foreach ($option in $options)
+						<option value="$option" #if($prevDataValues.get($key) == $option) selected #end> $option </option>
+					#end
+					</select>
+				#end
 			#end
-			</select>
-		#end
 	#end
 		<input type="hidden" name="organisationUnitId" value="$organisationUnitId" />
 		<input type="hidden" name="programId" value="$programId" />

=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventOptionSetFindForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventOptionSetFindForm.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/singleevent/singleEventOptionSetFindForm.vm	2012-09-28 08:13:37 +0000
@@ -0,0 +1,19 @@
+<h2>Option Set Searching Result</h2>
+<p>
+	#if( $searchingResultList.size() == 0 )
+		No result
+	#else
+		<ul>
+		#foreach( $option in $searchingResultList )
+			<li><a href="showSingleEventForm.action?searchResult=$option&dataElementIdForSearching=$dataElementIdForSearching&organisationUnitId=$organisationUnitId&patientId=$patientId&programId=$programId">$option</a></li>
+		#end	
+		</ul>
+	#end
+</p>
+<div id="footer">
+	<h2>$i18n.getString( "navigate_to" )</h2>
+	<ul>
+		<li><a href="showSingleEventForm.action?organisationUnitId=$organisationUnitId&patientId=$patientId&programId=$programId">$i18n.getString("back_single_event_form")</a></li>
+		<li><a href="index.action">$i18n.getString("home")</a></li>
+	</ul>
+</div>
\ No newline at end of file