-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jian | BAH-460 | add api for search similar patient using PersonService #29
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.bahmni.module.bahmnicore.service; | ||
|
||
import org.bahmni.module.bahmnicore.contract.patient.PatientSearchParameters; | ||
import org.bahmni.module.bahmnicore.contract.patient.mapper.PatientResponseMapper; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientConfigResponse; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Person; | ||
import org.openmrs.RelationshipType; | ||
|
||
import java.util.List; | ||
|
@@ -15,6 +17,8 @@ public interface BahmniPatientService { | |
|
||
List<PatientResponse> luceneSearch(PatientSearchParameters searchParameters); | ||
|
||
List<PatientResponse> searchSimilarPatients(PatientSearchParameters searchParameters, PatientResponseMapper patientResponseMapper); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the input parameter to this should actually be PatientProfile (which is https://github.com/openmrs/openmrs-module-emrapi/blob/master/api/src/main/java/org/openmrs/module/emrapi/patient/PatientProfile.java) This method should take the same type, so that the UI that is building up a PatientProfile to submit can just submit a partial version. |
||
|
||
public List<Patient> get(String partialIdentifier, boolean shouldMatchExactPatientId); | ||
|
||
public List<RelationshipType> getByAIsToB(String aIsToB); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package org.bahmni.module.bahmnicore.service.impl; | ||
|
||
import org.bahmni.module.bahmnicore.contract.patient.PatientSearchParameters; | ||
import org.bahmni.module.bahmnicore.contract.patient.mapper.PatientResponseMapper; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientConfigResponse; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; | ||
import org.bahmni.module.bahmnicore.dao.PatientDao; | ||
import org.bahmni.module.bahmnicore.service.BahmniPatientService; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Person; | ||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.RelationshipType; | ||
import org.openmrs.api.ConceptService; | ||
import org.openmrs.api.PersonService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.bahmniemrapi.visitlocation.BahmniVisitLocationServiceImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Service | ||
@Lazy //to get rid of cyclic dependencies | ||
|
@@ -83,6 +89,23 @@ public List<PatientResponse> luceneSearch(PatientSearchParameters searchParamete | |
searchParameters.getFilterPatientsByLocation(), searchParameters.getFilterOnAllIdentifiers()); | ||
} | ||
|
||
@Override | ||
public List<PatientResponse> searchSimilarPatients(PatientSearchParameters searchParameters, PatientResponseMapper patientResponseMapper) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going to use PatientResponseMapper in this service we should autowire it in the constructor, not ask for it to be passed in by the caller. |
||
List<PatientResponse> patients = new ArrayList<PatientResponse>(); | ||
Set<Person> persons = personService.getSimilarPeople(searchParameters.getName(), null, searchParameters.getGender()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to actually use Lucene here. OpenMRS's personService.getSimilarPeople does a handcrafted SQL query which doesn't perform well against large databases: https://github.com/openmrs/openmrs-core/blob/2.1.3/api/src/main/java/org/openmrs/api/db/hibernate/HibernatePersonDAO.java#L82 |
||
for (Person person : persons) { | ||
Patient patient = new Patient(person); | ||
PatientResponse patientResponse = patientResponseMapper.map( | ||
patient, | ||
searchParameters.getLoginLocationUuid(), | ||
searchParameters.getPatientSearchResultFields(), | ||
searchParameters.getAddressSearchResultFields(), | ||
patient.getPatientId()); | ||
patients.add(patientResponse); | ||
} | ||
return patients; | ||
} | ||
|
||
@Override | ||
public List<Patient> get(String partialIdentifier, boolean shouldMatchExactPatientId) { | ||
return patientDao.getPatients(partialIdentifier, shouldMatchExactPatientId); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
package org.bahmni.module.bahmnicore.service.impl; | ||
|
||
import org.bahmni.module.bahmnicore.contract.patient.PatientSearchParameters; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. presumably this change isn't necessary since there's no changes to the class itself |
||
import org.bahmni.module.bahmnicore.contract.patient.mapper.PatientResponseMapper; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientConfigResponse; | ||
import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; | ||
import org.bahmni.module.bahmnicore.dao.PatientDao; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Person; | ||
import org.openmrs.PersonAttributeType; | ||
import org.openmrs.api.ConceptService; | ||
import org.openmrs.api.PersonService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static org.mockito.Mockito.anyInt; | ||
|
@@ -26,6 +32,10 @@ public class BahmniPatientServiceImplTest { | |
private ConceptService conceptService; | ||
@Mock | ||
private PatientDao patientDao; | ||
@Mock | ||
private PatientSearchParameters searchParameters; | ||
@Mock | ||
private PatientResponseMapper patientResponseMapper; | ||
|
||
private BahmniPatientServiceImpl bahmniPatientService; | ||
|
||
|
@@ -67,4 +77,17 @@ public void shouldGetPatientByPartialIdentifier() throws Exception { | |
bahmniPatientService.get("partial_identifier", shouldMatchExactPatientId); | ||
verify(patientDao).getPatients("partial_identifier", shouldMatchExactPatientId); | ||
} | ||
|
||
@Test | ||
public void shouldGetSimiliarPatientResponseFromPersonSet() throws Exception { | ||
Set<Person> persons = new HashSet<Person>(); | ||
persons.add(new Person()); | ||
persons.add(new Person()); | ||
when(personService.getSimilarPeople(searchParameters.getName(), null, searchParameters.getGender())).thenReturn(persons); | ||
|
||
List<PatientResponse> response = bahmniPatientService.searchSimilarPatients(searchParameters, patientResponseMapper); | ||
|
||
assertEquals(response.size(), 2); | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add this field here we also need to make sure it's respected by existing API methods that use PatientSearchParameters.
(It would be okay to skip the gender field when searching for similar patients, if your timeline to finish this is tight.)