=== 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 2010-09-01 08:32:05 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java 2010-10-04 12:38:22 +0000 @@ -45,7 +45,6 @@ import org.hisp.dhis.relationship.RelationshipTypeService; import org.springframework.transaction.annotation.Transactional; - /** * @author Abyot Asalefew Gizaw * @version $Id$ @@ -78,28 +77,28 @@ { this.patientAttributeValueService = patientAttributeValueService; } - + private PatientAttributeService patientAttributeService; - + public void setPatientAttributeService( PatientAttributeService patientAttributeService ) { this.patientAttributeService = patientAttributeService; } - + private PatientIdentifierTypeService patientIdentifierTypeService; - + public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService ) { this.patientIdentifierTypeService = patientIdentifierTypeService; } - + private RelationshipService relationshipService; - + public void setRelationshipService( RelationshipService relationshipService ) { this.relationshipService = relationshipService; } - + private RelationshipTypeService relationshipTypeService; public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService ) @@ -108,7 +107,7 @@ } // ------------------------------------------------------------------------- - // PatientDataValue + // Patient // ------------------------------------------------------------------------- public int savePatient( Patient patient ) @@ -171,35 +170,40 @@ return patients; } - public Collection getPatients( OrganisationUnit organisationUnit, String searchText, int min, int max ) + public Collection getPatients( OrganisationUnit organisationUnit, String searchText, int min, int max ) { Collection patients = new ArrayList(); Collection allPatients = getPatients( searchText ); - if ( allPatients.retainAll( getPatientsByOrgUnit( organisationUnit , min, max ) ) ) + if ( allPatients.retainAll( getPatientsByOrgUnit( organisationUnit, min, max ) ) ) { patients = allPatients; } - + return patients; } public Collection getPatientsByOrgUnit( OrganisationUnit organisationUnit, int min, int max ) { - //List patientList = (ArrayList) patientIdentifierService.listPatientByOrganisationUnit( organisationUnit ); - return patientIdentifierService.listPatientByOrganisationUnit( organisationUnit , min, max ); + // List patientList = (ArrayList) + // patientIdentifierService.listPatientByOrganisationUnit( + // organisationUnit ); + return patientIdentifierService.listPatientByOrganisationUnit( organisationUnit, min, max ); } - public Collection getPatientsByOrgUnitAttr( OrganisationUnit organisationUnit, int min, int max , PatientAttribute patientAttribute) + public Collection getPatientsByOrgUnitAttr( OrganisationUnit organisationUnit, int min, int max, + PatientAttribute patientAttribute ) { - List patientList = (ArrayList) patientIdentifierService.listPatientByOrganisationUnit( organisationUnit ); - if(patientAttribute != null) + List patientList = (ArrayList) patientIdentifierService + .listPatientByOrganisationUnit( organisationUnit ); + if ( patientAttribute != null ) { - List sortedPatientList = (ArrayList) sortPatientsByAttribute(patientList, patientAttribute); - return sortedPatientList.subList(min, max); + List sortedPatientList = (ArrayList) sortPatientsByAttribute( patientList, + patientAttribute ); + return sortedPatientList.subList( min, max ); } - return patientList.subList(min, max); + return patientList.subList( min, max ); } public Collection sortPatientsByAttribute( Collection patients, PatientAttribute patientAttribute ) @@ -216,11 +220,16 @@ Collection patientAttributeValues = patientAttributeValueService .getPatientAttributeValues( patients ); - for ( PatientAttributeValue patientAttributeValue : patientAttributeValues ) + if ( patientAttributeValues != null ) { - if ( patientAttribute == patientAttributeValue.getPatientAttribute() ) - { - patientsSortedByAttribute.put( patientAttributeValue.getValue() + "-" + patientAttributeValue.getPatient().getFullName() + "-" + patientAttributeValue.getPatient().getId(), patientAttributeValue.getPatient() ); + for ( PatientAttributeValue patientAttributeValue : patientAttributeValues ) + { + if ( patientAttribute == patientAttributeValue.getPatientAttribute() ) + { + patientsSortedByAttribute.put( patientAttributeValue.getValue() + "-" + + patientAttributeValue.getPatient().getFullName() + "-" + + patientAttributeValue.getPatient().getId(), patientAttributeValue.getPatient() ); + } } } @@ -244,38 +253,38 @@ return sortedPatients; } - - public Collection getPatient( String firstName, String middleName, String lastName, Date birthdate, String gender ) + public Collection getPatient( String firstName, String middleName, String lastName, Date birthdate, + String gender ) { - return patientStore.getPatient( firstName, middleName, lastName, birthdate , gender); + return patientStore.getPatient( firstName, middleName, lastName, birthdate, gender ); } public Collection searchPatient( Integer identifierTypeId, Integer attributeId, String value ) { - if( attributeId != null ) + if ( attributeId != null ) { PatientAttribute attribute = patientAttributeService.getPatientAttribute( attributeId ); - if( attribute != null ) + if ( attribute != null ) { return patientAttributeValueService.getPatient( attribute, value ); } } - else if( identifierTypeId != null ) + else if ( identifierTypeId != null ) { PatientIdentifierType idenType = patientIdentifierTypeService.getPatientIdentifierType( identifierTypeId ); - if( idenType != null ) + if ( idenType != null ) { - Patient p = patientIdentifierService.getPatient( idenType, value ); - if( p != null ) - { - Set set = new HashSet(); - set.add( p ); - return set; - } + Patient p = patientIdentifierService.getPatient( idenType, value ); + if ( p != null ) + { + Set set = new HashSet(); + set.add( p ); + return set; + } } } - else + else { return patientStore.getByNames( value ); } @@ -294,38 +303,44 @@ public int countGetPatients( String searchText ) { - return patientStore.countGetPatientsByNames( searchText )+patientIdentifierService.countGetPatientsByIdentifier( searchText ); + return patientStore.countGetPatientsByNames( searchText ) + + patientIdentifierService.countGetPatientsByIdentifier( searchText ); } public Collection getPatients( String searchText, int min, int max ) { int countPatientName = patientStore.countGetPatientsByNames( searchText ); - + Set patients = new HashSet(); - - if( max < countPatientName ) + + if ( max < countPatientName ) { - patients.addAll( getPatientsByNames( searchText, min, max ) ); - + patients.addAll( getPatientsByNames( searchText, min, max ) ); + min = min - patients.size(); - }else { - if( min <= countPatientName ) + } + else + { + if ( min <= countPatientName ) { - patients.addAll( getPatientsByNames( searchText, min, countPatientName ) ); - + patients.addAll( getPatientsByNames( searchText, min, countPatientName ) ); + min = 0; max = max - countPatientName; - - Collection patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( searchText, min, max ); - + + Collection patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( + searchText, min, max ); + patients.addAll( patientsByIdentifier ); - }else + } + else { min = 0; max = max - countPatientName; - - Collection patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( searchText, min, max ); - + + Collection patientsByIdentifier = patientIdentifierService.getPatientsByIdentifier( + searchText, min, max ); + patients.addAll( patientsByIdentifier ); } } @@ -341,38 +356,38 @@ { return patientStore.getPatientsByNames( name, min, max ); } - + public int createPatient( Patient patient, OrganisationUnit orgUnit, Integer representativeId, - Integer relationshipTypeId, List patientAttributeValues ) + Integer relationshipTypeId, List patientAttributeValues ) { - + int patientid = savePatient( patient ); - for( PatientAttributeValue pav : patientAttributeValues ) + for ( PatientAttributeValue pav : patientAttributeValues ) { patientAttributeValueService.savePatientAttributeValue( pav ); } - //------------------------------------------------------------------------- + // ------------------------------------------------------------------------- // If underAge = true : save representative information. - //------------------------------------------------------------------------- - + // ------------------------------------------------------------------------- + if ( patient.isUnderAge() ) { - if( representativeId != null ) + if ( representativeId != null ) { Patient representative = patientStore.get( representativeId ); - if( representative != null ) + if ( representative != null ) { patient.setRepresentative( representative ); - + Relationship rel = new Relationship(); rel.setPatientA( representative ); - rel.setPatientB( patient ); - - if( relationshipTypeId != null ) + rel.setPatientB( patient ); + + if ( relationshipTypeId != null ) { RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId ); - if( relType != null ) + if ( relType != null ) { rel.setRelationshipType( relType ); relationshipService.saveRelationship( rel ); @@ -381,57 +396,58 @@ } } } - + return patientid; - + } - + public void updatePatient( Patient patient, OrganisationUnit orgUnit, Integer representativeId, - Integer relationshipTypeId, List valuesForSave, List valuesForUpdate, Collection valuesForDelete ) + Integer relationshipTypeId, List valuesForSave, + List valuesForUpdate, Collection valuesForDelete ) { - + patientStore.update( patient ); - for( PatientAttributeValue av : valuesForSave ) + for ( PatientAttributeValue av : valuesForSave ) { patientAttributeValueService.savePatientAttributeValue( av ); } - + for ( PatientAttributeValue av : valuesForUpdate ) { patientAttributeValueService.updatePatientAttributeValue( av ); } - + for ( PatientAttributeValue av : valuesForDelete ) { patientAttributeValueService.deletePatientAttributeValue( av ); } - - //------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- // If underAge = true : save representative information. - //------------------------------------------------------------------------- - + // ------------------------------------------------------------------------- + if ( patient.isUnderAge() ) { - - if( representativeId != null ) + + if ( representativeId != null ) { - if( patient.getRepresentative() == null || patient.getRepresentative().getId() != representativeId ) + if ( patient.getRepresentative() == null || patient.getRepresentative().getId() != representativeId ) { Patient representative = patientStore.get( representativeId ); - - if( representative != null ) + + if ( representative != null ) { patient.setRepresentative( representative ); - + Relationship rel = new Relationship(); rel.setPatientA( representative ); - rel.setPatientB( patient ); - - if( relationshipTypeId != null ) + rel.setPatientB( patient ); + + if ( relationshipTypeId != null ) { RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId ); - if( relType != null ) + if ( relType != null ) { rel.setRelationshipType( relType ); relationshipService.saveRelationship( rel );