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

Commit

Permalink
Merge remote-tracking branch 'origin/feature/labs_tab' into feature/l…
Browse files Browse the repository at this point in the history
…abs_tab
  • Loading branch information
rubencgt committed May 3, 2020
2 parents c9bcd47 + 0fa5639 commit 652f11d
Show file tree
Hide file tree
Showing 22 changed files with 514 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 90
daysUntilStale: 30
# Number of days of inactivity before a stale issue is closed
daysUntilStale: 120
daysUntilStale: 60
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/compressed-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2-beta
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: preactjs/compressed-size-action@v1
- uses: preactjs/compressed-size-action@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
138 changes: 138 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@hospitalrun/frontend",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "React frontend for HospitalRun",
"private": false,
"license": "MIT",
"dependencies": {
"@hospitalrun/components": "^1.3.0",
"@hospitalrun/components": "^1.4.0",
"@reduxjs/toolkit": "~1.3.0",
"@types/escape-string-regexp": "~2.0.1",
"@types/pouchdb-find": "~6.3.4",
Expand All @@ -15,8 +15,8 @@
"i18next": "~19.4.0",
"i18next-browser-languagedetector": "~4.1.0",
"i18next-xhr-backend": "~3.2.2",
"node-sass": "~4.14.0",
"lodash": "^4.17.15",
"node-sass": "~4.14.0",
"pouchdb": "~7.2.1",
"pouchdb-adapter-memory": "~7.2.1",
"pouchdb-find": "~7.2.1",
Expand All @@ -34,7 +34,14 @@
"redux-thunk": "~2.3.0",
"shortid": "^2.2.15",
"typescript": "~3.8.2",
"uuid": "^8.0.0"
"uuid": "^8.0.0",
"validator": "^13.0.0"
},
"resolutions": {
"moment": "2.24.0"
},
"comments": {
"resolutions": "Added this key as temp fix https://github.com/moment/moment/issues/5484"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,6 +72,7 @@
"@types/redux-mock-store": "~1.0.1",
"@types/shortid": "^0.0.29",
"@types/uuid": "^7.0.0",
"@types/validator": "~13.0.0",
"@typescript-eslint/eslint-plugin": "~2.30.0",
"@typescript-eslint/parser": "~2.30.0",
"commitizen": "~4.0.3",
Expand Down
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: 8 additions & 0 deletions src/__tests__/patients/GeneralInformation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('Error handling', () => {
message: 'some message',
givenName: 'given name message',
dateOfBirth: 'date of birth message',
phoneNumber: 'phone number message',
email: 'email message',
}
const history = createMemoryHistory()
const wrapper = mount(
Expand All @@ -27,12 +29,18 @@ describe('Error handling', () => {
const errorMessage = wrapper.find(Alert)
const givenNameInput = wrapper.findWhere((w: any) => w.prop('name') === 'givenName')
const dateOfBirthInput = wrapper.findWhere((w: any) => w.prop('name') === 'dateOfBirth')
const emailInput = wrapper.findWhere((w: any) => w.prop('name') === 'email')
const phoneNumberInput = wrapper.findWhere((w: any) => w.prop('name') === 'phoneNumber')
expect(errorMessage).toBeTruthy()
expect(errorMessage.prop('message')).toMatch(error.message)
expect(givenNameInput.prop('isInvalid')).toBeTruthy()
expect(givenNameInput.prop('feedback')).toEqual(error.givenName)
expect(dateOfBirthInput.prop('isInvalid')).toBeTruthy()
expect(dateOfBirthInput.prop('feedback')).toEqual(error.dateOfBirth)
expect(emailInput.prop('feedback')).toEqual(error.email)
expect(emailInput.prop('isInvalid')).toBeTruthy()
expect(phoneNumberInput.prop('feedback')).toEqual(error.phoneNumber)
expect(phoneNumberInput.prop('isInvalid')).toBeTruthy()
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/patients/edit/EditPatient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Edit Patient', () => {
type: 'charity',
occupation: 'occupation',
preferredLanguage: 'preferredLanguage',
phoneNumber: 'phoneNumber',
phoneNumber: '123456789',
email: '[email protected]',
address: 'address',
code: 'P00001',
Expand Down
77 changes: 75 additions & 2 deletions src/__tests__/patients/patient-slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ describe('patients slice', () => {
expect(onSuccessSpy).toHaveBeenCalledWith(expectedPatient)
})

it('should validate the patient', async () => {
it('should validate the patient required fields', async () => {
const store = mockStore()
const expectedPatientId = 'sliceId10'
const expectedPatient = {
id: expectedPatientId,
givenName: undefined,
dateOfBirth: addDays(new Date(), 4).toISOString(),
} as Patient
const saveOrUpdateSpy = jest
.spyOn(PatientRepository, 'saveOrUpdate')
Expand All @@ -218,10 +217,84 @@ describe('patients slice', () => {
createPatientError({
message: 'patient.errors.createPatientError',
givenName: 'patient.errors.patientGivenNameFeedback',
}),
)
})

it('should validate that the patient birthday is not a future date', async () => {
const store = mockStore()
const expectedPatientId = 'sliceId10'
const expectedPatient = {
id: expectedPatientId,
givenName: 'some given name',
dateOfBirth: addDays(new Date(), 4).toISOString(),
} as Patient
const saveOrUpdateSpy = jest
.spyOn(PatientRepository, 'saveOrUpdate')
.mockResolvedValue(expectedPatient)
const onSuccessSpy = jest.fn()

await store.dispatch(createPatient(expectedPatient, onSuccessSpy))

expect(onSuccessSpy).not.toHaveBeenCalled()
expect(saveOrUpdateSpy).not.toHaveBeenCalled()
expect(store.getActions()[1]).toEqual(
createPatientError({
message: 'patient.errors.createPatientError',
dateOfBirth: 'patient.errors.patientDateOfBirthFeedback',
}),
)
})

it('should validate that the patient email is a valid email', async () => {
const store = mockStore()
const expectedPatientId = 'sliceId10'
const expectedPatient = {
id: expectedPatientId,
givenName: 'some given name',
phoneNumber: 'not a phone number',
} as Patient
const saveOrUpdateSpy = jest
.spyOn(PatientRepository, 'saveOrUpdate')
.mockResolvedValue(expectedPatient)
const onSuccessSpy = jest.fn()

await store.dispatch(createPatient(expectedPatient, onSuccessSpy))

expect(onSuccessSpy).not.toHaveBeenCalled()
expect(saveOrUpdateSpy).not.toHaveBeenCalled()
expect(store.getActions()[1]).toEqual(
createPatientError({
message: 'patient.errors.createPatientError',
phoneNumber: 'patient.errors.invalidPhoneNumber',
}),
)
})

it('should validate that the patient phone number is a valid phone number', async () => {
const store = mockStore()
const expectedPatientId = 'sliceId10'
const expectedPatient = {
id: expectedPatientId,
givenName: 'some given name',
phoneNumber: 'not a phone number',
} as Patient
const saveOrUpdateSpy = jest
.spyOn(PatientRepository, 'saveOrUpdate')
.mockResolvedValue(expectedPatient)
const onSuccessSpy = jest.fn()

await store.dispatch(createPatient(expectedPatient, onSuccessSpy))

expect(onSuccessSpy).not.toHaveBeenCalled()
expect(saveOrUpdateSpy).not.toHaveBeenCalled()
expect(store.getActions()[1]).toEqual(
createPatientError({
message: 'patient.errors.createPatientError',
phoneNumber: 'patient.errors.invalidPhoneNumber',
}),
)
})
})

describe('fetch patient', () => {
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
4 changes: 4 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import translationJA from './locales/ja/translations'
import translationPtBR from './locales/ptBr/translations'
import translationRU from './locales/ru/translations'
import translationZR from './locales/zr/translations'
import translationIT from './locales/it/translations'

const resources = {
it: {
translation: translationIT,
},
ar: {
translation: translationAR,
},
Expand Down
2 changes: 2 additions & 0 deletions src/locales/enUs/translations/patient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export default {
updatePatientError: 'Could not update patient.',
patientGivenNameFeedback: 'Given Name is required.',
patientDateOfBirthFeedback: 'Date of Birth can not be greater than today',
invalidEmail: 'Must be a valid email.',
invalidPhoneNumber: 'Must be a valid phone number.',
},
},
}
15 changes: 15 additions & 0 deletions src/locales/it/translations/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
actions: {
label: 'Azioni',
edit: 'Modifica',
save: 'Salva',
update: 'Aggiorna',
complete: 'Completa',
delete: 'Rimuovi',
cancel: 'Annulla',
new: 'Nuovo',
list: 'Lista',
search: 'Cerca',
confirmDelete: 'Conferma cancellazione',
},
}
5 changes: 5 additions & 0 deletions src/locales/it/translations/dashboard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
dashboard: {
label: 'Dashboard',
},
}
19 changes: 19 additions & 0 deletions src/locales/it/translations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import actions from './actions'
import dashboard from './dashboard'
import patient from './patient'
import patients from './patients'
import scheduling from './scheduling'
import states from './states'
import sex from './sex'
import labs from './labs'

export default {
...actions,
...dashboard,
...patient,
...patients,
...scheduling,
...states,
...sex,
...labs,
}
29 changes: 29 additions & 0 deletions src/locales/it/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
labs: {
label: 'Laboratori',
requests: {
label: 'Richieste di laboratorio',
new: 'Nuova richiesta di laboratorio',
view: 'Visualizza richiesta',
cancel: 'Annulla richiesta',
complete: 'Completa',
error: {
unableToRequest: 'Impossibile creare la richiesta.',
unableToComplete: 'Impossibile completare la richiesta.',
typeRequired: 'La tipologia è richiesta.',
resultRequiredToComplete: 'Il risultato è obbligatorio per completare la richiesta.',
},
},
lab: {
status: 'Stato',
for: 'Per',
type: 'Tipo',
result: 'Risultato',
notes: 'Note',
requestedOn: 'Richiesta fatta il',
completedOn: 'Completato il',
canceledOn: 'Annullata il',
patient: 'Paziente',
},
},
}
Loading

0 comments on commit 652f11d

Please sign in to comment.