← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10167: minor fix

 

------------------------------------------------------------
revno: 10167
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-03-13 15:59:09 +0700
message:
  minor fix
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/ProgramStageDataElement.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java
  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/ModelMapping.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/api/mobile/model/LWUITmodel/ProgramStageDataElement.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/ProgramStageDataElement.java	2013-02-25 06:32:56 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/ProgramStageDataElement.java	2013-03-13 08:59:09 +0000
@@ -33,7 +33,6 @@
 
 import org.hisp.dhis.api.mobile.model.Model;
 import org.hisp.dhis.api.mobile.model.ModelList;
-import org.hisp.dhis.api.mobile.model.OptionSet;
 
  /**
  * @author Nguyen Kim Lai
@@ -46,6 +45,8 @@
     
     private String type;
     
+    private String numberType;
+    
     private boolean compulsory;
 
     private ModelList categoryOptionCombos;
@@ -60,6 +61,15 @@
     {
         super.serialize( dout );
         dout.writeUTF( this.getType() );
+        if ( this.getNumberType() != null )
+        {    
+            dout.writeBoolean( true );
+            dout.writeUTF( this.getNumberType() );
+        }
+        else
+        {
+            dout.writeBoolean( false );
+        }
         dout.writeBoolean( this.isCompulsory() );
         
         List<Model> cateOptCombos = this.getCategoryOptionCombos().getModels();
@@ -96,11 +106,19 @@
     {
         super.deSerialize( dint );
         this.setType( dint.readUTF() );
+        if( dint.readBoolean() )
+        {
+            this.setNumberType( dint.readUTF() );
+        }
+        else
+        {
+            this.setNumberType( null );
+        }
         this.setCompulsory( dint.readBoolean() );
-        /*this.categoryOptionCombos = new ModelList();
+        this.categoryOptionCombos = new ModelList();
         this.categoryOptionCombos.deSerialize( dint );
         this.optionSet = new OptionSet();
-        this.optionSet.deSerialize( dint );*/
+        this.optionSet.deSerialize( dint );
         this.setValue( dint.readUTF() );
     }
     
@@ -164,4 +182,15 @@
     {
         this.optionSet = optionSet;
     }
+
+    public String getNumberType()
+    {
+        return numberType;
+    }
+
+    public void setNumberType( String numberType )
+    {
+        this.numberType = numberType;
+    }
+    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java	2013-03-08 10:17:23 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java	2013-03-13 08:59:09 +0000
@@ -92,7 +92,5 @@
             String option = dataInputStream.readUTF();
             options.add( option );
         }
-
     }
-
 }

=== 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-03-11 07:37:35 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java	2013-03-13 08:59:09 +0000
@@ -86,9 +86,9 @@
     implements ActivityReportingService
 {
     private static final String PROGRAM_STAGE_UPLOADED = "program_stage_uploaded";
-    
+
     private static final String PROGRAM_STAGE_SECTION_UPLOADED = "program_stage_section_uploaded";
-    
+
     private ActivityComparator activityComparator = new ActivityComparator();
 
     // -------------------------------------------------------------------------
@@ -116,15 +116,15 @@
     private ProgramInstanceService programInstanceService;
 
     private RelationshipService relationshipService;
-    
+
     private DataElementService dataElementService;
-    
+
     private PatientDataValueService patientDataValueService;
-    
+
     private ProgramService programService;
-    
+
     private OrganisationUnitService organisationUnitService;
-    
+
     private org.hisp.dhis.mobile.service.ModelMapping modelMapping;
 
     // -------------------------------------------------------------------------
@@ -333,6 +333,200 @@
 
     }
 
