← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2161: Added Functionality to import ANM Name from mobile into orgunit comment field

 

------------------------------------------------------------
revno: 2161
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2010-11-24 19:07:22 +0530
message:
  Added Functionality to import ANM Name from mobile into orgunit comment field
modified:
  dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java
  dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java
  dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java
  dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java
  dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml
  dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/DraftPageAction.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-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java	2010-11-17 07:27:27 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/DefaultMobileImportService.java	2010-11-24 13:37:22 +0000
@@ -45,7 +45,6 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -56,8 +55,9 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.external.location.LocationManager;
-import org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler;
 import org.hisp.dhis.mobile.SmsService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.DailyPeriodType;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
@@ -149,6 +149,13 @@
         this.dataElementCategoryService = dataElementCategoryService;
     }
 
+    private OrganisationUnitService organisationUnitService;
+    
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     private BatchHandlerFactory batchHandlerFactory;
 
     public void setBatchHandlerFactory( BatchHandlerFactory batchHandlerFactory )
@@ -171,7 +178,6 @@
     {
         smsService.readAllMessages();
         System.out.println("Message reading done");
-        
     }
     
     @Override
@@ -186,16 +192,6 @@
             selectedUser = userList.iterator().next();
         }
 
-        /*
-         * List<User> allUsers = new ArrayList<User>( userStore.getAllUsers() );
-         * 
-         * User selectedUser = null;
-         * 
-         * for ( User user : allUsers ) { if ( user.getPhoneNumber() != null &&
-         * user.getPhoneNumber().equalsIgnoreCase( mobileNumber ) ) {
-         * selectedUser = user; break; } }
-         */
-
         return selectedUser;
     }
 
@@ -268,6 +264,8 @@
         String smsTime;
         String startDate;
         String periodType;
+        String formType;
+        String anmName;
 
         String tempDeid;
         String tempDataValue;
@@ -318,34 +316,54 @@
 
             mobileImportParameters.setPeriodType( periodType );
 
-            NodeList listOfDataValues = doc.getElementsByTagName( "dataValue" );
-            int totalDataValues = listOfDataValues.getLength();
-            for ( int s = 0; s < totalDataValues; s++ )
+            // To get FormType
+            NodeList formTypeInfo = doc.getElementsByTagName( "formtype" );
+            Element formTypeInfoElement = (Element) formTypeInfo.item( 0 );
+            NodeList formTypeInfoNameList = formTypeInfoElement.getChildNodes();
+            formType = formTypeInfoNameList.item( 0 ).getNodeValue().trim();
+
+            mobileImportParameters.setFormType( formType );
+            
+            if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_DATAFORM ) )
             {
-                Node dataValueNode = listOfDataValues.item( s );
-                if ( dataValueNode.getNodeType() == Node.ELEMENT_NODE )
+                NodeList listOfDataValues = doc.getElementsByTagName( "dataValue" );
+                int totalDataValues = listOfDataValues.getLength();
+                for ( int s = 0; s < totalDataValues; s++ )
                 {
-                    Element dataValueElement = (Element) dataValueNode;
-
-                    NodeList dataElementIdList = dataValueElement.getElementsByTagName( "dataElement" );
-                    Element dataElementElement = (Element) dataElementIdList.item( 0 );
-                    NodeList textdataElementIdList = dataElementElement.getChildNodes();
-                    tempDeid = textdataElementIdList.item( 0 ).getNodeValue().trim();
-
-                    NodeList valueList = dataValueElement.getElementsByTagName( "value" );
-                    Element valueElement = (Element) valueList.item( 0 );
-                    NodeList textValueElementList = valueElement.getChildNodes();
-                    tempDataValue = textValueElementList.item( 0 ).getNodeValue();
-
-                    String tempDeID = tempDeid;
-                    //Integer tempDV = Integer.parseInt( tempDataValue );
-
-                    dataValues.put( tempDeID, tempDataValue );
-                }
-            }// end of for loop with s var
-
-            mobileImportParameters.setDataValues( dataValues );
-
+                    Node dataValueNode = listOfDataValues.item( s );
+                    if ( dataValueNode.getNodeType() == Node.ELEMENT_NODE )
+                    {
+                        Element dataValueElement = (Element) dataValueNode;
+    
+                        NodeList dataElementIdList = dataValueElement.getElementsByTagName( "dataElement" );
+                        Element dataElementElement = (Element) dataElementIdList.item( 0 );
+                        NodeList textdataElementIdList = dataElementElement.getChildNodes();
+                        tempDeid = textdataElementIdList.item( 0 ).getNodeValue().trim();
+    
+                        NodeList valueList = dataValueElement.getElementsByTagName( "value" );
+                        Element valueElement = (Element) valueList.item( 0 );
+                        NodeList textValueElementList = valueElement.getChildNodes();
+                        tempDataValue = textValueElementList.item( 0 ).getNodeValue();
+    
+                        String tempDeID = tempDeid;
+                        //Integer tempDV = Integer.parseInt( tempDataValue );
+    
+                        dataValues.put( tempDeID, tempDataValue );
+                    }
+                }// end of for loop with s var
+    
+                mobileImportParameters.setDataValues( dataValues );
+            }
+            else if( formType.equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
+            {
+                // To get ANM Name
+                NodeList anmNameInfo = doc.getElementsByTagName( "anmname" );
+                Element anmNameInfoElement = (Element) anmNameInfo.item( 0 );
+                NodeList anmNameInfoNameList = anmNameInfoElement.getChildNodes();
+                anmName = anmNameInfoNameList.item( 0 ).getNodeValue().trim();
+
+                mobileImportParameters.setAnmName( anmName );
+            }
         }// try block end
         catch ( SAXParseException err )
         {
@@ -518,7 +536,7 @@
         }
     }
 
