Skip to content

Commit f0d8913

Browse files
committed
Add missing mocks
1 parent d988488 commit f0d8913

1 file changed

Lines changed: 278 additions & 5 deletions

File tree

packages/smart-forms-renderer/.storybook/preview.tsx

Lines changed: 278 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Preview } from '@storybook/react-vite';
2+
import type { Bundle, Condition, Observation, ValueSet } from 'fhir/r4';
23
import '@fontsource/roboto/300.css';
34
import '@fontsource/roboto/400.css';
45
import '@fontsource/roboto/500.css';
@@ -9,11 +10,106 @@ import { createTheme } from '@mui/material/styles';
910
import { CssBaseline, ThemeProvider } from '@mui/material';
1011
import '../src/stories/storybookWrappers/iframeResizerChild.js';
1112

12-
const mockLibrary: Record<string, unknown> = {
13+
const createObservationBundle = (observation: Observation): Bundle => ({
14+
resourceType: 'Bundle',
15+
type: 'searchset',
16+
total: 1,
17+
entry: [{ resource: observation }]
18+
});
19+
20+
const formPopulationConditions: Condition[] = [
21+
{
22+
resourceType: 'Condition',
23+
id: 'condition-diabetes-pat-sf',
24+
subject: {
25+
reference: 'Patient/pat-sf'
26+
},
27+
category: [
28+
{
29+
coding: [
30+
{
31+
system: 'http://terminology.hl7.org/CodeSystem/condition-category',
32+
code: 'problem-list-item'
33+
}
34+
]
35+
}
36+
],
37+
code: {
38+
coding: [
39+
{
40+
system: 'http://snomed.info/sct',
41+
code: '44054006',
42+
display: 'Diabetes mellitus type 2'
43+
}
44+
],
45+
text: 'Diabetes mellitus type 2'
46+
},
47+
clinicalStatus: {
48+
coding: [
49+
{
50+
system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
51+
code: 'active',
52+
display: 'Active'
53+
}
54+
]
55+
},
56+
onsetDateTime: '2020-01-10',
57+
recordedDate: '2020-01-15'
58+
},
59+
{
60+
resourceType: 'Condition',
61+
id: 'condition-asthma-pat-sf',
62+
subject: {
63+
reference: 'Patient/pat-sf'
64+
},
65+
category: [
66+
{
67+
coding: [
68+
{
69+
system: 'http://terminology.hl7.org/CodeSystem/condition-category',
70+
code: 'problem-list-item'
71+
}
72+
]
73+
}
74+
],
75+
code: {
76+
coding: [
77+
{
78+
system: 'http://snomed.info/sct',
79+
code: '195967001',
80+
display: 'Asthma'
81+
}
82+
],
83+
text: 'Asthma'
84+
},
85+
clinicalStatus: {
86+
coding: [
87+
{
88+
system: 'http://terminology.hl7.org/CodeSystem/condition-clinical',
89+
code: 'resolved',
90+
display: 'Resolved'
91+
}
92+
]
93+
},
94+
onsetDateTime: '2018-05-01',
95+
recordedDate: '2018-05-03'
96+
}
97+
];
98+
99+
const formPopulationConditionBundle: Bundle = {
100+
resourceType: 'Bundle',
101+
type: 'searchset',
102+
total: formPopulationConditions.length,
103+
entry: formPopulationConditions.map((resource) => ({ resource }))
104+
};
105+
106+
const mockLibrary: Record<string, Bundle | ValueSet> = {
13107
'https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/administrative-gender':
14108
{
15109
resourceType: 'ValueSet',
110+
status: 'active',
16111
expansion: {
112+
timestamp: '2026-01-01T00:00:00Z',
17113
contains: [
18114
{
19115
code: 'female',
@@ -33,7 +129,9 @@ const mockLibrary: Record<string, unknown> = {
33129
'https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=https://healthterminologies.gov.au/fhir/ValueSet/australian-states-territories-2':
34130
{
35131
resourceType: 'ValueSet',
132+
status: 'active',
36133
expansion: {
134+
timestamp: '2026-01-01T00:00:00Z',
37135
contains: [
38136
{
39137
system:
@@ -95,7 +193,9 @@ const mockLibrary: Record<string, unknown> = {
95193
'https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=https://smartforms.csiro.au/ig/ValueSet/MedicalHistory&filter=Asthma&count=10':
96194
{
97195
resourceType: 'ValueSet',
196+
status: 'active',
98197
expansion: {
198+
timestamp: '2026-01-01T00:00:00Z',
99199
contains: [
100200
{
101201
system: 'http://snomed.info/sct',
@@ -108,7 +208,9 @@ const mockLibrary: Record<string, unknown> = {
108208
'https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=https://smartforms.csiro.au/ig/ValueSet/MedicalHistory&filter=Hypertension&count=10':
109209
{
110210
resourceType: 'ValueSet',
211+
status: 'active',
111212
expansion: {
213+
timestamp: '2026-01-01T00:00:00Z',
112214
contains: [
113215
{
114216
system: 'http://snomed.info/sct',
@@ -121,7 +223,9 @@ const mockLibrary: Record<string, unknown> = {
121223
'https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/languages':
122224
{
123225
resourceType: 'ValueSet',
226+
status: 'active',
124227
expansion: {
228+
timestamp: '2026-01-01T00:00:00Z',
125229
contains: [
126230
{
127231
system: 'urn:ietf:bcp:47',
@@ -144,7 +248,9 @@ const mockLibrary: Record<string, unknown> = {
144248
'https://sqlonfhir-r4.azurewebsites.net/fhir/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/languages':
145249
{
146250
resourceType: 'ValueSet',
251+
status: 'active',
147252
expansion: {
253+
timestamp: '2026-01-01T00:00:00Z',
148254
contains: [
149255
{
150256
system: 'urn:ietf:bcp:47',
@@ -163,15 +269,180 @@ const mockLibrary: Record<string, unknown> = {
163269
}
164270
]
165271
}
166-
}
272+
},
273+
'https://proxy.smartforms.io/v/r4/fhir/Condition?patient=pat-sf': formPopulationConditionBundle,
274+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=72166-2&_count=1&_sort=-date&patient=pat-sf':
275+
createObservationBundle({
276+
resourceType: 'Observation',
277+
id: 'observation-smoking-status-pat-sf',
278+
status: 'final',
279+
code: {
280+
coding: [{ system: 'http://loinc.org', code: '72166-2', display: 'Tobacco smoking status' }]
281+
},
282+
valueCodeableConcept: {
283+
coding: [{ system: 'http://snomed.info/sct', code: '8517006', display: 'Ex-Smoker' }]
284+
}
285+
}),
286+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=8302-2&_count=1&_sort=-date&patient=pat-sf':
287+
createObservationBundle({
288+
resourceType: 'Observation',
289+
id: 'observation-height-pat-sf',
290+
status: 'final',
291+
code: {
292+
coding: [{ system: 'http://loinc.org', code: '8302-2', display: 'Body height' }]
293+
},
294+
valueQuantity: { value: 163, unit: 'cm', system: 'http://unitsofmeasure.org', code: 'cm' }
295+
}),
296+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=29463-7&_count=1&_sort=-date&patient=pat-sf':
297+
createObservationBundle({
298+
resourceType: 'Observation',
299+
id: 'observation-weight-pat-sf',
300+
status: 'final',
301+
code: {
302+
coding: [{ system: 'http://loinc.org', code: '29463-7', display: 'Body weight' }]
303+
},
304+
valueQuantity: { value: 77.3, unit: 'kg', system: 'http://unitsofmeasure.org', code: 'kg' }
305+
}),
306+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=9843-4&_count=1&_sort=-date&patient=pat-sf':
307+
createObservationBundle({
308+
resourceType: 'Observation',
309+
id: 'observation-head-circumference-pat-sf',
310+
status: 'final',
311+
code: {
312+
coding: [
313+
{
314+
system: 'http://loinc.org',
315+
code: '9843-4',
316+
display: 'Head Occipital-frontal circumference'
317+
}
318+
]
319+
},
320+
valueQuantity: { value: 56.1, unit: 'cm', system: 'http://unitsofmeasure.org', code: 'cm' }
321+
}),
322+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=8280-0&_count=1&_sort=-date&patient=pat-sf':
323+
createObservationBundle({
324+
resourceType: 'Observation',
325+
id: 'observation-waist-circumference-pat-sf',
326+
status: 'final',
327+
code: {
328+
coding: [
329+
{
330+
system: 'http://loinc.org',
331+
code: '8280-0',
332+
display: 'Waist Circumference at umbilicus by Tape measure'
333+
}
334+
]
335+
},
336+
valueQuantity: { value: 91.4, unit: 'cm', system: 'http://unitsofmeasure.org', code: 'cm' }
337+
}),
338+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=85354-9&_count=1&_sort=-date&patient=pat-sf':
339+
createObservationBundle({
340+
resourceType: 'Observation',
341+
id: 'observation-blood-pressure-pat-sf',
342+
status: 'final',
343+
code: {
344+
coding: [
345+
{
346+
system: 'http://loinc.org',
347+
code: '85354-9',
348+
display: 'Blood pressure panel with all children optional'
349+
}
350+
]
351+
},
352+
component: [
353+
{
354+
code: {
355+
coding: [
356+
{ system: 'http://loinc.org', code: '8480-6', display: 'Systolic blood pressure' }
357+
]
358+
},
359+
valueQuantity: {
360+
value: 124,
361+
unit: 'mm[Hg]',
362+
system: 'http://unitsofmeasure.org',
363+
code: 'mm[Hg]'
364+
}
365+
},
366+
{
367+
code: {
368+
coding: [
369+
{ system: 'http://loinc.org', code: '8462-4', display: 'Diastolic blood pressure' }
370+
]
371+
},
372+
valueQuantity: {
373+
value: 78,
374+
unit: 'mm[Hg]',
375+
system: 'http://unitsofmeasure.org',
376+
code: 'mm[Hg]'
377+
}
378+
}
379+
]
380+
}),
381+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=8867-4&_count=1&_sort=-date&patient=pat-sf':
382+
createObservationBundle({
383+
resourceType: 'Observation',
384+
id: 'observation-heart-rate-pat-sf',
385+
status: 'final',
386+
code: {
387+
coding: [{ system: 'http://loinc.org', code: '8867-4', display: 'Heart rate' }]
388+
},
389+
valueQuantity: {
390+
value: 72,
391+
unit: 'beats/minute',
392+
system: 'http://unitsofmeasure.org',
393+
code: '/min'
394+
}
395+
}),
396+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=14647-2&_count=1&_sort=-date&patient=pat-sf':
397+
createObservationBundle({
398+
resourceType: 'Observation',
399+
id: 'observation-total-cholesterol-pat-sf',
400+
status: 'final',
401+
code: {
402+
coding: [
403+
{
404+
system: 'http://loinc.org',
405+
code: '14647-2',
406+
display: 'Cholesterol [Moles/volume] in Serum or Plasma'
407+
}
408+
]
409+
},
410+
valueQuantity: {
411+
value: 5.4,
412+
unit: 'mmol/L',
413+
system: 'http://unitsofmeasure.org',
414+
code: 'mmol/L'
415+
}
416+
}),
417+
'https://proxy.smartforms.io/v/r4/fhir/Observation?code=14646-4&_count=1&_sort=-date&patient=pat-sf':
418+
createObservationBundle({
419+
resourceType: 'Observation',
420+
id: 'observation-hdl-cholesterol-pat-sf',
421+
status: 'final',
422+
code: {
423+
coding: [
424+
{
425+
system: 'http://loinc.org',
426+
code: '14646-4',
427+
display: 'Cholesterol in HDL [Moles/volume] in Serum or Plasma'
428+
}
429+
]
430+
},
431+
valueQuantity: {
432+
value: 1.6,
433+
unit: 'mmol/L',
434+
system: 'http://unitsofmeasure.org',
435+
code: 'mmol/L'
436+
}
437+
})
167438
};
168439

169440
// If running CI tests, override the global fetch function to return mock responses for specific URLs.
170441
// This allows Storybook stories to work with predictable test data without relying on real network requests.
171-
// @ts-ignore
442+
// @ts-expect-error - `import.meta.env` typing differs in Storybook runtime
172443
const isCI = import.meta.env.VITE_CI === 'true';
173444
if (isCI) {
174-
global.fetch = (async (input: RequestInfo | URL) => {
445+
const ciFetch: typeof fetch = async (input) => {
175446
const url =
176447
typeof input === 'string' ? input.trim() : input instanceof URL ? input.href : input.url;
177448

@@ -186,7 +457,9 @@ if (isCI) {
186457
status: 404,
187458
headers: { 'Content-Type': 'application/json' }
188459
});
189-
}) as typeof fetch;
460+
};
461+
462+
global.fetch = ciFetch;
190463
}
191464

192465
export const decorators = [

0 commit comments

Comments
 (0)