From 0bd7831a7463a1006dec0d3d28e7c0c7af824a54 Mon Sep 17 00:00:00 2001 From: Jose Costa Teixeira Date: Mon, 16 Feb 2026 07:43:01 +0100 Subject: [PATCH 1/3] Fix crash when converting bundles without entries to R4 --- tests/tx/search.test.js | 13 +++++++++++++ tx/xversion/xv-bundle.js | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/tx/search.test.js b/tests/tx/search.test.js index 0a7af62..bb82150 100644 --- a/tests/tx/search.test.js +++ b/tests/tx/search.test.js @@ -236,6 +236,19 @@ describe('Search Worker', () => { expect(response.body.link).toBeUndefined(); }); + test('should return only count with _summary=count on R4 endpoint', async () => { + const response = await request(app) + .get('/tx/r4/ValueSet') + .query({ _summary: 'count' }) + .set('Accept', 'application/json'); + + expect(response.status).toBe(200); + expect(response.body.resourceType).toBe('Bundle'); + expect(response.body.type).toBe('searchset'); + expect(response.body.total).toBeGreaterThan(0); + expect(response.body.entry).toBeUndefined(); + }); + test('should return full resources with _summary=false', async () => { const response = await request(app) .get('/tx/r5/CodeSystem') diff --git a/tx/xversion/xv-bundle.js b/tx/xversion/xv-bundle.js index 9f27fb6..74492dc 100644 --- a/tx/xversion/xv-bundle.js +++ b/tx/xversion/xv-bundle.js @@ -15,7 +15,7 @@ function bundleToR5(jsonObj, sourceVersion) { return jsonObj; // No conversion needed } - for (let be of jsonObj.entry) { + for (let be of jsonObj.entry || []) convertResourceToR5(be.resource, sourceVersion); } @@ -51,7 +51,7 @@ function bundleFromR5(r5Obj, targetVersion) { } bundle.total = r5Obj.total; bundle.link = r5Obj.link; - for (let be5 of r5Obj.entry) { + for (let be5 of r5Obj.entry || []) { let be = {}; if (!bundle.entry) { bundle.entry = []; From 3e703cb9158a64da728cbbc0de031b66b02db24c Mon Sep 17 00:00:00 2001 From: Jose Costa Teixeira Date: Mon, 16 Feb 2026 06:48:16 +0000 Subject: [PATCH 2/3] Fix syntax error in xv-bundle.js --- tx/xversion/xv-bundle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tx/xversion/xv-bundle.js b/tx/xversion/xv-bundle.js index 74492dc..ebc6d88 100644 --- a/tx/xversion/xv-bundle.js +++ b/tx/xversion/xv-bundle.js @@ -15,7 +15,7 @@ function bundleToR5(jsonObj, sourceVersion) { return jsonObj; // No conversion needed } - for (let be of jsonObj.entry || []) + for (let be of jsonObj.entry || []) { convertResourceToR5(be.resource, sourceVersion); } @@ -68,4 +68,4 @@ function bundleFromR5(r5Obj, targetVersion) { return bundle; } -module.exports = { bundleToR5, bundleFromR5 }; \ No newline at end of file +module.exports = { bundleToR5, bundleFromR5 }; From 27127d45609fbe04bc302af1a3b20699d6a0be7c Mon Sep 17 00:00:00 2001 From: Jose Costa Teixeira Date: Mon, 16 Feb 2026 07:59:25 +0100 Subject: [PATCH 3/3] Fix R4 search test to use R5 endpoint --- tests/tx/search.test.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/tx/search.test.js b/tests/tx/search.test.js index bb82150..ebecde6 100644 --- a/tests/tx/search.test.js +++ b/tests/tx/search.test.js @@ -236,9 +236,9 @@ describe('Search Worker', () => { expect(response.body.link).toBeUndefined(); }); - test('should return only count with _summary=count on R4 endpoint', async () => { + test('should return only count with _summary=count for ValueSet', async () => { const response = await request(app) - .get('/tx/r4/ValueSet') + .get('/tx/r5/ValueSet') .query({ _summary: 'count' }) .set('Accept', 'application/json'); @@ -249,6 +249,19 @@ describe('Search Worker', () => { expect(response.body.entry).toBeUndefined(); }); + test('bundleFromR5 handles bundle without entries', () => { + const { bundleFromR5 } = require('../../tx/xversion/xv-bundle'); + const r5Bundle = { + resourceType: 'Bundle', + type: 'searchset', + total: 42 + }; + const r4Bundle = bundleFromR5(r5Bundle, '4.0.1'); + expect(r4Bundle.resourceType).toBe('Bundle'); + expect(r4Bundle.total).toBe(42); + expect(r4Bundle.entry).toBeUndefined(); + }); + test('should return full resources with _summary=false', async () => { const response = await request(app) .get('/tx/r5/CodeSystem')