From 0ff30d7b17b111683d1bd52233b03fa8dae94548 Mon Sep 17 00:00:00 2001 From: Anthony Roach Date: Sat, 22 Jun 2019 13:45:07 -0400 Subject: [PATCH] Fix `lo fhir list --json` to actually output valid json --- lib/cmds/fhir_cmds/list.js | 13 ++++++++++--- test/unit/commands/fhir-test.js | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/cmds/fhir_cmds/list.js b/lib/cmds/fhir_cmds/list.js index 07569c0..00416ad 100644 --- a/lib/cmds/fhir_cmds/list.js +++ b/lib/cmds/fhir_cmds/list.js @@ -56,6 +56,7 @@ async function search (type, query, options) { } const searchUrl = `${account}/dstu3/${type}/_search`; + let allResults = []; while (true) { const response = await post( options, @@ -73,8 +74,10 @@ async function search (type, query, options) { linesResult.forEach(line => { console.log(line); }); - } else { + } else if (options.jsonLine) { results.forEach(result => print(result, options)); + } else { + allResults = allResults.concat(results); } } @@ -84,12 +87,16 @@ async function search (type, query, options) { const parsedUrl = url.parse(next.url, true); query = Object.assign(query, parsedUrl.query); } else { - return; + break; } } else { - return; + break; } } + + if (!csvConfig && !options.jsonLine) { + print(allResults, options); + } } function formatResults (results, csvConfig, options) { diff --git a/test/unit/commands/fhir-test.js b/test/unit/commands/fhir-test.js index a69fe45..bc97cf8 100644 --- a/test/unit/commands/fhir-test.js +++ b/test/unit/commands/fhir-test.js @@ -55,7 +55,7 @@ test.serial.cb('The "fhir" command should list fhir resources', t => { t.is(postStub.getCall(0).args[2], '_tag=http%3A%2F%2Flifeomic.com%2Ffhir%2Fdataset%7CprojectId&pageSize=1000'); t.deepEqual(postStub.getCall(0).args[3], {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}); t.is(printSpy.callCount, 1); - t.deepEqual(printSpy.getCall(0).args[0], {'resourceType': 'Patient', 'id': 'ABC1234'}); + t.deepEqual(printSpy.getCall(0).args[0], [{'resourceType': 'Patient', 'id': 'ABC1234'}]); t.end(); }; @@ -73,7 +73,7 @@ test.serial.cb('The "fhir" command should list fhir resources with a query expre t.is(postStub.getCall(0).args[2], '_tag=http%3A%2F%2Flifeomic.com%2Ffhir%2Ftag%7Cvalue&_tag=http%3A%2F%2Flifeomic.com%2Ffhir%2Fdataset%7CprojectId&pageSize=1000'); t.deepEqual(postStub.getCall(0).args[3], {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}); t.is(printSpy.callCount, 1); - t.deepEqual(printSpy.getCall(0).args[0], {'resourceType': 'Patient', 'id': 'ABC1234'}); + t.deepEqual(printSpy.getCall(0).args[0], [{'resourceType': 'Patient', 'id': 'ABC1234'}]); t.end(); }; @@ -91,7 +91,7 @@ test.serial.cb('Limit should set the page size for the "fhir" command', t => { t.is(postStub.getCall(0).args[2], 'pageSize=10'); t.deepEqual(postStub.getCall(0).args[3], {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}); t.is(printSpy.callCount, 1); - t.deepEqual(printSpy.getCall(0).args[0], {'resourceType': 'Patient', 'id': 'ABC1234'}); + t.deepEqual(printSpy.getCall(0).args[0], [{'resourceType': 'Patient', 'id': 'ABC1234'}]); t.end(); };