← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9041: [mobile] update Provided elsewhere check option for program stage form

 

------------------------------------------------------------
revno: 9041
committer: Homg Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-11-15 13:17:43 +0700
message:
  [mobile] update Provided elsewhere check option for program stage form
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetProgramStageFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.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/webapp/dhis-web-light/namebased/completedProgramStageForm.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/selectProgramStageSection.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/GetProgramStageFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetProgramStageFormAction.java	2012-11-07 12:55:09 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetProgramStageFormAction.java	2012-11-15 06:17:43 +0000
@@ -32,11 +32,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.hisp.dhis.api.mobile.model.Activity;
 import org.hisp.dhis.api.mobile.model.ActivityPlan;
-import org.hisp.dhis.api.mobile.model.DataElement;
-
 import org.hisp.dhis.light.utils.NamebasedUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
@@ -168,13 +165,6 @@
         this.organisationUnit = organisationUnit;
     }
 
-    private List<DataElement> dataElements;
-
-    public List<DataElement> getDataElements()
-    {
-        return this.dataElements;
-    }
-
     private ProgramStage programStage;
 
     public ProgramStage getProgramStage()
@@ -300,11 +290,16 @@
         this.current = current;
     }
 
-    private List<ProgramStageDataElement> listOfProgramStageDataElement;
-
-    public List<ProgramStageDataElement> getListOfProgramStageDataElement()
-    {
-        return listOfProgramStageDataElement;
+    private List<ProgramStageDataElement> dataElements;
+
+    public List<ProgramStageDataElement> getDataElements()
+    {
+        return dataElements;
+    }
+
+    public void setDataElements( List<ProgramStageDataElement> dataElements )
+    {
+        this.dataElements = dataElements;
     }
 
     @Override
@@ -318,18 +313,12 @@
         if ( programStageSectionId != null && programStageSectionId != 0 )
         {
             this.programStageSection = programStageSectionService.getProgramStageSection( this.programStageSectionId );
-
-            listOfProgramStageDataElement = programStageSection.getProgramStageDataElements();
-
-            dataElements = util.transformDataElementsToMobileModel( listOfProgramStageDataElement );
+            dataElements = programStageSection.getProgramStageDataElements();
 
         }
         else
         {
-            listOfProgramStageDataElement = new ArrayList<ProgramStageDataElement>(
-                programStage.getProgramStageDataElements() );
-
-            dataElements = util.transformDataElementsToMobileModel( programStageId );
+            dataElements = new ArrayList<ProgramStageDataElement>( programStage.getProgramStageDataElements() );
         }
 
         program = programStageInstanceService.getProgramStageInstance( programStageInstanceId ).getProgramInstance()
@@ -339,6 +328,11 @@
         for ( PatientDataValue patientDataValue : patientDataValues )
         {
             prevDataValues.put( "DE" + patientDataValue.getDataElement().getId(), patientDataValue.getValue() );
+            if ( patientDataValue.getProvidedElsewhere() != null )
+            {
+                prevDataValues.put( "CB" + patientDataValue.getDataElement().getId(), patientDataValue
+                    .getProvidedElsewhere().toString() );
+            }
         }
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java	2012-11-13 04:26:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/SaveProgramStageFormAction.java	2012-11-15 06:17:43 +0000
@@ -29,18 +29,12 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.api.mobile.ActivityReportingService;
-import org.hisp.dhis.api.mobile.NotAllowedException;
-import org.hisp.dhis.api.mobile.model.ActivityValue;
-import org.hisp.dhis.api.mobile.model.DataElement;
-import org.hisp.dhis.api.mobile.model.DataValue;
 import org.hisp.dhis.program.ProgramExpressionService;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -50,6 +44,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
@@ -67,7 +62,6 @@
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
 
-
 public class SaveProgramStageFormAction
     implements Action
 {
@@ -99,14 +93,7 @@
     {
         this.dataElementService = dataElementService;
     }
-
-    private ActivityReportingService activityReportingService;
-
-    public void setActivityReportingService( ActivityReportingService activityReportingService )
-    {
-        this.activityReportingService = activityReportingService;
-    }
-
+    
     private OrganisationUnitService organisationUnitService;
 
     public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
@@ -204,9 +191,9 @@
     {
         this.programStageSectionService = programStageSectionService;
     }
-    
+
     private ProgramExpressionService programExpressionService;
-    
+
     public ProgramExpressionService getProgramExpressionService()
     {
         return programExpressionService;
@@ -216,7 +203,7 @@
     {
         this.programExpressionService = programExpressionService;
     }
-        
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -302,10 +289,8 @@
     {
         return programStage;
     }
-    
+
     private ProgramStageDataElement programStageDataElement;
-    
-    
 
     public ProgramStageDataElement getProgramStageDataElement()
     {
@@ -324,9 +309,9 @@
         return current;
     }
 
-    private List<DataElement> dataElements;
+    private List<ProgramStageDataElement> dataElements;
 
-    public List<DataElement> getDataElements()
+    public List<ProgramStageDataElement> getDataElements()
     {
         return dataElements;
     }
@@ -427,12 +412,12 @@
     private I18nFormat format;
 
     private List<ProgramValidationResult> programValidationResults;
-    
+
     public List<ProgramValidationResult> getProgramValidationResults()
     {
         return programValidationResults;
     }
-    
+
     @Override
     public String execute()
         throws Exception
@@ -450,27 +435,28 @@
         program = programStageService.getProgramStage( programStageId ).getProgram();
         org.hisp.dhis.program.ProgramStage dhisProgramStage = programStageService.getProgramStage( programStageId );
 
+        ProgramStageInstance programStageInstance = programStageInstanceService
+            .getProgramStageInstance( programStageInstanceId );
+
+        List<PatientDataValue> patientDataValues = new ArrayList<PatientDataValue>();
+
         patient = patientService.getPatient( patientId );
         if ( programStageSectionId != null && programStageSectionId != 0 )
         {
             this.programStageSection = programStageSectionService.getProgramStageSection( this.programStageSectionId );
 
-            List<ProgramStageDataElement> listOfProgramStageDataElement = programStageSection
-                .getProgramStageDataElements();
-
-            dataElements = util.transformDataElementsToMobileModel( listOfProgramStageDataElement );
+            dataElements = programStageSection.getProgramStageDataElements();
         }
         else
         {
-            dataElements = util.transformDataElementsToMobileModel( programStageId );
+            dataElements = new ArrayList<ProgramStageDataElement>( programStage.getProgramStageDataElements() );
         }
 
-        int defaultCategoryOptionId = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo().getId();
         HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
             ServletActionContext.HTTP_REQUEST );
         Map<String, String> parameterMap = ContextUtils.getParameterMap( request );
 
-        List<DataValue> dataValues = new ArrayList<DataValue>();
+        // List<DataValue> dataValues = new ArrayList<DataValue>();
 
         typeViolations.clear();
         prevDataValues.clear();
@@ -480,13 +466,12 @@
             if ( key.startsWith( "DE" ) )
             {
                 Integer dataElementId = Integer.parseInt( key.substring( 2, key.length() ) );
-                // Integer categoryOptComboId = Integer.parseInt( splitKey[1] );
                 String value = parameterMap.get( key );
 
-                // validate types
                 org.hisp.dhis.dataelement.DataElement dataElement = dataElementService.getDataElement( dataElementId );
                 ProgramStageDataElement programStageDataElement = programStageDataElementService.get( dhisProgramStage,
                     dataElement );
+
                 value = value.trim();
                 Boolean valueIsEmpty = (value == null || value.length() == 0);
 
@@ -498,23 +483,26 @@
                     {
                         typeViolations.put( key, typeViolation );
                     }
-
-                    prevDataValues.put( key, value );
                 }
                 else if ( valueIsEmpty && programStageDataElement.isCompulsory() )
                 {
                     typeViolations.put( key, "is_empty" );
-                    prevDataValues.put( key, value );
-                }
-
-                // build dataValue for activity value
-                DataValue dataValue = new DataValue();
-                dataValue.setId( dataElementId );
-                dataValue.setValue( value );
-
-                dataValue.setCategoryOptComboID( defaultCategoryOptionId );
-
-                dataValues.add( dataValue );
+                }
+
+                prevDataValues.put( key, value );
+                prevDataValues.put( "CB" + dataElement.getId(), parameterMap.get( "CB" + dataElement.getId() ) );
+                
+                // build patient data value
+                PatientDataValue patientDataValue = new PatientDataValue( programStageInstance, dataElement,
+                    new Date(), value );
+                String providedElseWhereValue = parameterMap.get( "CB" + dataElementId );
+
+                if ( providedElseWhereValue != null )
+                {
+                    patientDataValue.setProvidedElsewhere( Boolean.parseBoolean( providedElseWhereValue ) );
+                }
+
+                patientDataValues.add( patientDataValue );
             }
         }
 
