@aehrc/smart-forms-renderer 0.39.0 → 0.40.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/lib/index.d.ts +1 -1
  3. package/lib/index.js +1 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/tests/test-data/observationSample.d.ts +2 -0
  6. package/lib/tests/test-data/observationSample.js +523 -0
  7. package/lib/tests/test-data/observationSample.js.map +1 -1
  8. package/lib/utils/dynamicValueSet.d.ts +1 -1
  9. package/lib/utils/extractObservation.d.ts +5 -0
  10. package/lib/utils/extractObservation.js +121 -33
  11. package/lib/utils/extractObservation.js.map +1 -1
  12. package/lib/utils/fhirpathAsyncUtils/fhirpath-async.js +1 -1
  13. package/lib/utils/fhirpathAsyncUtils/fhirpath-async.js.map +1 -1
  14. package/lib/utils/fhirpathAsyncUtils/outcome-utils.js +3 -3
  15. package/lib/utils/fhirpathAsyncUtils/outcome-utils.js.map +1 -1
  16. package/lib/utils/genericRecursive.d.ts +5 -2
  17. package/lib/utils/genericRecursive.js +10 -2
  18. package/lib/utils/genericRecursive.js.map +1 -1
  19. package/lib/utils/index.d.ts +1 -0
  20. package/lib/utils/index.js +1 -0
  21. package/lib/utils/index.js.map +1 -1
  22. package/lib/utils/itemControl.js +1 -1
  23. package/lib/utils/itemControl.js.map +1 -1
  24. package/lib/utils/qItem.js +5 -0
  25. package/lib/utils/qItem.js.map +1 -1
  26. package/lib/utils/questionnaireStoreUtils/extractPreferredTerminologyServerUrls.d.ts +3 -0
  27. package/lib/utils/questionnaireStoreUtils/extractPreferredTerminologyServerUrls.js +34 -0
  28. package/lib/utils/questionnaireStoreUtils/extractPreferredTerminologyServerUrls.js.map +1 -0
  29. package/package.json +1 -1
  30. package/src/index.ts +2 -1
  31. package/src/tests/extractObservation.test.ts +132 -0
  32. package/src/tests/test-data/observationSample.ts +721 -0
  33. package/src/utils/extractObservation.ts +284 -0
  34. package/src/utils/genericRecursive.ts +27 -5
  35. package/src/utils/index.ts +1 -0
  36. package/src/utils/itemControl.ts +1 -1
  37. package/src/utils/qItem.ts +6 -0
