@medplum/hl7 2.0.29 → 2.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/client.d.ts +3 -6
- package/dist/types/connection.d.ts +13 -0
- package/dist/types/events.d.ts +3 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/server.d.ts +4 -2
- package/package.json +4 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.create;var p=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var O=(n,t)=>{for(var e in t)p(n,e,{get:t[e],enumerable:!0})},g=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of L(t))!y.call(n,s)&&s!==e&&p(n,s,{get:()=>t[s],enumerable:!(o=M(t,s))||o.enumerable});return n};var w=(n,t,e)=>(e=n!=null?b(C(n)):{},g(t||!n||!n.__esModule?p(e,"default",{value:n,enumerable:!0}):e,n)),S=n=>g(p({},"__esModule",{value:!0}),n);var A={};O(A,{CR:()=>m,FS:()=>v,Hl7Base:()=>i,Hl7Client:()=>E,Hl7Connection:()=>c,Hl7ErrorEvent:()=>l,Hl7MessageEvent:()=>d,Hl7Server:()=>f,VT:()=>h});module.exports=S(A);var i=class extends EventTarget{addEventListener(t,e,o){super.addEventListener(t,e,o)}removeEventListener(t,e,o){super.removeEventListener(t,e,o)}};var H=require("net");var u=require("@medplum/core");var h=String.fromCharCode(11),v=String.fromCharCode(28),m=String.fromCharCode(13);var d=class extends Event{constructor(e,o){super("message");this.connection=e;this.message=o}},l=class extends Event{constructor(e){super("error");this.error=e}};var c=class extends i{constructor(e,o){super();this.socket=e;this.encoding=o;let s="";e.on("data",r=>{try{if(s+=r.toString(),s.endsWith(v+m)){let a=u.Hl7Message.parse(s.substring(1,s.length-2));this.dispatchEvent(new d(this,a)),s=""}}catch(a){this.dispatchEvent(new l(a))}}).setEncoding(o??"utf-8"),e.on("error",r=>{s="",this.dispatchEvent(new l(r))})}send(e){this.socket.write(h+e.toString()+v+m)}async sendAndWait(e){let o=new Promise(s=>{function r(a){a.target.removeEventListener("message",r),s(a.message)}this.addEventListener("message",r)});return this.send(e),o}close(){this.socket.end(),this.socket.destroy()}};var E=class extends i{constructor(e){super();this.options=e,this.host=this.options.host,this.port=this.options.port}connect(){return this.connection?Promise.resolve(this.connection):new Promise(e=>{let o=(0,H.connect)({host:this.host,port:this.port},()=>{this.connection=new c(o),e(this.connection)})})}async send(e){return(await this.connect()).send(e)}async sendAndWait(e){return(await this.connect()).sendAndWait(e)}close(){this.connection&&(this.connection.close(),delete this.connection)}};var x=w(require("net"));var f=class{constructor(t){this.handler=t}start(t,e){let o=x.default.createServer(s=>{let r=new c(s,e);this.handler(r)});o.listen(t),this.server=o}stop(){this.server&&(this.server.close(),this.server=void 0)}};0&&(module.exports={CR,FS,Hl7Base,Hl7Client,Hl7Connection,Hl7ErrorEvent,Hl7MessageEvent,Hl7Server,VT});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts", "../../src/base.ts", "../../src/client.ts", "../../src/constants.ts", "../../src/events.ts", "../../src/server.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './base';\nexport * from './client';\nexport * from './constants';\nexport * from './events';\nexport * from './server';\n", "import { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport interface Hl7EventMap {\n message: Hl7MessageEvent;\n error: Hl7ErrorEvent;\n}\n\nexport abstract class Hl7Base extends EventTarget {\n addEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.addEventListener(type, listener, options);\n }\n removeEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.removeEventListener(type, listener, options);\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport { connect
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,kBAAAC,EAAA,oBAAAC,EAAA,cAAAC,EAAA,OAAAC,IAAA,eAAAC,
|
|
6
|
-
"names": ["src_exports", "__export", "CR", "FS", "Hl7Base", "Hl7Client", "Hl7ErrorEvent", "Hl7MessageEvent", "Hl7Server", "VT", "__toCommonJS", "Hl7Base", "type", "listener", "options", "
|
|
3
|
+
"sources": ["../../src/index.ts", "../../src/base.ts", "../../src/client.ts", "../../src/connection.ts", "../../src/constants.ts", "../../src/events.ts", "../../src/server.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './base';\nexport * from './client';\nexport * from './connection';\nexport * from './constants';\nexport * from './events';\nexport * from './server';\n", "import { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport interface Hl7EventMap {\n message: Hl7MessageEvent;\n error: Hl7ErrorEvent;\n}\n\nexport abstract class Hl7Base extends EventTarget {\n addEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.addEventListener(type, listener, options);\n }\n removeEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.removeEventListener(type, listener, options);\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport { connect } from 'net';\nimport { Hl7Base } from './base';\nimport { Hl7Connection } from './connection';\n\nexport interface Hl7ClientOptions {\n host: string;\n port: number;\n}\n\nexport class Hl7Client extends Hl7Base {\n options: Hl7ClientOptions;\n host: string;\n port: number;\n connection?: Hl7Connection;\n\n constructor(options: Hl7ClientOptions) {\n super();\n this.options = options;\n this.host = this.options.host;\n this.port = this.options.port;\n }\n\n connect(): Promise<Hl7Connection> {\n if (this.connection) {\n return Promise.resolve(this.connection);\n }\n\n return new Promise((resolve) => {\n const socket = connect({ host: this.host, port: this.port }, () => {\n this.connection = new Hl7Connection(socket);\n resolve(this.connection);\n });\n });\n }\n\n async send(msg: Hl7Message): Promise<void> {\n return (await this.connect()).send(msg);\n }\n\n async sendAndWait(msg: Hl7Message): Promise<Hl7Message> {\n return (await this.connect()).sendAndWait(msg);\n }\n\n close(): void {\n if (this.connection) {\n this.connection.close();\n delete this.connection;\n }\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport net from 'net';\nimport { Hl7Base } from './base';\nimport { CR, FS, VT } from './constants';\nimport { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport class Hl7Connection extends Hl7Base {\n constructor(readonly socket: net.Socket, readonly encoding?: BufferEncoding) {\n super();\n\n let buffer = '';\n\n socket\n .on('data', (data) => {\n try {\n buffer += data.toString();\n if (buffer.endsWith(FS + CR)) {\n const message = Hl7Message.parse(buffer.substring(1, buffer.length - 2));\n this.dispatchEvent(new Hl7MessageEvent(this, message));\n buffer = '';\n }\n } catch (err) {\n this.dispatchEvent(new Hl7ErrorEvent(err as Error));\n }\n })\n .setEncoding(encoding ?? 'utf-8');\n\n socket.on('error', (err) => {\n buffer = '';\n this.dispatchEvent(new Hl7ErrorEvent(err));\n });\n }\n\n send(reply: Hl7Message): void {\n this.socket.write(VT + reply.toString() + FS + CR);\n }\n\n async sendAndWait(msg: Hl7Message): Promise<Hl7Message> {\n const promise = new Promise<Hl7Message>((resolve) => {\n function handler(event: Hl7MessageEvent): void {\n (event.target as Hl7Connection).removeEventListener('message', handler);\n resolve(event.message);\n }\n this.addEventListener('message', handler);\n });\n\n this.send(msg);\n return promise;\n }\n\n close(): void {\n this.socket.end();\n this.socket.destroy();\n }\n}\n", "export const VT = String.fromCharCode(0x0b);\nexport const FS = String.fromCharCode(0x1c);\nexport const CR = String.fromCharCode(0x0d);\n", "import { Hl7Message } from '@medplum/core';\nimport { Hl7Connection } from './connection';\n\nexport class Hl7MessageEvent extends Event {\n constructor(public readonly connection: Hl7Connection, public readonly message: Hl7Message) {\n super('message');\n }\n}\n\nexport class Hl7ErrorEvent extends Event {\n constructor(public readonly error: Error) {\n super('error');\n }\n}\n", "import net from 'net';\nimport { Hl7Connection } from './connection';\n\nexport class Hl7Server {\n server?: net.Server;\n\n constructor(public readonly handler: (connection: Hl7Connection) => void) {}\n\n start(port: number, encoding?: BufferEncoding): void {\n const server = net.createServer((socket) => {\n const connection = new Hl7Connection(socket, encoding);\n this.handler(connection);\n });\n\n server.listen(port);\n this.server = server;\n }\n\n stop(): void {\n if (this.server) {\n this.server.close();\n this.server = undefined;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,QAAAE,EAAA,OAAAC,EAAA,YAAAC,EAAA,cAAAC,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,oBAAAC,EAAA,cAAAC,EAAA,OAAAC,IAAA,eAAAC,EAAAX,GCOO,IAAeY,EAAf,cAA+B,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EAAO,OAAOF,CAAI,EAClB,KAAK,OAASE,CAChB,CAEA,MAAa,CACP,KAAK,SACP,KAAK,OAAO,MAAM,EAClB,KAAK,OAAS,OAElB,CACF",
|
|
6
|
+
"names": ["src_exports", "__export", "CR", "FS", "Hl7Base", "Hl7Client", "Hl7Connection", "Hl7ErrorEvent", "Hl7MessageEvent", "Hl7Server", "VT", "__toCommonJS", "Hl7Base", "type", "listener", "options", "import_net", "import_core", "VT", "FS", "CR", "Hl7MessageEvent", "connection", "message", "Hl7ErrorEvent", "error", "Hl7Connection", "Hl7Base", "socket", "encoding", "buffer", "data", "FS", "CR", "message", "Hl7MessageEvent", "err", "Hl7ErrorEvent", "reply", "VT", "msg", "promise", "resolve", "handler", "event", "Hl7Client", "Hl7Base", "options", "resolve", "socket", "Hl7Connection", "msg", "import_net", "Hl7Server", "handler", "port", "encoding", "server", "net", "socket", "connection", "Hl7Connection"]
|
|
7
7
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=class extends EventTarget{addEventListener(n,e,t){super.addEventListener(n,e,t)}removeEventListener(n,e,t){super.removeEventListener(n,e,t)}};import{connect as g}from"net";import{Hl7Message as f}from"@medplum/core";var m=String.fromCharCode(11),p=String.fromCharCode(28),v=String.fromCharCode(13);var d=class extends Event{constructor(e,t){super("message");this.connection=e;this.message=t}},l=class extends Event{constructor(e){super("error");this.error=e}};var c=class extends i{constructor(e,t){super();this.socket=e;this.encoding=t;let o="";e.on("data",s=>{try{if(o+=s.toString(),o.endsWith(p+v)){let r=f.parse(o.substring(1,o.length-2));this.dispatchEvent(new d(this,r)),o=""}}catch(r){this.dispatchEvent(new l(r))}}).setEncoding(t??"utf-8"),e.on("error",s=>{o="",this.dispatchEvent(new l(s))})}send(e){this.socket.write(m+e.toString()+p+v)}async sendAndWait(e){let t=new Promise(o=>{function s(r){r.target.removeEventListener("message",s),o(r.message)}this.addEventListener("message",s)});return this.send(e),t}close(){this.socket.end(),this.socket.destroy()}};var h=class extends i{constructor(e){super();this.options=e,this.host=this.options.host,this.port=this.options.port}connect(){return this.connection?Promise.resolve(this.connection):new Promise(e=>{let t=g({host:this.host,port:this.port},()=>{this.connection=new c(t),e(this.connection)})})}async send(e){return(await this.connect()).send(e)}async sendAndWait(e){return(await this.connect()).sendAndWait(e)}close(){this.connection&&(this.connection.close(),delete this.connection)}};import u from"net";var E=class{constructor(n){this.handler=n}start(n,e){let t=u.createServer(o=>{let s=new c(o,e);this.handler(s)});t.listen(n),this.server=t}stop(){this.server&&(this.server.close(),this.server=void 0)}};export{v as CR,p as FS,i as Hl7Base,h as Hl7Client,c as Hl7Connection,l as Hl7ErrorEvent,d as Hl7MessageEvent,E as Hl7Server,m as VT};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/base.ts", "../../src/client.ts", "../../src/constants.ts", "../../src/events.ts", "../../src/server.ts"],
|
|
4
|
-
"sourcesContent": ["import { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport interface Hl7EventMap {\n message: Hl7MessageEvent;\n error: Hl7ErrorEvent;\n}\n\nexport abstract class Hl7Base extends EventTarget {\n addEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.addEventListener(type, listener, options);\n }\n removeEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.removeEventListener(type, listener, options);\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport { connect
|
|
5
|
-
"mappings": "AAOO,IAAeA,EAAf,cAA+B,WAAY,CAOhD,iBACEC,EACAC,EACAC,EACM,CACN,MAAM,iBAAiBF,EAAMC,EAAUC,CAAO,CAChD,CAOA,oBACEF,EACAC,EACAC,EACM,CACN,MAAM,oBAAoBF,EAAMC,EAAUC,CAAO,CACnD,CACF,
|
|
6
|
-
"names": ["Hl7Base", "type", "listener", "options", "
|
|
3
|
+
"sources": ["../../src/base.ts", "../../src/client.ts", "../../src/connection.ts", "../../src/constants.ts", "../../src/events.ts", "../../src/server.ts"],
|
|
4
|
+
"sourcesContent": ["import { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport interface Hl7EventMap {\n message: Hl7MessageEvent;\n error: Hl7ErrorEvent;\n}\n\nexport abstract class Hl7Base extends EventTarget {\n addEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.addEventListener(type, listener, options);\n }\n removeEventListener<K extends keyof Hl7EventMap>(\n type: K,\n listener: ((event: Hl7EventMap[K]) => void) | EventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void;\n\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject | null,\n options?: boolean | AddEventListenerOptions\n ): void {\n super.removeEventListener(type, listener, options);\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport { connect } from 'net';\nimport { Hl7Base } from './base';\nimport { Hl7Connection } from './connection';\n\nexport interface Hl7ClientOptions {\n host: string;\n port: number;\n}\n\nexport class Hl7Client extends Hl7Base {\n options: Hl7ClientOptions;\n host: string;\n port: number;\n connection?: Hl7Connection;\n\n constructor(options: Hl7ClientOptions) {\n super();\n this.options = options;\n this.host = this.options.host;\n this.port = this.options.port;\n }\n\n connect(): Promise<Hl7Connection> {\n if (this.connection) {\n return Promise.resolve(this.connection);\n }\n\n return new Promise((resolve) => {\n const socket = connect({ host: this.host, port: this.port }, () => {\n this.connection = new Hl7Connection(socket);\n resolve(this.connection);\n });\n });\n }\n\n async send(msg: Hl7Message): Promise<void> {\n return (await this.connect()).send(msg);\n }\n\n async sendAndWait(msg: Hl7Message): Promise<Hl7Message> {\n return (await this.connect()).sendAndWait(msg);\n }\n\n close(): void {\n if (this.connection) {\n this.connection.close();\n delete this.connection;\n }\n }\n}\n", "import { Hl7Message } from '@medplum/core';\nimport net from 'net';\nimport { Hl7Base } from './base';\nimport { CR, FS, VT } from './constants';\nimport { Hl7ErrorEvent, Hl7MessageEvent } from './events';\n\nexport class Hl7Connection extends Hl7Base {\n constructor(readonly socket: net.Socket, readonly encoding?: BufferEncoding) {\n super();\n\n let buffer = '';\n\n socket\n .on('data', (data) => {\n try {\n buffer += data.toString();\n if (buffer.endsWith(FS + CR)) {\n const message = Hl7Message.parse(buffer.substring(1, buffer.length - 2));\n this.dispatchEvent(new Hl7MessageEvent(this, message));\n buffer = '';\n }\n } catch (err) {\n this.dispatchEvent(new Hl7ErrorEvent(err as Error));\n }\n })\n .setEncoding(encoding ?? 'utf-8');\n\n socket.on('error', (err) => {\n buffer = '';\n this.dispatchEvent(new Hl7ErrorEvent(err));\n });\n }\n\n send(reply: Hl7Message): void {\n this.socket.write(VT + reply.toString() + FS + CR);\n }\n\n async sendAndWait(msg: Hl7Message): Promise<Hl7Message> {\n const promise = new Promise<Hl7Message>((resolve) => {\n function handler(event: Hl7MessageEvent): void {\n (event.target as Hl7Connection).removeEventListener('message', handler);\n resolve(event.message);\n }\n this.addEventListener('message', handler);\n });\n\n this.send(msg);\n return promise;\n }\n\n close(): void {\n this.socket.end();\n this.socket.destroy();\n }\n}\n", "export const VT = String.fromCharCode(0x0b);\nexport const FS = String.fromCharCode(0x1c);\nexport const CR = String.fromCharCode(0x0d);\n", "import { Hl7Message } from '@medplum/core';\nimport { Hl7Connection } from './connection';\n\nexport class Hl7MessageEvent extends Event {\n constructor(public readonly connection: Hl7Connection, public readonly message: Hl7Message) {\n super('message');\n }\n}\n\nexport class Hl7ErrorEvent extends Event {\n constructor(public readonly error: Error) {\n super('error');\n }\n}\n", "import net from 'net';\nimport { Hl7Connection } from './connection';\n\nexport class Hl7Server {\n server?: net.Server;\n\n constructor(public readonly handler: (connection: Hl7Connection) => void) {}\n\n start(port: number, encoding?: BufferEncoding): void {\n const server = net.createServer((socket) => {\n const connection = new Hl7Connection(socket, encoding);\n this.handler(connection);\n });\n\n server.listen(port);\n this.server = server;\n }\n\n stop(): void {\n if (this.server) {\n this.server.close();\n this.server = undefined;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAOO,IAAeA,EAAf,cAA+B,WAAY,CAOhD,iBACEC,EACAC,EACAC,EACM,CACN,MAAM,iBAAiBF,EAAMC,EAAUC,CAAO,CAChD,CAOA,oBACEF,EACAC,EACAC,EACM,CACN,MAAM,oBAAoBF,EAAMC,EAAUC,CAAO,CACnD,CACF,ECjCA,OAAS,WAAAC,MAAe,MCDxB,OAAS,cAAAC,MAAkB,gBCApB,IAAMC,EAAK,OAAO,aAAa,EAAI,EAC7BC,EAAK,OAAO,aAAa,EAAI,EAC7BC,EAAK,OAAO,aAAa,EAAI,ECCnC,IAAMC,EAAN,cAA8B,KAAM,CACzC,YAA4BC,EAA2CC,EAAqB,CAC1F,MAAM,SAAS,EADW,gBAAAD,EAA2C,aAAAC,CAEvE,CACF,EAEaC,EAAN,cAA4B,KAAM,CACvC,YAA4BC,EAAc,CACxC,MAAM,OAAO,EADa,WAAAA,CAE5B,CACF,EFPO,IAAMC,EAAN,cAA4BC,CAAQ,CACzC,YAAqBC,EAA6BC,EAA2B,CAC3E,MAAM,EADa,YAAAD,EAA6B,cAAAC,EAGhD,IAAIC,EAAS,GAEbF,EACG,GAAG,OAASG,GAAS,CACpB,GAAI,CAEF,GADAD,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AAC,CACH,CAAC,CACH,CAEA,MAAM,KAAKI,EAAgC,CACzC,OAAQ,MAAM,KAAK,QAAQ,GAAG,KAAKA,CAAG,CACxC,CAEA,MAAM,YAAYA,EAAsC,CACtD,OAAQ,MAAM,KAAK,QAAQ,GAAG,YAAYA,CAAG,CAC/C,CAEA,OAAc,CACR,KAAK,aACP,KAAK,WAAW,MAAM,EACtB,OAAO,KAAK,WAEhB,CACF,EIlDA,OAAOC,MAAS,MAGT,IAAMC,EAAN,KAAgB,CAGrB,YAA4BC,EAA8C,CAA9C,aAAAA,CAA+C,CAE3E,MAAMC,EAAcC,EAAiC,CACnD,IAAMC,EAASC,EAAI,aAAcC,GAAW,CAC1C,IAAMC,EAAa,IAAIC,EAAcF,EAAQH,CAAQ,EACrD,KAAK,QAAQI,CAAU,CACzB,CAAC,EAEDH,EAAO,OAAOF,CAAI,EAClB,KAAK,OAASE,CAChB,CAEA,MAAa,CACP,KAAK,SACP,KAAK,OAAO,MAAM,EAClB,KAAK,OAAS,OAElB,CACF",
|
|
6
|
+
"names": ["Hl7Base", "type", "listener", "options", "connect", "Hl7Message", "VT", "FS", "CR", "Hl7MessageEvent", "connection", "message", "Hl7ErrorEvent", "error", "Hl7Connection", "Hl7Base", "socket", "encoding", "buffer", "data", "FS", "CR", "message", "Hl7Message", "Hl7MessageEvent", "err", "Hl7ErrorEvent", "reply", "VT", "msg", "promise", "resolve", "handler", "event", "Hl7Client", "Hl7Base", "options", "resolve", "socket", "connect", "Hl7Connection", "msg", "net", "Hl7Server", "handler", "port", "encoding", "server", "net", "socket", "connection", "Hl7Connection"]
|
|
7
7
|
}
|
package/dist/types/client.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Hl7Message } from '@medplum/core';
|
|
3
|
-
import { Socket } from 'net';
|
|
4
2
|
import { Hl7Base } from './base';
|
|
3
|
+
import { Hl7Connection } from './connection';
|
|
5
4
|
export interface Hl7ClientOptions {
|
|
6
5
|
host: string;
|
|
7
6
|
port: number;
|
|
@@ -10,11 +9,9 @@ export declare class Hl7Client extends Hl7Base {
|
|
|
10
9
|
options: Hl7ClientOptions;
|
|
11
10
|
host: string;
|
|
12
11
|
port: number;
|
|
13
|
-
|
|
14
|
-
buffer: string;
|
|
15
|
-
awaitingResponse: boolean;
|
|
12
|
+
connection?: Hl7Connection;
|
|
16
13
|
constructor(options: Hl7ClientOptions);
|
|
17
|
-
connect(): Promise<
|
|
14
|
+
connect(): Promise<Hl7Connection>;
|
|
18
15
|
send(msg: Hl7Message): Promise<void>;
|
|
19
16
|
sendAndWait(msg: Hl7Message): Promise<Hl7Message>;
|
|
20
17
|
close(): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Hl7Message } from '@medplum/core';
|
|
4
|
+
import net from 'net';
|
|
5
|
+
import { Hl7Base } from './base';
|
|
6
|
+
export declare class Hl7Connection extends Hl7Base {
|
|
7
|
+
readonly socket: net.Socket;
|
|
8
|
+
readonly encoding?: BufferEncoding | undefined;
|
|
9
|
+
constructor(socket: net.Socket, encoding?: BufferEncoding | undefined);
|
|
10
|
+
send(reply: Hl7Message): void;
|
|
11
|
+
sendAndWait(msg: Hl7Message): Promise<Hl7Message>;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
package/dist/types/events.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Hl7Message } from '@medplum/core';
|
|
3
|
-
import {
|
|
2
|
+
import { Hl7Connection } from './connection';
|
|
4
3
|
export declare class Hl7MessageEvent extends Event {
|
|
5
|
-
readonly
|
|
4
|
+
readonly connection: Hl7Connection;
|
|
6
5
|
readonly message: Hl7Message;
|
|
7
|
-
constructor(
|
|
8
|
-
send(reply: Hl7Message): void;
|
|
6
|
+
constructor(connection: Hl7Connection, message: Hl7Message);
|
|
9
7
|
}
|
|
10
8
|
export declare class Hl7ErrorEvent extends Event {
|
|
11
9
|
readonly error: Error;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/server.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import net from 'net';
|
|
4
|
-
import {
|
|
5
|
-
export declare class Hl7Server
|
|
4
|
+
import { Hl7Connection } from './connection';
|
|
5
|
+
export declare class Hl7Server {
|
|
6
|
+
readonly handler: (connection: Hl7Connection) => void;
|
|
6
7
|
server?: net.Server;
|
|
8
|
+
constructor(handler: (connection: Hl7Connection) => void);
|
|
7
9
|
start(port: number, encoding?: BufferEncoding): void;
|
|
8
10
|
stop(): void;
|
|
9
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/hl7",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.30",
|
|
4
4
|
"description": "Medplum HL7 Utilities",
|
|
5
5
|
"author": "Medplum <hello@medplum.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"test": "jest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@medplum/core": "*"
|
|
22
|
+
"@medplum/core": "*"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
23
25
|
"@medplum/fhirtypes": "*"
|
|
24
26
|
},
|
|
25
27
|
"main": "dist/cjs/index.cjs",
|