-    @Override
+    /*
     @Transactional
     public void importAllFiles()
     {
@@ -595,26 +613,17 @@
                     {
                         LOG.error( "dataValue map is null" );
                     }
-                    else
-                    {
-                        if ( source == null )
-                        {
-                            LOG.error( "source is null" );
-                        }
-                        else
-                        {
-                            if ( period == null )
-                            {
-                                LOG.error( "period is null" );
-                            }
-                            else
-                            {
-                                if ( timeStamp == null )
-                                {
-                                    LOG.error( "timeStamp is null" );
-                                }
-                            }
-                        }
+                    else if ( source == null )
+                    {
+                        LOG.error( "source is null" );
+                    }
+                    else if ( period == null )
+                    {
+                        LOG.error( "period is null" );
+                    }
+                    else if ( timeStamp == null )
+                    {
+                        LOG.error( "timeStamp is null" );
                     }
 
                     if ( source == null || period == null || timeStamp == null || dataValueMap == null
@@ -647,8 +656,6 @@
                         optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer
                             .valueOf( optStr ) );
 
-                        // DataValue dataValue = dataValueService.getDataValue(
-                        // source, dataElement, period, optionCombo );
                         DataValue dataValue = new DataValue( dataElement, period, source, value, storedBy, timeStamp,
                             null, optionCombo );
                         boolean exists = batchHandler.objectExists( dataValue );
@@ -657,11 +664,6 @@
                         {
                             if ( value != null )
                             {
-                                // dataValue = new DataValue( dataElement,
-                                // period, source, value, storedBy, timeStamp,
-                                // null, optionCombo );
-
-                                // dataValueService.addDataValue( dataValue );
                                 batchHandler.addObject( dataValue );
                             }
                         }
@@ -673,7 +675,6 @@
 
                             dataValue.setStoredBy( storedBy );
 
-                            // dataValueService.updateDataValue( dataValue );
                             batchHandler.updateObject( dataValue );
                         }
                     }
@@ -701,76 +702,24 @@
             }
         }
     }
-
+*/
     @Override
     @Transactional
     public void importPendingFiles()
     {
-        /*
-        List<String> status1PhoneNumbers = new ArrayList<String>();
-        List<String> status2PhoneNumbers = new ArrayList<String>();
-        List<String> status3PhoneNumbers = new ArrayList<String>();
-        List<String> status4PhoneNumbers = new ArrayList<String>();
-        List<String> status5PhoneNumbers = new ArrayList<String>();
-        */
-        
         List<String> fileNames = new ArrayList<String>( getImportFiles() );
 
         for ( String importFile : fileNames )
         {
-            //List<String> status = importPendingFile( importFile );
-            
             String statusMsg = importXMLFile( importFile );
             
-            //smsService.sendMessage( importFile.split( "_" )[0], statusMsg );
-            
             SendSMS sendSMS = new SendSMS( importFile.replace( ".xml", "" ), statusMsg );
             
             sendSMSService.addSendSMS( sendSMS );
-            
-            /*
-            if( status.get( 0 ).equalsIgnoreCase( "1" ) )
-            {
-                status1PhoneNumbers.add( importFile.split( "_" )[0] );
-            }
-            else if( status.get( 0 ).equalsIgnoreCase( "2" ) )
-            {
-                status2PhoneNumbers.add( importFile.split( "_" )[0] );
-            }
-            else if( status.get( 0 ).equalsIgnoreCase( "3" ) )
-            {
-                status3PhoneNumbers.add( importFile.split( "_" )[0] );
-            }
-            else if( status.get( 0 ).equalsIgnoreCase( "4" ) )
-            {
-                status4PhoneNumbers.add( importFile.split( "_" )[0] );
-            }
-            else if( status.get( 0 ).equalsIgnoreCase( "5" ) )
-            {
-                status5PhoneNumbers.add( importFile.split( "_" )[0] );
-            }
-            */
         }
-        
-        /*
-        String groupName = UUID.randomUUID().toString();
-        smsService.sendMessageToGroup( groupName, status1PhoneNumbers, msg );
-        
-        groupName = UUID.randomUUID().toString();
-        smsService.sendMessageToGroup( groupName, status2PhoneNumbers, msg );
-        
-        groupName = UUID.randomUUID().toString();
-        smsService.sendMessageToGroup( groupName, status3PhoneNumbers, msg );
-        
-        groupName = UUID.randomUUID().toString();
-        smsService.sendMessageToGroup( groupName, status4PhoneNumbers, msg );
-        
-        groupName = UUID.randomUUID().toString();
-        smsService.sendMessageToGroup( groupName, status5PhoneNumbers, msg );
-        */
     }
     
