From b695ac899ea73e7059a50ad633bea90932431ff8 Mon Sep 17 00:00:00 2001 From: Marco Moretti Date: Sun, 3 May 2020 20:43:09 +0200 Subject: [PATCH 1/6] feat(labs): add lab code (#2040) --- src/__tests__/clients/db/LabRepository.test.ts | 14 ++++++++++++++ src/__tests__/labs/ViewLab.test.tsx | 5 ++++- src/__tests__/labs/ViewLabs.test.tsx | 17 +++++++++++------ src/__tests__/utils/generateCode.test.ts | 6 ++++++ src/clients/db/LabRepository.ts | 7 +++++++ src/clients/db/PatientRepository.ts | 8 ++------ src/labs/ViewLab.tsx | 2 +- src/labs/ViewLabs.tsx | 2 ++ src/locales/ar/translations/labs/index.ts | 7 +++++++ src/locales/de/translations/labs/index.ts | 7 +++++++ src/locales/enUs/translations/labs/index.ts | 1 + src/locales/es/translations/labs/index.ts | 7 +++++++ src/locales/fr/translations/labs/index.ts | 1 + src/locales/in/translations/labs/index.ts | 7 +++++++ src/locales/ja/translations/labs/index.ts | 7 +++++++ src/locales/ptBr/translations/labs/index.ts | 1 + src/locales/ru/translations/labs/index.ts | 7 +++++++ src/locales/zr/translations/labs/index.ts | 7 +++++++ src/model/Lab.ts | 1 + src/util/generateCode.ts | 8 ++++++++ 20 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 src/__tests__/clients/db/LabRepository.test.ts create mode 100644 src/__tests__/utils/generateCode.test.ts create mode 100644 src/locales/ar/translations/labs/index.ts create mode 100644 src/locales/de/translations/labs/index.ts create mode 100644 src/locales/es/translations/labs/index.ts create mode 100644 src/locales/in/translations/labs/index.ts create mode 100644 src/locales/ja/translations/labs/index.ts create mode 100644 src/locales/ru/translations/labs/index.ts create mode 100644 src/locales/zr/translations/labs/index.ts create mode 100644 src/util/generateCode.ts diff --git a/src/__tests__/clients/db/LabRepository.test.ts b/src/__tests__/clients/db/LabRepository.test.ts new file mode 100644 index 0000000000..e7f24726d5 --- /dev/null +++ b/src/__tests__/clients/db/LabRepository.test.ts @@ -0,0 +1,14 @@ +import shortid from 'shortid' +import LabRepository from '../../../clients/db/LabRepository' +import Lab from '../../../model/Lab' + +describe('lab repository', () => { + it('should generate a lab code', async () => { + const newLab = await LabRepository.save({ + patientId: '123', + type: 'test', + } as Lab) + + expect(shortid.isValid(newLab.code)).toBeTruthy() + }) +}) diff --git a/src/__tests__/labs/ViewLab.test.tsx b/src/__tests__/labs/ViewLab.test.tsx index 97f17faff5..b5cbd154e2 100644 --- a/src/__tests__/labs/ViewLab.test.tsx +++ b/src/__tests__/labs/ViewLab.test.tsx @@ -25,6 +25,7 @@ describe('View Labs', () => { let history: any const mockPatient = { fullName: 'test' } const mockLab = { + code: 'L-1234', id: '12456', status: 'requested', patientId: '1234', @@ -83,7 +84,9 @@ describe('View Labs', () => { it('should set the title', async () => { await setup(mockLab, [Permissions.ViewLab]) - expect(titleSpy).toHaveBeenCalledWith(`${mockLab.type} for ${mockPatient.fullName}`) + expect(titleSpy).toHaveBeenCalledWith( + `${mockLab.type} for ${mockPatient.fullName}(${mockLab.code})`, + ) }) describe('page content', () => { diff --git a/src/__tests__/labs/ViewLabs.test.tsx b/src/__tests__/labs/ViewLabs.test.tsx index 89c2e9f8c4..a1c22b4c12 100644 --- a/src/__tests__/labs/ViewLabs.test.tsx +++ b/src/__tests__/labs/ViewLabs.test.tsx @@ -94,6 +94,7 @@ describe('View Labs', () => { let wrapper: ReactWrapper let history: any const expectedLab = { + code: 'L-1234', id: '1234', type: 'lab type', patientId: 'patientId', @@ -133,19 +134,23 @@ describe('View Labs', () => { expect(table).toBeDefined() expect(tableHeader).toBeDefined() expect(tableBody).toBeDefined() - expect(tableColumnHeaders.at(0).text().trim()).toEqual('labs.lab.type') + expect(tableColumnHeaders.at(0).text().trim()).toEqual('labs.lab.code') - expect(tableColumnHeaders.at(1).text().trim()).toEqual('labs.lab.requestedOn') + expect(tableColumnHeaders.at(1).text().trim()).toEqual('labs.lab.type') - expect(tableColumnHeaders.at(2).text().trim()).toEqual('labs.lab.status') + expect(tableColumnHeaders.at(2).text().trim()).toEqual('labs.lab.requestedOn') - expect(tableDataColumns.at(0).text().trim()).toEqual(expectedLab.type) + expect(tableColumnHeaders.at(3).text().trim()).toEqual('labs.lab.status') - expect(tableDataColumns.at(1).text().trim()).toEqual( + expect(tableDataColumns.at(0).text().trim()).toEqual(expectedLab.code) + + expect(tableDataColumns.at(1).text().trim()).toEqual(expectedLab.type) + + expect(tableDataColumns.at(2).text().trim()).toEqual( format(new Date(expectedLab.requestedOn), 'yyyy-MM-dd hh:mm a'), ) - expect(tableDataColumns.at(2).text().trim()).toEqual(expectedLab.status) + expect(tableDataColumns.at(3).text().trim()).toEqual(expectedLab.status) }) it('should navigate to the lab when the row is clicked', () => { diff --git a/src/__tests__/utils/generateCode.test.ts b/src/__tests__/utils/generateCode.test.ts new file mode 100644 index 0000000000..22a44dd2a5 --- /dev/null +++ b/src/__tests__/utils/generateCode.test.ts @@ -0,0 +1,6 @@ +import generateCode from '../../util/generateCode' + +it('should generate a code with prefix A-', () => { + const generatedCode = generateCode('A') + expect(generatedCode).toMatch(/^A-/) +}) diff --git a/src/clients/db/LabRepository.ts b/src/clients/db/LabRepository.ts index 9ddfa74df0..6748ab1e7d 100644 --- a/src/clients/db/LabRepository.ts +++ b/src/clients/db/LabRepository.ts @@ -1,4 +1,5 @@ import Lab from 'model/Lab' +import generateCode from '../../util/generateCode' import Repository from './Repository' import { labs } from '../../config/pouchdb' @@ -10,6 +11,12 @@ export class LabRepository extends Repository { }) } + async save(entity: Lab): Promise { + const labCode = generateCode('L') + entity.code = labCode + return super.save(entity) + } + async findAllByPatientId(patientId: string): Promise { return super.search({ selector: { diff --git a/src/clients/db/PatientRepository.ts b/src/clients/db/PatientRepository.ts index 99a239685e..172e380a7f 100644 --- a/src/clients/db/PatientRepository.ts +++ b/src/clients/db/PatientRepository.ts @@ -1,13 +1,9 @@ import escapeStringRegexp from 'escape-string-regexp' -import shortid from 'shortid' import Patient from '../../model/Patient' +import generateCode from '../../util/generateCode' import Repository from './Repository' import { patients } from '../../config/pouchdb' -const formatPatientCode = (prefix: string, sequenceNumber: string) => `${prefix}${sequenceNumber}` - -const getPatientCode = (): string => formatPatientCode('P-', shortid.generate()) - export class PatientRepository extends Repository { constructor() { super(patients) @@ -32,7 +28,7 @@ export class PatientRepository extends Repository { } async save(entity: Patient): Promise { - const patientCode = getPatientCode() + const patientCode = generateCode('P') entity.code = patientCode return super.save(entity) } diff --git a/src/labs/ViewLab.tsx b/src/labs/ViewLab.tsx index 57c72b860b..6f58f2c9e6 100644 --- a/src/labs/ViewLab.tsx +++ b/src/labs/ViewLab.tsx @@ -14,7 +14,7 @@ import { RootState } from '../store' import { cancelLab, completeLab, updateLab, fetchLab } from './lab-slice' const getTitle = (patient: Patient | undefined, lab: Lab | undefined) => - patient && lab ? `${lab.type} for ${patient.fullName}` : '' + patient && lab ? `${lab.type} for ${patient.fullName}(${lab.code})` : '' const ViewLab = () => { const { id } = useParams() diff --git a/src/labs/ViewLabs.tsx b/src/labs/ViewLabs.tsx index 0e68270f44..42909a9537 100644 --- a/src/labs/ViewLabs.tsx +++ b/src/labs/ViewLabs.tsx @@ -72,6 +72,7 @@ const ViewLabs = () => { + @@ -80,6 +81,7 @@ const ViewLabs = () => { {labs.map((lab) => ( onTableRowClick(lab)} key={lab.id}> + diff --git a/src/locales/ar/translations/labs/index.ts b/src/locales/ar/translations/labs/index.ts new file mode 100644 index 0000000000..f0cc9a23d0 --- /dev/null +++ b/src/locales/ar/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'كود المختبر', + }, + }, +} diff --git a/src/locales/de/translations/labs/index.ts b/src/locales/de/translations/labs/index.ts new file mode 100644 index 0000000000..6bdaf43580 --- /dev/null +++ b/src/locales/de/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'Laborcode', + }, + }, +} diff --git a/src/locales/enUs/translations/labs/index.ts b/src/locales/enUs/translations/labs/index.ts index 691424c04e..ae22c88c02 100644 --- a/src/locales/enUs/translations/labs/index.ts +++ b/src/locales/enUs/translations/labs/index.ts @@ -15,6 +15,7 @@ export default { }, }, lab: { + code: 'Lab Code', status: 'Status', for: 'For', type: 'Type', diff --git a/src/locales/es/translations/labs/index.ts b/src/locales/es/translations/labs/index.ts new file mode 100644 index 0000000000..e7f7d6c8e9 --- /dev/null +++ b/src/locales/es/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'Código', + }, + }, +} diff --git a/src/locales/fr/translations/labs/index.ts b/src/locales/fr/translations/labs/index.ts index 83c6934752..8123ce3003 100644 --- a/src/locales/fr/translations/labs/index.ts +++ b/src/locales/fr/translations/labs/index.ts @@ -15,6 +15,7 @@ export default { }, }, lab: { + code: 'Code', status: 'Statut', for: 'Pour', type: 'Type', diff --git a/src/locales/in/translations/labs/index.ts b/src/locales/in/translations/labs/index.ts new file mode 100644 index 0000000000..2297a1bd24 --- /dev/null +++ b/src/locales/in/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'Kode', + }, + }, +} diff --git a/src/locales/ja/translations/labs/index.ts b/src/locales/ja/translations/labs/index.ts new file mode 100644 index 0000000000..1db4e26a65 --- /dev/null +++ b/src/locales/ja/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: '検査コード', + }, + }, +} diff --git a/src/locales/ptBr/translations/labs/index.ts b/src/locales/ptBr/translations/labs/index.ts index 94be005b4d..f4b384e36d 100644 --- a/src/locales/ptBr/translations/labs/index.ts +++ b/src/locales/ptBr/translations/labs/index.ts @@ -15,6 +15,7 @@ export default { }, }, lab: { + code: 'Código', status: 'Estado', for: 'Por', type: 'Tipo', diff --git a/src/locales/ru/translations/labs/index.ts b/src/locales/ru/translations/labs/index.ts new file mode 100644 index 0000000000..1c889914f5 --- /dev/null +++ b/src/locales/ru/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'Лабораторный код', + }, + }, +} diff --git a/src/locales/zr/translations/labs/index.ts b/src/locales/zr/translations/labs/index.ts new file mode 100644 index 0000000000..1c889914f5 --- /dev/null +++ b/src/locales/zr/translations/labs/index.ts @@ -0,0 +1,7 @@ +export default { + labs: { + lab: { + code: 'Лабораторный код', + }, + }, +} diff --git a/src/model/Lab.ts b/src/model/Lab.ts index 0c9d0e22f4..64b17ce431 100644 --- a/src/model/Lab.ts +++ b/src/model/Lab.ts @@ -1,6 +1,7 @@ import AbstractDBModel from './AbstractDBModel' export default interface Lab extends AbstractDBModel { + code: string patientId: string type: string notes?: string diff --git a/src/util/generateCode.ts b/src/util/generateCode.ts new file mode 100644 index 0000000000..f476809c1a --- /dev/null +++ b/src/util/generateCode.ts @@ -0,0 +1,8 @@ +import shortid from 'shortid' + +const generateCode = (prefix: string) => { + const id = shortid.generate() + return `${prefix}-${id}` +} + +export default generateCode From 6cdefb76aca0a21c5e43926611df9763a464da9b Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Mon, 4 May 2020 10:17:33 +0200 Subject: [PATCH 2/6] chore(pull): add automatic fork pull feature --- .github/pull.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/pull.yml diff --git a/.github/pull.yml b/.github/pull.yml new file mode 100644 index 0000000000..a7643e59cd --- /dev/null +++ b/.github/pull.yml @@ -0,0 +1,5 @@ +version: "1" +rules: + - base: master + upstream: hospitalrun:master + mergeMethod: hardreset From c086dc10110e6e7e11169e44d603cc424133ab9a Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Mon, 4 May 2020 10:19:07 +0200 Subject: [PATCH 3/6] chore(pull): remove pull and add app --- .github/pull.yml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .github/pull.yml diff --git a/.github/pull.yml b/.github/pull.yml deleted file mode 100644 index a7643e59cd..0000000000 --- a/.github/pull.yml +++ /dev/null @@ -1,5 +0,0 @@ -version: "1" -rules: - - base: master - upstream: hospitalrun:master - mergeMethod: hardreset From 705c387c99c47544589888db1607d2435a822087 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 4 May 2020 21:17:19 +0000 Subject: [PATCH 4/6] chore(deps-dev): bump @typescript-eslint/parser from 2.30.0 to 2.31.0 Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.30.0 to 2.31.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.31.0/packages/parser) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a14ebd333..6bcc5b67d2 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@types/uuid": "^7.0.0", "@types/validator": "~13.0.0", "@typescript-eslint/eslint-plugin": "~2.30.0", - "@typescript-eslint/parser": "~2.30.0", + "@typescript-eslint/parser": "~2.31.0", "commitizen": "~4.0.3", "commitlint-config-cz": "~0.13.0", "cross-env": "~7.0.0", From 85eb0e70916919436460e6ea236e48191a01e7ca Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 4 May 2020 21:45:20 +0000 Subject: [PATCH 5/6] chore(deps-dev): bump @typescript-eslint/eslint-plugin Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.30.0 to 2.31.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.31.0/packages/eslint-plugin) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bcc5b67d2..3a8454c9d4 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@types/shortid": "^0.0.29", "@types/uuid": "^7.0.0", "@types/validator": "~13.0.0", - "@typescript-eslint/eslint-plugin": "~2.30.0", + "@typescript-eslint/eslint-plugin": "~2.31.0", "@typescript-eslint/parser": "~2.31.0", "commitizen": "~4.0.3", "commitlint-config-cz": "~0.13.0", From 9084411bc459abfd5e7003460ff2f1574cbbc243 Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Tue, 5 May 2020 05:40:58 +0530 Subject: [PATCH 6/6] fix(viewpatients): call PatientRepository.findAll() only once (#2044) --- src/__tests__/patients/list/ViewPatients.test.tsx | 12 ++++++++++++ src/patients/list/ViewPatients.tsx | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/__tests__/patients/list/ViewPatients.test.tsx b/src/__tests__/patients/list/ViewPatients.test.tsx index 4d13c1f516..a250d28a1d 100644 --- a/src/__tests__/patients/list/ViewPatients.test.tsx +++ b/src/__tests__/patients/list/ViewPatients.test.tsx @@ -53,6 +53,18 @@ describe('Patients', () => { mockedPatientRepository.findAll.mockResolvedValue([]) }) + describe('initalLoad', () => { + afterEach(() => { + jest.restoreAllMocks() + }) + + it('should call fetchPatients only once', () => { + setup() + const findAllPagedSpy = jest.spyOn(PatientRepository, 'findAll') + expect(findAllPagedSpy).toHaveBeenCalledTimes(1) + }) + }) + describe('layout', () => { afterEach(() => { jest.restoreAllMocks() diff --git a/src/patients/list/ViewPatients.tsx b/src/patients/list/ViewPatients.tsx index 7682463e46..ba2c470013 100644 --- a/src/patients/list/ViewPatients.tsx +++ b/src/patients/list/ViewPatients.tsx @@ -6,7 +6,7 @@ import { Spinner, Button, Container, Row, TextInput, Column } from '@hospitalrun import { useButtonToolbarSetter } from 'page-header/ButtonBarProvider' import format from 'date-fns/format' import { RootState } from '../../store' -import { fetchPatients, searchPatients } from '../patients-slice' +import { searchPatients } from '../patients-slice' import useTitle from '../../page-header/useTitle' import useAddBreadcrumbs from '../../breadcrumbs/useAddBreadcrumbs' import useDebounce from '../../hooks/debounce' @@ -32,8 +32,6 @@ const ViewPatients = () => { }, [dispatch, debouncedSearchText]) useEffect(() => { - dispatch(fetchPatients()) - setButtonToolBar([
{t('labs.lab.code')} {t('labs.lab.type')} {t('labs.lab.requestedOn')} {t('labs.lab.status')}
{lab.code} {lab.type} {format(new Date(lab.requestedOn), 'yyyy-MM-dd hh:mm a')} {lab.status}