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

feat(patients): escape string in appointments search #2031

Merged
merged 44 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1f19bb8
npm yarn install
JDarke Apr 21, 2020
1d922c7
fix(src/components/input/textfieldwithlabelformgroup.tsx): update Label
JDarke Apr 21, 2020
7efe678
revert(package.json): remove yarn listing
JDarke Apr 21, 2020
c7dba69
Merge branch 'master' into master
Apr 21, 2020
ba91b21
Merge branch 'master' into master
Apr 21, 2020
404a7a2
Merge branch 'master' into master
Apr 22, 2020
6a2523c
Merge branch 'master' into master
Apr 22, 2020
9f8c1d7
Merge branch 'master' into master
Apr 22, 2020
9bfb378
Merge branch 'master' into master
Apr 22, 2020
71cd8b0
Merge branch 'master' into master
Apr 22, 2020
8cac332
Merge branch 'master' into master
Apr 22, 2020
92ad7f7
Merge branch 'master' into master
Apr 22, 2020
b7e355a
Merge branch 'master' into master
Apr 22, 2020
36b889e
test(textfieldwithlabelformgroup.test.tsx): add test to Label isRequired
JDarke Apr 22, 2020
7791d9e
refactor(textfieldwithlabelformgroup.test.tsx): make props semantic
JDarke Apr 22, 2020
add9c02
fix(patientrepository.ts): clean the search string of illegal chars
JDarke Apr 23, 2020
57144a2
fix(patientrepository.ts): clean search string of illegal chars
JDarke Apr 23, 2020
0ffef66
fix(patientrepository.ts): clean search string of special chars
JDarke Apr 24, 2020
3354e9f
Merge branch 'master' into master
Apr 24, 2020
7cfaf06
Merge branch 'master' into master
Apr 24, 2020
a6e9be3
Merge branch 'master' into master
Apr 24, 2020
ee2f4d6
Merge branch 'master' into master
Apr 24, 2020
6b56390
Merge branch 'master' into master
Apr 25, 2020
b147cae
Merge branch 'master' into master
Apr 25, 2020
14c71f8
Merge branch 'master' into master
Apr 25, 2020
8b044e5
Merge branch 'master' into master
Apr 25, 2020
fccc145
test(patientrepository.test.ts): add test for search string clean regex
JDarke Apr 25, 2020
1f97dff
test(src/__tests__/clients/db/patientrepository.test.ts): add test
JDarke Apr 25, 2020
7347207
revert(package.json): undo mocha dependency in package.json
JDarke Apr 25, 2020
1d2c485
Merge branch 'master' into master
Apr 26, 2020
df737ec
Merge branch 'master' into master
Apr 26, 2020
7e63752
Merge branch 'master' into master
Apr 26, 2020
f3ec82a
Merge branch 'master' into master
Apr 27, 2020
5214a4c
Merge branch 'master' into master
Apr 27, 2020
6b5b30b
Merge branch 'master' into master
Apr 27, 2020
f830e3d
Merge branch 'master' into master
Apr 27, 2020
d2314da
Merge branch 'master' into master
Apr 28, 2020
234b125
Merge branch 'master' into master
Apr 28, 2020
b603dd1
fix(src/clients/db/patientrepository.ts): add escapeStringRegex package
JDarke Apr 28, 2020
bb1af60
Merge branch 'master' of https://github.com/JDarke/hospitalrun-frontend
JDarke Apr 29, 2020
d8be269
Merge branch 'master' into master
Apr 29, 2020
e94dfe5
Merge pull request #1 from HospitalRun/master
JDarke May 1, 2020
f4dccc8
fix(appointmentrepository.ts): add escapeStringRegex to appointment srch
JDarke May 1, 2020
cd233d2
Merge branch 'master' into fix-2029
May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/__tests__/clients/db/AppointmentRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AppointmentRepository from 'clients/db/AppointmentRepository'
import { appointments } from 'config/pouchdb'
import { appointments, patients } from 'config/pouchdb'
import Appointment from 'model/Appointment'

const uuidV4Regex = /^[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i
Expand All @@ -24,6 +24,21 @@ describe('Appointment Repository', () => {
})
})

describe('searchPatientAppointments', () => {
it('should escape all special chars from search text', async () => {
await patients.put({ _id: 'id2222' })
await appointments.put({ _id: 'id3333', patientId: 'id2222', location: 'id-]?}(){*[$+.^\\' })

const result = await AppointmentRepository.searchPatientAppointments(
'id2222',
'id-]?}(){*[$+.^\\',
)

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

describe('save', () => {
it('should create an id that is a uuid', async () => {
const newAppointment = await AppointmentRepository.save({
Expand Down
8 changes: 5 additions & 3 deletions src/clients/db/AppointmentRepository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeStringRegexp from 'escape-string-regexp'
import Appointment from 'model/Appointment'
import { appointments } from 'config/pouchdb'
import Repository from './Repository'
Expand All @@ -9,6 +10,7 @@ export class AppointmentRepository extends Repository<Appointment> {

// Fuzzy search for patient appointments. Used for patient appointment search bar
async searchPatientAppointments(patientId: string, text: string): Promise<Appointment[]> {
const escapedString = escapeStringRegexp(text)
return super.search({
selector: {
$and: [
Expand All @@ -19,17 +21,17 @@ export class AppointmentRepository extends Repository<Appointment> {
$or: [
{
location: {
$regex: RegExp(text, 'i'),
$regex: RegExp(escapedString, 'i'),
},
},
{
reason: {
$regex: RegExp(text, 'i'),
$regex: RegExp(escapedString, 'i'),
},
},
{
type: {
$regex: RegExp(text, 'i'),
$regex: RegExp(escapedString, 'i'),
},
},
],
Expand Down