Skip to content

Commit 29d7f8c

Browse files
Modified app.js to return object instead of writing to file; moved code to write to file to cli.js
1 parent 40f75a5 commit 29d7f8c

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/cli/app.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,23 @@ async function mcodeApp(Client, fromDate, toDate, pathToConfig, pathToRunLogs, d
129129
}
130130
}
131131

132+
133+
134+
132135
// Finally, save the data to disk
133-
const outputPath = './output';
134-
if (!fs.existsSync(outputPath)) {
135-
logger.info(`Creating directory ${outputPath}`);
136-
fs.mkdirSync(outputPath);
137-
}
138-
// For each bundle in our extractedData, write it to our output directory
139-
extractedData.forEach((bundle, i) => {
140-
const outputFile = path.join(outputPath, `mcode-extraction-patient-${i + 1}.json`);
141-
logger.debug(`Logging mCODE output to ${outputFile}`);
142-
fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8');
143-
});
144-
logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`);
136+
// const outputPath = './output';
137+
// if (!fs.existsSync(outputPath)) {
138+
// logger.info(`Creating directory ${outputPath}`);
139+
// fs.mkdirSync(outputPath);
140+
// }
141+
// // For each bundle in our extractedData, write it to our output directory
142+
// extractedData.forEach((bundle, i) => {
143+
// const outputFile = path.join(outputPath, `mcode-extraction-patient-${i + 1}.json`);
144+
// logger.debug(`Logging mCODE output to ${outputFile}`);
145+
// fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8');
146+
// });
147+
// logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`);
148+
return extractedData;
145149
}
146150

147151
module.exports = {

src/cli/cli.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs');
12
const path = require('path');
23
const program = require('commander');
34
const { MCODEClient } = require('../client/MCODEClient');
@@ -26,8 +27,24 @@ const allEntries = !entriesFilter;
2627

2728
async function runApp() {
2829
try {
29-
await mcodeApp(MCODEClient, fromDate, toDate, configFilepath, runLogFilepath, debug, allEntries);
30-
} catch (e) {
30+
extractedData = await mcodeApp(MCODEClient, fromDate, toDate, configFilepath, runLogFilepath, debug, allEntries);
31+
32+
33+
// Finally, save the data to disk
34+
const outputPath = './output';
35+
if (!fs.existsSync(outputPath)) {
36+
logger.info(`Creating directory ${outputPath}`);
37+
fs.mkdirSync(outputPath);
38+
}
39+
// For each bundle in our extractedData, write it to our output directory
40+
extractedData.forEach((bundle, i) => {
41+
const outputFile = path.join(outputPath, `mcode-extraction-patient-${i + 1}.json`);
42+
logger.debug(`Logging mCODE output to ${outputFile}`);
43+
fs.writeFileSync(outputFile, JSON.stringify(bundle), 'utf8');
44+
});
45+
logger.info(`Successfully logged ${extractedData.length} mCODE bundle(s) to ${outputPath}`);
46+
47+
} catch (e) {
3148
if (debug) logger.level = 'debug';
3249
logger.error(e.message);
3350
logger.debug(e.stack);

0 commit comments

Comments
 (0)