=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java 2013-04-03 06:20:25 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java 2013-05-15 03:23:45 +0000 @@ -243,4 +243,6 @@ Collection getPatientByFullname(String fullName, Integer orgunitId); Collection getRegistrationOrgunitIds( Date startDate, Date endDate ); + + Patient getLatestPatient(Integer orgunitId); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java 2013-04-03 06:20:25 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java 2013-05-15 03:23:45 +0000 @@ -75,15 +75,16 @@ Collection getPatientPhoneNumbers( List searchKeys, OrganisationUnit orgunit, Integer min, Integer max ); - List getProgramStageInstances( List searchKeys, OrganisationUnit orgunit, Integer min, - Integer max ); + List getProgramStageInstances( List searchKeys, OrganisationUnit orgunit, Integer min, Integer max ); Grid getPatientEventReport( Grid grid, List searchKeys, OrganisationUnit orgunit ); - - Collection getByPhoneNumber( String phoneNumber, Integer min, Integer max); - + + Collection getByPhoneNumber( String phoneNumber, Integer min, Integer max ); + Collection getByFullName( String fullName, Integer orgunitId ); - + Collection getRegistrationOrgunitIds( Date startDate, Date endDate ); + Patient getLatestPatient(Integer orgunitId); + } === modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java' --- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-04-22 03:11:28 +0000 +++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-05-15 03:23:45 +0000 @@ -83,5 +83,6 @@ public Program findProgram( String programInfo ) throws NotAllowedException; + public Patient findLatestPatient(int orgUnitId) throws NotAllowedException; } === 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-17 09:03:38 +0000 +++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-05-15 03:23:45 +0000 @@ -31,6 +31,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.net.IDN; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -287,7 +288,7 @@ { this.enrollmentRelationships = enrollmentRelationships; } - + public String getOrganisationUnitName() { return organisationUnitName; @@ -386,10 +387,13 @@ } // Write PatientIdentifier - dout.writeInt( identifiers.size() ); - for ( PatientIdentifier each : identifiers ) + if ( identifiers != null ) { - each.serialize( dout ); + dout.writeInt( identifiers.size() ); + for ( PatientIdentifier each : identifiers ) + { + each.serialize( dout ); + } } // Write Program === modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java' --- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-04-22 03:11:28 +0000 +++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-05-15 03:23:45 +0000 @@ -309,15 +309,14 @@ // programStageInstance.getDueDate(), 0 ) ); expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(), 30 ) ); - if ( programStageInstance.getDueDate().getTime() <= time - && expiredDate.getTimeInMillis() > time ) + if ( programStageInstance.getDueDate().getTime() <= time && expiredDate.getTimeInMillis() > time ) { items.add( getActivity( programStageInstance, programStageInstance.getDueDate().getTime() < time ) ); } } } - + return new ActivityPlan( items ); } @@ -446,8 +445,11 @@ } else { - //org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId, patients.get( 0 ) ); + // org.hisp.dhis.api.mobile.model.LWUITmodel.Patient + // patientMobile = getPatientModel( orgUnitId, patients.get( 0 ) + // ); org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patients.get( 0 ) ); + System.out.println( "patientmobile: " + patientMobile.getPrograms() ); return patientMobile; } } @@ -455,9 +457,10 @@ { Patient patient = patientService.getPatient( Integer.parseInt( keyword ) ); - //org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId, patient ); + // org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = + // getPatientModel( orgUnitId, patient ); org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patient ); - + System.out.println( "patient mobile2: " + patientMobile.getPrograms() ); return patientMobile; } @@ -496,7 +499,7 @@ programStageInstance.setCompleted( true ); - if( patientId != 0 ) + if ( patientId != 0 ) { programStageInstance.setOrganisationUnit( patientService.getPatient( patientId ).getOrganisationUnit() ); } @@ -661,7 +664,7 @@ } - //return getPatientModel( orgUnitId, patient ); + // return getPatientModel( orgUnitId, patient ); return getPatientModel( patient ); } @@ -787,7 +790,8 @@ } // get patient model for LWUIT - //private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( int orgUnitId, Patient patient ) + // private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient + // getPatientModel( int orgUnitId, Patient patient ) private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( Patient patient ) { org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientModel = new org.hisp.dhis.api.mobile.model.LWUITmodel.Patient(); @@ -1097,9 +1101,10 @@ private List generateEnrollmentProgramList( Patient patient ) { List programs = new ArrayList(); - - //for ( Program program : programService.getPrograms( orgUnitService.getOrganisationUnit( orgId ) ) ) - for ( Program program : programService.getPrograms( patient.getOrganisationUnit()) ) + + // for ( Program program : programService.getPrograms( + // orgUnitService.getOrganisationUnit( orgId ) ) ) + for ( Program program : programService.getPrograms( patient.getOrganisationUnit() ) ) { if ( (program.isSingleEvent() && program.isRegistration()) || !program.isSingleEvent() ) { @@ -1141,11 +1146,11 @@ String fullName = enrollmentRelationship.getPersonBName(); int startIndex = fullName.indexOf( ' ' ); int endIndex = fullName.lastIndexOf( ' ' ); - + String firstName = fullName.toString(); String middleName = " "; String lastName = " "; - + if ( fullName.indexOf( ' ' ) != -1 ) { firstName = fullName.substring( 0, startIndex ); @@ -1162,22 +1167,22 @@ } List patients = (List) this.patientService.getPatientByFullname( firstName + middleName + lastName, orgUnitId ); - - //remove the own searcher - patients = removeIfDuplicated( patients, enrollmentRelationship.getPersonAId()); - + + // remove the own searcher + patients = removeIfDuplicated( patients, enrollmentRelationship.getPersonAId() ); + if ( patients.size() > 1 ) { String patientsInfo = new String(); - + DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" ); - + for ( Patient each : patients ) { - patientsInfo += each.getId() + "/" + each.getFullName() + "/" + dateFormat.format( each.getBirthDate() ) - + "$"; + patientsInfo += each.getId() + "/" + each.getFullName() + "/" + + dateFormat.format( each.getBirthDate() ) + "$"; } - + throw new NotAllowedException( patientsInfo ); } else if ( patients.size() == 0 ) @@ -1190,8 +1195,8 @@ } } Patient patientA = patientService.getPatient( enrollmentRelationship.getPersonAId() ); - RelationshipType relationshipType = relationshipTypeService.getRelationshipType( enrollmentRelationship - .getId() ); + RelationshipType relationshipType = relationshipTypeService + .getRelationshipType( enrollmentRelationship.getId() ); Relationship relationship = new Relationship(); relationship.setRelationshipType( relationshipType ); @@ -1206,7 +1211,7 @@ relationship.setPatientB( patientA ); } relationshipService.saveRelationship( relationship ); - //return getPatientModel( orgUnitId, patientA ); + // return getPatientModel( orgUnitId, patientA ); return getPatientModel( patientA ); } @@ -1293,7 +1298,7 @@ anonymousProgramMobile.setId( anonymousProgram.getId() ); anonymousProgramMobile.setName( anonymousProgram.getName() ); - + anonymousProgramMobile.setVersion( anonymousProgram.getVersion() ); anonymousProgramMobile.setStatus( ProgramInstance.STATUS_ACTIVE ); @@ -1360,7 +1365,7 @@ private List removeIfDuplicated( List patients, int patientId ) { - List result = new ArrayList(patients); + List result = new ArrayList( patients ); for ( int i = 0; i < patients.size(); i++ ) { if ( patients.get( i ).getId() == patientId ) @@ -1635,4 +1640,14 @@ this.programStageService = programStageService; } + @Override + public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient findLatestPatient(int orgUnitId) + throws NotAllowedException + { + + Patient patient = (Patient) this.patientService.getLatestPatient(orgUnitId); + + org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patient ); + return patientMobile; + } } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java 2013-04-03 06:20:25 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java 2013-05-15 03:23:45 +0000 @@ -600,4 +600,11 @@ return patientStore.getRegistrationOrgunitIds( startDate, endDate ); } + @Override + public Patient getLatestPatient(Integer orgunitId) + { + + return patientStore.getLatestPatient(orgunitId); + } + } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-04-17 09:03:38 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-05-15 03:23:45 +0000 @@ -712,4 +712,16 @@ return orgunitIds; } + @Override + public Patient getLatestPatient(Integer orgunitId) + { + Patient patient = new Patient(); + String hql = "select p from Patient p where p.organisationUnit.id = " + orgunitId + " order by p.id DESC"; + Query query = getQuery( hql ); + query.setMaxResults( 1 ); + patient = (Patient) query.uniqueResult(); + + return patient; + } + } === 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-22 03:11:28 +0000 +++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-05-15 03:23:45 +0000 @@ -33,6 +33,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeService; +import org.hisp.dhis.patient.PatientIdentifierService; import org.hisp.dhis.patient.PatientIdentifierType; import org.hisp.dhis.patient.PatientIdentifierTypeService; import org.hisp.dhis.patient.PatientService; @@ -85,6 +86,13 @@ @Autowired private PatientAttributeService patientAttributeService; + private PatientIdentifierService patientIdentifierService; + + public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService ) + { + this.patientIdentifierService = patientIdentifierService; + } + private Integer patientId; public Integer getPatientId() @@ -353,7 +361,10 @@ @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/uploadProgramStage/{patientId}" ) @ResponseBody - public String saveProgramStage( @PathVariable int patientId, @PathVariable int id, @RequestBody ProgramStage programStage ) + public String saveProgramStage( @PathVariable + int patientId, @PathVariable + int id, @RequestBody + ProgramStage programStage ) throws NotAllowedException { return activityReportingService.saveProgramStage( programStage, patientId, id ); @@ -522,7 +533,6 @@ patientAttributeValue.setPatient( patientWeb ); patientAttributeValue.setPatientAttribute( patientAttribute ); patientAttributeValue.setValue( paAtt.getValue() ); - patientAttributeValues.add( patientAttributeValue ); } @@ -530,7 +540,7 @@ patientWeb.setIdentifiers( patientIdentifierSet ); patientWeb.setAttributes( patientAttributeSet ); - patientId = patientService.savePatient( patientWeb ); + patientId = patientService.createPatient( patientWeb, null, null, patientAttributeValues ); return PATIENT_REGISTERED; @@ -551,14 +561,13 @@ return patientIdentifierAndAttribute; } - + @RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/findLatestPerson" ) @ResponseBody public Patient findLatestPerson( @PathVariable - int id, @RequestHeader( "name" ) - String keyword ) + int id ) throws NotAllowedException { - return activityReportingService.findPatient( keyword, id ); + return activityReportingService.findLatestPatient( id ); } }