← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10451: Upgrade custom entry forms to use uids instead of ids.

 

------------------------------------------------------------
revno: 10451
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-04-02 15:24:05 +0700
message:
  Upgrade custom entry forms to use uids instead of ids.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.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/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.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/ProgramDataEntryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2013-02-18 09:50:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java	2013-04-02 08:24:05 +0000
@@ -43,7 +43,7 @@
 {
     final Pattern INPUT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
 
-    final Pattern IDENTIFIER_PATTERN_FIELD = Pattern.compile( "id=\"(\\d+)-(\\d+)-val\"" );
+    final Pattern IDENTIFIER_PATTERN_FIELD = Pattern.compile( "id=\"(\\w+)-(\\w+)-val\"" );
 
     // --------------------------------------------------------------------------
     // ProgramDataEntryService

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java	2013-01-23 10:27:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageService.java	2013-04-02 08:24:05 +0000
@@ -48,6 +48,8 @@
     
     ProgramStage getProgramStage( int id );
     
+    ProgramStage getProgramStage( String uid );
+    
     ProgramStage getProgramStageByName( String name );
     
     Collection<ProgramStage> getAllProgramStages();

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-03-10 14:20:48 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2013-04-02 08:24:05 +0000
@@ -27,12 +27,9 @@
 
 package org.hisp.dhis.patient.startup;
 
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_ID;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
-
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.Collection;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -41,6 +38,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -54,7 +57,9 @@
 {
     private static final Log log = LogFactory.getLog( TableAlteror.class );
 
-    Pattern IDENTIFIER_PATTERN = Pattern.compile( "DE:(\\d+)\\.(\\d+)\\.(\\d+)" );
+    final Pattern INPUT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
+
+    final Pattern IDENTIFIER_PATTERN_FIELD = Pattern.compile( "id=\"(\\d+)-(\\d+)-val\"" );
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -67,6 +72,27 @@
         this.statementManager = statementManager;
     }
 
+    private ProgramStageService programStageService;
+
+    public void setProgramStageService( ProgramStageService programStageService )
+    {
+        this.programStageService = programStageService;
+    }
+
+    private DataElementService dataElementService;
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    private DataEntryFormService dataEntryFormService;
+
+    public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
+    {
+        this.dataEntryFormService = dataEntryFormService;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -77,8 +103,6 @@
     {
         executeSql( "ALTER TABLE relationshiptype RENAME description TO name" );
 
-        updateProgramStageInstanceOrgunit();
-
         executeSql( "ALTER TABLE programstage_dataelements DROP COLUMN showOnReport" );
 
         executeSql( "ALTER TABLE patientdatavalue DROP COLUMN categoryoptioncomboid" );
@@ -111,22 +135,14 @@
         executeSql( "ALTER TABLE patientmobilesetting DROP COLUMN bloodGroup" );
 
         executeSql( "ALTER TABLE caseaggregationcondition RENAME description TO name" );
-        updateCaseAggregationCondition();
 
         executeSql( "UPDATE programstage_dataelements SET allowProvidedElsewhere=false WHERE allowProvidedElsewhere is null" );
         executeSql( "UPDATE patientdatavalue SET providedElsewhere=false WHERE providedElsewhere is null" );
         executeSql( "ALTER TABLE programstageinstance DROP COLUMN providedbyanotherfacility" );
 
-        updateMultiOrgunitTabularReportTable();
-        updateProgramStageTabularReportTable();
-        moveStoredByFormStageInstanceToDataValue();
-
         executeSql( "ALTER TABLE patientattribute DROP COLUMN inheritable" );
         executeSql( "ALTER TABLE programstageinstance DROP COLUMN stageInProgram" );
 
-        updateRelationshipIdentifiers();
-        updateRelationshipAttributes();
-
         executeSql( "UPDATE programstage SET reportDateDescription='Report date' WHERE reportDateDescription is null" );
 
         executeSql( "CREATE INDEX programstageinstance_executiondate ON programstageinstance (executiondate)" );
@@ -140,33 +156,33 @@
         executeSql( "CREATE INDEX index_patientdatavalue ON patientdatavalue( programstageinstanceid, dataelementid, value, timestamp )" );
 
         executeSql( "CREATE INDEX index_programinstance ON programinstance( programinstanceid )" );
-        
-        executeSql( "ALTER TABLE program DROP COLUMN maxDaysAllowedInputData");
-                
-        executeSql( "ALTER TABLE period modify periodid int AUTO_INCREMENT");
-        executeSql( "CREATE SEQUENCE period_periodid_seq");
-        executeSql( "ALTER TABLE period ALTER COLUMN periodid SET DEFAULT NEXTVAL('period_periodid_seq')");
-        
+
+        executeSql( "ALTER TABLE program DROP COLUMN maxDaysAllowedInputData" );
+
+        executeSql( "ALTER TABLE period modify periodid int AUTO_INCREMENT" );
+        executeSql( "CREATE SEQUENCE period_periodid_seq" );
+        executeSql( "ALTER TABLE period ALTER COLUMN periodid SET DEFAULT NEXTVAL('period_periodid_seq')" );
+
         executeSql( "UPDATE program SET programstage_dataelements=false WHERE displayInReports is null" );
-        
+
         executeSql( "ALTER TABLE programvalidation DROP COLUMN leftside" );
         executeSql( "ALTER TABLE programvalidation DROP COLUMN rightside" );
         executeSql( "ALTER TABLE programvalidation DROP COLUMN dateType" );
-        
+
         executeSql( "UPDATE programstage SET validCompleteOnly=false WHERE validCompleteOnly is null" );
         executeSql( "UPDATE program SET ignoreOverdueEvents=false WHERE ignoreOverdueEvents is null" );
-        
+
         executeSql( "UPDATE programstage SET displayGenerateEventBox=true WHERE displayGenerateEventBox is null" );
-        executeSql( "ALTER TABLE patientidentifier DROP COLUMN preferred");
+        executeSql( "ALTER TABLE patientidentifier DROP COLUMN preferred" );
 
-        executeSql( "UPDATE patientidentifiertype SET personDisplayName=false WHERE personDisplayName is null");
+        executeSql( "UPDATE patientidentifiertype SET personDisplayName=false WHERE personDisplayName is null" );
 
         executeSql( "ALTER TABLE programvalidation RENAME description TO name" );
-        
+
         executeSql( "UPDATE program SET blockEntryForm=false WHERE blockEntryForm is null" );
         executeSql( "ALTER TABLE dataset DROP CONSTRAINT program_name_key" );
         executeSql( "UPDATE userroleauthorities SET authority='F_PROGRAM_PUBLIC_ADD' WHERE authority='F_PROGRAM_ADD'" );
-        
+
         executeSql( "UPDATE patientaudit SET accessedModule='patient_dashboard' WHERE accessedModule is null" );
         executeSql( "UPDATE patienttabularreport SET userOrganisationUnit=false WHERE userOrganisationUnit is null" );
         executeSql( "UPDATE patienttabularreport SET userOrganisationUnitChildren=false WHERE userOrganisationUnitChildren is null" );
@@ -179,247 +195,18 @@
 
         executeSql( "UPDATE program SET onlyEnrollOnce='false' WHERE onlyEnrollOnce is null" );
         executeSql( "UPDATE programStage SET captureCoordinates='false' WHERE captureCoordinates is null" );
-        
+
         executeSql( "update caseaggregationcondition set \"operator\"='times' where \"operator\"='SUM'" );
-        
+
         updateUid();
+        
+        updateUidInDataEntryFrom();
     }
 
     // -------------------------------------------------------------------------
     // Supporting methods
     // -------------------------------------------------------------------------
 
-    private void updateProgramStageInstanceOrgunit()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( "UPDATE programstageinstance SET organisationunitid=" + resultSet.getInt( 2 )
-                    + ", providedByAnotherFacility=" + resultSet.getBoolean( 3 ) + "  WHERE programstageinstanceid="
-                    + resultSet.getInt( 1 ) );
-            }
-
-            executeSql( "ALTER TABLE patientdatavalue DROP COLUMN organisationUnitid" );
-            executeSql( "ALTER TABLE patientdatavalue DROP COLUMN providedByAnotherFacility" );
-            executeSql( "ALTER TABLE patientdatavalue ADD PRIMARY KEY ( programstageinstanceid, dataelementid )" );            
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
-    private void updateCaseAggregationCondition()
-    {
-        String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([0-9]+" + SEPARATOR_ID
-            + "[0-9]+" + "\\])";
-
-        try
-        {
-            StatementHolder holder = statementManager.getHolder();
-
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT caseaggregationconditionid, aggregationExpression FROM caseaggregationcondition" );
-
-            while ( resultSet.next() )
-            {
-                StringBuffer formular = new StringBuffer();
-
-                // ---------------------------------------------------------------------
-                // parse expressions
-                // ---------------------------------------------------------------------
-
-                Pattern pattern = Pattern.compile( regExp );
-                String expression = resultSet.getString( 2 ).replaceAll( "'", "''" );
-                Matcher matcher = pattern.matcher( expression );
-
-                while ( matcher.find() )
-                {
-                    String match = matcher.group();
-                    match = match.replaceAll( "[\\[\\]]", "" );
-
-                    String[] info = match.split( SEPARATOR_OBJECT );
-                    String[] ids = info[1].split( SEPARATOR_ID );
-                    int programStageId = Integer.parseInt( ids[0] );
-
-                    StatementHolder _holder = statementManager.getHolder();
-                    Statement _statement = _holder.getStatement();
-                    ResultSet rsProgramId = _statement
-                        .executeQuery( "SELECT programid FROM programstage where programstageid=" + programStageId );
-
-                    if ( rsProgramId.next() )
-                    {
-                        int programId = rsProgramId.getInt( 1 );
-                        String aggregationExpression = "[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT
-                            + programId + SEPARATOR_ID + programStageId + SEPARATOR_ID + ids[1] + "]";
-                        matcher.appendReplacement( formular, aggregationExpression );
-                    }
-                }
-
-                matcher.appendTail( formular );
-                executeSql( "UPDATE caseaggregationcondition SET aggregationExpression='" + formular.toString()
-                    + "'  WHERE caseaggregationconditionid=" + resultSet.getInt( 1 ) );
-            }
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
-    }
-
-    private void updateMultiOrgunitTabularReportTable()
-    {
-        try
-        {
-            StatementHolder holder = statementManager.getHolder();
-
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT patienttabularreportid, organisationunitid FROM patienttabularreport" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( " INSERT INTO patienttabularreport_organisationUnits ( patienttabularreportid, organisationunitid ) VALUES ( "
-                    + resultSet.getInt( 1 ) + ", " + resultSet.getInt( 2 ) + ")" );
-            }
-            executeSql( "ALTER TABLE patienttabularreport DROP COLUMN organisationunitid" );
-        }
-        catch ( Exception e )
-        {
-
-        }
-    }
-
-    private void updateProgramStageTabularReportTable()
-    {
-        try
-        {
-            StatementHolder holder = statementManager.getHolder();
-
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT pd.patienttabularreportid, tr.programstageid, pd.elt, sort_order "
-                    + " FROM patienttabularreport_dataelements pd inner join patienttabularreport  tr"
-                    + " on pd.patienttabularreportid=tr.patienttabularreportid" + " order by pd.patienttabularreportid" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( "INSERT INTO patienttabularreport_programstagedataelements ( patienttabularreportid, programstageid, dataelementid, sort_order ) VALUES ( "
-                    + resultSet.getInt( 1 )
-                    + ", "
-                    + resultSet.getInt( 2 )
-                    + ", "
-                    + resultSet.getInt( 3 )
-                    + ", "
-                    + resultSet.getInt( 4 ) + ")" );
-            }
-            executeSql( "ALTER TABLE patienttabularreport DROP COLUMN programstageid" );
-            executeSql( "UPDATE program SET displayIncidentDate=true WHERE displayIncidentDate is null and type!=3" );
-            executeSql( "UPDATE program SET displayIncidentDate=false WHERE displayIncidentDate is null and type==3" );
-        }
-        catch ( Exception e )
-        {
-
-        }
-    }
-
-    private void moveStoredByFormStageInstanceToDataValue()
-    {
-        try
-        {
-            StatementHolder holder = statementManager.getHolder();
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement.executeQuery( "SELECT programstageinstanceid, storedBy"
-                + " FROM programstageinstance where storedBy is not null" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( "UPDATE patientdatavalue SET storedBy='" + resultSet.getString( 2 )
-                    + "' where programstageinstanceid=" + resultSet.getInt( 1 ) );
-            }
-
-            executeSql( "ALTER TABLE programstageinstance DROP COLUMN storedBy" );
-        }
-        catch ( Exception ex )
-        {
-        }
-    }
-
-    private void updateRelationshipIdentifiers()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT distinct programid, patientidentifiertypeid FROM patientidentifiertype" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( "INSERT into program_patientIdentifierTypes( programid, patientidentifiertypeid) values ("
-                    + resultSet.getString( 1 ) + "," + resultSet.getString( 2 ) + ")" );
-            }
-
-            executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN programid" );
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
-    private void updateRelationshipAttributes()
-    {
-        StatementHolder holder = statementManager.getHolder();
-
-        try
-        {
-            Statement statement = holder.getStatement();
-
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT distinct programid, patientattributeid FROM program_patientAttributes" );
-
-            while ( resultSet.next() )
-            {
-                executeSql( "INSERT into program_patientAttributes( programid, patientattributeid) values ("
-                    + resultSet.getString( 1 ) + "," + resultSet.getString( 2 ) + ")" );
-            }
-
-            executeSql( "ALTER TABLE patientattribute DROP COLUMN programid" );
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-        }
-        finally
-        {
-            holder.close();
-        }
-    }
-
     private void updateUid()
     {
         updateUidColumn( "patientattribute" );
@@ -431,7 +218,7 @@
         updateUidColumn( "programstagesection" );
         updateUidColumn( "programvalidation" );
     }
