From 29d7f8c74017977a64d2c08cd3b73110e1fa48a5 Mon Sep 17 00:00:00 2001 From: SenecaAnderson Date: Thu, 3 Jun 2021 11:09:43 -0400 Subject: [PATCH 1/3] Modified app.js to return object instead of writing to file; moved code to write to file to cli.js --- src/cli/app.js | 28 ++++++++++++++++------------ src/cli/cli.js | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/cli/app.js b/src/cli/app.js index 7ac4b60a..3fb118c5 100644 --- a/src/cli/app.js +++ b/src/cli/app.js @@ -129,19 +129,23 @@ 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}`); + // 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..829925c0 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,8 +27,24 @@ const allEntries = !entriesFilter; async function runApp() { try { - await mcodeApp(MCODEClient, fromDate, toDate, configFilepath, runLogFilepath, debug, allEntries); - } catch (e) { + 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); logger.debug(e.stack); From e3d01b4852a2dc6bd5b9b54550aefc3eee53a1d2 Mon Sep 17 00:00:00 2001 From: SenecaAnderson Date: Thu, 3 Jun 2021 11:13:05 -0400 Subject: [PATCH 2/3] Deleted excess comments in app.js --- src/cli/app.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/cli/app.js b/src/cli/app.js index 3fb118c5..99d1d632 100644 --- a/src/cli/app.js +++ b/src/cli/app.js @@ -129,22 +129,6 @@ 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; } From d0f9cec5399263dfa942d16cdd785c9c2306aa1d Mon Sep 17 00:00:00 2001 From: SenecaAnderson Date: Thu, 3 Jun 2021 13:08:55 -0400 Subject: [PATCH 3/3] Fixed linting errors and extractData declaration in cli.js --- src/cli/cli.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cli/cli.js b/src/cli/cli.js index 829925c0..d7a6e7af 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -27,8 +27,7 @@ const allEntries = !entriesFilter; async function runApp() { try { - extractedData = 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'; @@ -43,8 +42,7 @@ async function runApp() { fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8'); }); logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`); - - } catch (e) { + } catch (e) { if (debug) logger.level = 'debug'; logger.error(e.message); logger.debug(e.stack);