@amida-tech/hl7-parser
Version:
Typescript library to parse hl7 message into a typescript/javascript object and back
58 lines (57 loc) • 2.38 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hl7Message = void 0;
var segment_model_1 = require("./segment.model");
var Hl7Message = /** @class */ (function (_super) {
__extends(Hl7Message, _super);
function Hl7Message() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**Returns field element by its name i.e. (MSH-1) */
Hl7Message.prototype.getElementByName = function (fieldName) {
var segment = this.findSegmentByName(fieldName, this.children); //Find segment to not iterate over every field in wrong segment
if (!segment)
return;
var el = this.findElementByName(fieldName, segment.children); //find element on the segment's children
return el;
};
Hl7Message.prototype.findElementByName = function (fieldName, children) {
if (!children)
return;
for (var i = 0; i < children.length; i++) {
var name_1 = children[i].name;
if (fieldName == name_1)
return children[i];
var el = this.findElementByName(fieldName, children[i].children);
if (el) {
return el;
}
}
};
Hl7Message.prototype.findSegmentByName = function (fieldName, children) {
if (!this.children)
return;
for (var i = 0; i < children.length; i++) {
if (fieldName.includes(children[i].name)) {
return this;
}
}
};
return Hl7Message;
}(segment_model_1.Segment));
exports.Hl7Message = Hl7Message;