-    
+
     private void updateUidColumn( String tableName )
     {
         StatementHolder holder = statementManager.getHolder();
@@ -440,15 +227,15 @@
         {
             Statement statement = holder.getStatement();
 
-            ResultSet resultSet = statement
-                .executeQuery( "SELECT " + tableName + "id FROM " + tableName + " where uid is null" );
+            ResultSet resultSet = statement.executeQuery( "SELECT " + tableName + "id FROM " + tableName
+                + " where uid is null" );
 
             while ( resultSet.next() )
             {
                 String uid = CodeGenerator.generateCode();
-                
-                executeSql( "UPDATE " + tableName + " SET uid='" + uid
-                    + "'  WHERE " + tableName + "id=" + resultSet.getInt( 1 ) );
+
+                executeSql( "UPDATE " + tableName + " SET uid='" + uid + "'  WHERE " + tableName + "id="
+                    + resultSet.getInt( 1 ) );
             }
         }
         catch ( Exception ex )
@@ -460,6 +247,76 @@
             holder.close();
         }
     }
+
+    private void updateUidInDataEntryFrom()
+    {
+        Collection<ProgramStage> programStages = programStageService.getAllProgramStages();
+
+        for ( ProgramStage programStage : programStages )
+        {
+            DataEntryForm dataEntryForm = programStage.getDataEntryForm();
+            if ( dataEntryForm != null && dataEntryForm.getFormat() != DataEntryForm.CURRENT_FORMAT )
+            {
+                String programStageUid = programStage.getUid();
+                String htmlCode = programStage.getDataEntryForm().getHtmlCode();
+
+                // ---------------------------------------------------------------------
+                // Metadata code to add to HTML before outputting
+                // ---------------------------------------------------------------------
+
+                StringBuffer sb = new StringBuffer();
+
+                // ---------------------------------------------------------------------
+                // Pattern to match data elements in the HTML code
+                // ---------------------------------------------------------------------
+
+                Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
+
+                // ---------------------------------------------------------------------
+                // Iterate through all matching data element fields
+                // ---------------------------------------------------------------------
+
+                while ( inputMatcher.find() )
+                {
+                    String inputHTML = inputMatcher.group();
+                    inputHTML = inputHTML.replace( ">", "" );
+
+                    // -----------------------------------------------------------------
+                    // Get HTML input field code
+                    // -----------------------------------------------------------------
+
+                    String dataElementCode = inputMatcher.group( 1 );
+
+                    Matcher identifierMatcher = IDENTIFIER_PATTERN_FIELD.matcher( dataElementCode );
+
+                    if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+                    {
+                        // -------------------------------------------------------------
+                        // Get data element ID of data element
+                        // -------------------------------------------------------------
+
+                        int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                        DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+                        if ( dataElement != null )
+                        {
+                            inputHTML = inputHTML.replaceFirst( identifierMatcher.group( 1 ), programStageUid );
+                            inputHTML = inputHTML.replaceFirst( identifierMatcher.group( 2 ), dataElement.getUid() );
+                            inputMatcher.appendReplacement( sb, inputHTML );
+                        }
+
+                    }
+                }
+
+                inputMatcher.appendTail( sb );
+                
+                htmlCode = (sb.toString().isEmpty()) ? htmlCode : sb.toString();
+                dataEntryForm.setHtmlCode( htmlCode );
+                dataEntryForm.setFormat( DataEntryForm.CURRENT_FORMAT );
+                dataEntryFormService.updateDataEntryForm( dataEntryForm );
+            }
+        }
+    }
     
     private int executeSql( String sql )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2013-03-05 14:39:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2013-04-02 08:24:05 +0000
