Skip to content

Commit

Permalink
Adding post-extraction mapping and importing extractor list from MEF
Browse files Browse the repository at this point in the history
  • Loading branch information
dmendelowitz committed Nov 21, 2023
1 parent e9d77bc commit 6d2fb25
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ node_modules/
output/
logs/
*.p12
config/*.json
config/*
!config/csv.config.example.json
94 changes: 69 additions & 25 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"commander": "^4.1.1",
"cross-env": "^7.0.1",
"csv-parse": "^4.8.9",
"fhir-mapper": "git+https://github.com/standardhealth/fhir-mapper.git",
"fhir-messaging-client": "git+https://github.com/ICAREdata/fhir-messaging-client.git",
"fhirpath": "^2.3.0",
"lodash": "^4.17.21",
"mcode-extraction-framework": "git+https://github.com/mcode/mcode-extraction-framework.git",
"mcode-extraction-framework": "git+https://github.com/mcode/mcode-extraction-framework.git#export-extractor-list",
"moment": "^2.29.4",
"nodemailer": "^6.7.2",
"uuid": "^7.0.2"
Expand Down
50 changes: 2 additions & 48 deletions src/ICARECSVClient.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,12 @@
const {
BaseClient,
CSVAdverseEventExtractor,
CSVCancerDiseaseStatusExtractor,
CSVCancerRelatedMedicationAdministrationExtractor,
CSVCancerRelatedMedicationRequestExtractor,
CSVClinicalTrialInformationExtractor,
CSVConditionExtractor,
CSVCTCAdverseEventExtractor,
CSVEncounterExtractor,
CSVObservationExtractor,
CSVPatientExtractor,
CSVProcedureExtractor,
CSVStagingExtractor,
CSVTreatmentPlanChangeExtractor,
sortExtractors,
} = require('mcode-extraction-framework');
const { CSVExtractors, dependencyInfo, BaseClient, sortExtractors } = require('mcode-extraction-framework');
const { generateNewMessageBundle } = require('./icareFhirMessaging');

class ICARECSVClient extends BaseClient {
constructor({ extractors, commonExtractorArgs }) {
super();
this.registerExtractors(
CSVAdverseEventExtractor,
CSVCancerDiseaseStatusExtractor,
CSVCancerRelatedMedicationAdministrationExtractor,
CSVCancerRelatedMedicationRequestExtractor,
CSVClinicalTrialInformationExtractor,
CSVConditionExtractor,
CSVCTCAdverseEventExtractor,
CSVEncounterExtractor,
CSVObservationExtractor,
CSVPatientExtractor,
CSVProcedureExtractor,
CSVStagingExtractor,
CSVTreatmentPlanChangeExtractor,
);
this.registerExtractors(...CSVExtractors);
// Store the extractors defined by the configuration file as local state
this.extractorConfig = extractors;
// Define information about the order and dependencies of extractors
const dependencyInfo = [
{ type: 'CSVPatientExtractor', dependencies: [] },
{ type: 'CSVConditionExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVCancerDiseaseStatusExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVClinicalTrialInformationExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVTreatmentPlanChangeExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVStagingExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVCancerRelatedMedicationAdministrationExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVCancerRelatedMedicationRequestExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVProcedureExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVObservationExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVAdverseEventExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVCTCAdverseEventExtractor', dependencies: ['CSVPatientExtractor'] },
{ type: 'CSVEncounterExtractor', dependencies: ['CSVPatientExtractor'] },
];
// Sort extractors based on order and dependencies
this.extractorConfig = sortExtractors(this.extractorConfig, dependencyInfo);
this.commonExtractorArgs = {
Expand Down
16 changes: 16 additions & 0 deletions src/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,
sendEmailNotification,
Expand Down Expand Up @@ -81,6 +84,19 @@ async function icareApp(
logger.info(`Extracting data for ${patientIds.length} patients`);
const { extractedData, successfulExtraction, totalExtractionErrors } = await extractDataForPatients(patientIds, icareClient, 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;
});
}

// Post the data using the messagingClient
let successfulMessagePost = true;
let messagingErrors = {};
Expand Down

0 comments on commit 6d2fb25

Please sign in to comment.