-    
+    /*
     @Transactional
     public List<String> importPendingFile( String importFile )
     {
@@ -793,7 +742,6 @@
                 statusMsgs.add( 1, "Data not Received Properly, Please send again" );
                 
                 return statusMsgs;
-                //return "Data not Received Properly, Please send again";
             }
 
             User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
@@ -816,7 +764,6 @@
                     statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
                     
                     return statusMsgs;
-                    //return "Phone number is not registered to any facility. Please contact admin";
                 }
 
                 List<Source> sources = new ArrayList<Source>( curUser.getOrganisationUnits() );
@@ -831,8 +778,6 @@
                     statusMsgs.add( 1, "Phone number is not registered to any facility. Please contact admin" );
                     
                     return statusMsgs;
-
-                    //return "Phone number is not registered to any facility. Please contact admin";
                 }
                 
                 Source source = sources.get( 0 );
@@ -885,8 +830,6 @@
                     statusMsgs.add( 1, "Data not Received Properly, Please send again" );
                     
                     return statusMsgs;
-
-                    //return "Data not Received Properly, Please send again";
                 }
 
                 Set<String> keys = dataValueMap.keySet();
@@ -987,21 +930,95 @@
         }
         finally
         {
-            //batchHandler.flush();
         }
 
         return statusMsgs;
     }
+    */
+
+    @Transactional
+    public String importANMRegData( String importFile, MobileImportParameters mobImportParameters )
+    {
+        String importStatus="";
+
+        try
+        {
+            User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
+
+            if ( curUser != null )
+            {
+                UserCredentials userCredentials = userStore.getUserCredentials( curUser );
+
+                if ( (userCredentials != null)
+                    && (mobImportParameters.getMobileNumber().equals( curUser.getPhoneNumber() )) )
+                {
+                }
+                else
+                {
+                    LOG.error( " Import File Contains Unrecognised Phone Numbers : "
+                        + mobImportParameters.getMobileNumber() );
+                    moveFailedFile( importFile );
+                    return "Phone number is not registered to any facility. Please contact admin";
+                }
+
+                List<OrganisationUnit> sources = new ArrayList<OrganisationUnit>( curUser.getOrganisationUnits() );
+
+                if ( sources == null || sources.size() <= 0 )
+                {
+                    LOG.error( " No User Exists with corresponding Phone Numbers : "
+                        + mobImportParameters.getMobileNumber() );
+                    moveFailedFile( importFile );
+                    
+                    return "Phone number is not registered to any facility. Please contact admin";
+                }
+                
+                OrganisationUnit source = sources.get( 0 );
+                String anmName = mobImportParameters.getAnmName();
+
+                if ( source == null || anmName == null || anmName.trim().equalsIgnoreCase( "" ) )
+                {
+                    LOG.error( importFile + " Import File is not Properly Formated" );
+                    moveFailedFile( importFile );
+                    
+                    return "Data not Received Properly, Please send again";
+                }
+
+                source.setComment( anmName );
+                
+                organisationUnitService.updateOrganisationUnit( source );
+
+                moveImportedFile( importFile );
+                
+               importStatus = "YOUR NAME IS REGISTERD SUCCESSFULLY";
+            }
+            else
+            {
+                LOG.error( importFile + " Phone number not found... Sending to Bounced" );
+                importStatus = "Phone number is not registered to any facility. Please contact admin";
+                moveFailedFile( importFile );
+            }
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            LOG.error( e.getMessage() );
+            LOG.error( "Exception caused in importing... Moving to Bounced" );
+            
+            importStatus = "Data not Received Properly, Please send again";
+            moveFailedFile( importFile );
+        }
+        finally
+        {
+        }
+
+        return importStatus;
+    }
     
     @Override
     @Transactional
     public String importXMLFile( String importFile )
     {
-        //BatchHandler<DataValue> batchHandler = batchHandlerFactory.createBatchHandler( DataValueBatchHandler.class );
-        //batchHandler.init();
-        
         int insertFlag = 1;
-        //StringBuffer insertQuery = new StringBuffer( "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ") ;
         String insertQuery = "INSERT INTO datavalue (dataelementid, periodid, sourceid, categoryoptioncomboid, value, storedby, lastupdated ) VALUES ";
         String importStatus="";
 
@@ -1017,6 +1034,14 @@
                 return "Data not Received Properly, Please send again";
             }
 
