From 8407842650728d8268620800ca465a17114e7efc Mon Sep 17 00:00:00 2001 From: CynthiaKamau Date: Fri, 13 Oct 2023 12:52:36 +0300 Subject: [PATCH 1/2] O3-2495 Add required attributes to address hierarchy fields --- .../field/address/address-field.component.tsx | 5 +++++ .../field/address/address-hierarchy-levels.component.tsx | 1 + 2 files changed, 6 insertions(+) diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx index b7f892a83..e2ee25ab1 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx @@ -18,10 +18,12 @@ function parseString(xmlDockAsString: string) { export const AddressComponent: React.FC = () => { const [selected, setSelected] = useState(''); const { addressTemplate } = useContext(ResourcesContext); + const allRequiredFields = addressTemplate?.requiredElements?.reduce((acc, curr) => ({ ...acc, [curr]: curr }), {}); const addressLayout = useMemo(() => { if (!addressTemplate?.lines) { return []; } + const allFields = addressTemplate?.lines?.flat(); const fields = allFields?.filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); @@ -29,6 +31,7 @@ export const AddressComponent: React.FC = () => { id: codeName, name: codeName, label: displayText, + required: Boolean(allRequiredFields[codeName]), })); }, [addressTemplate]); @@ -83,6 +86,7 @@ export const AddressComponent: React.FC = () => { labelText={t(attributes.label)} id={attributes.name} selected={selected} + required={attributes.required} /> ))} @@ -123,6 +127,7 @@ export const AddressComponent: React.FC = () => { labelText={t(attributes.label)} id={attributes.name} selected={selected} + required={attributes.required} /> )) )} diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx index bc627d0ec..cafc78122 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx @@ -28,6 +28,7 @@ interface AddressComboBoxProps { name: string; value: string; label: string; + required?: boolean; }; } From 64ee6ae04cf71b082af6744f32201f108d778a5c Mon Sep 17 00:00:00 2001 From: Donald Kibet Date: Sat, 14 Oct 2023 16:47:21 +0300 Subject: [PATCH 2/2] (fix) fix broken unit test --- .../field/address/address-field.component.tsx | 17 +++++++++-------- .../address-hierarchy-levels.component.tsx | 4 +++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx index e2ee25ab1..b8253767b 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx @@ -18,7 +18,6 @@ function parseString(xmlDockAsString: string) { export const AddressComponent: React.FC = () => { const [selected, setSelected] = useState(''); const { addressTemplate } = useContext(ResourcesContext); - const allRequiredFields = addressTemplate?.requiredElements?.reduce((acc, curr) => ({ ...acc, [curr]: curr }), {}); const addressLayout = useMemo(() => { if (!addressTemplate?.lines) { return []; @@ -26,13 +25,15 @@ export const AddressComponent: React.FC = () => { const allFields = addressTemplate?.lines?.flat(); const fields = allFields?.filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); - - return fields.map(({ displayText, codeName }) => ({ - id: codeName, - name: codeName, - label: displayText, - required: Boolean(allRequiredFields[codeName]), - })); + const allRequiredFields = Object.fromEntries(addressTemplate?.requiredElements?.map((curr) => [curr, curr]) || []); + return fields.map(({ displayText, codeName }) => { + return { + id: codeName, + name: codeName, + label: displayText, + required: Boolean(allRequiredFields[codeName]), + }; + }); }, [addressTemplate]); const { t } = useTranslation(); diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx index cafc78122..23ac24895 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx @@ -37,6 +37,7 @@ const AddressComboBox: React.FC = ({ attribute }) => { const [field, meta, { setValue }] = useField(`address.${attribute.name}`); const { fetchEntriesForField, searchString, updateChildElements } = useAddressEntryFetchConfig(attribute.name); const { entries } = useAddressEntries(fetchEntriesForField, searchString); + const label = t(attribute.label) + (attribute?.required ? '' : ` (${t('optional', 'optional')})`); const handleInputChange = useCallback( (newValue) => { @@ -63,7 +64,8 @@ const AddressComboBox: React.FC = ({ attribute }) => { fieldProps={{ ...field, id: attribute.name, - labelText: `${t(attribute.label)} (${t('optional', 'optional')})`, + labelText: label, + required: attribute?.required, }} handleInputChange={handleInputChange} />