From 9efb01f6203c59e32fe95937d860bcbd8ef00a40 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Mon, 5 Aug 2024 19:19:02 +0200 Subject: [PATCH] feat(anni): contract redundant external data --- .../src/database/helpers/contraction-utils.ts | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/anni/src/database/helpers/contraction-utils.ts b/anni/src/database/helpers/contraction-utils.ts index 6f6644e5..a79a37cf 100644 --- a/anni/src/database/helpers/contraction-utils.ts +++ b/anni/src/database/helpers/contraction-utils.ts @@ -93,12 +93,37 @@ function contractByLookupkey( }); } +function contractRedundantExternalData( + drugsWithGuidelines: Array, +): Array { + return drugsWithGuidelines.map(({ drug, guidelines }) => { + return { + drug, + guidelines: guidelines.map((guideline) => { + const informationMap = new Map(); + guideline.externalData.forEach((externalData) => { + const key = externalDataInformationKey(externalData); + if (!informationMap.has(key)) { + informationMap.set(key, externalData); + } + }); + return { + ...guideline, + externalData: Array.from(informationMap.values()), + }; + }), + }; + }); +} + export function contractGuidelines( drugsWithGuidelines: Array, source: string, ): Array { - return contractByPhenotypeAndInformation( - contractByLookupkey(drugsWithGuidelines), - source, + return contractRedundantExternalData( + contractByPhenotypeAndInformation( + contractByLookupkey(drugsWithGuidelines), + source, + ), ); }