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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed May 1, 2020
2 parents 5308f5f + 025a4b8 commit 8727f38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 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 All @@ -32,7 +33,7 @@
"redux-thunk": "~2.3.0",
"shortid": "^2.2.15",
"typescript": "~3.8.2",
"uuid": "^7.0.1"
"uuid": "^8.0.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -84,7 +85,7 @@
"history": "~4.10.1",
"husky": "~4.2.1",
"jest": "~24.9.0",
"lint-staged": "~10.1.0",
"lint-staged": "~10.2.0",
"memdown": "~5.1.0",
"prettier": "~2.0.4",
"redux-mock-store": "~1.5.4",
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 Page from 'clients/Page'
import Patient from '../../model/Patient'
Expand All @@ -19,12 +20,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

0 comments on commit 8727f38

Please sign in to comment.