diff --git a/.gitignore b/.gitignore index a717e2a8..9f8e5364 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ node_modules/ .DS_Store output/ logs/ -config/*.json +config/* !config/csv.config.example.json diff --git a/package-lock.json b/package-lock.json index fde4bb9b..8ba334b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2412,7 +2412,8 @@ }, "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "ansi-styles": { @@ -3145,6 +3146,11 @@ "which": "^2.0.1" } }, + "crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==" + }, "cssom": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz", @@ -4052,6 +4058,32 @@ "url-join": "^4.0.1" } }, + "fhir-mapper": { + "version": "git+https://github.com/standardhealth/fhir-mapper.git#531dcdb9d4673b14aa4fafe8eccfcdeaa1dd370e", + "from": "git+https://github.com/standardhealth/fhir-mapper.git", + "requires": { + "crypto": "^1.0.1", + "fhirpath": "^0.10.3", + "lodash": "^4.17.21" + }, + "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + }, + "fhirpath": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/fhirpath/-/fhirpath-0.10.3.tgz", + "integrity": "sha512-QxASSupObeYe8IAfX/qbSJoU57iitln8sN3W716G4gk6NJcLcbDLuiINibPqQ1MyugUEpUH/trl8Kb9i/l3Mhw==", + "requires": { + "antlr4": "^4.7.1", + "commander": "^2.18.0", + "js-yaml": "^3.12.0" + } + } + } + }, "fhirpath": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/fhirpath/-/fhirpath-2.1.5.tgz", diff --git a/package.json b/package.json index 8b00d500..3ce76412 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/application/app.js b/src/application/app.js index 0c83f5d8..85630096 100644 --- a/src/application/app.js +++ b/src/application/app.js @@ -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'); @@ -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) {