From dd287f1985030150fe9ac8ef6362292631f9df02 Mon Sep 17 00:00:00 2001 From: Bodhish Thomas Date: Sun, 9 Jun 2024 23:49:37 +0530 Subject: [PATCH] Fix InvestigationBuilder component initialization --- .../InvestigationBuilder.tsx | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Components/Common/prescription-builder/InvestigationBuilder.tsx b/src/Components/Common/prescription-builder/InvestigationBuilder.tsx index 6de2a83f1cb..148a16752a6 100644 --- a/src/Components/Common/prescription-builder/InvestigationBuilder.tsx +++ b/src/Components/Common/prescription-builder/InvestigationBuilder.tsx @@ -64,21 +64,26 @@ export default function InvestigationBuilder( }, []); const loadInvestigations = async () => { - const invs = await fetchInvestigations(); - const groups = await fetchInvestigationGroups(); + try { + const invs = await fetchInvestigations(); + const groups = await fetchInvestigationGroups(); - let additionalStrings: string[] = []; - additionalInvestigations.forEach((investigation) => { - additionalStrings.push((investigation[0] as string) + " (GROUP)"); - additionalStrings = [ - ...additionalStrings, - ...(investigation[1] as string[]).map( - (i: any) => i + " -- ( " + investigation[0] + " )", - ), - ]; - }); + let additionalStrings: string[] = []; + additionalInvestigations.forEach((investigation) => { + additionalStrings.push((investigation[0] as string) + " (GROUP)"); + additionalStrings = [ + ...additionalStrings, + ...(investigation[1] as string[]).map( + (i: any) => i + " -- ( " + investigation[0] + " )", + ), + ]; + }); - setInvestigationsList([...groups, ...invs, ...additionalStrings]); + setInvestigationsList([...groups, ...invs, ...additionalStrings]); + } catch (error) { + console.error("Failed to load investigations", error); + setInvestigationsList([]); + } }; const fetchInvestigations = async () => {