+            // Checking for FormType, if formtype is ANMREG
+            if( mobImportParameters.getFormType().equalsIgnoreCase( MobileImportParameters.FORM_TYPE_ANMREGFORM ) )
+            {
+                importStatus = importANMRegData( importFile, mobImportParameters );
+                
+                return importStatus;
+            }
+            
             User curUser = getUserInfo( mobImportParameters.getMobileNumber() );
 
             if ( curUser != null )
@@ -1076,26 +1101,17 @@
                 {
                     LOG.error( "dataValue map is null" );
                 }
-                else
-                {
-                    if ( source == null )
-                    {
-                        LOG.error( "source is null" );
-                    }
-                    else
-                    {
-                        if ( period == null )
-                        {
-                            LOG.error( "period is null" );
-                        }
-                        else
-                        {
-                            if ( timeStamp == null )
-                            {
-                                LOG.error( "timeStamp is null" );
-                            }
-                        }
-                    }
+                else if ( source == null )
+                {
+                    LOG.error( "source is null" );
+                }
+                else if ( period == null )
+                {
+                    LOG.error( "period is null" );
+                }
+                else if ( timeStamp == null )
+                {
+                    LOG.error( "timeStamp is null" );
                 }
 
                 if ( source == null || period == null || timeStamp == null || dataValueMap == null
@@ -1128,25 +1144,14 @@
                         .valueOf( optStr ) );
 
                     DataValue dataValue = dataValueService.getDataValue( source, dataElement, period, optionCombo );
-                    //DataValue dataValue = new DataValue( dataElement, period, source, value, storedBy, timeStamp, null, optionCombo );
-                    //boolean exists = batchHandler.objectExists( dataValue );
 
                     if ( dataValue == null )
                     {
                         if ( value != null )
                         {
-                            //dataValue = new DataValue( dataElement, period, source, value, storedBy, timeStamp, null, optionCombo );
-                            
-                            //insertQuery.append( "( "+ dataElement.getId() + ", " + period.getId() + ", "+ source.getId() +", " + optionCombo.getId() + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ), " );
                             insertQuery += "( "+ dataElement.getId() + ", " + period.getId() + ", "+ source.getId() +", " + optionCombo.getId() + ", '" + value + "', '" + storedBy + "', '" + lastUpdatedDate + "' ), ";
-                            
-                            //System.out.println( insertQuery );
-                            
+
                             insertFlag = 2;
-                            
-                            //jdbcTemplate.update( insertQuery );
-                            //dataValueService.addDataValue( dataValue );
-                            //batchHandler.addObject( dataValue );
                         }
                     }
                     else
@@ -1158,16 +1163,12 @@
                         dataValue.setStoredBy( storedBy );
 
                         dataValueService.updateDataValue( dataValue );
-                        //batchHandler.updateObject( dataValue );
                     }
                 }
                 
                 if( insertFlag != 1 )
                 {
-                 
                     insertQuery = insertQuery.substring( 0, insertQuery.length()-2 );
-                    //insertQuery += ";";
-                    //System.out.println( insertQuery );
                     
                     jdbcTemplate.update( insertQuery );
                 }
