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

fix(lab): enforce the visit field when create lab #2559

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(lab): required visit not enforced
  • Loading branch information
Samuel Qian authored and Samuel Qian committed Feb 24, 2021
commit 9dadeb6fb9dc5c2ca8ce8cdb499058a8ccf7246d
1 change: 1 addition & 0 deletions src/__tests__/labs/hooks/useRequestLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Use Request lab', () => {
const lab = {
type: 'test',
patient: '123',
visitId: 'test visit id',
} as Lab
const expectedRequestedLab = {
...lab,
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/labs/requests/NewLabRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const setup = (
const expectedLab = {
patient: '1234567',
type: 'expected type',
visitId: 'visit_id',
status: 'requested',
notes: [expectedNotes],
id: '1234',
Expand Down Expand Up @@ -224,6 +225,8 @@ describe('New Lab Request', () => {
userEvent.type(screen.getByPlaceholderText(/labs.lab.patient/i), 'Jim Bob')
expect(await screen.findByText(/jim bob/i)).toBeVisible()
userEvent.click(screen.getByText(/jim bob/i))
userEvent.click(screen.getByPlaceholderText('-- Choose --')) // click the Visit field
userEvent.click(screen.getByText(/visit_type/i))
userEvent.type(screen.getByLabelText(/labs\.lab\.type/i), expectedLab.type)
userEvent.type(screen.getByLabelText(/labs\.lab\.notes/i), (expectedLab.notes as string[])[0])
userEvent.click(screen.getByRole('button', { name: /labs\.requests\.new/i }))
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/labs/utils/validate-lab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('lab validator', () => {
const lab = {
patient: 'some patient',
type: 'type test',
visitId: 'test visit id',
} as Lab

const expectedError = {} as LabError
Expand All @@ -23,6 +24,7 @@ describe('lab validator', () => {
patient: 'labs.requests.error.patientRequired',
type: 'labs.requests.error.typeRequired',
message: 'labs.requests.error.unableToRequest',
visit: 'labs.requests.error.visitRequired',
} as LabError

const actualError = validateLabRequest(lab)
Expand Down
1 change: 1 addition & 0 deletions src/labs/requests/NewLabRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const NewLabRequest = () => {
label={t('patient.visit')}
isRequired
isEditable={newLabRequest.patient !== undefined}
isInvalid={!!error?.visit}
options={visitOptions || []}
defaultSelected={defaultSelectedVisitsOption()}
onChange={(values) => {
Expand Down
6 changes: 6 additions & 0 deletions src/labs/utils/validate-lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class LabError extends Error {

type?: string

visit?: string

constructor(message: string, result: string, patient: string, type: string) {
super(message)
this.message = message
Expand All @@ -31,6 +33,10 @@ export function validateLabRequest(lab: Partial<Lab>): LabError {
labError.type = 'labs.requests.error.typeRequired'
}

if (!lab.visitId) {
labError.visit = 'labs.requests.error.visitRequired'
}

Comment on lines +36 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test should be added to cover this piece of functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the validate-lab.test.ts already cover this right?

if (!isEmpty(labError)) {
labError.message = 'labs.requests.error.unableToRequest'
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/enUs/translations/labs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
unableToComplete: 'Unable to complete lab request.',
typeRequired: 'Type is required.',
patientRequired: 'Patient is required.',
visitRequired: 'Visit is required.',
resultRequiredToComplete: 'Result is required to complete.',
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/shared/model/Lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default interface Lab extends AbstractDBModel {
requestedOn: string
completedOn?: string
canceledOn?: string
visitId?: string
visitId: string
}