← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2168: Fix bug: Cannot import information of patients from Excel file.

 

------------------------------------------------------------
revno: 2168
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-11-25 15:51:07 +0700
message:
  Fix bug: Cannot import information of patients from Excel file.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/ImportPatientAction.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-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/ImportPatientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/ImportPatientAction.java	2010-11-16 07:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/ImportPatientAction.java	2010-11-25 08:51:07 +0000
@@ -342,6 +342,8 @@
 
                 for ( XMLItem xmlItem : itemProperty )
                 {
+                    sheet = wb.getSheetAt( xmlItem.getSheet() );
+                    
                     value = readValue( row, xmlItem.getColumn(), sheet );
 
                     // ---------------------------------------------------------
@@ -575,15 +577,33 @@
                         ProgramStageInstance stageInstance = programStageInstanceService.getProgramStageInstance(
                             programInstance, stage );
 
-                        PatientDataValue dataValue = new PatientDataValue();
-                        dataValue.setDataElement( dataElement );
-                        dataValue.setOptionCombo( optionCombo );
-                        dataValue.setOrganisationUnit( orgunit );
-                        dataValue.setProgramStageInstance( stageInstance );
-                        dataValue.setTimestamp( new Date() );
-                        dataValue.setValue( value );
-
-                        patientDataValueService.savePatientDataValue( dataValue );
+                        PatientDataValue dataValue = patientDataValueService.getPatientDataValue( stageInstance,
+                            dataElement, orgunit );
+                        if ( dataValue == null )
+                        {
+                            dataValue = new PatientDataValue();
+
+                            dataValue.setDataElement( dataElement );
+                            dataValue.setOptionCombo( optionCombo );
+                            dataValue.setOrganisationUnit( orgunit );
+                            dataValue.setProgramStageInstance( stageInstance );
+                            dataValue.setTimestamp( new Date() );
+                            dataValue.setValue( value );
+
+                            patientDataValueService.savePatientDataValue( dataValue );
+                        }
+                        else
+                        {
+
+                            // dataValue.setDataElement(dataElement);
+                            // dataValue.setOptionCombo(optionCombo);
+                            // dataValue.setOrganisationUnit(orgunit);
+                            // dataValue.setProgramStageInstance(stageInstance);
+                            dataValue.setTimestamp( new Date() );
+                            dataValue.setValue( value );
+
+                            patientDataValueService.updatePatientDataValue( dataValue );
+                        }
                     }
 
                 }
@@ -782,7 +802,7 @@
         throws Exception
     {
         Type type = Patient.class.getMethod( "get" + StringUtils.capitalize( property ) ).getReturnType();
-
+       
         // Get value
         if ( type == Integer.class || type == Integer.TYPE )
         {
@@ -811,5 +831,6 @@
         {
             Patient.class.getMethod( "set" + StringUtils.capitalize( property ), String.class ).invoke( patient, value );
         }
+        
     }
 }