@@ -525,23 +513,9 @@
         }
 
         // Save patient data value
-        ActivityValue activityValue = new ActivityValue();
-        activityValue.setDataValues( dataValues );
-        activityValue.setProgramInstanceId( programStageInstanceId );
-
-        try
-        {
-            activityReportingService.saveActivityReport( organisationUnit, activityValue, programStageSectionId );
-        }
-        catch ( NotAllowedException e )
-        {
-            e.printStackTrace();
-            return ERROR;
-        }
+        this.savePatientDataValues( patientDataValues, programStageInstance );
 
         // Check validation rule
-        ProgramStageInstance programStageInstance = programStageInstanceService
-            .getProgramStageInstance( programStageInstanceId );
         this.runProgramValidation(
             programValidationService.getProgramValidation( programStageInstance.getProgramStage() ),
             programStageInstance );
@@ -573,11 +547,38 @@
         }
     }
 
+    private void savePatientDataValues( List<PatientDataValue> patientDataValues,
+        ProgramStageInstance programStageInstance )
+    {
+        for ( PatientDataValue patientDataValue : patientDataValues )
+        {
+            PatientDataValue previousPatientDataValue = patientDataValueService.getPatientDataValue(
+                patientDataValue.getProgramStageInstance(), patientDataValue.getDataElement() );
+
+            if ( previousPatientDataValue == null )
+            {
+                patientDataValueService.savePatientDataValue( patientDataValue );
+            }
+            else
+            {
+                previousPatientDataValue.setValue( patientDataValue.getValue() );
+                previousPatientDataValue.setTimestamp( new Date() );
+                previousPatientDataValue.setProvidedElsewhere( patientDataValue.getProvidedElsewhere() );
+                patientDataValueService.updatePatientDataValue( previousPatientDataValue );
+            }
+
+        }
+
+        programStageInstance.setCompleted( true );
+        programStageInstanceService.updateProgramStageInstance( programStageInstance );
+
+    }
+
     private void runProgramValidation( Collection<ProgramValidation> validations,
         ProgramStageInstance programStageInstance )
     {
         programValidationResults = new ArrayList<ProgramValidationResult>();
-        
+
         if ( validations != null )
         {
             for ( ProgramValidation validation : validations )
@@ -588,12 +589,12 @@
                 if ( validationResult != null )
                 {
                     programValidationResults.add( validationResult );
-                    
+
                     leftsideFormulaMap.put(
                         validationResult.getProgramValidation().getId(),
                         programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
                             .getLeftSide().getExpression() ) );
-                    
+
                     rightsideFormulaMap.put(
                         validationResult.getProgramValidation().getId(),
                         programExpressionService.getExpressionDescription( validationResult.getProgramValidation()
@@ -601,6 +602,6 @@
                 }
             }
         }
-        
+
     }
 }

