-
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): contains typescript specs for MSH
#4 first draft of how MSH typescript checking would work. [ci skip]
- Loading branch information
Showing
17 changed files
with
379 additions
and
298 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
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 |
---|---|---|
|
@@ -26,5 +26,4 @@ export class Client extends EventEmitter { | |
sendMessage (): void { | ||
/* noop */ | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ export enum Delimiters { | |
Repetition, | ||
Escape, | ||
SubComponent | ||
} | ||
} |
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,14 +1,11 @@ | ||
import {Delimiters} from "./delimiters"; | ||
import {Node} from "./node"; | ||
import {ValueNode} from "./valueNode"; | ||
import { Delimiters } from './delimiters' | ||
import { Node } from './node' | ||
import { ValueNode } from './valueNode' | ||
|
||
export class Field extends ValueNode { | ||
|
||
constructor(parent: Node, key: string, text: string) { | ||
super(parent, key, text, Delimiters.Field); | ||
constructor (parent: Node, key: string, text: string) { | ||
super(parent, key, text, Delimiters.Field) | ||
|
||
console.log(parent, key, 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,9 +1,15 @@ | ||
import { Client } from './client.js' | ||
import { Listener } from './listener.js' | ||
import { Message } from './message.js' | ||
import { Node } from './node.js' | ||
import { Parser, ParserPlan } from './parser.js' | ||
/** HL7 Specs **/ | ||
|
||
|
||
export default Client | ||
export { Client, Listener, Parser, ParserPlan} | ||
export { Client, Listener, Parser, ParserPlan, Message, Node } | ||
|
||
export type { HL7_2_7_MSH, HL7_2_7} from './specification/2.7.js' | ||
|
||
export type { ClientOptions, ClientListenerOptions, ParserProcessRawData } from './normalize.js' | ||
export type { HL7Error, HL7FatalError, HL7ParserError } from './exception.js' |
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,64 +1,83 @@ | ||
import {Delimiters} from "./delimiters"; | ||
import {Node} from "./node"; | ||
import {ClientBuilderOptions, normalizedClientBuilderOptions} from "./normalize"; | ||
import {Segment} from "./segment"; | ||
import {createDateTime} from "./utils"; | ||
|
||
import { Delimiters } from './delimiters' | ||
import { Node } from './node' | ||
import { ClientBuilderOptions, normalizedClientBuilderOptions } from './normalize' | ||
import { Segment } from './segment' | ||
import { createDateTime } from './utils' | ||
|
||
export class Message extends Node { | ||
|
||
private _opt: ReturnType<typeof normalizedClientBuilderOptions>; | ||
private readonly _delimiters: string; | ||
private readonly _opt: ReturnType<typeof normalizedClientBuilderOptions> | ||
private _delimiters: string | ||
|
||
/** | ||
* @param text If not provided, it will be MSH plus the default encoding characters. | ||
* @param text If not provided you have to build a MSH header using (@see createHeader) | ||
* @param props Override default encoding characters. (@default |^~\\&) | ||
* @example | ||
* If you are processing a full message, do this: | ||
* | ||
* const message = new Message("The HL7 Message Here") | ||
* ... output cut ... | ||
* | ||
* If you are building out a message, do this: | ||
* | ||
* const message = new Message(); | ||
* await message.createHeader<HL7_2_7_MSH>() ({ ... required parameters ... }) | ||
* ... add additional segments, etc. Check out Unit Tests for complete examples ... | ||
* | ||
* which will generate the properly formatted MSH header for your HL7 Method. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
constructor(text: string = "", props: ClientBuilderOptions = normalizedClientBuilderOptions()) { | ||
super( null,text, Delimiters.Segment) | ||
constructor (text: string = '', props: ClientBuilderOptions = normalizedClientBuilderOptions()) { | ||
super(null, text, Delimiters.Segment) | ||
|
||
this._opt = normalizedClientBuilderOptions(props) | ||
this._delimiters = `${this._opt.newLine}${this._opt.separatorField}${this._opt.separatorRepetition}${this._opt.separatorEscape}${this._opt.separatorSubComponent}` | ||
|
||
if (!text) { | ||
this.initialBuild() | ||
} | ||
|
||
} | ||
|
||
addSegment(path: string): Segment { | ||
if (!path) { | ||
throw new Error("Missing segment path."); | ||
addSegment (path: string): Segment { | ||
if (typeof path === 'undefined') { | ||
throw new Error('Missing segment path.') | ||
} | ||
let preparedPath = this.preparePath(path); | ||
if (preparedPath.length != 1) { | ||
throw new Error("Invalid segment path '" + path + "'."); | ||
const preparedPath = this.preparePath(path) | ||
if (preparedPath.length !== 1) { | ||
throw new Error("Invalid segment path '" + path + "'.") | ||
} | ||
return <Segment>this.addChild(preparedPath[0]); | ||
return this.addChild(preparedPath[0]) as Segment | ||
} | ||
|
||
initialBuild() { | ||
async createHeader<T>(specification: T): Promise<void> { | ||
try { | ||
const specs = await this._opt.specification.checkMSH(specification) | ||
|
||
if (typeof specs.msh_1 !== 'undefined') { | ||
this._opt.separatorField = specs.msh_1 | ||
} | ||
|
||
let segment = this.addSegment("MSH"); | ||
segment.set('MSH.1', this._opt.separatorField ) | ||
segment.set('MSH.2', `${this._opt.separatorRepetition}${this._opt.separatorEscape}${this._opt.separatorSubComponent}` ) | ||
segment.set('MSH.7', createDateTime()) | ||
if (typeof specs.msh_2 !== 'undefined') { | ||
this._delimiters = `${this._opt.newLine}${specs.msh_2}` | ||
} | ||
|
||
const segment = this.addSegment('MSH') | ||
segment.set('MSH.1', typeof specs.msh_1 !== 'undefined' ? specs.msh_1 : this._opt.separatorField) | ||
segment.set('MSH.2', typeof specs.msh_2 !== 'undefined' ? specs.msh_2 : `${typeof specs.msh_1 !== 'undefined' ? specs.msh_1 : this._opt.separatorField}${this._opt.separatorRepetition}${this._opt.separatorEscape}${this._opt.separatorSubComponent}`) | ||
segment.set('MSH.7', typeof specs.msh_7 !== 'undefined' ? specs.msh_7 : createDateTime()) | ||
segment.set('MSH.9').set('1', specs.msh_9_1).set('2', specs.msh_9_2).set('3', specs.msh_9_3) | ||
} catch (e: any) { | ||
throw new Error(e.message) | ||
} | ||
} | ||
|
||
protected pathCore(): string[] { | ||
protected pathCore (): string[] { | ||
// the message has an empty path | ||
return []; | ||
return [] | ||
} | ||
|
||
protected createChild(text: string, _index: number): Node { | ||
protected createChild (text: string, _index: number): Node { | ||
// make sure to remove any \n that might follow the \r | ||
return new Segment(this, text.trim()); | ||
return new Segment(this, text.trim()) | ||
} | ||
|
||
get delimiters(): string { | ||
return this._delimiters; | ||
get delimiters (): string { | ||
return this._delimiters | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.