@openfn/language-fhir-4 0.2.9 → 0.3.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/dist/index.cjs +107 -7
- package/dist/index.js +106 -7
- package/package.json +3 -3
- package/types/builders.d.ts +495 -526
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(src_exports, {
|
|
|
29
29
|
b: () => builders_exports,
|
|
30
30
|
builders: () => builders_exports,
|
|
31
31
|
create: () => create,
|
|
32
|
+
createBundle: () => createBundle,
|
|
32
33
|
cursor: () => import_language_common3.cursor,
|
|
33
34
|
dataPath: () => import_language_common3.dataPath,
|
|
34
35
|
dataValue: () => import_language_common3.dataValue,
|
|
@@ -55,6 +56,7 @@ var Adaptor_exports = {};
|
|
|
55
56
|
__export(Adaptor_exports, {
|
|
56
57
|
addToBundle: () => addToBundle,
|
|
57
58
|
create: () => create,
|
|
59
|
+
createBundle: () => createBundle,
|
|
58
60
|
cursor: () => import_language_common3.cursor,
|
|
59
61
|
dataPath: () => import_language_common3.dataPath,
|
|
60
62
|
dataValue: () => import_language_common3.dataValue,
|
|
@@ -156,6 +158,67 @@ var request = (method, path, options) => {
|
|
|
156
158
|
throw e;
|
|
157
159
|
});
|
|
158
160
|
};
|
|
161
|
+
function collectRefs(value2) {
|
|
162
|
+
if (!value2 || typeof value2 !== "object")
|
|
163
|
+
return [];
|
|
164
|
+
if (Array.isArray(value2))
|
|
165
|
+
return value2.flatMap(collectRefs);
|
|
166
|
+
const refs = [];
|
|
167
|
+
if (typeof value2.reference === "string") {
|
|
168
|
+
refs.push(value2.reference);
|
|
169
|
+
}
|
|
170
|
+
for (const v of Object.values(value2)) {
|
|
171
|
+
refs.push(...collectRefs(v));
|
|
172
|
+
}
|
|
173
|
+
return refs;
|
|
174
|
+
}
|
|
175
|
+
function sortBundle(entries) {
|
|
176
|
+
const indexByRef = /* @__PURE__ */ new Map();
|
|
177
|
+
for (let i = 0; i < entries.length; i++) {
|
|
178
|
+
const { resourceType, id: id2 } = entries[i].resource;
|
|
179
|
+
if (resourceType && id2) {
|
|
180
|
+
indexByRef.set(`${resourceType}/${id2}`, i);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const n = entries.length;
|
|
184
|
+
const inDegree = new Array(n).fill(0);
|
|
185
|
+
const adj = Array.from({ length: n }, () => []);
|
|
186
|
+
for (let i = 0; i < n; i++) {
|
|
187
|
+
const deps = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const ref2 of collectRefs(entries[i].resource)) {
|
|
189
|
+
const j = indexByRef.get(ref2);
|
|
190
|
+
if (j !== void 0 && j !== i)
|
|
191
|
+
deps.add(j);
|
|
192
|
+
}
|
|
193
|
+
for (const j of deps) {
|
|
194
|
+
adj[j].push(i);
|
|
195
|
+
inDegree[i]++;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const queue = [];
|
|
199
|
+
for (let i = 0; i < n; i++) {
|
|
200
|
+
if (inDegree[i] === 0)
|
|
201
|
+
queue.push(i);
|
|
202
|
+
}
|
|
203
|
+
const result = [];
|
|
204
|
+
while (queue.length > 0) {
|
|
205
|
+
const idx = queue.shift();
|
|
206
|
+
result.push(entries[idx]);
|
|
207
|
+
for (const dep of adj[idx]) {
|
|
208
|
+
if (--inDegree[dep] === 0) {
|
|
209
|
+
let k = 0;
|
|
210
|
+
while (k < queue.length && queue[k] < dep)
|
|
211
|
+
k++;
|
|
212
|
+
queue.splice(k, 0, dep);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (let i = 0; i < n; i++) {
|
|
217
|
+
if (inDegree[i] > 0)
|
|
218
|
+
result.push(entries[i]);
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
159
222
|
|
|
160
223
|
// src/Adaptor.ts
|
|
161
224
|
var import_language_common3 = require("@openfn/language-common");
|
|
@@ -266,6 +329,18 @@ function create(resource) {
|
|
|
266
329
|
return prepareNextState(state, response);
|
|
267
330
|
};
|
|
268
331
|
}
|
|
332
|
+
function createBundle(options, props = {}) {
|
|
333
|
+
return (state) => {
|
|
334
|
+
const [{ name = "bundle", type = "transaction" }, $props] = (0, import_util2.expandReferences)(state, options, props);
|
|
335
|
+
state[name] = {
|
|
336
|
+
resourceType: "Bundle",
|
|
337
|
+
type,
|
|
338
|
+
entry: [],
|
|
339
|
+
...props
|
|
340
|
+
};
|
|
341
|
+
return state;
|
|
342
|
+
};
|
|
343
|
+
}
|
|
269
344
|
function addToBundle(resources, name = "bundle") {
|
|
270
345
|
return (state) => {
|
|
271
346
|
let [$resources, $name] = (0, import_util2.expandReferences)(state, resources, name);
|
|
@@ -309,6 +384,7 @@ function uploadBundle(bundle = "bundle") {
|
|
|
309
384
|
bundle: $bundle ?? "bundle (default)"
|
|
310
385
|
});
|
|
311
386
|
}
|
|
387
|
+
data.entry = sortBundle(data.entry);
|
|
312
388
|
const response = await request("POST", "/", {
|
|
313
389
|
configuration: state.configuration,
|
|
314
390
|
body: data
|
|
@@ -361,6 +437,7 @@ __export(builders_exports, {
|
|
|
361
437
|
encounter: () => encounter,
|
|
362
438
|
enrollmentRequest: () => enrollmentRequest,
|
|
363
439
|
enrollmentResponse: () => enrollmentResponse,
|
|
440
|
+
ensureConceptText: () => ensureConceptText,
|
|
364
441
|
episodeOfCare: () => episodeOfCare,
|
|
365
442
|
eventDefinition: () => eventDefinition,
|
|
366
443
|
evidence: () => evidence,
|
|
@@ -462,6 +539,7 @@ __export(datatypes_exports, {
|
|
|
462
539
|
coding: () => coding,
|
|
463
540
|
composite: () => composite,
|
|
464
541
|
concept: () => concept,
|
|
542
|
+
ensureConceptText: () => ensureConceptText,
|
|
465
543
|
ext: () => ext,
|
|
466
544
|
extendSystemMap: () => extendSystemMap,
|
|
467
545
|
extendValues: () => extendValues,
|
|
@@ -483,7 +561,25 @@ var systemMap = {};
|
|
|
483
561
|
var datetimeregex = /^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?$/;
|
|
484
562
|
var defaultValues = {};
|
|
485
563
|
var userValues = {};
|
|
564
|
+
var mapExtraKeys = (values, keys = ["display"]) => {
|
|
565
|
+
const result = { ...values };
|
|
566
|
+
try {
|
|
567
|
+
for (const code in values) {
|
|
568
|
+
const v = values[code];
|
|
569
|
+
if (typeof v !== "string") {
|
|
570
|
+
for (const key of keys) {
|
|
571
|
+
if (key in v) {
|
|
572
|
+
result[v[key]] = v;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
} catch (e) {
|
|
578
|
+
}
|
|
579
|
+
return result;
|
|
580
|
+
};
|
|
486
581
|
var setValues = (url, values, type = "user") => {
|
|
582
|
+
values = mapExtraKeys(values);
|
|
487
583
|
if (type === "default") {
|
|
488
584
|
defaultValues[url] ?? (defaultValues[url] = {});
|
|
489
585
|
defaultValues[url] = values;
|
|
@@ -493,6 +589,7 @@ var setValues = (url, values, type = "user") => {
|
|
|
493
589
|
}
|
|
494
590
|
};
|
|
495
591
|
var extendValues = (url, values, type = "user") => {
|
|
592
|
+
values = mapExtraKeys(values);
|
|
496
593
|
if (type === "default") {
|
|
497
594
|
defaultValues[url] ?? (defaultValues[url] = {});
|
|
498
595
|
Object.assign(defaultValues[url], values);
|
|
@@ -538,13 +635,9 @@ var identifier = (id2, ext2 = [], valueHints = {}) => {
|
|
|
538
635
|
if (Array.isArray(id2)) {
|
|
539
636
|
return id2.map((i2) => identifier(i2, ext2, valueHints));
|
|
540
637
|
}
|
|
541
|
-
const i = mapValues(id2, valueHints);
|
|
542
|
-
if (
|
|
543
|
-
i.
|
|
544
|
-
} else {
|
|
545
|
-
if (i.type) {
|
|
546
|
-
i.type = concept(i.type);
|
|
547
|
-
}
|
|
638
|
+
const i = typeof id2 === "string" ? mapValues({ value: id2 }, valueHints) : mapValues(id2, valueHints);
|
|
639
|
+
if (i.type) {
|
|
640
|
+
i.type = concept(i.type);
|
|
548
641
|
}
|
|
549
642
|
ext2 == null ? void 0 : ext2.forEach((e) => {
|
|
550
643
|
addExtension(i, e.url, e.value);
|
|
@@ -615,6 +708,12 @@ var concept = (codings, extra = {}) => {
|
|
|
615
708
|
};
|
|
616
709
|
};
|
|
617
710
|
var cc = concept;
|
|
711
|
+
var ensureConceptText = (concept2) => {
|
|
712
|
+
var _a;
|
|
713
|
+
if (!concept2.text && ((_a = concept2.coding) == null ? void 0 : _a.length)) {
|
|
714
|
+
concept2.text = concept2.coding[0].display;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
618
717
|
var reference = (ref2, opts = {}) => {
|
|
619
718
|
if (Array.isArray(ref2)) {
|
|
620
719
|
return ref2.map(reference, opts);
|
|
@@ -9925,6 +10024,7 @@ var src_default = Adaptor_exports;
|
|
|
9925
10024
|
b,
|
|
9926
10025
|
builders,
|
|
9927
10026
|
create,
|
|
10027
|
+
createBundle,
|
|
9928
10028
|
cursor,
|
|
9929
10029
|
dataPath,
|
|
9930
10030
|
dataValue,
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var Adaptor_exports = {};
|
|
|
9
9
|
__export(Adaptor_exports, {
|
|
10
10
|
addToBundle: () => addToBundle,
|
|
11
11
|
create: () => create,
|
|
12
|
+
createBundle: () => createBundle,
|
|
12
13
|
cursor: () => cursor,
|
|
13
14
|
dataPath: () => dataPath,
|
|
14
15
|
dataValue: () => dataValue,
|
|
@@ -115,6 +116,67 @@ var request = (method, path, options) => {
|
|
|
115
116
|
throw e;
|
|
116
117
|
});
|
|
117
118
|
};
|
|
119
|
+
function collectRefs(value2) {
|
|
120
|
+
if (!value2 || typeof value2 !== "object")
|
|
121
|
+
return [];
|
|
122
|
+
if (Array.isArray(value2))
|
|
123
|
+
return value2.flatMap(collectRefs);
|
|
124
|
+
const refs = [];
|
|
125
|
+
if (typeof value2.reference === "string") {
|
|
126
|
+
refs.push(value2.reference);
|
|
127
|
+
}
|
|
128
|
+
for (const v of Object.values(value2)) {
|
|
129
|
+
refs.push(...collectRefs(v));
|
|
130
|
+
}
|
|
131
|
+
return refs;
|
|
132
|
+
}
|
|
133
|
+
function sortBundle(entries) {
|
|
134
|
+
const indexByRef = /* @__PURE__ */ new Map();
|
|
135
|
+
for (let i = 0; i < entries.length; i++) {
|
|
136
|
+
const { resourceType, id: id2 } = entries[i].resource;
|
|
137
|
+
if (resourceType && id2) {
|
|
138
|
+
indexByRef.set(`${resourceType}/${id2}`, i);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const n = entries.length;
|
|
142
|
+
const inDegree = new Array(n).fill(0);
|
|
143
|
+
const adj = Array.from({ length: n }, () => []);
|
|
144
|
+
for (let i = 0; i < n; i++) {
|
|
145
|
+
const deps = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const ref2 of collectRefs(entries[i].resource)) {
|
|
147
|
+
const j = indexByRef.get(ref2);
|
|
148
|
+
if (j !== void 0 && j !== i)
|
|
149
|
+
deps.add(j);
|
|
150
|
+
}
|
|
151
|
+
for (const j of deps) {
|
|
152
|
+
adj[j].push(i);
|
|
153
|
+
inDegree[i]++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const queue = [];
|
|
157
|
+
for (let i = 0; i < n; i++) {
|
|
158
|
+
if (inDegree[i] === 0)
|
|
159
|
+
queue.push(i);
|
|
160
|
+
}
|
|
161
|
+
const result = [];
|
|
162
|
+
while (queue.length > 0) {
|
|
163
|
+
const idx = queue.shift();
|
|
164
|
+
result.push(entries[idx]);
|
|
165
|
+
for (const dep of adj[idx]) {
|
|
166
|
+
if (--inDegree[dep] === 0) {
|
|
167
|
+
let k = 0;
|
|
168
|
+
while (k < queue.length && queue[k] < dep)
|
|
169
|
+
k++;
|
|
170
|
+
queue.splice(k, 0, dep);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (let i = 0; i < n; i++) {
|
|
175
|
+
if (inDegree[i] > 0)
|
|
176
|
+
result.push(entries[i]);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
118
180
|
|
|
119
181
|
// src/Adaptor.ts
|
|
120
182
|
import {
|
|
@@ -237,6 +299,18 @@ function create(resource) {
|
|
|
237
299
|
return prepareNextState(state, response);
|
|
238
300
|
};
|
|
239
301
|
}
|
|
302
|
+
function createBundle(options, props = {}) {
|
|
303
|
+
return (state) => {
|
|
304
|
+
const [{ name = "bundle", type = "transaction" }, $props] = expandReferences(state, options, props);
|
|
305
|
+
state[name] = {
|
|
306
|
+
resourceType: "Bundle",
|
|
307
|
+
type,
|
|
308
|
+
entry: [],
|
|
309
|
+
...props
|
|
310
|
+
};
|
|
311
|
+
return state;
|
|
312
|
+
};
|
|
313
|
+
}
|
|
240
314
|
function addToBundle(resources, name = "bundle") {
|
|
241
315
|
return (state) => {
|
|
242
316
|
let [$resources, $name] = expandReferences(state, resources, name);
|
|
@@ -280,6 +354,7 @@ function uploadBundle(bundle = "bundle") {
|
|
|
280
354
|
bundle: $bundle ?? "bundle (default)"
|
|
281
355
|
});
|
|
282
356
|
}
|
|
357
|
+
data.entry = sortBundle(data.entry);
|
|
283
358
|
const response = await request("POST", "/", {
|
|
284
359
|
configuration: state.configuration,
|
|
285
360
|
body: data
|
|
@@ -332,6 +407,7 @@ __export(builders_exports, {
|
|
|
332
407
|
encounter: () => encounter,
|
|
333
408
|
enrollmentRequest: () => enrollmentRequest,
|
|
334
409
|
enrollmentResponse: () => enrollmentResponse,
|
|
410
|
+
ensureConceptText: () => ensureConceptText,
|
|
335
411
|
episodeOfCare: () => episodeOfCare,
|
|
336
412
|
eventDefinition: () => eventDefinition,
|
|
337
413
|
evidence: () => evidence,
|
|
@@ -433,6 +509,7 @@ __export(datatypes_exports, {
|
|
|
433
509
|
coding: () => coding,
|
|
434
510
|
composite: () => composite,
|
|
435
511
|
concept: () => concept,
|
|
512
|
+
ensureConceptText: () => ensureConceptText,
|
|
436
513
|
ext: () => ext,
|
|
437
514
|
extendSystemMap: () => extendSystemMap,
|
|
438
515
|
extendValues: () => extendValues,
|
|
@@ -454,7 +531,25 @@ var systemMap = {};
|
|
|
454
531
|
var datetimeregex = /^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?$/;
|
|
455
532
|
var defaultValues = {};
|
|
456
533
|
var userValues = {};
|
|
534
|
+
var mapExtraKeys = (values, keys = ["display"]) => {
|
|
535
|
+
const result = { ...values };
|
|
536
|
+
try {
|
|
537
|
+
for (const code in values) {
|
|
538
|
+
const v = values[code];
|
|
539
|
+
if (typeof v !== "string") {
|
|
540
|
+
for (const key of keys) {
|
|
541
|
+
if (key in v) {
|
|
542
|
+
result[v[key]] = v;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
} catch (e) {
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
};
|
|
457
551
|
var setValues = (url, values, type = "user") => {
|
|
552
|
+
values = mapExtraKeys(values);
|
|
458
553
|
if (type === "default") {
|
|
459
554
|
defaultValues[url] ?? (defaultValues[url] = {});
|
|
460
555
|
defaultValues[url] = values;
|
|
@@ -464,6 +559,7 @@ var setValues = (url, values, type = "user") => {
|
|
|
464
559
|
}
|
|
465
560
|
};
|
|
466
561
|
var extendValues = (url, values, type = "user") => {
|
|
562
|
+
values = mapExtraKeys(values);
|
|
467
563
|
if (type === "default") {
|
|
468
564
|
defaultValues[url] ?? (defaultValues[url] = {});
|
|
469
565
|
Object.assign(defaultValues[url], values);
|
|
@@ -509,13 +605,9 @@ var identifier = (id2, ext2 = [], valueHints = {}) => {
|
|
|
509
605
|
if (Array.isArray(id2)) {
|
|
510
606
|
return id2.map((i2) => identifier(i2, ext2, valueHints));
|
|
511
607
|
}
|
|
512
|
-
const i = mapValues(id2, valueHints);
|
|
513
|
-
if (
|
|
514
|
-
i.
|
|
515
|
-
} else {
|
|
516
|
-
if (i.type) {
|
|
517
|
-
i.type = concept(i.type);
|
|
518
|
-
}
|
|
608
|
+
const i = typeof id2 === "string" ? mapValues({ value: id2 }, valueHints) : mapValues(id2, valueHints);
|
|
609
|
+
if (i.type) {
|
|
610
|
+
i.type = concept(i.type);
|
|
519
611
|
}
|
|
520
612
|
ext2 == null ? void 0 : ext2.forEach((e) => {
|
|
521
613
|
addExtension(i, e.url, e.value);
|
|
@@ -586,6 +678,12 @@ var concept = (codings, extra = {}) => {
|
|
|
586
678
|
};
|
|
587
679
|
};
|
|
588
680
|
var cc = concept;
|
|
681
|
+
var ensureConceptText = (concept2) => {
|
|
682
|
+
var _a;
|
|
683
|
+
if (!concept2.text && ((_a = concept2.coding) == null ? void 0 : _a.length)) {
|
|
684
|
+
concept2.text = concept2.coding[0].display;
|
|
685
|
+
}
|
|
686
|
+
};
|
|
589
687
|
var reference = (ref2, opts = {}) => {
|
|
590
688
|
if (Array.isArray(ref2)) {
|
|
591
689
|
return ref2.map(reference, opts);
|
|
@@ -9895,6 +9993,7 @@ export {
|
|
|
9895
9993
|
builders_exports as b,
|
|
9896
9994
|
builders_exports as builders,
|
|
9897
9995
|
create,
|
|
9996
|
+
createBundle,
|
|
9898
9997
|
cursor,
|
|
9899
9998
|
dataPath,
|
|
9900
9999
|
dataValue,
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-fhir-4",
|
|
3
3
|
"label": "FHIR r4",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "OpenFn FHIR r4 adaptor",
|
|
6
6
|
"author": "Open Function Group",
|
|
7
7
|
"license": "LGPLv3",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"fhir": {
|
|
10
10
|
"specUrl": "https://hl7.org/fhir/R4B/definitions.json.zip",
|
|
11
|
-
"adaptorGeneratedDate": "2026-02-
|
|
12
|
-
"generatorVersion": "0.
|
|
11
|
+
"adaptorGeneratedDate": "2026-02-24T16:33:46.057Z",
|
|
12
|
+
"generatorVersion": "0.7.0",
|
|
13
13
|
"options": {
|
|
14
14
|
"simpleBuilders": true
|
|
15
15
|
}
|