=== 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-11-13 04:26:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2012-11-15 06:17:43 +0000
@@ -198,8 +198,6 @@
 		class="org.hisp.dhis.light.namebaseddataentry.action.SaveProgramStageFormAction">
 		<property name="organisationUnitService"
 			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-		<property name="activityReportingService"
-			ref="org.hisp.dhis.mobile.api.ActivityReportingService" />
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
 		<property name="util" ref="org.hisp.dhis.light.utils.NamebasedUtils" />
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
@@ -211,6 +209,7 @@
 		<property name="programValidationService" ref="org.hisp.dhis.program.ProgramValidationService" />
 		<property name="programStageSectionService" ref="org.hisp.dhis.program.ProgramStageSectionService"/>
 		<property name="programExpressionService" ref="org.hisp.dhis.program.ProgramExpressionService" />
+		<property name="patientDataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
 
 	</bean>
 

=== 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-10-29 03:48:40 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2012-11-15 06:17:43 +0000
@@ -126,4 +126,5 @@
 or_register_new_person=or register new person
 invalid_phone_number=invalid phone number
 save_any_way=Save anyway
-form_in_complete= Form InComplete
\ No newline at end of file
+form_in_complete= Form InComplete
+allow_provided_elsewhere= Provided elsewhere
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/completedProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/completedProgramStageForm.vm	2012-09-27 04:28:53 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/completedProgramStageForm.vm	2012-11-15 06:17:43 +0000
@@ -22,17 +22,15 @@
 
 <div class="header-box" align="center">
 	<p style="text-align: left;">
-		#foreach( $dataElement in $dataElements)
-			#if( $dataElement.shortName )
-				#set( $dataElementName = $dataElement.shortName )
-			#else
-				#set( $dataElementName = $dataElement.name )
-			#end
+		#foreach( $programStageDataElement in $dataElements)
+			#set( $dataElement = $programStageDataElement.getDataElement())
+			#set( $key = "DE${dataElement.id}" )
+			#set( $dataElementName = $dataElement.getFormNameFallback() )
+			
 				#if (! $dataElement.getOptionSet())			
-					#set( $categoryOptionCombo = $dataElement.getCategoryOptionCombos().getModels().get( 0 ) )
 					#set( $key = "DE${dataElement.id}" )
 
