@outburn/format-converter 1.0.3 โ 1.0.5
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/LICENSE +20 -20
- package/README.md +355 -170
- package/dist/index.cjs +85 -0
- package/dist/index.d.ts +33 -1
- package/dist/index.mjs +85 -1
- package/package.json +77 -66
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -165
- package/dist/index.mjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Outburn
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Outburn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,171 +1,356 @@
|
|
|
1
|
-
# Format Converter
|
|
2
|
-
|
|
3
|
-
A TypeScript library for converting
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- ๐ **Multi-format support**: Convert
|
|
8
|
-
- ๐ฅ **Healthcare focused**: Specialized HL7 v2 message parsing and conversion
|
|
9
|
-
- ๐ **Format detection**: Automatic content type detection
|
|
10
|
-
- ๐ก๏ธ **Type-safe**: Written in TypeScript with full type definitions
|
|
11
|
-
- ๐งช **Well-tested**: Comprehensive test suite
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @outburn/format-converter
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
###
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import { FormatConverter } from '@outburn/format-converter';
|
|
53
|
-
|
|
54
|
-
const converter = new FormatConverter();
|
|
55
|
-
|
|
56
|
-
// Convert
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
1
|
+
# Format Converter
|
|
2
|
+
|
|
3
|
+
A TypeScript library for converting various data formats (CSV, XML, HL7 v2) to JSON.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Multi-format support**: Convert CSV, XML, HL7 v2 to JSON
|
|
8
|
+
- ๐ฅ **Healthcare focused**: Specialized HL7 v2 message parsing and conversion to JSON
|
|
9
|
+
- ๐ **Format detection**: Automatic content type detection
|
|
10
|
+
- ๐ก๏ธ **Type-safe**: Written in TypeScript with full type definitions
|
|
11
|
+
- ๐งช **Well-tested**: Comprehensive test suite
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @outburn/format-converter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Browser Compatibility
|
|
20
|
+
|
|
21
|
+
This library provides different builds for different environments:
|
|
22
|
+
|
|
23
|
+
### Node.js (Full functionality)
|
|
24
|
+
```typescript
|
|
25
|
+
import { FormatConverter, TypeConverter, FormatDetector } from '@outburn/format-converter';
|
|
26
|
+
// All features available including HL7 v2 conversion
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Browser (Limited functionality)
|
|
30
|
+
```html
|
|
31
|
+
<script src="node_modules/@outburn/format-converter/dist/browser.js"></script>
|
|
32
|
+
<script>
|
|
33
|
+
const { TypeConverter, FormatDetector } = FormatUtils;
|
|
34
|
+
// FormatConverter is not available in browser due to HL7.js dependency
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Browser limitations:**
|
|
39
|
+
- โ `FormatConverter` is not available (requires HL7.js which is not browser-compatible)
|
|
40
|
+
- โ HL7 v2 parsing and conversion
|
|
41
|
+
- โ
`TypeConverter` for type detection and conversion
|
|
42
|
+
- โ
`FormatDetector` for format detection (JSON, XML, CSV, HL7)
|
|
43
|
+
- โ
All type definitions and enums
|
|
44
|
+
|
|
45
|
+
For full functionality including HL7 processing, use the Node.js version.
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Basic Usage
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { FormatConverter } from '@outburn/format-converter';
|
|
53
|
+
|
|
54
|
+
const converter = new FormatConverter();
|
|
55
|
+
|
|
56
|
+
// Convert CSV to JSON
|
|
57
|
+
const csvData = `name,age,city
|
|
58
|
+
John,25,New York
|
|
59
|
+
Jane,30,Los Angeles`;
|
|
60
|
+
|
|
61
|
+
const jsonResult = await converter.toJson(csvData, 'text/csv');
|
|
62
|
+
console.log(jsonResult);
|
|
63
|
+
|
|
64
|
+
// Convert XML to JSON
|
|
65
|
+
const xmlData = `<?xml version="1.0"?>
|
|
66
|
+
<root>
|
|
67
|
+
<person>
|
|
68
|
+
<name>John</name>
|
|
69
|
+
<age>25</age>
|
|
70
|
+
</person>
|
|
71
|
+
</root>`;
|
|
72
|
+
|
|
73
|
+
const xmlToJson = await converter.toJson(xmlData, 'application/xml');
|
|
74
|
+
console.log(xmlToJson);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### HL7 v2 Message Conversion
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { FormatConverter } from '@outburn/format-converter';
|
|
81
|
+
|
|
82
|
+
const converter = new FormatConverter();
|
|
83
|
+
|
|
84
|
+
// Convert HL7 v2 message to JSON
|
|
85
|
+
const hl7Message = `MSH|^~\\&|GHH LAB|ELAB-3|GHH OE|BLDG4|200202150930||ORU^R01|CNTRL-3456|P|2.4
|
|
86
|
+
PID|||PATID1234^5^M11^ADT1^MR^UNIVERSITY HOSPITAL~123456789^^^USSSA^SS||EVERYMAN^ADAM^A^III||19610615|M||C|1200 N ELM STREET^^GREENSBORO^NC^27401-1020|GL|(919)379-1212|(919)271-3434||S||PATID12345001^2^M10^ADT1^AN^A|123456789|9-87654^NC`;
|
|
87
|
+
|
|
88
|
+
const hl7ToJson = await converter.toJson(hl7Message, 'x-application/hl7-v2+er7');
|
|
89
|
+
console.log(hl7ToJson);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### With Logging
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { FormatConverter } from '@outburn/format-converter';
|
|
96
|
+
|
|
97
|
+
// Custom logger implementation
|
|
98
|
+
const logger = {
|
|
99
|
+
info: (message: string) => console.log(`[INFO] ${message}`),
|
|
100
|
+
warn: (message: string) => console.warn(`[WARN] ${message}`),
|
|
101
|
+
error: (message: string) => console.error(`[ERROR] ${message}`)
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const converter = new FormatConverter(logger);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Type Conversion Utilities
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { TypeConverter } from '@outburn/format-converter';
|
|
111
|
+
|
|
112
|
+
const typeConverter = new TypeConverter();
|
|
113
|
+
|
|
114
|
+
// Convert MIME type strings to ContentType enum
|
|
115
|
+
const contentType = typeConverter.stringToContentType('text/csv');
|
|
116
|
+
|
|
117
|
+
// Detect format from content
|
|
118
|
+
const detectedFormat = typeConverter.detectFormat(csvData);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Supported Formats
|
|
122
|
+
|
|
123
|
+
This library converts the following input formats to JSON:
|
|
124
|
+
|
|
125
|
+
| Input Format | Content Type | Output |
|
|
126
|
+
|--------------|--------------|--------|
|
|
127
|
+
| CSV | `text/csv` | JSON |
|
|
128
|
+
| XML | `application/xml` | JSON |
|
|
129
|
+
| HL7 v2 | `x-application/hl7-v2+er7` | JSON |
|
|
130
|
+
| JSON | `application/json` | JSON (passthrough) |
|
|
131
|
+
|
|
132
|
+
## API Reference
|
|
133
|
+
|
|
134
|
+
### FormatConverter
|
|
135
|
+
|
|
136
|
+
The main class for converting various formats to JSON.
|
|
137
|
+
|
|
138
|
+
#### Constructor
|
|
139
|
+
```typescript
|
|
140
|
+
new FormatConverter(logger?: ILogger)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Parameters:**
|
|
144
|
+
- `logger` (optional): Custom logger implementing the `ILogger` interface
|
|
145
|
+
|
|
146
|
+
#### Methods
|
|
147
|
+
|
|
148
|
+
##### `toJson(input: any, contentType?: ContentType | string): Promise<any>`
|
|
149
|
+
|
|
150
|
+
Converts input data to JSON format. This is the primary method for format conversion.
|
|
151
|
+
|
|
152
|
+
**Parameters:**
|
|
153
|
+
- `input`: The data to convert (string or object)
|
|
154
|
+
- `contentType` (optional): The MIME type or ContentType enum value of the input data. If not provided, defaults to `application/json`
|
|
155
|
+
|
|
156
|
+
**Returns:** Promise resolving to the converted JSON data
|
|
157
|
+
|
|
158
|
+
**Example:**
|
|
159
|
+
```typescript
|
|
160
|
+
const result = await converter.toJson(csvData, 'text/csv');
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
##### `csvToJson(input: string): Promise<any>`
|
|
164
|
+
|
|
165
|
+
Converts CSV data to JSON format.
|
|
166
|
+
|
|
167
|
+
**Parameters:**
|
|
168
|
+
- `input`: CSV string to convert
|
|
169
|
+
|
|
170
|
+
**Returns:** Promise resolving to the converted JSON data
|
|
171
|
+
|
|
172
|
+
##### `xmlToJson(input: string): Promise<any>`
|
|
173
|
+
|
|
174
|
+
Converts XML data to JSON format.
|
|
175
|
+
|
|
176
|
+
**Parameters:**
|
|
177
|
+
- `input`: XML string to convert
|
|
178
|
+
|
|
179
|
+
**Returns:** Promise resolving to the converted JSON data
|
|
180
|
+
|
|
181
|
+
##### `hl7v2ToJson(input: string): Promise<any>`
|
|
182
|
+
|
|
183
|
+
Converts HL7 v2 message to JSON format.
|
|
184
|
+
|
|
185
|
+
**Parameters:**
|
|
186
|
+
- `input`: HL7 v2 message string to convert
|
|
187
|
+
|
|
188
|
+
**Returns:** Promise resolving to the converted JSON data
|
|
189
|
+
|
|
190
|
+
### TypeConverter
|
|
191
|
+
|
|
192
|
+
Utility class for converting between different content type representations.
|
|
193
|
+
|
|
194
|
+
#### Methods
|
|
195
|
+
|
|
196
|
+
##### `stringToContentType(contentType: string): ContentType | null`
|
|
197
|
+
|
|
198
|
+
Converts a MIME type string to a ContentType enum value.
|
|
199
|
+
|
|
200
|
+
**Parameters:**
|
|
201
|
+
- `contentType`: MIME type string (e.g., 'text/csv', 'application/xml')
|
|
202
|
+
|
|
203
|
+
**Returns:** ContentType enum value or null if not found
|
|
204
|
+
|
|
205
|
+
**Example:**
|
|
206
|
+
```typescript
|
|
207
|
+
const contentType = typeConverter.stringToContentType('text/csv');
|
|
208
|
+
// Returns: ContentType.CSV
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
##### `stringToContentFormat(format: string): ContentFormat | null`
|
|
212
|
+
|
|
213
|
+
Converts a format string to a ContentFormat enum value.
|
|
214
|
+
|
|
215
|
+
**Parameters:**
|
|
216
|
+
- `format`: Format string (e.g., 'json', 'csv', 'xml', 'hl7')
|
|
217
|
+
|
|
218
|
+
**Returns:** ContentFormat enum value or null if not found
|
|
219
|
+
|
|
220
|
+
##### `stringToEditorLanguage(editorLanguage: string): EditorLanguage | null`
|
|
221
|
+
|
|
222
|
+
Converts a language string to an EditorLanguage enum value.
|
|
223
|
+
|
|
224
|
+
**Parameters:**
|
|
225
|
+
- `editorLanguage`: Editor language string (e.g., 'json', 'xml', 'plaintext')
|
|
226
|
+
|
|
227
|
+
**Returns:** EditorLanguage enum value or null if not found
|
|
228
|
+
|
|
229
|
+
##### `contentTypeToContentFormat(contentType: ContentType): ContentFormat`
|
|
230
|
+
|
|
231
|
+
Converts a ContentType enum to a ContentFormat enum.
|
|
232
|
+
|
|
233
|
+
**Parameters:**
|
|
234
|
+
- `contentType`: ContentType enum value
|
|
235
|
+
|
|
236
|
+
**Returns:** Corresponding ContentFormat enum value
|
|
237
|
+
|
|
238
|
+
##### `contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage`
|
|
239
|
+
|
|
240
|
+
Converts a ContentType enum to an EditorLanguage enum.
|
|
241
|
+
|
|
242
|
+
**Parameters:**
|
|
243
|
+
- `contentType`: ContentType enum value
|
|
244
|
+
|
|
245
|
+
**Returns:** Corresponding EditorLanguage enum value
|
|
246
|
+
|
|
247
|
+
##### `contentFormatToContentType(format: ContentFormat): ContentType | null`
|
|
248
|
+
|
|
249
|
+
Converts a ContentFormat enum to a ContentType enum.
|
|
250
|
+
|
|
251
|
+
**Parameters:**
|
|
252
|
+
- `format`: ContentFormat enum value
|
|
253
|
+
|
|
254
|
+
**Returns:** Corresponding ContentType enum value or null if not applicable
|
|
255
|
+
|
|
256
|
+
##### `contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage`
|
|
257
|
+
|
|
258
|
+
Converts a ContentFormat enum to an EditorLanguage enum.
|
|
259
|
+
|
|
260
|
+
**Parameters:**
|
|
261
|
+
- `format`: ContentFormat enum value
|
|
262
|
+
|
|
263
|
+
**Returns:** Corresponding EditorLanguage enum value
|
|
264
|
+
|
|
265
|
+
### FormatDetector
|
|
266
|
+
|
|
267
|
+
Utility class for automatically detecting content formats from input strings.
|
|
268
|
+
|
|
269
|
+
#### Methods
|
|
270
|
+
|
|
271
|
+
##### `detectContentType(input: string): ContentType | null`
|
|
272
|
+
|
|
273
|
+
Detects the content type of the input string and returns the corresponding ContentType enum.
|
|
274
|
+
|
|
275
|
+
**Parameters:**
|
|
276
|
+
- `input`: String content to analyze
|
|
277
|
+
|
|
278
|
+
**Returns:** ContentType enum value or null if format cannot be determined
|
|
279
|
+
|
|
280
|
+
**Example:**
|
|
281
|
+
```typescript
|
|
282
|
+
const detector = new FormatDetector();
|
|
283
|
+
const contentType = detector.detectContentType(csvData);
|
|
284
|
+
// Returns: ContentType.CSV
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
##### `detectFormat(input: string): ContentFormat`
|
|
288
|
+
|
|
289
|
+
Analyzes the input string and detects its format.
|
|
290
|
+
|
|
291
|
+
**Parameters:**
|
|
292
|
+
- `input`: String content to analyze
|
|
293
|
+
|
|
294
|
+
**Returns:** ContentFormat enum value (returns ContentFormat.UNKNOWN if format cannot be determined)
|
|
295
|
+
|
|
296
|
+
**Example:**
|
|
297
|
+
```typescript
|
|
298
|
+
const detector = new FormatDetector();
|
|
299
|
+
const format = detector.detectFormat(xmlData);
|
|
300
|
+
// Returns: ContentFormat.XML
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
##### `detectEditorLanguage(input: string): EditorLanguage`
|
|
304
|
+
|
|
305
|
+
Detects the appropriate editor language syntax highlighting for the input content.
|
|
306
|
+
|
|
307
|
+
**Parameters:**
|
|
308
|
+
- `input`: String content to analyze
|
|
309
|
+
|
|
310
|
+
**Returns:** EditorLanguage enum value
|
|
311
|
+
|
|
312
|
+
**Example:**
|
|
313
|
+
```typescript
|
|
314
|
+
const detector = new FormatDetector();
|
|
315
|
+
const language = detector.detectEditorLanguage(jsonData);
|
|
316
|
+
// Returns: EditorLanguage.JSON
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Development
|
|
320
|
+
|
|
321
|
+
### Building
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
npm run build
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Testing
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
npm test
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Linting
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
npm run lint
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Dependencies
|
|
340
|
+
|
|
341
|
+
- **csvtojson**: CSV parsing functionality
|
|
342
|
+
- **fast-xml-parser**: XML parsing and conversion
|
|
343
|
+
- **hl7-dictionary**: HL7 v2 message definitions
|
|
344
|
+
- **hl7js**: HL7 message parsing utilities
|
|
345
|
+
- **jsonata**: JSON transformation and querying
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
MIT
|
|
349
|
+
ยฉ Outburn Ltd. 2022โ2025. All Rights Reserved.
|
|
350
|
+
|
|
351
|
+
## Disclaimer
|
|
352
|
+
This project is part of the [FUME](https://github.com/Outburn-IL/fume-community) open-source initiative and intended for use in FHIR tooling and development environments.
|
|
353
|
+
|
|
354
|
+
## Support
|
|
355
|
+
|
|
171
356
|
For issues and questions, please use the [GitHub Issues](https://github.com/Outburn-IL/format-converter/issues) page.
|
package/dist/index.cjs
CHANGED
|
@@ -583,7 +583,92 @@ var FormatConverter = class _FormatConverter {
|
|
|
583
583
|
}
|
|
584
584
|
};
|
|
585
585
|
|
|
586
|
+
// src/FormatDetector.ts
|
|
587
|
+
var isPossiblyHL7 = (input) => typeof input === "string" && input.trimStart().startsWith("MSH|");
|
|
588
|
+
var isValidJson = (input) => {
|
|
589
|
+
try {
|
|
590
|
+
JSON.parse(input);
|
|
591
|
+
return true;
|
|
592
|
+
} catch (e) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var isJsonLikely = (input) => {
|
|
597
|
+
const inputWithoutStrings = input;
|
|
598
|
+
const jsonStats = {
|
|
599
|
+
curlyBraces: (inputWithoutStrings.match(/[{}]/g) || []).length,
|
|
600
|
+
colons: (inputWithoutStrings.match(/:/g) || []).length,
|
|
601
|
+
keyValueStructure: /{[^}]*:[^}]*}/.test(input)
|
|
602
|
+
// Key-value pattern
|
|
603
|
+
};
|
|
604
|
+
const hasIncompleteJsonPattern = /{[^}]*"[^"]*"\s*:\s*/.test(input);
|
|
605
|
+
const isJsonLikely2 = (jsonStats.curlyBraces >= 2 || jsonStats.curlyBraces >= 1 && hasIncompleteJsonPattern) && jsonStats.colons >= 1 && (jsonStats.keyValueStructure || /{.*:.*}/.test(input) || hasIncompleteJsonPattern);
|
|
606
|
+
return isJsonLikely2;
|
|
607
|
+
};
|
|
608
|
+
var isXmlLikely = (input) => {
|
|
609
|
+
const xmlStats = {
|
|
610
|
+
openingTags: (input.match(/<[^/!?][^>]*?>/g) || []).length,
|
|
611
|
+
closingTags: (input.match(/<\/[^>]+>/g) || []).length,
|
|
612
|
+
selfClosingTags: (input.match(/<[^>]+\/>/g) || []).length,
|
|
613
|
+
xmlNamespaces: (input.match(/xmlns(:[a-zA-Z0-9]+)?=/g) || []).length
|
|
614
|
+
};
|
|
615
|
+
const hasXmlHeader = /^<\?xml.*?\?>/.test(input);
|
|
616
|
+
const isXmlLikely2 = (hasXmlHeader || xmlStats.xmlNamespaces >= 1 || xmlStats.openingTags >= 1) && (xmlStats.openingTags === xmlStats.closingTags || xmlStats.selfClosingTags >= 1);
|
|
617
|
+
return isXmlLikely2;
|
|
618
|
+
};
|
|
619
|
+
var isCsvLikely = (input) => {
|
|
620
|
+
const lines = input.split(/\r?\n/);
|
|
621
|
+
const headerRow = lines[0];
|
|
622
|
+
const csvStats = {
|
|
623
|
+
rowCount: lines.length,
|
|
624
|
+
commaCounts: lines.map((line) => (line.match(/,/g) || []).length)
|
|
625
|
+
};
|
|
626
|
+
const headerStats = {
|
|
627
|
+
curlyBraces: (headerRow.match(/[{}]/g) || []).length,
|
|
628
|
+
squareBrackets: (headerRow.match(/[\[\]]/g) || []).length,
|
|
629
|
+
angularBrackets: (headerRow.match(/[<>]/g) || []).length,
|
|
630
|
+
colons: (headerRow.match(/:/g) || []).length
|
|
631
|
+
};
|
|
632
|
+
const isCsvLikely2 = (csvStats.rowCount > 1 || csvStats.commaCounts.some((count) => count > 0)) && headerStats.curlyBraces === 0 && headerStats.squareBrackets === 0 && headerStats.angularBrackets === 0 && headerStats.colons === 0;
|
|
633
|
+
return isCsvLikely2;
|
|
634
|
+
};
|
|
635
|
+
var FormatDetector = class _FormatDetector {
|
|
636
|
+
static {
|
|
637
|
+
this.typeConverter = new TypeConverter();
|
|
638
|
+
}
|
|
639
|
+
detectContentType(input) {
|
|
640
|
+
const format = this.detectFormat(input);
|
|
641
|
+
return _FormatDetector.typeConverter.contentFormatToContentType(format);
|
|
642
|
+
}
|
|
643
|
+
detectFormat(input) {
|
|
644
|
+
try {
|
|
645
|
+
const trimmedInput = input?.trim();
|
|
646
|
+
if (!trimmedInput) return "unknown" /* UNKNOWN */;
|
|
647
|
+
if (isValidJson(input)) return "json" /* JSON */;
|
|
648
|
+
if (isPossiblyHL7(input)) return "hl7" /* HL7 */;
|
|
649
|
+
if (isJsonLikely(input)) return "json" /* JSON */;
|
|
650
|
+
if (isXmlLikely(input)) return "xml" /* XML */;
|
|
651
|
+
if (isCsvLikely(input)) return "csv" /* CSV */;
|
|
652
|
+
return "unknown" /* UNKNOWN */;
|
|
653
|
+
} catch (e) {
|
|
654
|
+
return "unknown" /* UNKNOWN */;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
detectEditorLanguage(input) {
|
|
658
|
+
const format = this.detectFormat(input);
|
|
659
|
+
switch (format) {
|
|
660
|
+
case "json" /* JSON */:
|
|
661
|
+
return "json" /* JSON */;
|
|
662
|
+
case "xml" /* XML */:
|
|
663
|
+
return "xml" /* XML */;
|
|
664
|
+
default:
|
|
665
|
+
return "plaintext" /* PLAINTEXT */;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
|
|
586
670
|
exports.FormatConverter = FormatConverter;
|
|
671
|
+
exports.FormatDetector = FormatDetector;
|
|
587
672
|
exports.TypeConverter = TypeConverter;
|
|
588
673
|
//# sourceMappingURL=index.cjs.map
|
|
589
674
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,31 @@ declare const enum EditorLanguage {
|
|
|
52
52
|
PLAINTEXT = "plaintext"
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Interface for format detection operations, providing methods to analyze and identify
|
|
57
|
+
* various aspects of input data including content type, format, and appropriate editor language.
|
|
58
|
+
*/
|
|
59
|
+
interface IFormatDetector {
|
|
60
|
+
/**
|
|
61
|
+
* Detects the content type of the given input string.
|
|
62
|
+
* @param input Input string to analyze
|
|
63
|
+
* @returns Detected ContentType or null if undetectable
|
|
64
|
+
*/
|
|
65
|
+
detectContentType: (input: string) => ContentType | null;
|
|
66
|
+
/**
|
|
67
|
+
* Detects the content format of the given input string.
|
|
68
|
+
* @param input Input string to analyze
|
|
69
|
+
* @returns Detected ContentFormat
|
|
70
|
+
*/
|
|
71
|
+
detectFormat: (input: string) => ContentFormat;
|
|
72
|
+
/**
|
|
73
|
+
* Detects the appropriate editor language for the given input string.
|
|
74
|
+
* @param input Input string to analyze
|
|
75
|
+
* @returns Detected EditorLanguage
|
|
76
|
+
*/
|
|
77
|
+
detectEditorLanguage: (input: string) => EditorLanguage;
|
|
78
|
+
}
|
|
79
|
+
|
|
55
80
|
/**
|
|
56
81
|
* Interface for format conversion operations, providing methods to convert various data formats to JSON.
|
|
57
82
|
* Supports conversion from CSV, XML, and HL7 V2.x message formats.
|
|
@@ -162,4 +187,11 @@ declare class FormatConverter implements IFormatConverter {
|
|
|
162
187
|
hl7v2ToJson: (message: string) => Promise<any>;
|
|
163
188
|
}
|
|
164
189
|
|
|
165
|
-
|
|
190
|
+
declare class FormatDetector implements IFormatDetector {
|
|
191
|
+
private static readonly typeConverter;
|
|
192
|
+
detectContentType(input: string): ContentType | null;
|
|
193
|
+
detectFormat(input: string): ContentFormat;
|
|
194
|
+
detectEditorLanguage(input: string): EditorLanguage;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { FormatConverter, FormatDetector, TypeConverter };
|
package/dist/index.mjs
CHANGED
|
@@ -574,6 +574,90 @@ var FormatConverter = class _FormatConverter {
|
|
|
574
574
|
}
|
|
575
575
|
};
|
|
576
576
|
|
|
577
|
-
|
|
577
|
+
// src/FormatDetector.ts
|
|
578
|
+
var isPossiblyHL7 = (input) => typeof input === "string" && input.trimStart().startsWith("MSH|");
|
|
579
|
+
var isValidJson = (input) => {
|
|
580
|
+
try {
|
|
581
|
+
JSON.parse(input);
|
|
582
|
+
return true;
|
|
583
|
+
} catch (e) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var isJsonLikely = (input) => {
|
|
588
|
+
const inputWithoutStrings = input;
|
|
589
|
+
const jsonStats = {
|
|
590
|
+
curlyBraces: (inputWithoutStrings.match(/[{}]/g) || []).length,
|
|
591
|
+
colons: (inputWithoutStrings.match(/:/g) || []).length,
|
|
592
|
+
keyValueStructure: /{[^}]*:[^}]*}/.test(input)
|
|
593
|
+
// Key-value pattern
|
|
594
|
+
};
|
|
595
|
+
const hasIncompleteJsonPattern = /{[^}]*"[^"]*"\s*:\s*/.test(input);
|
|
596
|
+
const isJsonLikely2 = (jsonStats.curlyBraces >= 2 || jsonStats.curlyBraces >= 1 && hasIncompleteJsonPattern) && jsonStats.colons >= 1 && (jsonStats.keyValueStructure || /{.*:.*}/.test(input) || hasIncompleteJsonPattern);
|
|
597
|
+
return isJsonLikely2;
|
|
598
|
+
};
|
|
599
|
+
var isXmlLikely = (input) => {
|
|
600
|
+
const xmlStats = {
|
|
601
|
+
openingTags: (input.match(/<[^/!?][^>]*?>/g) || []).length,
|
|
602
|
+
closingTags: (input.match(/<\/[^>]+>/g) || []).length,
|
|
603
|
+
selfClosingTags: (input.match(/<[^>]+\/>/g) || []).length,
|
|
604
|
+
xmlNamespaces: (input.match(/xmlns(:[a-zA-Z0-9]+)?=/g) || []).length
|
|
605
|
+
};
|
|
606
|
+
const hasXmlHeader = /^<\?xml.*?\?>/.test(input);
|
|
607
|
+
const isXmlLikely2 = (hasXmlHeader || xmlStats.xmlNamespaces >= 1 || xmlStats.openingTags >= 1) && (xmlStats.openingTags === xmlStats.closingTags || xmlStats.selfClosingTags >= 1);
|
|
608
|
+
return isXmlLikely2;
|
|
609
|
+
};
|
|
610
|
+
var isCsvLikely = (input) => {
|
|
611
|
+
const lines = input.split(/\r?\n/);
|
|
612
|
+
const headerRow = lines[0];
|
|
613
|
+
const csvStats = {
|
|
614
|
+
rowCount: lines.length,
|
|
615
|
+
commaCounts: lines.map((line) => (line.match(/,/g) || []).length)
|
|
616
|
+
};
|
|
617
|
+
const headerStats = {
|
|
618
|
+
curlyBraces: (headerRow.match(/[{}]/g) || []).length,
|
|
619
|
+
squareBrackets: (headerRow.match(/[\[\]]/g) || []).length,
|
|
620
|
+
angularBrackets: (headerRow.match(/[<>]/g) || []).length,
|
|
621
|
+
colons: (headerRow.match(/:/g) || []).length
|
|
622
|
+
};
|
|
623
|
+
const isCsvLikely2 = (csvStats.rowCount > 1 || csvStats.commaCounts.some((count) => count > 0)) && headerStats.curlyBraces === 0 && headerStats.squareBrackets === 0 && headerStats.angularBrackets === 0 && headerStats.colons === 0;
|
|
624
|
+
return isCsvLikely2;
|
|
625
|
+
};
|
|
626
|
+
var FormatDetector = class _FormatDetector {
|
|
627
|
+
static {
|
|
628
|
+
this.typeConverter = new TypeConverter();
|
|
629
|
+
}
|
|
630
|
+
detectContentType(input) {
|
|
631
|
+
const format = this.detectFormat(input);
|
|
632
|
+
return _FormatDetector.typeConverter.contentFormatToContentType(format);
|
|
633
|
+
}
|
|
634
|
+
detectFormat(input) {
|
|
635
|
+
try {
|
|
636
|
+
const trimmedInput = input?.trim();
|
|
637
|
+
if (!trimmedInput) return "unknown" /* UNKNOWN */;
|
|
638
|
+
if (isValidJson(input)) return "json" /* JSON */;
|
|
639
|
+
if (isPossiblyHL7(input)) return "hl7" /* HL7 */;
|
|
640
|
+
if (isJsonLikely(input)) return "json" /* JSON */;
|
|
641
|
+
if (isXmlLikely(input)) return "xml" /* XML */;
|
|
642
|
+
if (isCsvLikely(input)) return "csv" /* CSV */;
|
|
643
|
+
return "unknown" /* UNKNOWN */;
|
|
644
|
+
} catch (e) {
|
|
645
|
+
return "unknown" /* UNKNOWN */;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
detectEditorLanguage(input) {
|
|
649
|
+
const format = this.detectFormat(input);
|
|
650
|
+
switch (format) {
|
|
651
|
+
case "json" /* JSON */:
|
|
652
|
+
return "json" /* JSON */;
|
|
653
|
+
case "xml" /* XML */:
|
|
654
|
+
return "xml" /* XML */;
|
|
655
|
+
default:
|
|
656
|
+
return "plaintext" /* PLAINTEXT */;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
export { FormatConverter, FormatDetector, TypeConverter };
|
|
578
662
|
//# sourceMappingURL=index.mjs.map
|
|
579
663
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,66 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@outburn/format-converter",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A TypeScript library for converting between various data formats including CSV, XML, HL7 v2, and JSON with specialized healthcare message parsing",
|
|
5
|
-
"main": "./dist/index.cjs",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"converter",
|
|
35
|
-
"data-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@outburn/format-converter",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "A TypeScript library for converting between various data formats including CSV, XML, HL7 v2, and JSON with specialized healthcare message parsing",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"browser": "./dist/browser.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./browser": "./dist/browser.js"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"lint": "eslint src",
|
|
21
|
+
"build": "npm run clean && tsup",
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"demo": "node scripts/browser-demo.mjs"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/**/*.cjs",
|
|
28
|
+
"dist/**/*.mjs",
|
|
29
|
+
"dist/**/*.d.ts",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"format-converter",
|
|
35
|
+
"data-conversion",
|
|
36
|
+
"csv",
|
|
37
|
+
"xml",
|
|
38
|
+
"json",
|
|
39
|
+
"hl7",
|
|
40
|
+
"hl7v2",
|
|
41
|
+
"hl7json",
|
|
42
|
+
"hl7toJson",
|
|
43
|
+
"healthcare",
|
|
44
|
+
"parser",
|
|
45
|
+
"typescript",
|
|
46
|
+
"converter",
|
|
47
|
+
"data-transformation",
|
|
48
|
+
"message-parsing",
|
|
49
|
+
"healthcare-integration",
|
|
50
|
+
"interoperability"
|
|
51
|
+
],
|
|
52
|
+
"author": "Outburn Ltd.",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"csvtojson": "^2.0.14",
|
|
56
|
+
"fast-xml-parser": "^4.5.3",
|
|
57
|
+
"hl7-dictionary": "^1.0.1",
|
|
58
|
+
"hl7js": "^0.0.6",
|
|
59
|
+
"jsonata": "^2.1.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/node": "^24.10.1",
|
|
63
|
+
"eslint": "^9.39.1",
|
|
64
|
+
"rimraf": "^6.1.2",
|
|
65
|
+
"tsup": "^8.5.1",
|
|
66
|
+
"tsx": "^4.21.0",
|
|
67
|
+
"typescript": "^5.9.3",
|
|
68
|
+
"typescript-eslint": "^8.48.1",
|
|
69
|
+
"vitest": "^4.0.15"
|
|
70
|
+
},
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "git+https://github.com/Outburn-IL/format-converter.git"
|
|
74
|
+
},
|
|
75
|
+
"bugs": "https://github.com/Outburn-IL/format-converter/issues",
|
|
76
|
+
"homepage": "https://github.com/Outburn-IL/format-converter#readme"
|
|
77
|
+
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TypeConverter.ts","../src/converters/csvToJson.ts","../src/converters/xmlToJson.ts","../src/converters/hl7v2/v2parse.ts","../src/converters/hl7v2/getV2DatatypeDef.ts","../src/converters/hl7v2/cache.ts","../src/converters/hl7v2/jsonataExpressions.ts","../src/converters/hl7v2/registerV2key.ts","../src/converters/hl7v2/stringFuncations.ts","../src/converters/hl7v2/v2normalizeKey.ts","../src/converters/hl7v2/v2json.ts","../src/FormatConverter.ts"],"names":["csvToJson","XMLParser","namespaceIndex","key","hl7js","HL7Dictionary","jsonata"],"mappings":";;;;;;;;;;;;;;;;AAEO,IAAM,aAAA,GAAN,MAAM,cAAA,CAAwC;AAAA,EACnD;AAAA,IAAA,IAAA,CAAe,6BAAA,GAAyE;AAAA,MACtF,CAAA,kBAAA,cAAiB,MAAA;AAAA,MACjB,CAAA,UAAA,aAAgB,KAAA;AAAA,MAChB,CAAA,iBAAA,aAAgB,KAAA;AAAA,MAChB,CAAA,0BAAA,eAAkB,KAAA;AAAA,KACpB;AAAA;AAAA,EAEA;AAAA,IAAA,IAAA,CAAe,6BAAA,GAAgF;AAAA,MAC7F,CAAA,MAAA,cAAmB,kBAAA;AAAA,MACnB,CAAA,KAAA,aAAkB,UAAA;AAAA,MAClB,CAAA,KAAA,aAAkB,iBAAA;AAAA,MAClB,CAAA,KAAA,aAAkB,0BAAA;AAAA,MAClB,2BAAyB;AAAA,KAC3B;AAAA;AAAA,EAEA;AAAA,IAAA,IAAA,CAAe,gCAAA,GAA+E;AAAA,MAC5F,CAAA,MAAA,cAAmB,MAAA;AAAA,MACnB,CAAA,KAAA,aAAkB,KAAA;A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K,oCAAoC,CAAA;AAAA,IACvD,CAAA,MAAO;AAEL,MAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,IAC3E;AAEA,IAAA,OAAO,UAAA;AAAA,EACT;AAAA,EAIA,UAAU,KAAA,EAA6B;AACrC,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EACxC;AAGF","file":"index.cjs","sourcesContent":["import { ContentFormat, ContentType, EditorLanguage, ITypeConverter } from './types';\r\n\r\nexport class TypeConverter implements ITypeConverter {\r\n private static contentTypeToContentFormatMap: { [key in ContentType]: ContentFormat } = {\r\n [ContentType.JSON]: ContentFormat.JSON,\r\n [ContentType.CSV]: ContentFormat.CSV,\r\n [ContentType.XML]: ContentFormat.XML,\r\n [ContentType.HL7V2]: ContentFormat.HL7\r\n };\r\n\r\n private static contentFormatToContentTypeMap: { [key in ContentFormat]: ContentType | null } = {\r\n [ContentFormat.JSON]: ContentType.JSON,\r\n [ContentFormat.CSV]: ContentType.CSV,\r\n [ContentFormat.XML]: ContentType.XML,\r\n [ContentFormat.HL7]: ContentType.HL7V2,\r\n [ContentFormat.UNKNOWN]: null\r\n };\r\n\r\n private static contentFormatToEditorLanguageMap: { [key in ContentFormat]: EditorLanguage } = {\r\n [ContentFormat.JSON]: EditorLanguage.JSON,\r\n [ContentFormat.XML]: EditorLanguage.XML,\r\n [ContentFormat.CSV]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.HL7]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.UNKNOWN]: EditorLanguage.PLAINTEXT\r\n };\r\n\r\n private static contentFormats: ContentFormat[] = [\r\n ContentFormat.JSON,\r\n ContentFormat.CSV,\r\n ContentFormat.XML,\r\n ContentFormat.HL7,\r\n ContentFormat.UNKNOWN\r\n ];\r\n\r\n private static contentTypes: ContentType[] = [\r\n ContentType.JSON,\r\n ContentType.CSV,\r\n ContentType.XML,\r\n ContentType.HL7V2\r\n ];\r\n\r\n private static editorLanguages: EditorLanguage[] = [\r\n EditorLanguage.JSON,\r\n EditorLanguage.XML,\r\n EditorLanguage.PLAINTEXT\r\n ];\r\n\r\n contentTypeToContentFormat(contentType: ContentType): ContentFormat {\r\n return TypeConverter.contentTypeToContentFormatMap[contentType];\r\n }\r\n\r\n contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage {\r\n const format = this.contentTypeToContentFormat(contentType);\r\n return this.contentFormatToEditorLanguage(format);\r\n }\r\n\r\n contentFormatToContentType(format: ContentFormat): ContentType | null {\r\n return TypeConverter.contentFormatToContentTypeMap[format] || null;\r\n }\r\n\r\n contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage {\r\n return TypeConverter.contentFormatToEditorLanguageMap[format];\r\n }\r\n\r\n stringToContentFormat(format: string): ContentFormat | null {\r\n const normalizedFormat = format.toLowerCase();\r\n return TypeConverter.contentFormats.find(value => value === normalizedFormat) || null;\r\n }\r\n\r\n stringToContentType(contentType: string): ContentType | null {\r\n const normalizedContentType = contentType.toLowerCase();\r\n return TypeConverter.contentTypes.find(value => normalizedContentType.startsWith(value)) || null;\r\n }\r\n\r\n stringToEditorLanguage(editorLanguage: string): EditorLanguage | null {\r\n const normalizedLanguage = editorLanguage.toLowerCase();\r\n return TypeConverter.editorLanguages.find(value => value === normalizedLanguage) || null;\r\n }\r\n\r\n}","import csvToJson from 'csvtojson';\r\n\r\nexport const parseCsv = async (csv: string): Promise<any> => {\r\n let json = {};\r\n try {\r\n json = await csvToJson().fromString(csv);\r\n } catch {\r\n json = [];\r\n }\r\n return json;\r\n};","import { XMLParser } from 'fast-xml-parser';\r\n\r\nconst ATTRIBUTE_PREFIX = '@_';\r\n\r\nexport const parseXml = (xml: string) => {\r\n xml = xml?.trim() || '';\r\n if (xml === '') {\r\n return {};\r\n }\r\n \r\n const json = parseXmlWithXhtmlHandling(xml);\r\n\r\n const values: any[] = [];\r\n if (Object.keys(json).length === 1) {\r\n const rootKey = Object.keys(json)[0];\r\n if (Array.isArray(json[rootKey])) {\r\n for (const jsonValue of json[rootKey]) {\r\n values.push(standardizeJson(jsonValue, rootKey));\r\n }\r\n } else {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n if (Object.keys(json).length > 1) {\r\n for (const rootKey of Object.keys(json)) {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n return values.length === 1 ? values[0] : values;\r\n};\r\n\r\nconst parseXmlWithXhtmlHandling = (xml: string): any => {\r\n const options: Record<string, any> = {\r\n ignoreAttributes: false,\r\n ignoreDeclaration: true,\r\n attributeNamePrefix: ATTRIBUTE_PREFIX,\r\n allowBooleanAttributes: true,\r\n alwaysCreateTextNode: true,\r\n numberParseOptions: {\r\n leadingZeros: false,\r\n hex: false,\r\n skipLike: /\\*/\r\n }\r\n };\r\n const firstParser = new XMLParser(options);\r\n const firstParsing = firstParser.parse(xml, true);\r\n const xhtmlPaths = getXhtmlPaths('', firstParsing, []);\r\n\r\n if (xhtmlPaths.length === 0) {\r\n return firstParsing;\r\n }\r\n\r\n options.stopNodes = [...new Set(xhtmlPaths)]; // remove duplications;\r\n const secondParser = new XMLParser(options);\r\n const secondParsing = secondParser.parse(xml);\r\n return secondParsing;\r\n};\r\n\r\nconst getXhtmlPaths = (currentPath, currentValue, xhtmlPaths) => {\r\n if (Array.isArray(currentValue)) {\r\n for (let i = 0; i < currentValue.length; i++) {\r\n getXhtmlPaths(`${currentPath}`, currentValue[i], xhtmlPaths);\r\n }\r\n } else if (typeof currentValue === 'object') {\r\n if (currentValue[`${ATTRIBUTE_PREFIX}xmlns`] === 'http://www.w3.org/1999/xhtml') {\r\n xhtmlPaths.push(currentPath);\r\n } else {\r\n for (const key of Object.keys(currentValue)) {\r\n getXhtmlPaths(`${currentPath ? `${currentPath}.` : ''}${key}`, currentValue[key], xhtmlPaths);\r\n }\r\n }\r\n }\r\n return xhtmlPaths;\r\n};\r\n\r\nconst standardizeJson = (json, rootKey: string): Record<string, any> => {\r\n const parsedXml = recursiveStandardize(json, rootKey);\r\n\r\n const namespaceIndex = rootKey.indexOf(':');\r\n const baseRootKey = namespaceIndex === -1 ? rootKey : rootKey.slice(namespaceIndex + 1);\r\n\r\n const value = parsedXml[baseRootKey];\r\n if (typeof value === 'object') {\r\n const namespaceIndex = rootKey.indexOf(':');\r\n if (namespaceIndex !== -1) {\r\n value._namespace = rootKey.slice(0, namespaceIndex);\r\n if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n } else if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n }\r\n return value;\r\n};\r\n\r\nconst recursiveStandardize = (node: any, key: string) => {\r\n const newNode: Record<string, any | any[]> = {};\r\n let newKey: string = key;\r\n\r\n // extract values and attributes\r\n let textValue: any | undefined;\r\n const complexValue = {};\r\n let valueAttribute: string | undefined;\r\n const attributes: Record<string, any> = {};\r\n for (const key of Object.keys(node)) {\r\n if (key === '#text' && (typeof node[key] !== 'string' || node[key].length > 0)) {\r\n textValue = String(node[key]);\r\n } else if (key.startsWith(ATTRIBUTE_PREFIX)) {\r\n attributes[key.slice(ATTRIBUTE_PREFIX.length)] = node[key];\r\n if (key === `${ATTRIBUTE_PREFIX}value`) {\r\n valueAttribute = node[key];\r\n }\r\n } else {\r\n complexValue[key] = node[key];\r\n }\r\n }\r\n\r\n // extract namespace\r\n const namespaceIndex = key.indexOf(':');\r\n let namespaceValue;\r\n if (namespaceIndex !== -1) {\r\n newKey = key.slice(namespaceIndex + 1);\r\n namespaceValue = key.slice(0, namespaceIndex);\r\n }\r\n\r\n // extract complex childs\r\n const complexChildsObject = createComplexChildsObject(complexValue);\r\n\r\n // replace xmlns=\"http://hl7.org/fhir\" with resourceType\r\n if (attributes.xmlns === 'http://hl7.org/fhir') {\r\n attributes.resourceType = newKey;\r\n delete attributes.xmlns;\r\n }\r\n\r\n // build new node\r\n if (textValue && attributes.xmlns === 'http://www.w3.org/1999/xhtml') {\r\n textValue = `<${key}${buildAttributesString(attributes)}>${textValue}</${key}>`;\r\n newNode[newKey] = textValue;\r\n } else if (textValue) {\r\n newNode[newKey] = textValue;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n } else if (valueAttribute) {\r\n newNode[newKey] = valueAttribute;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n delete attributes.value;\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n addInnerKeys(newNode, `_${newKey}`, complexChildsObject);\r\n } else if (Object.keys(complexChildsObject).length > 0) {\r\n addInnerKeys(newNode, newKey, complexChildsObject);\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n } else if (Object.keys(attributes).length > 0) {\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n }\r\n return newNode;\r\n};\r\n\r\nconst createComplexChildsObject = (complexChilds) => {\r\n const complexChildsObject = {};\r\n for (const childKey of Object.keys(complexChilds)) {\r\n if (Array.isArray(complexChilds[childKey])) {\r\n const childValues = complexChilds[childKey];\r\n for (const childValue of childValues) {\r\n const child = recursiveStandardize(childValue, childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n } else {\r\n const child = recursiveStandardize(complexChilds[childKey], childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n }\r\n return complexChildsObject;\r\n};\r\n// /_xmlTagName\r\n\r\nconst addChildToParent = (parentNode, child) => {\r\n const childKey: string | undefined = Object.keys(child).find(key => !key.startsWith('_'));\r\n const childAttKey: string | undefined = Object.keys(child).find(key => key.startsWith('_'));\r\n\r\n if (childKey === undefined && childAttKey === undefined) return;\r\n const key = childKey ?? childAttKey!.slice(1);\r\n const attKey = childAttKey ?? `_${childKey}`;\r\n\r\n if ((parentNode[key]) || (parentNode[attKey])) {\r\n const keySize = parentNode[key] ? (Array.isArray(parentNode[key]) ? parentNode[key].length : 1) : 0;\r\n const attKeySize = parentNode[attKey] ? (Array.isArray(parentNode[attKey]) ? parentNode[attKey].length : 1) : 0;\r\n\r\n if (keySize > 1) {\r\n parentNode[key].push(child[key] ?? null);\r\n } else if (keySize === 1) {\r\n parentNode[key] = [parentNode[key], child[key] ?? null];\r\n } else if (childKey) {\r\n parentNode[key] = Array.from({ length: attKeySize }, (x, i) => null);\r\n parentNode[key].push(child[key] ?? null);\r\n }\r\n\r\n if (attKeySize > 1) {\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n } else if (attKeySize === 1) {\r\n parentNode[attKey] = [parentNode[attKey], child[attKey] ?? null];\r\n } else if (childAttKey) {\r\n parentNode[attKey] = Array.from({ length: keySize }, (x, i) => null);\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n }\r\n } else {\r\n if (childKey) {\r\n parentNode[key] = child[key];\r\n }\r\n if (childAttKey) {\r\n parentNode[attKey] = child[attKey];\r\n }\r\n }\r\n};\r\n\r\nconst addInnerKeys = (object, key, innerObject) => {\r\n for (const innerKey of Object.keys(innerObject)) {\r\n addInnerKey(object, key, innerKey, innerObject[innerKey]);\r\n }\r\n};\r\n\r\nconst addInnerKey = (object, key, innerKey, innerValue) => {\r\n if (innerValue === undefined) return;\r\n if (object[key] === undefined) {\r\n object[key] = {};\r\n }\r\n\r\n if (innerKey === 'resourceType') {\r\n object[key] = {\r\n resourceType: innerValue,\r\n ...object[key]\r\n };\r\n } else {\r\n object[key][innerKey] = innerValue;\r\n }\r\n};\r\n\r\nconst buildAttributesString = (attributs) => {\r\n let string = '';\r\n for (const key of Object.keys(attributs)) {\r\n string += ` ${key}=\"${attributs[key]}\"`;\r\n }\r\n return string;\r\n};\r\n","import hl7js from 'hl7js';\r\n\r\nexport const v2parse = async (msg: string): Promise<object> => {\r\n // parses hl7 v2 to raw json (without field names, only numbers)\r\n msg = msg.replace(/(?:\\r\\n|\\r|\\n)/g, '\\r\\n');\r\n\r\n // Create a new Reader instance for each parse operation to avoid race conditions\r\n const v2reader = new hl7js.Reader('BASIC');\r\n\r\n return await new Promise<object>((resolve, reject) => {\r\n v2reader.read(msg, function (err, hl7Data) {\r\n if (err) {\r\n reject(new Error(`Transformation error: ${JSON.stringify(err)}`));\r\n return;\r\n };\r\n return resolve(hl7Data);\r\n });\r\n });\r\n};","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nexport const getV2DatatypeDef = (datatype: string, v2version: string) => {\r\n return HL7Dictionary.definitions[v2version].fields[datatype];\r\n};\r\n","export interface ICache<T> {\r\n get: (key: string) => T\r\n set: (key: string, value: T) => void\r\n getDict: () => Record<string, T>\r\n}\r\n\r\nclass SimpleCache<T> implements ICache<T> {\r\n private cache: Record<string, any> = {};\r\n\r\n get = (key: string) => this.cache[key];\r\n set = (key: string, value: any) => this.cache[key] = value;\r\n getDict = () => this.cache;\r\n}\r\n\r\nconst v2keyMap: ICache<string> = new SimpleCache<string>();\r\n\r\nconst cache = { v2keyMap };\r\n\r\nexport const getCache = () => cache;","import jsonata from 'jsonata';\r\n\r\nexport const expressions = {\r\n\r\n v2jsonExpression: jsonata(`(\r\n $rawJson := $v2parse($);\r\n $v2version := $rawJson.segments[0].\\`12\\`;\r\n\r\n $dtToIso := function($dt){(\r\n $y := $substring($dt,0,4);\r\n $m := $substring($dt,4,2);\r\n $d := $substring($dt,6,2);\r\n $join([$y,$m,$d],'-')\r\n )};\r\n\r\n $dtmToIso := function($dtm){(\r\n $dt := $dtToIso($dtm);\r\n $hh := $substring($dtm,8,2);\r\n $mm := $substring($dtm,10,2);\r\n $ss := $substring($dtm,12,2);\r\n $tm := $join([($hh!=''?$hh),($mm!=''?$mm),($ss!=''?$ss)],':');\r\n $dt & ($tm!=''? 'T' & $tm)\r\n )};\r\n\r\n $parseValue := function($value, $datatype){( \r\n $value = '' \r\n ? \r\n undefined \r\n : $value.(\r\n $datatype = 'DT' ? $dtToIso($) : ($datatype = 'DTM' ? $dtmToIso($) : $)\r\n )\r\n )};\r\n\r\n $translateSubfield := function($subfield, $datatypeDef, $sfi){(\r\n $subfieldDef := $datatypeDef.subfields[$sfi];\r\n $subfieldDesc := $subfieldDef.desc;\r\n $subfieldDatatype := $subfieldDef.datatype;\r\n $sfDataTypeDef := $getDatatypeDef($subfieldDatatype, $v2version);\r\n $isComplex := $count($sfDataTypeDef.subfields)>0;\r\n $hasChildren := $count($subfield.fields)>0;\r\n\r\n $value := (\r\n $isComplex = false \r\n ? $parseValue($subfield.value, $subfieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $subfield.fields@$subsubfield#$ssfi.$translateSubfield($subsubfield, $sfDataTypeDef, $ssfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $subfield.value}, $sfDataTypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n ) \r\n );\r\n\r\n {\r\n 'name': $subfieldDesc,\r\n 'value': $value != {} ? $value\r\n }\r\n )};\r\n\r\n $translateField := function($field, $segDef, $fieldIndex){(\r\n $fieldDef := $segDef.fields[$fieldIndex];\r\n $fieldDef := $exists($fieldDef)=false ? {'name': $segDef.segmentId & ($fieldIndex + 1)} : $fieldDef;\r\n $fieldDesc := $fieldDef.desc ? $fieldDef.desc : $fieldDef.name;\r\n $fieldDesc := $type($fieldDesc) = 'string' and $startsWith($fieldDesc,'Set ID - ') and $fieldIndex=0 ? 'SetID' : $fieldDesc;\r\n $fieldDatatype := $fieldDef.datatype;\r\n $datatypeDef := $getDatatypeDef($fieldDatatype, $v2version);\r\n $isEnc := $segDef.segmentId='MSH' and $fieldIndex=1;\r\n $isComplex := $count($datatypeDef.subfields)>0;\r\n $hasChildren := $count($field.fields)>0;\r\n\r\n $value := (\r\n $isEnc ? $field.value : (\r\n $isComplex = false \r\n ? $parseValue($field.value, $fieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $field.fields@$subfield#$sfi.$translateSubfield($subfield, $datatypeDef, $sfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $field.value}, $datatypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n )\r\n )\r\n );\r\n $value := $value = {} ? undefined : $value;\r\n \r\n {\r\n 'name': $fieldDesc,\r\n 'value': $value\r\n };\r\n )};\r\n\r\n $translateSegment := function($segment){(\r\n $line := $segment.MessageLine;\r\n $segId := $segment.\\`0\\`;\r\n $segDef := $getSegmentDef($segId, $v2version);\r\n $segment.fields#$i[$i>0].$translateField($, $segDef, $i-1){\r\n 'SegmentDescription': $segDef.desc,\r\n 'MessageLine': $line,\r\n $normalizeKey(name): value\r\n }\r\n )};\r\n \r\n $segmentsWithLines := $rawJson.segments#$line.($merge([$, {'MessageLine': $line+1}]));\r\n\r\n $segmentsWithLines@$s.$translateSegment($s){\r\n $s.\\`0\\`: $\r\n };\r\n )`),\r\n\r\n v2normalizeKey: jsonata(`(\r\n $cached := $lookup($keyMap, $);\r\n $exists($cached) = false \r\n ? (\r\n $titleCased := ($split($initCap($replace($,\"'\", '')), ' ')~>$join);\r\n $dtmFixed := $titleCased.$replace('Date/Time', 'DateTime') ~> $replace('Date / Time', 'DateTime');$underscored := $replace($dtmFixed, /[-\\+\".()\\\\//]/, '_');\r\n $registerV2key($, $underscored);\r\n $underscored;\r\n )\r\n : ($cached);\r\n )`),\r\n\r\n initCap: jsonata(`(\r\n $words := $trim($)~>$split(\" \");\r\n ($words.$initCapOnce($))~>$join(' ')\r\n )`)\r\n};","import { getCache } from './cache';\r\n\r\nexport const registerV2key = (key, normalized) => {\r\n getCache().v2keyMap.set(key, normalized);\r\n};\r\n","import { expressions } from './jsonataExpressions';\r\n\r\nexport const startsWith = (str: string | undefined, startStr: string): boolean | undefined => {\r\n if (typeof str === 'undefined') return undefined;\r\n return str.startsWith(startStr);\r\n};\r\n\r\nexport const initCapOnce = (str: string): string => {\r\n return str[0].toUpperCase() + str.slice(1);\r\n};\r\n\r\nexport const initCap = (str: string): Promise<string> => {\r\n return expressions.initCap.evaluate(str, { initCapOnce });\r\n};","import { getCache } from './cache';\r\nimport { expressions } from './jsonataExpressions';\r\nimport { registerV2key } from './registerV2key';\r\nimport { initCap } from './stringFuncations';\r\n\r\nexport const v2normalizeKey = async (key: string) => {\r\n const bindings = {\r\n initCap,\r\n registerV2key,\r\n keyMap: getCache().v2keyMap.getDict()\r\n };\r\n const res = await expressions.v2normalizeKey.evaluate(key, bindings);\r\n return res;\r\n};\r\n","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nimport { v2parse } from './v2parse';\r\nimport { getV2DatatypeDef } from './getV2DatatypeDef';\r\nimport { v2normalizeKey } from './v2normalizeKey';\r\nimport { startsWith } from './stringFuncations';\r\nimport { expressions } from './jsonataExpressions';\r\n\r\nconst getV2SegmentDef = (segmentId: string, v2version: string) => {\r\n const segDef = HL7Dictionary.definitions[v2version].segments[segmentId];\r\n return { segmentId, ...segDef };\r\n};\r\n\r\nexport const v2json = async (message: string) => {\r\n const bindings = {\r\n v2parse,\r\n startsWith,\r\n normalizeKey: v2normalizeKey,\r\n getSegmentDef: getV2SegmentDef,\r\n getDatatypeDef: getV2DatatypeDef\r\n };\r\n\r\n const res = await expressions.v2jsonExpression.evaluate(message, bindings);\r\n return res;\r\n};\r\n","import { parseCsv, parseXml, v2json } from './converters';\r\nimport { TypeConverter } from './TypeConverter';\r\nimport { ContentType, IFormatConverter, ILogger, ITypeConverter } from './types';\r\n\r\nconst noopLogger: ILogger = {\r\n info: () => {},\r\n warn: () => {},\r\n error: () => {},\r\n};\r\n\r\nexport class FormatConverter implements IFormatConverter {\r\n private static readonly typeConverter: ITypeConverter = new TypeConverter();\r\n private logger: ILogger;\r\n\r\n constructor(logger?: ILogger) {\r\n this.logger = logger || noopLogger;\r\n }\r\n\r\n async toJson(input: any, contentType?: ContentType | string): Promise<any> {\r\n if (!contentType || contentType === '') {\r\n this.logger.info('No content type provided, defaulting to \\'application/json\\'');\r\n contentType = ContentType.JSON;\r\n }\r\n const suggestedContentType = typeof contentType === 'string'\r\n ? FormatConverter.typeConverter.stringToContentType(contentType)\r\n : contentType;\r\n if (!suggestedContentType) {\r\n throw new Error(`Unsupported Content-Type: ${suggestedContentType}`);\r\n }\r\n\r\n let parsedJson: any;\r\n if (suggestedContentType === ContentType.HL7V2) {\r\n this.logger.info('Content-Type suggests HL7 V2.x message');\r\n this.logger.info('Trying to parse HL7 V2.x message as JSON...');\r\n parsedJson = await this.hl7v2ToJson(input);\r\n this.logger.info('Parsed HL7 V2.x message to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.CSV) {\r\n this.logger.info('Content-Type suggests CSV input');\r\n this.logger.info('Trying to parse CSV as JSON...');\r\n parsedJson = await this.csvToJson(input);\r\n this.logger.info('Parsed CSV to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.XML) {\r\n this.logger.info('Content-Type suggests XML input');\r\n this.logger.info('Trying to parse XML as JSON...');\r\n parsedJson = await this.xmlToJson(input);\r\n this.logger.info('Parsed XML to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.JSON) {\r\n this.logger.info('Content-Type suggests JSON input');\r\n parsedJson = input;\r\n this.logger.info('Parsed input to JSON successfully.');\r\n } else {\r\n // should never reach here\r\n throw new Error('Unsupported Content-Type encountered during processing.');\r\n }\r\n\r\n return parsedJson;\r\n }\r\n\r\n csvToJson = parseCsv;\r\n\r\n xmlToJson(input: string): Promise<any> {\r\n return Promise.resolve(parseXml(input));\r\n }\r\n\r\n hl7v2ToJson = v2json;\r\n}"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
interface ILogger {
|
|
2
|
-
info: (msg: any) => void;
|
|
3
|
-
warn: (msg: any) => void;
|
|
4
|
-
error: (msg: any) => void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Enumeration of supported content formats for detection and conversion.
|
|
9
|
-
* Used by format detection algorithms to categorize input data and determine
|
|
10
|
-
* appropriate conversion strategies.
|
|
11
|
-
*/
|
|
12
|
-
declare const enum ContentFormat {
|
|
13
|
-
/** JavaScript Object Notation format */
|
|
14
|
-
JSON = "json",
|
|
15
|
-
/** Comma-Separated Values format */
|
|
16
|
-
CSV = "csv",
|
|
17
|
-
/** eXtensible Markup Language format */
|
|
18
|
-
XML = "xml",
|
|
19
|
-
/** Health Level 7 Version 2.x message format */
|
|
20
|
-
HL7 = "hl7",
|
|
21
|
-
/** Unknown or unsupported format */
|
|
22
|
-
UNKNOWN = "unknown"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Enumeration of supported MIME types/content types for data format identification.
|
|
27
|
-
* These values correspond to standard HTTP Content-Type header values and are used
|
|
28
|
-
* for format detection and conversion operations.
|
|
29
|
-
*/
|
|
30
|
-
declare const enum ContentType {
|
|
31
|
-
/** Standard MIME type for JSON data */
|
|
32
|
-
JSON = "application/json",
|
|
33
|
-
/** Standard MIME type for CSV data */
|
|
34
|
-
CSV = "text/csv",
|
|
35
|
-
/** Standard MIME type for XML data */
|
|
36
|
-
XML = "application/xml",
|
|
37
|
-
/** Custom MIME type for HL7 Version 2.x messages in ER7 encoding */
|
|
38
|
-
HL7V2 = "x-application/hl7-v2+er7"
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Enumeration of supported editor language identifiers for syntax highlighting and editor configuration.
|
|
43
|
-
* These values are used to determine the appropriate language mode for displaying content
|
|
44
|
-
* in code editors or other text editing interfaces.
|
|
45
|
-
*/
|
|
46
|
-
declare const enum EditorLanguage {
|
|
47
|
-
/** JSON language mode for syntax highlighting */
|
|
48
|
-
JSON = "json",
|
|
49
|
-
/** XML language mode for syntax highlighting */
|
|
50
|
-
XML = "xml",
|
|
51
|
-
/** Plain text mode with no syntax highlighting */
|
|
52
|
-
PLAINTEXT = "plaintext"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Interface for format conversion operations, providing methods to convert various data formats to JSON.
|
|
57
|
-
* Supports conversion from CSV, XML, and HL7 V2.x message formats.
|
|
58
|
-
*/
|
|
59
|
-
interface IFormatConverter {
|
|
60
|
-
/**
|
|
61
|
-
* Converts input data to JSON format based on the specified content type.
|
|
62
|
-
* If content type is not provided, defaults to `application/json`.
|
|
63
|
-
* @param input Data to be converted
|
|
64
|
-
* @param contentType Optional content type indicating the format of the input data
|
|
65
|
-
* @returns Promise resolving to JSON object
|
|
66
|
-
* @throws Error if the content type is unsupported or conversion fails
|
|
67
|
-
*/
|
|
68
|
-
toJson: (input: any, contentType?: ContentType | string) => Promise<any>;
|
|
69
|
-
/**
|
|
70
|
-
* Converts CSV string to JSON object. If conversion fails, returns an empty array.
|
|
71
|
-
* @param input CSV string to be converted
|
|
72
|
-
* @returns Promise resolving to JSON object
|
|
73
|
-
*/
|
|
74
|
-
csvToJson: (input: string) => Promise<any>;
|
|
75
|
-
/**
|
|
76
|
-
* Converts XML string to JSON object. If the input is empty, returns an empty object.
|
|
77
|
-
* @param input XML string to be converted
|
|
78
|
-
* @returns Promise resolving to JSON object
|
|
79
|
-
* @throws Error if XML parsing fails
|
|
80
|
-
*/
|
|
81
|
-
xmlToJson: (input: string) => Promise<any>;
|
|
82
|
-
/**
|
|
83
|
-
* Converts HL7 V2.x message string to JSON object.
|
|
84
|
-
* @param message HL7 V2.x message string to be converted
|
|
85
|
-
* @returns Promise resolving to JSON object
|
|
86
|
-
*/
|
|
87
|
-
hl7v2ToJson: (message: string) => Promise<any>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Interface for type conversion operations, providing methods to convert between
|
|
92
|
-
* different content type representations (ContentType, ContentFormat, EditorLanguage, and string).
|
|
93
|
-
*/
|
|
94
|
-
interface ITypeConverter {
|
|
95
|
-
/**
|
|
96
|
-
* Converts a ContentType to its corresponding ContentFormat.
|
|
97
|
-
* @param contentType The ContentType to convert
|
|
98
|
-
* @returns The corresponding ContentFormat
|
|
99
|
-
*/
|
|
100
|
-
contentTypeToContentFormat: (contentType: ContentType) => ContentFormat;
|
|
101
|
-
/**
|
|
102
|
-
* Converts a ContentType to its corresponding EditorLanguage.
|
|
103
|
-
* @param contentType The ContentType to convert
|
|
104
|
-
* @returns The corresponding EditorLanguage
|
|
105
|
-
*/
|
|
106
|
-
contentTypeToEditorLanguage: (contentType: ContentType) => EditorLanguage;
|
|
107
|
-
/**
|
|
108
|
-
* Converts a ContentFormat to its corresponding ContentType.
|
|
109
|
-
* @param format The ContentFormat to convert
|
|
110
|
-
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
111
|
-
*/
|
|
112
|
-
contentFormatToContentType: (format: ContentFormat) => ContentType | null;
|
|
113
|
-
/**
|
|
114
|
-
* Converts a ContentFormat to its corresponding EditorLanguage.
|
|
115
|
-
* @param format The ContentFormat to convert
|
|
116
|
-
* @returns The corresponding EditorLanguage
|
|
117
|
-
*/
|
|
118
|
-
contentFormatToEditorLanguage: (format: ContentFormat) => EditorLanguage;
|
|
119
|
-
/**
|
|
120
|
-
* Converts a string representation to its corresponding ContentFormat.
|
|
121
|
-
* @param format The string representation of a format
|
|
122
|
-
* @returns The corresponding ContentFormat, or null if conversion is not possible
|
|
123
|
-
*/
|
|
124
|
-
stringToContentFormat: (format: string) => ContentFormat | null;
|
|
125
|
-
/**
|
|
126
|
-
* Converts a string representation to its corresponding ContentType.
|
|
127
|
-
* @param contentType The string representation of a content type
|
|
128
|
-
* @returns The corresponding ContentType, or null if conversion is not possible
|
|
129
|
-
*/
|
|
130
|
-
stringToContentType: (contentType: string) => ContentType | null;
|
|
131
|
-
/**
|
|
132
|
-
* Converts a string representation to its corresponding EditorLanguage.
|
|
133
|
-
* @param editorLanguage The string representation of an editor language
|
|
134
|
-
* @returns The corresponding EditorLanguage, or null if conversion is not possible
|
|
135
|
-
*/
|
|
136
|
-
stringToEditorLanguage: (editorLanguage: string) => EditorLanguage | null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
declare class TypeConverter implements ITypeConverter {
|
|
140
|
-
private static contentTypeToContentFormatMap;
|
|
141
|
-
private static contentFormatToContentTypeMap;
|
|
142
|
-
private static contentFormatToEditorLanguageMap;
|
|
143
|
-
private static contentFormats;
|
|
144
|
-
private static contentTypes;
|
|
145
|
-
private static editorLanguages;
|
|
146
|
-
contentTypeToContentFormat(contentType: ContentType): ContentFormat;
|
|
147
|
-
contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage;
|
|
148
|
-
contentFormatToContentType(format: ContentFormat): ContentType | null;
|
|
149
|
-
contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage;
|
|
150
|
-
stringToContentFormat(format: string): ContentFormat | null;
|
|
151
|
-
stringToContentType(contentType: string): ContentType | null;
|
|
152
|
-
stringToEditorLanguage(editorLanguage: string): EditorLanguage | null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
declare class FormatConverter implements IFormatConverter {
|
|
156
|
-
private static readonly typeConverter;
|
|
157
|
-
private logger;
|
|
158
|
-
constructor(logger?: ILogger);
|
|
159
|
-
toJson(input: any, contentType?: ContentType | string): Promise<any>;
|
|
160
|
-
csvToJson: (csv: string) => Promise<any>;
|
|
161
|
-
xmlToJson(input: string): Promise<any>;
|
|
162
|
-
hl7v2ToJson: (message: string) => Promise<any>;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export { FormatConverter, TypeConverter };
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TypeConverter.ts","../src/converters/csvToJson.ts","../src/converters/xmlToJson.ts","../src/converters/hl7v2/v2parse.ts","../src/converters/hl7v2/getV2DatatypeDef.ts","../src/converters/hl7v2/cache.ts","../src/converters/hl7v2/jsonataExpressions.ts","../src/converters/hl7v2/registerV2key.ts","../src/converters/hl7v2/stringFuncations.ts","../src/converters/hl7v2/v2norm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AA,KAAA,UAAA,YAA0C;AACnD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAClD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,gCAAgC,CAAA;AACjD,MAAA,UAAA,GAAa,MAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA;AACvC,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AAAA,IACrD,WAAW,oBAAA,KAAA,iBAAA,YAA0C;AACnD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAClD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,gCAAgC,CAAA;AACjD,MAAA,UAAA,GAAa,MAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA;AACvC,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AAAA,IACrD,WAAW,oBAAA,KAAA,kBAAA,aAA2C;AACpD,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,kCAAkC,CAAA;AACnD,MAAA,UAAA,GAAa,KAAA;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,oCAAoC,CAAA;AAAA,IACvD,CAAA,MAAO;AAEL,MAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,IAC3E;AAEA,IAAA,OAAO,UAAA;AAAA,EACT;AAAA,EAIA,UAAU,KAAA,EAA6B;AACrC,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EACxC;AAGF","file":"index.mjs","sourcesContent":["import { ContentFormat, ContentType, EditorLanguage, ITypeConverter } from './types';\r\n\r\nexport class TypeConverter implements ITypeConverter {\r\n private static contentTypeToContentFormatMap: { [key in ContentType]: ContentFormat } = {\r\n [ContentType.JSON]: ContentFormat.JSON,\r\n [ContentType.CSV]: ContentFormat.CSV,\r\n [ContentType.XML]: ContentFormat.XML,\r\n [ContentType.HL7V2]: ContentFormat.HL7\r\n };\r\n\r\n private static contentFormatToContentTypeMap: { [key in ContentFormat]: ContentType | null } = {\r\n [ContentFormat.JSON]: ContentType.JSON,\r\n [ContentFormat.CSV]: ContentType.CSV,\r\n [ContentFormat.XML]: ContentType.XML,\r\n [ContentFormat.HL7]: ContentType.HL7V2,\r\n [ContentFormat.UNKNOWN]: null\r\n };\r\n\r\n private static contentFormatToEditorLanguageMap: { [key in ContentFormat]: EditorLanguage } = {\r\n [ContentFormat.JSON]: EditorLanguage.JSON,\r\n [ContentFormat.XML]: EditorLanguage.XML,\r\n [ContentFormat.CSV]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.HL7]: EditorLanguage.PLAINTEXT,\r\n [ContentFormat.UNKNOWN]: EditorLanguage.PLAINTEXT\r\n };\r\n\r\n private static contentFormats: ContentFormat[] = [\r\n ContentFormat.JSON,\r\n ContentFormat.CSV,\r\n ContentFormat.XML,\r\n ContentFormat.HL7,\r\n ContentFormat.UNKNOWN\r\n ];\r\n\r\n private static contentTypes: ContentType[] = [\r\n ContentType.JSON,\r\n ContentType.CSV,\r\n ContentType.XML,\r\n ContentType.HL7V2\r\n ];\r\n\r\n private static editorLanguages: EditorLanguage[] = [\r\n EditorLanguage.JSON,\r\n EditorLanguage.XML,\r\n EditorLanguage.PLAINTEXT\r\n ];\r\n\r\n contentTypeToContentFormat(contentType: ContentType): ContentFormat {\r\n return TypeConverter.contentTypeToContentFormatMap[contentType];\r\n }\r\n\r\n contentTypeToEditorLanguage(contentType: ContentType): EditorLanguage {\r\n const format = this.contentTypeToContentFormat(contentType);\r\n return this.contentFormatToEditorLanguage(format);\r\n }\r\n\r\n contentFormatToContentType(format: ContentFormat): ContentType | null {\r\n return TypeConverter.contentFormatToContentTypeMap[format] || null;\r\n }\r\n\r\n contentFormatToEditorLanguage(format: ContentFormat): EditorLanguage {\r\n return TypeConverter.contentFormatToEditorLanguageMap[format];\r\n }\r\n\r\n stringToContentFormat(format: string): ContentFormat | null {\r\n const normalizedFormat = format.toLowerCase();\r\n return TypeConverter.contentFormats.find(value => value === normalizedFormat) || null;\r\n }\r\n\r\n stringToContentType(contentType: string): ContentType | null {\r\n const normalizedContentType = contentType.toLowerCase();\r\n return TypeConverter.contentTypes.find(value => normalizedContentType.startsWith(value)) || null;\r\n }\r\n\r\n stringToEditorLanguage(editorLanguage: string): EditorLanguage | null {\r\n const normalizedLanguage = editorLanguage.toLowerCase();\r\n return TypeConverter.editorLanguages.find(value => value === normalizedLanguage) || null;\r\n }\r\n\r\n}","import csvToJson from 'csvtojson';\r\n\r\nexport const parseCsv = async (csv: string): Promise<any> => {\r\n let json = {};\r\n try {\r\n json = await csvToJson().fromString(csv);\r\n } catch {\r\n json = [];\r\n }\r\n return json;\r\n};","import { XMLParser } from 'fast-xml-parser';\r\n\r\nconst ATTRIBUTE_PREFIX = '@_';\r\n\r\nexport const parseXml = (xml: string) => {\r\n xml = xml?.trim() || '';\r\n if (xml === '') {\r\n return {};\r\n }\r\n \r\n const json = parseXmlWithXhtmlHandling(xml);\r\n\r\n const values: any[] = [];\r\n if (Object.keys(json).length === 1) {\r\n const rootKey = Object.keys(json)[0];\r\n if (Array.isArray(json[rootKey])) {\r\n for (const jsonValue of json[rootKey]) {\r\n values.push(standardizeJson(jsonValue, rootKey));\r\n }\r\n } else {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n if (Object.keys(json).length > 1) {\r\n for (const rootKey of Object.keys(json)) {\r\n values.push(standardizeJson(json[rootKey], rootKey));\r\n }\r\n }\r\n\r\n return values.length === 1 ? values[0] : values;\r\n};\r\n\r\nconst parseXmlWithXhtmlHandling = (xml: string): any => {\r\n const options: Record<string, any> = {\r\n ignoreAttributes: false,\r\n ignoreDeclaration: true,\r\n attributeNamePrefix: ATTRIBUTE_PREFIX,\r\n allowBooleanAttributes: true,\r\n alwaysCreateTextNode: true,\r\n numberParseOptions: {\r\n leadingZeros: false,\r\n hex: false,\r\n skipLike: /\\*/\r\n }\r\n };\r\n const firstParser = new XMLParser(options);\r\n const firstParsing = firstParser.parse(xml, true);\r\n const xhtmlPaths = getXhtmlPaths('', firstParsing, []);\r\n\r\n if (xhtmlPaths.length === 0) {\r\n return firstParsing;\r\n }\r\n\r\n options.stopNodes = [...new Set(xhtmlPaths)]; // remove duplications;\r\n const secondParser = new XMLParser(options);\r\n const secondParsing = secondParser.parse(xml);\r\n return secondParsing;\r\n};\r\n\r\nconst getXhtmlPaths = (currentPath, currentValue, xhtmlPaths) => {\r\n if (Array.isArray(currentValue)) {\r\n for (let i = 0; i < currentValue.length; i++) {\r\n getXhtmlPaths(`${currentPath}`, currentValue[i], xhtmlPaths);\r\n }\r\n } else if (typeof currentValue === 'object') {\r\n if (currentValue[`${ATTRIBUTE_PREFIX}xmlns`] === 'http://www.w3.org/1999/xhtml') {\r\n xhtmlPaths.push(currentPath);\r\n } else {\r\n for (const key of Object.keys(currentValue)) {\r\n getXhtmlPaths(`${currentPath ? `${currentPath}.` : ''}${key}`, currentValue[key], xhtmlPaths);\r\n }\r\n }\r\n }\r\n return xhtmlPaths;\r\n};\r\n\r\nconst standardizeJson = (json, rootKey: string): Record<string, any> => {\r\n const parsedXml = recursiveStandardize(json, rootKey);\r\n\r\n const namespaceIndex = rootKey.indexOf(':');\r\n const baseRootKey = namespaceIndex === -1 ? rootKey : rootKey.slice(namespaceIndex + 1);\r\n\r\n const value = parsedXml[baseRootKey];\r\n if (typeof value === 'object') {\r\n const namespaceIndex = rootKey.indexOf(':');\r\n if (namespaceIndex !== -1) {\r\n value._namespace = rootKey.slice(0, namespaceIndex);\r\n if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n } else if (!value.resourceType) {\r\n value._xmlTagName = baseRootKey;\r\n }\r\n }\r\n return value;\r\n};\r\n\r\nconst recursiveStandardize = (node: any, key: string) => {\r\n const newNode: Record<string, any | any[]> = {};\r\n let newKey: string = key;\r\n\r\n // extract values and attributes\r\n let textValue: any | undefined;\r\n const complexValue = {};\r\n let valueAttribute: string | undefined;\r\n const attributes: Record<string, any> = {};\r\n for (const key of Object.keys(node)) {\r\n if (key === '#text' && (typeof node[key] !== 'string' || node[key].length > 0)) {\r\n textValue = String(node[key]);\r\n } else if (key.startsWith(ATTRIBUTE_PREFIX)) {\r\n attributes[key.slice(ATTRIBUTE_PREFIX.length)] = node[key];\r\n if (key === `${ATTRIBUTE_PREFIX}value`) {\r\n valueAttribute = node[key];\r\n }\r\n } else {\r\n complexValue[key] = node[key];\r\n }\r\n }\r\n\r\n // extract namespace\r\n const namespaceIndex = key.indexOf(':');\r\n let namespaceValue;\r\n if (namespaceIndex !== -1) {\r\n newKey = key.slice(namespaceIndex + 1);\r\n namespaceValue = key.slice(0, namespaceIndex);\r\n }\r\n\r\n // extract complex childs\r\n const complexChildsObject = createComplexChildsObject(complexValue);\r\n\r\n // replace xmlns=\"http://hl7.org/fhir\" with resourceType\r\n if (attributes.xmlns === 'http://hl7.org/fhir') {\r\n attributes.resourceType = newKey;\r\n delete attributes.xmlns;\r\n }\r\n\r\n // build new node\r\n if (textValue && attributes.xmlns === 'http://www.w3.org/1999/xhtml') {\r\n textValue = `<${key}${buildAttributesString(attributes)}>${textValue}</${key}>`;\r\n newNode[newKey] = textValue;\r\n } else if (textValue) {\r\n newNode[newKey] = textValue;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n } else if (valueAttribute) {\r\n newNode[newKey] = valueAttribute;\r\n addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });\r\n delete attributes.value;\r\n addInnerKeys(newNode, `_${newKey}`, attributes);\r\n addInnerKeys(newNode, `_${newKey}`, complexChildsObject);\r\n } else if (Object.keys(complexChildsObject).length > 0) {\r\n addInnerKeys(newNode, newKey, complexChildsObject);\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n } else if (Object.keys(attributes).length > 0) {\r\n addInnerKeys(newNode, newKey, { _namespace: namespaceValue });\r\n addInnerKeys(newNode, newKey, attributes);\r\n }\r\n return newNode;\r\n};\r\n\r\nconst createComplexChildsObject = (complexChilds) => {\r\n const complexChildsObject = {};\r\n for (const childKey of Object.keys(complexChilds)) {\r\n if (Array.isArray(complexChilds[childKey])) {\r\n const childValues = complexChilds[childKey];\r\n for (const childValue of childValues) {\r\n const child = recursiveStandardize(childValue, childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n } else {\r\n const child = recursiveStandardize(complexChilds[childKey], childKey);\r\n addChildToParent(complexChildsObject, child);\r\n }\r\n }\r\n return complexChildsObject;\r\n};\r\n// /_xmlTagName\r\n\r\nconst addChildToParent = (parentNode, child) => {\r\n const childKey: string | undefined = Object.keys(child).find(key => !key.startsWith('_'));\r\n const childAttKey: string | undefined = Object.keys(child).find(key => key.startsWith('_'));\r\n\r\n if (childKey === undefined && childAttKey === undefined) return;\r\n const key = childKey ?? childAttKey!.slice(1);\r\n const attKey = childAttKey ?? `_${childKey}`;\r\n\r\n if ((parentNode[key]) || (parentNode[attKey])) {\r\n const keySize = parentNode[key] ? (Array.isArray(parentNode[key]) ? parentNode[key].length : 1) : 0;\r\n const attKeySize = parentNode[attKey] ? (Array.isArray(parentNode[attKey]) ? parentNode[attKey].length : 1) : 0;\r\n\r\n if (keySize > 1) {\r\n parentNode[key].push(child[key] ?? null);\r\n } else if (keySize === 1) {\r\n parentNode[key] = [parentNode[key], child[key] ?? null];\r\n } else if (childKey) {\r\n parentNode[key] = Array.from({ length: attKeySize }, (x, i) => null);\r\n parentNode[key].push(child[key] ?? null);\r\n }\r\n\r\n if (attKeySize > 1) {\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n } else if (attKeySize === 1) {\r\n parentNode[attKey] = [parentNode[attKey], child[attKey] ?? null];\r\n } else if (childAttKey) {\r\n parentNode[attKey] = Array.from({ length: keySize }, (x, i) => null);\r\n parentNode[attKey].push(child[attKey] ?? null);\r\n }\r\n } else {\r\n if (childKey) {\r\n parentNode[key] = child[key];\r\n }\r\n if (childAttKey) {\r\n parentNode[attKey] = child[attKey];\r\n }\r\n }\r\n};\r\n\r\nconst addInnerKeys = (object, key, innerObject) => {\r\n for (const innerKey of Object.keys(innerObject)) {\r\n addInnerKey(object, key, innerKey, innerObject[innerKey]);\r\n }\r\n};\r\n\r\nconst addInnerKey = (object, key, innerKey, innerValue) => {\r\n if (innerValue === undefined) return;\r\n if (object[key] === undefined) {\r\n object[key] = {};\r\n }\r\n\r\n if (innerKey === 'resourceType') {\r\n object[key] = {\r\n resourceType: innerValue,\r\n ...object[key]\r\n };\r\n } else {\r\n object[key][innerKey] = innerValue;\r\n }\r\n};\r\n\r\nconst buildAttributesString = (attributs) => {\r\n let string = '';\r\n for (const key of Object.keys(attributs)) {\r\n string += ` ${key}=\"${attributs[key]}\"`;\r\n }\r\n return string;\r\n};\r\n","import hl7js from 'hl7js';\r\n\r\nexport const v2parse = async (msg: string): Promise<object> => {\r\n // parses hl7 v2 to raw json (without field names, only numbers)\r\n msg = msg.replace(/(?:\\r\\n|\\r|\\n)/g, '\\r\\n');\r\n\r\n // Create a new Reader instance for each parse operation to avoid race conditions\r\n const v2reader = new hl7js.Reader('BASIC');\r\n\r\n return await new Promise<object>((resolve, reject) => {\r\n v2reader.read(msg, function (err, hl7Data) {\r\n if (err) {\r\n reject(new Error(`Transformation error: ${JSON.stringify(err)}`));\r\n return;\r\n };\r\n return resolve(hl7Data);\r\n });\r\n });\r\n};","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nexport const getV2DatatypeDef = (datatype: string, v2version: string) => {\r\n return HL7Dictionary.definitions[v2version].fields[datatype];\r\n};\r\n","export interface ICache<T> {\r\n get: (key: string) => T\r\n set: (key: string, value: T) => void\r\n getDict: () => Record<string, T>\r\n}\r\n\r\nclass SimpleCache<T> implements ICache<T> {\r\n private cache: Record<string, any> = {};\r\n\r\n get = (key: string) => this.cache[key];\r\n set = (key: string, value: any) => this.cache[key] = value;\r\n getDict = () => this.cache;\r\n}\r\n\r\nconst v2keyMap: ICache<string> = new SimpleCache<string>();\r\n\r\nconst cache = { v2keyMap };\r\n\r\nexport const getCache = () => cache;","import jsonata from 'jsonata';\r\n\r\nexport const expressions = {\r\n\r\n v2jsonExpression: jsonata(`(\r\n $rawJson := $v2parse($);\r\n $v2version := $rawJson.segments[0].\\`12\\`;\r\n\r\n $dtToIso := function($dt){(\r\n $y := $substring($dt,0,4);\r\n $m := $substring($dt,4,2);\r\n $d := $substring($dt,6,2);\r\n $join([$y,$m,$d],'-')\r\n )};\r\n\r\n $dtmToIso := function($dtm){(\r\n $dt := $dtToIso($dtm);\r\n $hh := $substring($dtm,8,2);\r\n $mm := $substring($dtm,10,2);\r\n $ss := $substring($dtm,12,2);\r\n $tm := $join([($hh!=''?$hh),($mm!=''?$mm),($ss!=''?$ss)],':');\r\n $dt & ($tm!=''? 'T' & $tm)\r\n )};\r\n\r\n $parseValue := function($value, $datatype){( \r\n $value = '' \r\n ? \r\n undefined \r\n : $value.(\r\n $datatype = 'DT' ? $dtToIso($) : ($datatype = 'DTM' ? $dtmToIso($) : $)\r\n )\r\n )};\r\n\r\n $translateSubfield := function($subfield, $datatypeDef, $sfi){(\r\n $subfieldDef := $datatypeDef.subfields[$sfi];\r\n $subfieldDesc := $subfieldDef.desc;\r\n $subfieldDatatype := $subfieldDef.datatype;\r\n $sfDataTypeDef := $getDatatypeDef($subfieldDatatype, $v2version);\r\n $isComplex := $count($sfDataTypeDef.subfields)>0;\r\n $hasChildren := $count($subfield.fields)>0;\r\n\r\n $value := (\r\n $isComplex = false \r\n ? $parseValue($subfield.value, $subfieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $subfield.fields@$subsubfield#$ssfi.$translateSubfield($subsubfield, $sfDataTypeDef, $ssfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $subfield.value}, $sfDataTypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n ) \r\n );\r\n\r\n {\r\n 'name': $subfieldDesc,\r\n 'value': $value != {} ? $value\r\n }\r\n )};\r\n\r\n $translateField := function($field, $segDef, $fieldIndex){(\r\n $fieldDef := $segDef.fields[$fieldIndex];\r\n $fieldDef := $exists($fieldDef)=false ? {'name': $segDef.segmentId & ($fieldIndex + 1)} : $fieldDef;\r\n $fieldDesc := $fieldDef.desc ? $fieldDef.desc : $fieldDef.name;\r\n $fieldDesc := $type($fieldDesc) = 'string' and $startsWith($fieldDesc,'Set ID - ') and $fieldIndex=0 ? 'SetID' : $fieldDesc;\r\n $fieldDatatype := $fieldDef.datatype;\r\n $datatypeDef := $getDatatypeDef($fieldDatatype, $v2version);\r\n $isEnc := $segDef.segmentId='MSH' and $fieldIndex=1;\r\n $isComplex := $count($datatypeDef.subfields)>0;\r\n $hasChildren := $count($field.fields)>0;\r\n\r\n $value := (\r\n $isEnc ? $field.value : (\r\n $isComplex = false \r\n ? $parseValue($field.value, $fieldDatatype)\r\n : (\r\n /* it's a complex type */\r\n $hasChildren \r\n ? ( \r\n /* input has children */\r\n $field.fields@$subfield#$sfi.$translateSubfield($subfield, $datatypeDef, $sfi){\r\n $normalizeKey(name): value\r\n };\r\n )\r\n : ( \r\n /* input doesn't have children */\r\n $translateSubfield({'value': $field.value}, $datatypeDef, 0){\r\n $normalizeKey(name): value\r\n }\r\n )\r\n )\r\n )\r\n );\r\n $value := $value = {} ? undefined : $value;\r\n \r\n {\r\n 'name': $fieldDesc,\r\n 'value': $value\r\n };\r\n )};\r\n\r\n $translateSegment := function($segment){(\r\n $line := $segment.MessageLine;\r\n $segId := $segment.\\`0\\`;\r\n $segDef := $getSegmentDef($segId, $v2version);\r\n $segment.fields#$i[$i>0].$translateField($, $segDef, $i-1){\r\n 'SegmentDescription': $segDef.desc,\r\n 'MessageLine': $line,\r\n $normalizeKey(name): value\r\n }\r\n )};\r\n \r\n $segmentsWithLines := $rawJson.segments#$line.($merge([$, {'MessageLine': $line+1}]));\r\n\r\n $segmentsWithLines@$s.$translateSegment($s){\r\n $s.\\`0\\`: $\r\n };\r\n )`),\r\n\r\n v2normalizeKey: jsonata(`(\r\n $cached := $lookup($keyMap, $);\r\n $exists($cached) = false \r\n ? (\r\n $titleCased := ($split($initCap($replace($,\"'\", '')), ' ')~>$join);\r\n $dtmFixed := $titleCased.$replace('Date/Time', 'DateTime') ~> $replace('Date / Time', 'DateTime');$underscored := $replace($dtmFixed, /[-\\+\".()\\\\//]/, '_');\r\n $registerV2key($, $underscored);\r\n $underscored;\r\n )\r\n : ($cached);\r\n )`),\r\n\r\n initCap: jsonata(`(\r\n $words := $trim($)~>$split(\" \");\r\n ($words.$initCapOnce($))~>$join(' ')\r\n )`)\r\n};","import { getCache } from './cache';\r\n\r\nexport const registerV2key = (key, normalized) => {\r\n getCache().v2keyMap.set(key, normalized);\r\n};\r\n","import { expressions } from './jsonataExpressions';\r\n\r\nexport const startsWith = (str: string | undefined, startStr: string): boolean | undefined => {\r\n if (typeof str === 'undefined') return undefined;\r\n return str.startsWith(startStr);\r\n};\r\n\r\nexport const initCapOnce = (str: string): string => {\r\n return str[0].toUpperCase() + str.slice(1);\r\n};\r\n\r\nexport const initCap = (str: string): Promise<string> => {\r\n return expressions.initCap.evaluate(str, { initCapOnce });\r\n};","import { getCache } from './cache';\r\nimport { expressions } from './jsonataExpressions';\r\nimport { registerV2key } from './registerV2key';\r\nimport { initCap } from './stringFuncations';\r\n\r\nexport const v2normalizeKey = async (key: string) => {\r\n const bindings = {\r\n initCap,\r\n registerV2key,\r\n keyMap: getCache().v2keyMap.getDict()\r\n };\r\n const res = await expressions.v2normalizeKey.evaluate(key, bindings);\r\n return res;\r\n};\r\n","import HL7Dictionary from 'hl7-dictionary';\r\n\r\nimport { v2parse } from './v2parse';\r\nimport { getV2DatatypeDef } from './getV2DatatypeDef';\r\nimport { v2normalizeKey } from './v2normalizeKey';\r\nimport { startsWith } from './stringFuncations';\r\nimport { expressions } from './jsonataExpressions';\r\n\r\nconst getV2SegmentDef = (segmentId: string, v2version: string) => {\r\n const segDef = HL7Dictionary.definitions[v2version].segments[segmentId];\r\n return { segmentId, ...segDef };\r\n};\r\n\r\nexport const v2json = async (message: string) => {\r\n const bindings = {\r\n v2parse,\r\n startsWith,\r\n normalizeKey: v2normalizeKey,\r\n getSegmentDef: getV2SegmentDef,\r\n getDatatypeDef: getV2DatatypeDef\r\n };\r\n\r\n const res = await expressions.v2jsonExpression.evaluate(message, bindings);\r\n return res;\r\n};\r\n","import { parseCsv, parseXml, v2json } from './converters';\r\nimport { TypeConverter } from './TypeConverter';\r\nimport { ContentType, IFormatConverter, ILogger, ITypeConverter } from './types';\r\n\r\nconst noopLogger: ILogger = {\r\n info: () => {},\r\n warn: () => {},\r\n error: () => {},\r\n};\r\n\r\nexport class FormatConverter implements IFormatConverter {\r\n private static readonly typeConverter: ITypeConverter = new TypeConverter();\r\n private logger: ILogger;\r\n\r\n constructor(logger?: ILogger) {\r\n this.logger = logger || noopLogger;\r\n }\r\n\r\n async toJson(input: any, contentType?: ContentType | string): Promise<any> {\r\n if (!contentType || contentType === '') {\r\n this.logger.info('No content type provided, defaulting to \\'application/json\\'');\r\n contentType = ContentType.JSON;\r\n }\r\n const suggestedContentType = typeof contentType === 'string'\r\n ? FormatConverter.typeConverter.stringToContentType(contentType)\r\n : contentType;\r\n if (!suggestedContentType) {\r\n throw new Error(`Unsupported Content-Type: ${suggestedContentType}`);\r\n }\r\n\r\n let parsedJson: any;\r\n if (suggestedContentType === ContentType.HL7V2) {\r\n this.logger.info('Content-Type suggests HL7 V2.x message');\r\n this.logger.info('Trying to parse HL7 V2.x message as JSON...');\r\n parsedJson = await this.hl7v2ToJson(input);\r\n this.logger.info('Parsed HL7 V2.x message to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.CSV) {\r\n this.logger.info('Content-Type suggests CSV input');\r\n this.logger.info('Trying to parse CSV as JSON...');\r\n parsedJson = await this.csvToJson(input);\r\n this.logger.info('Parsed CSV to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.XML) {\r\n this.logger.info('Content-Type suggests XML input');\r\n this.logger.info('Trying to parse XML as JSON...');\r\n parsedJson = await this.xmlToJson(input);\r\n this.logger.info('Parsed XML to JSON successfully.');\r\n } else if (suggestedContentType === ContentType.JSON) {\r\n this.logger.info('Content-Type suggests JSON input');\r\n parsedJson = input;\r\n this.logger.info('Parsed input to JSON successfully.');\r\n } else {\r\n // should never reach here\r\n throw new Error('Unsupported Content-Type encountered during processing.');\r\n }\r\n\r\n return parsedJson;\r\n }\r\n\r\n csvToJson = parseCsv;\r\n\r\n xmlToJson(input: string): Promise<any> {\r\n return Promise.resolve(parseXml(input));\r\n }\r\n\r\n hl7v2ToJson = v2json;\r\n}"]}
|