Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
fix(patients): makes patient search case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Feb 7, 2020
1 parent 347f36e commit 4303b6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/__tests__/clients/db/PatientRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('patient repository', () => {

describe('search', () => {
it('should return all records that friendly ids match search text', async () => {
// same full to prove that it is finding by friendly id
// same full name to prove that it is finding by friendly id
const expectedFriendlyId = 'P00001'
await patients.put({ _id: 'id5678', friendlyId: expectedFriendlyId, fullName: 'test test' })
await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'test test' })
Expand All @@ -37,7 +37,7 @@ describe('patient repository', () => {
})

it('should return all records that fullName contains search text', async () => {
await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'blah test test blah' })
await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'blh test test blah' })
await patients.put({ _id: 'id5678', friendlyId: 'P00001', fullName: 'test test' })
await patients.put({ _id: 'id2345', friendlyId: 'P00003', fullName: 'not found' })

Expand All @@ -51,6 +51,19 @@ describe('patient repository', () => {
await patients.remove(await patients.get('id5678'))
await patients.remove(await patients.get('id2345'))
})

it('should match search criteria with case insensitive match', async () => {
await patients.put({ _id: 'id5678', friendlyId: 'P00001', fullName: 'test test' })
await patients.put({ _id: 'id1234', friendlyId: 'P00002', fullName: 'not found' })

const result = await PatientRepository.search('TEST TEST')

expect(result).toHaveLength(1)
expect(result[0].id).toEqual('id5678')

await patients.remove(await patients.get('id1234'))
await patients.remove(await patients.get('id5678'))
})
})

describe('findAll', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/clients/db/PatientRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PatientRepository extends Repository<Patient> {
$or: [
{
fullName: {
$regex: `^(.)*${text}(.)*$`,
$regex: RegExp(text, 'i'),
},
},
{
Expand Down

0 comments on commit 4303b6c

Please sign in to comment.