@petrarca/sonnet-fhir 0.0.1 → 0.9.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.
@@ -0,0 +1,1718 @@
1
+ // src/questionnaire/vocabulary.ts
2
+ var DATA_ABSENT_REASON = "http://hl7.org/fhir/StructureDefinition/data-absent-reason";
3
+ var ITEM_CONTROL = "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl";
4
+ var ITEM_CONTROL_SYSTEM = "http://hl7.org/fhir/questionnaire-item-control";
5
+ var UNIT_OPTION = "http://hl7.org/fhir/StructureDefinition/questionnaire-unitOption";
6
+ var MIN_LENGTH = "http://hl7.org/fhir/StructureDefinition/minLength";
7
+ var REGEX = "http://hl7.org/fhir/StructureDefinition/regex";
8
+ var MIN_VALUE = "http://hl7.org/fhir/StructureDefinition/minValue";
9
+ var MAX_VALUE = "http://hl7.org/fhir/StructureDefinition/maxValue";
10
+ var MIN_OCCURS = "http://hl7.org/fhir/StructureDefinition/questionnaire-minOccurs";
11
+ var MAX_OCCURS = "http://hl7.org/fhir/StructureDefinition/questionnaire-maxOccurs";
12
+ var OTHER_OPTION_EXTENSION = "https://schemas.petrarca-labs.com/fhir/StructureDefinition/questionnaire-otherOption";
13
+ var ENTRY_FORMAT = "http://hl7.org/fhir/StructureDefinition/entryFormat";
14
+ var X_FHIR = "x-fhir-";
15
+ var X_FHIR_LINK_ID = "x-fhir-linkId";
16
+ var X_FHIR_EXTENSION = "x-fhir-extension";
17
+ var X_FHIR_SYSTEM = "x-fhir-system";
18
+ var X_FHIR_HELP_LINK_ID = "x-fhir-helpLinkId";
19
+ var X_FHIR_LEAD_QUESTION = "x-fhir-leadQuestion";
20
+ var X_FHIR_ITEM = "x-fhir-item";
21
+ var FHIR_TYPE_INDEPENDENT_ANNOTATIONS = [
22
+ X_FHIR_LINK_ID,
23
+ X_FHIR_HELP_LINK_ID,
24
+ `${X_FHIR}prefix`,
25
+ `${X_FHIR}code`,
26
+ `${X_FHIR}definition`
27
+ ];
28
+ function isFhirAnnotation(keyword) {
29
+ return keyword.startsWith(X_FHIR);
30
+ }
31
+
32
+ // src/questionnaire/valueTypes.ts
33
+ import { UCUM_SYSTEM } from "@petrarca/sonnet-core/schema";
34
+ import {
35
+ QUANTITY_ANSWER
36
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
37
+
38
+ // src/questionnaire/codings.ts
39
+ function fromCodings(wrappers, also) {
40
+ const plain = wrappers.every(
41
+ (w) => Object.keys(w).every((k) => also.includes(k) || k === "valueCoding") && w.valueCoding && Object.keys(w.valueCoding).every(
42
+ (k) => ["system", "code", "display"].includes(k)
43
+ )
44
+ );
45
+ const systems = new Set(wrappers.map((w) => w.valueCoding?.system));
46
+ if (!plain || systems.size > 1) return void 0;
47
+ return {
48
+ options: wrappers.map((w) => ({
49
+ value: w.valueCoding.code,
50
+ label: w.valueCoding.display ?? w.valueCoding.code
51
+ })),
52
+ system: [...systems][0]
53
+ };
54
+ }
55
+
56
+ // src/questionnaire/coding.ts
57
+ import {
58
+ codeToken,
59
+ parseCodeToken
60
+ } from "@petrarca/sonnet-core/schema";
61
+ import { CODING_ANSWER } from "@petrarca/sonnet-schema-designer/questionnaire";
62
+
63
+ // src/questionnaire/itemControls.ts
64
+ var CONTROLS = {
65
+ singleChoice: { radio: "radio-button", select: "drop-down" },
66
+ multipleChoice: { "checkbox-group": "check-box", select: "drop-down" }
67
+ };
68
+ function itemControl(code) {
69
+ return {
70
+ url: ITEM_CONTROL,
71
+ valueCodeableConcept: {
72
+ coding: [{ system: ITEM_CONTROL_SYSTEM, code }]
73
+ }
74
+ };
75
+ }
76
+ function itemControlCode(e) {
77
+ const coding = e.valueCodeableConcept?.coding;
78
+ if (e.url !== ITEM_CONTROL || coding?.length !== 1) return void 0;
79
+ const [c] = coding;
80
+ const plain = Object.keys(c).every((k) => k === "system" || k === "code");
81
+ return plain && c.system === ITEM_CONTROL_SYSTEM ? c.code : void 0;
82
+ }
83
+ function controlOf(type, presentation) {
84
+ const code = presentation && CONTROLS[type]?.[presentation];
85
+ return code ? [itemControl(code)] : [];
86
+ }
87
+ function controlIn(item, controls) {
88
+ for (const extension of item.extension ?? []) {
89
+ const code = itemControlCode(extension);
90
+ const key = Object.entries(controls).find(([, c]) => c === code)?.[0];
91
+ if (key) return { key, extension };
92
+ }
93
+ return void 0;
94
+ }
95
+ function presentationOf(item, type) {
96
+ const controls = CONTROLS[type];
97
+ const read = controls && controlIn(item, controls);
98
+ return read && { widget: read.key, extension: read.extension };
99
+ }
100
+
101
+ // src/questionnaire/coding.ts
102
+ var MODE_CONTROLS = {
103
+ list: "drop-down",
104
+ search: "autocomplete"
105
+ };
106
+ var BAR = "|";
107
+ function listOf(context) {
108
+ const list = String(context.settings.list ?? "");
109
+ return context.settings.listKind === "system" ? { list, system: list } : { list };
110
+ }
111
+ function toCoding(c) {
112
+ return {
113
+ ...c.system ? { system: c.system } : {},
114
+ ...c.version ? { version: c.version } : {},
115
+ code: c.code,
116
+ ...c.display ? { display: c.display } : {}
117
+ };
118
+ }
119
+ function fromCoding(c) {
120
+ const version = typeof c.version === "string" ? c.version : void 0;
121
+ return {
122
+ system: c.system ?? "",
123
+ code: c.code,
124
+ ...version ? { version } : {},
125
+ ...c.display ? { display: c.display } : {}
126
+ };
127
+ }
128
+ var CODING_FHIR = {
129
+ answer: CODING_ANSWER,
130
+ // Several codes: a repeating item.
131
+ repeats: true,
132
+ // Spelled as a choice is: R4 choice / open-choice, R5 coding with its answerConstraint.
133
+ spell: (spelling, orText) => spelling.write("singleChoice", orText),
134
+ // A choice of codes from a value set, or from no list named -- one with its
135
+ // options listed is a choice.
136
+ claims: (item, spelling) => !item.answerOption && (spelling.isChoice(item) || spelling.isOpen(item)),
137
+ toItem(context) {
138
+ const { list, system } = listOf(context);
139
+ const version = context.settings.version;
140
+ const control = MODE_CONTROLS[String(context.settings.mode)];
141
+ const bound = list && !system;
142
+ return {
143
+ ...bound ? { answerValueSet: version ? `${list}${BAR}${version}` : list } : {},
144
+ ...control ? { extension: [itemControl(control)] } : {},
145
+ ...system ? {
146
+ notConverted: [
147
+ "a code system as the list: FHIR binds a question to a value set"
148
+ ]
149
+ } : {}
150
+ };
151
+ },
152
+ fromItem(item, spelling) {
153
+ const shown = controlIn(item, MODE_CONTROLS);
154
+ const canonical = item.answerValueSet ?? "";
155
+ const bar = canonical.indexOf(BAR);
156
+ return {
157
+ settings: {
158
+ list: bar < 0 ? canonical : canonical.slice(0, bar),
159
+ listKind: "valueSet",
160
+ version: bar < 0 ? "" : canonical.slice(bar + 1),
161
+ strength: spelling.isOpen(item) ? "extensible" : "required",
162
+ several: item.repeats === true,
163
+ mode: shown?.key ?? "auto"
164
+ },
165
+ extensions: shown ? [shown.extension] : [],
166
+ elements: ["answerValueSet"]
167
+ };
168
+ },
169
+ toAnswer: (value) => typeof value === "string" ? { valueString: value } : { valueCoding: toCoding(value) },
170
+ fromAnswer(answer) {
171
+ if (answer.valueCoding) return fromCoding(answer.valueCoding);
172
+ return answer.valueString;
173
+ },
174
+ // A code, as FHIR compares codings; a text of one's own as answerString.
175
+ toEnableAnswer: ({ value, asText }, context) => asText ? { answerString: value } : { answerCoding: parseCodeToken(value, listOf(context).system) },
176
+ fromEnableAnswer(e, context) {
177
+ if (e.answerString !== void 0)
178
+ return { value: e.answerString, asText: true };
179
+ if (!e.answerCoding)
180
+ return {
181
+ why: "a coded question compared with other than a coding or a text"
182
+ };
183
+ const { system, code, ...rest } = e.answerCoding;
184
+ if (Object.keys(rest).length)
185
+ return { why: "answerCoding beyond its system and code" };
186
+ return { value: codeToken({ system, code }, listOf(context).system) };
187
+ }
188
+ };
189
+
190
+ // src/questionnaire/codeableConcept.ts
191
+ import { CODEABLE_CONCEPT_ANSWER } from "@petrarca/sonnet-schema-designer/questionnaire";
192
+ function beyondFhir(context) {
193
+ const further = context.settings.additional;
194
+ return [
195
+ ...Array.isArray(further) && further.length ? [
196
+ "further lists: a FHIR answer is one coding -- the first list's is written"
197
+ ] : [],
198
+ ...context.settings.offerText === true ? ["a text beside the codes: a FHIR answer is a coding or a text"] : []
199
+ ];
200
+ }
201
+ var CODEABLE_CONCEPT_FHIR = {
202
+ answer: CODEABLE_CONCEPT_ANSWER,
203
+ spell: (spelling) => spelling.write("singleChoice", false),
204
+ // FHIR has no codeable concept question: no item is read as one.
205
+ claims: () => false,
206
+ toItem(context) {
207
+ const { notConverted = [], ...written } = CODING_FHIR.toItem(context);
208
+ const more = [...notConverted, ...beyondFhir(context)];
209
+ return { ...written, ...more.length ? { notConverted: more } : {} };
210
+ },
211
+ fromItem: () => ({ why: "FHIR has no codeable concept question" }),
212
+ toAnswer(value) {
213
+ const concept = value;
214
+ const [first] = concept.codings ?? [];
215
+ return first ? CODING_FHIR.toAnswer(first, { settings: {} }) : { valueString: concept.text ?? "" };
216
+ },
217
+ fromAnswer(answer, context) {
218
+ const read = CODING_FHIR.fromAnswer(answer, context);
219
+ if (typeof read === "string")
220
+ return { text: read };
221
+ return read ? { codings: [read] } : void 0;
222
+ },
223
+ toEnableAnswer: CODING_FHIR.toEnableAnswer
224
+ };
225
+
226
+ // src/questionnaire/valueTypes.ts
227
+ var unitsOf = (context) => context.settings.units ?? [];
228
+ var BOUNDS = [
229
+ { key: "min", url: MIN_VALUE },
230
+ { key: "max", url: MAX_VALUE }
231
+ ];
232
+ function rangeToFhir(units, system) {
233
+ const extensions = [];
234
+ const notConverted = [];
235
+ for (const { key, url } of BOUNDS) {
236
+ const [first, ...others] = units.filter((u) => u[key] !== void 0);
237
+ if (!first) continue;
238
+ extensions.push({
239
+ url,
240
+ valueQuantity: {
241
+ value: first[key],
242
+ unit: first.label,
243
+ system,
244
+ code: first.value
245
+ }
246
+ });
247
+ for (const u of others)
248
+ notConverted.push(
249
+ `${key}Value of ${u.value}: FHIR takes one, ${first.value}'s`
250
+ );
251
+ }
252
+ return { extensions, notConverted };
253
+ }
254
+ function boundOf(item, url, system) {
255
+ const found = item.extension?.find((e) => e.url === url && e.valueQuantity);
256
+ const q = found?.valueQuantity;
257
+ const ok = typeof q?.value === "number" && (q.system ?? system) === system;
258
+ return ok ? { extension: found, code: q.code, value: q.value } : void 0;
259
+ }
260
+ function rangeFromFhir(item, units, system) {
261
+ const read = [];
262
+ const ranged = units.map((u) => ({ ...u }));
263
+ for (const { key, url } of BOUNDS) {
264
+ const bound = boundOf(item, url, system);
265
+ const unit = ranged.find((u) => u.value === bound?.code);
266
+ if (!bound || !unit) continue;
267
+ unit[key] = bound.value;
268
+ read.push(bound.extension);
269
+ }
270
+ return { units: ranged, read };
271
+ }
272
+ var QUANTITY_FHIR = {
273
+ answer: QUANTITY_ANSWER,
274
+ itemType: "quantity",
275
+ toItem(context) {
276
+ const system = context.system ?? UCUM_SYSTEM;
277
+ const units = unitsOf(context);
278
+ const options = units.map((u) => ({
279
+ url: UNIT_OPTION,
280
+ valueCoding: { system, code: u.value, display: u.label }
281
+ }));
282
+ const range = rangeToFhir(units, system);
283
+ const extension = [...options, ...range.extensions];
284
+ return {
285
+ ...extension.length ? { extension } : {},
286
+ ...range.notConverted.length ? { notConverted: range.notConverted } : {}
287
+ };
288
+ },
289
+ fromItem(item) {
290
+ const options = (item.extension ?? []).filter((e) => e.url === UNIT_OPTION);
291
+ const read = fromCodings(options, ["url"]);
292
+ if (!read)
293
+ return { why: "unitOption: units other than codings of one system" };
294
+ const range = rangeFromFhir(item, read.options, read.system ?? UCUM_SYSTEM);
295
+ const system = read.system === UCUM_SYSTEM ? void 0 : read.system;
296
+ return {
297
+ settings: { units: range.units },
298
+ ...system ? { system } : {},
299
+ extensions: [...options, ...range.read]
300
+ };
301
+ },
302
+ toAnswer(value, context) {
303
+ const q = value;
304
+ return {
305
+ valueQuantity: {
306
+ value: q.value,
307
+ ...q.comparator ? { comparator: q.comparator } : {},
308
+ unit: unitsOf(context).find((u) => u.value === q.unit)?.label ?? q.unit,
309
+ system: q.system ?? context.system ?? UCUM_SYSTEM,
310
+ code: q.unit
311
+ }
312
+ };
313
+ },
314
+ fromAnswer(answer, context) {
315
+ const written = answer.valueQuantity;
316
+ if (!written) return void 0;
317
+ const expected = context.system ?? UCUM_SYSTEM;
318
+ return {
319
+ value: written.value,
320
+ unit: written.code ?? written.unit ?? "",
321
+ ...written.system && written.system !== expected ? { system: written.system } : {},
322
+ ...written.comparator ? { comparator: written.comparator } : {}
323
+ };
324
+ }
325
+ };
326
+ var DEFAULT_FHIR_VALUE_TYPES = [
327
+ QUANTITY_FHIR,
328
+ CODING_FHIR,
329
+ CODEABLE_CONCEPT_FHIR
330
+ ];
331
+ function itemOf(type, spelling, orText, multiple) {
332
+ const item = type.spell ? type.spell(spelling, orText) : { type: type.itemType ?? "" };
333
+ return multiple ? { ...item, repeats: true } : item;
334
+ }
335
+ function claimsItem(type, item, spelling) {
336
+ const ofType = type.spell ? true : type.itemType === item.type;
337
+ const repeatsOk = !item.repeats || type.repeats === true;
338
+ return ofType && repeatsOk && (type.claims?.(item, spelling) ?? !type.spell);
339
+ }
340
+ function valueTypesOf(options) {
341
+ return options.valueTypes ?? DEFAULT_FHIR_VALUE_TYPES;
342
+ }
343
+ function answerTypesOf(types) {
344
+ return types.map((t) => t.answer);
345
+ }
346
+ function fhirValueType(answerType, types) {
347
+ return types.find((t) => t.answer.type.id === answerType);
348
+ }
349
+
350
+ // src/questionnaire/toQuestionnaire.ts
351
+ import {
352
+ classifyQuestionnaire as classifyQuestionnaire2,
353
+ OTHER_OPTION,
354
+ getProperty as getProperty3
355
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
356
+ import { valueRefOf as valueRefOf2 } from "@petrarca/sonnet-core/schema";
357
+
358
+ // src/questionnaire/annotations.ts
359
+ var OWN = [
360
+ X_FHIR_LINK_ID,
361
+ X_FHIR_EXTENSION,
362
+ X_FHIR_SYSTEM,
363
+ X_FHIR_HELP_LINK_ID,
364
+ X_FHIR_ITEM,
365
+ X_FHIR_LEAD_QUESTION
366
+ ];
367
+ function elementsOf(prop) {
368
+ return Object.fromEntries(
369
+ Object.entries(prop).filter(([k]) => isFhirAnnotation(k) && !OWN.includes(k)).map(([k, v]) => [k.slice(X_FHIR.length), v])
370
+ );
371
+ }
372
+ function annotationsOf(elements) {
373
+ return Object.fromEntries(
374
+ Object.entries(elements).map(([k, v]) => [`${X_FHIR}${k}`, v])
375
+ );
376
+ }
377
+ function keptExtensions(prop) {
378
+ const kept = prop[X_FHIR_EXTENSION];
379
+ return Array.isArray(kept) ? kept : [];
380
+ }
381
+ function systemOf(prop) {
382
+ const system = prop[X_FHIR_SYSTEM];
383
+ return typeof system === "string" ? system : void 0;
384
+ }
385
+ function isReportedExtra(extra) {
386
+ return !extra.split(".").some(isFhirAnnotation);
387
+ }
388
+
389
+ // src/questionnaire/limits.ts
390
+ import {
391
+ limitsFor
392
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
393
+ var EXTENSIONS = {
394
+ minLength: { url: MIN_LENGTH, value: () => "valueInteger" },
395
+ pattern: { url: REGEX, value: () => "valueString" },
396
+ minimum: { url: MIN_VALUE, value: numberValue },
397
+ maximum: { url: MAX_VALUE, value: numberValue },
398
+ minItems: { url: MIN_OCCURS, value: () => "valueInteger" },
399
+ maxItems: { url: MAX_OCCURS, value: () => "valueInteger" },
400
+ formatMinimum: { url: MIN_VALUE, value: temporalValue, write: withSeconds },
401
+ formatMaximum: { url: MAX_VALUE, value: temporalValue, write: withSeconds }
402
+ };
403
+ function numberValue(type) {
404
+ return type === "integer" ? "valueInteger" : "valueDecimal";
405
+ }
406
+ function temporalValue(type) {
407
+ if (type === "time") return "valueTime";
408
+ return type === "dateTime" ? "valueDateTime" : "valueDate";
409
+ }
410
+ function withSeconds(value) {
411
+ return typeof value === "string" && /^\d{2}:\d{2}$/.test(value) ? `${value}:00` : value;
412
+ }
413
+ function limitsToFhir(limits, type) {
414
+ const takes = limitsFor(type);
415
+ const extensions = Object.entries(EXTENSIONS).flatMap(([k, e]) => {
416
+ const value = limits?.[k];
417
+ if (value === void 0 || !takes.includes(k)) return [];
418
+ return [{ url: e.url, [e.value(type)]: e.write ? e.write(value) : value }];
419
+ });
420
+ return {
421
+ ...limits?.maxLength !== void 0 ? { maxLength: limits.maxLength } : {},
422
+ extensions
423
+ };
424
+ }
425
+ function limitsFromFhir(item, type) {
426
+ const takes = limitsFor(type);
427
+ const limits = {};
428
+ const extensions = [];
429
+ if (takes.includes("maxLength") && item.maxLength !== void 0)
430
+ limits.maxLength = item.maxLength;
431
+ for (const [k, e] of Object.entries(EXTENSIONS)) {
432
+ if (!takes.includes(k)) continue;
433
+ const found = item.extension?.find(
434
+ (x) => x.url === e.url && x[e.value(type)] !== void 0
435
+ );
436
+ if (!found) continue;
437
+ limits[k] = found[e.value(type)];
438
+ extensions.push(found);
439
+ }
440
+ return { limits, extensions };
441
+ }
442
+
443
+ // src/questionnaire/linkId.ts
444
+ import {
445
+ getProperty
446
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
447
+ function keyPathOf(item) {
448
+ return item.path.flatMap((s) => s.kind === "prop" ? [s.key] : []).join(".") || item.key;
449
+ }
450
+ function linkIdOf(model, item) {
451
+ const prop = getProperty(model.schema, item.path);
452
+ const kept = prop?.[X_FHIR_LINK_ID];
453
+ return typeof kept === "string" ? kept : keyPathOf(item);
454
+ }
455
+ function leadQuestionOf(model, section) {
456
+ if (section.kind !== "section") return void 0;
457
+ const prop = getProperty(model.schema, section.path);
458
+ const key = prop?.[X_FHIR_LEAD_QUESTION];
459
+ return section.items.find((i) => i.key === key);
460
+ }
461
+
462
+ // src/questionnaire/toResponse.ts
463
+ import { valueRefOf } from "@petrarca/sonnet-core/schema";
464
+ import {
465
+ classifyQuestionnaire,
466
+ getProperty as getProperty2
467
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
468
+
469
+ // src/questionnaire/r4.ts
470
+ var ITEM_TYPES = {
471
+ yesNo: { type: "boolean" },
472
+ shortText: { type: "string" },
473
+ longText: { type: "text" },
474
+ integer: { type: "integer" },
475
+ decimal: { type: "decimal" },
476
+ date: { type: "date" },
477
+ time: { type: "time" },
478
+ dateTime: { type: "dateTime" },
479
+ singleChoice: { type: "choice" },
480
+ multipleChoice: { type: "choice", repeats: true },
481
+ choiceWithText: { type: "choice" },
482
+ listOfText: { type: "string", repeats: true },
483
+ parts: { type: "group" }
484
+ };
485
+ var OPEN_CHOICE = "open-choice";
486
+ var R4_SPELLING = {
487
+ write: (answerType, open) => open ? { type: OPEN_CHOICE } : ITEM_TYPES[answerType],
488
+ answerTypeOf: (item) => answerTypeOf(item.type, item.repeats ?? false),
489
+ isChoice: (item) => item.type === "choice",
490
+ isOpen: (item) => item.type === OPEN_CHOICE,
491
+ elements: []
492
+ };
493
+ function answerTypeOf(type, repeats) {
494
+ const found = Object.entries(ITEM_TYPES).find(
495
+ ([answer, t]) => t.type === type && (t.repeats ?? false) === repeats && // A group is a section; a choice with text is read from its shape.
496
+ answer !== "parts" && answer !== "choiceWithText"
497
+ );
498
+ return found?.[0];
499
+ }
500
+ var VALUE_KEYS = {
501
+ yesNo: "valueBoolean",
502
+ shortText: "valueString",
503
+ longText: "valueString",
504
+ listOfText: "valueString",
505
+ integer: "valueInteger",
506
+ decimal: "valueDecimal",
507
+ date: "valueDate",
508
+ time: "valueTime",
509
+ dateTime: "valueDateTime"
510
+ };
511
+ var ENABLE_ANSWER_KEYS = {
512
+ yesNo: "answerBoolean",
513
+ shortText: "answerString",
514
+ longText: "answerString",
515
+ integer: "answerInteger",
516
+ decimal: "answerDecimal",
517
+ date: "answerDate",
518
+ time: "answerTime",
519
+ dateTime: "answerDateTime",
520
+ singleChoice: "answerCoding",
521
+ multipleChoice: "answerCoding"
522
+ };
523
+
524
+ // src/questionnaire/toResponse.ts
525
+ var ResponseWriter = class {
526
+ constructor(model, types) {
527
+ this.model = model;
528
+ this.types = types;
529
+ }
530
+ model;
531
+ types;
532
+ linkId(item) {
533
+ return linkIdOf(this.model, item);
534
+ }
535
+ leadOf(section) {
536
+ return leadQuestionOf(this.model, section);
537
+ }
538
+ prop(q) {
539
+ return getProperty2(this.model.schema, q.path) ?? {};
540
+ }
541
+ system(q) {
542
+ return systemOf(this.prop(q));
543
+ }
544
+ /** Whether a value type's question takes several answers. */
545
+ multiple(q) {
546
+ return valueRefOf(this.prop(q))?.multiple ?? false;
547
+ }
548
+ coding(q, value) {
549
+ const code = String(value);
550
+ const system = this.system(q);
551
+ return {
552
+ ...system ? { system } : {},
553
+ code,
554
+ display: q.options?.find((o) => o.value === code)?.label ?? code
555
+ };
556
+ }
557
+ };
558
+ function valueTypeAnswers(w, q, valueType, value) {
559
+ const context = { settings: q.settings ?? {}, system: w.system(q) };
560
+ const values = w.multiple(q) && Array.isArray(value) ? value : [value];
561
+ return values.map((v) => valueType.toAnswer(v, context));
562
+ }
563
+ function answersOf(w, q, value) {
564
+ if (q.answerType === "choiceWithText")
565
+ return choiceWithTextAnswer(w, q, value);
566
+ if (q.answerType === "parts") return [];
567
+ const valueType = fhirValueType(q.answerType, w.types);
568
+ if (valueType) return valueTypeAnswers(w, q, valueType, value);
569
+ const values = Array.isArray(value) ? value : [value];
570
+ if (q.answerType === "singleChoice" || q.answerType === "multipleChoice") {
571
+ return values.map((v) => ({ valueCoding: w.coding(q, v) }));
572
+ }
573
+ const key = VALUE_KEYS[q.answerType];
574
+ return key ? values.map((v) => ({ [key]: v })) : [];
575
+ }
576
+ function answersFor(model, types, q, value) {
577
+ return answersOf(new ResponseWriter(model, types), q, value);
578
+ }
579
+ function otherAnswer(value) {
580
+ return typeof value.text === "string" && value.text ? [{ valueString: value.text }] : [];
581
+ }
582
+ function choiceWithTextAnswer(w, q, value) {
583
+ if (value.choice === void 0) return [];
584
+ if (q.textWhen !== void 0 && value.choice === q.textWhen)
585
+ return otherAnswer(value);
586
+ const text = q.parts?.find((p) => p.key === "text");
587
+ const nested = text && typeof value.text === "string" && value.text ? [{ linkId: w.linkId(text), answer: [{ valueString: value.text }] }] : [];
588
+ return [
589
+ {
590
+ valueCoding: w.coding(q, value.choice),
591
+ ...nested.length ? { item: nested } : {}
592
+ }
593
+ ];
594
+ }
595
+ function responseItems(w, items, data) {
596
+ const absent = data.absent ?? {};
597
+ return items.flatMap(
598
+ (item) => item.kind === "question" && data[item.key] === void 0 && absent[item.key] ? [
599
+ {
600
+ linkId: w.linkId(item),
601
+ text: item.title,
602
+ extension: [
603
+ { url: DATA_ABSENT_REASON, valueCode: absent[item.key] }
604
+ ]
605
+ }
606
+ ] : responseItem(w, item, data[item.key])
607
+ );
608
+ }
609
+ function answered(item, value) {
610
+ return value !== void 0 && value !== null && item.kind !== "locked" && item.kind !== "text";
611
+ }
612
+ function sectionResponse(w, item, value) {
613
+ const lead = w.leadOf(item);
614
+ if (lead) return ledResponse(w, item, lead, value);
615
+ const groups = item.repeats && Array.isArray(value) ? value : [value];
616
+ return groups.map((g) => ({
617
+ linkId: w.linkId(item),
618
+ text: item.title,
619
+ item: responseItems(w, item.items, g)
620
+ }));
621
+ }
622
+ function ledResponse(w, section, lead, value) {
623
+ const [answered2] = responseItems(w, [lead], value);
624
+ if (!answered2?.answer?.length) return answered2 ? [answered2] : [];
625
+ const followUps = responseItems(
626
+ w,
627
+ section.items.filter((i) => i !== lead),
628
+ value
629
+ );
630
+ if (!followUps.length) return [answered2];
631
+ const [first, ...more] = answered2.answer;
632
+ return [
633
+ {
634
+ ...answered2,
635
+ answer: [
636
+ { ...first, item: [...first.item ?? [], ...followUps] },
637
+ ...more
638
+ ]
639
+ }
640
+ ];
641
+ }
642
+ function responseItem(w, item, value) {
643
+ if (!answered(item, value) || item.kind === "locked" || item.kind === "text")
644
+ return [];
645
+ if (item.kind === "section") return sectionResponse(w, item, value);
646
+ const linkId = w.linkId(item);
647
+ if (item.answerType === "parts") {
648
+ return [
649
+ {
650
+ linkId,
651
+ text: item.title,
652
+ item: responseItems(w, item.parts ?? [], value)
653
+ }
654
+ ];
655
+ }
656
+ const answer = answersOf(w, item, value);
657
+ return answer.length ? [{ linkId, text: item.title, answer }] : [];
658
+ }
659
+ function canonicalOf(model) {
660
+ const schema = model.schema;
661
+ const url = schema[`${X_FHIR}url`];
662
+ const version = schema[`${X_FHIR}version`];
663
+ if (typeof url !== "string") return void 0;
664
+ return typeof version === "string" ? `${url}|${version}` : url;
665
+ }
666
+ function toFhirQuestionnaireResponse(model, data, options) {
667
+ const elements = options.elements ?? {};
668
+ const status = options.status ?? elements.status ?? "completed";
669
+ const types = valueTypesOf(options);
670
+ const questionnaire = elements.questionnaire ?? canonicalOf(model);
671
+ return {
672
+ resourceType: "QuestionnaireResponse",
673
+ ...elements,
674
+ ...questionnaire ? { questionnaire } : {},
675
+ status,
676
+ item: responseItems(
677
+ new ResponseWriter(model, types),
678
+ classifyQuestionnaire(model, answerTypesOf(types)).items,
679
+ data
680
+ )
681
+ };
682
+ }
683
+
684
+ // src/questionnaire/r5.ts
685
+ var CODING = "coding";
686
+ var OR_STRING = "optionsOrString";
687
+ var CHOICES = ["singleChoice", "multipleChoice", "choiceWithText"];
688
+ var R5_SPELLING = {
689
+ write(answerType, open) {
690
+ if (open) return { type: CODING, answerConstraint: OR_STRING };
691
+ const r4 = ITEM_TYPES[answerType];
692
+ return CHOICES.includes(answerType) ? { ...r4, type: CODING } : r4;
693
+ },
694
+ answerTypeOf(item) {
695
+ if (item.type !== CODING)
696
+ return item.type === "choice" || item.type === "open-choice" ? void 0 : answerTypeOf(item.type, item.repeats ?? false);
697
+ if (!R5_SPELLING.isChoice(item)) return void 0;
698
+ return item.repeats ? "multipleChoice" : "singleChoice";
699
+ },
700
+ isChoice: (item) => item.type === CODING && (item.answerConstraint ?? "optionsOnly") === "optionsOnly",
701
+ isOpen: (item) => item.type === CODING && item.answerConstraint === OR_STRING,
702
+ elements: ["answerConstraint"]
703
+ };
704
+
705
+ // src/questionnaire/spelling.ts
706
+ function spellingOf(version) {
707
+ return version === "R5" ? R5_SPELLING : R4_SPELLING;
708
+ }
709
+
710
+ // src/questionnaire/toQuestionnaire.ts
711
+ function helpItem(linkId, text) {
712
+ return {
713
+ linkId,
714
+ type: "display",
715
+ text,
716
+ extension: [itemControl("help")]
717
+ };
718
+ }
719
+ function answerOptions(options, system) {
720
+ return options.map((o) => ({
721
+ valueCoding: {
722
+ ...system ? { system } : {},
723
+ code: o.value,
724
+ ...o.label !== o.value ? { display: o.label } : {}
725
+ }
726
+ }));
727
+ }
728
+ function otherOptionExtension(q) {
729
+ if (q.textWhen === void 0) return [];
730
+ const option = q.options?.find((o) => o.value === q.textWhen);
731
+ const value = q.textWhen;
732
+ const label = option?.label ?? value;
733
+ if (value === OTHER_OPTION.value && label === OTHER_OPTION.label) return [];
734
+ return [
735
+ {
736
+ url: OTHER_OPTION_EXTENSION,
737
+ valueCoding: { code: value, display: label }
738
+ }
739
+ ];
740
+ }
741
+ function choiceOptions(q, system) {
742
+ const options = q.textWhen !== void 0 ? q.options?.filter((o) => o.value !== q.textWhen) : q.options;
743
+ return options ? { answerOption: answerOptions(options, system) } : {};
744
+ }
745
+ function itemTypeOf(q, prop, valueType, spelling) {
746
+ if (valueType) {
747
+ const ref = valueRefOf2(prop);
748
+ return itemOf(
749
+ valueType,
750
+ spelling,
751
+ ref?.orText ?? false,
752
+ ref?.multiple ?? false
753
+ );
754
+ }
755
+ return spelling.write(
756
+ q.answerType,
757
+ q.textWhen !== void 0
758
+ );
759
+ }
760
+ function textOf(item, prop) {
761
+ const untitled = prop.title === void 0 && item.title === item.key;
762
+ return untitled ? {} : { text: item.title };
763
+ }
764
+ function flags(values) {
765
+ return Object.fromEntries(
766
+ Object.entries(values).filter(([, v]) => v)
767
+ );
768
+ }
769
+ function withExtensions(mapped, kept) {
770
+ const extension = [...mapped, ...kept];
771
+ return extension.length ? { extension } : {};
772
+ }
773
+ function comparand(key, value) {
774
+ if (key === "answerBoolean") return value === "true";
775
+ if (key === "answerInteger" || key === "answerDecimal") return Number(value);
776
+ return value;
777
+ }
778
+ var QuestionnaireWriter = class {
779
+ constructor(model, types, spelling) {
780
+ this.model = model;
781
+ this.types = types;
782
+ this.spelling = spelling;
783
+ }
784
+ model;
785
+ types;
786
+ spelling;
787
+ notConverted = [];
788
+ prop(item) {
789
+ return getProperty3(this.model.schema, item.path) ?? {};
790
+ }
791
+ items(items) {
792
+ const write = this.writerOf(items);
793
+ return items.flatMap(write);
794
+ }
795
+ // How a container's items are written: each with its show-if, which tests its siblings.
796
+ writerOf(items) {
797
+ const siblings = new Map(items.map((i) => [i.key, i]));
798
+ return (item) => this.item(item).map(
799
+ (written) => this.withEnableWhen(written, item, siblings)
800
+ );
801
+ }
802
+ // A section led by its question: the lead question's item, its follow-ups nested under it.
803
+ ledSection(section, leadKey, linkId) {
804
+ const lead = section.items.find((i) => i.key === leadKey);
805
+ const write = this.writerOf(section.items);
806
+ const [written] = lead ? write(lead) : [];
807
+ if (!written) {
808
+ this.notConverted.push({
809
+ linkId,
810
+ what: "a lead question it does not have"
811
+ });
812
+ return void 0;
813
+ }
814
+ const followUps = section.items.filter((i) => i !== lead).flatMap(write);
815
+ return { ...written, item: [...written.item ?? [], ...followUps] };
816
+ }
817
+ item(item) {
818
+ const prop = this.prop(item);
819
+ const kept = prop[X_FHIR_ITEM];
820
+ if (kept) return [kept];
821
+ const linkId = linkIdOf(this.model, item);
822
+ if (item.kind === "locked") {
823
+ this.notConverted.push({ linkId, what: item.reason });
824
+ return [];
825
+ }
826
+ this.reportExtras(linkId, item.extras);
827
+ const elements = elementsOf(prop);
828
+ if (item.kind === "text")
829
+ return [
830
+ {
831
+ ...elements,
832
+ linkId,
833
+ type: "display",
834
+ text: item.text ?? item.title,
835
+ ...withExtensions([], keptExtensions(prop))
836
+ }
837
+ ];
838
+ const lead = prop[X_FHIR_LEAD_QUESTION];
839
+ const written = item.kind === "section" ? typeof lead === "string" ? this.ledSection(item, lead, linkId) : this.section(item, linkId) : this.question(item, linkId);
840
+ return written ? [{ ...elements, ...written }] : [];
841
+ }
842
+ section(section, linkId) {
843
+ const intro = section.description ? [
844
+ {
845
+ linkId: `${linkId}.intro`,
846
+ type: "display",
847
+ text: section.description
848
+ }
849
+ ] : [];
850
+ const count = limitsToFhir(section.limits, "listOfText").extensions;
851
+ return {
852
+ linkId,
853
+ ...textOf(section, this.prop(section)),
854
+ type: "group",
855
+ ...flags({ required: section.required, repeats: section.repeats }),
856
+ ...withExtensions(count, keptExtensions(this.prop(section))),
857
+ item: [...intro, ...this.items(section.items)]
858
+ };
859
+ }
860
+ question(q, linkId) {
861
+ const prop = this.prop(q);
862
+ const valueType = fhirValueType(q.answerType, this.types);
863
+ const { type, repeats, answerConstraint } = itemTypeOf(
864
+ q,
865
+ prop,
866
+ valueType,
867
+ this.spelling
868
+ );
869
+ const nested = this.nested(q, linkId);
870
+ const limits = limitsToFhir(q.limits, q.answerType);
871
+ const { extension: valueTypeExtensions, ...valueTypeElements } = this.valueTypeParts(q, linkId, valueType);
872
+ const mapped = [
873
+ ...q.placeholder ? [{ url: ENTRY_FORMAT, valueString: q.placeholder }] : [],
874
+ ...valueTypeExtensions ?? [],
875
+ ...limits.extensions,
876
+ ...otherOptionExtension(q),
877
+ // A built-in type's presentation; a value type writes its own.
878
+ ...valueType ? [] : controlOf(q.answerType, q.presentation)
879
+ ];
880
+ return {
881
+ linkId,
882
+ ...textOf(q, prop),
883
+ type,
884
+ ...answerConstraint ? { answerConstraint } : {},
885
+ ...flags({ required: q.required, repeats, readOnly: q.readOnly }),
886
+ ...limits.maxLength !== void 0 ? { maxLength: limits.maxLength } : {},
887
+ ...valueTypeElements,
888
+ ...this.withInitial(q, choiceOptions(q, systemOf(prop))),
889
+ ...withExtensions(mapped, keptExtensions(prop)),
890
+ ...nested.length ? { item: nested } : {}
891
+ };
892
+ }
893
+ // A question's default answer: its options chosen (`initialSelected`) when it
894
+ // has options -- FHIR allows no `initial` beside them -- else its `initial`.
895
+ withInitial(q, options) {
896
+ if (q.defaultAnswer === void 0) return options;
897
+ if (!options.answerOption)
898
+ return {
899
+ initial: answersFor(this.model, this.types, q, q.defaultAnswer)
900
+ };
901
+ const chosen = [q.defaultAnswer].flat().map(String);
902
+ return {
903
+ answerOption: options.answerOption.map(
904
+ (o) => chosen.includes(String(o.valueCoding?.code)) ? { ...o, initialSelected: true } : o
905
+ )
906
+ };
907
+ }
908
+ // A value type's settings as the item's extensions and elements; those FHIR cannot say, reported.
909
+ valueTypeParts(q, linkId, valueType) {
910
+ if (!valueType) return {};
911
+ const { notConverted, ...written } = valueType.toItem(this.context(q));
912
+ for (const what of notConverted ?? [])
913
+ this.notConverted.push({ linkId, what });
914
+ return written;
915
+ }
916
+ // What a value type's settings and answers are read with: the question's settings and code system.
917
+ context(q) {
918
+ return { settings: q.settings ?? {}, system: systemOf(this.prop(q)) };
919
+ }
920
+ // The items under a question: its help, its parts, a choice with text's text
921
+ // (FHIR nests items under a question).
922
+ nested(q, linkId) {
923
+ const text = q.answerType === "choiceWithText" && q.textWhen === void 0 ? q.parts?.find((p) => p.key === "text") : void 0;
924
+ const helpLinkId = this.prop(q)[X_FHIR_HELP_LINK_ID];
925
+ return [
926
+ ...q.help ? [
927
+ helpItem(
928
+ typeof helpLinkId === "string" ? helpLinkId : `${linkId}.help`,
929
+ q.help
930
+ )
931
+ ] : [],
932
+ ...q.answerType === "parts" ? this.items(q.parts ?? []) : [],
933
+ ...text ? [this.question(text, linkIdOf(this.model, text))] : []
934
+ ];
935
+ }
936
+ // An item's show-if as FHIR's enableWhen: one entry per condition, all or any.
937
+ withEnableWhen(written, item, siblings) {
938
+ if (!item.showIf) return written;
939
+ const enableWhen = item.showIf.conditions.map((c) => {
940
+ const tested = siblings.get(c.field);
941
+ const question = tested ? linkIdOf(this.model, tested) : c.field;
942
+ return c.operator === "exists" ? { question, operator: "exists", answerBoolean: true } : {
943
+ question,
944
+ operator: c.operator,
945
+ ...this.enableAnswer(tested, c)
946
+ };
947
+ });
948
+ return {
949
+ ...written,
950
+ enableWhen,
951
+ ...enableWhen.length > 1 ? { enableBehavior: item.showIf.behavior } : {}
952
+ };
953
+ }
954
+ // The FHIR answer a condition compares with, typed by the question it tests:
955
+ // as a value type writes it, else by its built-in answer type.
956
+ enableAnswer(tested, c) {
957
+ if (tested?.kind !== "question") return { answerString: c.value };
958
+ const valueType = fhirValueType(tested.answerType, this.types);
959
+ if (valueType?.toEnableAnswer)
960
+ return valueType.toEnableAnswer(c, this.context(tested));
961
+ return this.builtinEnableAnswer(tested, c.value);
962
+ }
963
+ builtinEnableAnswer(tested, value) {
964
+ const key = ENABLE_ANSWER_KEYS[tested.answerType] ?? "answerString";
965
+ if (key !== "answerCoding") return { [key]: comparand(key, value) };
966
+ const system = systemOf(this.prop(tested));
967
+ return { answerCoding: { ...system ? { system } : {}, code: value } };
968
+ }
969
+ reportExtras(linkId, extras) {
970
+ for (const what of extras.filter(isReportedExtra))
971
+ this.notConverted.push({ linkId, what });
972
+ }
973
+ };
974
+ function toFhirQuestionnaire(model, options) {
975
+ const types = valueTypesOf(options);
976
+ const view = classifyQuestionnaire2(model, answerTypesOf(types));
977
+ const writer = new QuestionnaireWriter(
978
+ model,
979
+ types,
980
+ spellingOf(options.version)
981
+ );
982
+ const item = writer.items(view.items);
983
+ writer.reportExtras("", view.extras);
984
+ const root = model.schema;
985
+ const elements = elementsOf(root);
986
+ const extension = keptExtensions(root);
987
+ return {
988
+ resource: {
989
+ resourceType: "Questionnaire",
990
+ ...elements,
991
+ status: elements.status ?? "draft",
992
+ ...view.title ? { title: view.title } : {},
993
+ ...view.description ? { description: view.description } : {},
994
+ ...extension.length ? { extension } : {},
995
+ item
996
+ },
997
+ notConverted: writer.notConverted
998
+ };
999
+ }
1000
+
1001
+ // src/questionnaire/fromQuestionnaire.ts
1002
+ import {
1003
+ addItem,
1004
+ changeAnswerType,
1005
+ classifyQuestionnaire as classifyQuestionnaire4,
1006
+ getProperty as getProperty5,
1007
+ keyFromText,
1008
+ prop as propSeg,
1009
+ OTHER_OPTION as OTHER_OPTION2,
1010
+ setChoiceTextWhen,
1011
+ setPresentation,
1012
+ setHelp,
1013
+ setItemText,
1014
+ setKeywords,
1015
+ setOptions,
1016
+ setPlaceholder,
1017
+ setQuestionnaireText,
1018
+ setQuestionRequired,
1019
+ setReadOnly,
1020
+ setSectionRepeats,
1021
+ setShowIf,
1022
+ isContainerType,
1023
+ itemsOf,
1024
+ setDefaultAnswer,
1025
+ setLimit,
1026
+ setValueTypeSettings
1027
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
1028
+
1029
+ // src/questionnaire/fromResponse.ts
1030
+ import { valueRefOf as valueRefOf3 } from "@petrarca/sonnet-core/schema";
1031
+ import {
1032
+ ABSENT_KEY,
1033
+ classifyQuestionnaire as classifyQuestionnaire3,
1034
+ getProperty as getProperty4
1035
+ } from "@petrarca/sonnet-schema-designer/questionnaire";
1036
+ function valuesOf(q, answers) {
1037
+ const key = VALUE_KEYS[q.answerType];
1038
+ if (!key) return void 0;
1039
+ const values = answers.map((a) => a[key]);
1040
+ return q.answerType === "listOfText" ? values : values[0];
1041
+ }
1042
+ function codesOf(q, answers) {
1043
+ const codes = answers.map((a) => a.valueCoding?.code);
1044
+ return q.answerType === "multipleChoice" ? codes : codes[0];
1045
+ }
1046
+ var ResponseReader = class {
1047
+ constructor(model, types) {
1048
+ this.model = model;
1049
+ this.types = types;
1050
+ }
1051
+ model;
1052
+ types;
1053
+ notConverted = [];
1054
+ // The answers of one container: its items' values by key, its reasons in `absent`.
1055
+ answers(items, written) {
1056
+ const byLinkId = new Map(
1057
+ items.map((i) => [
1058
+ linkIdOf(this.model, leadQuestionOf(this.model, i) ?? i),
1059
+ i
1060
+ ])
1061
+ );
1062
+ const data = {};
1063
+ for (const r of written) {
1064
+ const item = byLinkId.get(r.linkId);
1065
+ if (!item) {
1066
+ this.notConverted.push({
1067
+ linkId: r.linkId,
1068
+ what: "an answer to no question of the questionnaire"
1069
+ });
1070
+ continue;
1071
+ }
1072
+ this.answer(data, item, r);
1073
+ }
1074
+ return data;
1075
+ }
1076
+ answer(data, item, r) {
1077
+ const reason = r.extension?.find((e) => e.url === DATA_ABSENT_REASON);
1078
+ if (reason?.valueCode) {
1079
+ data[ABSENT_KEY] = {
1080
+ ...data[ABSENT_KEY] ?? {},
1081
+ [item.key]: reason.valueCode
1082
+ };
1083
+ return;
1084
+ }
1085
+ if (item.kind === "section") {
1086
+ this.section(data, item, r);
1087
+ return;
1088
+ }
1089
+ if (item.kind !== "question") {
1090
+ this.notConverted.push({
1091
+ linkId: r.linkId,
1092
+ what: "an answer to a question of no answer type"
1093
+ });
1094
+ return;
1095
+ }
1096
+ const value = this.value(item, r);
1097
+ if (value !== void 0) data[item.key] = value;
1098
+ }
1099
+ // A section's answers: one group, or one more entry of a repeating section --
1100
+ // or, led by its question, the lead's answer and the follow-ups' inside it.
1101
+ section(data, item, r) {
1102
+ const lead = leadQuestionOf(this.model, item);
1103
+ if (lead) {
1104
+ data[item.key] = {
1105
+ ...this.answers([lead], [r]),
1106
+ ...this.answers(
1107
+ item.items.filter((i) => i !== lead),
1108
+ r.answer?.[0]?.item ?? []
1109
+ )
1110
+ };
1111
+ return;
1112
+ }
1113
+ const group = this.answers(item.items, r.item ?? []);
1114
+ data[item.key] = item.repeats ? [...data[item.key] ?? [], group] : group;
1115
+ }
1116
+ // The stored value of a question's answers, by its answer type.
1117
+ value(q, r) {
1118
+ const answers = r.answer ?? [];
1119
+ switch (q.answerType) {
1120
+ case "parts":
1121
+ return this.answers(q.parts ?? [], r.item ?? []);
1122
+ case "choiceWithText":
1123
+ return answers[0] && this.choiceWithText(q, answers[0]);
1124
+ case "multipleChoice":
1125
+ case "singleChoice":
1126
+ return codesOf(q, answers);
1127
+ default:
1128
+ return this.valueTypeOrValues(q, answers);
1129
+ }
1130
+ }
1131
+ // A value type's answer, read through its contribution; else the stored values of a built-in type.
1132
+ valueTypeOrValues(q, answers) {
1133
+ const valueType = fhirValueType(q.answerType, this.types);
1134
+ if (!valueType) return valuesOf(q, answers);
1135
+ const prop = this.prop(q);
1136
+ const context = { settings: q.settings ?? {}, system: systemOf(prop) };
1137
+ if (valueRefOf3(prop)?.multiple) {
1138
+ const read = answers.map((a) => valueType.fromAnswer(a, context));
1139
+ return read.length ? read : void 0;
1140
+ }
1141
+ return answers[0] ? valueType.fromAnswer(answers[0], context) : void 0;
1142
+ }
1143
+ prop(q) {
1144
+ return getProperty4(this.model.schema, q.path) ?? {};
1145
+ }
1146
+ // A choice with text: the option asking for the text, an open-choice's string; or the choice and its note.
1147
+ choiceWithText(q, a) {
1148
+ if (a.valueString !== void 0 && q.textWhen !== void 0)
1149
+ return { choice: q.textWhen, text: a.valueString };
1150
+ const note = a.item?.[0]?.answer?.[0]?.valueString;
1151
+ return {
1152
+ choice: a.valueCoding?.code,
1153
+ ...note !== void 0 ? { text: note } : {}
1154
+ };
1155
+ }
1156
+ };
1157
+ function valueOfAnswers(model, types, q, answers) {
1158
+ return new ResponseReader(model, types).value(q, {
1159
+ linkId: "",
1160
+ answer: answers
1161
+ });
1162
+ }
1163
+ function fromFhirQuestionnaireResponse(model, response, options) {
1164
+ const types = valueTypesOf(options);
1165
+ const reader = new ResponseReader(model, types);
1166
+ const data = reader.answers(
1167
+ classifyQuestionnaire3(model, answerTypesOf(types)).items,
1168
+ response.item ?? []
1169
+ );
1170
+ const { resourceType: _type, item: _answers, ...elements } = response;
1171
+ return { data, elements, notConverted: reader.notConverted };
1172
+ }
1173
+
1174
+ // src/questionnaire/fromQuestionnaire.ts
1175
+ var MAPPED = [
1176
+ "linkId",
1177
+ "text",
1178
+ "type",
1179
+ "required",
1180
+ "repeats",
1181
+ "readOnly",
1182
+ "answerOption",
1183
+ "enableWhen",
1184
+ "enableBehavior",
1185
+ "item",
1186
+ "extension"
1187
+ ];
1188
+ var MAPPED_ROOT = ["resourceType", "title", "description", "item"];
1189
+ var OPERATORS = ["=", "!=", ">", ">=", "<", "<=", "exists"];
1190
+ function unmapped(element, mapped, extensions = []) {
1191
+ const rest = Object.entries(element).filter(
1192
+ ([k]) => !mapped.includes(k) && k !== "extension"
1193
+ );
1194
+ return Object.fromEntries([
1195
+ ...rest,
1196
+ ...extensions.length ? [["extension", extensions]] : []
1197
+ ]);
1198
+ }
1199
+ function withTitle(model, path, text, key) {
1200
+ return setItemText(model, path, text === key ? "" : text ?? "");
1201
+ }
1202
+ function mappedOf(plan, spellingElements, read) {
1203
+ return {
1204
+ extensions: [
1205
+ ...read.extensions,
1206
+ ...plan.valueType?.extensions ?? [],
1207
+ ...plan.other ? [plan.other.extension] : []
1208
+ ],
1209
+ elements: [
1210
+ ...spellingElements,
1211
+ ...plan.valueType?.elements ?? [],
1212
+ ...read.elements
1213
+ ]
1214
+ };
1215
+ }
1216
+ function withPresentation(model, path, widget) {
1217
+ return widget ? setPresentation(model, path, widget) : model;
1218
+ }
1219
+ function isHelpControl(e) {
1220
+ return itemControlCode(e) === "help";
1221
+ }
1222
+ function isHelp(child) {
1223
+ const only = Object.keys(child).every(
1224
+ (k) => ["linkId", "type", "text", "extension"].includes(k)
1225
+ );
1226
+ return only && child.type === "display" && child.extension?.length === 1 && isHelpControl(child.extension[0]);
1227
+ }
1228
+ function isPlain(child, types) {
1229
+ return types.includes(child.type) && Object.keys(child).every((k) => ["linkId", "type", "text"].includes(k));
1230
+ }
1231
+ function readOptions(item) {
1232
+ const options = item.answerOption ?? [];
1233
+ if (options.length === 0) return "answerValueSet: no terminology expansion";
1234
+ return (
1235
+ // An option chosen until the person answers is the question's default, read with it.
1236
+ fromCodings(options, ["initialSelected"]) ?? "answerOption: options other than codings of one code system"
1237
+ );
1238
+ }
1239
+ function initialOf(item) {
1240
+ if (item.initial?.length) return item.initial;
1241
+ const chosen = (item.answerOption ?? []).filter((o) => o.initialSelected);
1242
+ return chosen.length ? chosen.map((o) => ({ valueCoding: o.valueCoding })) : void 0;
1243
+ }
1244
+ function questionsByLinkId(model, items) {
1245
+ return new Map(
1246
+ itemsOf(items).filter((i) => i.kind === "question").map((q) => [linkIdOf(model, q), q])
1247
+ );
1248
+ }
1249
+ function otherOptionOf(item) {
1250
+ const extension = item.extension?.find(
1251
+ (e) => e.url === OTHER_OPTION_EXTENSION
1252
+ );
1253
+ const coding = extension?.valueCoding;
1254
+ if (!extension || !coding?.code) return void 0;
1255
+ return {
1256
+ option: { value: coding.code, label: coding.display ?? coding.code },
1257
+ extension
1258
+ };
1259
+ }
1260
+ function noteOf(item, others, spelling) {
1261
+ const single = spelling.isChoice(item) && !item.repeats && others.length === 1;
1262
+ return single && isPlain(others[0], ["string", "text"]) ? others[0] : void 0;
1263
+ }
1264
+ function answerTypeFor(item, note, spelling) {
1265
+ const repeats = item.repeats ?? false;
1266
+ const withText = note || spelling.isOpen(item) && !repeats;
1267
+ const type = withText ? "choiceWithText" : spelling.answerTypeOf(item);
1268
+ return type ? { type } : {
1269
+ why: `item type ${item.type}${repeats ? ", repeating" : ""}: no answer type`
1270
+ };
1271
+ }
1272
+ function planQuestion(item, types, spelling) {
1273
+ const children = item.item ?? [];
1274
+ const help = children.find(isHelp);
1275
+ const others = children.filter((c) => c !== help);
1276
+ const valueType = types.find((t) => claimsItem(t, item, spelling));
1277
+ if (valueType) return planValueType(item, valueType, spelling, help, others);
1278
+ const note = noteOf(item, others, spelling);
1279
+ if (others.length > (note ? 1 : 0)) return "a question with items under it";
1280
+ const read = answerTypeFor(item, note, spelling);
1281
+ if ("why" in read) return read.why;
1282
+ const answerType = read.type;
1283
+ const open = spelling.isOpen(item);
1284
+ if (!spelling.isChoice(item) && !open) return { answerType, open, help };
1285
+ return choicePlan(item, { answerType, open, help, note });
1286
+ }
1287
+ function choicePlan(item, base) {
1288
+ const options = readOptions(item);
1289
+ if (typeof options === "string") return options;
1290
+ const other = base.open ? otherOptionOf(item) : void 0;
1291
+ return { ...base, options, ...other ? { other } : {} };
1292
+ }
1293
+ function planValueType(item, fhir, spelling, help, others) {
1294
+ if (others.length) return "a question with items under it";
1295
+ const read = fhir.fromItem(item, spelling);
1296
+ if ("why" in read) return read.why;
1297
+ return {
1298
+ answerType: fhir.answer.type.id,
1299
+ open: false,
1300
+ help,
1301
+ valueType: { fhir, ...read }
1302
+ };
1303
+ }
1304
+ function nameOf(item) {
1305
+ const code = item.code?.[0];
1306
+ return item.text || code?.display || code?.code || item.linkId;
1307
+ }
1308
+ function followUpsOf(item, spelling) {
1309
+ const children = item.item ?? [];
1310
+ const others = children.filter((c) => !isHelp(c));
1311
+ return noteOf(item, others, spelling) ? [] : others;
1312
+ }
1313
+ function introOf(item) {
1314
+ const first = item.item?.[0];
1315
+ return first?.linkId === `${item.linkId}.intro` && isPlain(first, ["display"]) ? first : void 0;
1316
+ }
1317
+ function questionKeywords(item, plan, linkId, mapped) {
1318
+ const help = plan.help;
1319
+ const helpLinkId = help && help.linkId !== `${item.linkId}.help` ? { [X_FHIR_HELP_LINK_ID]: help.linkId } : {};
1320
+ const named = plan.options?.system ?? plan.valueType?.system;
1321
+ const system = named ? { [X_FHIR_SYSTEM]: named } : {};
1322
+ const extensions = (item.extension ?? []).filter(
1323
+ (e) => !mapped.extensions.includes(e)
1324
+ );
1325
+ return {
1326
+ ...linkId,
1327
+ ...helpLinkId,
1328
+ ...system,
1329
+ ...annotationsOf(
1330
+ unmapped(item, [...MAPPED, ...mapped.elements], extensions)
1331
+ )
1332
+ };
1333
+ }
1334
+ function withLimits(model, path, limits) {
1335
+ return Object.entries(limits).reduce(
1336
+ (m, [k, v]) => setLimit(m, path, k, v),
1337
+ model
1338
+ );
1339
+ }
1340
+ function questionFlags(model, path, item, entryFormat) {
1341
+ let next = model;
1342
+ if (entryFormat?.valueString)
1343
+ next = setPlaceholder(next, path, entryFormat.valueString);
1344
+ if (item.readOnly) next = setReadOnly(next, path, true);
1345
+ if (item.required) next = setQuestionRequired(next, path, true);
1346
+ return next;
1347
+ }
1348
+ var QuestionnaireReader = class {
1349
+ constructor(types, spelling) {
1350
+ this.types = types;
1351
+ this.spelling = spelling;
1352
+ }
1353
+ types;
1354
+ spelling;
1355
+ model = {
1356
+ schema: { title: "", type: "object", properties: {} },
1357
+ uiSchema: {}
1358
+ };
1359
+ notConverted = [];
1360
+ // The questions' answers given in advance, by linkId: read once every question is placed.
1361
+ initials = /* @__PURE__ */ new Map();
1362
+ /**
1363
+ * The questions' answers given in advance, as their default answers --
1364
+ * read as a response's answers are, once the questions are all there. One
1365
+ * not read stays as it came: an `initial` kept, written back, and reported.
1366
+ */
1367
+ applyInitials() {
1368
+ if (this.initials.size === 0) return;
1369
+ const view = classifyQuestionnaire4(this.model, answerTypesOf(this.types));
1370
+ const questions = questionsByLinkId(this.model, view.items);
1371
+ for (const [linkId, answers] of this.initials) {
1372
+ const q = questions.get(linkId);
1373
+ const value = q && !isContainerType(q.answerType) ? valueOfAnswers(this.model, this.types, q, answers) : void 0;
1374
+ if (!q || value === void 0) {
1375
+ this.notConverted.push({
1376
+ linkId,
1377
+ what: "initial: an answer of no value the question takes"
1378
+ });
1379
+ continue;
1380
+ }
1381
+ this.model = setKeywords(
1382
+ setDefaultAnswer(this.model, q.path, value),
1383
+ q.path,
1384
+ { [`${X_FHIR}initial`]: void 0 }
1385
+ );
1386
+ }
1387
+ }
1388
+ read(items, parent) {
1389
+ const taken = /* @__PURE__ */ new Set();
1390
+ const placed = items.map((item) => this.add(item, parent, taken));
1391
+ for (const p of placed) this.enableWhen(p, placed);
1392
+ return placed;
1393
+ }
1394
+ // The key an item gets: its linkId below its parent's, if that is a key; else one from its text.
1395
+ keyFor(item, parentLinkId, taken) {
1396
+ const local = parentLinkId && item.linkId.startsWith(`${parentLinkId}.`) ? item.linkId.slice(parentLinkId.length + 1) : item.linkId;
1397
+ const key = keyFromText(local, []) === local && !taken.has(local) ? local : keyFromText(nameOf(item), taken);
1398
+ taken.add(key);
1399
+ return key;
1400
+ }
1401
+ add(item, parent, taken) {
1402
+ const key = this.keyFor(item, parent.linkId, taken);
1403
+ const keyPath = parent.keyPath ? `${parent.keyPath}.${key}` : key;
1404
+ const linkId = keyPath === item.linkId ? {} : { [X_FHIR_LINK_ID]: item.linkId };
1405
+ if (item.type === "display") {
1406
+ const path2 = this.place(parent.path, { kind: "text" }, key);
1407
+ this.model = withTitle(this.model, path2, item.text, key);
1408
+ this.keep(path2, {
1409
+ ...linkId,
1410
+ ...annotationsOf(unmapped(item, MAPPED, item.extension))
1411
+ });
1412
+ return { item, key, path: path2, keyPath };
1413
+ }
1414
+ if (item.type === "group")
1415
+ return this.group(item, parent.path, key, keyPath, linkId);
1416
+ const followUps = followUpsOf(item, this.spelling);
1417
+ if (followUps.length)
1418
+ return this.ledSection(item, followUps, parent.path, key, keyPath);
1419
+ const plan = planQuestion(item, this.types, this.spelling);
1420
+ if (typeof plan === "string") {
1421
+ this.notConverted.push({ linkId: item.linkId, what: plan });
1422
+ const path2 = this.place(parent.path, { kind: "text" }, key);
1423
+ this.model = withTitle(this.model, path2, item.text, key);
1424
+ this.keep(path2, {
1425
+ ...linkId,
1426
+ type: void 0,
1427
+ "x-ui-widget": "display",
1428
+ [X_FHIR_ITEM]: item
1429
+ });
1430
+ return { item, key, path: path2, keyPath, kept: true };
1431
+ }
1432
+ const path = this.question(item, plan, parent.path, key, keyPath, linkId);
1433
+ return {
1434
+ item,
1435
+ key,
1436
+ path,
1437
+ keyPath,
1438
+ answerType: plan.answerType,
1439
+ system: plan.options?.system,
1440
+ ...plan.valueType ? {
1441
+ valueType: {
1442
+ fhir: plan.valueType.fhir,
1443
+ settings: plan.valueType.settings
1444
+ }
1445
+ } : {}
1446
+ };
1447
+ }
1448
+ // Add an item with its key, its text set by the caller.
1449
+ place(parentPath, kind, key) {
1450
+ const added = addItem(this.model, parentPath, kind, key);
1451
+ this.model = added.model;
1452
+ return added.path;
1453
+ }
1454
+ keep(path, keywords) {
1455
+ if (Object.keys(keywords).length)
1456
+ this.model = setKeywords(this.model, path, keywords);
1457
+ }
1458
+ // A question with follow-up questions: a section led by it, the follow-ups after it.
1459
+ ledSection(item, followUps, parentPath, key, keyPath) {
1460
+ const path = this.place(parentPath, { kind: "section" }, key);
1461
+ this.model = setItemText(this.model, path, "");
1462
+ const { enableWhen: _w, enableBehavior: _b, ...rest } = item;
1463
+ const lead = {
1464
+ ...rest,
1465
+ item: (item.item ?? []).filter((c) => !followUps.includes(c))
1466
+ };
1467
+ if (!lead.item?.length) delete lead.item;
1468
+ const [placedLead] = this.read([lead, ...followUps], {
1469
+ path,
1470
+ keyPath,
1471
+ linkId: item.linkId
1472
+ });
1473
+ this.keep(path, { [X_FHIR_LEAD_QUESTION]: placedLead.key });
1474
+ return { item, key, path, keyPath };
1475
+ }
1476
+ group(item, parentPath, key, keyPath, linkId) {
1477
+ const path = this.place(parentPath, { kind: "section" }, key);
1478
+ this.model = withTitle(this.model, path, item.text, key);
1479
+ const intro = introOf(item);
1480
+ if (intro) this.model = setHelp(this.model, path, intro.text ?? "");
1481
+ this.read(
1482
+ (item.item ?? []).filter((c) => c !== intro),
1483
+ {
1484
+ path,
1485
+ keyPath,
1486
+ linkId: item.linkId
1487
+ }
1488
+ );
1489
+ const count = item.repeats ? limitsFromFhir(item, "listOfText") : { limits: {}, extensions: [] };
1490
+ if (item.repeats)
1491
+ this.model = withLimits(
1492
+ setSectionRepeats(this.model, path, true),
1493
+ path,
1494
+ count.limits
1495
+ );
1496
+ if (item.required) this.model = setQuestionRequired(this.model, path, true);
1497
+ const kept = (item.extension ?? []).filter(
1498
+ (e) => !count.extensions.includes(e)
1499
+ );
1500
+ this.keep(path, {
1501
+ ...linkId,
1502
+ ...annotationsOf(unmapped(item, MAPPED, kept))
1503
+ });
1504
+ return { item, key, path, keyPath };
1505
+ }
1506
+ question(item, plan, parentPath, key, keyPath, linkId) {
1507
+ const path = this.place(
1508
+ parentPath,
1509
+ { kind: "question", answerType: plan.answerType },
1510
+ key
1511
+ );
1512
+ const answered2 = this.answer(
1513
+ withTitle(this.model, path, item.text, key),
1514
+ path,
1515
+ keyPath,
1516
+ plan
1517
+ );
1518
+ const entryFormat = item.extension?.find((e) => e.url === ENTRY_FORMAT);
1519
+ const { limits, extensions: limitExtensions } = limitsFromFhir(
1520
+ item,
1521
+ plan.answerType
1522
+ );
1523
+ const shown = plan.valueType ? void 0 : presentationOf(item, plan.answerType);
1524
+ this.model = withPresentation(
1525
+ withLimits(
1526
+ questionFlags(answered2, path, item, entryFormat),
1527
+ path,
1528
+ limits
1529
+ ),
1530
+ path,
1531
+ shown?.widget
1532
+ );
1533
+ const mapped = mappedOf(plan, this.spelling.elements, {
1534
+ extensions: [
1535
+ ...entryFormat ? [entryFormat] : [],
1536
+ ...limitExtensions,
1537
+ ...shown ? [shown.extension] : []
1538
+ ],
1539
+ elements: limits.maxLength !== void 0 ? ["maxLength"] : []
1540
+ });
1541
+ this.keep(path, questionKeywords(item, plan, linkId, mapped));
1542
+ const initial = initialOf(item);
1543
+ if (initial) this.initials.set(item.linkId, initial);
1544
+ return path;
1545
+ }
1546
+ // A question's answer: its options, its text of one's own or note, its help.
1547
+ answer(model, path, keyPath, plan) {
1548
+ let next = model;
1549
+ if (plan.options) next = setOptions(next, path, plan.options.options);
1550
+ if (plan.valueType)
1551
+ next = setValueTypeSettings(
1552
+ next,
1553
+ path,
1554
+ plan.valueType.fhir.answer,
1555
+ plan.valueType.settings
1556
+ );
1557
+ if (plan.open) next = this.other(next, path, plan);
1558
+ if (plan.note) next = this.note(next, path, keyPath, plan.note);
1559
+ if (plan.help) next = setHelp(next, path, plan.help.text ?? "");
1560
+ return next;
1561
+ }
1562
+ // An open choice's option asking for the text: ours, when the extension names it; else the default.
1563
+ other(model, path, plan) {
1564
+ const option = plan.other?.option ?? OTHER_OPTION2;
1565
+ const options = [...plan.options?.options ?? [], option];
1566
+ return setChoiceTextWhen(
1567
+ setOptions(model, path, options),
1568
+ path,
1569
+ option.value
1570
+ );
1571
+ }
1572
+ // A choice's note: the text under it, its title and its linkId.
1573
+ note(model, path, keyPath, note) {
1574
+ const textPath = [...path, propSeg("text")];
1575
+ let next = withTitle(model, textPath, note.text, "text");
1576
+ if (note.type === "text")
1577
+ next = changeAnswerType(next, textPath, "longText").model;
1578
+ return note.linkId === `${keyPath}.text` ? next : setKeywords(next, textPath, { [X_FHIR_LINK_ID]: note.linkId });
1579
+ }
1580
+ // An item's enableWhen as its show-if; kept as it is when the show-if cannot say it.
1581
+ enableWhen(p, siblings) {
1582
+ const { enableWhen, enableBehavior } = p.item;
1583
+ if (!enableWhen?.length || p.kept) return;
1584
+ const read = enableWhen.map((e) => condition(e, siblings));
1585
+ const failed = read.find((c) => "why" in c);
1586
+ if (failed && "why" in failed) {
1587
+ this.notConverted.push({
1588
+ linkId: p.item.linkId,
1589
+ what: `enableWhen: ${failed.why}; kept, not applied`
1590
+ });
1591
+ this.keep(
1592
+ p.path,
1593
+ annotationsOf({
1594
+ enableWhen,
1595
+ ...enableBehavior ? { enableBehavior } : {}
1596
+ })
1597
+ );
1598
+ return;
1599
+ }
1600
+ const showIf = {
1601
+ behavior: enableBehavior ?? "all",
1602
+ conditions: read.flatMap((c) => "condition" in c ? [c.condition] : [])
1603
+ };
1604
+ this.model = setShowIf(this.model, p.path, showIf).model;
1605
+ }
1606
+ };
1607
+ var ANSWER_KEYS = [
1608
+ "answerBoolean",
1609
+ "answerString",
1610
+ "answerInteger",
1611
+ "answerDecimal",
1612
+ "answerDate",
1613
+ "answerTime",
1614
+ "answerDateTime"
1615
+ ];
1616
+ function condition(e, siblings) {
1617
+ const tested = siblings.find((s) => s.item.linkId === e.question);
1618
+ if (!tested) return { why: "a question outside its group" };
1619
+ if (tested.kept) return { why: "a question kept whole" };
1620
+ if (!OPERATORS.includes(e.operator)) return { why: `operator ${e.operator}` };
1621
+ const operator = e.operator;
1622
+ if (operator === "exists")
1623
+ return e.answerBoolean === true ? { condition: { field: tested.key, operator, value: "" } } : { why: "exists false" };
1624
+ const read = answerValue(e, tested);
1625
+ return "value" in read ? { condition: { field: tested.key, operator, ...read } } : read;
1626
+ }
1627
+ function answerValue(e, tested) {
1628
+ const valueType = tested.valueType;
1629
+ if (valueType?.fhir.fromEnableAnswer)
1630
+ return valueType.fhir.fromEnableAnswer(e, {
1631
+ settings: valueType.settings,
1632
+ system: tested.system
1633
+ });
1634
+ if (e.answerCoding) {
1635
+ const { system, code, ...rest } = e.answerCoding;
1636
+ return Object.keys(rest).length || system && system !== tested.system ? { why: "answerCoding beyond a code of the question's options" } : { value: code };
1637
+ }
1638
+ const key = ANSWER_KEYS.find((k) => e[k] !== void 0);
1639
+ return key ? { value: String(e[key]) } : { why: "an answer of a type the show-if does not compare" };
1640
+ }
1641
+ function fromFhirQuestionnaire(questionnaire, options) {
1642
+ const reader = new QuestionnaireReader(
1643
+ valueTypesOf(options),
1644
+ spellingOf(options.version)
1645
+ );
1646
+ reader.model = setQuestionnaireText(reader.model, {
1647
+ ...questionnaire.title ? { title: questionnaire.title } : {},
1648
+ ...questionnaire.description ? { description: questionnaire.description } : {}
1649
+ });
1650
+ reader.read(questionnaire.item ?? [], { path: [], keyPath: "", linkId: "" });
1651
+ reader.applyInitials();
1652
+ const { status, ...rest } = unmapped(
1653
+ questionnaire,
1654
+ MAPPED_ROOT,
1655
+ questionnaire.extension ?? []
1656
+ );
1657
+ reader.model = setKeywords(
1658
+ reader.model,
1659
+ [],
1660
+ annotationsOf({
1661
+ ...rest,
1662
+ ...status && status !== "draft" ? { status } : {}
1663
+ })
1664
+ );
1665
+ return {
1666
+ model: reader.model,
1667
+ notConverted: [
1668
+ ...reader.notConverted,
1669
+ ...notUnderstood(reader.model, reader.types)
1670
+ ]
1671
+ };
1672
+ }
1673
+ function notUnderstood(model, types) {
1674
+ return itemsOf(classifyQuestionnaire4(model, answerTypesOf(types)).items).filter((i) => i.kind === "locked").filter((i) => {
1675
+ const prop = getProperty5(model.schema, i.path);
1676
+ return !prop?.[X_FHIR_ITEM];
1677
+ }).map((i) => ({
1678
+ linkId: linkIdOf(model, i),
1679
+ what: `${i.kind === "locked" ? i.reason : ""}; read, not understood`
1680
+ }));
1681
+ }
1682
+ export {
1683
+ CODEABLE_CONCEPT_FHIR,
1684
+ CODING_FHIR,
1685
+ DATA_ABSENT_REASON,
1686
+ DEFAULT_FHIR_VALUE_TYPES,
1687
+ ENTRY_FORMAT,
1688
+ FHIR_TYPE_INDEPENDENT_ANNOTATIONS,
1689
+ ITEM_CONTROL,
1690
+ ITEM_CONTROL_SYSTEM,
1691
+ MAX_OCCURS,
1692
+ MAX_VALUE,
1693
+ MIN_LENGTH,
1694
+ MIN_OCCURS,
1695
+ MIN_VALUE,
1696
+ OTHER_OPTION_EXTENSION,
1697
+ QUANTITY_FHIR,
1698
+ REGEX,
1699
+ UNIT_OPTION,
1700
+ X_FHIR,
1701
+ X_FHIR_EXTENSION,
1702
+ X_FHIR_HELP_LINK_ID,
1703
+ X_FHIR_ITEM,
1704
+ X_FHIR_LEAD_QUESTION,
1705
+ X_FHIR_LINK_ID,
1706
+ X_FHIR_SYSTEM,
1707
+ answerTypesOf,
1708
+ claimsItem,
1709
+ fhirValueType,
1710
+ fromFhirQuestionnaire,
1711
+ fromFhirQuestionnaireResponse,
1712
+ isFhirAnnotation,
1713
+ itemOf,
1714
+ toFhirQuestionnaire,
1715
+ toFhirQuestionnaireResponse,
1716
+ valueTypesOf
1717
+ };
1718
+ //# sourceMappingURL=index.js.map