=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java' --- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-04-03 08:06:46 +0000 +++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-04-05 06:01:19 +0000 @@ -79,7 +79,7 @@ private List enrollmentPrograms; private List relationships; - + private List enrollmentRelationships; private String phoneNumber; @@ -385,7 +385,7 @@ dout.writeInt( atts.size() ); for ( PatientAttribute att : atts ) { - att.serialize( dout ); + dout.writeUTF( att.getName() + ":" + att.getValue() ); } // Write PatientIdentifier @@ -395,10 +395,7 @@ each.serialize( dout ); } - // Write Enrolled Programs - // Write Program - dout.writeInt( programs.size() ); for ( Program each : programs ) { @@ -419,9 +416,9 @@ { each.serialize( dout ); } - + // Write Enrolled - + dout.writeInt( enrollmentRelationships.size() ); for ( Relationship each : enrollmentRelationships ) { === modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java' --- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java 2013-04-03 08:06:46 +0000 +++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/MobileOrgUnitLinks.java 2013-04-05 06:01:19 +0000 @@ -328,6 +328,7 @@ this.getVariesInfoUrl = dataInputStream.readUTF(); this.addRelationshipUrl = dataInputStream.readUTF(); this.downloadAnonymousProgramUrl = dataInputStream.readUTF(); + this.findProgramUrl = dataInputStream.readUTF(); } @Override === modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java' --- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 2013-04-03 08:06:46 +0000 +++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java 2013-04-05 06:01:19 +0000 @@ -117,6 +117,7 @@ orgUnit.setUpdateDataSetUrl( getUrl( request, unit.getId(), "updateDataSets" ) ); orgUnit.setChangeUpdateDataSetLangUrl( getUrl( request, unit.getId(), "changeLanguageDataSet" ) ); orgUnit.setSearchUrl( getUrl( request, unit.getId(), "search" ) ); + orgUnit.setUpdateNewVersionUrl( getUrl( request, unit.getId(), "updateNewVersionUrl" ) ); orgUnit.setUpdateContactUrl( getUrl( request, unit.getId(), "updateContactForMobile" ) ); orgUnit.setFindPatientUrl( getUrl( request, unit.getId(), "findPatient" ) ); orgUnit.setRegisterPersonUrl( getUrl( request, unit.getId(), "registerPerson" ) ); === modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java' --- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-04-04 18:06:19 +0000 +++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-04-05 06:01:19 +0000 @@ -46,39 +46,39 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping( value = "/mobile" ) -public class MobileOrganisationUnitController - extends AbstractMobileController -{ - private static final String ACTIVITY_REPORT_UPLOADED = "activity_report_uploaded"; - + +@Controller +@RequestMapping( value = "/mobile" ) +public class MobileOrganisationUnitController + extends AbstractMobileController +{ + private static final String ACTIVITY_REPORT_UPLOADED = "activity_report_uploaded"; + private static final String DATASET_REPORT_UPLOADED = "dataset_report_uploaded"; - - private static final String PATIENT_REGISTERED = "patient_registered"; - - @Autowired - private ActivityReportingService activityReportingService; - - @Autowired - private IProgramService programService; - - @Autowired - private FacilityReportingService facilityReportingService; - - @Autowired - private OrganisationUnitService organisationUnitService; - - @Autowired - private I18nService i18nService; - - @Autowired - private PatientService patientService; - - @Autowired + + private static final String PATIENT_REGISTERED = "patient_registered"; + + @Autowired + private ActivityReportingService activityReportingService; + + @Autowired + private IProgramService programService; + + @Autowired + private FacilityReportingService facilityReportingService; + + @Autowired + private OrganisationUnitService organisationUnitService; + + @Autowired + private I18nService i18nService; + + @Autowired + private PatientService patientService; + + @Autowired private SMSCommandService smsCommandService; - + @Autowired private PatientIdentifierTypeService patientIdentifierTypeService; @@ -95,320 +95,362 @@ public void setPatientId( Integer patientId ) { this.patientId = patientId; - } - - // For client version 2.8 and lower - @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/all" ) - @ResponseBody - public MobileModel getAllDataForOrgUnit2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale ) - { - MobileModel mobileModel = new MobileModel(); - mobileModel.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); - OrganisationUnit unit = getUnit( id ); - mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) ); - mobileModel.setPrograms( programService.getPrograms( unit, locale ) ); - mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); - mobileModel.setServerCurrentDate( new Date() ); - mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) ); - return mobileModel; - } - - @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets" ) - @ResponseBody - public DataSetList checkUpdatedDataSet2_8( @PathVariable int id, @RequestBody DataSetList dataSetList, - @RequestHeader( "accept-language" ) String locale ) - { - DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale ); - returnList.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); - return returnList; - } - - /** - * Save a facility report for unit - * - * @param dataSetValue - the report to save - * @throws NotAllowedException if the {@link DataSetValue} is invalid - */ - @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/dataSets" ) - @ResponseBody - public String saveDataSetValues2_8( @PathVariable int id, @RequestBody DataSetValue dataSetValue ) - throws NotAllowedException - { - facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue ); - return DATASET_REPORT_UPLOADED; - } - - /** - * Save activity report for unit - * - * @param activityValue - the report to save - * @throws NotAllowedException if the {@link ActivityValue activity value} - * is invalid - */ - @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activities" ) - @ResponseBody - public String saveActivityReport2_8( @PathVariable int id, @RequestBody ActivityValue activityValue ) - throws NotAllowedException - { - // FIXME set the last argument to 0 to fix compilation error - activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 ); - return ACTIVITY_REPORT_UPLOADED; - } - - @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan" ) - @ResponseBody - public MobileModel updatePrograms2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale, - @RequestBody ModelList programsFromClient ) - { - MobileModel model = new MobileModel(); - model.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); - model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) ); - model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) ); - model.setServerCurrentDate( new Date() ); - return model; - } - - @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/search" ) - @ResponseBody - public ActivityPlan search2_8( @PathVariable int id, @RequestHeader( "identifier" ) String identifier ) - throws NotAllowedException - { - ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier ); - activityPlan.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); - return activityPlan; - } - - @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet" ) - @ResponseBody - public DataSetList changeLanguageDataSet2_8( @PathVariable int id, @RequestHeader( "accept-language" ) String locale ) - { - return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale ); - } - - // For client version 2.9 and higher - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all" ) - @ResponseBody - public MobileModel getAllDataForOrgUnit( @PathVariable String clientVersion, @PathVariable int id, - @RequestHeader( "accept-language" ) String locale ) - { - MobileModel mobileModel = new MobileModel(); - mobileModel.setClientVersion( clientVersion ); - OrganisationUnit unit = getUnit( id ); - mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) ); - mobileModel.setPrograms( programService.getPrograms( unit, locale ) ); - mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); - mobileModel.setServerCurrentDate( new Date() ); - mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) ); - mobileModel.setSmsCommands( this.getMobileSMSCommands( smsCommandService.getJ2MESMSCommands() ) ); - return mobileModel; - } - - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets" ) - @ResponseBody - public DataSetList checkUpdatedDataSet( @PathVariable String clientVersion, @PathVariable int id, - @RequestBody DataSetList dataSetList, @RequestHeader( "accept-language" ) String locale ) - { - DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale ); - returnList.setClientVersion( clientVersion ); - return returnList; - } - - /** - * Save a facility report for unit - * - * @param dataSetValue - the report to save - * @throws NotAllowedException if the {@link DataSetValue} is invalid - */ - - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/dataSets" ) - @ResponseBody - public String saveDataSetValues( @PathVariable int id, @RequestBody DataSetValue dataSetValue ) - throws NotAllowedException - { - facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue ); - return DATASET_REPORT_UPLOADED; - } - - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activitiyplan" ) - @ResponseBody - public MobileModel updatePrograms( @PathVariable String clientVersion, @PathVariable int id, - @RequestHeader( "accept-language" ) String locale, @RequestBody ModelList programsFromClient ) - { - MobileModel model = new MobileModel(); - model.setClientVersion( clientVersion ); - model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) ); - model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) ); - model.setServerCurrentDate( new Date() ); - return model; - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/search" ) - @ResponseBody - public ActivityPlan search( @PathVariable String clientVersion, @PathVariable int id, - @RequestHeader( "identifier" ) String identifier ) - throws NotAllowedException - { - ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier ); - activityPlan.setClientVersion( clientVersion ); - return activityPlan; - } - - /** - * Save a facility report for unit - * - * @param dataSetValue - the report to save - * @throws NotAllowedException if the {@link DataSetValue} is invalid - */ - - // @RequestMapping( method = RequestMethod.POST, value = - // "{clientVersion}/orgUnits/{id}/dataSets" ) - // @ResponseBody - // public String saveDataSetValues( @PathVariable int id, @RequestBody - // DataSetValue dataSetValue ) - // throws NotAllowedException - // { - // facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue - // ); - // return DATASET_REPORT_UPLOADED; - // } - - /** - * Save activity report for unit - * - * @param activityValue - the report to save - * @throws NotAllowedException if the {@link ActivityValue activity value} - * is invalid - */ - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activities" ) - @ResponseBody - public String saveActivityReport( @PathVariable int id, @RequestBody ActivityValue activityValue ) - throws NotAllowedException - { - // FIXME set the last argument to 0 to fix compilation error - activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 ); - return ACTIVITY_REPORT_UPLOADED; - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/changeLanguageDataSet" ) - @ResponseBody - public DataSetList changeLanguageDataSet( @PathVariable int id, @RequestHeader( "accept-language" ) String locale ) - { - return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale ); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/updateContactForMobile" ) - @ResponseBody - public Contact updateContactForMobile() - { - return facilityReportingService.updateContactForMobile(); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/updateContactForMobile" ) - @ResponseBody - public Contact updateContactForMobileLWUIT() - { - return facilityReportingService.updateContactForMobile(); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/findPatient" ) - @ResponseBody - public Patient findPatientByName( @PathVariable int id, @RequestHeader( "name" ) String keyword ) - throws NotAllowedException - { - return activityReportingService.findPatient( keyword, id ); - } - - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/uploadProgramStage" ) - @ResponseBody - public String saveProgramStage( @PathVariable int id, @RequestBody ProgramStage programStage ) - throws NotAllowedException - { - return activityReportingService.saveProgramStage( programStage, id ); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/enrollProgram" ) - @ResponseBody - public Patient enrollProgram( @PathVariable int id, @RequestHeader( "enrollInfo" ) String enrollInfo ) - throws NotAllowedException - { - return activityReportingService.enrollProgram( enrollInfo, id ); - } - - @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/addRelationship" ) - @ResponseBody - public Patient addRelationship( @PathVariable int id, @RequestBody Relationship enrollmentRelationship ) - throws NotAllowedException - { - return activityReportingService.addRelationship( enrollmentRelationship, id ); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/downloadAnonymousProgramUrl" ) - @ResponseBody - public Program getAnonymousProgram( @PathVariable int id, @RequestHeader( "useless-part" ) String enrollInfo ) - throws NotAllowedException - { - return activityReportingService.getAllAnonymousProgram( id ); - } - - @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/findProgram" ) - @ResponseBody - public Program findProgram( @PathVariable int id, @RequestHeader( "info" ) String programInfo ) - throws NotAllowedException - { - return activityReportingService.findProgram( programInfo ); - } - - // Supportive methods - - private Collection getLocalStrings( Collection locales ) - { - if ( locales == null || locales.isEmpty() ) - { - return null; - } - Collection localeStrings = new ArrayList(); - - for ( Locale locale : locales ) - { - localeStrings.add( locale.getLanguage() + "-" + locale.getCountry() ); - } - return localeStrings; - } - - private List getMobileSMSCommands( Collection normalSMSCommands ) - { - List smsCommands = new ArrayList(); - for ( org.hisp.dhis.smscommand.SMSCommand normalSMSCommand : normalSMSCommands ) - { - SMSCommand mobileSMSCommand = new SMSCommand(); - List smsCodes = new ArrayList(); - - mobileSMSCommand.setName( normalSMSCommand.getName() ); - mobileSMSCommand.setCodeSeparator( normalSMSCommand.getCodeSeparator() ); - mobileSMSCommand.setDataSetId( normalSMSCommand.getDataset().getId() ); - mobileSMSCommand.setSeparator( normalSMSCommand.getSeparator() ); - - for ( org.hisp.dhis.smscommand.SMSCode normalSMSCode : normalSMSCommand.getCodes() ) - { - SMSCode smsCode = new SMSCode(); - - smsCode.setCode( normalSMSCode.getCode() ); - smsCode.setDataElementId( normalSMSCode.getDataElement().getId() ); - smsCode.setOptionId( normalSMSCode.getOptionId() ); - smsCodes.add( smsCode ); - } - mobileSMSCommand.setSmsCodes( smsCodes ); - smsCommands.add( mobileSMSCommand ); - } - return smsCommands; - } - - private OrganisationUnit getUnit( int id ) - { - return organisationUnitService.getOrganisationUnit( id ); - } - + } + + // For client version 2.8 and lower + @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/all" ) + @ResponseBody + public MobileModel getAllDataForOrgUnit2_8( @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale ) + { + MobileModel mobileModel = new MobileModel(); + mobileModel.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); + OrganisationUnit unit = getUnit( id ); + mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) ); + mobileModel.setPrograms( programService.getPrograms( unit, locale ) ); + mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); + mobileModel.setServerCurrentDate( new Date() ); + mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) ); + return mobileModel; + } + + @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/updateDataSets" ) + @ResponseBody + public DataSetList checkUpdatedDataSet2_8( @PathVariable + int id, @RequestBody + DataSetList dataSetList, @RequestHeader( "accept-language" ) + String locale ) + { + DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale ); + returnList.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); + return returnList; + } + + /** + * Save a facility report for unit + * + * @param dataSetValue - the report to save + * @throws NotAllowedException if the {@link DataSetValue} is invalid + */ + @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/dataSets" ) + @ResponseBody + public String saveDataSetValues2_8( @PathVariable + int id, @RequestBody + DataSetValue dataSetValue ) + throws NotAllowedException + { + facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue ); + return DATASET_REPORT_UPLOADED; + } + + /** + * Save activity report for unit + * + * @param activityValue - the report to save + * @throws NotAllowedException if the {@link ActivityValue activity value} + * is invalid + */ + @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activities" ) + @ResponseBody + public String saveActivityReport2_8( @PathVariable + int id, @RequestBody + ActivityValue activityValue ) + throws NotAllowedException + { + // FIXME set the last argument to 0 to fix compilation error + activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 ); + return ACTIVITY_REPORT_UPLOADED; + } + + @RequestMapping( method = RequestMethod.POST, value = "orgUnits/{id}/activitiyplan" ) + @ResponseBody + public MobileModel updatePrograms2_8( @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale, @RequestBody + ModelList programsFromClient ) + { + MobileModel model = new MobileModel(); + model.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); + model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) ); + model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) ); + model.setServerCurrentDate( new Date() ); + return model; + } + + @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/search" ) + @ResponseBody + public ActivityPlan search2_8( @PathVariable + int id, @RequestHeader( "identifier" ) + String identifier ) + throws NotAllowedException + { + ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier ); + activityPlan.setClientVersion( DataStreamSerializable.TWO_POINT_EIGHT ); + return activityPlan; + } + + @RequestMapping( method = RequestMethod.GET, value = "orgUnits/{id}/changeLanguageDataSet" ) + @ResponseBody + public DataSetList changeLanguageDataSet2_8( @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale ) + { + return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale ); + } + + // For client version 2.9 and higher + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/all" ) + @ResponseBody + public MobileModel getAllDataForOrgUnit( @PathVariable + String clientVersion, @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale ) + { + MobileModel mobileModel = new MobileModel(); + mobileModel.setClientVersion( clientVersion ); + OrganisationUnit unit = getUnit( id ); + mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) ); + mobileModel.setPrograms( programService.getPrograms( unit, locale ) ); + mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) ); + mobileModel.setServerCurrentDate( new Date() ); + mobileModel.setLocales( getLocalStrings( i18nService.getAvailableLocales() ) ); + mobileModel.setSmsCommands( this.getMobileSMSCommands( smsCommandService.getJ2MESMSCommands() ) ); + return mobileModel; + } + + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/updateDataSets" ) + @ResponseBody + public DataSetList checkUpdatedDataSet( @PathVariable + String clientVersion, @PathVariable + int id, @RequestBody + DataSetList dataSetList, @RequestHeader( "accept-language" ) + String locale ) + { + DataSetList returnList = facilityReportingService.getUpdatedDataSet( dataSetList, getUnit( id ), locale ); + returnList.setClientVersion( clientVersion ); + return returnList; + } + + /** + * Save a facility report for unit + * + * @param dataSetValue - the report to save + * @throws NotAllowedException if the {@link DataSetValue} is invalid + */ + + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/dataSets" ) + @ResponseBody + public String saveDataSetValues( @PathVariable + int id, @RequestBody + DataSetValue dataSetValue ) + throws NotAllowedException + { + facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue ); + return DATASET_REPORT_UPLOADED; + } + + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activitiyplan" ) + @ResponseBody + public MobileModel updatePrograms( @PathVariable + String clientVersion, @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale, @RequestBody + ModelList programsFromClient ) + { + MobileModel model = new MobileModel(); + model.setClientVersion( clientVersion ); + model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit( id ) ) ); + model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit( id ), locale ) ); + model.setServerCurrentDate( new Date() ); + return model; + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/search" ) + @ResponseBody + public ActivityPlan search( @PathVariable + String clientVersion, @PathVariable + int id, @RequestHeader( "identifier" ) + String identifier ) + throws NotAllowedException + { + ActivityPlan activityPlan = activityReportingService.getActivitiesByIdentifier( identifier ); + activityPlan.setClientVersion( clientVersion ); + return activityPlan; + } + + /** + * Save a facility report for unit + * + * @param dataSetValue - the report to save + * @throws NotAllowedException if the {@link DataSetValue} is invalid + */ + + // @RequestMapping( method = RequestMethod.POST, value = + // "{clientVersion}/orgUnits/{id}/dataSets" ) + // @ResponseBody + // public String saveDataSetValues( @PathVariable int id, @RequestBody + // DataSetValue dataSetValue ) + // throws NotAllowedException + // { + // facilityReportingService.saveDataSetValues( getUnit( id ), dataSetValue + // ); + // return DATASET_REPORT_UPLOADED; + // } + + /** + * Save activity report for unit + * + * @param activityValue - the report to save + * @throws NotAllowedException if the {@link ActivityValue activity value} + * is invalid + */ + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/orgUnits/{id}/activities" ) + @ResponseBody + public String saveActivityReport( @PathVariable + int id, @RequestBody + ActivityValue activityValue ) + throws NotAllowedException + { + // FIXME set the last argument to 0 to fix compilation error + activityReportingService.saveActivityReport( getUnit( id ), activityValue, 0 ); + return ACTIVITY_REPORT_UPLOADED; + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/changeLanguageDataSet" ) + @ResponseBody + public DataSetList changeLanguageDataSet( @PathVariable + int id, @RequestHeader( "accept-language" ) + String locale ) + { + return facilityReportingService.getDataSetsForLocale( getUnit( id ), locale ); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/orgUnits/{id}/updateContactForMobile" ) + @ResponseBody + public Contact updateContactForMobile() + { + return facilityReportingService.updateContactForMobile(); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/updateContactForMobile" ) + @ResponseBody + public Contact updateContactForMobileLWUIT() + { + return facilityReportingService.updateContactForMobile(); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/findPatient" ) + @ResponseBody + public Patient findPatientByName( @PathVariable + int id, @RequestHeader( "name" ) + String keyword ) + throws NotAllowedException + { + return activityReportingService.findPatient( keyword, id ); + } + + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/uploadProgramStage" ) + @ResponseBody + public String saveProgramStage( @PathVariable + int id, @RequestBody + ProgramStage programStage ) + throws NotAllowedException + { + return activityReportingService.saveProgramStage( programStage, id ); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/enrollProgram" ) + @ResponseBody + public Patient enrollProgram( @PathVariable + int id, @RequestHeader( "enrollInfo" ) + String enrollInfo ) + throws NotAllowedException + { + return activityReportingService.enrollProgram( enrollInfo, id ); + } + + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/addRelationship" ) + @ResponseBody + public Patient addRelationship( @PathVariable + int id, @RequestBody + Relationship enrollmentRelationship ) + throws NotAllowedException + { + return activityReportingService.addRelationship( enrollmentRelationship, id ); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/downloadAnonymousProgramUrl" ) + @ResponseBody + public Program getAnonymousProgram( @PathVariable + int id, @RequestHeader( "useless-part" ) + String enrollInfo ) + throws NotAllowedException + { + return activityReportingService.getAllAnonymousProgram( id ); + } + + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/findProgram" ) + @ResponseBody + public Program findProgram( @PathVariable + int id, @RequestHeader( "info" ) + String programInfo ) + throws NotAllowedException + { + return activityReportingService.findProgram( programInfo ); + } + + // Supportive methods + + private Collection getLocalStrings( Collection locales ) + { + if ( locales == null || locales.isEmpty() ) + { + return null; + } + Collection localeStrings = new ArrayList(); + + for ( Locale locale : locales ) + { + localeStrings.add( locale.getLanguage() + "-" + locale.getCountry() ); + } + return localeStrings; + } + + private List getMobileSMSCommands( Collection normalSMSCommands ) + { + List smsCommands = new ArrayList(); + for ( org.hisp.dhis.smscommand.SMSCommand normalSMSCommand : normalSMSCommands ) + { + SMSCommand mobileSMSCommand = new SMSCommand(); + List smsCodes = new ArrayList(); + + mobileSMSCommand.setName( normalSMSCommand.getName() ); + mobileSMSCommand.setCodeSeparator( normalSMSCommand.getCodeSeparator() ); + mobileSMSCommand.setDataSetId( normalSMSCommand.getDataset().getId() ); + mobileSMSCommand.setSeparator( normalSMSCommand.getSeparator() ); + + for ( org.hisp.dhis.smscommand.SMSCode normalSMSCode : normalSMSCommand.getCodes() ) + { + SMSCode smsCode = new SMSCode(); + + smsCode.setCode( normalSMSCode.getCode() ); + smsCode.setDataElementId( normalSMSCode.getDataElement().getId() ); + smsCode.setOptionId( normalSMSCode.getOptionId() ); + smsCodes.add( smsCode ); + } + mobileSMSCommand.setSmsCodes( smsCodes ); + smsCommands.add( mobileSMSCommand ); + } + return smsCommands; + } + + private OrganisationUnit getUnit( int id ) + { + return organisationUnitService.getOrganisationUnit( id ); + } + @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/registerPerson" ) @ResponseBody public String savePatient( @PathVariable @@ -510,6 +552,5 @@ return patientIdentifierAndAttribute; - } -} - + } +}