dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08514
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2054: [DHIS Mobile] Support sending CategoryOptionCombo for NBITS Reporting
------------------------------------------------------------
revno: 2054
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Sun 2010-11-14 00:48:18 +0700
message:
[DHIS Mobile] Support sending CategoryOptionCombo for NBITS Reporting
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.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-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java 2010-11-13 17:48:18 +0000
@@ -53,6 +53,7 @@
{
DataValue dv = (DataValue)dataValues.get(i);
dout.writeInt( dv.getId() );
+ dout.writeInt( dv.getCategoryOptComboID() );
dout.writeUTF( dv.getVal() );
}
@@ -72,7 +73,8 @@
{
DataValue dv = new DataValue();
dv.setId( din.readInt() );
- dv.setVal( din.readUTF() );
+ dv.setCategoryOptComboID( din.readInt() );
+ dv.setVal( din.readUTF() );
this.dataValues.add(dv);
}
}
@@ -89,6 +91,7 @@
{
DataValue dv = new DataValue();
dv.setId( din.readInt() );
+ dv.setCategoryOptComboID( din.readInt() );
dv.setVal( din.readUTF() );
this.dataValues.add(dv);
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 2010-11-01 06:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 2010-11-13 17:48:18 +0000
@@ -1,4 +1,5 @@
package org.hisp.dhis.web.api.model;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -7,80 +8,103 @@
/**
* @author Tran Ng Minh Luan
- *
+ *
*/
-public class MobileWrapper implements ISerializable{
- private ActivityPlan activityPlan;
+public class MobileWrapper
+ implements ISerializable
+{
+ private ActivityPlan activityPlan;
+
private List<Program> programs;
+
private List<DataSet> datasets;
-
- public MobileWrapper() {
- }
-
- public ActivityPlan getActivityPlan() {
- return activityPlan;
- }
-
- public void setActivityPlan(ActivityPlan activityPlan) {
- this.activityPlan = activityPlan;
- }
-
- public List<Program> getPrograms() {
- return programs;
- }
-
- public void setPrograms(List<Program> programs) {
- this.programs = programs;
- }
-
- public List<DataSet> getDatasets() {
- return datasets;
- }
-
- public void setDatasets(List<DataSet> datasets) {
- this.datasets = datasets;
- }
-
- public void serialize(OutputStream out) throws IOException
- {
-
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream(bout);
-
- if(programs != null){
- dout.writeInt(programs.size());
- }else{
- dout.writeInt(0);
- }
-
- //Write ActivityPlans
- if(this.activityPlan == null){
- dout.writeInt(0);
- }else{
- this.activityPlan.serialize( dout );
- }
-
- //Write Programs
- if(programs != null || programs.size() > 0){
- for(Program prog : programs){
- prog.serialize( dout );
- }
- }
-
- //Write DataSets
- if(datasets == null){
- dout.writeInt(0);
- }else{
- dout.writeInt(datasets.size());
- for(DataSet ds : datasets){
- ds.serialize(dout);
- }
- }
-
+
+ public MobileWrapper()
+ {
+ }
+
+ public ActivityPlan getActivityPlan()
+ {
+ return activityPlan;
+ }
+
+ public void setActivityPlan( ActivityPlan activityPlan )
+ {
+ this.activityPlan = activityPlan;
+ }
+
+ public List<Program> getPrograms()
+ {
+ return programs;
+ }
+
+ public void setPrograms( List<Program> programs )
+ {
+ this.programs = programs;
+ }
+
+ public List<DataSet> getDatasets()
+ {
+ return datasets;
+ }
+
+ public void setDatasets( List<DataSet> datasets )
+ {
+ this.datasets = datasets;
+ }
+
+ public void serialize( OutputStream out )
+ throws IOException
+ {
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream( bout );
+
+ if ( programs != null )
+ {
+ dout.writeInt( programs.size() );
+ }
+ else
+ {
+ dout.writeInt( 0 );
+ }
+
+ // Write ActivityPlans
+ if ( this.activityPlan == null )
+ {
+ dout.writeInt( 0 );
+ }
+ else
+ {
+ this.activityPlan.serialize( dout );
+ }
+
+ // Write Programs
+ if ( programs != null || programs.size() > 0 )
+ {
+ for ( Program prog : programs )
+ {
+ prog.serialize( dout );
+ }
+ }
+
+ // Write DataSets
+ if ( datasets == null )
+ {
+ dout.writeInt( 0 );
+ }
+ else
+ {
+ dout.writeInt( datasets.size() );
+ for ( DataSet ds : datasets )
+ {
+ ds.serialize( dout );
+ }
+ }
+
bout.flush();
- bout.writeTo(out);
-
+ bout.writeTo( out );
+
}
@Override
@@ -96,14 +120,7 @@
throws IOException
{
// TODO Auto-generated method stub
-
+
}
-
-
-
-
-
-
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java 2010-10-21 11:17:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java 2010-11-13 17:48:18 +0000
@@ -8,94 +8,116 @@
import java.io.OutputStream;
import java.util.List;
-public class ProgramStage extends AbstractModel {
-
- private List<DataElement> dataElements;
-
- public List<DataElement> getDataElements() {
- return dataElements;
- }
-
- public void setDataElements(List<DataElement> dataElements) {
- this.dataElements = dataElements;
- }
-
- public byte[] serialize() throws IOException
+public class ProgramStage
+ extends AbstractModel
+{
+
+ private List<DataElement> dataElements;
+
+ public List<DataElement> getDataElements()
+ {
+ return dataElements;
+ }
+
+ public void setDataElements( List<DataElement> dataElements )
+ {
+ this.dataElements = dataElements;
+ }
+
+ public byte[] serialize()
+ throws IOException
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream(bout);
-
- dout.writeInt(this.getId());
- dout.writeUTF(this.getName());
- dout.writeInt(dataElements.size());
-
- for(int i=0; i<dataElements.size(); i++)
+ DataOutputStream dout = new DataOutputStream( bout );
+
+ dout.writeInt( this.getId() );
+ dout.writeUTF( this.getName() );
+ dout.writeInt( dataElements.size() );
+
+ for ( int i = 0; i < dataElements.size(); i++ )
{
- DataElement de = (DataElement)dataElements.get(i);
+ DataElement de = (DataElement) dataElements.get( i );
dout.writeInt( de.getId() );
dout.writeUTF( de.getName() );
dout.writeUTF( de.getType() );
}
return bout.toByteArray();
- }
-
- public void serialize( OutputStream out ) throws IOException
+ }
+
+ public void serialize( OutputStream out )
+ throws IOException
{
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- DataOutputStream dout = new DataOutputStream(bout);
-
- dout.writeInt(this.getId());
- dout.writeUTF(this.getName());
-
- dout.writeInt(dataElements.size());
-
- for(int i=0; i<dataElements.size(); i++)
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ DataOutputStream dout = new DataOutputStream( bout );
+
+ dout.writeInt( this.getId() );
+ dout.writeUTF( this.getName() );
+
+ dout.writeInt( dataElements.size() );
+
+ for ( int i = 0; i < dataElements.size(); i++ )
{
- DataElement de = (DataElement)dataElements.get(i);
+ DataElement de = (DataElement) dataElements.get( i );
dout.writeInt( de.getId() );
dout.writeUTF( de.getName() );
dout.writeUTF( de.getType() );
- }
-
+
+ List<AbstractModel> cateOptCombos = de.getCategoryOptionCombos().getAbstractModels();
+ if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
+ {
+ dout.writeInt( 0 );
+ }
+ else
+ {
+ dout.writeInt( cateOptCombos.size() );
+ for ( AbstractModel each : cateOptCombos )
+ {
+ dout.writeInt( each.getId() );
+ dout.writeUTF( each.getName() );
+ }
+ }
+ }
+
bout.flush();
- bout.writeTo(out);
- }
-
-// public void serialize( DataOutputStream dout ) throws IOException
-// {
-// dout.writeInt(this.getId());
-// dout.writeUTF(this.getName());
-// dout.writeInt(dataElements.size());
-// System.out.println("add dataelement");
-// for(int i=0; i<dataElements.size(); i++)
-// {
-// DataElement de = (DataElement)dataElements.get(i);
-// dout.writeInt( de.getId() );
-// dout.writeUTF( de.getName() );
-// dout.writeUTF( de.getType() );
-// }
-//
-// dout.flush();
-// }
-
- public void deSerialize(byte[] data) throws IOException
+ bout.writeTo( out );
+ }
+
+ // public void serialize( DataOutputStream dout ) throws IOException
+ // {
+ // dout.writeInt(this.getId());
+ // dout.writeUTF(this.getName());
+ // dout.writeInt(dataElements.size());
+ // System.out.println("add dataelement");
+ // for(int i=0; i<dataElements.size(); i++)
+ // {
+ // DataElement de = (DataElement)dataElements.get(i);
+ // dout.writeInt( de.getId() );
+ // dout.writeUTF( de.getName() );
+ // dout.writeUTF( de.getType() );
+ // }
+ //
+ // dout.flush();
+ // }
+
+ public void deSerialize( byte[] data )
+ throws IOException
{
- ByteArrayInputStream bin = new ByteArrayInputStream(data);
- DataInputStream din = new DataInputStream(bin);
+ ByteArrayInputStream bin = new ByteArrayInputStream( data );
+ DataInputStream din = new DataInputStream( bin );
- this.setId( din.readInt() ) ;
- this.setName( din.readUTF() );
+ this.setId( din.readInt() );
+ this.setName( din.readUTF() );
int size = din.readInt();
- for(int i=0; i<size; i++)
+ for ( int i = 0; i < size; i++ )
{
DataElement de = new DataElement();
de.setId( din.readInt() );
de.setName( din.readUTF() );
de.setType( din.readUTF() );
- this.dataElements.add(de);
+ this.dataElements.add( de );
}
}
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java 2010-11-01 06:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java 2010-11-13 17:48:18 +0000
@@ -13,39 +13,38 @@
import org.hisp.dhis.web.api.service.IActivityValueService;
import org.springframework.beans.factory.annotation.Autowired;
-@Path("/activityplan")
-public class ActivityPlanResource {
+@Path( "/activityplan" )
+public class ActivityPlanResource
+{
-
- // -------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
- @Autowired
- private IActivityPlanService activityPlanService;
-
- @Autowired
- private IActivityValueService iactivityValueService;
-
-
- // -------------------------------------------------------------------------
+
+ @Autowired
+ private IActivityPlanService activityPlanService;
+
+ @Autowired
+ private IActivityValueService iactivityValueService;
+
+ // -------------------------------------------------------------------------
// Resources
- // -------------------------------------------------------------------------
-
- @GET
- @Path( "current" )
- @Produces( "application/vnd.org.dhis2.activityplan+serialized" )
- public ActivityPlan getCurrentActivityPlan(@HeaderParam("accept-language") String locale)
+ // -------------------------------------------------------------------------
+
+ @GET
+ @Path( "current" )
+ @Produces( "application/vnd.org.dhis2.activityplan+serialized" )
+ public ActivityPlan getCurrentActivityPlan( @HeaderParam( "accept-language" ) String locale )
{
return activityPlanService.getCurrentActivityPlan( locale );
}
-
- @POST
- @Path( "values" )
- @Consumes( "application/vnd.org.dhis2.activityvaluelist+serialized" )
- @Produces("application/xml")
- public String getValues(ActivityValue activityValue)
- {
- return iactivityValueService.saveValues(activityValue);
- }
+
+ @POST
+ @Path( "values" )
+ @Consumes( "application/vnd.org.dhis2.activityvaluelist+serialized" )
+ @Produces( "application/xml" )
+ public String getValues( ActivityValue activityValue )
+ {
+ return iactivityValueService.saveValues( activityValue );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java 2010-11-13 17:48:18 +0000
@@ -17,147 +17,156 @@
import org.hisp.dhis.web.api.model.DataValue;
import org.springframework.beans.factory.annotation.Autowired;
-public class DefaultActivityValueService implements IActivityValueService {
+public class DefaultActivityValueService
+ implements IActivityValueService
+{
- // -------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
- @Autowired
- private org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService;
-
- @Autowired
- private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
-
- @Autowired
- private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService;
-
- @Autowired
+
+ @Autowired
+ private org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService;
+
+ @Autowired
+ private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
+
+ @Autowired
+ private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService;
+
+ @Autowired
private CurrentUserService currentUserService;
-
-
- // -------------------------------------------------------------------------
+
+ // -------------------------------------------------------------------------
// DataValueService
// -------------------------------------------------------------------------
+ @Override
+ public String saveValues( ActivityValue activityValue )
+ {
- @Override
- public String saveValues(ActivityValue activityValue) {
-
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
+ Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
OrganisationUnit unit = null;
-
- if( units.size() > 0 )
+
+ if ( units.size() > 0 )
{
- unit = units.iterator().next();
+ unit = units.iterator().next();
}
else
{
- return "INVALID_SERVICE_PROVIDING_UNIT";
- }
-
- ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( activityValue.getProgramInstanceId() );
-
- if( programStageInstance == null )
- {
- return "INVALID_PROGRAM_STAGE";
- }
-
- programStageInstance.getProgramStage();
- Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
-
- for( ProgramStageDataElement de : programStageInstance.getProgramStage().getProgramStageDataElements() )
- {
- dataElements.add( de.getDataElement() );
- }
-
- programStageInstance.getProgramStage().getProgramStageDataElements();
- Collection<Integer> dataElementIds = new ArrayList<Integer>(activityValue.getDataValues().size());
-
- for( DataValue dv : activityValue.getDataValues() )
- {
- dataElementIds.add( dv.getId() );
- }
-
- if( dataElements.size() != dataElementIds.size() )
- {
- return "INVALID_PROGRAM_STAGE";
- }
-
- Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
- for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
- {
- if( !dataElementIds.contains( dataElement.getId()) )
- {
- return "INVALID_PROGRAM_STAGE";
- }
- dataElementMap.put(dataElement.getId(), dataElement);
- }
-
- //Everything is fine, hence save
- saveDataValues( activityValue, programStageInstance, dataElementMap, unit, categoryService.getDefaultDataElementCategoryOptionCombo() );
-
- return "SUCCESS";
-
- }
-
- // -------------------------------------------------------------------------
+ return "INVALID_SERVICE_PROVIDING_UNIT";
+ }
+
+ ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( activityValue
+ .getProgramInstanceId() );
+
+ if ( programStageInstance == null )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+
+ programStageInstance.getProgramStage();
+ Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
+
+ for ( ProgramStageDataElement de : programStageInstance.getProgramStage().getProgramStageDataElements() )
+ {
+ dataElements.add( de.getDataElement() );
+ }
+
+ programStageInstance.getProgramStage().getProgramStageDataElements();
+ Collection<Integer> dataElementIds = new ArrayList<Integer>( activityValue.getDataValues().size() );
+
+ for ( DataValue dv : activityValue.getDataValues() )
+ {
+ dataElementIds.add( dv.getId() );
+ }
+
+ if ( dataElements.size() != dataElementIds.size() )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+
+ Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
+ for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
+ {
+ if ( !dataElementIds.contains( dataElement.getId() ) )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+ dataElementMap.put( dataElement.getId(), dataElement );
+ }
+
+ // Everything is fine, hence save
+ saveDataValues( activityValue, programStageInstance, dataElementMap, unit,
+ categoryService.getDefaultDataElementCategoryOptionCombo() );
+
+ return "SUCCESS";
+
+ }
+
+ // -------------------------------------------------------------------------
// Supportive method
// -------------------------------------------------------------------------
-
- private void saveDataValues(ActivityValue activityValue, ProgramStageInstance programStageInstance,
- Map<Integer, DataElement> dataElementMap, OrganisationUnit orgUnit, DataElementCategoryOptionCombo optionCombo) {
-
-
- org.hisp.dhis.dataelement.DataElement dataElement;
- String value;
-
- for( DataValue dv : activityValue.getDataValues() )
- {
- value = dv.getVal();
-
- if ( value != null && value.trim().length() == 0 )
- {
- value = null;
- }
-
- if ( value != null )
- {
- value = value.trim();
- }
-
- dataElement = dataElementMap.get( dv.getId() );
- PatientDataValue dataValue = dataValueService.getPatientDataValue(programStageInstance, dataElement, orgUnit);
-
- if ( dataValue == null )
- {
- if( value != null )
- {
- if ( programStageInstance.getExecutionDate() == null )
- {
- programStageInstance.setExecutionDate( new Date() );
- programStageInstanceService.updateProgramStageInstance( programStageInstance );
- }
-
- dataValue = new PatientDataValue( programStageInstance, dataElement, optionCombo, orgUnit, new Date(), value, false );;
- dataValueService.savePatientDataValue( dataValue );
- }
- }
- else
- {
- if ( programStageInstance.getExecutionDate() == null )
- {
- programStageInstance.setExecutionDate( new Date() );
- programStageInstanceService.updateProgramStageInstance( programStageInstance );
- }
-
- dataValue.setValue( value );
- dataValue.setOptionCombo( optionCombo );
- dataValue.setProvidedByAnotherFacility( false );
- dataValue.setTimestamp( new Date() );
-
- dataValueService.updatePatientDataValue( dataValue );
- }
- }
- }
+
+ private void saveDataValues( ActivityValue activityValue, ProgramStageInstance programStageInstance,
+ Map<Integer, DataElement> dataElementMap, OrganisationUnit orgUnit, DataElementCategoryOptionCombo optionCombo )
+ {
+
+ org.hisp.dhis.dataelement.DataElement dataElement;
+ String value;
+
+ for ( DataValue dv : activityValue.getDataValues() )
+ {
+ value = dv.getVal();
+ System.out.println("COC ID: " + dv.getCategoryOptComboID());
+ DataElementCategoryOptionCombo cateOptCombo = categoryService.getDataElementCategoryOptionCombo( dv
+ .getCategoryOptComboID() );
+ System.out.println(cateOptCombo);
+ if ( value != null && value.trim().length() == 0 )
+ {
+ value = null;
+ }
+
+ if ( value != null )
+ {
+ value = value.trim();
+ }
+
+ dataElement = dataElementMap.get( dv.getId() );
+ PatientDataValue dataValue = dataValueService.getPatientDataValue( programStageInstance, dataElement,
+ orgUnit );
+
+ if ( dataValue == null )
+ {
+ if ( value != null )
+ {
+ if ( programStageInstance.getExecutionDate() == null )
+ {
+ programStageInstance.setExecutionDate( new Date() );
+ programStageInstanceService.updateProgramStageInstance( programStageInstance );
+ }
+
+ dataValue = new PatientDataValue( programStageInstance, dataElement, cateOptCombo, orgUnit,
+ new Date(), value, false );
+ ;
+ dataValueService.savePatientDataValue( dataValue );
+ }
+ }
+ else
+ {
+ if ( programStageInstance.getExecutionDate() == null )
+ {
+ programStageInstance.setExecutionDate( new Date() );
+ programStageInstanceService.updateProgramStageInstance( programStageInstance );
+ }
+
+ dataValue.setValue( value );
+ dataValue.setOptionCombo( optionCombo );
+ dataValue.setProvidedByAnotherFacility( false );
+ dataValue.setTimestamp( new Date() );
+
+ dataValueService.updatePatientDataValue( dataValue );
+ }
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-01 06:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-13 17:48:18 +0000
@@ -9,7 +9,9 @@
import java.util.Collection;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.web.api.model.AbstractModel;
@@ -22,134 +24,151 @@
/**
* @author abyotag_adm
- *
+ *
*/
-public class DefaultProgramService implements IProgramService
+public class DefaultProgramService
+ implements IProgramService
{
-
- // -------------------------------------------------------------------------
+
+ // -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
- @Autowired
- private org.hisp.dhis.program.ProgramService programService;
-
- @Autowired
- private org.hisp.dhis.i18n.I18nService i18nService;
-
- @Autowired
+
+ @Autowired
+ private org.hisp.dhis.program.ProgramService programService;
+
+ @Autowired
+ private org.hisp.dhis.i18n.I18nService i18nService;
+
+ @Autowired
private CurrentUserService currentUserService;
-
- // -------------------------------------------------------------------------
+
+ // -------------------------------------------------------------------------
// ProgramService
// -------------------------------------------------------------------------
-
-// public AbstractModelList getAllProgramsForLocale(String localeString)
-// {
-// Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
-// OrganisationUnit unit = null;
-//
-// if( units.size() > 0 )
-// {
-// unit = units.iterator().next();
-// }
-// else
-// {
-// return null;
-// }
-//
-// Locale locale = LocaleUtil.getLocale(localeString);
-//
-// AbstractModelList abstractModelList = new AbstractModelList();
-//
-// List<AbstractModel> abstractModels = new ArrayList<AbstractModel>();
-//
-// for (org.hisp.dhis.program.Program program : programService.getPrograms(unit))
-// {
-// program = i18n( i18nService, locale, program );
-//
-// AbstractModel abstractModel = new AbstractModel();
-//
-// abstractModel.setId( program.getId());
-// abstractModel.setName(program.getName());
-//
-// abstractModels.add(abstractModel);
-// }
-//
-// abstractModelList.setAbstractModels(abstractModels);
-//
-// return abstractModelList;
-// }
-
- public List<Program> getAllProgramsForLocale(String localeString)
- {
- List<Program> programs = new ArrayList<Program>();
-
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
- OrganisationUnit unit = null;
-
- if( units.size() > 0 )
- {
- unit = units.iterator().next();
- }
- else
- {
- return null;
- }
- for (org.hisp.dhis.program.Program program : programService.getPrograms(unit))
- {
- programs.add(getProgramForLocale( program.getId() , localeString));
- }
-
- return programs;
- }
-
- public Program getProgramForLocale(int programId, String localeString)
- {
- Locale locale = LocaleUtil.getLocale(localeString);
-
- org.hisp.dhis.program.Program program = programService.getProgram( programId );
-
- program = i18n( i18nService, locale, program );
-
- Program pr = new Program();
-
- pr.setId( program.getId() );
- pr.setName( program.getName() );
-
- List<ProgramStage> prStgs = new ArrayList<ProgramStage>();
-
- for( org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages() )
- {
- programStage = i18n( i18nService, locale, programStage );
-
- ProgramStage prStg = new ProgramStage();
- prStg.setId( programStage.getId() );
- prStg.setName( programStage.getName() );
-
- List<DataElement> des = new ArrayList<DataElement>();
-
- for( org.hisp.dhis.program.ProgramStageDataElement programStagedataElement : programStage.getProgramStageDataElements())
- {
- programStagedataElement = i18n( i18nService, locale, programStagedataElement );
-
- DataElement de = new DataElement();
- de.setId( programStagedataElement.getDataElement().getId() );
- de.setName( programStagedataElement.getDataElement().getName() );
- de.setType( programStagedataElement.getDataElement().getType() );
-
- des.add( de );
- }
-
- prStg.setDataElements(des);
-
- prStgs.add(prStg);
-
- }
-
- pr.setProgramStages(prStgs) ;
-
- return pr;
- }
+
+ // public AbstractModelList getAllProgramsForLocale(String localeString)
+ // {
+ // Collection<OrganisationUnit> units =
+ // currentUserService.getCurrentUser().getOrganisationUnits();
+ // OrganisationUnit unit = null;
+ //
+ // if( units.size() > 0 )
+ // {
+ // unit = units.iterator().next();
+ // }
+ // else
+ // {
+ // return null;
+ // }
+ //
+ // Locale locale = LocaleUtil.getLocale(localeString);
+ //
+ // AbstractModelList abstractModelList = new AbstractModelList();
+ //
+ // List<AbstractModel> abstractModels = new ArrayList<AbstractModel>();
+ //
+ // for (org.hisp.dhis.program.Program program :
+ // programService.getPrograms(unit))
+ // {
+ // program = i18n( i18nService, locale, program );
+ //
+ // AbstractModel abstractModel = new AbstractModel();
+ //
+ // abstractModel.setId( program.getId());
+ // abstractModel.setName(program.getName());
+ //
+ // abstractModels.add(abstractModel);
+ // }
+ //
+ // abstractModelList.setAbstractModels(abstractModels);
+ //
+ // return abstractModelList;
+ // }
+
+ public List<Program> getAllProgramsForLocale( String localeString )
+ {
+ List<Program> programs = new ArrayList<Program>();
+
+ Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
+ OrganisationUnit unit = null;
+
+ if ( units.size() > 0 )
+ {
+ unit = units.iterator().next();
+ }
+ else
+ {
+ return null;
+ }
+ for ( org.hisp.dhis.program.Program program : programService.getPrograms( unit ) )
+ {
+ programs.add( getProgramForLocale( program.getId(), localeString ) );
+ }
+
+ return programs;
+ }
+
+ public Program getProgramForLocale( int programId, String localeString )
+ {
+ Locale locale = LocaleUtil.getLocale( localeString );
+
+ org.hisp.dhis.program.Program program = programService.getProgram( programId );
+
+ program = i18n( i18nService, locale, program );
+
+ Program pr = new Program();
+
+ pr.setId( program.getId() );
+ pr.setName( program.getName() );
+
+ List<ProgramStage> prStgs = new ArrayList<ProgramStage>();
+
+ for ( org.hisp.dhis.program.ProgramStage programStage : program.getProgramStages() )
+ {
+ programStage = i18n( i18nService, locale, programStage );
+
+ ProgramStage prStg = new ProgramStage();
+ prStg.setId( programStage.getId() );
+ prStg.setName( programStage.getName() );
+
+ List<DataElement> des = new ArrayList<DataElement>();
+
+ for ( org.hisp.dhis.program.ProgramStageDataElement programStagedataElement : programStage
+ .getProgramStageDataElements() )
+ {
+ AbstractModelList mobileCategpryOptCombos = new AbstractModelList();
+ mobileCategpryOptCombos.setAbstractModels( new ArrayList<AbstractModel>() );
+ programStagedataElement = i18n( i18nService, locale, programStagedataElement );
+ Set<DataElementCategoryOptionCombo> deCatOptCombs = programStagedataElement.getDataElement()
+ .getCategoryCombo().getOptionCombos();
+
+ for ( DataElementCategoryOptionCombo categoryOptCombo : deCatOptCombs )
+ {
+ AbstractModel mobileCategpryOptCombo = new AbstractModel();
+ mobileCategpryOptCombo.setId( categoryOptCombo.getId() );
+ mobileCategpryOptCombo.setName( categoryOptCombo.getName() );
+ mobileCategpryOptCombos.getAbstractModels().add( mobileCategpryOptCombo );
+ }
+
+ DataElement de = new DataElement();
+ de.setId( programStagedataElement.getDataElement().getId() );
+ de.setName( programStagedataElement.getDataElement().getName() );
+ de.setType( programStagedataElement.getDataElement().getType() );
+ de.setCategoryOptionCombos( mobileCategpryOptCombos );
+
+ des.add( de );
+ }
+
+ prStg.setDataElements( des );
+
+ prStgs.add( prStg );
+
+ }
+
+ pr.setProgramStages( prStgs );
+
+ return pr;
+ }
}