@@ -1205,7 +1206,6 @@
         }
         finally
         {
-            //batchHandler.flush();
         }
 
         return importStatus;

=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java	2010-11-17 07:27:27 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportParameters.java	2010-11-24 13:37:22 +0000
@@ -34,6 +34,12 @@
 public class MobileImportParameters implements Serializable
 {
 
+    public static final String FORM_TYPE_ANMREGFORM = "anmregform";
+    public static final String FORM_TYPE_DATAFORM = "dataform";
+    public static final String ANMREG_FORM_ID = "ANMRF";
+    
+    private String formType;
+    
     private String mobileNumber;
 
     private String startDate;
@@ -44,6 +50,8 @@
 
     private Map<String, String> dataValues;
 
+    private String anmName;
+    
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -103,5 +111,25 @@
     {
         this.dataValues = dataValues;
     }
+
+    public String getFormType()
+    {
+        return formType;
+    }
+
+    public void setFormType( String formType )
+    {
+        this.formType = formType;
+    }
+
+    public String getAnmName()
+    {
+        return anmName;
+    }
+
+    public void setAnmName( String anmName )
+    {
+        this.anmName = anmName;
+    }
     
 }

=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java	2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/MobileImportService.java	2010-11-24 13:37:22 +0000
@@ -47,7 +47,7 @@
 
     public void moveFailedFile( String fileName );
 
-    public void importAllFiles();
+    //public void importAllFiles();
     
     public String importXMLFile( String importFile );
     

