Which file to look into so I can change the Sql query for Search Patients

So I am calling this url:/openmrs/ws/rest/v1/bahmnicore/search/patient to retrieve all the patient records.But I want to change the sql query a bit and retrieve the records.Which file should I look into so that I can change the underlying sql query in Openmrs?

You mean you want to change the query in the OpenMRS core? Would you mind sharing the exact problem you’re facing?

Actually what I want to do is fetch all the registered patients from the db,so I called the searchPatients() of the registration page in my own page and it worked.But now I dont want to use the default code written for retrieving the records,but use a modified query to retrieve the records from the db.So how do I do that?

In other words,how do I write my own code to retrieve records from db

Are you using legacy UI or REST-WS? Because what you need might not require any modification in code. If you are using REST-WS. You may fetch objects by passing several types of filters. Check the Person and Patient examples here

How to pass filters?

If you’re using REST-WS, you can retrieve a person object by passing: name, address, attribute or UUID. Please check the swagger docs in OpenMRS demo: REST-WS Documentation

Username: admin Password: Admin123

Actually what I want to do is create a service in openmrs which will execute the following sql query: select * from person_name where SOUNDEX(given_name)=‘M540’; etc

I want to create a REST WS url and it should be consumed by Bahmni.

1 Like

OpenMRS does have Soundex implemented. You can check getSimilarPeople(…) method in: openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/HibernatePersonDAO.java

In fact, you can read other methods in this class as well.