← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2068: Add function 'Import patients from Excel file'.

 

------------------------------------------------------------
revno: 2068
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2010-11-16 12:45:36 +0700
message:
  Add function 'Import patients from Excel file'.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/GetPatientExcelItemplateFileAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/SetPatientExcelItemplateFileAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/
  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/UploadExcelFileAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/XMLItem.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/configurationParams.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientParams.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientResult.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/import.js
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/pom.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  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/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/index.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatient.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/menu.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/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2010-11-16 05:45:36 +0000
@@ -44,14 +44,15 @@
     implements Serializable
 {
     public static final String MALE = "M";
+
     public static final String FEMALE = "F";
-    
 
     public static final char DOB_TYPE_VERIFIED = 'V';
+
     public static final char DOB_TYPE_DECLARED = 'D';
+
     public static final char DOB_TYPE_APPROXIATED = 'A';
 
-
     private Integer id;
 
     private String firstName;
@@ -121,30 +122,62 @@
     @Override
     public int hashCode()
     {
-        return id.hashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
+        result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
+        result = prime * result + ((gender == null) ? 0 : gender.hashCode());
+        result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
+        result = prime * result + ((middleName == null) ? 0 : middleName.hashCode());
+        return result;
     }
 
     @Override
-    public boolean equals( Object o )
+    public boolean equals( Object obj )
     {
-        if ( this == o )
-        {
+        if ( this == obj )
             return true;
-        }
-
-        if ( o == null )
-        {
-            return false;
-        }
-
-        if ( !(o instanceof Patient) )
-        {
-            return false;
-        }
-
-        final Patient other = (Patient) o;
-
-        return id.equals( other.getId() );
+        if ( obj == null )
+            return false;
+        if ( getClass() != obj.getClass() )
+            return false;
+        Patient other = (Patient) obj;
+        if ( birthDate == null )
+        {
+            if ( other.birthDate != null )
+                return false;
+        }
+        else if ( !birthDate.equals( other.birthDate ) )
+            return false;
+        if ( firstName == null )
+        {
+            if ( other.firstName != null )
+                return false;
+        }
+        else if ( !firstName.equals( other.firstName ) )
+            return false;
+        if ( gender == null )
+        {
+            if ( other.gender != null )
+                return false;
+        }
+        else if ( !gender.equals( other.gender ) )
+            return false;
+        if ( lastName == null )
+        {
+            if ( other.lastName != null )
+                return false;
+        }
+        else if ( !lastName.equals( other.lastName ) )
+            return false;
+        if ( middleName == null )
+        {
+            if ( other.middleName != null )
+                return false;
+        }
+        else if ( !middleName.equals( other.middleName ) )
+            return false;
+        return true;
     }
 
     // -------------------------------------------------------------------------
@@ -366,14 +399,19 @@
         // Assumed relative to the 1st of January
         // todayCalendar.set( Calendar.DATE, 1 );
         // todayCalendar.set( Calendar.MONTH, Calendar.JANUARY );
-        if(ageType == 'Y'){
+        if ( ageType == 'Y' )
+        {
             todayCalendar.add( Calendar.YEAR, -1 * age );
-        }else if(ageType == 'M'){
+        }
+        else if ( ageType == 'M' )
+        {
             todayCalendar.add( Calendar.MONTH, -1 * age );
-        }else if(ageType == 'D'){
+        }
+        else if ( ageType == 'D' )
+        {
             todayCalendar.add( Calendar.DATE, -1 * age );
         }
-        
+
         setBirthDate( todayCalendar.getTime() );
     }
 
@@ -421,12 +459,12 @@
     {
         switch ( dobType )
         {
-            case 'V':
-                return "Verified";
-            case 'D':
-                return "Declared";
-            default:
-                return "Approxiated";
+        case 'V':
+            return "Verified";
+        case 'D':
+            return "Declared";
+        default:
+            return "Approxiated";
         }
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/pom.xml	2010-08-20 09:13:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/pom.xml	2010-11-16 05:45:36 +0000
@@ -43,6 +43,14 @@
       <type>war</type>
     </dependency>
     
+	<!-- POI Library -->
+	
+	<dependency>
+		<groupId>org.apache.poi</groupId>
+		<artifactId>poi</artifactId>		
+		<version>3.5-FINAL</version>
+	</dependency>
+	
      <!-- Other -->
      
     <dependency>

=== added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration'
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/GetPatientExcelItemplateFileAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/GetPatientExcelItemplateFileAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/GetPatientExcelItemplateFileAction.java	2010-11-16 05:45:36 +0000
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2004-2010, 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.patient.action.configuration;
+
+import org.hisp.dhis.options.SystemSettingManager;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version GetPatientExcelItemplateFileAction.java Nov 12, 2010 1:46:51 PM
+ */
+public class GetPatientExcelItemplateFileAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SystemSettingManager systemSettingManager;
+
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter and Setter
+    // -------------------------------------------------------------------------
+
+    private String fileName;
+
+    public String getFileName()
+    {
+        return fileName;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        fileName = (String) systemSettingManager
+            .getSystemSetting( SystemSettingManager.KEY_PATIENT_EXCEL_TEMPLATE_FILE_NAME );
+
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/SetPatientExcelItemplateFileAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/SetPatientExcelItemplateFileAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/configuration/SetPatientExcelItemplateFileAction.java	2010-11-16 05:45:36 +0000
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2004-2010, 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.patient.action.configuration;
+
+import org.hisp.dhis.options.SystemSettingManager;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version SetPatientExcelItemplateFileAction.java Nov 12, 2010 1:41:23 PM
+ */
+public class SetPatientExcelItemplateFileAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SystemSettingManager systemSettingManager;
+
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getter and Setter
+    // -------------------------------------------------------------------------
+
+    private String fileName;
+
+    public void setFileName( String fileName )
+    {
+        this.fileName = fileName;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation Action
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        systemSettingManager.saveSystemSetting( SystemSettingManager.KEY_PATIENT_EXCEL_TEMPLATE_FILE_NAME, fileName );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java	2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientidentifiertype/UpdatePatientIdentifierTypeAction.java	2010-11-16 05:45:36 +0000
@@ -71,8 +71,6 @@
     public String execute()
         throws Exception
     {
-        
-        
         PatientIdentifierType identifierType = patientIdentifierTypeService.getPatientIdentifierType( id );
         if( identifierType != null )
         {

=== added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport'
=== added 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	1970-01-01 00:00:00 +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-16 05:45:36 +0000
@@ -0,0 +1,810 @@
+/*
+ * Copyright (c) 2004-2010, 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.patient.action.patientimport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.options.SystemSettingManager;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeOption;
+import org.hisp.dhis.patient.PatientAttributeOptionService;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patient.PatientIdentifier;
+import org.hisp.dhis.patient.PatientIdentifierService;
+import org.hisp.dhis.patient.PatientIdentifierType;
+import org.hisp.dhis.patient.PatientIdentifierTypeService;
+import org.hisp.dhis.patient.PatientService;
+import org.hisp.dhis.patient.idgen.PatientIdentifierGenerator;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.system.util.DateUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ImportPatientAction.java Nov 12, 2010 12:45:57 PM
+ */
+public class ImportPatientAction
+    implements Action
+{
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PatientService patientService;
+
+    private PatientIdentifierService patientIdentifierService;
+
+    private PatientIdentifierTypeService patientIdentifierTypeService;
+
+    private PatientAttributeService patientAttributeService;
+
+    private PatientAttributeOptionService patientAttributeOptionService;
+
+    private PatientAttributeValueService patientAttributeValueService;
+
+    private ProgramService programService;
+
+    private ProgramStageService programStageService;
+
+    private ProgramInstanceService programInstanceService;
+
+    private ProgramStageInstanceService programStageInstanceService;
+
+    private DataElementService dataElementService;
+
+    private PatientDataValueService patientDataValueService;
+
+    private SystemSettingManager systemSettingManager;
+
+    private OrganisationUnitService organisationUnitService;
+
+    private I18nFormat format;
+
+    private I18n i18n;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private File output;
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private HashMap<Integer, Patient> errPatients = new HashMap<Integer, Patient>();
+
+    private HashMap<Integer, String> errMessage = new HashMap<Integer, String>();
+
+    // -------------------------------------------------------------------------
+    // Private Parameters
+    // -------------------------------------------------------------------------
+
+    private XMLItem xmlStartRow;
+
+    private XMLItem xmlEndRow;
+
+    private XMLItem xmlOrgunit;
+
+    private XMLItem xmlProgram;
+
+    private char ageType;
+
+    Collection<XMLItem> itemProperty = new HashSet<XMLItem>();
+
+    Collection<XMLItem> itemAttribute = new HashSet<XMLItem>();
+
+    Collection<XMLItem> itemEnrollProgram = new HashSet<XMLItem>();
+
+    Collection<XMLItem> itemProgramStage = new HashSet<XMLItem>();
+
+    // -------------------------------------------------------------------------
+    // Getters && Setters
+    // -------------------------------------------------------------------------
+
+    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+    {
+        this.programInstanceService = programInstanceService;
+    }
+
+    public void setPatientService( PatientService patientService )
+    {
+        this.patientService = patientService;
+    }
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService )
+    {
+        this.patientIdentifierService = patientIdentifierService;
+    }
+
+    public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService )
+    {
+        this.patientAttributeValueService = patientAttributeValueService;
+    }
+
+    public void setPatientDataValueService( PatientDataValueService patientDataValueService )
+    {
+        this.patientDataValueService = patientDataValueService;
+    }
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    public void setProgramStageService( ProgramStageService programStageService )
+    {
+        this.programStageService = programStageService;
+    }
+
+    public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService )
+    {
+        this.patientIdentifierTypeService = patientIdentifierTypeService;
+    }
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
+    public void setPatientAttributeOptionService( PatientAttributeOptionService patientAttributeOptionService )
+    {
+        this.patientAttributeOptionService = patientAttributeOptionService;
+    }
+
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    public HashMap<Integer, Patient> getErrPatients()
+    {
+        return errPatients;
+    }
+    
+    public HashMap<Integer, String> getErrMessage()
+    {
+        return errMessage;
+    }
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    public File getOutput()
+    {
+        return output;
+    }
+
+    public void setOutput( File output )
+    {
+        this.output = output;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation Action
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        try
+        {
+            // -----------------------------------------------------------------
+            // Get excel-items from XML-template-file
+            // -----------------------------------------------------------------
+
+            readXMLTemplateFile();
+
+            // -----------------------------------------------------------------
+            // Get file which need to import information
+            // -----------------------------------------------------------------
+
+            FileInputStream inputStream = new FileInputStream( output );
+
+            HSSFWorkbook wb = new HSSFWorkbook( inputStream );
+
+            // -----------------------------------------------------------------
+            // Get common-information from XML-template-file
+            // -----------------------------------------------------------------
+
+            // Get organisation-unit
+            HSSFSheet sheet = wb.getSheetAt( xmlOrgunit.getSheet() );
+            String value = readValue( xmlOrgunit.getRow(), xmlOrgunit.getColumn(), sheet );
+            OrganisationUnit orgunit = organisationUnitService.getOrganisationUnit( Integer.parseInt( value ) );
+
+            // Get program
+            sheet = wb.getSheetAt( xmlProgram.getSheet() );
+            value = readValue( xmlProgram.getRow(), xmlProgram.getColumn(), sheet );
+            Program program = programService.getProgram( Integer.parseInt( value ) );
+
+            // Get startRow
+            sheet = wb.getSheetAt( xmlStartRow.getSheet() );
+            value = readValue( xmlStartRow.getRow(), xmlStartRow.getColumn(), sheet );
+            int startRow = Integer.parseInt( value ) - 1;
+
+            // get endRow
+            sheet = wb.getSheetAt( xmlEndRow.getSheet() );
+            value = readValue( xmlEndRow.getRow(), xmlEndRow.getColumn(), sheet );
+            int endRow = Integer.parseInt( value ) - 1;
+
+            // -----------------------------------------------------------------
+            // Import information
+            // -----------------------------------------------------------------
+
+            for ( int row = startRow; row <= endRow; row++ )
+            {
+                Patient patient = new Patient();
+                patient.setMiddleName( "" );
+                patient.setLastName( "" );
+                patient.setOrganisationUnit( orgunit );
+                patient.setOrganisationUnit( orgunit );
+                patient.setRegistrationDate( new Date() );
+                patient.setUnderAge( false );
+
+                // ---------------------------------------------------------
+                // Create Patient
+                // ---------------------------------------------------------
+
+                for ( XMLItem xmlItem : itemProperty )
+                {
+                    value = readValue( row, xmlItem.getColumn(), sheet );
+
+                    // ---------------------------------------------------------
+                    // Import identifier values
+                    // ---------------------------------------------------------
+
+                    if ( xmlItem.isType( XMLItem.IDENTIFIER_TYPE ) )
+                    {
+                        int objectId = Integer.parseInt( xmlItem.getValue() );
+                        PatientIdentifierType identifierType = patientIdentifierTypeService
+                            .getPatientIdentifierType( objectId );
+
+                        PatientIdentifier identifier = new PatientIdentifier();
+                        identifier.setIdentifierType( identifierType );
+                        identifier.setPatient( patient );
+                        identifier.setIdentifier( value.trim() );
+                        patient.getIdentifiers().add( identifier );
+                    }
+
+                    // ---------------------------------------------------------
+                    // Import property values
+                    // ---------------------------------------------------------
+                    else if ( xmlItem.isType( XMLItem.PROPERTY_TYPE ) )
+                    {
+                        if ( !value.isEmpty() )
+                        {
+                            if ( xmlItem.getValue().equalsIgnoreCase( XMLItem.BIRTH_DATE_FROM_VALUE ) )
+                            {
+                                patient.setBirthDateFromAge( Integer.parseInt( value ), ageType );
+                            }
+                            else
+                            {
+                                setObject( patient, xmlItem.getValue(), value );
+                            }
+                        }
+                    }
+                }
+
+                // -------------------------------------------------------------
+                // Generate system id with this format :
+                // (BirthDate)(Gender)(XXXXXX)(checkdigit)
+                // PatientIdentifierType will be null
+                // -------------------------------------------------------------
+
+                String systemIdentifier = PatientIdentifierGenerator.getNewIdentifier( patient.getBirthDate(), patient
+                    .getGender() );
+
+                PatientIdentifier systemGenerateIdentifier = patientIdentifierService.get( null, systemIdentifier );
+                while ( systemGenerateIdentifier != null )
+                {
+                    systemIdentifier = PatientIdentifierGenerator.getNewIdentifier( patient.getBirthDate(), patient
+                        .getGender() );
+                    systemGenerateIdentifier = patientIdentifierService.get( null, systemIdentifier );
+                }
+
+                systemGenerateIdentifier = new PatientIdentifier();
+                systemGenerateIdentifier.setIdentifier( systemIdentifier );
+                systemGenerateIdentifier.setPatient( patient );
+
+                patient.getIdentifiers().add( systemGenerateIdentifier );
+
+                if ( validatePatient( patient, row ) )
+                {
+                    // Save patient
+                    patientService.savePatient( patient );
+                }
+                else
+                {
+                    continue;
+                }
+
+                // -------------------------------------------------------------
+                // Import Information of Registration
+                // -------------------------------------------------------------
+
+                Set<PatientAttribute> attributes = new HashSet<PatientAttribute>();
+
+                for ( XMLItem xmlItem : itemAttribute )
+                {
+                    sheet = wb.getSheetAt( xmlItem.getSheet() );
+
+                    // ---------------------------------------------------------
+                    // Get value into Excel-file
+                    // ---------------------------------------------------------
+
+                    value = readValue( row, xmlItem.getColumn(), sheet );
+
+                    // ---------------------------------------------------------
+                    // Import attribute value
+                    // ---------------------------------------------------------
+
+                    int objectId = Integer.parseInt( xmlItem.getValue() );
+                    PatientAttribute attribute = patientAttributeService.getPatientAttribute( objectId );
+
+                    attributes.add( attribute );
+                    PatientAttributeValue attributeValue = new PatientAttributeValue();
+                    attributeValue.setPatient( patient );
+                    attributeValue.setPatientAttribute( attribute );
+
+                    // Attribute is combo-type
+                    if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) )
+                    {
+                        // value is the id of the option
+                        PatientAttributeOption option = patientAttributeOptionService.get( Integer.parseInt( value
+                            .split( ":" )[1] ) );
+
+                        if ( option != null )
+                        {
+                            attributeValue.setPatientAttributeOption( option );
+                            attributeValue.setValue( option.getName() );
+                        }
+                    }// end Attribute is combo-type
+                    else
+                    {
+                        attributeValue.setValue( value.trim() );
+                    }
+
+                    patientAttributeValueService.savePatientAttributeValue( attributeValue );
+
+                }
+
+                patient.setAttributes( attributes );
+                patientService.updatePatient( patient );
+
+                // -------------------------------------------------------------
+                // Import Information of EnrollProgram
+                // -------------------------------------------------------------
+
+                ProgramInstance programInstance = new ProgramInstance();
+
+                for ( XMLItem xmlItem : itemEnrollProgram )
+                {
+                    sheet = wb.getSheetAt( xmlItem.getSheet() );
+
+                    // Get value into Excel-file
+                    value = readValue( row, xmlItem.getColumn(), sheet );
+
+                    // ---------------------------------------------------------
+                    // Create programInstance
+                    // ---------------------------------------------------------
+
+                    Date date = format.parseDate( value );
+
+                    ProgramInstance.class.getMethod( "set" + StringUtils.capitalize( xmlItem.getValue() ), Date.class )
+                        .invoke( programInstance, date );
+
+                }
+
+                // -------------------------------------------------------------
+                // Enroll program
+                // -------------------------------------------------------------
+
+                programInstance.setProgram( program );
+                programInstance.setPatient( patient );
+                programInstance.setCompleted( false );
+
+                programInstanceService.addProgramInstance( programInstance );
+
+                patient.getPrograms().add( program );
+                patientService.updatePatient( patient );
+
+                for ( ProgramStage programStage : program.getProgramStages() )
+                {
+                    ProgramStageInstance programStageInstance = new ProgramStageInstance();
+                    programStageInstance.setProgramInstance( programInstance );
+                    programStageInstance.setProgramStage( programStage );
+                    programStageInstance.setStageInProgram( programStage.getStageInProgram() );
+
+                    Date dueDate = DateUtils.getDateAfterAddition( programInstance.getDateOfIncident(), programStage
+                        .getMinDaysFromStart() );
+
+                    programStageInstance.setDueDate( dueDate );
+
+                    programStageInstanceService.addProgramStageInstance( programStageInstance );
+                }
+
+                // -------------------------------------------------------------
+                // Import Information of EnrollProgram
+                // -------------------------------------------------------------
+
+                for ( XMLItem xmlItem : itemProgramStage )
+                {
+                    sheet = wb.getSheetAt( xmlItem.getSheet() );
+
+                    // Get value into Excel-file
+                    value = readValue( row, xmlItem.getColumn(), sheet );
+
+                    // ---------------------------------------------------------
+                    // Create PatientDataValue
+                    // ---------------------------------------------------------
+
+                    String[] infor = xmlItem.getValue().split( "\\." );
+
+                    ProgramStage stage = programStageService.getProgramStage( Integer.parseInt( infor[0] ) );
+
+                    DataElement dataElement = dataElementService.getDataElement( Integer.parseInt( infor[1] ) );
+
+                    int optionComboId = Integer.parseInt( infor[2] );
+                    DataElementCategoryOptionCombo optionCombo = null;
+
+                    if ( optionComboId == 0 )
+                    {
+                        String[] temp = value.trim().split( ":" );
+                        if ( temp.length == 2 )
+                        {
+                            optionComboId = Integer.parseInt( temp[1] );
+                        }
+                        else
+                        {
+                            value = (value.equalsIgnoreCase( "yes" )) ? "true" : "false";
+                            optionComboId = dataElement.getCategoryCombo().getOptionCombos().iterator().next().getId();
+                        }
+                    }
+
+                    Set<DataElementCategoryOptionCombo> options = dataElement.getCategoryCombo().getOptionCombos();
+                    if ( options != null && options.size() > 0 )
+                    {
+                        Iterator<DataElementCategoryOptionCombo> i = options.iterator();
+                        while ( i.hasNext() )
+                        {
+                            DataElementCategoryOptionCombo tmpOption = i.next();
+                            if ( tmpOption.getId() == optionComboId )
+                            {
+                                optionCombo = tmpOption;
+                            }
+                        }
+                    }
+
+                    if ( stage != null && dataElement != null && optionCombo != null )
+                    {
+                        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 );
+                    }
+
+                }
+
+            }
+
+        }
+        catch ( Exception ex )
+        {
+            ex.printStackTrace();
+        }
+
+        return SUCCESS;
+    }
+
+    // -------------------------------------------------------------------------
+    // Support methods
+    // -------------------------------------------------------------------------
+
+    private void readXMLTemplateFile()
+    {
+        // ---------------------------------------------------------------------
+        // Get template-file
+        // ---------------------------------------------------------------------
+
+        String fileName = (String) systemSettingManager
+            .getSystemSetting( SystemSettingManager.KEY_PATIENT_EXCEL_TEMPLATE_FILE_NAME );
+
+        if ( fileName == null )
+        {
+            return;
+        }
+
+        String path = System.getenv( "DHIS2_HOME" );
+
+        if ( path != null )
+        {
+            path += File.separator + File.separator + fileName;
+        }
+        else
+        {
+            path = System.getenv( "user.home" ) + File.separator + "dhis" + File.separator + fileName;
+        }
+
+        // ---------------------------------------------------------------------
+        // Get contents into template-file
+        // ---------------------------------------------------------------------
+
+        try
+        {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            Document doc = docBuilder.parse( new File( path ) );
+            if ( doc == null )
+            {
+                System.out.println( "There is no any definition related XML file in the user home" );
+
+                return;
+            }
+
+            NodeList cellNode = doc.getElementsByTagName( "cell" );
+
+            for ( int i = 0; i < cellNode.getLength(); i++ )
+            {
+                Element cellElement = (Element) cellNode.item( i );
+
+                XMLItem item = new XMLItem();
+
+                item.setValue( cellElement.getAttribute( "value" ) );
+
+                item.setType( cellElement.getAttribute( "type" ) );
+
+                item.setColumn( Integer.parseInt( cellElement.getAttribute( "colno" ) ) - 1 );
+
+                item.setRow( Integer.parseInt( cellElement.getAttribute( "rowno" ) ) - 1 );
+
+                item.setSheet( Integer.parseInt( cellElement.getAttribute( "sheetno" ) ) - 1 );
+
+                if ( item.isType( XMLItem.ORGUNIT_TYPE ) )
+                {
+                    xmlOrgunit = item;
+                }
+                else if ( item.isType( XMLItem.START_ROW_TYPE ) )
+                {
+                    xmlStartRow = item;
+                }
+                else if ( item.isType( XMLItem.END_ROW_TYPE ) )
+                {
+                    xmlEndRow = item;
+                }
+                else if ( item.isType( XMLItem.PROGRAM_TYPE ) )
+                {
+                    xmlProgram = item;
+                }
+                else if ( item.isType( XMLItem.AGE_TYPE ) )
+                {
+                    ageType = cellElement.getAttribute( "value" ).charAt( 0 );
+                }
+                else if ( item.isType( XMLItem.PROGRAM_ATTRIBUTE_TYPE ) )
+                {
+                    itemEnrollProgram.add( item );
+                }
+                else if ( item.isType( XMLItem.PROGRAM_STAGE_TYPE ) )
+                {
+                    itemProgramStage.add( item );
+                }
+                else if ( item.isType( XMLItem.ATTRIBUTE_TYPE ) )
+                {
+                    itemAttribute.add( item );
+                }
+                else
+                {
+                    itemProperty.add( item );
+                }
+            }
+
+        }
+        catch ( Exception t )
+        {
+            t.printStackTrace();
+        }
+
+    }
+
+    private boolean validatePatient( Patient patient, int row )
+    {
+        if ( patient.getFirstName() == null && patient.getMiddleName() == null && patient.getLastName() == null )
+        {
+            errPatients.put( row, patient );
+            errMessage.put( row, i18n.getString( "patient_name_is_null" ) );
+            return false;
+        }
+
+        if ( patient.getBirthDate() == null )
+        {
+            errPatients.put( row, patient );
+            errMessage.put( row, i18n.getString( "birthday_is_null" ) );
+            return false;
+        }
+
+        // Check duplication name, birthdate, gender
+        Collection<Patient> patients = patientService.getPatient( patient.getFirstName(), patient.getMiddleName(),
+            patient.getLastName(), patient.getBirthDate(), patient.getGender() );
+
+        if ( patients != null && patients.size() > 0 )
+        {
+            errPatients.put( row, patient );
+            errMessage.put( row, i18n.getString( "duplicate" ) );
+            return false;
+        }
+
+        return true;
+    }
+
+    private String readValue( int row, int column, Sheet sheet )
+    {
+        Cell cell = sheet.getRow( row ).getCell( column );
+
+        String value = "";
+
+        if ( cell != null )
+        {
+            switch ( cell.getCellType() )
+            {
+            case Cell.CELL_TYPE_NUMERIC:
+
+                if ( HSSFDateUtil.isCellDateFormatted( cell ) )
+                {
+                    value = format.formatDate( cell.getDateCellValue() );
+                }
+                else
+                {
+                    value = String.valueOf( Math.round( cell.getNumericCellValue() ) );
+                }
+                break;
+
+            case Cell.CELL_TYPE_BOOLEAN:
+                value = String.valueOf( cell.getBooleanCellValue() );
+                break;
+
+            case Cell.CELL_TYPE_FORMULA:
+                value = cell.getCellFormula();
+                break;
+
+            case Cell.CELL_TYPE_STRING:
+                value = cell.getRichStringCellValue().toString();
+                break;
+            }
+        }
+
+        return value;
+
+    }
+
+    private void setObject( Patient patient, String property, String value )
+        throws Exception
+    {
+        Type type = Patient.class.getMethod( "get" + StringUtils.capitalize( property ) ).getReturnType();
+
+        // Get value
+        if ( type == Integer.class || type == Integer.TYPE )
+        {
+            Integer object = Integer.valueOf( value );
+            Patient.class.getMethod( "set" + StringUtils.capitalize( property ), Integer.class ).invoke( patient,
+                object );
+        }
+        else if ( type.equals( Boolean.class ) || type == Boolean.TYPE )
+        {
+            Boolean object = Boolean.valueOf( value );
+            Patient.class.getMethod( "set" + StringUtils.capitalize( property ), Boolean.class ).invoke( patient,
+                object );
+        }
+        else if ( type.equals( Date.class ) )
+        {
+            Date object = format.parseDate( value.trim() );
+            Patient.class.getMethod( "set" + StringUtils.capitalize( property ), Date.class ).invoke( patient, object );
+        }
+        else if ( type.equals( Character.class ) || type == Character.TYPE )
+        {
+            Character object = Character.valueOf( value.charAt( 0 ) );
+            Patient.class.getMethod( "set" + StringUtils.capitalize( property ), Character.class ).invoke( patient,
+                object );
+        }
+        else
+        {
+            Patient.class.getMethod( "set" + StringUtils.capitalize( property ), String.class ).invoke( patient, value );
+        }
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/UploadExcelFileAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/UploadExcelFileAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/UploadExcelFileAction.java	2010-11-16 05:45:36 +0000
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2004-2010, 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.patient.action.patientimport;
+
+import java.io.File;
+
+import org.hisp.dhis.system.util.StreamUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version UploadExcelFileAction.java Nov 12, 2010 4:09:10 PM
+ */
+public class UploadExcelFileAction
+    implements Action
+{
+    // -------------------------------------------
+    // Input & Output
+    // -------------------------------------------
+
+    private File output;
+
+    public File getOutput()
+    {
+        return output;
+    }
+
+    private File upload;
+
+//    public File getUpload()
+//    {
+//        return upload;
+//    }
+
+    public void setUpload( File upload )
+    {
+        this.upload = upload;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        // ---------------------------------------------------------------------
+        // Get template-file
+        // ---------------------------------------------------------------------
+
+        String path = System.getenv( "DHIS2_HOME" );
+
+        if ( path != null )
+        {
+            path += File.separator + "temp" + File.separator 
+                    + upload.getName() + (Math.random() * 1000) + ".xls";
+        }
+        else
+        {
+            path = System.getenv( "user.home" ) + File.separator + "dhis" + "temp" + File.separator 
+                    + upload.getName() + (Math.random() * 1000) + ".xls";
+        }
+
+        output = new File( path );
+
+        StreamUtils.write( upload, output );
+
+        return SUCCESS;
+    }
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/XMLItem.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/XMLItem.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientimport/XMLItem.java	2010-11-16 05:45:36 +0000
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2004-2010, 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.patient.action.patientimport;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ExcelItem.java Nov 12, 2010 1:07:17 PM
+ */
+public class XMLItem
+{
+    public static String ORGUNIT_TYPE = "orgunit";
+
+    public static String START_ROW_TYPE = "startRow";
+
+    public static String END_ROW_TYPE = "endRow";
+
+    public static String PROPERTY_TYPE = "property";
+
+    public static String ATTRIBUTE_TYPE = "attribute";
+
+    public static String IDENTIFIER_TYPE = "identifier";
+    
+    public static String AGE_TYPE = "age-type";
+    
+    public static String BIRTH_DATE_FROM_VALUE = "birthDateFromAge";
+    
+    
+    public static String PROGRAM_TYPE = "program";
+    
+    public static String PROGRAM_ATTRIBUTE_TYPE = "programAttr";
+    
+    
+    public static String PROGRAM_STAGE_TYPE = "programStage";
+
+    // -------------------------------------------------------------------------
+    // Fields
+    // -------------------------------------------------------------------------
+
+    private int row;
+
+    private int column;
+
+    private int sheet;
+
+    private String type;
+
+    private String value;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public XMLItem()
+    {
+
+    }
+
+    public XMLItem( int row, int column, int sheet, String type, String value )
+    {
+        this.row = row;
+        this.column = column;
+        this.type = type;
+        this.value = value;
+        this.sheet = sheet;
+    }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public boolean isType( String type )
+    {
+       return this.type.equalsIgnoreCase( type );
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters && Setters
+    // -------------------------------------------------------------------------
+
+    public int getRow()
+    {
+        return row;
+    }
+
+    public void setRow( int row )
+    {
+        this.row = row;
+    }
+
+    public int getColumn()
+    {
+        return column;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public void setColumn( int column )
+    {
+        this.column = column;
+    }
+
+    public String getValue()
+    {
+        return value;
+    }
+
+    public void setValue( String value )
+    {
+        this.value = value;
+    }
+
+    public int getSheet()
+    {
+        return sheet;
+    }
+
+    public void setSheet( int sheet )
+    {
+        this.sheet = sheet;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2010-11-09 02:09:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2010-11-16 05:45:36 +0000
@@ -1190,4 +1190,80 @@
 		</property>
 	</bean>
 	
+	<!-- Configuration -->
+	
+	<bean
+		id="org.hisp.dhis.patient.action.configuration.GetPatientExcelItemplateFileAction"
+		class="org.hisp.dhis.patient.action.configuration.GetPatientExcelItemplateFileAction"
+		scope="prototype">
+		<property name="systemSettingManager">
+			<ref bean="org.hisp.dhis.options.SystemSettingManager" />
+		</property>
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.patient.action.configuration.SetPatientExcelItemplateFileAction"
+		class="org.hisp.dhis.patient.action.configuration.SetPatientExcelItemplateFileAction"
+		scope="prototype">
+		<property name="systemSettingManager">
+			<ref bean="org.hisp.dhis.options.SystemSettingManager" />
+		</property>
+	</bean>
+	
+	<!-- Import patient -->
+	<bean
+		id="org.hisp.dhis.patient.action.patientimport.UploadExcelFileAction"
+		class="org.hisp.dhis.patient.action.patientimport.UploadExcelFileAction"
+		scope="prototype">
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.patient.action.patientimport.ImportPatientAction"
+		class="org.hisp.dhis.patient.action.patientimport.ImportPatientAction"
+		scope="prototype">
+		<property name="patientService">
+			<ref bean="org.hisp.dhis.patient.PatientService" />
+		</property>
+		<property name="programInstanceService">
+			<ref bean="org.hisp.dhis.program.ProgramInstanceService" />
+		</property>
+		<property name="programStageInstanceService">
+			<ref bean="org.hisp.dhis.program.ProgramStageInstanceService" />
+		</property>
+		<property name="patientIdentifierTypeService">
+			<ref bean="org.hisp.dhis.patient.PatientIdentifierTypeService" />
+		</property>
+		<property name="patientAttributeService">
+			<ref bean="org.hisp.dhis.patient.PatientAttributeService" />
+		</property>
+		<property name="patientAttributeOptionService">
+			<ref bean="org.hisp.dhis.patient.PatientAttributeOptionService" />
+		</property>
+		<property name="systemSettingManager">
+			<ref bean="org.hisp.dhis.options.SystemSettingManager" />
+		</property>
+		<property name="organisationUnitService">
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		</property>
+		<property name="programService">
+			<ref bean="org.hisp.dhis.program.ProgramService" />
+		</property>
+		<property name="programStageService">
+			<ref bean="org.hisp.dhis.program.ProgramStageService" />
+		</property>
+		<property name="dataElementService">
+			<ref bean="org.hisp.dhis.dataelement.DataElementService" />
+		</property>
+		<property name="patientDataValueService">
+			<ref bean="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
+		</property>
+		<property name="patientIdentifierService">
+			<ref bean="org.hisp.dhis.patient.PatientIdentifierService" />
+			
+		</property>
+		<property name="patientAttributeValueService">
+			<ref bean="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
+		</property>
+	</bean>
+	
 </beans>
\ No newline at end of file

=== 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	2010-11-12 10:28:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2010-11-16 05:45:36 +0000
@@ -423,4 +423,20 @@
 program_attribute_management = Program Attribute Management
 add_new_program_attribute = Add New Program Attribute
 update_new_program_attribute = Update New Program Attribute
-program_infor = Program information
\ No newline at end of file
+program_infor = Program information
+import = Import
+import_data = Import Data
+intro_import_data = Import information of patients from Excel file.
+import_file = Import file
+upload = Upload
+configuration = Configuration
+intro_configuration = Set the XML template file.
+patient_xml_template_file = Patient XML template file
+save_successfull = Save successfully
+not_save_patient = Patients not saved
+row = Row
+reason = Reason
+patient_name_is_null = The name of patient is null
+birthday_is_null = Birthday is null
+duplicate = Duplicate
+excel_file = Excel file.

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2010-11-09 07:12:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2010-11-16 05:45:36 +0000
@@ -1126,8 +1126,51 @@
 		<action name="removeProgramStageDEValidation"
 			class="org.hisp.dhis.patient.action.validation.RemoveProgramStageDEValidationAction">
 			<result name="success" type="velocity-json">
-				dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
 		</action>
 
+		<!-- Configuration -->
+		
+		<action name="configuration"
+			class="org.hisp.dhis.patient.action.configuration.GetPatientExcelItemplateFileAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-patient/configurationParams.vm</param>
+			<param name="menu">/dhis-web-maintenance-patient/menu.vm</param>
+			<param name="javascripts">javascript/import.js</param>
+		</action>
+		
+		<action name="saveConfiguration"
+			class="org.hisp.dhis.patient.action.configuration.SetPatientExcelItemplateFileAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+		</action>
+		
+		<!-- Import Action -->
+		
+		<action name="importPatientForm"
+			class="org.hisp.dhis.patient.action.NoAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-patient/importPatientParams.vm</param>
+			<param name="menu">/dhis-web-maintenance-patient/menu.vm</param>
+		</action>
+		
+		<action name="importPatient"
+			class="org.hisp.dhis.patient.action.patientimport.UploadExcelFileAction">
+			<result name="success" type="chain">importPatientChain</result>
+			<interceptor-ref name="fileUploadStack" />
+		</action>
+		
+		<action name="importPatientChain"
+			class="org.hisp.dhis.patient.action.patientimport.ImportPatientAction">
+			<result name="success" type="chain">importPatientResult</result>
+		</action>
+		
+		<action name="importPatientResult"
+			class="org.hisp.dhis.patient.action.NoAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-patient/importPatientResult.vm</param>
+			<param name="menu">/dhis-web-maintenance-patient/menu.vm</param>
+		</action>
+		
 	</package>
 </struts>

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/configurationParams.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/configurationParams.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/configurationParams.vm	2010-11-16 05:45:36 +0000
@@ -0,0 +1,28 @@
+<script>
+	jQuery(document).ready(
+		function()
+		{
+			validation( 'configurationParamsForm', function(form){ form.submit() })
+		}
+	);
+	
+	var i18n_save_successfull = '$encoder.jsEscape( $i18n.getString( "save_successfull" ) , "'" )';
+</script>
+
+<h3>$i18n.getString('configuration') #openHelp( "excelReportingConfiguration" )</h3>
+<form id="configurationParamsForm" action="saveConfiguration.action" method="post">
+<table>
+	<tr>
+		<td>$i18n.getString('patient_xml_template_file')</td>		
+	</tr>
+	<tr>
+		<td><input type="text" id="fileName" name="fileName" style="width:400px" value="$!fileName" class="{validate:{required:true}}"/></td>
+	</tr>
+	<tr>		
+		<td><input type="button" value="$i18n.getString('ok')" style="width:150px" onclick="saveConfiguration();"/>
+			<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location='administration.action'" style="width:150px">
+		</td>
+	</tr>
+</table>
+</form>
+

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientParams.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientParams.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientParams.vm	2010-11-16 05:45:36 +0000
@@ -0,0 +1,16 @@
+<h3>$i18n.getString('import_data')</h3>
+<form name="importingParam" id="importingParam" action="importPatient.action" method="post" enctype="multipart/form-data">   
+
+<table width="62%">
+ <tr>
+     <td width="18%" style=" width:25% ">$i18n.getString( 'excel_file' )</td>
+      <td width="82%">
+          <input type="file" id="upload" name="upload" onChange="enable('uploadButton');">
+          <input name="uploadButton" id="uploadButton" type="submit" value="$i18n.getString( 'upload' )" />    
+	  </td>   
+  </tr>
+</table>
+
+</form>
+
+<hr/>

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientResult.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientResult.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/importPatientResult.vm	2010-11-16 05:45:36 +0000
@@ -0,0 +1,22 @@
+#parse( "/dhis-web-maintenance-patient/importPatientParams.vm" )
+
+<h4>$i18n.getString( 'not_save_patient' )</h4>  
+<table width=100%>
+	<tr>
+		<th>$i18n.getString('patient')</th>
+		<th>$i18n.getString('row')</th>
+		<th>$i18n.getString('reason')</th>
+	</tr>
+	 #foreach($row in $errPatients.keySet())
+	 #set ($mark = false)
+	<tr #alternate( $mark )>
+		<td>$errPatients.get($row).getFullName()</td>
+		<td>
+			#set($index =$row + 1 )
+			$index
+		</td>
+		<td>$errMessage.get($row)</td>
+	</tr>
+	#set ($mark = !$mark)
+	#end
+</table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/index.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/index.vm	2010-11-09 02:09:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/index.vm	2010-11-16 05:45:36 +0000
@@ -11,4 +11,6 @@
 	#introListImgItem( "programAttribute.action" "program_attribute" "program" )
     #introListImgItem( "caseaggregationMapForm.action" "case_aggregation_mapping" "caseaggregationmapping" )
 	#introListImgItem( "validationCriteria.action" "validation_criteria" "validationcriteria" )
+	#introListImgItem( "configuration.action" "configuration" "systemsettings" )
+	#introListImgItem( "importPatientForm.action" "import_data" "excel" )
 </ul>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/import.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/import.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/import.js	2010-11-16 05:45:36 +0000
@@ -0,0 +1,21 @@
+//------------------------------------------------------------------------------
+// Save Configuration
+//------------------------------------------------------------------------------
+
+function saveConfiguration()
+{	
+	var url = 'saveConfiguration.action?' +
+			'fileName=' + getFieldValue( 'fileName' );
+	
+	var request = new Request();
+    request.setResponseTypeXML( 'message' );
+    request.setCallbackSuccess( saveConfigurationCompleted );    
+    request.send( url );        
+
+    return false;
+}
+
+function saveConfigurationCompleted( messageElement )
+{
+    showSuccessMessage( i18n_save_successfull );
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatient.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatient.vm	2010-10-29 05:24:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatient.vm	2010-11-16 05:45:36 +0000
@@ -88,23 +88,23 @@
                 #end
                 
 		<td>			
-                    $encoder.htmlEncode( $patient.firstName )
-		</td>
-		<td>			
-                    $encoder.htmlEncode( $patient.middleName )
-		</td>
-		<td>			
-                    $encoder.htmlEncode( $patient.lastName )
+                    $!patient.firstName
+		</td>
+		<td>			
+                    $!patient.middleName
+		</td>
+		<td>			
+                    $!patient.lastName
 		</td>				
 		<td>			
-                    $encoder.htmlEncode( $patient.gender )
+                    $!patient.gender
 		</td>
 		<td>			
-                    $format.formatDate( $patient.birthDate )
+                    $format.formatDate( $!patient.birthDate)
 		</td>
 		<td>            
-                    $encoder.htmlEncode( $patient.getAge() )
-                </td>
+                    $!patient.getAge()
+        </td>
 				
 		<td style="text-align:center"#alternate( $mark )>
                   <a href="showProgramEnrollmentForm.action?id=$patient.id" title="$i18n.getString( "manage_program_enrollment" )"><img src="../images/enroll.png" alt="$i18n.getString( "manage_program_enrollment" )"></a>                  

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/menu.vm	2010-11-09 02:09:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/menu.vm	2010-11-16 05:45:36 +0000
@@ -11,3 +11,10 @@
 	<li><a href="validationCriteria.action">$i18n.getString( "validation_criteria" )</a></li>
 </ul>
 
+<h2>$i18n.getString( "import" )</h2>
+<ul>
+	<li><a href="configuration.action">$i18n.getString( "configuration" )</a></li>
+	<li><a href="importPatientForm.action">$i18n.getString( "import_data" )</a></li>
+</ul>
+
+