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

fix(patients): fixes search when using special characters #2012

Merged
merged 41 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 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
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/pouchdb-find": "~6.3.4",
"bootstrap": "~4.4.1",
"date-fns": "~2.12.0",
"escape-string-regexp": "~4.0.0",
"i18next": "~19.4.0",
"i18next-browser-languagedetector": "~4.1.0",
"i18next-xhr-backend": "~3.2.2",
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/clients/db/PatientRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('patient repository', () => {
await removeAllDocs()
})

it('should escape all special chars from search text', async () => {
await patients.put({ _id: 'id9999', code: 'P00001', fullName: 'test -]?}(){*[\\$+.^test' })

const result = await PatientRepository.search('test -]?}(){*[\\$+.^test')

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

it('should return all records that patient code matches search text', async () => {
// same full name to prove that it is finding by patient code
const expectedPatientCode = 'P00001'
Expand Down
4 changes: 3 additions & 1 deletion src/clients/db/PatientRepository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeStringRegexp from 'escape-string-regexp'
import shortid from 'shortid'
import Patient from '../../model/Patient'
import Repository from './Repository'
Expand All @@ -13,12 +14,13 @@ export class PatientRepository extends Repository<Patient> {
}

async search(text: string): Promise<Patient[]> {
const escapedString = escapeStringRegexp(text)
return super.search({
selector: {
$or: [
{
fullName: {
$regex: RegExp(text, 'i'),
$regex: RegExp(escapedString, 'i'),
},
},
{
Expand Down
18 changes: 8 additions & 10 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,20 @@ const Sidebar = () => {
cursor: 'pointer',
fontSize: 'small',
borderBottomWidth: 0,
color:
(splittedPath[1].includes('patients') || splittedPath[1].includes('appointments')) &&
splittedPath.length > 2
? 'white'
: 'black',
borderTopWidth: 0,
color: 'black',
padding: '.6rem 1.25rem',
backgroundColor: 'rgba(245,245,245,1)',
}

const listSubItemStyle: CSSProperties = {
cursor: 'pointer',
fontSize: 'small',
borderBottomWidth: 0,
color:
(splittedPath[1].includes('patients') || splittedPath[1].includes('appointments')) &&
splittedPath.length < 3
? 'white'
: 'black',
borderTopWidth: 0,
color: 'black',
padding: '.6rem 1.25rem',
backgroundColor: 'rgba(245,245,245,1)',
}

const getDashboardLink = () => (
Expand Down