=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-10-16 17:00:52 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-11-25 06:30:47 +0000 @@ -81,7 +81,9 @@ private Integer status = ACTIVE_STATUS; - private String coordinates; + private Double longitude; + + private Double latitude; private String completedUser; @@ -292,16 +294,6 @@ this.status = status; } - public String getCoordinates() - { - return coordinates; - } - - public void setCoordinates( String coordinates ) - { - this.coordinates = coordinates; - } - public List getMessageConversations() { return messageConversations; @@ -312,6 +304,26 @@ this.messageConversations = messageConversations; } + public Double getLongitude() + { + return longitude; + } + + public void setLongitude( Double longitude ) + { + this.longitude = longitude; + } + + public Double getLatitude() + { + return latitude; + } + + public void setLatitude( Double latitude ) + { + this.latitude = latitude; + } + public Integer getEventStatus() { if ( this.status != 0 ) === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-11-19 10:02:44 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-11-25 06:30:47 +0000 @@ -72,7 +72,8 @@ /** * @author Morten Olav Hansen */ -public abstract class AbstractEventService implements EventService +public abstract class AbstractEventService + implements EventService { // ------------------------------------------------------------------------- // Dependencies @@ -170,7 +171,8 @@ if ( programStage == null && !program.isSingleEvent() ) { - return new ImportSummary( ImportStatus.ERROR, "Event.programStage does not point to a valid programStage, and program is multi stage" ); + return new ImportSummary( ImportStatus.ERROR, + "Event.programStage does not point to a valid programStage, and program is multi stage" ); } else if ( programStage == null ) { @@ -182,14 +184,16 @@ if ( verifyProgramAccess( program ) ) { - return new ImportSummary( ImportStatus.ERROR, "Current user does not have permission to access this program." ); + return new ImportSummary( ImportStatus.ERROR, + "Current user does not have permission to access this program." ); } if ( program.isRegistration() ) { if ( event.getPerson() == null ) { - return new ImportSummary( ImportStatus.ERROR, "No Event.person was provided for registration based program." ); + return new ImportSummary( ImportStatus.ERROR, + "No Event.person was provided for registration based program." ); } Patient patient = patientService.getPatient( event.getPerson() ); @@ -204,13 +208,14 @@ if ( programInstances.isEmpty() ) { - return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + " is not enrolled in program " + program.getUid() ); + return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + + " is not enrolled in program " + program.getUid() ); } else if ( programInstances.size() > 1 ) { - return new ImportSummary( ImportStatus.ERROR, - "Person " + patient.getUid() + " have multiple active enrollments into program " + program.getUid() - + " please check and correct your database." ); + return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + + " have multiple active enrollments into program " + program.getUid() + + " please check and correct your database." ); } programInstance = programInstances.get( 0 ); @@ -222,13 +227,14 @@ if ( programStageInstances.isEmpty() ) { - return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + " is not enrolled in programStage " + programStage.getUid() ); + return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + + " is not enrolled in programStage " + programStage.getUid() ); } else if ( programStageInstances.size() > 1 ) { - return new ImportSummary( ImportStatus.ERROR, - "Person " + patient.getUid() + " have multiple active enrollments into programStage " + programStage.getUid() - + " please check and correct your database for multiple active stages." ); + return new ImportSummary( ImportStatus.ERROR, "Person " + patient.getUid() + + " have multiple active enrollments into programStage " + programStage.getUid() + + " please check and correct your database for multiple active stages." ); } programStageInstance = programStageInstances.get( 0 ); @@ -237,7 +243,8 @@ { if ( !programStage.getIrregular() ) { - programStageInstance = programStageInstanceService.getProgramStageInstance( programInstance, programStage ); + programStageInstance = programStageInstanceService.getProgramStageInstance( programInstance, + programStage ); } else @@ -261,13 +268,15 @@ if ( programInstances.isEmpty() ) { - return new ImportSummary( ImportStatus.ERROR, "No active event exists for single event no registration program " + program.getUid() - + ", please check and correct your database." ); + return new ImportSummary( ImportStatus.ERROR, + "No active event exists for single event no registration program " + program.getUid() + + ", please check and correct your database." ); } else if ( programInstances.size() > 1 ) { - return new ImportSummary( ImportStatus.ERROR, "Multiple active events exists for single event no registration program " + program.getUid() - + ", please check and correct your database." ); + return new ImportSummary( ImportStatus.ERROR, + "Multiple active events exists for single event no registration program " + program.getUid() + + ", please check and correct your database." ); } programInstance = programInstances.get( 0 ); @@ -286,7 +295,8 @@ return new ImportSummary( ImportStatus.ERROR, "Program is not assigned to this organisation unit." ); } - return saveEvent( program, programInstance, programStage, programStageInstance, organisationUnit, event, importOptions ); + return saveEvent( program, programInstance, programStage, programStageInstance, organisationUnit, event, + importOptions ); } // ------------------------------------------------------------------------- @@ -314,7 +324,8 @@ } @Override - public Events getEvents( Program program, OrganisationUnit organisationUnit, Person person, Date startDate, Date endDate ) + public Events getEvents( Program program, OrganisationUnit organisationUnit, Person person, Date startDate, + Date endDate ) { List eventList = eventStore.getAll( program, organisationUnit, person, startDate, endDate ); Events events = new Events(); @@ -344,7 +355,8 @@ } @Override - public Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit, Person person, Date startDate, Date endDate ) + public Events getEvents( ProgramStage programStage, OrganisationUnit organisationUnit, Person person, + Date startDate, Date endDate ) { List eventList = eventStore.getAll( programStage, organisationUnit, person, startDate, endDate ); Events events = new Events(); @@ -364,7 +376,8 @@ } @Override - public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Person person ) + public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, + Person person ) { List eventList = eventStore.getAll( program, programStage, organisationUnit, person ); Events events = new Events(); @@ -374,7 +387,8 @@ } @Override - public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Date startDate, Date endDate ) + public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, + Date startDate, Date endDate ) { List eventList = eventStore.getAll( program, programStage, organisationUnit, startDate, endDate ); Events events = new Events(); @@ -384,7 +398,8 @@ } @Override - public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, Person person, Date startDate, Date endDate ) + public Events getEvents( Program program, ProgramStage programStage, OrganisationUnit organisationUnit, + Person person, Date startDate, Date endDate ) { List eventList = eventStore.getAll( program, programStage, organisationUnit, person, startDate, endDate ); Events events = new Events(); @@ -394,7 +409,8 @@ } @Override - public Events getEvents( List programs, List programStages, List organisationUnits, Date startDate, Date endDate ) + public Events getEvents( List programs, List programStages, + List organisationUnits, Date startDate, Date endDate ) { List eventList = eventStore.getAll( programs, programStages, organisationUnits, startDate, endDate ); Events events = new Events(); @@ -423,7 +439,8 @@ @Override public void updateEvent( Event event ) { - ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() ); + ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event + .getEvent() ); if ( programStageInstance == null ) { @@ -452,13 +469,15 @@ programStageInstanceService.updateProgramStageInstance( programStageInstance ); - Set patientDataValues = new HashSet( patientDataValueService.getPatientDataValues( programStageInstance ) ); + Set patientDataValues = new HashSet( + patientDataValueService.getPatientDataValues( programStageInstance ) ); for ( DataValue value : event.getDataValues() ) { DataElement dataElement = dataElementService.getDataElement( value.getDataElement() ); - PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, dataElement ); + PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, + dataElement ); if ( patientDataValue != null ) { @@ -470,7 +489,8 @@ } else { - saveDataValue( programStageInstance, event.getStoredBy(), dataElement, value.getValue(), value.getProvidedElsewhere() ); + saveDataValue( programStageInstance, event.getStoredBy(), dataElement, value.getValue(), + value.getProvidedElsewhere() ); } } @@ -487,7 +507,8 @@ @Override public void deleteEvent( Event event ) { - ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event.getEvent() ); + ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( event + .getEvent() ); if ( programStageInstance != null ) { @@ -518,13 +539,14 @@ if ( programStageInstance.getProgramStage().getCaptureCoordinates() ) { - Coordinate coordinate = new Coordinate(); + Coordinate coordinate = null; + if ( programStageInstance.getLongitude() != null && programStageInstance.getLongitude() != null ) + { + coordinate = new Coordinate( programStageInstance.getLongitude(), programStageInstance.getLatitude() ); - if ( programStageInstance.getCoordinates() != null ) - { try { - List list = objectMapper.readValue( programStageInstance.getCoordinates(), new TypeReference>() + List list = objectMapper.readValue( coordinate.getCoordinateString(), new TypeReference>() { } ); @@ -542,7 +564,8 @@ } } - Collection patientDataValues = patientDataValueService.getPatientDataValues( programStageInstance ); + Collection patientDataValues = patientDataValueService + .getPatientDataValues( programStageInstance ); for ( PatientDataValue patientDataValue : patientDataValues ) { @@ -589,7 +612,8 @@ private boolean validateDataElement( DataElement dataElement, String value, ImportSummary importSummary ) { - InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value, getFormat() ); + InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value, + getFormat() ); if ( !status.isSuccess() ) { @@ -613,21 +637,25 @@ { if ( importSummary != null ) { - importSummary.getConflicts().add( new ImportConflict( "storedBy", storedBy + " is more than 31 characters, using current username instead." ) ); + importSummary.getConflicts().add( + new ImportConflict( "storedBy", storedBy + + " is more than 31 characters, using current username instead." ) ); } storedBy = currentUserService.getCurrentUsername(); } return storedBy; } - private void saveDataValue( ProgramStageInstance programStageInstance, String storedBy, DataElement dataElement, String value, Boolean providedElsewhere ) + private void saveDataValue( ProgramStageInstance programStageInstance, String storedBy, DataElement dataElement, + String value, Boolean providedElsewhere ) { if ( value != null && value.trim().length() == 0 ) { value = null; } - PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, dataElement ); + PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, + dataElement ); if ( value != null ) { @@ -655,17 +683,21 @@ } } - private ProgramStageInstance createProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance, OrganisationUnit organisationUnit, Date date, Boolean completed, + private ProgramStageInstance createProgramStageInstance( ProgramStage programStage, + ProgramInstance programInstance, OrganisationUnit organisationUnit, Date date, Boolean completed, Coordinate coordinate, String storedBy ) { ProgramStageInstance programStageInstance = new ProgramStageInstance(); - updateProgramStageInstance( programStage, programInstance, organisationUnit, date, completed, coordinate, storedBy, programStageInstance ); + updateProgramStageInstance( programStage, programInstance, organisationUnit, date, completed, coordinate, + storedBy, programStageInstance ); programStageInstanceService.addProgramStageInstance( programStageInstance ); return programStageInstance; } - private void updateProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance, OrganisationUnit organisationUnit, Date date, Boolean completed, Coordinate coordinate, String storedBy, ProgramStageInstance programStageInstance ) + private void updateProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance, + OrganisationUnit organisationUnit, Date date, Boolean completed, Coordinate coordinate, String storedBy, + ProgramStageInstance programStageInstance ) { programStageInstance.setProgramInstance( programInstance ); programStageInstance.setProgramStage( programStage ); @@ -677,11 +709,8 @@ { if ( coordinate.isValid() ) { - programStageInstance.setCoordinates( coordinate.getCoordinateString() ); - } - else - { - programStageInstance.setCoordinates( null ); + programStageInstance.setLongitude( coordinate.getLongitude() ); + programStageInstance.setLatitude( coordinate.getLatitude() ); } } @@ -696,7 +725,9 @@ } } - private ImportSummary saveEvent( Program program, ProgramInstance programInstance, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions ) + private ImportSummary saveEvent( Program program, ProgramInstance programInstance, ProgramStage programStage, + ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, Event event, + ImportOptions importOptions ) { Assert.notNull( program ); Assert.notNull( programInstance ); @@ -719,13 +750,14 @@ { if ( programStageInstance == null ) { - programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit, eventDate, - EventStatus.COMPLETED.equals( event.getStatus() ), event.getCoordinate(), storedBy ); + programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit, + eventDate, EventStatus.COMPLETED.equals( event.getStatus() ), event.getCoordinate(), storedBy ); } else { updateProgramStageInstance( programStage, programInstance, organisationUnit, eventDate, - EventStatus.COMPLETED.equals( event.getStatus() ), event.getCoordinate(), storedBy, programStageInstance ); + EventStatus.COMPLETED.equals( event.getStatus() ), event.getCoordinate(), storedBy, + programStageInstance ); } importSummary.setReference( programStageInstance.getUid() ); @@ -737,7 +769,8 @@ if ( dataElement == null ) { - importSummary.getConflicts().add( new ImportConflict( "dataElement", dataValue.getDataElement() + " is not a valid dataElementId." ) ); + importSummary.getConflicts().add( + new ImportConflict( "dataElement", dataValue.getDataElement() + " is not a valid dataElementId." ) ); importSummary.getDataValueCount().incrementIgnored(); } else @@ -748,7 +781,8 @@ if ( !dryRun ) { - saveDataValue( programStageInstance, dataValueStoredBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere() ); + saveDataValue( programStageInstance, dataValueStoredBy, dataElement, dataValue.getValue(), + dataValue.getProvidedElsewhere() ); } importSummary.getDataValueCount().incrementImported(); === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2013-10-16 17:29:40 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2013-11-25 06:30:47 +0000 @@ -46,6 +46,7 @@ import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.program.ProgramStageService; import org.hisp.dhis.system.startup.AbstractStartupRoutine; +import org.hisp.dhis.system.util.ValidationUtils; import org.springframework.transaction.annotation.Transactional; /** @@ -248,9 +249,9 @@ executeSql( "update patientidentifiertype set orgunitScope=false where orgunitScope is null" ); executeSql( "update patientidentifiertype set programScope=false where programScope is null" ); - + executeSql( "update programstageinstance set status=0 where status is null" ); - executeSql( "ALTER TABLE patienttabularreport RENAME level TO ouMode" ); + executeSql( "ALTER TABLE patienttabularreport RENAME level TO ouMode" ); executeSql( "ALTER TABLE program DROP COLUMN facilityLB" ); executeSql( "DROP TABLE patienttabularreport_attributes" ); executeSql( "DROP TABLE patienttabularreport_filtervalues" ); @@ -265,10 +266,12 @@ executeSql( "DROP TABLE patientaggregatereport_organisationunits" ); executeSql( "DROP TABLE patientaggregatereport_relativeperiods" ); executeSql( "DROP TABLE patientaggregatereport_startdates" ); - executeSql( "ALTER TABLE patientaggregatereport RENAME level TO ouMode" ); + executeSql( "ALTER TABLE patientaggregatereport RENAME level TO ouMode" ); executeSql( "ALTER TABLE patientaggregatereport DROP COLUMN facilityLB" ); executeSql( "update programstage_dataelements set allowDateInFuture=false where allowDateInFuture is null" ); executeSql( "update programstage set autoGenerateEvent=true where programid in ( select programid from program where type=2 )" ); + + updateCoordinatesProgramStageInstance(); } // ------------------------------------------------------------------------- @@ -403,6 +406,38 @@ executeSql( "ALTER TABLE programinstance DROP COLUMN completed" ); } + private void updateCoordinatesProgramStageInstance() + { + StatementHolder holder = statementManager.getHolder(); + + try + { + Statement statement = holder.getStatement(); + + ResultSet resultSet = statement + .executeQuery( "SELECT programstageinstanceid, coordinates FROM programstageinstance where coordinates is not null" ); + + while ( resultSet.next() ) + { + String coordinates = resultSet.getString( "coordinates" ); + String longitude = ValidationUtils.getLongitude( coordinates ); + String latitude = ValidationUtils.getLatitude( coordinates ); + executeSql( "UPDATE programstageinstance SET longitude='" + longitude + "', latitude='" + latitude + + "' WHERE programstageinstanceid=" + resultSet.getInt( "programstageinstanceid" ) ); + } + + executeSql( "ALTER TABLE programstageinstance DROP COLUMN coordinates" ); + } + catch ( Exception ex ) + { + log.debug( ex ); + } + finally + { + holder.close(); + } + } + private int executeSql( String sql ) { try === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml 2013-10-30 16:09:53 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml 2013-11-25 06:30:47 +0000 @@ -50,8 +50,10 @@ - + + + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetProgramStageInstanceAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetProgramStageInstanceAction.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetProgramStageInstanceAction.java 2013-11-25 06:30:47 +0000 @@ -28,22 +28,23 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.opensymphony.xwork2.Action; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + import org.hisp.dhis.patientdatavalue.PatientDataValue; import org.hisp.dhis.patientdatavalue.PatientDataValueService; import org.hisp.dhis.program.ProgramStageInstance; import org.hisp.dhis.program.ProgramStageInstanceService; -import org.hisp.dhis.system.util.ValidationUtils; import org.hisp.dhis.user.CurrentUserService; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import com.opensymphony.xwork2.Action; /** * @author Morten Olav Hansen */ -public class GetProgramStageInstanceAction implements Action +public class GetProgramStageInstanceAction + implements Action { // ------------------------------------------------------------------------- @@ -89,16 +90,16 @@ return programStageInstance; } - private String latitude; + private Double latitude; - public String getLatitude() + public Double getLatitude() { return latitude; } - private String longitude; + private Double longitude; - public String getLongitude() + public Double getLongitude() { return longitude; } @@ -122,7 +123,8 @@ // ------------------------------------------------------------------------- @Override - public String execute() throws Exception + public String execute() + throws Exception { if ( programStageInstanceId == null ) { @@ -138,6 +140,10 @@ return SUCCESS; } + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + private void populateCurrentUsername() { currentUsername = currentUserService.getCurrentUsername(); @@ -148,8 +154,8 @@ if ( programStageInstance != null && programStageInstance.getProgramStage() != null && programStageInstance.getProgramStage().getCaptureCoordinates() ) { - longitude = ValidationUtils.getLongitude( programStageInstance.getCoordinates() ); - latitude = ValidationUtils.getLatitude( programStageInstance.getCoordinates() ); + longitude = programStageInstance.getLongitude(); + latitude = programStageInstance.getLatitude(); } } @@ -166,4 +172,3 @@ } } } - === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2013-11-19 06:51:39 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2013-11-25 06:30:47 +0000 @@ -55,7 +55,6 @@ import org.hisp.dhis.program.ProgramStageService; import org.hisp.dhis.program.comparator.ProgramStageDataElementSortOrderComparator; import org.hisp.dhis.program.comparator.ProgramStageSectionSortOrderComparator; -import org.hisp.dhis.system.util.ValidationUtils; import com.opensymphony.xwork2.Action; @@ -241,16 +240,16 @@ return calAttributeValueMap; } - private String longitude; + private Double longitude; - public String getLongitude() + public Double getLongitude() { return longitude; } - private String latitude; + private Double latitude; - public String getLatitude() + public Double getLatitude() { return latitude; } @@ -357,8 +356,8 @@ // Allow update only if org unit does not have polygon coordinates // ----------------------------------------------------------------- - longitude = ValidationUtils.getLongitude( programStageInstance.getCoordinates() ); - latitude = ValidationUtils.getLatitude( programStageInstance.getCoordinates() ); + longitude = programStageInstance.getLongitude(); + latitude = programStageInstance.getLatitude(); } return SUCCESS; === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveCoordinatesEventAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveCoordinatesEventAction.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveCoordinatesEventAction.java 2013-11-25 06:30:47 +0000 @@ -30,7 +30,6 @@ import org.hisp.dhis.program.ProgramStageInstance; import org.hisp.dhis.program.ProgramStageInstanceService; -import org.hisp.dhis.system.util.ValidationUtils; import com.opensymphony.xwork2.Action; @@ -64,16 +63,16 @@ this.programStageInstanceId = programStageInstanceId; } - private String longitude; + private Double longitude; - public void setLongitude( String longitude ) + public void setLongitude( Double longitude ) { this.longitude = longitude; } - private String latitude; + private Double latitude; - public void setLatitude( String latitude ) + public void setLatitude( Double latitude ) { this.latitude = latitude; } @@ -85,9 +84,6 @@ public String execute() throws Exception { - longitude = (longitude == null || longitude.isEmpty() ) ? null : longitude; - latitude = (latitude == null || latitude.isEmpty() ) ? null : latitude; - // --------------------------------------------------------------------- // Set coordinates and feature type to point if valid // --------------------------------------------------------------------- @@ -97,20 +93,12 @@ if ( longitude != null && latitude != null ) { - String coordinates = ValidationUtils.getCoordinate( longitude, latitude ); - - if ( ValidationUtils.coordinateIsValid( coordinates ) ) - { - programStageInstance.setCoordinates( coordinates ); - } - } - else - { - programStageInstance.setCoordinates( null ); + programStageInstance.setLongitude( longitude ); + programStageInstance.setLatitude( latitude ); } programStageInstanceService.updateProgramStageInstance( programStageInstance ); - + return SUCCESS; } } === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java 2013-09-17 12:15:39 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java 2013-11-25 06:30:47 +0000 @@ -58,7 +58,8 @@ /** * @author Morten Olav Hansen */ -public class UploadAnonymousEventAction implements Action +public class UploadAnonymousEventAction + implements Action { // ------------------------------------------------------------------------- // Dependencies @@ -108,14 +109,16 @@ // ------------------------------------------------------------------------- @Override - @SuppressWarnings("unchecked") - public String execute() throws Exception + @SuppressWarnings( "unchecked" ) + public String execute() + throws Exception { ServletInputStream inputStream = ServletActionContext.getRequest().getInputStream(); - Map input = JacksonUtils.getJsonMapper().readValue( inputStream, new TypeReference>() - { - } ); + Map input = JacksonUtils.getJsonMapper().readValue( inputStream, + new TypeReference>() + { + } ); Map executionDate = (Map) input.get( "executionDate" ); @@ -136,17 +139,16 @@ { } - Coordinate coordinate = null; + Double longitude = null; + Double latitude = null; Map coord = (Map) input.get( "coordinate" ); if ( coord != null ) { try { - double lng = Double.parseDouble( coord.get( "longitude" ) ); - double lat = Double.parseDouble( coord.get( "latitude" ) ); - - coordinate = new Coordinate( lng, lat ); + longitude = Double.parseDouble( coord.get( "longitude" ) ); + latitude = Double.parseDouble( coord.get( "latitude" ) ); } catch ( NullPointerException ignored ) { @@ -171,7 +173,7 @@ if ( programStageInstanceId != null ) { programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId ); - updateExecutionDate( programStageInstance, date, completed, coordinate ); + updateExecutionDate( programStageInstance, date, completed, longitude, latitude ); } else { @@ -191,7 +193,7 @@ return INPUT; } - programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed, coordinate ); + programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed, longitude, latitude ); } Map values = (Map) input.get( "values" ); @@ -213,7 +215,8 @@ return SUCCESS; } - private void updateExecutionDate( ProgramStageInstance programStageInstance, Date date, Boolean completed, Coordinate coordinate ) + private void updateExecutionDate( ProgramStageInstance programStageInstance, Date date, Boolean completed, + Double longitude, Double latitude ) { if ( date != null ) { @@ -230,13 +233,10 @@ if ( programStageInstance.getProgramStage().getCaptureCoordinates() ) { - if ( coordinate != null && coordinate.isValid() ) - { - programStageInstance.setCoordinates( coordinate.getCoordinateString() ); - } - else - { - programStageInstance.setCoordinates( null ); + if ( longitude != null && latitude != null ) + { + programStageInstance.setLongitude( longitude ); + programStageInstance.setLatitude( latitude ); } } @@ -245,8 +245,8 @@ programStageInstanceService.updateProgramStageInstance( programStageInstance ); } - private ProgramStageInstance saveExecutionDate( Integer programId, Integer organisationUnitId, Date date, Boolean completed, - Coordinate coordinate ) + private ProgramStageInstance saveExecutionDate( Integer programId, Integer organisationUnitId, Date date, + Boolean completed, Double longitude, Double latitude ) { OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); Program program = programService.getProgram( programId ); @@ -269,13 +269,10 @@ if ( programStage.getCaptureCoordinates() ) { - if ( coordinate != null && coordinate.isValid() ) - { - programStageInstance.setCoordinates( coordinate.getCoordinateString() ); - } - else - { - programStageInstance.setCoordinates( null ); + if ( longitude != null && latitude != null ) + { + programStageInstance.setLongitude( longitude ); + programStageInstance.setLatitude( latitude ); } } @@ -286,7 +283,8 @@ return programStageInstance; } - private void saveDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, String value, Boolean providedElsewhere ) + private void saveDataValue( ProgramStageInstance programStageInstance, DataElement dataElement, String value, + Boolean providedElsewhere ) { String storedBy = currentUserService.getCurrentUsername(); @@ -295,7 +293,8 @@ value = null; } - PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, dataElement ); + PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance, + dataElement ); if ( value != null ) {