diff --git a/src/component.ts b/src/component.ts index 95468fe..bb82b9a 100644 --- a/src/component.ts +++ b/src/component.ts @@ -46,6 +46,7 @@ export class Component extends ValueNode { * @since 1.0.0 * @param text * @param index + * @see {@link SubComponent} * @protected */ protected createChild(text: string, index: number): Node { diff --git a/src/field.ts b/src/field.ts index 312b52b..1d4f18b 100644 --- a/src/field.ts +++ b/src/field.ts @@ -1,47 +1,70 @@ -import Node from './node'; -import Delimiters from "./delimiters"; -import ValueNode from "./valueNode"; -import FieldRepetition from "./fieldRepetition"; -import NodeBase from './nodeBase'; +import {Delimiters} from "./decorators/enum/delimiters.js"; +import { Node } from "./decorators/interfaces/node.js" +import {FieldRepetition} from "./fieldRepetition.js"; +import {NodeBase} from "./nodeBase.js"; +import {ValueNode} from "./valueNode.js"; -export default class Field extends ValueNode { +/** + * Field Area of the HL7 Segment + * @since 1.0.0 + * @extends ValueNode + */ +export class Field extends ValueNode { + /** + * @since 1.0.0 + * @param parent + * @param key + * @param text + */ constructor(parent: NodeBase, key: string, text: string) { super(parent, key, text, Delimiters.Repetition); } + /** + * Read a Field Path + * @since 1.0.0 + * @param path + */ read(path: string[]): Node { - - if(this.children.length > 0) { + if (this.children.length > 0) { return this.children[0].read(path); } - - return null; + throw new Error("We have a problem.") } + /** + * Write a Field + * @since 1.0.0 + * @param path + * @param value + * @protected + */ protected writeCore(path: string[], value: string): Node { - return this._ensureChild().write(path, value); } - protected createChild(text: string, index: number): Node { - + /** + * Create a field repetition field of FieldRepetition + * @since 1.0.0 + * @see {@link FieldRepetition} + * @param text + * @param _index + * @protected + */ + protected createChild(text: string, _index: number): Node { return new FieldRepetition(this, this.key, text); } + /** @internal */ private _ensureChild(): Node { - - var child: Node; - - // create a repetition if we do not have one already - if(this.children.length == 0) { + let child: Node; + if (this.children.length == 0) { child = this.createChild("", 0); this.setChild(child, 0); - } - else { + } else { child = this.children[0]; } - return child; } } \ No newline at end of file diff --git a/src/fieldRepetition.ts b/src/fieldRepetition.ts index 75b5ec2..f36b069 100644 --- a/src/fieldRepetition.ts +++ b/src/fieldRepetition.ts @@ -1,33 +1,69 @@ -import Node from './node'; -import Delimiters from "./delimiters"; -import ValueNode from "./valueNode"; -import Component from "./component"; -import NodeBase from './nodeBase'; +import {Component} from "./component"; +import {Delimiters} from "./decorators/enum/delimiters"; +import {Node} from "./decorators/interfaces/node" +import {HL7FatalError} from "./exception"; +import {NodeBase} from "./nodeBase"; +import {ValueNode} from "./valueNode"; -export default class FieldRepetition extends ValueNode { +/** + * Create a Field Repetition in an HL7 message segment + * @since 1.0.0 + * @extends ValueNode + */ +export class FieldRepetition extends ValueNode { + /** + * @since 1.0.0 + * @param parent + * @param key + * @param text + */ constructor(parent: NodeBase, key: string, text: string) { super(parent, key, text, Delimiters.Component); } + /** + * Read Path + * @since 1.0.0 + * @param path + */ read(path: string[]): Node { - - var component = this.children[parseInt(path.shift())-1]; + let component = this.children[parseInt(path.shift())-1]; return component && path.length > 0 ? component.read(path) : component; } + /** + * Write Core + * @since 1.0.0 + * @param path + * @param value + * @protected + */ protected writeCore(path: string[], value: string): Node { - - return this.writeAtIndex(path, value, parseInt(path.shift())-1); + return this.writeAtIndex(path, value, parseInt(path.shift())-1); } + /** + * Get Path Core + * @since 1.0.0 + * @protected + */ protected pathCore(): string[] { - + if (this.parent == null) { + throw new HL7FatalError(500, "this.parent must not be null.") + } return this.parent.path; } + /** + * Create child of a field repetition + * @since 1.0.0 + * @param text + * @param index + * @see {@link Component} + * @protected + */ protected createChild(text: string, index: number): Node { - return new Component(this, (index + 1).toString(), text); } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 9d54c73..188f6a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,27 @@ import { Client } from './client.js' +import { Component } from './component.js' +import { Delimiters } from './decorators/enum/delimiters.js' +import { Node } from './decorators/interfaces/node.js' +import { EmptyNode } from './emptyNode.js' +import { Field } from './field.js' +import { FieldRepetition } from './fieldRepetition.js' import { Listener } from './listener.js' import { Message } from './message.js' +import { NodeBase } from './nodeBase.js' import { Parser, ParserPlan } from './parser.js' +import { Segment } from './segment.js' +import { HL7_2_7 } from './specification/2.7.js' +import { HL7_SPEC, HL7_SPEC_BASE } from './specification/specification.js' +import { SubComponent } from './subComponent.js' export default Client -export { Client, Listener, Parser, ParserPlan, Message } +export { Client, Listener, Parser, ParserPlan, Message, Delimiters, Segment, Component, SubComponent, Field, FieldRepetition, EmptyNode, NodeBase, Node } /** HL7 Specs **/ -export type { HL7_2_7_MSH, HL7_2_7 } from './specification/2.7.js' +export type { MSH } from './specification/specification.js' +export type { HL7_MSH_MESSAGE_TYPE } from './specification/generic.js' +export type { HL7_2_7_MSH } from './specification/2.7.js' +export { HL7_SPEC, HL7_SPEC_BASE, HL7_2_7 } export type { ClientOptions, ClientListenerOptions, ClientBuilderOptions, ClientBuilderBatchOptions, ClientBuilderFileOptions, ParserProcessRawData} from './normalize.js' export type { HL7Error, HL7FatalError, HL7ParserError } from './exception.js'