From 4303b6c3523576df8125980df98d81bb8512db20 Mon Sep 17 00:00:00 2001 From: Jack Meyer Date: Thu, 6 Feb 2020 23:23:01 -0600 Subject: [PATCH] fix(patients): makes patient search case insensitive --- .../clients/db/PatientRepository.test.ts | 17 +++++++++++++++-- src/clients/db/PatientRepository.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/__tests__/clients/db/PatientRepository.test.ts b/src/__tests__/clients/db/PatientRepository.test.ts index 083ef9f247..6d60393d33 100644 --- a/src/__tests__/clients/db/PatientRepository.test.ts +++ b/src/__tests__/clients/db/PatientRepository.test.ts @@ -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' }) @@ -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' }) @@ -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', () => { diff --git a/src/clients/db/PatientRepository.ts b/src/clients/db/PatientRepository.ts index a3dbcca39f..e92b2d8190 100644 --- a/src/clients/db/PatientRepository.ts +++ b/src/clients/db/PatientRepository.ts @@ -24,7 +24,7 @@ export class PatientRepository extends Repository { $or: [ { fullName: { - $regex: `^(.)*${text}(.)*$`, + $regex: RegExp(text, 'i'), }, }, {