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

feat(labs): add lab code #2040

Merged
merged 7 commits into from
May 3, 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
14 changes: 14 additions & 0 deletions src/__tests__/clients/db/LabRepository.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
5 changes: 4 additions & 1 deletion src/__tests__/labs/ViewLab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', () => {
Expand Down
17 changes: 11 additions & 6 deletions src/__tests__/labs/ViewLabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/utils/generateCode.test.ts
Original file line number Diff line number Diff line change
@@ -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-/)
})
7 changes: 7 additions & 0 deletions src/clients/db/LabRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Lab from 'model/Lab'
import generateCode from '../../util/generateCode'
import Repository from './Repository'
import { labs } from '../../config/pouchdb'

Expand All @@ -10,6 +11,12 @@ export class LabRepository extends Repository<Lab> {
})
}

async save(entity: Lab): Promise<Lab> {
const labCode = generateCode('L')
entity.code = labCode
return super.save(entity)
}

async findAllByPatientId(patientId: string): Promise<Lab[]> {
return super.search({
selector: {
Expand Down
8 changes: 2 additions & 6 deletions src/clients/db/PatientRepository.ts
Original file line number Diff line number Diff line change
@@ -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<Patient> {
constructor() {
super(patients)
Expand All @@ -32,7 +28,7 @@ export class PatientRepository extends Repository<Patient> {
}

async save(entity: Patient): Promise<Patient> {
const patientCode = getPatientCode()
const patientCode = generateCode('P')
entity.code = patientCode
return super.save(entity)
}
Expand Down
2 changes: 1 addition & 1 deletion src/labs/ViewLab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/labs/ViewLabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const ViewLabs = () => {
<table className="table table-hover">
<thead className="thead-light">
<tr>
<th>{t('labs.lab.code')}</th>
<th>{t('labs.lab.type')}</th>
<th>{t('labs.lab.requestedOn')}</th>
<th>{t('labs.lab.status')}</th>
Expand All @@ -80,6 +81,7 @@ const ViewLabs = () => {
<tbody>
{labs.map((lab) => (
<tr onClick={() => onTableRowClick(lab)} key={lab.id}>
<td>{lab.code}</td>
<td>{lab.type}</td>
<td>{format(new Date(lab.requestedOn), 'yyyy-MM-dd hh:mm a')}</td>
<td>{lab.status}</td>
Expand Down
7 changes: 7 additions & 0 deletions src/locales/ar/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'كود المختبر',
},
},
}
7 changes: 7 additions & 0 deletions src/locales/de/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'Laborcode',
},
},
}
1 change: 1 addition & 0 deletions src/locales/enUs/translations/labs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
},
},
lab: {
code: 'Lab Code',
status: 'Status',
for: 'For',
type: 'Type',
Expand Down
7 changes: 7 additions & 0 deletions src/locales/es/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'Código',
},
},
}
1 change: 1 addition & 0 deletions src/locales/fr/translations/labs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
},
},
lab: {
code: 'Code',
status: 'Statut',
for: 'Pour',
type: 'Type',
Expand Down
7 changes: 7 additions & 0 deletions src/locales/in/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'Kode',
},
},
}
7 changes: 7 additions & 0 deletions src/locales/ja/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: '検査コード',
},
},
}
1 change: 1 addition & 0 deletions src/locales/ptBr/translations/labs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
},
},
lab: {
code: 'Código',
status: 'Estado',
for: 'Por',
type: 'Tipo',
Expand Down
7 changes: 7 additions & 0 deletions src/locales/ru/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'Лабораторный код',
},
},
}
7 changes: 7 additions & 0 deletions src/locales/zr/translations/labs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
labs: {
lab: {
code: 'Лабораторный код',
},
},
}
1 change: 1 addition & 0 deletions src/model/Lab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AbstractDBModel from './AbstractDBModel'

export default interface Lab extends AbstractDBModel {
code: string
patientId: string
type: string
notes?: string
Expand Down
8 changes: 8 additions & 0 deletions src/util/generateCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import shortid from 'shortid'

const generateCode = (prefix: string) => {
const id = shortid.generate()
return `${prefix}-${id}`
}

export default generateCode