Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-extraction mapper #199

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ node_modules/
.DS_Store
output/
logs/
config/*.json
config/*
!config/csv.config.example.json
34 changes: 33 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"commander": "^6.2.0",
"csv-parse": "^4.8.8",
"fhir-crud-client": "^1.2.2",
"fhir-mapper": "git+https://github.com/standardhealth/fhir-mapper.git",
"fhirpath": "2.1.5",
"lodash": "^4.17.21",
"moment": "^2.29.4",
Expand Down
16 changes: 16 additions & 0 deletions src/application/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const moment = require('moment');
const fs = require('fs');
const path = require('path');
const { AggregateMapper } = require('fhir-mapper');
const logger = require('../helpers/logger');
const { RunInstanceLogger } = require('./tools/RunInstanceLogger');
const { sendEmailNotification, zipErrors } = require('./tools/emailNotifications');
Expand Down Expand Up @@ -43,6 +46,19 @@ 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);

// Post-extraction mapping
if (fs.existsSync('./config/mapper.js')) {
logger.info('Applying post-extraction mapping');
// eslint-disable-next-line global-require, import/no-dynamic-require
const { resourceMapping, variables } = require(path.resolve('../../config/mapper.js'));
const mapper = new AggregateMapper(resourceMapping, variables);
extractedData.map((bundle) => {
const mappedBundle = bundle;
mappedBundle.entry = mapper.execute(bundle.entry);
return bundle;
});
}

// If we have notification information, send an emailNotification
const { notificationInfo } = config;
if (notificationInfo && Object.keys(notificationInfo).length > 0) {
Expand Down
Loading