@@ -0,0 +1,721 @@
1
+ import type { Observation, Questionnaire, QuestionnaireResponse } from 'fhir/r4';
2
+
3
+ export const qObservationSample: Questionnaire = {
4
+ resourceType: 'Questionnaire',
5
+ id: 'phq-2-questionnaire',
6
+ meta: {
7
+ versionId: '1',
8
+ lastUpdated: '2024-08-29T12:00:00Z'
9
+ },
10
+ title: 'PHQ-2 Depression Screening',
11
+ status: 'active',
12
+ date: '2024-08-29T12:00:00Z',
13
+ publisher: 'Konsulin',
14
+ description: 'Patient Health Questionnaire-2 (PHQ-2) for depression screening.',
15
+ subjectType: ['Patient'],
16
+ item: [
17
+ {
18
+ linkId: 'phq2-1',
19
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
20
+ type: 'choice',
21
+ code: [
22
+ {
23
+ system: 'http://snomed.info/sct',
24
+ code: '28669007',
25
+ display: 'Anhedonia'
26
+ }
27
+ ],
28
+ answerOption: [
29
+ {
30
+ valueCoding: {
31
+ code: '0',
32
+ display: 'Not at all'
33
+ }
34
+ },
35
+ {
36
+ valueCoding: {
37
+ code: '1',
38
+ display: 'Several days'
39
+ }
40
+ },
41
+ {
42
+ valueCoding: {
43
+ code: '2',
44
+ display: 'More than half the days'
45
+ }
46
+ },
47
+ {
48
+ valueCoding: {
49
+ code: '3',
50
+ display: 'Nearly every day'
51
+ }
52
+ }
53
+ ]
54
+ },
55
+ {
56
+ linkId: 'phq2-2',
57
+ text: 'Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?',
58
+ type: 'choice',
59
+ code: [
60
+ {
61
+ system: 'http://snomed.info/sct',
62
+ code: '307077003',
63
+ display: 'Feeling hopeless'
64
+ }
65
+ ],
66
+ answerOption: [
67
+ {
68
+ valueCoding: {
69
+ code: '0',
70
+ display: 'Not at all'
71
+ }
72
+ },
73
+ {
74
+ valueCoding: {
75
+ code: '1',
76
+ display: 'Several days'
77
+ }
78
+ },
79
+ {
80
+ valueCoding: {
81
+ code: '2',
82
+ display: 'More than half the days'
83
+ }
84
+ },
85
+ {
86
+ valueCoding: {
87
+ code: '3',
88
+ display: 'Nearly every day'
89
+ }
90
+ }
91
+ ]
92
+ }
93
+ ]
94
+ };
95
+
96
+ export const qObservationSampleWithExtractExtension: Questionnaire = {
97
+ resourceType: 'Questionnaire',
98
+ id: 'phq-2-questionnaire',
99
+ meta: {
100
+ versionId: '1',
101
+ lastUpdated: '2024-09-06T15:33:00Z'
102
+ },
103
+ title: 'PHQ-2 Depression Screening',
104
+ status: 'active',
105
+ date: '2024-08-29T12:00:00Z',
106
+ publisher: 'Konsulin',
107
+ description: 'Patient Health Questionnaire-2 (PHQ-2) for depression screening.',
108
+ subjectType: ['Patient'],
109
+ extension: [
110
+ {
111
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
112
+ valueBoolean: false
113
+ }
114
+ ],
115
+ item: [
116
+ {
117
+ linkId: 'phq2-1',
118
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
119
+ type: 'choice',
120
+ code: [
121
+ {
122
+ system: 'http://snomed.info/sct',
123
+ code: '28669007',
124
+ display: 'Anhedonia'
125
+ }
126
+ ],
127
+ answerOption: [
128
+ {
129
+ valueCoding: {
130
+ code: '0',
131
+ display: 'Not at all'
132
+ }
133
+ },
134
+ {
135
+ valueCoding: {
136
+ code: '1',
137
+ display: 'Several days'
138
+ }
139
+ },
140
+ {
141
+ valueCoding: {
142
+ code: '2',
143
+ display: 'More than half the days'
144
+ }
145
+ },
146
+ {
147
+ valueCoding: {
148
+ code: '3',
149
+ display: 'Nearly every day'
150
+ }
151
+ }
152
+ ],
153
+ extension: [
154
+ {
155
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
156
+ valueBoolean: true
157
+ }
158
+ ],
159
+ item: [
160
+ {
161
+ linkId: 'phq2-8',
162
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
163
+ type: 'choice',
164
+ code: [
165
+ {
166
+ system: 'http://snomed.info/sct',
167
+ code: '28669007',
168
+ display: 'Anhedonia'
169
+ }
170
+ ],
171
+ answerOption: [
172
+ {
173
+ valueCoding: {
174
+ code: '0',
175
+ display: 'Not at all'
176
+ }
177
+ },
178
+ {
179
+ valueCoding: {
180
+ code: '1',
181
+ display: 'Several days'
182
+ }
183
+ },
184
+ {
185
+ valueCoding: {
186
+ code: '2',
187
+ display: 'More than half the days'
188
+ }
189
+ },
190
+ {
191
+ valueCoding: {
192
+ code: '3',
193
+ display: 'Nearly every day'
194
+ }
195
+ }
196
+ ]
197
+ }
198
+ ]
199
+ },
200
+ {
201
+ linkId: 'phq2-2',
202
+ text: 'Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?',
203
+ type: 'choice',
204
+ code: [
205
+ {
206
+ system: 'http://snomed.info/sct',
207
+ code: '307077003',
208
+ display: 'Feeling hopeless'
209
+ }
210
+ ],
211
+ answerOption: [
212
+ {
213
+ valueCoding: {
214
+ code: '0',
215
+ display: 'Not at all'
216
+ }
217
+ },
218
+ {
219
+ valueCoding: {
220
+ code: '1',
221
+ display: 'Several days'
222
+ }
223
+ },
224
+ {
225
+ valueCoding: {
226
+ code: '2',
227
+ display: 'More than half the days'
228
+ }
229
+ },
230
+ {
231
+ valueCoding: {
232
+ code: '3',
233
+ display: 'Nearly every day'
234
+ }
235
+ }
236
+ ],
237
+ extension: [
238
+ {
239
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
240
+ valueBoolean: false
241
+ }
242
+ ],
243
+ item: [
244
+ {
245
+ linkId: 'phq2-4',
246
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
247
+ type: 'choice',
248
+ code: [
249
+ {
250
+ system: 'http://snomed.info/sct',
251
+ code: '28669007',
252
+ display: 'Anhedonia'
253
+ }
254
+ ],
255
+ answerOption: [
256
+ {
257
+ valueCoding: {
258
+ code: '0',
259
+ display: 'Not at all'
260
+ }
261
+ },
262
+ {
263
+ valueCoding: {
264
+ code: '1',
265
+ display: 'Several days'
266
+ }
267
+ },
268
+ {
269
+ valueCoding: {
270
+ code: '2',
271
+ display: 'More than half the days'
272
+ }
273
+ },
274
+ {
275
+ valueCoding: {
276
+ code: '3',
277
+ display: 'Nearly every day'
278
+ }
279
+ }
280
+ ],
281
+ extension: [
282
+ {
283
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
284
+ valueBoolean: true
285
+ }
286
+ ]
287
+ }
288
+ ]
289
+ },
290
+ {
291
+ linkId: 'phq2-3',
292
+ text: 'Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?',
293
+ type: 'choice',
294
+ code: [
295
+ {
296
+ system: 'http://snomed.info/sct',
297
+ code: '307077003',
298
+ display: 'Feeling hopeless'
299
+ }
300
+ ],
301
+ answerOption: [
302
+ {
303
+ valueCoding: {
304
+ code: '0',
305
+ display: 'Not at all'
306
+ }
307
+ },
308
+ {
309
+ valueCoding: {
310
+ code: '1',
311
+ display: 'Several days'
312
+ }
313
+ },
314
+ {
315
+ valueCoding: {
316
+ code: '2',
317
+ display: 'More than half the days'
318
+ }
319
+ },
320
+ {
321
+ valueCoding: {
322
+ code: '3',
323
+ display: 'Nearly every day'
324
+ }
325
+ }
326
+ ],
327
+ item: [
328
+ {
329
+ linkId: 'phq2-5',
330
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
331
+ type: 'choice',
332
+ code: [
333
+ {
334
+ system: 'http://snomed.info/sct',
335
+ code: '28669007',
336
+ display: 'Anhedonia'
337
+ }
338
+ ],
339
+ answerOption: [
340
+ {
341
+ valueCoding: {
342
+ code: '0',
343
+ display: 'Not at all'
344
+ }
345
+ },
346
+ {
347
+ valueCoding: {
348
+ code: '1',
349
+ display: 'Several days'
350
+ }
351
+ },
352
+ {
353
+ valueCoding: {
354
+ code: '2',
355
+ display: 'More than half the days'
356
+ }
357
+ },
358
+ {
359
+ valueCoding: {
360
+ code: '3',
361
+ display: 'Nearly every day'
362
+ }
363
+ }
364
+ ],
365
+ extension: [
366
+ {
367
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
368
+ valueBoolean: true
369
+ }
370
+ ]
371
+ },
372
+ {
373
+ linkId: 'phq2-6',
374
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
375
+ type: 'choice',
376
+ code: [
377
+ {
378
+ system: 'http://snomed.info/sct',
379
+ code: '28669007',
380
+ display: 'Anhedonia'
381
+ }
382
+ ],
383
+ answerOption: [
384
+ {
385
+ valueCoding: {
386
+ code: '0',
387
+ display: 'Not at all'
388
+ }
389
+ },
390
+ {
391
+ valueCoding: {
392
+ code: '1',
393
+ display: 'Several days'
394
+ }
395
+ },
396
+ {
397
+ valueCoding: {
398
+ code: '2',
399
+ display: 'More than half the days'
400
+ }
401
+ },
402
+ {
403
+ valueCoding: {
404
+ code: '3',
405
+ display: 'Nearly every day'
406
+ }
407
+ }
408
+ ],
409
+ extension: [
410
+ {
411
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
412
+ valueBoolean: false
413
+ }
414
+ ]
415
+ },
416
+ {
417
+ linkId: 'phq2-7',
418
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
419
+ type: 'choice',
420
+ code: [
421
+ {
422
+ system: 'http://snomed.info/sct',
423
+ code: '28669007',
424
+ display: 'Anhedonia'
425
+ }
426
+ ],
427
+ answerOption: [
428
+ {
429
+ valueCoding: {
430
+ code: '0',
431
+ display: 'Not at all'
432
+ }
433
+ },
434
+ {
435
+ valueCoding: {
436
+ code: '1',
437
+ display: 'Several days'
438
+ }
439
+ },
440
+ {
441
+ valueCoding: {
442
+ code: '2',
443
+ display: 'More than half the days'
444
+ }
445
+ },
446
+ {
447
+ valueCoding: {
448
+ code: '3',
449
+ display: 'Nearly every day'
450
+ }
451
+ }
452
+ ]
453
+ }
454
+ ]
455
+ }
456
+ ]
457
+ };
458
+
459
+ export const qrObservationSample: QuestionnaireResponse = {
460
+ resourceType: 'QuestionnaireResponse',
461
+ id: 'phq2-response',
462
+ questionnaire: 'https://fhir.konsulin.care/fhir/Questionnaire/phq-2-questionnaire',
463
+ status: 'completed',
464
+ subject: {
465
+ reference: 'Patient/123'
466
+ },
467
+ authored: '2024-08-29T12:00:00Z',
468
+ item: [
469
+ {
470
+ linkId: 'phq2-1',
471
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
472
+ answer: [
473
+ {
474
+ valueCoding: {
475
+ code: '2',
476
+ display: 'More than half the days'
477
+ }
478
+ }
479
+ ],
480
+ item: [
481
+ {
482
+ linkId: 'phq2-8',
483
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
484
+ answer: [
485
+ {
486
+ valueCoding: {
487
+ code: '2',
488
+ display: 'More than half the days'
489
+ }
490
+ }
491
+ ]
492
+ }
493
+ ]
494
+ },
495
+ {
496
+ linkId: 'phq2-2',
497
+ text: 'Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?',
498
+ answer: [
499
+ {
500
+ valueCoding: {
501
+ code: '1',
502
+ display: 'Several days'
503
+ }
504
+ }
505
+ ],
506
+ item: [
507
+ {
508
+ linkId: 'phq2-4',
509
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
510
+ answer: [
511
+ {
512
+ valueCoding: {
513
+ code: '1',
514
+ display: 'Several days'
515
+ }
516
+ }
517
+ ]
518
+ }
519
+ ]
520
+ },
521
+ {
522
+ linkId: 'phq2-3',
523
+ text: 'Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?',
524
+ answer: [
525
+ {
526
+ valueCoding: {
527
+ code: '1',
528
+ display: 'Several days'
529
+ }
530
+ }
531
+ ],
532
+ item: [
533
+ {
534
+ linkId: 'phq2-5',
535
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
536
+ answer: [
537
+ {
538
+ valueCoding: {
539
+ code: '1',
540
+ display: 'Several days'
541
+ }
542
+ }
543
+ ]
544
+ },
545
+ {
546
+ linkId: 'phq2-6',
547
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
548
+ answer: [
549
+ {
550
+ valueCoding: {
551
+ code: '1',
552
+ display: 'Several days'
553
+ }
554
+ }
555
+ ]
556
+ },
557
+ {
558
+ linkId: 'phq2-7',
559
+ text: 'Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?',
560
+ answer: [
561
+ {
562
+ valueCoding: {
563
+ code: '1',
564
+ display: 'Several days'
565
+ }
566
+ }
567
+ ]
568
+ }
569
+ ]
570
+ }
571
+ ]
572
+ };
573
+
574
+ export const observationResults: Observation[] = [
575
+ {
576
+ resourceType: 'Observation',
577
+ id: 'obs-phq2-1',
578
+ status: 'final',
579
+ code: {
580
+ coding: [
581
+ {
582
+ system: 'http://snomed.info/sct',
583
+ code: '28669007',
584
+ display: 'Anhedonia'
585
+ }
586
+ ]
587
+ },
588
+ subject: {
589
+ reference: 'Patient/123'
590
+ },
591
+ derivedFrom: [
592
+ {
593
+ reference: 'QuestionnaireResponse/phq2-response'
594
+ }
595
+ ],
596
+ effectiveDateTime: '2024-08-29T12:00:00Z',
597
+ issued: '2024-08-29T12:00:00Z',
598
+ valueCodeableConcept: {
599
+ coding: [
600
+ {
601
+ code: '2',
602
+ display: 'More than half the days'
603
+ }
604
+ ]
605
+ }
606
+ },
607
+ {
608
+ resourceType: 'Observation',
609
+ id: 'obs-phq2-2',
610
+ status: 'final',
611
+ code: {
612
+ coding: [
613
+ {
614
+ system: 'http://snomed.info/sct',
615
+ code: '307077003',
616
+ display: 'Feeling hopeless'
617
+ }
618
+ ]
619
+ },
620
+ subject: {
621
+ reference: 'Patient/123'
622
+ },
623
+ derivedFrom: [
624
+ {
625
+ reference: 'QuestionnaireResponse/phq2-response'
626
+ }
627
+ ],
628
+ effectiveDateTime: '2024-08-29T12:00:00Z',
629
+ issued: '2024-08-29T12:00:00Z',
630
+ valueCodeableConcept: {
631
+ coding: [
632
+ {
633
+ code: '1',
634
+ display: 'Several days'
635
+ }
636
+ ]
637
+ }
638
+ }
639
+ ];
640
+
641
+ export const qExtractSample: Questionnaire = {
642
+ resourceType: 'Questionnaire',
643
+ id: 'phq-2-questionnaire',
644
+ status: 'draft',
645
+ extension: [
646
+ {
647
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
648
+ valueBoolean: false
649
+ }
650
+ ],
651
+ item: [
652
+ {
653
+ linkId: 'phq2-1',
654
+ type: 'choice',
655
+ extension: [
656
+ {
657
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
658
+ valueBoolean: true
659
+ }
660
+ ],
661
+ item: [
662
+ {
663
+ linkId: 'phq2-8',
664
+ type: 'choice'
665
+ }
666
+ ]
667
+ },
668
+ {
669
+ linkId: 'phq2-2',
670
+ type: 'choice',
671
+ extension: [
672
+ {
673
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
674
+ valueBoolean: false
675
+ }
676
+ ],
677
+ item: [
678
+ {
679
+ linkId: 'phq2-4',
680
+ type: 'choice',
681
+ extension: [
682
+ {
683
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
684
+ valueBoolean: true
685
+ }
686
+ ]
687
+ }
688
+ ]
689
+ },
690
+ {
691
+ linkId: 'phq2-3',
692
+ type: 'choice',
693
+ item: [
694
+ {
695
+ linkId: 'phq2-5',
696
+ type: 'choice',
697
+ extension: [
698
+ {
699
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
700
+ valueBoolean: true
701
+ }
702
+ ]
703
+ },
704
+ {
705
+ linkId: 'phq2-6',
706
+ type: 'choice',
707
+ extension: [
708
+ {
709
+ url: 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract',
710
+ valueBoolean: false
711
+ }
712
+ ]
713
+ },
714
+ {
715
+ linkId: 'phq2-7',
716
+ type: 'choice'
717
+ }
718
+ ]
719
+ }
720
+ ]
721
+ };