← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12045: [mobile] support date format dd-mm-yyyy in data entry form

 

------------------------------------------------------------
revno: 12045
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Wed 2013-09-11 23:13:49 +0700
message:
  [mobile] support date format dd-mm-yyyy in data entry form
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-09-11 15:26:20 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-09-11 16:13:49 +0000
@@ -543,10 +543,17 @@
             {
                 DataElement dataElement = dataElementService.getDataElement( dataElements.get( i ).getId() );
 
+                String value = dataElements.get( i ).getValue();
+
+                if ( dataElement.getType().equalsIgnoreCase( "date" ) && !value.trim().equals( "" ) )
+                {
+                    value = PeriodUtil.convertDateFormat( value );
+                }
+
                 PatientDataValue patientDataValue = new PatientDataValue();
                 patientDataValue.setDataElement( dataElement );
 
-                patientDataValue.setValue( dataElements.get( i ).getValue() );
+                patientDataValue.setValue( value );
                 patientDataValue.setProgramStageInstance( programStageInstance );
                 patientDataValue.setTimestamp( new Date() );
                 patientDataValueService.savePatientDataValue( patientDataValue );
@@ -584,6 +591,12 @@
             for ( int i = 0; i < dataElements.size(); i++ )
             {
                 DataElement dataElement = dataElementService.getDataElement( dataElements.get( i ).getId() );
+                String value = dataElements.get( i ).getValue();
+
+                if ( dataElement.getType().equalsIgnoreCase( "date" ) && !value.trim().equals( "" ) )
+                {
+                    value = PeriodUtil.convertDateFormat( value );
+                }
 
                 PatientDataValue previousPatientDataValue = patientDataValueService.getPatientDataValue(
                     programStageInstance, dataElement );
@@ -591,12 +604,12 @@
                 if ( previousPatientDataValue == null )
                 {
                     PatientDataValue patientDataValue = new PatientDataValue( programStageInstance, dataElement,
-                        new Date(), dataElements.get( i ).getValue() );
+                        new Date(), value );
                     patientDataValueService.savePatientDataValue( patientDataValue );
                 }
                 else
                 {
-                    previousPatientDataValue.setValue( dataElements.get( i ).getValue() );
+                    previousPatientDataValue.setValue( value );
                     previousPatientDataValue.setTimestamp( new Date() );
                     previousPatientDataValue.setProvidedElsewhere( false );
                     patientDataValueService.updatePatientDataValue( previousPatientDataValue );
@@ -882,8 +895,10 @@
 
         Period period = new Period( new DateTime( patient.getBirthDate() ), new DateTime() );
         patientModel.setAge( period.getYears() );
-        /*DateFormat dateFormat = new SimpleDateFormat( "dd-MM-yyyy" );
-        patientModel.setAge( dateFormat.format( patient.getBirthDate() ) );*/
+        /*
+         * DateFormat dateFormat = new SimpleDateFormat( "dd-MM-yyyy" );
+         * patientModel.setAge( dateFormat.format( patient.getBirthDate() ) );
+         */
         if ( patient.getOrganisationUnit() != null )
         {
             patientModel.setOrganisationUnitName( patient.getOrganisationUnit().getName() );
@@ -1213,7 +1228,16 @@
                 programStageDataElement.getDataElement() );
             if ( patientDataValue != null )
             {
-                mobileDataElement.setValue( patientDataValue.getValue() );
+                // Convert to standard date format before send to client
+                if ( programStageDataElement.getDataElement().getType().equalsIgnoreCase( "date" )
+                    && !patientDataValue.equals( "" ) )
+                {
+                    mobileDataElement.setValue( PeriodUtil.convertDateFormat( patientDataValue.getValue() ) );
+                }
+                else
+                {
+                    mobileDataElement.setValue( patientDataValue.getValue() );
+                }
             }
             else
             {
@@ -1820,7 +1844,7 @@
         throws NotAllowedException
     {
         org.hisp.dhis.patient.Patient patientWeb = new org.hisp.dhis.patient.Patient();
-        
+
         int startIndex = patient.getFirstName().indexOf( ' ' );
         int endIndex = patient.getFirstName().lastIndexOf( ' ' );
 
@@ -1886,8 +1910,8 @@
         // --------------------------------------------------------------------------------
         if ( identifierTypes.size() == 0 )
         {
-            String identifier = PatientIdentifierGenerator.getNewIdentifier( PeriodUtil.stringToDate( patient.getBirthDate() ),
-                patient.getGender() );
+            String identifier = PatientIdentifierGenerator.getNewIdentifier(
+                PeriodUtil.stringToDate( patient.getBirthDate() ), patient.getGender() );
 
             org.hisp.dhis.patient.PatientIdentifier systemGenerateIdentifier = new org.hisp.dhis.patient.PatientIdentifier();
             systemGenerateIdentifier.setIdentifier( identifier );

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java	2013-09-11 14:28:23 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java	2013-09-11 16:13:49 +0000
@@ -184,4 +184,17 @@
         return date;
     }
 
+    public static String convertDateFormat( String standardDate )
+    {
+        try
+        {
+            String[] tokens = standardDate.split( "-" );
+            return tokens[2] + "-" + tokens[1] + "-" + tokens[0];
+        }
+        catch ( Exception e )
+        {
+            return standardDate;
+        }
+    }
+
 }