In this article
Bp Premier offers a comprehensive database search tool for retrieving records from the database based on patient record or system criteria.
What can I use a database search for?
A common use of the search tool is to produce a list of patients for a mail merge. For example, your practice is introducing a new diabetes management plan, and you need to set up a mailout to all of your active patients with this condition. See Send health awareness communications for more information.
If you are only interested in searching for patients by name or basic demographics, the Patient List window might be easier to use. Press F10 from the main screen.
Searches are created in Structured Query Language (SQL), but you do not need to understand SQL to use the search tool. You can select from a set of standard search filters for the records you are looking for, and Bp Premier will create the SQL query for you. You can also save queries that you run often, and import queries from other Bp Premier users.
Two common searches are searching for patients with diabetes and searching for patients who are or are not immunised. These searches provide examples of creating complex queries using the logic operators NOT, AND, and OR.
Where do I find the queries supplied with Bp Premier?
A number of useful queries are provided with a Bp Premier installation. These can be found in the folder C:\Program Files\Best Practice Software\BPS\SuppliedQueries.
- Select Utilities> Search from the Main menu to view the Database Search screen.
- Click Load query. A file explorer will open.
- Browse to the SQL query file you want to load and click Open. The query will be loaded into the SQL query box.
- Click Run Query.
A useful query for your practice to run is 'Active patients who have not had a visit in the last 12 months and have no future appointments and not created in the last 6 months'. This query can assist your practice in deactivating patients who have not visited your practice in some time, and can be marked as inactive. See Mark patients as inactive or deceased for more information.
Run a database search query
- Select Utilities > Search from the main menu to view the Database Search screen.
- If you are proficient at SQL and know the Bp Premier database structure, you can type your custom query directly into the SQL Query text field.
- Otherwise, click the button that matches the area you want to search by. A Search for ... screen will be displayed that depends on the selected button.
- Complete the criteria you want to search for in the top half of the Search screen. The fields available will depend on the selected button. For example, if you clicked Drugs, you would select the drug prescription you are searching for, and which doctor prescribed. If you clicked Observations, you would select the clinical observation and the range of values the observation should fall between.
- Click Add to add the search condition to the Condition box at the bottom of the screen.
- Repeat to add as many conditions are you need.
- Click OK from the Search screen to return to the Database search screen. The SQL Query has been updated to reflect your search criteria.
- If you need to include inactive patients in your search results, tick the checkbox.
- If you need to include deceased patients in your search results, tick the checkbox.
- Click Run query to execute the query and list the patients who meet that condition.
- If the query ran successfully, and you think you may need to rerun the query in the future, click Save query to save the query to disk with a meaningful name.
The filter buttons along the top will open a filter screen that allows you to drill down on the data you are looking for. For example, click Demographics to search based on patient demographic data, or click Visits to search based on patient visit data.
It may take a few attempts to create a query that returns the results you want. You can use the samples database installed with Bp Premier to practice running database requests without putting load on the live server.
Using AND and NOT
Use the logic operators in each filter screen to create complex searches. For example, the following construct for the Rx filter searches for patients prescribed Zoloft by both Dr I. Cure and Dr F. Findacure, and have not been prescribed Lipitor by Dr I. Cure.
This example searches for all patients who are 55 or over years old with a body mass index over 25.
- From the Database search screen, click Demographics to display the Search for patients screen.
- Select 'Age' from the Column name field.
- Select '>=' from the middle column.
- Type '55' in the field marked with the red asterisk.
- Click Add, and click OK.
- Click Observations to open the Search by observation screen.
- Select 'BMI' in the Observation field.
- Select '>' from the middle column.
- Type '25' in the text field on the right.
- Click Add, and click OK.
- Click Run Query.
- Select File > Save to save the list of patients who match the query results.
Save the results of a query
You can export the results of a query to file. This is not the same as exporting patient data.
- Create or load a query from the Database search screen, and run the query.
- Click the disk icon in the toolbar, or select File > Save. The Save As screen will appear.
- Replace the default File name with a meaningful file name, so you can recognise the results file.
- Select the file format from the Save as type field: XML, CSV, or tab delimited. Select 'CSV' if you intend to use the results in a spreadsheet application.
- Click Save.
Database search examples
Patients who have past history of diabetes but not Gestational diabetes and their Systolic BP in the past year has been over 170
SELECT *
FROM BPS_Patients
WHERE StatusText = 'Active'
AND InternalID IN (SELECT InternalID FROM PastHistory
WHERE ItemCode IN (3, 775, 776, 778, 774) AND RecordStatus = 1)
AND NOT InternalID IN (SELECT InternalID FROM PastHistory WHERE ItemCode = 780 AND RecordStatus = 1)
AND InternalID IN (SELECT InternalID FROM Observations WHERE DataName = 'Systolic' AND ObsDate > '01/01/2007' AND DataValue >= 170 AND RecordStatus = 1)
ORDER BY surname, firstname
Patients who have had 45 to 49 year old health assessments performed in the last year who was seen by a specific doctor
SELECT *
FROM BPS_Patients
WHERE StatusText = 'Active'
AND DOB < DateAdd(Year, -45, GetDate())
AND DOB > DateAdd(Year, -50, GetDate())
AND InternalID IN (SELECT InternalID FROM Visits WHERE VisitDate >= DateAdd(Year, -1, GetDate()) AND VisitDate <= GetDate()AND RecordStatus = 1 AND
UserID in (SELECT UserID FROM Users WHERE Surname ='Findacure'))
ORDER BY surname, firstname
Patients who smoke more than 10 cigarettes per day and have not received a Fluvax immunisation
SELECT *
FROM BPS_Patients
WHERE StatusText = 'Active'
AND InternalID IN (SELECT InternalID FROM Tobacco WHERE SmokingCode = 3 AND SmokesPerDay > 10)
AND InternalID NOT IN (SELECT InternalID FROM Immunisations
WHERE GivenDate >= '01/01/2005' AND VaccineName = 'Fluvax')
ORDER BY surname, firstname