From 97929b2ef607b7ec09a1a13c8b9c4b7e2959fcb8 Mon Sep 17 00:00:00 2001 From: BernoRaj Date: Sat, 6 Feb 2021 19:09:58 +0530 Subject: [PATCH 1/3] fix(image): enforce visit field when create image --- .../util/validate-imaging-request.test.ts | 2 ++ src/imagings/requests/NewImagingRequest.tsx | 2 ++ src/imagings/util/validate-imaging-request.ts | 20 +++++++++++++++---- .../input/SelectWithLabelFormGroup.tsx | 3 +++ .../enUs/translations/imagings/index.ts | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/__tests__/imagings/util/validate-imaging-request.test.ts b/src/__tests__/imagings/util/validate-imaging-request.test.ts index af3f23e659..271d56b36c 100644 --- a/src/__tests__/imagings/util/validate-imaging-request.test.ts +++ b/src/__tests__/imagings/util/validate-imaging-request.test.ts @@ -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) diff --git a/src/imagings/requests/NewImagingRequest.tsx b/src/imagings/requests/NewImagingRequest.tsx index 723aa03fb4..696e02bdbe 100644 --- a/src/imagings/requests/NewImagingRequest.tsx +++ b/src/imagings/requests/NewImagingRequest.tsx @@ -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]) }} diff --git a/src/imagings/util/validate-imaging-request.ts b/src/imagings/util/validate-imaging-request.ts index d077ecc0cc..7dfc843f6f 100644 --- a/src/imagings/util/validate-imaging-request.ts +++ b/src/imagings/util/validate-imaging-request.ts @@ -1,3 +1,5 @@ +import { isEmpty } from 'lodash' + import Imaging from '../../shared/model/Imaging' const statusType: string[] = ['requested', 'completed', 'canceled'] @@ -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) { - const imagingRequestError = {} as any +export default function validateImagingRequest(request: Partial): 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' } @@ -34,5 +42,9 @@ export default function validateImagingRequest(request: Partial) { imagingRequestError.status = 'imagings.requests.error.incorrectStatus' } + if (!isEmpty(imagingRequestError)) { + imagingRequestError.message = 'imagings.requests.error.unableToRequest' + } + return imagingRequestError } diff --git a/src/shared/components/input/SelectWithLabelFormGroup.tsx b/src/shared/components/input/SelectWithLabelFormGroup.tsx index fb5fd11402..83b8f1d747 100644 --- a/src/shared/components/input/SelectWithLabelFormGroup.tsx +++ b/src/shared/components/input/SelectWithLabelFormGroup.tsx @@ -18,6 +18,7 @@ interface Props { multiple?: boolean isEditable?: boolean isInvalid?: boolean + feedback?: string } const SelectWithLabelFormGroup = (props: Props) => { @@ -32,6 +33,7 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple, isEditable, isInvalid, + feedback, } = props const id = `${name}Select` return ( @@ -46,6 +48,7 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple={multiple} disabled={!isEditable} isInvalid={isInvalid} + feedback={feedback} /> ) diff --git a/src/shared/locales/enUs/translations/imagings/index.ts b/src/shared/locales/enUs/translations/imagings/index.ts index ff85ba1f78..4ff570d4ad 100644 --- a/src/shared/locales/enUs/translations/imagings/index.ts +++ b/src/shared/locales/enUs/translations/imagings/index.ts @@ -19,6 +19,7 @@ export default { typeRequired: 'Type is required.', statusRequired: 'Status is required.', patientRequired: 'Patient name is required.', + visitRequired: 'Visit is required.', }, }, imaging: { From f5fe7f5434c27a64b3cd87b8cf3f6088280ec714 Mon Sep 17 00:00:00 2001 From: BernoRaj Date: Tue, 16 Feb 2021 15:03:31 +0530 Subject: [PATCH 2/3] fix(image): enforce visit field when create image --- src/imagings/requests/NewImagingRequest.tsx | 1 - src/shared/components/input/SelectWithLabelFormGroup.tsx | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/imagings/requests/NewImagingRequest.tsx b/src/imagings/requests/NewImagingRequest.tsx index 696e02bdbe..6b9e4686e8 100644 --- a/src/imagings/requests/NewImagingRequest.tsx +++ b/src/imagings/requests/NewImagingRequest.tsx @@ -163,7 +163,6 @@ const NewImagingRequest = () => { options={visitOption || []} defaultSelected={defaultSelectedVisitsOption()} isInvalid={!!error?.visit} - feedback={t(error?.visit)} onChange={(values) => { onVisitChange(values[0]) }} diff --git a/src/shared/components/input/SelectWithLabelFormGroup.tsx b/src/shared/components/input/SelectWithLabelFormGroup.tsx index 83b8f1d747..fb5fd11402 100644 --- a/src/shared/components/input/SelectWithLabelFormGroup.tsx +++ b/src/shared/components/input/SelectWithLabelFormGroup.tsx @@ -18,7 +18,6 @@ interface Props { multiple?: boolean isEditable?: boolean isInvalid?: boolean - feedback?: string } const SelectWithLabelFormGroup = (props: Props) => { @@ -33,7 +32,6 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple, isEditable, isInvalid, - feedback, } = props const id = `${name}Select` return ( @@ -48,7 +46,6 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple={multiple} disabled={!isEditable} isInvalid={isInvalid} - feedback={feedback} /> ) From 7fe4bec8acefcf3529d756dd968846f10a941222 Mon Sep 17 00:00:00 2001 From: BernoRaj Date: Tue, 16 Feb 2021 15:20:25 +0530 Subject: [PATCH 3/3] fix(image): error message in visit field --- package.json | 2 +- src/imagings/requests/NewImagingRequest.tsx | 1 + src/shared/components/input/SelectWithLabelFormGroup.tsx | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2114a534c0..2b68363ee0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/imagings/requests/NewImagingRequest.tsx b/src/imagings/requests/NewImagingRequest.tsx index 6b9e4686e8..696e02bdbe 100644 --- a/src/imagings/requests/NewImagingRequest.tsx +++ b/src/imagings/requests/NewImagingRequest.tsx @@ -163,6 +163,7 @@ const NewImagingRequest = () => { options={visitOption || []} defaultSelected={defaultSelectedVisitsOption()} isInvalid={!!error?.visit} + feedback={t(error?.visit)} onChange={(values) => { onVisitChange(values[0]) }} diff --git a/src/shared/components/input/SelectWithLabelFormGroup.tsx b/src/shared/components/input/SelectWithLabelFormGroup.tsx index fb5fd11402..83b8f1d747 100644 --- a/src/shared/components/input/SelectWithLabelFormGroup.tsx +++ b/src/shared/components/input/SelectWithLabelFormGroup.tsx @@ -18,6 +18,7 @@ interface Props { multiple?: boolean isEditable?: boolean isInvalid?: boolean + feedback?: string } const SelectWithLabelFormGroup = (props: Props) => { @@ -32,6 +33,7 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple, isEditable, isInvalid, + feedback, } = props const id = `${name}Select` return ( @@ -46,6 +48,7 @@ const SelectWithLabelFormGroup = (props: Props) => { multiple={multiple} disabled={!isEditable} isInvalid={isInvalid} + feedback={feedback} /> )