-					<label>$encoder.htmlEncode( $dataElementName ) #if( $categoryOptionCombo.name!="(default)")$encoder.htmlEncode( $categoryOptionCombo.name )#end 
+					<label>$encoder.htmlEncode( $dataElementName ) 
 					#if($dataElement.type=="date") [yyyy-MM-dd] #end
 					</label>
 					
@@ -98,6 +96,14 @@
 					
 					</select>
 				#end
+
+				#if( $programStage.program.displayProvidedOtherFacility == 'true' && $programStageDataElement.allowProvidedElsewhere == 'true')
+				#set( $providedKey = "CB${dataElement.id}" )
+					<label>$i18n.getString( "allow_provided_elsewhere" ) $prevDataValues.get($providedKey)</label>
+					<input class='provided-elsewhere' name="CB$dataElement.id" value="true" type="checkbox" #if($prevDataValues.get($providedKey) == 'true') checked #end disabled />
+				#end
+				
+				
 		#end
 				
 	</p>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm	2012-11-13 04:26:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/programStageForm.vm	2012-11-15 06:17:43 +0000
@@ -39,16 +39,13 @@
 <div class="header-box" align="center">
 	<p style="text-align: left;">
 
-		#foreach( $dataElement in $dataElements)
+		#foreach( $programStageDataElement in $dataElements)
+			#set( $dataElement = $programStageDataElement.getDataElement())
 			#set( $key = "DE${dataElement.id}" )
-			#if( $dataElement.shortName )
-				#set( $dataElementName = $dataElement.shortName )
-			#else
-				#set( $dataElementName = $dataElement.name )
-			#end
+			#set( $dataElementName = $dataElement.getFormNameFallback() )
 
 			<label>$encoder.htmlEncode( $dataElementName )
-					#if($dataElement.isCompulsory())*#end
+					#if($programStageDataElement.isCompulsory())*#end
 					#if($dataElement.type=="date") [yyyy-MM-dd] #end
 			</label>
 			
@@ -93,14 +90,11 @@
 				
 			#end
 			
-			#if( $programStage.program.displayProvidedOtherFacility=='true' )
-				#foreach( $programStageDataElement in $listOfProgramStageDataElement )
-				#if( $programStageDataElement.allowProvidedElsewhere == 'true' && $programStageDataElement.dataElement.id == $dataElement.id )
-					<input class='provided-elsewhere' name="$id" id="$id" type="checkbox" onclick="updateProvidingFacility( $programStageDataElement.dataElement.id, this )" #if($patientDataValue.providedElsewhere == 'true') checked #end />
-				#end
-				#end
+			#if( $programStage.program.displayProvidedOtherFacility == 'true' && $programStageDataElement.allowProvidedElsewhere == 'true')
+			#set( $providedKey = "CB${dataElement.id}" )
+				<label>$i18n.getString( "allow_provided_elsewhere" ) $prevDataValues.get($providedKey)</label>
+				<input class='provided-elsewhere' name="CB$dataElement.id" value="true" type="checkbox" #if($prevDataValues.get($providedKey) == 'true') checked #end />
 			#end
-			
 		#end
 
 	</p>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/selectProgramStageSection.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/selectProgramStageSection.vm	2012-10-23 07:56:15 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/namebased/selectProgramStageSection.vm	2012-11-15 06:17:43 +0000
@@ -17,9 +17,17 @@
 <h2>$i18n.getString( "sections" )</h2>
 <div>
 	<ul>
-	#foreach( $each in $listOfProgramStageSections )
-		<li><a href="showProgramStageForm.action?programStageSectionId=$each.Id&programId=$programId&programStageId=$programStageInstance.getProgramStage().getId()&programStageInstanceId=$programStageInstance.getId()&patientId=$patient.getId()&programInstanceId=$programStageInstance.getProgramInstance().getId()&orgUnitId=0">$each.name</a></li>
+	#if ($programStageInstance.isCompleted() == true)
+		#foreach( $each in $listOfProgramStageSections )
+			<li><a href="showCompletedProgramStageForm.action?programStageSectionId=$each.Id&programId=$programId&programStageId=$programStageInstance.getProgramStage().getId()&programStageInstanceId=$programStageInstance.getId()&patientId=$patient.getId()&programInstanceId=$programStageInstance.getProgramInstance().getId()&orgUnitId=0">$each.name</a></li>
+		#end
+	#else
+		#foreach( $each in $listOfProgramStageSections )
+			<li><a href="showProgramStageForm.action?programStageSectionId=$each.Id&programId=$programId&programStageId=$programStageInstance.getProgramStage().getId()&programStageInstanceId=$programStageInstance.getId()&patientId=$patient.getId()&programInstanceId=$programStageInstance.getProgramInstance().getId()&orgUnitId=0">$each.name</a></li>
+		#end
 	#end
+		
+	
 	</ul>
 </div>