@outburn/format-converter 1.0.0
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 +21 -0
- package/README.md +171 -0
- package/dist/index.cjs +589 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.mjs +579 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +49 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import csvToJson from 'csvtojson';
|
|
2
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
3
|
+
import HL7Dictionary from 'hl7-dictionary';
|
|
4
|
+
import hl7js from 'hl7js';
|
|
5
|
+
import jsonata from 'jsonata';
|
|
6
|
+
|
|
7
|
+
// src/TypeConverter.ts
|
|
8
|
+
var TypeConverter = class _TypeConverter {
|
|
9
|
+
static {
|
|
10
|
+
this.contentTypeToContentFormatMap = {
|
|
11
|
+
["application/json" /* JSON */]: "json" /* JSON */,
|
|
12
|
+
["text/csv" /* CSV */]: "csv" /* CSV */,
|
|
13
|
+
["application/xml" /* XML */]: "xml" /* XML */,
|
|
14
|
+
["x-application/hl7-v2+er7" /* HL7V2 */]: "hl7" /* HL7 */
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static {
|
|
18
|
+
this.contentFormatToContentTypeMap = {
|
|
19
|
+
["json" /* JSON */]: "application/json" /* JSON */,
|
|
20
|
+
["csv" /* CSV */]: "text/csv" /* CSV */,
|
|
21
|
+
["xml" /* XML */]: "application/xml" /* XML */,
|
|
22
|
+
["hl7" /* HL7 */]: "x-application/hl7-v2+er7" /* HL7V2 */,
|
|
23
|
+
["unknown" /* UNKNOWN */]: null
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static {
|
|
27
|
+
this.contentFormatToEditorLanguageMap = {
|
|
28
|
+
["json" /* JSON */]: "json" /* JSON */,
|
|
29
|
+
["xml" /* XML */]: "xml" /* XML */,
|
|
30
|
+
["csv" /* CSV */]: "plaintext" /* PLAINTEXT */,
|
|
31
|
+
["hl7" /* HL7 */]: "plaintext" /* PLAINTEXT */,
|
|
32
|
+
["unknown" /* UNKNOWN */]: "plaintext" /* PLAINTEXT */
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static {
|
|
36
|
+
this.contentFormats = [
|
|
37
|
+
"json" /* JSON */,
|
|
38
|
+
"csv" /* CSV */,
|
|
39
|
+
"xml" /* XML */,
|
|
40
|
+
"hl7" /* HL7 */,
|
|
41
|
+
"unknown" /* UNKNOWN */
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
static {
|
|
45
|
+
this.contentTypes = [
|
|
46
|
+
"application/json" /* JSON */,
|
|
47
|
+
"text/csv" /* CSV */,
|
|
48
|
+
"application/xml" /* XML */,
|
|
49
|
+
"x-application/hl7-v2+er7" /* HL7V2 */
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
static {
|
|
53
|
+
this.editorLanguages = [
|
|
54
|
+
"json" /* JSON */,
|
|
55
|
+
"xml" /* XML */,
|
|
56
|
+
"plaintext" /* PLAINTEXT */
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
contentTypeToContentFormat(contentType) {
|
|
60
|
+
return _TypeConverter.contentTypeToContentFormatMap[contentType];
|
|
61
|
+
}
|
|
62
|
+
contentTypeToEditorLanguage(contentType) {
|
|
63
|
+
const format = this.contentTypeToContentFormat(contentType);
|
|
64
|
+
return this.contentFormatToEditorLanguage(format);
|
|
65
|
+
}
|
|
66
|
+
contentFormatToContentType(format) {
|
|
67
|
+
return _TypeConverter.contentFormatToContentTypeMap[format] || null;
|
|
68
|
+
}
|
|
69
|
+
contentFormatToEditorLanguage(format) {
|
|
70
|
+
return _TypeConverter.contentFormatToEditorLanguageMap[format];
|
|
71
|
+
}
|
|
72
|
+
stringToContentFormat(format) {
|
|
73
|
+
const normalizedFormat = format.toLowerCase();
|
|
74
|
+
return _TypeConverter.contentFormats.find((value) => value === normalizedFormat) || null;
|
|
75
|
+
}
|
|
76
|
+
stringToContentType(contentType) {
|
|
77
|
+
const normalizedContentType = contentType.toLowerCase();
|
|
78
|
+
return _TypeConverter.contentTypes.find((value) => normalizedContentType.startsWith(value)) || null;
|
|
79
|
+
}
|
|
80
|
+
stringToEditorLanguage(editorLanguage) {
|
|
81
|
+
const normalizedLanguage = editorLanguage.toLowerCase();
|
|
82
|
+
return _TypeConverter.editorLanguages.find((value) => value === normalizedLanguage) || null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var parseCsv = async (csv) => {
|
|
86
|
+
let json = {};
|
|
87
|
+
try {
|
|
88
|
+
json = await csvToJson().fromString(csv);
|
|
89
|
+
} catch {
|
|
90
|
+
json = [];
|
|
91
|
+
}
|
|
92
|
+
return json;
|
|
93
|
+
};
|
|
94
|
+
var ATTRIBUTE_PREFIX = "@_";
|
|
95
|
+
var parseXml = (xml) => {
|
|
96
|
+
xml = xml?.trim() || "";
|
|
97
|
+
if (xml === "") {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
const json = parseXmlWithXhtmlHandling(xml);
|
|
101
|
+
const values = [];
|
|
102
|
+
if (Object.keys(json).length === 1) {
|
|
103
|
+
const rootKey = Object.keys(json)[0];
|
|
104
|
+
if (Array.isArray(json[rootKey])) {
|
|
105
|
+
for (const jsonValue of json[rootKey]) {
|
|
106
|
+
values.push(standardizeJson(jsonValue, rootKey));
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
values.push(standardizeJson(json[rootKey], rootKey));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (Object.keys(json).length > 1) {
|
|
113
|
+
for (const rootKey of Object.keys(json)) {
|
|
114
|
+
values.push(standardizeJson(json[rootKey], rootKey));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return values.length === 1 ? values[0] : values;
|
|
118
|
+
};
|
|
119
|
+
var parseXmlWithXhtmlHandling = (xml) => {
|
|
120
|
+
const options = {
|
|
121
|
+
ignoreAttributes: false,
|
|
122
|
+
ignoreDeclaration: true,
|
|
123
|
+
attributeNamePrefix: ATTRIBUTE_PREFIX,
|
|
124
|
+
allowBooleanAttributes: true,
|
|
125
|
+
alwaysCreateTextNode: true,
|
|
126
|
+
numberParseOptions: {
|
|
127
|
+
leadingZeros: false,
|
|
128
|
+
hex: false,
|
|
129
|
+
skipLike: /\*/
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const firstParser = new XMLParser(options);
|
|
133
|
+
const firstParsing = firstParser.parse(xml, true);
|
|
134
|
+
const xhtmlPaths = getXhtmlPaths("", firstParsing, []);
|
|
135
|
+
if (xhtmlPaths.length === 0) {
|
|
136
|
+
return firstParsing;
|
|
137
|
+
}
|
|
138
|
+
options.stopNodes = [...new Set(xhtmlPaths)];
|
|
139
|
+
const secondParser = new XMLParser(options);
|
|
140
|
+
const secondParsing = secondParser.parse(xml);
|
|
141
|
+
return secondParsing;
|
|
142
|
+
};
|
|
143
|
+
var getXhtmlPaths = (currentPath, currentValue, xhtmlPaths) => {
|
|
144
|
+
if (Array.isArray(currentValue)) {
|
|
145
|
+
for (let i = 0; i < currentValue.length; i++) {
|
|
146
|
+
getXhtmlPaths(`${currentPath}`, currentValue[i], xhtmlPaths);
|
|
147
|
+
}
|
|
148
|
+
} else if (typeof currentValue === "object") {
|
|
149
|
+
if (currentValue[`${ATTRIBUTE_PREFIX}xmlns`] === "http://www.w3.org/1999/xhtml") {
|
|
150
|
+
xhtmlPaths.push(currentPath);
|
|
151
|
+
} else {
|
|
152
|
+
for (const key of Object.keys(currentValue)) {
|
|
153
|
+
getXhtmlPaths(`${currentPath ? `${currentPath}.` : ""}${key}`, currentValue[key], xhtmlPaths);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return xhtmlPaths;
|
|
158
|
+
};
|
|
159
|
+
var standardizeJson = (json, rootKey) => {
|
|
160
|
+
const parsedXml = recursiveStandardize(json, rootKey);
|
|
161
|
+
const namespaceIndex = rootKey.indexOf(":");
|
|
162
|
+
const baseRootKey = namespaceIndex === -1 ? rootKey : rootKey.slice(namespaceIndex + 1);
|
|
163
|
+
const value = parsedXml[baseRootKey];
|
|
164
|
+
if (typeof value === "object") {
|
|
165
|
+
const namespaceIndex2 = rootKey.indexOf(":");
|
|
166
|
+
if (namespaceIndex2 !== -1) {
|
|
167
|
+
value._namespace = rootKey.slice(0, namespaceIndex2);
|
|
168
|
+
if (!value.resourceType) {
|
|
169
|
+
value._xmlTagName = baseRootKey;
|
|
170
|
+
}
|
|
171
|
+
} else if (!value.resourceType) {
|
|
172
|
+
value._xmlTagName = baseRootKey;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
};
|
|
177
|
+
var recursiveStandardize = (node, key) => {
|
|
178
|
+
const newNode = {};
|
|
179
|
+
let newKey = key;
|
|
180
|
+
let textValue;
|
|
181
|
+
const complexValue = {};
|
|
182
|
+
let valueAttribute;
|
|
183
|
+
const attributes = {};
|
|
184
|
+
for (const key2 of Object.keys(node)) {
|
|
185
|
+
if (key2 === "#text" && (typeof node[key2] !== "string" || node[key2].length > 0)) {
|
|
186
|
+
textValue = String(node[key2]);
|
|
187
|
+
} else if (key2.startsWith(ATTRIBUTE_PREFIX)) {
|
|
188
|
+
attributes[key2.slice(ATTRIBUTE_PREFIX.length)] = node[key2];
|
|
189
|
+
if (key2 === `${ATTRIBUTE_PREFIX}value`) {
|
|
190
|
+
valueAttribute = node[key2];
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
complexValue[key2] = node[key2];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const namespaceIndex = key.indexOf(":");
|
|
197
|
+
let namespaceValue;
|
|
198
|
+
if (namespaceIndex !== -1) {
|
|
199
|
+
newKey = key.slice(namespaceIndex + 1);
|
|
200
|
+
namespaceValue = key.slice(0, namespaceIndex);
|
|
201
|
+
}
|
|
202
|
+
const complexChildsObject = createComplexChildsObject(complexValue);
|
|
203
|
+
if (attributes.xmlns === "http://hl7.org/fhir") {
|
|
204
|
+
attributes.resourceType = newKey;
|
|
205
|
+
delete attributes.xmlns;
|
|
206
|
+
}
|
|
207
|
+
if (textValue && attributes.xmlns === "http://www.w3.org/1999/xhtml") {
|
|
208
|
+
textValue = `<${key}${buildAttributesString(attributes)}>${textValue}</${key}>`;
|
|
209
|
+
newNode[newKey] = textValue;
|
|
210
|
+
} else if (textValue) {
|
|
211
|
+
newNode[newKey] = textValue;
|
|
212
|
+
addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });
|
|
213
|
+
addInnerKeys(newNode, `_${newKey}`, attributes);
|
|
214
|
+
} else if (valueAttribute) {
|
|
215
|
+
newNode[newKey] = valueAttribute;
|
|
216
|
+
addInnerKeys(newNode, `_${newKey}`, { _namespace: namespaceValue });
|
|
217
|
+
delete attributes.value;
|
|
218
|
+
addInnerKeys(newNode, `_${newKey}`, attributes);
|
|
219
|
+
addInnerKeys(newNode, `_${newKey}`, complexChildsObject);
|
|
220
|
+
} else if (Object.keys(complexChildsObject).length > 0) {
|
|
221
|
+
addInnerKeys(newNode, newKey, complexChildsObject);
|
|
222
|
+
addInnerKeys(newNode, newKey, { _namespace: namespaceValue });
|
|
223
|
+
addInnerKeys(newNode, newKey, attributes);
|
|
224
|
+
} else if (Object.keys(attributes).length > 0) {
|
|
225
|
+
addInnerKeys(newNode, newKey, { _namespace: namespaceValue });
|
|
226
|
+
addInnerKeys(newNode, newKey, attributes);
|
|
227
|
+
}
|
|
228
|
+
return newNode;
|
|
229
|
+
};
|
|
230
|
+
var createComplexChildsObject = (complexChilds) => {
|
|
231
|
+
const complexChildsObject = {};
|
|
232
|
+
for (const childKey of Object.keys(complexChilds)) {
|
|
233
|
+
if (Array.isArray(complexChilds[childKey])) {
|
|
234
|
+
const childValues = complexChilds[childKey];
|
|
235
|
+
for (const childValue of childValues) {
|
|
236
|
+
const child = recursiveStandardize(childValue, childKey);
|
|
237
|
+
addChildToParent(complexChildsObject, child);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
const child = recursiveStandardize(complexChilds[childKey], childKey);
|
|
241
|
+
addChildToParent(complexChildsObject, child);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return complexChildsObject;
|
|
245
|
+
};
|
|
246
|
+
var addChildToParent = (parentNode, child) => {
|
|
247
|
+
const childKey = Object.keys(child).find((key2) => !key2.startsWith("_"));
|
|
248
|
+
const childAttKey = Object.keys(child).find((key2) => key2.startsWith("_"));
|
|
249
|
+
if (childKey === void 0 && childAttKey === void 0) return;
|
|
250
|
+
const key = childKey ?? childAttKey.slice(1);
|
|
251
|
+
const attKey = childAttKey ?? `_${childKey}`;
|
|
252
|
+
if (parentNode[key] || parentNode[attKey]) {
|
|
253
|
+
const keySize = parentNode[key] ? Array.isArray(parentNode[key]) ? parentNode[key].length : 1 : 0;
|
|
254
|
+
const attKeySize = parentNode[attKey] ? Array.isArray(parentNode[attKey]) ? parentNode[attKey].length : 1 : 0;
|
|
255
|
+
if (keySize > 1) {
|
|
256
|
+
parentNode[key].push(child[key] ?? null);
|
|
257
|
+
} else if (keySize === 1) {
|
|
258
|
+
parentNode[key] = [parentNode[key], child[key] ?? null];
|
|
259
|
+
} else if (childKey) {
|
|
260
|
+
parentNode[key] = Array.from({ length: attKeySize }, (x, i) => null);
|
|
261
|
+
parentNode[key].push(child[key] ?? null);
|
|
262
|
+
}
|
|
263
|
+
if (attKeySize > 1) {
|
|
264
|
+
parentNode[attKey].push(child[attKey] ?? null);
|
|
265
|
+
} else if (attKeySize === 1) {
|
|
266
|
+
parentNode[attKey] = [parentNode[attKey], child[attKey] ?? null];
|
|
267
|
+
} else if (childAttKey) {
|
|
268
|
+
parentNode[attKey] = Array.from({ length: keySize }, (x, i) => null);
|
|
269
|
+
parentNode[attKey].push(child[attKey] ?? null);
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
if (childKey) {
|
|
273
|
+
parentNode[key] = child[key];
|
|
274
|
+
}
|
|
275
|
+
if (childAttKey) {
|
|
276
|
+
parentNode[attKey] = child[attKey];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var addInnerKeys = (object, key, innerObject) => {
|
|
281
|
+
for (const innerKey of Object.keys(innerObject)) {
|
|
282
|
+
addInnerKey(object, key, innerKey, innerObject[innerKey]);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var addInnerKey = (object, key, innerKey, innerValue) => {
|
|
286
|
+
if (innerValue === void 0) return;
|
|
287
|
+
if (object[key] === void 0) {
|
|
288
|
+
object[key] = {};
|
|
289
|
+
}
|
|
290
|
+
if (innerKey === "resourceType") {
|
|
291
|
+
object[key] = {
|
|
292
|
+
resourceType: innerValue,
|
|
293
|
+
...object[key]
|
|
294
|
+
};
|
|
295
|
+
} else {
|
|
296
|
+
object[key][innerKey] = innerValue;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
var buildAttributesString = (attributs) => {
|
|
300
|
+
let string = "";
|
|
301
|
+
for (const key of Object.keys(attributs)) {
|
|
302
|
+
string += ` ${key}="${attributs[key]}"`;
|
|
303
|
+
}
|
|
304
|
+
return string;
|
|
305
|
+
};
|
|
306
|
+
var v2parse = async (msg) => {
|
|
307
|
+
msg = msg.replace(/(?:\r\n|\r|\n)/g, "\r\n");
|
|
308
|
+
const v2reader = new hl7js.Reader("BASIC");
|
|
309
|
+
return await new Promise((resolve, reject) => {
|
|
310
|
+
v2reader.read(msg, function(err, hl7Data) {
|
|
311
|
+
if (err) {
|
|
312
|
+
reject(new Error(`Transformation error: ${JSON.stringify(err)}`));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
return resolve(hl7Data);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
var getV2DatatypeDef = (datatype, v2version) => {
|
|
320
|
+
return HL7Dictionary.definitions[v2version].fields[datatype];
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/converters/hl7v2/cache.ts
|
|
324
|
+
var SimpleCache = class {
|
|
325
|
+
constructor() {
|
|
326
|
+
this.cache = {};
|
|
327
|
+
this.get = (key) => this.cache[key];
|
|
328
|
+
this.set = (key, value) => this.cache[key] = value;
|
|
329
|
+
this.getDict = () => this.cache;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var v2keyMap = new SimpleCache();
|
|
333
|
+
var cache = { v2keyMap };
|
|
334
|
+
var getCache = () => cache;
|
|
335
|
+
var expressions = {
|
|
336
|
+
v2jsonExpression: jsonata(`(
|
|
337
|
+
$rawJson := $v2parse($);
|
|
338
|
+
$v2version := $rawJson.segments[0].\`12\`;
|
|
339
|
+
|
|
340
|
+
$dtToIso := function($dt){(
|
|
341
|
+
$y := $substring($dt,0,4);
|
|
342
|
+
$m := $substring($dt,4,2);
|
|
343
|
+
$d := $substring($dt,6,2);
|
|
344
|
+
$join([$y,$m,$d],'-')
|
|
345
|
+
)};
|
|
346
|
+
|
|
347
|
+
$dtmToIso := function($dtm){(
|
|
348
|
+
$dt := $dtToIso($dtm);
|
|
349
|
+
$hh := $substring($dtm,8,2);
|
|
350
|
+
$mm := $substring($dtm,10,2);
|
|
351
|
+
$ss := $substring($dtm,12,2);
|
|
352
|
+
$tm := $join([($hh!=''?$hh),($mm!=''?$mm),($ss!=''?$ss)],':');
|
|
353
|
+
$dt & ($tm!=''? 'T' & $tm)
|
|
354
|
+
)};
|
|
355
|
+
|
|
356
|
+
$parseValue := function($value, $datatype){(
|
|
357
|
+
$value = ''
|
|
358
|
+
?
|
|
359
|
+
undefined
|
|
360
|
+
: $value.(
|
|
361
|
+
$datatype = 'DT' ? $dtToIso($) : ($datatype = 'DTM' ? $dtmToIso($) : $)
|
|
362
|
+
)
|
|
363
|
+
)};
|
|
364
|
+
|
|
365
|
+
$translateSubfield := function($subfield, $datatypeDef, $sfi){(
|
|
366
|
+
$subfieldDef := $datatypeDef.subfields[$sfi];
|
|
367
|
+
$subfieldDesc := $subfieldDef.desc;
|
|
368
|
+
$subfieldDatatype := $subfieldDef.datatype;
|
|
369
|
+
$sfDataTypeDef := $getDatatypeDef($subfieldDatatype, $v2version);
|
|
370
|
+
$isComplex := $count($sfDataTypeDef.subfields)>0;
|
|
371
|
+
$hasChildren := $count($subfield.fields)>0;
|
|
372
|
+
|
|
373
|
+
$value := (
|
|
374
|
+
$isComplex = false
|
|
375
|
+
? $parseValue($subfield.value, $subfieldDatatype)
|
|
376
|
+
: (
|
|
377
|
+
/* it's a complex type */
|
|
378
|
+
$hasChildren
|
|
379
|
+
? (
|
|
380
|
+
/* input has children */
|
|
381
|
+
$subfield.fields@$subsubfield#$ssfi.$translateSubfield($subsubfield, $sfDataTypeDef, $ssfi){
|
|
382
|
+
$normalizeKey(name): value
|
|
383
|
+
};
|
|
384
|
+
)
|
|
385
|
+
: (
|
|
386
|
+
/* input doesn't have children */
|
|
387
|
+
$translateSubfield({'value': $subfield.value}, $sfDataTypeDef, 0){
|
|
388
|
+
$normalizeKey(name): value
|
|
389
|
+
}
|
|
390
|
+
)
|
|
391
|
+
)
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
{
|
|
395
|
+
'name': $subfieldDesc,
|
|
396
|
+
'value': $value != {} ? $value
|
|
397
|
+
}
|
|
398
|
+
)};
|
|
399
|
+
|
|
400
|
+
$translateField := function($field, $segDef, $fieldIndex){(
|
|
401
|
+
$fieldDef := $segDef.fields[$fieldIndex];
|
|
402
|
+
$fieldDef := $exists($fieldDef)=false ? {'name': $segDef.segmentId & ($fieldIndex + 1)} : $fieldDef;
|
|
403
|
+
$fieldDesc := $fieldDef.desc ? $fieldDef.desc : $fieldDef.name;
|
|
404
|
+
$fieldDesc := $type($fieldDesc) = 'string' and $startsWith($fieldDesc,'Set ID - ') and $fieldIndex=0 ? 'SetID' : $fieldDesc;
|
|
405
|
+
$fieldDatatype := $fieldDef.datatype;
|
|
406
|
+
$datatypeDef := $getDatatypeDef($fieldDatatype, $v2version);
|
|
407
|
+
$isEnc := $segDef.segmentId='MSH' and $fieldIndex=1;
|
|
408
|
+
$isComplex := $count($datatypeDef.subfields)>0;
|
|
409
|
+
$hasChildren := $count($field.fields)>0;
|
|
410
|
+
|
|
411
|
+
$value := (
|
|
412
|
+
$isEnc ? $field.value : (
|
|
413
|
+
$isComplex = false
|
|
414
|
+
? $parseValue($field.value, $fieldDatatype)
|
|
415
|
+
: (
|
|
416
|
+
/* it's a complex type */
|
|
417
|
+
$hasChildren
|
|
418
|
+
? (
|
|
419
|
+
/* input has children */
|
|
420
|
+
$field.fields@$subfield#$sfi.$translateSubfield($subfield, $datatypeDef, $sfi){
|
|
421
|
+
$normalizeKey(name): value
|
|
422
|
+
};
|
|
423
|
+
)
|
|
424
|
+
: (
|
|
425
|
+
/* input doesn't have children */
|
|
426
|
+
$translateSubfield({'value': $field.value}, $datatypeDef, 0){
|
|
427
|
+
$normalizeKey(name): value
|
|
428
|
+
}
|
|
429
|
+
)
|
|
430
|
+
)
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
$value := $value = {} ? undefined : $value;
|
|
434
|
+
|
|
435
|
+
{
|
|
436
|
+
'name': $fieldDesc,
|
|
437
|
+
'value': $value
|
|
438
|
+
};
|
|
439
|
+
)};
|
|
440
|
+
|
|
441
|
+
$translateSegment := function($segment){(
|
|
442
|
+
$line := $segment.MessageLine;
|
|
443
|
+
$segId := $segment.\`0\`;
|
|
444
|
+
$segDef := $getSegmentDef($segId, $v2version);
|
|
445
|
+
$segment.fields#$i[$i>0].$translateField($, $segDef, $i-1){
|
|
446
|
+
'SegmentDescription': $segDef.desc,
|
|
447
|
+
'MessageLine': $line,
|
|
448
|
+
$normalizeKey(name): value
|
|
449
|
+
}
|
|
450
|
+
)};
|
|
451
|
+
|
|
452
|
+
$segmentsWithLines := $rawJson.segments#$line.($merge([$, {'MessageLine': $line+1}]));
|
|
453
|
+
|
|
454
|
+
$segmentsWithLines@$s.$translateSegment($s){
|
|
455
|
+
$s.\`0\`: $
|
|
456
|
+
};
|
|
457
|
+
)`),
|
|
458
|
+
v2normalizeKey: jsonata(`(
|
|
459
|
+
$cached := $lookup($keyMap, $);
|
|
460
|
+
$exists($cached) = false
|
|
461
|
+
? (
|
|
462
|
+
$titleCased := ($split($initCap($replace($,"'", '')), ' ')~>$join);
|
|
463
|
+
$dtmFixed := $titleCased.$replace('Date/Time', 'DateTime') ~> $replace('Date / Time', 'DateTime');$underscored := $replace($dtmFixed, /[-+".()\\//]/, '_');
|
|
464
|
+
$registerV2key($, $underscored);
|
|
465
|
+
$underscored;
|
|
466
|
+
)
|
|
467
|
+
: ($cached);
|
|
468
|
+
)`),
|
|
469
|
+
initCap: jsonata(`(
|
|
470
|
+
$words := $trim($)~>$split(" ");
|
|
471
|
+
($words.$initCapOnce($))~>$join(' ')
|
|
472
|
+
)`)
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// src/converters/hl7v2/registerV2key.ts
|
|
476
|
+
var registerV2key = (key, normalized) => {
|
|
477
|
+
getCache().v2keyMap.set(key, normalized);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// src/converters/hl7v2/stringFuncations.ts
|
|
481
|
+
var startsWith = (str, startStr) => {
|
|
482
|
+
if (typeof str === "undefined") return void 0;
|
|
483
|
+
return str.startsWith(startStr);
|
|
484
|
+
};
|
|
485
|
+
var initCapOnce = (str) => {
|
|
486
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
487
|
+
};
|
|
488
|
+
var initCap = (str) => {
|
|
489
|
+
return expressions.initCap.evaluate(str, { initCapOnce });
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// src/converters/hl7v2/v2normalizeKey.ts
|
|
493
|
+
var v2normalizeKey = async (key) => {
|
|
494
|
+
const bindings = {
|
|
495
|
+
initCap,
|
|
496
|
+
registerV2key,
|
|
497
|
+
keyMap: getCache().v2keyMap.getDict()
|
|
498
|
+
};
|
|
499
|
+
const res = await expressions.v2normalizeKey.evaluate(key, bindings);
|
|
500
|
+
return res;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/converters/hl7v2/v2json.ts
|
|
504
|
+
var getV2SegmentDef = (segmentId, v2version) => {
|
|
505
|
+
const segDef = HL7Dictionary.definitions[v2version].segments[segmentId];
|
|
506
|
+
return { segmentId, ...segDef };
|
|
507
|
+
};
|
|
508
|
+
var v2json = async (message) => {
|
|
509
|
+
const bindings = {
|
|
510
|
+
v2parse,
|
|
511
|
+
startsWith,
|
|
512
|
+
normalizeKey: v2normalizeKey,
|
|
513
|
+
getSegmentDef: getV2SegmentDef,
|
|
514
|
+
getDatatypeDef: getV2DatatypeDef
|
|
515
|
+
};
|
|
516
|
+
const res = await expressions.v2jsonExpression.evaluate(message, bindings);
|
|
517
|
+
return res;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/FormatConverter.ts
|
|
521
|
+
var noopLogger = {
|
|
522
|
+
info: () => {
|
|
523
|
+
},
|
|
524
|
+
warn: () => {
|
|
525
|
+
},
|
|
526
|
+
error: () => {
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
var FormatConverter = class _FormatConverter {
|
|
530
|
+
constructor(logger) {
|
|
531
|
+
this.csvToJson = parseCsv;
|
|
532
|
+
this.hl7v2ToJson = v2json;
|
|
533
|
+
this.logger = logger || noopLogger;
|
|
534
|
+
}
|
|
535
|
+
static {
|
|
536
|
+
this.typeConverter = new TypeConverter();
|
|
537
|
+
}
|
|
538
|
+
async toJson(input, contentType) {
|
|
539
|
+
if (!contentType || contentType === "") {
|
|
540
|
+
this.logger.info("No content type provided, defaulting to 'application/json'");
|
|
541
|
+
contentType = "application/json" /* JSON */;
|
|
542
|
+
}
|
|
543
|
+
const suggestedContentType = typeof contentType === "string" ? _FormatConverter.typeConverter.stringToContentType(contentType) : contentType;
|
|
544
|
+
if (!suggestedContentType) {
|
|
545
|
+
throw new Error(`Unsupported Content-Type: ${suggestedContentType}`);
|
|
546
|
+
}
|
|
547
|
+
let parsedJson;
|
|
548
|
+
if (suggestedContentType === "x-application/hl7-v2+er7" /* HL7V2 */) {
|
|
549
|
+
this.logger.info("Content-Type suggests HL7 V2.x message");
|
|
550
|
+
this.logger.info("Trying to parse HL7 V2.x message as JSON...");
|
|
551
|
+
parsedJson = await this.hl7v2ToJson(input);
|
|
552
|
+
this.logger.info("Parsed HL7 V2.x message to JSON successfully.");
|
|
553
|
+
} else if (suggestedContentType === "text/csv" /* CSV */) {
|
|
554
|
+
this.logger.info("Content-Type suggests CSV input");
|
|
555
|
+
this.logger.info("Trying to parse CSV as JSON...");
|
|
556
|
+
parsedJson = await this.csvToJson(input);
|
|
557
|
+
this.logger.info("Parsed CSV to JSON successfully.");
|
|
558
|
+
} else if (suggestedContentType === "application/xml" /* XML */) {
|
|
559
|
+
this.logger.info("Content-Type suggests XML input");
|
|
560
|
+
this.logger.info("Trying to parse XML as JSON...");
|
|
561
|
+
parsedJson = await this.xmlToJson(input);
|
|
562
|
+
this.logger.info("Parsed XML to JSON successfully.");
|
|
563
|
+
} else if (suggestedContentType === "application/json" /* JSON */) {
|
|
564
|
+
this.logger.info("Content-Type suggests JSON input");
|
|
565
|
+
parsedJson = input;
|
|
566
|
+
this.logger.info("Parsed input to JSON successfully.");
|
|
567
|
+
} else {
|
|
568
|
+
throw new Error("Unsupported Content-Type encountered during processing.");
|
|
569
|
+
}
|
|
570
|
+
return parsedJson;
|
|
571
|
+
}
|
|
572
|
+
xmlToJson(input) {
|
|
573
|
+
return Promise.resolve(parseXml(input));
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
export { FormatConverter, TypeConverter };
|
|
578
|
+
//# sourceMappingURL=index.mjs.map
|
|
579
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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":["namespaceIndex","key","HL7Dictionary"],"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;AAAA,MAClB,CAAA,KAAA,aAAkB,WAAA;AAAA,MAClB,CAAA,KAAA,aAAkB,WAAA;AAAA,MAClB,CAAA,SAAA,iBAAsB,WAAA;AAAA,KACxB;AAAA;AAAA,EAEA;AAAA,IAAA,IAAA,CAAe,cAAA,GAAkC;AAAA,MAAA,MAAA;AAAA,MAAA,KAAA;AAAA,MAAA,KAAA;AAAA,MAAA,KAAA;AAAA,MAAA,SAAA;AAAA,KAMjD;AAAA;AAAA,EAEA;AAAA,IAAA,IAAA,CAAe,YAAA,G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AO,KAAK,6CAA6C,CAAA;AAC9D,MAAA,UAAA,GAAa,MAAM,IAAA,CAAK,WAAA,CAAY,KAAK,CAAA;AACzC,MAAA,IAAA,CAAK,MAAA,CAAO,KAAK,+CAA+C,CAAA;AAAA,IAClE,WAAW,oBAAA,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}"]}
|