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

Commit

Permalink
refactor: resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed May 5, 2020
2 parents 6cdf785 + 9084411 commit 923560f
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"@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",
"@typescript-eslint/eslint-plugin": "~2.31.0",
"@typescript-eslint/parser": "~2.31.0",
"commitizen": "~4.0.3",
"commitlint-config-cz": "~0.13.0",
"cross-env": "~7.0.0",
Expand Down
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
12 changes: 12 additions & 0 deletions src/__tests__/patients/list/ViewPatients.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ describe('Patients', () => {
)
})

describe('initalLoad', () => {
afterEach(() => {
jest.restoreAllMocks()
})

it('should call fetchPatients only once', () => {
setup()
const findAllPagedSpy = jest.spyOn(PatientRepository, 'findAllPaged')
expect(findAllPagedSpy).toHaveBeenCalledTimes(1)
})
})

describe('layout', () => {
afterEach(() => {
jest.restoreAllMocks()
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,16 +1,12 @@
import escapeStringRegexp from 'escape-string-regexp'
import shortid from 'shortid'
import Page from 'clients/Page'
import Patient from '../../model/Patient'
import generateCode from '../../util/generateCode'
import Repository from './Repository'
import { patients } from '../../config/pouchdb'
import PageRequest, { UnpagedRequest } from './PageRequest'
import SortRequest, { Unsorted } from './SortRequest'

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 Down Expand Up @@ -84,7 +80,7 @@ export class PatientRepository extends Repository<Patient> {
}

async save(entity: Patient): Promise<Patient> {
const patientCode = getPatientCode()
const patientCode = generateCode('P')
entity.code = patientCode
entity.index = (entity.fullName ? entity.fullName : '') + 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
9 changes: 2 additions & 7 deletions src/patients/list/ViewPatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SortRequest from 'clients/db/SortRequest'
import PageRequest from 'clients/db/PageRequest'
import PageComponent from 'components/PageComponent'
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'
Expand Down Expand Up @@ -75,11 +75,6 @@ const ViewPatients = () => {
}, [dispatch, debouncedSearchText, userPageRequest])

useEffect(() => {
const sortRequest: SortRequest = {
sorts: [{ field: 'index', direction: 'asc' }],
}
dispatch(fetchPatients(sortRequest, userPageRequest))

setButtonToolBar([
<Button
key="newPatientButton"
Expand All @@ -95,7 +90,7 @@ const ViewPatients = () => {
return () => {
setButtonToolBar([])
}
}, [dispatch, setButtonToolBar, t, history, userPageRequest])
}, [dispatch, setButtonToolBar, t, history])

const loadingIndicator = <Spinner color="blue" loading size={[10, 25]} type="ScaleLoader" />
const table = (
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

0 comments on commit 923560f

Please sign in to comment.