← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6227: (patient) Put data values of each program-stage into a table in patient history form.

 

------------------------------------------------------------
revno: 6227
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-03-09 10:20:39 +0700
message:
  (patient) Put data values of each program-stage into a table in patient history form.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientHistory.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/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-03-08 04:56:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java	2012-03-09 03:20:39 +0000
@@ -95,5 +95,5 @@
 
     int countProgramStageInstances( ProgramStage programStage, Map<Integer,String> searchingKeys, Collection<Integer> orgunitIds, Date startDate, Date endDate );
     
-    Grid getProgramInstanceReport( ProgramInstance programInstance, I18nFormat format, I18n i18n );
+    List<Grid> getProgramStageInstancesReport( ProgramInstance programInstance, I18nFormat format, I18n i18n );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2012-03-08 04:56:36 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java	2012-03-09 03:20:39 +0000
@@ -82,7 +82,6 @@
     // Implementation methods
     // -------------------------------------------------------------------------
 
- 
     public int addProgramInstance( ProgramInstance programInstance )
     {
         return programInstanceStore.save( programInstance );
@@ -201,7 +200,8 @@
 
         attrGrid.addHeader( new GridHeader( i18n.getString( "name" ), false, false ) );
         attrGrid.addHeader( new GridHeader( i18n.getString( "value" ), false, false ) );
-
+        attrGrid.addHeader( new GridHeader( "", true, false ) );
+        
         Collection<PatientAttribute> patientAttributes = patient.getAttributes();
 
         // ---------------------------------------------------------------------
@@ -215,15 +215,15 @@
         attrGrid.addRow();
         attrGrid.addValue( i18n.getString( "age" ) );
         attrGrid.addValue( patient.getAge() );
-        
+
         attrGrid.addRow();
         attrGrid.addValue( i18n.getString( "dob_type" ) );
         attrGrid.addValue( i18n.getString( patient.getDobType() + "" ) );
-        
+
         attrGrid.addRow();
         attrGrid.addValue( i18n.getString( "blood_group" ) );
         attrGrid.addValue( i18n.getString( patient.getBloodGroup() ) );
-        
+
         // ---------------------------------------------------------------------
         // Add dynamic attribues
         // ---------------------------------------------------------------------
@@ -244,7 +244,7 @@
         for ( PatientIdentifier identifier : patient.getIdentifiers() )
         {
             attrGrid.addRow();
-            
+
             PatientIdentifierType idType = identifier.getIdentifierType();
             if ( idType != null )
             {
@@ -257,9 +257,9 @@
                 attrGrid.addValue( identifier.getIdentifier() );
             }
         }
-        
+
         grids.add( attrGrid );
-        
+
         // ---------------------------------------------------------------------
         // Get all program data registered
         // ---------------------------------------------------------------------
@@ -270,8 +270,39 @@
         {
             for ( ProgramInstance programInstance : programInstances )
             {
-                Grid programGrid = programStageInstanceService.getProgramInstanceReport( programInstance, format, i18n );
-                grids.add( programGrid );
+                Grid gridProgram = new ListGrid();
+                gridProgram.setTitle( programInstance.getProgram().getName() );
+                gridProgram.setSubtitle( "" );
+                
+                // ---------------------------------------------------------------------
+                // Headers
+                // ---------------------------------------------------------------------
+
+                gridProgram.addHeader( new GridHeader( i18n.getString( "name" ), false, false ) );
+                gridProgram.addHeader( new GridHeader( i18n.getString( "value" ), false, false ) );
+                gridProgram.addHeader( new GridHeader( "", true, false ) );
+                
+                // ---------------------------------------------------------------------
+                // Values
+                // ---------------------------------------------------------------------
+
+                gridProgram.addRow();
+                gridProgram.addValue( i18n.getString( "date_of_enrollment" ) );
+                gridProgram.addValue( format.formatDate( programInstance.getEnrollmentDate() ) );
+
+                gridProgram.addRow();
+                gridProgram.addValue( i18n.getString( "date_of_incident" ) );
+                gridProgram.addValue( format.formatDate( programInstance.getDateOfIncident() ) );
+
+                grids.add( gridProgram );
+
+                // ---------------------------------------------------------------------
+                // Grids for program-stage-instance
+                // ---------------------------------------------------------------------
+
+                List<Grid> programInstanceGrids = programStageInstanceService.getProgramStageInstancesReport(
+                    programInstance, format, i18n );
+                grids.addAll( programInstanceGrids );
             }
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-03-09 01:56:35 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java	2012-03-09 03:20:39 +0000
@@ -27,15 +27,12 @@
 package org.hisp.dhis.program;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
@@ -75,13 +72,6 @@
         this.patientDataValueService = patientDataValueService;
     }
 
-    private ProgramStageDataElementService programStageDataElementService;
-
-    public void setProgramStageDataElementService( ProgramStageDataElementService programStageDataElementService )
-    {
-        this.programStageDataElementService = programStageDataElementService;
-    }
-
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
@@ -236,83 +226,71 @@
         return programStageInstanceStore.count( programStage, searchingKeys, orgunitIds, startDate, endDate );
     }
 
