diff --git a/lib/services/medipostTest.service.ts b/lib/services/medipostTest.service.ts index ee5a294..192db4c 100644 --- a/lib/services/medipostTest.service.ts +++ b/lib/services/medipostTest.service.ts @@ -91,6 +91,12 @@ export async function composeOrderTestResponseXML({ // 5 – Tagasi lükatud, 6 – Tühistatud. const orderStatus = 4; const orderNumber = 'TSU000001200'; + + const allAnalysisElementsForGroups = analysisElements?.filter((element) => { + return analysisGroups.some((group) => group.id === element.analysis_groups.id); + }); + const addedIds = new Set(); + return ` ${getPais(USER, RECIPIENT, orderCreatedAt, orderId, "AL")} @@ -118,12 +124,17 @@ export async function composeOrderTestResponseXML({ ${orderNumber} ${orderStatus} - ${analysisGroups.map((group) => { + ${allAnalysisElementsForGroups.map((analysisElement) => { + const group = analysisGroups.find((group) => group.id === analysisElement.analysis_groups.id); + if (!group) { + throw new Error(`Failed to find group for analysis element ${analysisElement.id}`); + } + let relatedAnalysisElement = analysisElements?.find( - (element) => element.analysis_groups.id === group.id, + (element) => element.analysis_groups.id === group.id && !addedIds.has(element.id), ); const relatedAnalyses = analyses?.filter((analysis) => { - return analysis.analysis_elements.analysis_groups.id === group.id; + return analysis.analysis_elements.analysis_groups.id === group.id && !addedIds.has(analysis.analysis_elements.id); }); if (!relatedAnalysisElement) { @@ -143,6 +154,7 @@ export async function composeOrderTestResponseXML({ const lower = getRandomInt(0, 100); const upper = getRandomInt(lower + 1, 500); const result = getRandomInt(lower, upper); + addedIds.add(relatedAnalysisElement.id); return (` ${group.original_id}