Skip to content

Instantly share code, notes, and snippets.

@tuananh

tuananh/transform.js

Created May 30, 2018
Embed
What would you like to do?
const transform = require('camaro')
const fs = require('fs')
const xml = fs.readFileSync('./test.xml', 'utf8')
const template = {
responses: [
'//responses[@type="C-FIND"]/data-set', {
AccessionNumber: 'element[1]/text()',
PatientName: 'element[2]/text()',
PatientID: 'element[3]/text()',
PatientBirthDate: 'element[4]/text()',
PatientSex: 'element[5]/text()',
MedicalAlerts: 'element[6]/text()',
Allergies: 'element[7]/text()',
StudyInstanceUID: 'element[8]/text()',
RequestingPhysician:
'element[9]/text()',
RequestedProcedureDescription:
'element[10]/text()',
RequestedProcedureCode:
'sequence[1]/item[@len="58"]/element[1]/text()',
RequestedProcedureDesignator:
'sequence[1]/item[@len="58"]/element[2]/text()',
CurrentPatientLocation:
'element[11]/text()',
Modality:
'sequence[2]/item[@len="164"]/element[1]/text()',
RequestedContrastAgent:
'sequence[2]/item[@len="164"]/element[2]/text()',
ScheduledStationAETitle:
'sequence[2]/item[@len="164"]/element[3]/text()',
ScheduledProcedureStepStartDate:
'sequence[2]/item[@len="164"]/element[4]/text()',
ScheduledProcedureStepStartTime:
'sequence[2]/item[@len="164"]/element[5]/text()',
ScheduledPerformingPhysicianName:
'sequence[2]/item[@len="164"]/element[6]/text()',
ScheduledProcedureStepDescription:
'sequence[2]/item[@len="164"]/element[7]/text()',
ScheduledProcedureStepID:
'sequence[2]/item[@len="164"]/element[8]/text()',
ScheduledStationName:
'sequence[2]/item[@len="164"]/element[9]/text()',
ScheduledProcedureStepLocation:
'sequence[2]/item[@len="164"]/element[10]/text()',
PreMedication:
'sequence[2]/item[@len="164"]/element[11]/text()',
CommentsOnTheScheduledProcedureStep:
'sequence[2]/item[@len="164"]/element[12]/text()',
RequestedProcedureID:
'element[12]/text()',
ReasonForTheRequestedProcedure:
'element[13]/text()',
RequestedProcedurePriority:
'element[14]/text()'
}
]
}
console.log(transform(xml, template))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment