UNPKG

health-level-seven-parser

Version:

Typescript library to parse hl7 message into a typescript/javascript object and back

52 lines (51 loc) 2.13 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); 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;