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

fix(image): enforce visit field when create image #2572

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": false,
"license": "MIT",
"dependencies": {
"@hospitalrun/components": "~3.3.0",
"@hospitalrun/components": "~3.4.0",
"@reduxjs/toolkit": "~1.5.0",
"@types/escape-string-regexp": "~2.0.1",
"@types/json2csv": "~5.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/imagings/util/validate-imaging-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('imaging request validator', () => {
patient: 'imagings.requests.error.patientRequired',
status: 'imagings.requests.error.statusRequired',
type: 'imagings.requests.error.typeRequired',
visit: 'imagings.requests.error.visitRequired',
message: 'imagings.requests.error.unableToRequest',
}

const actualError = validateImagingRequest(newImagingRequest)
Expand Down
2 changes: 2 additions & 0 deletions src/imagings/requests/NewImagingRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ const NewImagingRequest = () => {
isEditable={newImagingRequest.patient !== undefined}
options={visitOption || []}
defaultSelected={defaultSelectedVisitsOption()}
isInvalid={!!error?.visit}
feedback={t(error?.visit)}
onChange={(values) => {
onVisitChange(values[0])
}}
Expand Down
20 changes: 16 additions & 4 deletions src/imagings/util/validate-imaging-request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isEmpty } from 'lodash'

import Imaging from '../../shared/model/Imaging'

const statusType: string[] = ['requested', 'completed', 'canceled']
Expand All @@ -9,21 +11,27 @@ export class ImagingRequestError extends Error {

status?: string

constructor(message: string, patient?: string, type?: string, status?: string) {
visit?: string

constructor(message: string, patient?: string, type?: string, status?: string, visit?: string) {
super(message)
this.patient = patient
this.type = type
this.status = status
this.visit = visit
Object.setPrototypeOf(this, ImagingRequestError.prototype)
}
}

export default function validateImagingRequest(request: Partial<Imaging>) {
const imagingRequestError = {} as any
export default function validateImagingRequest(request: Partial<Imaging>): ImagingRequestError {
const imagingRequestError = {} as ImagingRequestError

if (!request.patient) {
imagingRequestError.patient = 'imagings.requests.error.patientRequired'
}

if (!request.visitId) {
imagingRequestError.visit = 'imagings.requests.error.visitRequired'
}
if (!request.type) {
imagingRequestError.type = 'imagings.requests.error.typeRequired'
}
Expand All @@ -34,5 +42,9 @@ export default function validateImagingRequest(request: Partial<Imaging>) {
imagingRequestError.status = 'imagings.requests.error.incorrectStatus'
}

if (!isEmpty(imagingRequestError)) {
imagingRequestError.message = 'imagings.requests.error.unableToRequest'
}

return imagingRequestError
}
3 changes: 3 additions & 0 deletions src/shared/components/input/SelectWithLabelFormGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
multiple?: boolean
isEditable?: boolean
isInvalid?: boolean
feedback?: string
}

const SelectWithLabelFormGroup = (props: Props) => {
Expand All @@ -32,6 +33,7 @@ const SelectWithLabelFormGroup = (props: Props) => {
multiple,
isEditable,
isInvalid,
feedback,
} = props
const id = `${name}Select`
return (
Expand All @@ -46,6 +48,7 @@ const SelectWithLabelFormGroup = (props: Props) => {
multiple={multiple}
disabled={!isEditable}
isInvalid={isInvalid}
feedback={feedback}
/>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/enUs/translations/imagings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
typeRequired: 'Type is required.',
statusRequired: 'Status is required.',
patientRequired: 'Patient name is required.',
visitRequired: 'Visit is required.',
},
},
imaging: {
Expand Down