Skip to content

Commit

Permalink
Adding post-extraction filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
dmendelowitz committed Sep 25, 2023
1 parent 9e96594 commit 3c3a6f6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { sendEmailNotification, zipErrors } = require('./tools/emailNotifications
const { extractDataForPatients } = require('./tools/mcodeExtraction');
const { parsePatientIds } = require('../helpers/appUtils');
const { validateConfig } = require('../helpers/configUtils');
const { postExtractionFilter } = require('../helpers/filterUtils');

function checkInputAndConfig(config, fromDate, toDate) {
// Check input args and needed config variables based on client being used
Expand Down Expand Up @@ -43,6 +44,12 @@ async function mcodeApp(Client, fromDate, toDate, config, pathToRunLogs, debug,
logger.info(`Extracting data for ${patientIds.length} patients`);
const { extractedData, successfulExtraction, totalExtractionErrors } = await extractDataForPatients(patientIds, mcodeClient, effectiveFromDate, effectiveToDate);

// Perform post-extraction processes
if (config.postExtractionFilter) {
logger.info('Applying post-extraction filter to bundle');
postExtractionFilter(extractedData, config.postExtractionFilter);
}

// If we have notification information, send an emailNotification
const { notificationInfo } = config;
if (notificationInfo && Object.keys(notificationInfo).length > 0) {
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/filterUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fhirpath = require('fhirpath');

function postExtractionFilter(extractedData, filter) {
extractedData.map((bundle) => {
const filteredBundle = bundle;
filteredBundle.entry = fhirpath.evaluate(
bundle,
`Bundle.entry.where(${filter})`,
);
return filteredBundle;
});
}

module.exports = {
postExtractionFilter,
};
4 changes: 4 additions & 0 deletions src/helpers/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"title": "Patient ID CSV File",
"type": "string"
},
"postExtractionFilter": {
"title": "Post-Extraction Filter",
"type": "string"
},
"commonExtractorArgs": {
"$ref": "#/$defs/commonExtractorArgs"
},
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const { parsePatientIds } = require('./helpers/appUtils');
const { getConfig, validateConfig } = require('./helpers/configUtils');
const configSchema = require('./helpers/schemas/config.schema.json');
const { sortExtractors } = require('./helpers/dependencyUtils');
const { postExtractionFilter } = require('./helpers/filterUtils');

module.exports = {
// CLI Related utilities
Expand Down Expand Up @@ -156,6 +157,7 @@ module.exports = {
lowercaseLookupQuery,
mEpochToDate,
sortExtractors,
postExtractionFilter,
// Context operations
getConditionEntriesFromContext,
getConditionsFromContext,
Expand Down

0 comments on commit 3c3a6f6

Please sign in to comment.