@@ -105,7 +105,7 @@
         String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance,
         OrganisationUnit organisationUnit )
     {
-        Map<Integer, Collection<PatientDataValue>> mapDataValue = new HashMap<Integer, Collection<PatientDataValue>>();
+        Map<String, Collection<PatientDataValue>> mapDataValue = new HashMap<String, Collection<PatientDataValue>>();
 
         // ---------------------------------------------------------------------
         // Inline Javascript to add to HTML before outputting
@@ -126,7 +126,7 @@
         // Iterate through all matching data element fields
         // ---------------------------------------------------------------------
 
-        Map<Integer, DataElement> dataElementMap = getDataElementMap( programStage );
+        Map<String, DataElement> dataElementMap = getDataElementMap( programStage );
 
         while ( dataElementMatcher.find() )
         {
@@ -139,31 +139,31 @@
             String inputHTML = dataElementMatcher.group( 1 );
 
             Matcher identifierMatcher = IDENTIFIER_PATTERN_FIELD.matcher( inputHTML );
-
+            
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
                 // -------------------------------------------------------------
                 // Get data element ID of data element
                 // -------------------------------------------------------------
 
-                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                String programStageUid = identifierMatcher.group( 1 );
 
-                int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                String dataElementUid = identifierMatcher.group( 2 );
 
                 DataElement dataElement = null;
 
                 String programStageName = programStage.getDisplayName();
 
-                if ( programStageId != programStage.getId() )
+                if ( !programStageUid.equals( programStage.getUid() ) )
                 {
-                    dataElement = dataElementService.getDataElement( dataElementId );
+                    dataElement = dataElementService.getDataElement( dataElementUid );
 
-                    ProgramStage otherProgramStage = programStageService.getProgramStage( programStageId );
+                    ProgramStage otherProgramStage = programStageService.getProgramStage( programStageUid );
                     programStageName = otherProgramStage != null ? otherProgramStage.getDisplayName() : "N/A";
                 }
                 else
                 {
-                    dataElement = dataElementMap.get( dataElementId );
+                    dataElement = dataElementMap.get( dataElementUid );
                     if ( dataElement == null )
                     {
                         return i18n.getString( "some_data_element_not_exist" );
@@ -194,26 +194,26 @@
 
                 String dataElementValue = EMPTY;
 
-                if ( programStageId != programStage.getId() )
+                if ( !programStageUid.equals( programStage.getUid() ) )
                 {
-                    Collection<PatientDataValue> patientDataValues = mapDataValue.get( programStageId );
+                    Collection<PatientDataValue> patientDataValues = mapDataValue.get( programStageUid );
 
                     if ( patientDataValues == null )
                     {
-                        ProgramStage otherProgramStage = programStageService.getProgramStage( programStageId );
+                        ProgramStage otherProgramStage = programStageService.getProgramStage( programStageUid );
                         ProgramStageInstance otherProgramStageInstance = programStageInstanceService
                             .getProgramStageInstance( programStageInstance.getProgramInstance(), otherProgramStage );
                         patientDataValues = patientDataValueService.getPatientDataValues( otherProgramStageInstance );
-                        mapDataValue.put( programStageId, patientDataValues );
+                        mapDataValue.put( programStageUid, patientDataValues );
                     }
 
-                    patientDataValue = getValue( patientDataValues, dataElementId );
+                    patientDataValue = getValue( patientDataValues, dataElementUid );
 
                     dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue;
                 }
                 else
                 {
-                    patientDataValue = getValue( dataValues, dataElementId );
+                    patientDataValue = getValue( dataValues, dataElementUid );
 
                     dataElementValue = patientDataValue != null ? patientDataValue.getValue() : dataElementValue;
                 }
@@ -226,12 +226,12 @@
                 if ( inputHTML.contains( "title=\"\"" ) )
                 {
                     inputHTML = inputHTML.replace( "title=\"\"",
-                        "title=\"" + dataElement.getId() + "." + dataElement.getName() + " (" + dataElementType
+                        "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " (" + dataElementType
                             + ")\" " );
                 }
                 else
                 {
-                    inputHTML += "title=\"" + dataElement.getId() + "." + dataElement.getName() + " ("
+                    inputHTML += "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " ("
                         + dataElementType + ")\" ";
                 }
 
@@ -267,7 +267,7 @@
                 // -----------------------------------------------------------
 
                 disabled = "";
-                if ( programStageId != programStage.getId() )
+                if ( !programStageUid.equals( programStage.getUid() ) )
                 {
                     disabled = "disabled=\"\"";
                 }
@@ -289,9 +289,9 @@
                 //
                 // -----------------------------------------------------------
 
-                inputHTML = inputHTML.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
+                inputHTML = inputHTML.replace( "$DATAELEMENTID", String.valueOf( dataElementUid ) );
                 inputHTML = inputHTML.replace( "$VALUE", dataElementValue );
-                inputHTML = inputHTML.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) );
+                inputHTML = inputHTML.replace( "$PROGRAMSTAGEID", String.valueOf( programStageUid ) );
                 inputHTML = inputHTML.replace( "$PROGRAMSTAGENAME", programStageName );
                 inputHTML = inputHTML.replace( "$DATAELEMENTNAME", dataElement.getName() );
                 inputHTML = inputHTML.replace( "$DATAELEMENTTYPE", dataElementType );
@@ -332,7 +332,7 @@
         // Iterate through all matching data element fields
         // ---------------------------------------------------------------------
 
-        Map<Integer, DataElement> dataElementMap = getDataElementMap( programStage );
+        Map<String, DataElement> dataElementMap = getDataElementMap( programStage );
 
         while ( dataElementMatcher.find() )
         {
@@ -352,24 +352,24 @@
                 // Get data element ID of data element
                 // -------------------------------------------------------------
 
-                int programStageId = Integer.parseInt( identifierMatcher.group( 1 ) );
+                String programStageUid = identifierMatcher.group( 1 );
 
-                int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) );
+                String dataElementUid = identifierMatcher.group( 2 );
 
                 DataElement dataElement = null;
 
                 String programStageName = programStage.getDisplayName();
 
-                if ( programStageId != programStage.getId() )
+                if ( !programStageUid.equals( programStage.getUid() ) )
                 {
-                    dataElement = dataElementService.getDataElement( dataElementId );
+                    dataElement = dataElementService.getDataElement( dataElementUid );
 
-                    ProgramStage otherProgramStage = programStageService.getProgramStage( programStageId );
+                    ProgramStage otherProgramStage = programStageService.getProgramStage( programStageUid );
                     programStageName = otherProgramStage != null ? otherProgramStage.getDisplayName() : "N/A";
                 }
                 else
                 {
-                    dataElement = dataElementMap.get( dataElementId );
+                    dataElement = dataElementMap.get( dataElementUid );
                     if ( dataElement == null )
                     {
                         return i18n.getString( "some_data_element_not_exist" );
@@ -408,12 +408,12 @@
                 if ( inputHTML.contains( "title=\"\"" ) )
                 {
                     inputHTML = inputHTML.replace( "title=\"\"",
-                        "title=\"" + dataElement.getId() + "." + dataElement.getName() + " (" + dataElementType
+                        "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " (" + dataElementType
                             + ")\" " );
                 }
                 else
                 {
-                    inputHTML += "title=\"" + dataElement.getId() + "." + dataElement.getName() + " ("
+                    inputHTML += "title=\"" + dataElement.getUid() + "." + dataElement.getName() + " ("
                         + dataElementType + ")\" ";
                 }
 
@@ -449,7 +449,7 @@
                 // -----------------------------------------------------------
 
                 String disabled = "";
-                if ( programStageId != programStage.getId() )
+                if ( !programStageUid.equals( programStage.getUid() ) )
                 {
                     disabled = "disabled=\"\"";
                 }
@@ -471,9 +471,9 @@
                 //
                 // -----------------------------------------------------------
 
-                inputHTML = inputHTML.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
+                inputHTML = inputHTML.replace( "$DATAELEMENTID", String.valueOf( dataElementUid ) );
                 inputHTML = inputHTML.replace( "$VALUE", dataElementValue );
-                inputHTML = inputHTML.replace( "$PROGRAMSTAGEID", String.valueOf( programStageId ) );
+                inputHTML = inputHTML.replace( "$PROGRAMSTAGEID", String.valueOf( programStageUid ) );
                 inputHTML = inputHTML.replace( "$PROGRAMSTAGENAME", programStageName );
                 inputHTML = inputHTML.replace( "$DATAELEMENTNAME", dataElement.getName() );
                 inputHTML = inputHTML.replace( "$DATAELEMENTTYPE", dataElementType );
@@ -558,7 +558,7 @@
                 + dataElement.getDisplayName() + "]\"" ) : inputHTML + " value=\"[" + dataElement.getDisplayName()
                 + "]\" ";
 
-            String displayTitle = dataElement.getId() + " - " + dataElement.getName() + " - "
+            String displayTitle = dataElement.getUid() + " - " + dataElement.getName() + " - "
                 + dataElement.getDetailedNumberType() + " - ";
             inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, " title=\""
                 + displayTitle + "\"" ) : inputHTML + " title=\"" + displayTitle + "\"";
@@ -717,11 +717,11 @@
      * Returns the value of the PatientDataValue in the Collection of DataValues
      * with the given data element identifier.
      */
-    private PatientDataValue getValue( Collection<PatientDataValue> dataValues, int dataElementId )
+    private PatientDataValue getValue( Collection<PatientDataValue> dataValues, String dataElementUid )
     {
         for ( PatientDataValue dataValue : dataValues )
         {
-            if ( dataValue.getDataElement().getId() == dataElementId )
+            if ( dataValue.getDataElement().getUid().equals( dataElementUid ) )
             {
                 return dataValue;
             }
@@ -734,7 +734,7 @@
      * Returns a Map of all DataElements in the given ProgramStage where the key
      * is the DataElement identifier and the value is the DataElement.
      */
-    private Map<Integer, DataElement> getDataElementMap( ProgramStage programStage )
+    private Map<String, DataElement> getDataElementMap( ProgramStage programStage )
     {
         Collection<DataElement> dataElements = programStageDataElementService.getListDataElement( programStage );
 
@@ -742,11 +742,11 @@
         {
             return null;
         }
-        Map<Integer, DataElement> map = new HashMap<Integer, DataElement>();
+        Map<String, DataElement> map = new HashMap<String, DataElement>();
 
         for ( DataElement element : dataElements )
         {
-            map.put( element.getId(), element );
+            map.put( element.getUid(), element );
         }
 
         return map;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java	2013-01-23 10:27:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageService.java	2013-04-02 08:24:05 +0000
@@ -78,12 +78,17 @@
 
     public ProgramStage getProgramStage( int id )
     {
-        return i18n( i18nService, programStageStore.get( id ));
+        return i18n( i18nService, programStageStore.get( id ) );
+    }
+
+    public ProgramStage getProgramStage( String uid )
+    {
+        return i18n( i18nService, programStageStore.getByUid( uid ) );
     }
 
     public ProgramStage getProgramStageByName( String name )
     {
-        return i18n( i18nService, programStageStore.getByName( name ));
+        return i18n( i18nService, programStageStore.getByName( name ) );
     }
 
     public void updateProgramStage( ProgramStage programStage )
@@ -93,7 +98,7 @@
 
     public Collection<ProgramStage> getAllProgramStages()
     {
-        return i18n( i18nService, programStageStore.getAll());
+        return i18n( i18nService, programStageStore.getAll() );
     }
 
     public Collection<ProgramStage> getProgramStages( Program program )

=== 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	2013-04-01 05:56:41 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-02 08:24:05 +0000
@@ -520,6 +520,13 @@
 		<property name="name" value="PatientTableAlteror" />
 		<property name="runlevel" value="4" />
 		<property name="skipInTests" value="true" />
+		<property name="programStageService"
+			ref="org.hisp.dhis.program.ProgramStageService" />
+		<property name="dataElementService"
+			ref="org.hisp.dhis.dataelement.DataElementService" />
+		<property name="dataEntryFormService"
+			ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
+		
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	2012-11-01 15:15:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	2013-04-02 08:24:05 +0000
@@ -71,9 +71,9 @@
     // Input
     // -------------------------------------------------------------------------
 
-    private Integer id;
+    private String id;
 
-    public void setId( Integer id )
+    public void setId( String id )
     {
         this.id = id;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-04-02 04:51:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js	2013-04-02 08:24:05 +0000
@@ -317,7 +317,7 @@
                     var array = [];
                     Ext.Array.each(selected, function(item) {
 						var data = a.store.findExact('id', item);
-                        array.push({id: item, name: a.store.getAt(data).data.name, compulsory: a.store.getAt(data).data.compulsory, valueType: a.store.getAt(data).data.valueType});
+                        array.push({id: item, uid:a.store.getAt(data).data.uid, name: a.store.getAt(data).data.name, compulsory: a.store.getAt(data).data.compulsory, valueType: a.store.getAt(data).data.valueType});
                     });
                     s.store.add(array);
                 }
@@ -339,7 +339,7 @@
 						var name = a.store.getAt(i).data.name;
 						var valueType = a.store.getAt(i).data.valueType;
 						
-						array.push({id: id, name: name, compulsory: a.store.getAt(i).data.compulsory, valueType: valueType});
+						array.push({id: id, uid:a.store.getAt(data).data.uid, name: name, compulsory: a.store.getAt(i).data.compulsory, valueType: valueType});
 						if(f!=undefined)
 						{
 							this.addFilterField( f, id, name, valueType );
@@ -621,13 +621,15 @@
 						params.displayField = 'o';
 						params.multiSelect = true;
 						params.delimiter = ';';
+						var index = TR.store.dataelement.selected.findExact('id', 'de_' + deId);
+						var deUid = TR.store.dataelement.selected.getAt(index).data.uid;
 						params.store = Ext.create('Ext.data.Store', {
 							fields: ['o'],
 							data:[],
 							proxy: {
 								type: 'ajax',
 								url: TR.conf.finals.ajax.path_commons + TR.conf.finals.ajax.suggested_dataelement_get,
-								extraParams:{id: deId},
+								extraParams:{id: deUid},
 								reader: {
 									type: 'json',
 									root: 'options'
@@ -1489,7 +1491,7 @@
 		}),
 		dataelement: {
             available: Ext.create('Ext.data.Store', {
-                fields: ['id', 'name', 'compulsory', 'valueType'],
+                fields: ['id', 'uid', 'name', 'compulsory', 'valueType'],
                 proxy: {
                     type: 'ajax',
                     url: TR.conf.finals.ajax.path_commons + TR.conf.finals.ajax.dataelements_get,
@@ -1532,7 +1534,7 @@
 				}
             }),
             selected: Ext.create('Ext.data.Store', {
-                fields: ['id', 'name', 'compulsory', 'valueType'],
+                fields: ['id', 'uid', 'name', 'compulsory', 'valueType'],
                 data: []
             })
         },

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm	2012-12-10 12:54:54 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/responseDataElements.vm	2013-04-02 08:24:05 +0000
@@ -3,6 +3,7 @@
 #foreach( $psDataElement in $psDataElements )
   {
     "id": "de_$!{psDataElement.dataElement.id}",
+	"uid": "$!{psDataElement.dataElement.uid}",
     "name": "$encoder.xmlEncode(${psDataElement.dataElement.getFormNameFallback()} )",
 	"compulsory": "${psDataElement.compulsory}",
 	"displayInReports": "$psDataElement.displayInReports",

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2013-02-26 08:38:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2013-04-02 08:24:05 +0000
@@ -152,7 +152,7 @@
 	});	
 }
 
-function insertDataElement( source, programStageId )
+function insertDataElement( source, programStageUid )
 {
 	var dataElement = JSON.parse( jQuery( source + ' #dataElementIds').val() );
 
@@ -164,13 +164,13 @@
 		jQuery( source + " #message_").html( "" );
 	}
 
-	var dataElementId = dataElement.id;	
+	var dataElementUid = dataElement.uid;	
 	var dataElementName = dataElement.name;	
 	var dataElementType = dataElement.type;
 	
 	var htmlCode = "";
-	var id = programStageId + "-" + dataElementId + "-val" ;	
-	var titleValue = dataElementId + " - " + dataElementName + " - " + dataElementType;
+	var id = programStageUid + "-" + dataElementUid + "-val" ;	
+	var titleValue = dataElementUid + " - " + dataElementName + " - " + dataElementType;
 	
 	if ( dataElementType == "bool" )
 	{

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2013-02-26 08:38:13 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2013-04-02 08:24:05 +0000
@@ -66,7 +66,7 @@
 </style>
 
 <form id="saveDataEntryForm" name="saveDataEntryForm" action="saveDataEntryForm.action" method="post">
-<input type="hidden" name="programStageId" id="programStageId" value="$!programStage.id"/>
+<input type="hidden" name="programStageId" id="programStageId" uid="$!programStage.uid" value="$!programStage.id"/>
 <h3>$i18n.getString( "dataentryform_management_for_program_stage" )</h3>
 <h4>$programStage.displayName</h4>
 
@@ -157,15 +157,15 @@
 		</tr>
 		<tr>
 			<td colspan='2'>	
-				<select id="dataElementIds" name="dataElementIds" style="min-width:400; width:100%; height:210px;" multiple="multiple" size="10" ondblclick="insertDataElement( '#dataElementSelection', '$programStage.id')">
+				<select id="dataElementIds" name="dataElementIds" style="min-width:400; width:100%; height:210px;" multiple="multiple" size="10" ondblclick="insertDataElement( '#dataElementSelection', '$programStage.uid')">
 					#foreach( $de in $dataElements)
-					#set($deJSON = '{' + '"id"' + ":" + $de.id + "," + '"name"' + ':"' + "$de.name" + '",' + '"shortName"' + ':"' + "$de.shortName" + '",' + '"type"' + ':"' + "$de.getDetailedTextType()"  + '"}' )
+					#set($deJSON = '{' + '"uid"' + ':"' + "$de.uid" + '",' + '"name"' + ':"' + "$de.name" + '",' + '"shortName"' + ':"' + "$de.shortName" + '",' + '"type"' + ':"' + "$de.getDetailedTextType()"  + '"}' )
 					<option value='$deJSON' decode="$!de.code" dename="$de.name" title="$de.name">$encoder.htmlEncode( $de.name )</option>
 					#end
 				</select>
 				<select id="dataElementIdsStore" multiple="multiple" style="display:none">
 					#foreach( $de in $dataElements)
-					#set($deJSON = '{' + '"id"' + ":" + $de.id + "," + '"name"' + ':"' + "$de.name" + '",' + '"shortName"' + ':"' + "$de.shortName" + '",' + '"type"' + ':"' + "$de.getDetailedTextType()"  + '"}' )
+					#set($deJSON = '{' + '"uid"' + ':"' + "$de.uid" + '",' + '"name"' + ':"' + "$de.name" + '",' + '"shortName"' + ':"' + "$de.shortName" + '",' + '"type"' + ':"' + "$de.getDetailedTextType()"  + '"}' )
 					<option value='$deJSON' decode="$!de.code" dename="$de.name">$encoder.htmlEncode( $de.name )</option>
 					#end
 				</select>
@@ -173,7 +173,7 @@
 		</tr>
 		<tr>
 			<td>
-				<input type="button" id="insertButton" value="$i18n.getString('insert')" onclick="insertDataElement( '#dataElementSelection', '$programStage.id')" style="width:100px">
+				<input type="button" id="insertButton" value="$i18n.getString('insert')" onclick="insertDataElement( '#dataElementSelection', '$programStage.uid')" style="width:100px">
 			</td>
 			<td>
 				<span id="message_"></span>
@@ -228,7 +228,7 @@
 		</tr>
 		<tr>
 			<td colspan='2'>
-				<select id="dataElementIds" name="dataElementIds" style="min-width:400; width:100%; height:210px;" multiple="multiple" size="10" ondblclick="insertDataElement( '#otherProgramStageDataElements', byId('programStageIds').value )"/>
+				<select id="dataElementIds" name="dataElementIds" style="min-width:400; width:100%; height:210px;" multiple="multiple" size="10" ondblclick="insertDataElement( '#otherProgramStageDataElements', jQuery('#programStageIds option:selected').attr('uid') )"/>
 				<select id="dataElementIdsStore" style="min-width:300px;display:none" multiple="multiple" size="10"/>
 			</td>
 		</tr>