Skip to content

Instantly share code, notes, and snippets.

@starena
Created November 26, 2018 10:42
Show Gist options
  • Save starena/ff6447bdff7d2b7f662fc847e4da5946 to your computer and use it in GitHub Desktop.
Save starena/ff6447bdff7d2b7f662fc847e4da5946 to your computer and use it in GitHub Desktop.
var HL7Dictionary = require('hl7-dictionary');
// Use v 2.4 dictionnary
var dictionary = HL7Dictionary.definitions['2.4'];
// lookup each kind of message
var msgArray = Object.keys(dictionary.messages).map(function(key){ return dictionary.messages[key]; });
msgArray.forEach(message => {
console.log("Message " + message.name + " - " + message.desc);
// For a message, lookup each segment
var segments = message.segments;
segments.segments.forEach(segment => {
console.log("\tSegment " + segment.name);
// For each segment, lookup fields
if (dictionary.segments[segment.name]) {
dictionary.segments[segment.name].fields.forEach(function(sequence, i) {
console.log("\t\tField " + segment.name + "-" + (i+1) + " " + sequence.desc);
// IF the field is a complex one, lookup its subfields
if (dictionary.fields[sequence.datatype] && dictionary.fields[sequence.datatype].subfields.length >0) {
var field = dictionary.fields[sequence.datatype];
field.subfields.forEach(function(subfield, j) {
console.log("\t\t\t" + segment.name + "-" + (i+1) + "-" + (j+1) + " " + subfield.desc);
});
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment