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

Adding post-extraction mapping and importing extractor list from MEF #67

Merged
merged 4 commits into from
Nov 30, 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 .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @julianxcarter @dmendelowitz @dtphelan1
* @dmendelowitz
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
98 changes: 71 additions & 27 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#old-fhirpath",
"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
Loading