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 4 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
65 changes: 59 additions & 6 deletions src/helpers/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"notificationInfo": {
"$ref": "#/$defs/notificationInfo"
},
"postExtraction": {
"$ref": "#/$defs/postExtraction"
},
"extractors": {
"title": "Extractors",
"type": "array",
Expand Down Expand Up @@ -41,7 +44,7 @@
"title": "Request Headers",
"type": "object"
},
"csvParse" : {
"csvParse": {
"title": "CSV Parse",
"type": "object",
"properties": {
Expand Down Expand Up @@ -96,11 +99,61 @@
}
},
"dependencies": {
"host": { "required": ["to"] },
"to": { "required": ["host"] },
"from": { "required": ["host", "to"] },
"port": { "required": ["host", "to"] },
"tlsRejectUnauthorized": { "required": ["host", "to"] }
"host": {
"required": [
"to"
]
},
"to": {
"required": [
"host"
]
},
"from": {
"required": [
"host",
"to"
]
},
"port": {
"required": [
"host",
"to"
]
},
"tlsRejectUnauthorized": {
"required": [
"host",
"to"
]
}
}
},
"postExtraction": {
"title": "Post Extraction Processes",
"type": "object",
"properties": {
"dateFilter": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still relevant/correct?

"$ref": "#/$defs/postExtraction"
}
}
},
"dateFilter": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still relevant?

"title": "Date Filter",
"type": "object",
"properties": {
"resourceTypes": {
"title": "Resource Types",
"type": "string"
},
"startDate": {
"title": "Start Date",
"type": "string"
},
"endDate": {
"title": "End Date",
"type": "string"
}
}
},
"extractor": {
Expand Down
Loading