Skip to content

Commit 5b22683

Browse files
authored
Merge pull request #126 from mcode/return-extracted-data
Modified app.js to return object instead of writing to file; moved code to write to file to cli.js
2 parents 40f75a5 + d0f9cec commit 5b22683

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/cli/app.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,7 @@ async function mcodeApp(Client, fromDate, toDate, pathToConfig, pathToRunLogs, d
129129
}
130130
}
131131

132-
// 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}`);
132+
return extractedData;
145133
}
146134

147135
module.exports = {

src/cli/cli.js

Lines changed: 16 additions & 1 deletion
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,7 +27,21 @@ const allEntries = !entriesFilter;
2627

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

0 commit comments

Comments
 (0)