+    @Override
+    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient findPatient( String fullName, int orgUnitId )
+        throws NotAllowedException
+    {
+        int startIndex = fullName.indexOf( ' ' );
+        int endIndex = fullName.lastIndexOf( ' ' );
+
+        String firstName = fullName.toString();
+        String middleName = " ";
+        String lastName = " ";
+
+        if ( fullName.indexOf( ' ' ) != -1 )
+        {
+            firstName = fullName.substring( 0, startIndex );
+            if ( startIndex == endIndex )
+            {
+                middleName = "  ";
+                lastName = fullName.substring( startIndex + 1, fullName.length() );
+            }
+            else
+            {
+                middleName = " " + fullName.substring( startIndex + 1, endIndex ) + " ";
+                lastName = fullName.substring( endIndex + 1, fullName.length() );
+            }
+        }
+        List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
+            + lastName, orgUnitId );
+
+        if ( patients.size() > 1 )
+        {
+            throw NotAllowedException.NEED_MORE_SPECIFIC;
+        }
+        else if ( patients.size() == 0 )
+        {
+            throw NotAllowedException.NO_BENEFICIARY_FOUND;
+        }
+        else
+        {
+            org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient = getPatientModel( orgUnitId, patients.get( 0 ) );
+
+            return patient;
+        }
+    }
+
+    @Override
+    public String saveProgramStage( org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage programStage )
+        throws NotAllowedException
+    {
+        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( programStage
+            .getId() );
+
+        List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> dataElements = programStage
+            .getDataElements();
+
+        for ( int i = 0; i < dataElements.size(); i++ )
+        {
+            DataElement dataElement = dataElementService.getDataElement( dataElements.get( i ).getId() );
+
+            PatientDataValue patientDataValue = new PatientDataValue( programStageInstance, dataElement, new Date(),
+                dataElements.get( i ).getValue() );
+
+            PatientDataValue previousPatientDataValue = patientDataValueService.getPatientDataValue(
+                patientDataValue.getProgramStageInstance(), patientDataValue.getDataElement() );
+
+            if ( previousPatientDataValue == null )
+            {
+                patientDataValueService.savePatientDataValue( patientDataValue );
+            }
+            else
+            {
+                previousPatientDataValue.setValue( patientDataValue.getValue() );
+                previousPatientDataValue.setTimestamp( new Date() );
+                previousPatientDataValue.setProvidedElsewhere( patientDataValue.getProvidedElsewhere() );
+                patientDataValueService.updatePatientDataValue( previousPatientDataValue );
+            }
+
+        }
+
+        programStageInstance.setExecutionDate( new Date() );
+
+        if ( programStageInstance.getProgramStage().getProgramStageDataElements().size() > dataElements.size() )
+        {
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
+            return PROGRAM_STAGE_SECTION_UPLOADED;
+        }
+        else
+        {
+            programStageInstance.setCompleted( true );
+
+            // check if any compulsory value is null
+            for ( int i = 0; i < dataElements.size(); i++ )
+            {
+                if ( dataElements.get( i ).isCompulsory() == true )
+                {
+                    if ( dataElements.get( i ).getValue().equals( "" ) )
+                    {
+                        programStageInstance.setCompleted( false );
+                        // break;
+                        throw NotAllowedException.INVALID_PROGRAM_STAGE;
+                    }
+                }
+            }
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
+            
+            // check if all belonged program stage are completed
+            if ( isAllProgramStageFinished( programStageInstance ) == true )
+            {
+                ProgramInstance programInstance = programStageInstance.getProgramInstance();
+                programInstance.setCompleted( true );
+                programInstanceService.updateProgramInstance( programInstance );
+            }
+            
+            return PROGRAM_STAGE_UPLOADED;
+        }
+    }
+    
+    private boolean isAllProgramStageFinished( ProgramStageInstance programStageInstance )
+    {
+        ProgramInstance programInstance = programStageInstance.getProgramInstance();
+        Collection<ProgramStageInstance> programStageInstances =  programInstance.getProgramStageInstances();
+        if ( programStageInstances != null )
+        {
+            Iterator<ProgramStageInstance> iterator = programStageInstances.iterator();
+
+            while ( iterator.hasNext() )
+            {
+                ProgramStageInstance each = iterator.next();
+                if( !each.isCompleted() )
+                {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo, int orgUnitId )
+        throws NotAllowedException
+    {
+        String[] enrollProgramInfos = enrollInfo.split( "-" );
+        int patientId = Integer.parseInt( enrollProgramInfos[0] );
+        int programId = Integer.parseInt( enrollProgramInfos[1] );
+
+        Patient patient = patientService.getPatient( patientId );
+        Program program = programService.getProgram( programId );
+
+        ProgramInstance programInstance = new ProgramInstance();
+        // programInstance.setEnrollmentDate( sdf.parseDateTime( enrollmentDate
+        // ).toDate() );
+        // programInstance.setDateOfIncident( sdf.parseDateTime( incidentDate
+        // ).toDate() );
+        programInstance.setEnrollmentDate( new Date() );
+        programInstance.setDateOfIncident( new Date() );
+        programInstance.setProgram( program );
+        programInstance.setPatient( patient );
+        programInstance.setCompleted( false );
+        programInstanceService.addProgramInstance( programInstance );
+        patient.getPrograms().add( program );
+        patientService.updatePatient( patient );
+        for ( ProgramStage programStage : program.getProgramStages() )
+        {
+            if ( programStage.getAutoGenerateEvent() )
+            {
+                ProgramStageInstance programStageInstance = new ProgramStageInstance();
+                programStageInstance.setProgramInstance( programInstance );
+                programStageInstance.setProgramStage( programStage );
+
+                // Date dateCreatedEvent = sdf.parseDateTime( incidentDate
+                // ).toDate();
+                Date dateCreatedEvent = new Date();
+                if ( program.getGeneratedByEnrollmentDate() )
+                {
+                    // dateCreatedEvent = sdf.parseDateTime( enrollmentDate
+                    // ).toDate();
+                }
+                Date dueDate = DateUtils.getDateAfterAddition( dateCreatedEvent, programStage.getMinDaysFromStart() );
+
+                programStageInstance.setDueDate( dueDate );
+
+                if ( program.isSingleEvent() )
+                {
+                    programStageInstance.setExecutionDate( dueDate );
+                }
+
+                programStageInstanceService.addProgramStageInstance( programStageInstance );
+
+            }
+
+        }
+
+        return getPatientModel( orgUnitId, patient );
+    }
+
     // -------------------------------------------------------------------------
     // Supportive method
     // -------------------------------------------------------------------------
@@ -455,7 +649,7 @@
     }
 
     // get patient model for LWUIT
-    private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel(int orgUnitId, Patient patient )
+    private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( int orgUnitId, Patient patient )
     {
         org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientModel = new org.hisp.dhis.api.mobile.model.LWUITmodel.Patient();
         List<PatientAttribute> patientAtts = new ArrayList<PatientAttribute>();
@@ -559,7 +753,7 @@
                 mobileProgram.setName( each.getProgram().getName() );
                 mobileProgram.setCompleted( each.isCompleted() );
                 mobileProgram.setProgramStages( getMobileProgramStages( patient, each, each.getProgram() ) );
-                
+
                 mobileProgramList.add( mobileProgram );
             }
         }
@@ -587,7 +781,7 @@
             relationshipList.add( relationshipMobile );
         }
         patientModel.setRelationships( relationshipList );
