Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating forked repo from main #1

Merged
merged 1 commit into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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