=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java	2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/XmlCreatorService.java	2010-11-24 13:37:22 +0000
@@ -85,6 +85,22 @@
     @Override
     public void run()
     {
+        String[] text = info.split( "#" );
+        text = text[1].split( "\\*" );
+        String formID = text[0];
+        
+        if( formID.equalsIgnoreCase( MobileImportParameters.ANMREG_FORM_ID ) )
+        {
+            createXMLFileForANMRegForm();
+        }
+        else
+        {
+            createXMLFileForDataValueForm();
+        }
+    }
+    
+    void createXMLFileForDataValueForm()
+    {
         //System.out.println( "Info to convert to XML: " + info );
         String dhis2Home = System.getenv( "DHIS2_HOME" );
         String[] text = info.split( "#" );
@@ -109,6 +125,7 @@
             FileWriter writer = new FileWriter( file );
             writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
             writer.write( "<mxf version=\"" + msgVersion + "\">\n" );
+            writer.write( "<formtype>" + MobileImportParameters.FORM_TYPE_DATAFORM + "</formtype>\n" );
             writer.write( "<source>" + phoneNumber + "</source>\n" );
             writer.write( "<periodType>" + periodType + "</periodType>\n" );
             writer.write( "<period>" + period + "</period>\n" );
@@ -117,19 +134,67 @@
             {
                 if ( ( dataValues.length - 1 ) < i || dataValues[i].isEmpty() )
                 {
-                } else
+                } 
+                else
                 {
                     writer.write( "<dataValue>\n" );
                     writer.write( "<dataElement>" + elementIds[i] + "</dataElement>\n" );
                     writer.write( "<value>" + dataValues[i] + "</value>\n" );
                     writer.write( "</dataValue>\n" );
                 }
-
-            }
-            writer.write( "<info>" + info + "</info>\n" );
-            writer.write( "</mxf>\n" );
-            writer.close();
-        } catch (Exception e)
+            }
+            writer.write( "<info>" + info + "</info>\n" );
+            writer.write( "</mxf>\n" );
+            writer.close();
+        } 
+        catch (Exception e)
+        {
+            System.out.println("Exception while creating XML File"+ e.getMessage());
+            return;
+        }
+    }
+    
+    void createXMLFileForANMRegForm()
+    {
+        String dhis2Home = System.getenv( "DHIS2_HOME" );
+        String[] text = info.split( "#" );
+        String msgVersion = text[0];
+        text = text[1].split( "\\*" );
+        String formID = text[0];
+        text = text[1].split( "\\?" );
+        String periodType = text[0];
+        text = text[1].split( "\\$" );
+        String period = text[0];
+        String anmName = text[1];
+
+        System.out.println("ANM Name: "+text[1] + " period : " + text[0]);
+        
+        try
+        {
+            File file = new File( dhis2Home + File.separator + "mi" + File.separator + "pending" + File.separator + phoneNumber + "_" +sendTime.replace( ":", "-" ) + ".xml" );
+            FileWriter writer = new FileWriter( file );
+            writer.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
+            writer.write( "<mxf version=\"" + msgVersion + "\">\n" );
+            writer.write( "<formtype>" + MobileImportParameters.FORM_TYPE_ANMREGFORM + "</formtype>\n" );
+            writer.write( "<source>" + phoneNumber + "</source>\n" );
+            writer.write( "<periodType>" + periodType + "</periodType>\n" );
+            writer.write( "<period>" + period + "</period>\n" );
+            writer.write( "<timeStamp>" + sendTime + "</timeStamp>\n" );
+
+            if( anmName != null && !anmName.trim().equalsIgnoreCase( "" ) )
+            {
+                writer.write( "<anmname>" + anmName + "</anmname>\n" );
+            }
+            else
+            {
+                writer.write( "<anmname> </anmname>\n" );
+            }
+            
+            writer.write( "<info>" + info + "</info>\n" );
+            writer.write( "</mxf>\n" );
+            writer.close();
+        } 
+        catch (Exception e)
         {
             System.out.println("Exception while creating XML File"+ e.getMessage());
             return;

=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml	2010-10-21 06:32:42 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml	2010-11-24 13:37:22 +0000
@@ -23,6 +23,7 @@
 		<property name="smsService" ref="org.hisp.dhis.mobile.SmsService"/>
         <property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
 		<property name="sendSMSService" ref="org.hisp.dhis.mobile.api.SendSMSService"/>
+		<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
 		<property name="batchHandlerFactory" ref="batchHandlerFactory"/>
 		<property name="jdbcTemplate" ref="jdbcTemplate"/>
     </bean>

=== modified file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/DraftPageAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/DraftPageAction.java	2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/DraftPageAction.java	2010-11-24 13:37:22 +0000
@@ -1,9 +1,7 @@
 package org.hisp.dhis.mobile.action;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.hisp.dhis.mobile.SmsService;
 import org.hisp.dhis.mobile.api.SendSMS;
@@ -38,24 +36,6 @@
     
     public void setSendPendingSMS( String sendPendingSMS )
     {
-        /*
-        int draftCount = sendSMSService.getRowCount();
-        
-        if( draftCount == 0 )
-        {
-            this.result = "No Drafts to send";
-        }
-        else if( draftCount < 30 )
-        {
-            List<SendSMS> sendSMSList =  new ArrayList<SendSMS>( sendSMSService.getSendSMS( 0, draftCount ) );
-            this.result = smsService.sendMessages( sendSMSList );
-        }
-        else
-        {
-            List<SendSMS> sendSMSList =  new ArrayList<SendSMS>( sendSMSService.getSendSMS( 0, 29 ) );
-            this.result = smsService.sendMessages( sendSMSList );
-        }
-        */
         this.result = smsService.sendDrafts();
     }