=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2010-11-21 11:37:49 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2010-11-26 11:00:40 +0000 @@ -32,6 +32,8 @@ import java.io.IOException; import java.util.List; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement public class ActivityPlan implements DataStreamSerializable { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2010-11-25 08:05:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2010-11-26 11:00:40 +0000 @@ -50,19 +50,19 @@ private List patientAttValues; private PatientAttribute groupAttribute; - - private List identifiers; + + private List identifiers; private String gender; private Date birthDate; private String bloodGroup; - + private Date registrationDate; - + private Character dobType; - + public List getIdentifiers() { return identifiers; @@ -73,6 +73,32 @@ this.identifiers = identifiers; } + public String getFullName() + { + boolean space = false; + String name = ""; + + if ( firstName != null && firstName.length() != 0 ) + { + name = firstName; + space = true; + } + if ( middleName != null && middleName.length() != 0 ) + { + if ( space ) + name += " "; + name += middleName; + space = true; + } + if ( lastName != null && lastName.length() != 0 ) + { + if ( space ) + name += " "; + name += lastName; + } + return name; + } + public int getAge() { return age; @@ -205,48 +231,60 @@ dout.writeUTF( this.getMiddleName() ); dout.writeUTF( this.getLastName() ); dout.writeInt( this.getAge() ); - - // Write static attributes if it is required (gender, dobtype, birthdate, bloodgroup, registrationdate) - if(gender != null){ - dout.writeBoolean( true ); - dout.writeUTF(gender); - }else{ - dout.writeBoolean( false ); - } - - if(dobType != null){ - dout.writeBoolean( true ); - dout.writeChar(dobType); - }else{ - dout.writeBoolean( false ); - } - - if(birthDate != null){ - dout.writeBoolean( true ); - dout.writeLong(birthDate.getTime()); - }else{ - dout.writeBoolean( false ); - } - - if(bloodGroup != null){ - dout.writeBoolean( true ); - dout.writeUTF(bloodGroup); - }else{ - dout.writeBoolean( false ); - } - - if(registrationDate != null){ - dout.writeBoolean( true ); - dout.writeLong(registrationDate.getTime()); - }else{ - dout.writeBoolean( false ); - } - //End - - - // Write attribute which is used as group factor of beneficiary. + + if ( gender != null ) + { + dout.writeBoolean( true ); + dout.writeUTF( gender ); + } + else + { + dout.writeBoolean( false ); + } + + if ( dobType != null ) + { + dout.writeBoolean( true ); + dout.writeChar( dobType ); + } + else + { + dout.writeBoolean( false ); + } + + if ( birthDate != null ) + { + dout.writeBoolean( true ); + dout.writeLong( birthDate.getTime() ); + } + else + { + dout.writeBoolean( false ); + } + + if ( bloodGroup != null ) + { + dout.writeBoolean( true ); + dout.writeUTF( bloodGroup ); + } + else + { + dout.writeBoolean( false ); + } + + if ( registrationDate != null ) + { + dout.writeBoolean( true ); + dout.writeLong( registrationDate.getTime() ); + } + else + { + dout.writeBoolean( false ); + } + /* - * False: no group factor True: with group factor + * Write attribute which is used as group factor of beneficiary - false: + * no group factor, true: with group factor */ if ( this.getGroupAttribute() != null ) { @@ -264,10 +302,11 @@ { dout.writeUTF( att.getName() + ":" + att.getValue() ); } - - //Write PatientIdentifier + + // Write PatientIdentifier dout.writeInt( identifiers.size() ); - for(PatientIdentifier each : identifiers){ + for ( PatientIdentifier each : identifiers ) + { each.serialize( dout ); } @@ -283,5 +322,4 @@ } - } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2010-11-26 11:00:40 +0000 @@ -32,6 +32,9 @@ import java.io.IOException; import java.util.List; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement public class MobileModel implements DataStreamSerializable { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2010-11-26 11:00:40 +0000 @@ -39,7 +39,7 @@ private List models; - public List getAbstractModels() + public List getModels() { return models; } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2010-11-26 11:00:40 +0000 @@ -31,6 +31,9 @@ import java.io.DataOutputStream; import java.io.IOException; +import javax.xml.bind.annotation.XmlAttachmentRef; +import javax.xml.bind.annotation.XmlAttribute; + public class OrgUnit implements DataStreamSerializable { @@ -46,6 +49,7 @@ private String uploadActivityReportUrl; + @XmlAttribute public int getId() { return id; @@ -56,6 +60,7 @@ this.id = id; } + @XmlAttribute public String getName() { return name; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-11-26 11:00:40 +0000 @@ -4,19 +4,33 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; - - -public class OrgUnits - extends ArrayList - implements DataStreamSerializable +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement +public class OrgUnits implements DataStreamSerializable { + private List orgUnits = new ArrayList(); + + @XmlElement(name="orgUnit") + public List getOrgUnits() { + return orgUnits; + } + + public void setOrgUnits( List orgUnits ) + { + this.orgUnits = orgUnits; + } @Override public void serialize( DataOutputStream dataOutputStream ) throws IOException { - dataOutputStream.writeInt( size() ); - for ( OrgUnit unit : this ) + dataOutputStream.writeInt( orgUnits.size() ); + for ( OrgUnit unit : orgUnits ) { unit.serialize( dataOutputStream ); } @@ -27,14 +41,14 @@ public void deSerialize( DataInputStream dataInputStream ) throws IOException { - this.clear(); + orgUnits = new ArrayList(); int size = dataInputStream.readInt(); for ( int i = 0; i < size; i++ ) { OrgUnit unit = new OrgUnit(); unit.deSerialize( dataInputStream ); - add( unit ); + orgUnits.add( unit ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java 2010-11-25 08:05:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java 2010-11-26 11:00:40 +0000 @@ -4,18 +4,25 @@ import java.io.DataOutputStream; import java.io.IOException; +import javax.xml.bind.annotation.XmlAttribute; + public class PatientIdentifier implements DataStreamSerializable { private String identifierType; private String identifier; + public PatientIdentifier( ) + { + } + public PatientIdentifier( String identifierType, String identifier ) { this.identifierType = identifierType; this.identifier = identifier; } + @XmlAttribute public String getIdentifierType() { return identifierType; @@ -26,6 +33,7 @@ this.identifierType = identifierType; } + @XmlAttribute public String getIdentifier() { return identifier; @@ -48,7 +56,8 @@ public void deSerialize( DataInputStream dataInputStream ) throws IOException { - + identifierType = dataInputStream.readUTF(); + identifier = dataInputStream.readUTF(); } === 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-11-18 04:09:03 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java 2010-11-26 11:00:40 +0000 @@ -66,7 +66,7 @@ dout.writeUTF( de.getType() ); dout.writeBoolean( de.isCompulsory() ); - List cateOptCombos = de.getCategoryOptionCombos().getAbstractModels(); + List cateOptCombos = de.getCategoryOptionCombos().getModels(); if ( cateOptCombos == null || cateOptCombos.size() <= 0 ) { dout.writeInt( 0 ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java 2010-11-18 04:09:03 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java 2010-11-26 11:00:40 +0000 @@ -65,7 +65,7 @@ dout.writeUTF( de.getType() ); dout.writeBoolean( de.isCompulsory() ); - List cateOptCombos = de.getCategoryOptionCombos().getAbstractModels(); + List cateOptCombos = de.getCategoryOptionCombos().getModels(); if ( cateOptCombos == null || cateOptCombos.size() <= 0 ) { dout.writeInt( 0 ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java 2010-11-18 03:02:18 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java 2010-11-26 11:00:40 +0000 @@ -10,6 +10,6 @@ @Override public int compare( Activity act1, Activity act2 ) { - return act2.getBeneficiary().getFirstName().compareToIgnoreCase( act1.getBeneficiary().getFirstName() ); + return act2.getBeneficiary().getFullName().compareToIgnoreCase( act1.getBeneficiary().getFullName() ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/AbstractDataSerializableConsumer.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/AbstractDataSerializableConsumer.java 2010-11-20 08:35:36 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/AbstractDataSerializableConsumer.java 2010-11-26 11:00:40 +0000 @@ -53,7 +53,6 @@ @Override public boolean isReadable( Class type, Type genericType, Annotation[] annotations, MediaType mediaType ) { - System.out.println("****" + type.getName() + " - " + this.getClass().getName()); return DataStreamSerializable.class.isAssignableFrom( type ); } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-11-18 11:32:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-11-26 11:00:40 +0000 @@ -27,13 +27,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -47,7 +50,7 @@ import com.sun.jersey.api.core.ResourceContext; @Path( "/" ) -@Produces( DhisMediaType.MOBILE_SERIALIZED ) +@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML } ) public class MobileResource { @@ -73,11 +76,15 @@ OrgUnits orgUnits = new OrgUnits(); + List unitList = new ArrayList(); + for ( OrganisationUnit unit : units ) { - orgUnits.add( getOrgUnit( unit ) ); + unitList.add( getOrgUnit( unit ) ); } + orgUnits.setOrgUnits( unitList ); + return orgUnits; } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-11-18 11:32:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-11-26 11:00:40 +0000 @@ -8,21 +8,28 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.web.api.model.ActivityPlan; import org.hisp.dhis.web.api.model.ActivityValue; import org.hisp.dhis.web.api.model.DataSetValue; import org.hisp.dhis.web.api.model.MobileModel; import org.hisp.dhis.web.api.service.ActivityReportingService; +import org.hisp.dhis.web.api.service.ActivityReportingServiceImpl; import org.hisp.dhis.web.api.service.FacilityReportingService; import org.hisp.dhis.web.api.service.IProgramService; import org.springframework.beans.factory.annotation.Required; -@Produces( DhisMediaType.MOBILE_SERIALIZED ) +@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML } ) @Consumes( DhisMediaType.MOBILE_SERIALIZED ) public class OrgUnitResource { + private static Log log = LogFactory.getLog( ActivityReportingServiceImpl.class ); + + private static final boolean DEBUG = log.isDebugEnabled(); + private IProgramService programService; private ActivityReportingService activityReportingService; @@ -31,8 +38,9 @@ // Set by parent resource private OrganisationUnit unit; - - public void setOrgUnit(OrganisationUnit unit) { + + public void setOrgUnit( OrganisationUnit unit ) + { this.unit = unit; } @@ -42,9 +50,12 @@ { MobileModel mobileModel = new MobileModel(); + if ( DEBUG ) + log.debug( "Getting all resources for org unit " + unit.getName() ); + mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) ); mobileModel.setPrograms( programService.getPrograms( unit, locale ) ); - mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); + mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); return mobileModel; } @@ -58,7 +69,7 @@ @POST @Path( "dataSets" ) - @Produces(MediaType.TEXT_PLAIN) + @Produces( MediaType.TEXT_PLAIN ) public String saveDataSetValues( DataSetValue dataSetValue ) { return facilityReportingService.saveDataSetValues( unit, dataSetValue ); @@ -66,14 +77,14 @@ @POST @Path( "activities" ) - @Produces(MediaType.TEXT_PLAIN) + @Produces( MediaType.TEXT_PLAIN ) public String saveActivityReport( ActivityValue activityValue ) { return activityReportingService.saveActivityReport( unit, activityValue ); } // Setters... - + @Required public void setProgramService( IProgramService programService ) { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2010-11-25 08:05:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2010-11-26 11:00:40 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.service; +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -9,6 +36,8 @@ import java.util.Map; import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hisp.dhis.activityplan.Activity; import org.hisp.dhis.activityplan.ActivityPlanService; import org.hisp.dhis.dataelement.DataElement; @@ -17,7 +46,6 @@ import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patient.PatientAttributeService; import org.hisp.dhis.patient.PatientIdentifier; -import org.hisp.dhis.patient.PatientIdentifierService; import org.hisp.dhis.patient.PatientMobileSetting; import org.hisp.dhis.patient.PatientMobileSettingService; import org.hisp.dhis.patientattributevalue.PatientAttributeValue; @@ -25,7 +53,6 @@ import org.hisp.dhis.patientdatavalue.PatientDataValue; import org.hisp.dhis.program.ProgramStageDataElement; import org.hisp.dhis.program.ProgramStageInstance; -import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.web.api.model.ActivityPlan; import org.hisp.dhis.web.api.model.ActivityValue; import org.hisp.dhis.web.api.model.Beneficiary; @@ -35,12 +62,17 @@ import org.hisp.dhis.web.api.model.comparator.ActivityComparator; import org.joda.time.DateMidnight; import org.joda.time.DateTime; +import org.joda.time.Period; import org.springframework.beans.factory.annotation.Required; public class ActivityReportingServiceImpl implements ActivityReportingService { + private static Log log = LogFactory.getLog( ActivityReportingServiceImpl.class ); + + private static final boolean DEBUG = log.isDebugEnabled(); + private ActivityComparator activityComparator = new ActivityComparator(); // ------------------------------------------------------------------------- @@ -59,11 +91,7 @@ private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService; - private CurrentUserService currentUserService; - private PatientMobileSettingService patientMobileSettingService; - -// private PatientIdentifierService patientIdentifierService; // ------------------------------------------------------------------------- // MobileDataSetService @@ -81,43 +109,49 @@ List items = new ArrayList(); - int i = 0; + if (DEBUG) + log.debug( "Filtering through " + allActivities.size() + " activities" ); + for ( Activity activity : allActivities ) { - // there are error on db with patientattributeid 14, so I limit the - // patient to be downloaded - if ( i > 10 ) - { - break; - } - long dueTime = activity.getDueDate().getTime(); + if ( to.isBefore( dueTime ) ) { continue; } + + if (DEBUG) + log.debug( "Activity " + activity.getBeneficiary().getFirstName() + ", " + activity.getTask().getProgramStage().getName() ); + if ( from.isBefore( dueTime ) ) { items.add( getActivityModel( activity ) ); - i++; } else if ( !activity.getTask().isCompleted() ) { org.hisp.dhis.web.api.model.Activity a = getActivityModel( activity ); + a.setLate( true ); items.add( a ); - a.setLate( true ); - i++; } + + if (items.size() > 10) + break; } - if ( !items.isEmpty() ) + + if (DEBUG) + log.debug( "Found " + items.size() + " current activities" ); + + if ( items.isEmpty() ) { - Collections.sort( items, activityComparator ); - plan.setActivitiesList( items ); + return null; } + Collections.sort( items, activityComparator ); + plan.setActivitiesList( items ); + return plan; - } private org.hisp.dhis.web.api.model.Activity getActivityModel( org.hisp.dhis.activityplan.Activity activity ) @@ -151,10 +185,8 @@ return task; } - private org.hisp.dhis.web.api.model.Beneficiary getBeneficiaryModel( Patient patient ) + private Beneficiary getBeneficiaryModel( Patient patient ) { - PatientMobileSetting setting = patientMobileSettingService.getCurrentSetting()==null?null:patientMobileSettingService.getCurrentSetting().iterator().next(); - Beneficiary beneficiary = new Beneficiary(); List patientAtts = new ArrayList(); @@ -163,33 +195,34 @@ beneficiary.setFirstName( patient.getFirstName() ); beneficiary.setLastName( patient.getLastName() ); beneficiary.setMiddleName( patient.getMiddleName() ); - int currentYear = new Date().getYear(); - int age = currentYear - patient.getBirthDate().getYear(); - beneficiary.setAge( age ); - - // Set static attributes if it is required (gender, dobtype, birthdate, bloodgroup, registrationdate) - if(setting != null){ - if(setting.getGender()){ + + Period period = new Period( new DateTime(patient.getBirthDate()), new DateTime()); + beneficiary.setAge( period.getYears() ); + + PatientMobileSetting setting = getSettings(); + + if ( setting != null ) + { + if ( setting.getGender() ) + { beneficiary.setGender( patient.getGender() ); } - if(setting.getDobtype()){ + if ( setting.getDobtype() ) + { beneficiary.setDobType( patient.getDobType() ); } - if(setting.getBirthdate()){ + if ( setting.getBirthdate() ) + { beneficiary.setBirthDate( patient.getBirthDate() ); } - if(setting.getBloodgroup()){ + if ( setting.getBloodgroup() ) + { beneficiary.setBloodGroup( patient.getBloodGroup() ); } - if(setting.getRegistrationdate()){ + if ( setting.getRegistrationdate() ) + { beneficiary.setRegistrationDate( patient.getRegistrationDate() ); } - }else{ - beneficiary.setGender(null); - beneficiary.setBirthDate( null ); - beneficiary.setDobType( null ); - beneficiary.setBloodGroup( null ); - beneficiary.setRegistrationDate( null ); } // Set attribute which is used to group beneficiary on mobile (only if @@ -208,11 +241,13 @@ patientAttribute = null; // Set all attributes - + List atts; - if(setting != null){ + if ( setting != null ) + { atts = setting.getPatientAttributes(); - for(org.hisp.dhis.patient.PatientAttribute each : atts){ + for ( org.hisp.dhis.patient.PatientAttribute each : atts ) + { PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, each ); if ( value != null ) { @@ -220,23 +255,36 @@ } } } - + // Set all identifier Set patientIdentifiers = patient.getIdentifiers(); List identifiers = new ArrayList(); - if(patientIdentifiers.size() > 0){ - - for(PatientIdentifier each : patientIdentifiers){ - identifiers.add( new org.hisp.dhis.web.api.model.PatientIdentifier(each.getIdentifierType().getName(), each.getIdentifier()) ); + if ( patientIdentifiers.size() > 0 ) + { + + for ( PatientIdentifier id : patientIdentifiers ) + { + identifiers.add( new org.hisp.dhis.web.api.model.PatientIdentifier( id.getIdentifierType().getName(), + id.getIdentifier() ) ); } - + beneficiary.setIdentifiers( identifiers ); } - + beneficiary.setPatientAttValues( patientAtts ); return beneficiary; } + private PatientMobileSetting getSettings() + { + PatientMobileSetting setting = null; + + Collection currentSetting = patientMobileSettingService.getCurrentSetting(); + if ( currentSetting != null && !currentSetting.isEmpty() ) + setting = currentSetting.iterator().next(); + return setting; + } + // ------------------------------------------------------------------------- // DataValueService // ------------------------------------------------------------------------- @@ -337,7 +385,7 @@ dataValue = new PatientDataValue( programStageInstance, dataElement, cateOptCombo, orgUnit, new Date(), value, false ); - + dataValueService.savePatientDataValue( dataValue ); } } @@ -399,25 +447,9 @@ } @Required - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - - @Required public void setPatientMobileSettingService( PatientMobileSettingService patientMobileSettingService ) { this.patientMobileSettingService = patientMobileSettingService; } -// @Required -// public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService ) -// { -// this.patientIdentifierService = patientIdentifierService; -// } - - - - - } === 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-20 08:35:36 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-26 11:00:40 +0000 @@ -83,7 +83,7 @@ Model mobileCategpryOptCombo = new Model(); mobileCategpryOptCombo.setId( categoryOptCombo.getId() ); mobileCategpryOptCombo.setName( categoryOptCombo.getName() ); - mobileCategpryOptCombos.getAbstractModels().add( mobileCategpryOptCombo ); + mobileCategpryOptCombos.getModels().add( mobileCategpryOptCombo ); } DataElement de = new DataElement(); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2010-11-26 11:00:40 +0000 @@ -127,7 +127,7 @@ List
sectionList = new ArrayList
(); ds.setSections( sectionList ); - if ( sections.size() == 0 || sections == null ) + if ( sections == null || sections.size() == 0 ) { // Collection dataElements = // new ArrayList(); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-23 07:16:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-26 11:00:40 +0000 @@ -3,7 +3,7 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> - + @@ -32,7 +32,6 @@ - @@ -58,23 +57,11 @@ - - - - - - - - - - - - - - - - - + + + + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java' --- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2010-11-18 06:08:29 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2010-11-26 11:00:40 +0000 @@ -7,6 +7,8 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import org.hisp.dhis.web.api.model.OrgUnit; import org.hisp.dhis.web.api.model.OrgUnits; @@ -25,14 +27,15 @@ DataOutputStream dos = new DataOutputStream( baos ); OrgUnits units = new OrgUnits(); - units.add( unit ); + units.setOrgUnits( Arrays.asList( new OrgUnit[] {unit} )); units.serialize( dos ); dos.flush(); OrgUnits units2 = new OrgUnits( ); units2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) ); - assertEquals( 1, units2.size() ); + List unitList = units2.getOrgUnits(); + assertEquals( 1, unitList.size() ); - OrgUnit unit2 = units2.get( 0 ); + OrgUnit unit2 = unitList.get( 0 ); assertEquals( unit.getName(), unit2.getName() ); assertEquals( unit.getId(), unit2.getId() );