diff --git a/src/cli/app.js b/src/cli/app.js index 7ac4b60a..99d1d632 100644 --- a/src/cli/app.js +++ b/src/cli/app.js @@ -129,19 +129,7 @@ async function mcodeApp(Client, fromDate, toDate, pathToConfig, pathToRunLogs, d } } - // Finally, save the data to disk - const outputPath = './output'; - if (!fs.existsSync(outputPath)) { - logger.info(`Creating directory ${outputPath}`); - fs.mkdirSync(outputPath); - } - // For each bundle in our extractedData, write it to our output directory - extractedData.forEach((bundle, i) => { - const outputFile = path.join(outputPath, `mcode-extraction-patient-${i + 1}.json`); - logger.debug(`Logging mCODE output to ${outputFile}`); - fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8'); - }); - logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`); + return extractedData; } module.exports = { diff --git a/src/cli/cli.js b/src/cli/cli.js index 567663db..d7a6e7af 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const path = require('path'); const program = require('commander'); const { MCODEClient } = require('../client/MCODEClient'); @@ -26,7 +27,21 @@ const allEntries = !entriesFilter; async function runApp() { try { - await mcodeApp(MCODEClient, fromDate, toDate, configFilepath, runLogFilepath, debug, allEntries); + const extractedData = await mcodeApp(MCODEClient, fromDate, toDate, configFilepath, runLogFilepath, debug, allEntries); + + // Finally, save the data to disk + const outputPath = './output'; + if (!fs.existsSync(outputPath)) { + logger.info(`Creating directory ${outputPath}`); + fs.mkdirSync(outputPath); + } + // For each bundle in our extractedData, write it to our output directory + extractedData.forEach((bundle, i) => { + const outputFile = path.join(outputPath, `mcode-extraction-patient-${i + 1}.json`); + logger.debug(`Logging mCODE output to ${outputFile}`); + fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8'); + }); + logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`); } catch (e) { if (debug) logger.level = 'debug'; logger.error(e.message);