-    public Grid getProgramInstanceReport( ProgramInstance programInstance, I18nFormat format, I18n i18n )
+    public List<Grid> getProgramStageInstancesReport( ProgramInstance programInstance, I18nFormat format, I18n i18n )
     {
-        Grid grid = new ListGrid();
-
-        // ---------------------------------------------------------------------
-        // Title
-        // ---------------------------------------------------------------------
-
-        grid.setTitle( programInstance.getProgram().getName() );
-        grid.setSubtitle( i18n.getString( "date_of_enrollment" ) + ": "
-            + format.formatDate( programInstance.getEnrollmentDate() ) + " - " + i18n.getString( "date_of_incident" )
-            + ": " + format.formatDate( programInstance.getDateOfIncident() ) );
-
-        // ---------------------------------------------------------------------
-        // Headers && Get dataelements belongs to programs
-        // ---------------------------------------------------------------------
-
-        Set<ProgramStage> programStages = programInstance.getProgram().getProgramStages();
-        Set<DataElement> dataElements = new HashSet<DataElement>();
-
-        grid.addHeader( new GridHeader( "", false, false ) );
-        for ( ProgramStage programStage : programStages )
-        {
-            grid.addHeader( new GridHeader( programStage.getName(), false, false ) );
-            dataElements.addAll( programStageDataElementService.getListDataElement( programStage ) );
-        }
-
-        // ---------------------------------------------------------------------
-        // First Column
-        // ---------------------------------------------------------------------
-
-        List<Object> deValues = new ArrayList<Object>();
-        Map<Integer, Integer> mapDataElements = new HashMap<Integer, Integer>();
-
-        int columnIndex = 0;
-        for ( DataElement dataElement : dataElements )
-        {
-            grid.addRow();
-            deValues.add( dataElement.getName() );
-
-            mapDataElements.put( dataElement.getId(), columnIndex );
-            columnIndex++;
-        }
-
-        grid.addColumn( deValues );
-
-        // ---------------------------------------------------------------------
-        // Values
-        // ---------------------------------------------------------------------
+        List<Grid> grids = new ArrayList<Grid>();
 
         Collection<ProgramStageInstance> programStageInstances = programInstance.getProgramStageInstances();
 
         for ( ProgramStageInstance programStageInstance : programStageInstances )
         {
-            Object[] columnValues = new Object[dataElements.size()];
-
+            Grid grid = new ListGrid();
+
+            // ---------------------------------------------------------------------
+            // Title
+            // ---------------------------------------------------------------------
+            Date executionDate = programStageInstance.getExecutionDate();
+            String executionDateValue = (executionDate != null) ? format.formatDate( programStageInstance
+                .getExecutionDate() ) : "[" + i18n.getString( "none" ) + "]";
+
+            grid.setTitle( programStageInstance.getProgramStage().getName() );
+            grid.setSubtitle( i18n.getString( "due_date" ) + ": "
+                + format.formatDate( programStageInstance.getDueDate() ) + " - " + i18n.getString( "report_date" )
+                + ": " + executionDateValue );
+
+            // ---------------------------------------------------------------------
+            // Headers
+            // ---------------------------------------------------------------------
+
+            grid.addHeader( new GridHeader( i18n.getString( "name" ), false, false ) );
+            grid.addHeader( new GridHeader( i18n.getString( "value" ), false, false ) );
+
+            // ---------------------------------------------------------------------
+            // Values
+            // ---------------------------------------------------------------------
             Collection<PatientDataValue> patientDataValues = patientDataValueService
                 .getPatientDataValues( programStageInstance );
 
-            for ( PatientDataValue patientDataValue : patientDataValues )
-            {
-                DataElement dataElement = patientDataValue.getDataElement();
-
-                String value = patientDataValue.getValue();
-
-                if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
+            if ( executionDate == null || patientDataValues == null || patientDataValues.size() == 0 )
+            {
+                grid.addRow();
+                grid.addValue( "[" + i18n.getString( "none" ) + "]" );
+                grid.addValue( "" );
+            }
+            else
+            {
+                for ( PatientDataValue patientDataValue : patientDataValues )
                 {
-                    value = i18n.getString( patientDataValue.getValue() );
+                    DataElement dataElement = patientDataValue.getDataElement();
+
+                    grid.addRow();
+                    grid.addValue( dataElement.getName() );
+
+                    if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
+                    {
+                        grid.addValue( i18n.getString( patientDataValue.getValue() ) );
+                    }
+                    else
+                    {
+                        grid.addValue( patientDataValue.getValue() );
+                    }
                 }
-
-                columnValues[mapDataElements.get( dataElement.getId() )] = value;
             }
 
-            grid.addColumn( Arrays.asList( columnValues ) );
+            grids.add( grid );
         }
 
-        return grid;
+        return grids;
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-03-08 04:56:36 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-03-09 03:20:39 +0000
@@ -210,8 +210,6 @@
 			ref="org.hisp.dhis.program.ProgramStageInstanceStore" />
 		<property name="patientDataValueService"
 			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
-		<property name="programStageDataElementService"
-			ref="org.hisp.dhis.program.ProgramStageDataElementService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.program.ProgramInstanceService" class="org.hisp.dhis.program.DefaultProgramInstanceService">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientHistory.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientHistory.vm	2012-03-08 04:56:36 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientHistory.vm	2012-03-09 03:20:39 +0000
@@ -5,39 +5,41 @@
 <input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportPatientHistory( '$patient.id', 'xls' )" style="width:140px">
 <input type="button" value="$i18n.getString( 'get_report_as_pdf' )" onclick="exportPatientHistory( '$patient.id', 'pdf' )" style="width:140px">
 </div>
-
+<div>
 #foreach( $grid in $grids )
-	<div class="formSection" style="margin-bottom:30px">
-		<div class="cent">
-			<h3>$!encoder.htmlEncode( $grid.title )</h3>
-			<h4>$!encoder.htmlEncode( $grid.subtitle )</h4>
-		</div>
-		<table class="listTable">
-			<thead>
-				<tr>
-				#foreach( $header in $grid.getVisibleHeaders() )
-					<th #if( $header.meta )style="text-align:left"#end>$!encoder.htmlEncode( $header.name )</th>
-				#end
-				</tr>
-			</thead>
+	#if( $grid.getHeaders().size() == 3 )
+		</div><div class="formSection" style="margin-bottom:30px">
+	#end
+	
+	<div class="cent">
+		<h3>$!encoder.htmlEncode( $grid.title )</h3>
+		<h4>$!encoder.htmlEncode( $!grid.subtitle )</h4>
+	</div>
+	<table class="listTable">
+		<thead>
+			<tr>
+			#foreach( $header in $grid.getVisibleHeaders() )
+				<th #if( $header.meta )style="text-align:left"#end>$!encoder.htmlEncode( $header.name )</th>
+			#end
+			</tr>
+		</thead>
 
-			<tbody>  
-				#set( $mark = false )
-				#foreach( $row in $grid.getVisibleRows() )
-				<tr #alternate($mark)>
-					#set( $nameCol='false' )
-					#foreach( $col in $row )
-						#set( $index = ( $velocityCount - 1 ) )
-						#if( $grid.getVisibleHeaders().get( $index ).meta )
-							<td >$!encoder.htmlEncode( $col )</td>
-						#else 
-							<td>$!col</td>
-						#end
+		<tbody>  
+			#set( $mark = false )
+			#foreach( $row in $grid.getVisibleRows() )
+			<tr #alternate($mark)>
+				#set( $nameCol='false' )
+				#foreach( $col in $row )
+					#set( $index = ( $velocityCount - 1 ) )
+					#if( $grid.getVisibleHeaders().get( $index ).meta )
+						<td >$!encoder.htmlEncode( $col )</td>
+					#else 
+						<td>$!col</td>
 					#end
-				</tr>
 				#end
-				#set( $mark = !$mark)
-			</tbody>
-		</table>
-	</div>
+			</tr>
+			#end
+			#set( $mark = !$mark)
+		</tbody>
+	</table>
 #end