-        
+
         // Set available enrollment programs
         List<Program> enrollmentProgramList = new ArrayList<Program>();
         enrollmentProgramList = generateEnrollmentProgramList( orgUnitId, patient );
@@ -602,25 +796,26 @@
             enrollmentProgramMobile.setProgramStages( null );
             enrollmentProgramListMobileList.add( enrollmentProgramMobile );
         }
-        
+
         patientModel.setEnrollmentPrograms( enrollmentProgramListMobileList );
-        
+
         return patientModel;
     }
 
-    private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> getMobileProgramStages( Patient patient, ProgramInstance programInstance,
-        Program program )
+    private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> getMobileProgramStages( Patient patient,
+        ProgramInstance programInstance, Program program )
     {
-        
+
         List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage> mobileProgramStages = new ArrayList<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage>();
         for ( ProgramStage eachProgramStage : program.getProgramStages() )
         {
-            ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( programInstance, eachProgramStage );
+            ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(
+                programInstance, eachProgramStage );
             org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage = new org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage();
             List<org.hisp.dhis.api.mobile.model.LWUITmodel.Section> mobileSections = new ArrayList<org.hisp.dhis.api.mobile.model.LWUITmodel.Section>();
             mobileProgramStage.setId( programStageInstance.getId() );
             mobileProgramStage.setName( eachProgramStage.getName() );
-            
+
             // is repeatable
             mobileProgramStage.setRepeatable( eachProgramStage.getIrregular() );
 
@@ -628,8 +823,8 @@
             mobileProgramStage.setCompleted( checkIfProgramStageCompleted( patient, program, eachProgramStage ) );
 
             // Set all data elements
-            mobileProgramStage.setDataElements( getDataElementsForMobile( eachProgramStage,programStageInstance ) );
-            
+            mobileProgramStage.setDataElements( getDataElementsForMobile( eachProgramStage, programStageInstance ) );
+
             // Set all program sections
             if ( eachProgramStage.getProgramStageSections().size() > 0 )
             {
@@ -638,10 +833,12 @@
                     org.hisp.dhis.api.mobile.model.LWUITmodel.Section mobileSection = new org.hisp.dhis.api.mobile.model.LWUITmodel.Section();
                     mobileSection.setId( eachSection.getId() );
                     mobileSection.setName( eachSection.getName() );
-                    
-                    // Set all data elements' id, then we could have full from data element list of program stage
+
+                    // Set all data elements' id, then we could have full from
+                    // data element list of program stage
                     List<Integer> dataElementIds = new ArrayList<Integer>();
-                    for ( ProgramStageDataElement eachPogramStageDataElement : eachSection.getProgramStageDataElements() )
+                    for ( ProgramStageDataElement eachPogramStageDataElement : eachSection
+                        .getProgramStageDataElements() )
                     {
                         dataElementIds.add( eachPogramStageDataElement.getDataElement().getId() );
                     }
@@ -672,10 +869,12 @@
         }
         return programStageInstance.isCompleted();
     }
-    
-    private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> getDataElementsForMobile( ProgramStage programStage, ProgramStageInstance programStageInstance )
+
+    private List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> getDataElementsForMobile(
+        ProgramStage programStage, ProgramStageInstance programStageInstance )
     {
-        List<ProgramStageDataElement> programStageDataElements = new ArrayList<ProgramStageDataElement>(programStage.getProgramStageDataElements());
+        List<ProgramStageDataElement> programStageDataElements = new ArrayList<ProgramStageDataElement>(
+            programStage.getProgramStageDataElements() );
         List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> mobileDataElements = new ArrayList<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement>();
         for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
         {
@@ -683,27 +882,35 @@
             mobileDataElement.setId( programStageDataElement.getDataElement().getId() );
             mobileDataElement.setName( programStageDataElement.getDataElement().getName() );
             mobileDataElement.setType( programStageDataElement.getDataElement().getType() );
-            mobileDataElement.setCompulsory( programStageDataElement.isCompulsory()  );
-            PatientDataValue patientDataValue = dataValueService.getPatientDataValue( programStageInstance, programStageDataElement.getDataElement() );
-            if( patientDataValue != null )
+            if ( programStageDataElement.getDataElement().getNumberType() != null )
+            {
+                mobileDataElement.setCompulsory( programStageDataElement.isCompulsory() );
+            }
+            mobileDataElement.setNumberType( programStageDataElement.getDataElement().getNumberType() );
+
+            PatientDataValue patientDataValue = dataValueService.getPatientDataValue( programStageInstance,
+                programStageDataElement.getDataElement() );
+            if ( patientDataValue != null )
             {
                 mobileDataElement.setValue( patientDataValue.getValue() );
             }
             else
             {
-                mobileDataElement.setValue("");
+                mobileDataElement.setValue( "" );
             }
-            if(programStageDataElement.getDataElement().getOptionSet() != null)
+            if ( programStageDataElement.getDataElement().getOptionSet() != null )
             {
-                mobileDataElement.setOptionSet( modelMapping.getOptionSet( programStageDataElement.getDataElement()));
+                mobileDataElement.setOptionSet( modelMapping.getLWUITOptionSet( programStageDataElement
+                    .getDataElement() ) );
             }
             else
             {
                 mobileDataElement.setOptionSet( null );
             }
-            if( programStageDataElement.getDataElement().getCategoryCombo() != null )
+            if ( programStageDataElement.getDataElement().getCategoryCombo() != null )
             {
-                mobileDataElement.setCategoryOptionCombos( modelMapping.getCategoryOptionCombos( programStageDataElement.getDataElement() ) );
+                mobileDataElement.setCategoryOptionCombos( modelMapping
+                    .getCategoryOptionCombos( programStageDataElement.getDataElement() ) );
             }
             else
             {
@@ -724,6 +931,24 @@
         return setting;
     }
 
+    private List<Program> generateEnrollmentProgramList( int orgId, Patient patient )
+    {
+        List<Program> programs = new ArrayList<Program>();
+        for ( Program program : programService.getPrograms( organisationUnitService.getOrganisationUnit( orgId ) ) )
+
+        {
+            if ( (program.isSingleEvent() && program.isRegistration()) || !program.isSingleEvent() )
+            {
+                // wrong here
+                if ( programInstanceService.getProgramInstances( patient, program ).size() == 0 )
+                {
+                    programs.add( program );
+                }
+            }
+        }
+        return programs;
+    }
+
     private void saveDataValues( ActivityValue activityValue, ProgramStageInstance programStageInstance,
         Map<Integer, DataElement> dataElementMap )
     {
@@ -865,7 +1090,7 @@
     {
         this.programStageSectionService = programStageSectionService;
     }
-    
+
     @Required
     public void setDataElementService( DataElementService dataElementService )
     {
@@ -889,180 +1114,4 @@
     {
         this.programService = programService;
     }
-
-    @Override
-    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient findPatient( String fullName, int orgUnitId )
-        throws NotAllowedException
-    {
-        int startIndex = fullName.indexOf( ' ' );
-        int endIndex = fullName.lastIndexOf( ' ' );
-
-        String firstName = fullName.toString();
-        String middleName = " ";
-        String lastName = " ";
-
-        if ( fullName.indexOf( ' ' ) != -1 )
-        {
-            firstName = fullName.substring( 0, startIndex );
-            if ( startIndex == endIndex )
-            {
-                middleName = "  ";
-                lastName = fullName.substring( startIndex + 1, fullName.length() );
-            }
-            else
-            {
-                middleName = " " + fullName.substring( startIndex + 1, endIndex ) + " ";
-                lastName = fullName.substring( endIndex + 1, fullName.length() );
-            }
-        }
-        List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
-            + lastName, orgUnitId );
-
-        if ( patients.size() > 1 )
-        {
-            throw NotAllowedException.NEED_MORE_SPECIFIC;
-        }
-        else if ( patients.size() == 0 )
-        {
-            throw NotAllowedException.NO_BENEFICIARY_FOUND;
-        }
-        else
-        {
-            org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient = getPatientModel( orgUnitId, patients.get( 0 ) );
-
-            return patient;
-        }
-    }
-
-    @Override
-    public String saveProgramStage( org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage programStage )
-        throws NotAllowedException
-    {
-        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( programStage.getId() );
-        
-        List<org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement> dataElements = programStage.getDataElements();
-        
-        for ( int i = 0; i < dataElements.size(); i++ )
-        {
-            DataElement dataElement = dataElementService.getDataElement( dataElements.get( i ).getId() );
-            
-            PatientDataValue patientDataValue = new PatientDataValue( programStageInstance, dataElement, new Date(), dataElements.get( i ).getValue());
-            
-            PatientDataValue previousPatientDataValue = patientDataValueService.getPatientDataValue( patientDataValue.getProgramStageInstance(), patientDataValue.getDataElement() );
-
-            if ( previousPatientDataValue == null )
-            {
-                patientDataValueService.savePatientDataValue( patientDataValue );
-            }
-            else
-            {
-                previousPatientDataValue.setValue( patientDataValue.getValue() );
-                previousPatientDataValue.setTimestamp( new Date() );
-                previousPatientDataValue.setProvidedElsewhere( patientDataValue.getProvidedElsewhere() );
-                patientDataValueService.updatePatientDataValue( previousPatientDataValue );
-            }
-            
-        }
-        
-        programStageInstance.setExecutionDate( new Date() );
-        
-        if( programStageInstance.getProgramStage().getProgramStageDataElements().size() > dataElements.size() )
-        {
-            programStageInstanceService.updateProgramStageInstance( programStageInstance );
-            return PROGRAM_STAGE_SECTION_UPLOADED;
-        }
-        else
-        {
-            programStageInstance.setCompleted ( true );
-            
-            // check if any compulsory value is null
-            for ( int i = 0; i < dataElements.size(); i++ )
-            {
-                if ( dataElements.get( i ).isCompulsory() == true  )
-                {
-                    if ( dataElements.get( i ).getValue().equals( "" ) )
-                    {
-                        programStageInstance.setCompleted( false );
-                        //break;
-                        throw NotAllowedException.INVALID_PROGRAM_STAGE;        
-                    }
-                }
-            }
-            programStageInstanceService.updateProgramStageInstance( programStageInstance );
-            return PROGRAM_STAGE_UPLOADED;
-        }
-    }
-    
-    private List<Program> generateEnrollmentProgramList( int orgId, Patient patient )
-    {
-        List<Program> programs = new ArrayList<Program>();
-        for ( Program program : programService.getPrograms( organisationUnitService.getOrganisationUnit( orgId ) ) )
-
-        {
-            if ( (program.isSingleEvent() && program.isRegistration()) || !program.isSingleEvent() )
-            {
-                //wrong here
-                if ( programInstanceService.getProgramInstances( patient, program ).size() == 0 )
-                {
-                    programs.add( program );
-                }
-            }
-        }
-        return programs;
-    }
-
-    @Override
-    public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo, int orgUnitId )
-        throws NotAllowedException
-    {
-        String[] enrollProgramInfos = enrollInfo.split( "-" );
-        int patientId = Integer.parseInt( enrollProgramInfos[0] );
-        int programId = Integer.parseInt( enrollProgramInfos[1] );
-
-        Patient patient = patientService.getPatient( patientId );
-        Program program = programService.getProgram( programId );
-        
-        ProgramInstance programInstance = new ProgramInstance();
-        //programInstance.setEnrollmentDate( sdf.parseDateTime( enrollmentDate ).toDate() );
-        //programInstance.setDateOfIncident( sdf.parseDateTime( incidentDate ).toDate() );
-        programInstance.setEnrollmentDate( new Date() );
-        programInstance.setDateOfIncident( new Date() );
-        programInstance.setProgram( program );
-        programInstance.setPatient( patient );
-        programInstance.setCompleted( false );
-        programInstanceService.addProgramInstance( programInstance );
-        patient.getPrograms().add( program );
-        patientService.updatePatient( patient );
-        for ( ProgramStage programStage : program.getProgramStages() )
-        {
-            if ( programStage.getAutoGenerateEvent() )
-            {
-                ProgramStageInstance programStageInstance = new ProgramStageInstance();
-                programStageInstance.setProgramInstance( programInstance );
-                programStageInstance.setProgramStage( programStage );
-                
-                //Date dateCreatedEvent = sdf.parseDateTime( incidentDate ).toDate();
-                Date dateCreatedEvent = new Date();
-                if ( program.getGeneratedByEnrollmentDate() )
-                {
-                    //dateCreatedEvent = sdf.parseDateTime( enrollmentDate ).toDate();
-                }
-                Date dueDate = DateUtils
-                .getDateAfterAddition( dateCreatedEvent, programStage.getMinDaysFromStart() );
-                
-                programStageInstance.setDueDate( dueDate );
-                
-                if ( program.isSingleEvent() )
-                {
-                    programStageInstance.setExecutionDate( dueDate );
-                }
-                
-                programStageInstanceService.addProgramStageInstance( programStageInstance );
-                
-            }
-        
-        }
-        
-        return getPatientModel( orgUnitId, patient );
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2012-07-20 08:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2013-03-13 08:59:09 +0000
@@ -67,7 +67,24 @@
         }
 
         return mobileOptionSet;
+    }
+    
+    public org.hisp.dhis.api.mobile.model.LWUITmodel.OptionSet getLWUITOptionSet( org.hisp.dhis.dataelement.DataElement dataElement )
+    {
+        org.hisp.dhis.option.OptionSet dhisOptionSet = dataElement.getOptionSet();
+        org.hisp.dhis.api.mobile.model.LWUITmodel.OptionSet mobileOptionSet = new org.hisp.dhis.api.mobile.model.LWUITmodel.OptionSet();
+        if ( dhisOptionSet != null )
+        {
+            mobileOptionSet.setId( dhisOptionSet.getId() );
+            mobileOptionSet.setName( dhisOptionSet.getName() );
+            mobileOptionSet.setOptions( dhisOptionSet.getOptions() );
+        }
+        else
+        {
+            return null;
+        }
 
+        return mobileOptionSet;
     }
 
     public ModelList getCategoryOptionCombos( org.hisp.dhis.dataelement.DataElement dataElement )