-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experiential): fully typescript checked x2
#4 [ci skip]
- Loading branch information
Showing
4 changed files
with
109 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<string>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(<string>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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |