fhir-react 0.3.1 → 0.3.5

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 (83) hide show
  1. package/README.md +85 -2
  2. package/build/bootstrap-reboot.min.css +8 -2
  3. package/build/index.js +7 -14
  4. package/build/style.css +26 -239
  5. package/package.json +3 -2
  6. package/src/assets/containers/Binary/binary.svg +9 -0
  7. package/src/assets/containers/Patient/patient.svg +6 -0
  8. package/src/components/containers/Accordion/Accordion.js +17 -12
  9. package/src/components/datatypes/Annotation/Annotation.js +4 -4
  10. package/src/components/datatypes/CodeableConcept/CodeableConcept.css +4 -1
  11. package/src/components/datatypes/Coding/Coding.css +0 -1
  12. package/src/components/datatypes/HeaderIcon/HeaderIcon.js +67 -22
  13. package/src/components/datatypes/Reference/Reference.css +3 -0
  14. package/src/components/datatypes/Reference/Reference.js +2 -0
  15. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +87 -76
  16. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +11 -1
  17. package/src/components/resources/Appointment/Appointment.js +3 -3
  18. package/src/components/resources/Appointment/Appointment.stories.js +28 -5
  19. package/src/components/resources/Appointment/Appointment.test.js +72 -0
  20. package/src/components/resources/Binary/Binary.js +31 -20
  21. package/src/components/resources/Binary/Binary.stories.js +6 -5
  22. package/src/components/resources/CarePlan/CarePlan.js +111 -96
  23. package/src/components/resources/CarePlan/CarePlan.test.js +2 -2
  24. package/src/components/resources/CarePlan/CarePlanActivity.js +6 -2
  25. package/src/components/resources/Condition/Condition.js +1 -2
  26. package/src/components/resources/Condition/Condition.stories.js +9 -19
  27. package/src/components/resources/Condition/Condition.test.js +71 -1
  28. package/src/components/resources/Device/Device.js +54 -34
  29. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +53 -43
  30. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +7 -1
  31. package/src/components/resources/DocumentReference/DocumentReference.js +101 -65
  32. package/src/components/resources/DocumentReference/DocumentReference.stories.js +4 -0
  33. package/src/components/resources/Encounter/Encounter.js +3 -4
  34. package/src/components/resources/Encounter/Encounter.stories.js +27 -5
  35. package/src/components/resources/Encounter/Encounter.test.js +72 -0
  36. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +26 -10
  37. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +8 -0
  38. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +80 -3
  39. package/src/components/resources/ExplanationOfBenefit/SupportingInfo.js +21 -6
  40. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +47 -38
  41. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +4 -0
  42. package/src/components/resources/Goal/Goal.js +104 -85
  43. package/src/components/resources/Goal/Goal.stories.js +37 -7
  44. package/src/components/resources/Goal/Goal.test.js +1 -3
  45. package/src/components/resources/Immunization/Immunization.js +1 -2
  46. package/src/components/resources/Immunization/Immunization.stories.js +6 -9
  47. package/src/components/resources/Immunization/Immunization.test.js +71 -1
  48. package/src/components/resources/MedicationOrder/MedicationOrder.js +45 -28
  49. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +2 -1
  50. package/src/components/resources/MedicationRequest/MedicationRequest.js +65 -43
  51. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +16 -5
  52. package/src/components/resources/MedicationStatement/MedicationDetails.js +52 -0
  53. package/src/components/resources/MedicationStatement/MedicationDosage.js +46 -0
  54. package/src/components/resources/MedicationStatement/MedicationStatement.js +65 -118
  55. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +6 -0
  56. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +31 -6
  57. package/src/components/resources/Observation/Observation.js +3 -3
  58. package/src/components/resources/Observation/Observation.stories.js +14 -5
  59. package/src/components/resources/Observation/Observation.test.js +67 -0
  60. package/src/components/resources/Patient/Patient.js +9 -6
  61. package/src/components/resources/Patient/Patient.stories.js +12 -5
  62. package/src/components/resources/Patient/Patient.test.js +67 -0
  63. package/src/components/resources/Practitioner/Practitioner.js +3 -13
  64. package/src/components/resources/Practitioner/Practitioner.stories.js +19 -3
  65. package/src/components/resources/Practitioner/Practitioner.test.js +72 -0
  66. package/src/components/resources/Procedure/Procedure.js +1 -2
  67. package/src/components/resources/Procedure/Procedure.stories.js +11 -5
  68. package/src/components/resources/Procedure/Procedure.test.js +71 -1
  69. package/src/components/resources/ResourceCategory/ResourceCategory.js +6 -3
  70. package/src/components/resources/ResourceCategory/ResourceCategory.test.js +1 -1
  71. package/src/components/supportedFhirResourceList.js +2 -0
  72. package/src/components/ui/bootstrap-reboot.min.css +8 -2
  73. package/src/components/ui/index.js +44 -25
  74. package/src/fixtures/example-icons.jsx +55 -10
  75. package/src/fixtures/r4/resources/explanationOfBenefit/c4bbExample.json +18 -2
  76. package/src/index.js +1 -0
  77. package/src/style.scss +1 -0
  78. package/src/utils/convertCamelCaseToSentence.js +9 -0
  79. package/src/utils/convertCamelCaseToSentence.test.js +9 -0
  80. package/src/utils/formatDate.js +6 -4
  81. package/webpack.config.js +10 -1
  82. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.css +0 -4
  83. package/src/components/resources/CarePlan/CarePlan.css +0 -7
@@ -11,8 +11,80 @@ import example3AppointmentSTU3 from '../../../fixtures/stu3/resources/appointmen
11
11
  import example1AppointmentR4 from '../../../fixtures/r4/resources/appointment/example1.json';
12
12
  import example2AppointmentR4 from '../../../fixtures/r4/resources/appointment/example2.json';
13
13
  import example3AppointmentR4 from '../../../fixtures/r4/resources/appointment/example3.json';
14
+ import fhirIcons from '../../../fixtures/example-icons';
14
15
 
15
16
  describe('should render component correctly', () => {
17
+ it('component without a fhirIcons props should render a default icon', () => {
18
+ const defaultProps = {
19
+ fhirVersion: fhirVersions.DSTU2,
20
+ fhirResource: exampleAppointmentDSTU2,
21
+ };
22
+
23
+ const { getByAltText } = render(<Appointment {...defaultProps} />);
24
+ const headerIcon = getByAltText('appointment');
25
+
26
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
27
+ });
28
+
29
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
30
+ const defaultProps = {
31
+ fhirVersion: fhirVersions.DSTU2,
32
+ fhirResource: exampleAppointmentDSTU2,
33
+ fhirIcons: false,
34
+ };
35
+
36
+ const { getByTestId } = render(<Appointment {...defaultProps} />);
37
+ const headerIcon = getByTestId('placeholder');
38
+
39
+ expect(headerIcon).toBeTruthy();
40
+ });
41
+
42
+ it('component with the img as a fhirIcons props should render an img', () => {
43
+ const defaultProps = {
44
+ fhirVersion: fhirVersions.DSTU2,
45
+ fhirResource: exampleAppointmentDSTU2,
46
+ fhirIcons: (
47
+ <img
48
+ src={require('../assets/containers/Appointment/appointment.svg')}
49
+ alt="appointment"
50
+ />
51
+ ),
52
+ };
53
+
54
+ const { getByAltText } = render(<Appointment {...defaultProps} />);
55
+ const headerIcon = getByAltText('appointment');
56
+
57
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
58
+ });
59
+
60
+ it('component with the resources object as a fhirIcons props should render an img', () => {
61
+ const defaultProps = {
62
+ fhirVersion: fhirVersions.DSTU2,
63
+ fhirResource: exampleAppointmentDSTU2,
64
+ fhirIcons: fhirIcons,
65
+ };
66
+
67
+ const { getByAltText } = render(<Appointment {...defaultProps} />);
68
+ const headerIcon = getByAltText('appointment');
69
+
70
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
71
+ });
72
+
73
+ it('component with the url as a fhirIcons props should render an img', () => {
74
+ const avatarSrc =
75
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
76
+ const defaultProps = {
77
+ fhirVersion: fhirVersions.DSTU2,
78
+ fhirResource: exampleAppointmentDSTU2,
79
+ fhirIcons: avatarSrc,
80
+ };
81
+
82
+ const { getByAltText } = render(<Appointment {...defaultProps} />);
83
+ const headerIcon = getByAltText('header icon');
84
+
85
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
86
+ });
87
+
16
88
  it('should render with DSTU2 source data', () => {
17
89
  const defaultProps = {
18
90
  fhirResource: exampleAppointmentDSTU2,
@@ -2,32 +2,43 @@ import React from 'react';
2
2
  import Img from '../../datatypes/Img';
3
3
  import Pdf from '../../datatypes/Pdf';
4
4
  import BinaryText from '../../datatypes/BinaryText';
5
+ import Accordion from '../../containers/Accordion/Accordion';
6
+ import { Body, Header } from '../../ui';
5
7
 
6
8
  const Binary = props => {
7
- const { fhirResource } = props;
9
+ const { fhirResource, fhirIcons } = props;
10
+ const headerIcon = fhirIcons && fhirIcons['Binary'];
11
+
12
+ const loadBinaryFile = () => {
13
+ switch (fhirResource.contentType) {
14
+ case 'application/pdf':
15
+ if (props.children && typeof props.children === 'function') {
16
+ return props.children(fhirResource.content, fhirResource.contentType);
17
+ }
18
+ return <Pdf fhirResource={fhirResource} />;
19
+ case 'image/jpeg':
20
+ return <Img fhirResource={fhirResource} />;
21
+ case 'application/xml':
22
+ return <BinaryText fhirResource={fhirResource} />;
23
+ case 'application/json':
24
+ return <BinaryText fhirResource={fhirResource} />;
25
+ default:
26
+ return null;
27
+ }
28
+ };
8
29
 
9
30
  return (
10
31
  <div>
11
- {(() => {
12
- switch (fhirResource.contentType) {
13
- case 'application/pdf':
14
- if (props.children && typeof props.children === 'function') {
15
- return props.children(
16
- fhirResource.content,
17
- fhirResource.contentType,
18
- );
19
- }
20
- return <Pdf fhirResource={fhirResource} />;
21
- case 'image/jpeg':
22
- return <Img fhirResource={fhirResource} />;
23
- case 'application/xml':
24
- return <BinaryText fhirResource={fhirResource} />;
25
- case 'application/json':
26
- return <BinaryText fhirResource={fhirResource} />;
27
- default:
28
- return null;
32
+ <Accordion
33
+ headerContent={
34
+ <Header
35
+ resourceName="Binary"
36
+ title={`Binary file: ${fhirResource.contentType}`}
37
+ icon={headerIcon}
38
+ />
29
39
  }
30
- })()}
40
+ bodyContent={<Body>{loadBinaryFile()}</Body>}
41
+ />
31
42
  </div>
32
43
  );
33
44
  };
@@ -8,6 +8,7 @@ import dstu2ExampleJpeg from '../../../fixtures/dstu2/resources/binary/example-j
8
8
  import stu3ExamplePdf from '../../../fixtures/stu3/resources/binary/example-pdf.json';
9
9
  import stu3ExampleJpeg from '../../../fixtures/stu3/resources/binary/example-jpeg.json';
10
10
  import stu3ExampleJson from '../../../fixtures/stu3/resources/binary/example-json.json';
11
+ import fhirIcons from '../../../fixtures/example-icons';
11
12
 
12
13
  export default {
13
14
  title: 'Binary',
@@ -15,25 +16,25 @@ export default {
15
16
 
16
17
  export const PdfDSTU2 = () => {
17
18
  const fhirResource = object('Resource', dstu2ExamplePdf);
18
- return <Binary fhirResource={fhirResource} />;
19
+ return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
19
20
  };
20
21
 
21
22
  export const JpegDSTU2 = () => {
22
23
  const fhirResource = object('Resource', dstu2ExampleJpeg);
23
- return <Binary fhirResource={fhirResource} />;
24
+ return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
24
25
  };
25
26
 
26
27
  export const PdfSTU3 = () => {
27
28
  const fhirResource = object('Resource', stu3ExamplePdf);
28
- return <Binary fhirResource={fhirResource} />;
29
+ return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
29
30
  };
30
31
 
31
32
  export const JpegSTU3 = () => {
32
33
  const fhirResource = object('Resource', stu3ExampleJpeg);
33
- return <Binary fhirResource={fhirResource} />;
34
+ return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
34
35
  };
35
36
 
36
37
  export const JsonSTU3 = () => {
37
38
  const fhirResource = object('Resource', stu3ExampleJson);
38
- return <Binary fhirResource={fhirResource} />;
39
+ return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
39
40
  };
@@ -10,18 +10,17 @@ import { isNotEmptyArray } from '../../../utils';
10
10
  import fhirVersions from '../fhirResourceVersions';
11
11
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
12
12
  import CarePlanActivity from './CarePlanActivity';
13
- import './CarePlan.css';
14
13
 
15
14
  import {
16
15
  Root,
17
16
  Header,
18
- Title,
19
17
  Badge,
20
18
  BadgeSecondary,
21
19
  Body,
22
- Value,
23
20
  MissingValue,
21
+ ValueSectionItem,
24
22
  } from '../../ui';
23
+ import Accordion from '../../containers/Accordion';
25
24
 
26
25
  const commonDTO = fhirResource => {
27
26
  const status = _get(fhirResource, 'status', '');
@@ -163,8 +162,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
163
162
  }
164
163
  };
165
164
 
166
- const CarePlan = props => {
167
- const { fhirResource, fhirVersion } = props;
165
+ const CarePlan = ({ fhirResource, fhirVersion, fhirIcons }) => {
168
166
  let fhirResourceData = {};
169
167
  try {
170
168
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -197,99 +195,116 @@ const CarePlan = props => {
197
195
  const authorArr = Array.isArray(author) ? author : [author];
198
196
  return (
199
197
  <Root name="CarePlan">
200
- <Header>
201
- <Title>Care Plan</Title>
202
- {status && <Badge data-testid="status">{status}</Badge>}
203
- {expiry && <BadgeSecondary>expires on ${expiry}</BadgeSecondary>}
204
- </Header>
205
- <Body>
206
- {hasCategory && (
207
- <Value label="Category" data-testid="category">
208
- {category.map((category, i) =>
209
- (category.coding || []).map((coding, j) => (
210
- <Coding key={`item-${i}${j}`} fhirData={coding} />
211
- )),
198
+ <Accordion
199
+ headerContent={
200
+ <Header
201
+ icon={fhirIcons}
202
+ resourceName="CarePlan"
203
+ badges={status && <Badge data-testid="status">{status}</Badge>}
204
+ title={'Care Plan'}
205
+ additionalContent={
206
+ expiry && <BadgeSecondary>expires on ${expiry}</BadgeSecondary>
207
+ }
208
+ />
209
+ }
210
+ bodyContent={
211
+ <Body>
212
+ {hasCategory && (
213
+ <ValueSectionItem label="Category" data-testid="category">
214
+ {category.map((category, i) =>
215
+ (category.coding || []).map((coding, j) => (
216
+ <Coding key={`item-${i}${j}`} fhirData={coding} />
217
+ )),
218
+ )}
219
+ </ValueSectionItem>
212
220
  )}
213
- </Value>
214
- )}
215
- {intent && (
216
- <Value label="Intent" data-testid="intent">
217
- {intent}
218
- </Value>
219
- )}
220
- {hasGoals && (
221
- <Value label="Goals" data-testid="goals">
222
- {goals.map((goal, i) => (
223
- <div key={`goal-${i}`}>
224
- <Reference fhirData={goal} />
225
- </div>
226
- ))}
227
- </Value>
228
- )}
229
- {description && (
230
- <Value label="Description" data-testid="description">
231
- {description}
232
- </Value>
233
- )}
234
- {subject && (
235
- <Value label="Subject" data-testid="subject">
236
- <Reference fhirData={subject} />
237
- </Value>
238
- )}
239
- {hasValue(author) && (
240
- <Value label="Author" data-testid="author">
241
- {authorArr.map((item, i) => (
242
- <Reference key={`author-${i}`} fhirData={item} />
243
- ))}
244
- </Value>
245
- )}
246
- {periodStart && (
247
- <Value label="Plan Period Start" data-testid="periodStart">
248
- {periodStart ? (
249
- <DateType fhirData={periodStart} />
250
- ) : (
251
- <MissingValue />
221
+ {intent && (
222
+ <ValueSectionItem label="Intent" data-testid="intent">
223
+ {intent}
224
+ </ValueSectionItem>
252
225
  )}
253
- </Value>
254
- )}
255
- {periodEnd && (
256
- <Value label="Plan Period End" data-testid="periodEnd">
257
- {periodEnd ? <DateType fhirData={periodEnd} /> : <MissingValue />}
258
- </Value>
259
- )}
260
- {hasAddresses && (
261
- <Value label="Addresses" data-testid="addresses">
262
- {addresses.map((address, i) => (
263
- <div key={`item-${i}`}>
264
- <Reference fhirData={address} />
265
- </div>
266
- ))}
267
- </Value>
268
- )}
269
- {isNotEmptyArray(basedOn) && (
270
- <Value label="Based on" data-testid="basedOn">
271
- {basedOn.map((item, i) => (
272
- <Reference key={`based-on-${i}`} fhirData={item} />
273
- ))}
274
- </Value>
275
- )}
276
- {isNotEmptyArray(partOf) && (
277
- <Value label="Part of" data-testid="partOf">
278
- {partOf.map((item, i) => (
279
- <Reference key={`part-of-${i}`} fhirData={item} />
280
- ))}
281
- </Value>
282
- )}
283
- {hasActivity && (
284
- <Value label="Activity" data-testid="activity">
285
- {activity.map((activity, i) => (
286
- <div key={`item-${i}`}>
287
- <CarePlanActivity fhirData={activity} />
288
- </div>
289
- ))}
290
- </Value>
291
- )}
292
- </Body>
226
+ {hasGoals && (
227
+ <ValueSectionItem label="Goals" data-testid="goals">
228
+ {goals.map((goal, i) => (
229
+ <div key={`goal-${i}`}>
230
+ <Reference fhirData={goal} />
231
+ </div>
232
+ ))}
233
+ </ValueSectionItem>
234
+ )}
235
+ {description && (
236
+ <ValueSectionItem label="Description" data-testid="description">
237
+ {description}
238
+ </ValueSectionItem>
239
+ )}
240
+ {subject && (
241
+ <ValueSectionItem label="Subject" data-testid="subject">
242
+ <Reference fhirData={subject} />
243
+ </ValueSectionItem>
244
+ )}
245
+ {hasValue(author) && (
246
+ <ValueSectionItem label="Author" data-testid="author">
247
+ {authorArr.map((item, i) => (
248
+ <Reference key={`author-${i}`} fhirData={item} />
249
+ ))}
250
+ </ValueSectionItem>
251
+ )}
252
+ {periodStart && (
253
+ <ValueSectionItem
254
+ label="Plan Period Start"
255
+ data-testid="periodStart"
256
+ >
257
+ {periodStart ? (
258
+ <DateType fhirData={periodStart} isBlack />
259
+ ) : (
260
+ <MissingValue />
261
+ )}
262
+ </ValueSectionItem>
263
+ )}
264
+ {periodEnd && (
265
+ <ValueSectionItem label="Plan Period End" data-testid="periodEnd">
266
+ {periodEnd ? (
267
+ <DateType fhirData={periodEnd} isBlack />
268
+ ) : (
269
+ <MissingValue />
270
+ )}
271
+ </ValueSectionItem>
272
+ )}
273
+ {hasAddresses && (
274
+ <ValueSectionItem label="Addresses" data-testid="addresses">
275
+ {addresses.map((address, i) => (
276
+ <div key={`item-${i}`}>
277
+ <Reference fhirData={address} />
278
+ </div>
279
+ ))}
280
+ </ValueSectionItem>
281
+ )}
282
+ {isNotEmptyArray(basedOn) && (
283
+ <ValueSectionItem label="Based on" data-testid="basedOn">
284
+ {basedOn.map((item, i) => (
285
+ <Reference key={`based-on-${i}`} fhirData={item} />
286
+ ))}
287
+ </ValueSectionItem>
288
+ )}
289
+ {isNotEmptyArray(partOf) && (
290
+ <ValueSectionItem label="Part of" data-testid="partOf">
291
+ {partOf.map((item, i) => (
292
+ <Reference key={`part-of-${i}`} fhirData={item} />
293
+ ))}
294
+ </ValueSectionItem>
295
+ )}
296
+ {hasActivity && (
297
+ <ValueSectionItem label="Activity" data-testid="activity">
298
+ {activity.map((activity, i) => (
299
+ <div key={`item-${i}`}>
300
+ <CarePlanActivity fhirData={activity} />
301
+ </div>
302
+ ))}
303
+ </ValueSectionItem>
304
+ )}
305
+ </Body>
306
+ }
307
+ />
293
308
  </Root>
294
309
  );
295
310
  };
@@ -21,7 +21,7 @@ describe('should render component correctly', () => {
21
21
  expect(getByTestId('status').textContent).toContain('active');
22
22
  expect(getByTestId('category').textContent).toContain('Longitudinal');
23
23
  expect(getByTestId('addresses').textContent).toContain('Dog bite');
24
- expect(getByTestId('activity').textContent).toContain('ADULT DIET');
24
+ expect(getByTestId('activity').textContent).toContain('Adult diet');
25
25
  expect(getByTestId('subject').textContent).toEqual('Patient/d47f763e7c7f');
26
26
  });
27
27
 
@@ -84,7 +84,7 @@ describe('should render component correctly', () => {
84
84
  expect(container).not.toBeNull();
85
85
 
86
86
  expect(getByTestId('addresses').textContent).toContain('pregnancy');
87
- expect(getByTestId('activity').textContent).toContain('First Antenatal');
87
+ expect(getByTestId('activity').textContent).toContain('First antenatal');
88
88
  expect(getByTestId('intent').textContent).toEqual('plan');
89
89
  expect(getByTestId('goals').textContent).toEqual('#goal');
90
90
  expect(getByTestId('subject').textContent).toContain('Eve Everywoman');
@@ -5,8 +5,12 @@ import Coding from '../../datatypes/Coding';
5
5
  const CarePlanActivity = props => {
6
6
  const { title = '', hasCategories, categories } = props.fhirData;
7
7
  return (
8
- <div className="fhir-resource__CarePlan__activity">
9
- <div className="fhir-resource__CarePlan__activity-title">{title}</div>
8
+ <div className="fhir-resource__CarePlan__activity mb-2">
9
+ <div className="fhir-resource__CarePlan__activity-title fw-bold">
10
+ {title
11
+ .toLowerCase()
12
+ .replace(/./, firstLetter => firstLetter.toUpperCase())}
13
+ </div>
10
14
  {hasCategories &&
11
15
  categories.map((coding, i) => (
12
16
  <Coding key={`item-${i}`} fhirData={coding} />
@@ -101,7 +101,6 @@ function Condition(props) {
101
101
  dateRecorded,
102
102
  } = resourceDTO(fhirVersion, fhirResource);
103
103
 
104
- const headerIcon = fhirIcons[_get(fhirResource, 'resourceType')];
105
104
  const tableData = [
106
105
  {
107
106
  label: 'Asserted by',
@@ -145,7 +144,7 @@ function Condition(props) {
145
144
  )}
146
145
  </>
147
146
  }
148
- icon={headerIcon}
147
+ icon={fhirIcons}
149
148
  title={codeText}
150
149
  rightAdditionalContent={
151
150
  severityText && (
@@ -16,6 +16,8 @@ import example2ConditionR4 from '../../../fixtures/r4/resources/condition/exampl
16
16
  import example3ConditionR4 from '../../../fixtures/r4/resources/condition/example3.json';
17
17
 
18
18
  import fhirIcons from '../../../fixtures/example-icons';
19
+ import ConditionIcon from '../../../assets/containers/Condition/condition.svg';
20
+
19
21
  export default { title: 'Condition' };
20
22
 
21
23
  export const DefaultVisualizationDSTU2 = () => {
@@ -24,7 +26,7 @@ export const DefaultVisualizationDSTU2 = () => {
24
26
  <Condition
25
27
  fhirResource={fhirResource}
26
28
  fhirVersion={fhirVersions.DSTU2}
27
- fhirIcons={fhirIcons}
29
+ fhirIcons={require('../../../assets/containers/Condition/condition.svg')}
28
30
  />
29
31
  );
30
32
  };
@@ -35,7 +37,7 @@ export const ExampleWithoutSeverityDSTU2 = () => {
35
37
  <Condition
36
38
  fhirResource={fhirResource}
37
39
  fhirVersion={fhirVersions.DSTU2}
38
- fhirIcons={fhirIcons}
40
+ fhirIcons={ConditionIcon}
39
41
  />
40
42
  );
41
43
  };
@@ -57,7 +59,7 @@ export const ExampleWithoutSeveritySTU3 = () => {
57
59
  <Condition
58
60
  fhirResource={fhirResource}
59
61
  fhirVersion={fhirVersions.STU3}
60
- fhirIcons={fhirIcons}
62
+ fhirIcons={false}
61
63
  />
62
64
  );
63
65
  };
@@ -68,7 +70,7 @@ export const ExampleWithSeveritySTU3 = () => {
68
70
  <Condition
69
71
  fhirResource={fhirResource}
70
72
  fhirVersion={fhirVersions.STU3}
71
- fhirIcons={fhirIcons}
73
+ fhirIcons={'random text'}
72
74
  />
73
75
  );
74
76
  };
@@ -76,32 +78,20 @@ export const ExampleWithSeveritySTU3 = () => {
76
78
  export const Example1ofR4 = () => {
77
79
  const fhirResource = object('Resource', example1ConditionR4);
78
80
  return (
79
- <Condition
80
- fhirResource={fhirResource}
81
- fhirVersion={fhirVersions.R4}
82
- fhirIcons={fhirIcons}
83
- />
81
+ <Condition fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
84
82
  );
85
83
  };
86
84
 
87
85
  export const Example2ofR4 = () => {
88
86
  const fhirResource = object('Resource', example2ConditionR4);
89
87
  return (
90
- <Condition
91
- fhirResource={fhirResource}
92
- fhirVersion={fhirVersions.R4}
93
- fhirIcons={fhirIcons}
94
- />
88
+ <Condition fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
95
89
  );
96
90
  };
97
91
 
98
92
  export const Example3ofR4 = () => {
99
93
  const fhirResource = object('Resource', example3ConditionR4);
100
94
  return (
101
- <Condition
102
- fhirResource={fhirResource}
103
- fhirVersion={fhirVersions.R4}
104
- fhirIcons={fhirIcons}
105
- />
95
+ <Condition fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
106
96
  );
107
97
  };
@@ -9,10 +9,80 @@ import exampleConditionSeverity from '../../../fixtures/dstu2/resources/conditio
9
9
  import exampleConditionSeveritySTU3 from '../../../fixtures/stu3/resources/condition/example-severity.json';
10
10
  import fhirVersions from '../fhirResourceVersions';
11
11
  import { render } from '@testing-library/react';
12
-
13
12
  import fhirIcons from '../../../fixtures/example-icons';
14
13
 
15
14
  describe('should render component correctly', () => {
15
+ it('component without a fhirIcons props should render a default icon', () => {
16
+ const defaultProps = {
17
+ fhirVersion: fhirVersions.DSTU2,
18
+ fhirResource: exampleCondition,
19
+ };
20
+
21
+ const { getByAltText } = render(<Condition {...defaultProps} />);
22
+ const headerIcon = getByAltText('condition');
23
+
24
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
25
+ });
26
+
27
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
28
+ const defaultProps = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: exampleCondition,
31
+ fhirIcons: false,
32
+ };
33
+
34
+ const { getByTestId } = render(<Condition {...defaultProps} />);
35
+ const headerIcon = getByTestId('placeholder');
36
+
37
+ expect(headerIcon).toBeTruthy();
38
+ });
39
+
40
+ it('component with the img as a fhirIcons props should render an img', () => {
41
+ const defaultProps = {
42
+ fhirVersion: fhirVersions.DSTU2,
43
+ fhirResource: exampleCondition,
44
+ fhirIcons: (
45
+ <img
46
+ src={require('../assets/containers/Condition/condition.svg')}
47
+ alt="condition"
48
+ />
49
+ ),
50
+ };
51
+
52
+ const { getByAltText } = render(<Condition {...defaultProps} />);
53
+ const headerIcon = getByAltText('condition');
54
+
55
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
56
+ });
57
+
58
+ it('component with the resources object as a fhirIcons props should render an img', () => {
59
+ const defaultProps = {
60
+ fhirVersion: fhirVersions.DSTU2,
61
+ fhirResource: exampleCondition,
62
+ fhirIcons: fhirIcons,
63
+ };
64
+
65
+ const { getByAltText } = render(<Condition {...defaultProps} />);
66
+ const headerIcon = getByAltText('condition');
67
+
68
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
69
+ });
70
+
71
+ it('component with the url as a fhirIcons props should render an img', () => {
72
+ const avatarSrc =
73
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
74
+ const defaultProps = {
75
+ fhirVersion: fhirVersions.DSTU2,
76
+ fhirResource: exampleCondition,
77
+ fhirIcons: avatarSrc,
78
+ };
79
+
80
+ const { getByAltText } = render(<Condition {...defaultProps} />);
81
+ const headerIcon = getByAltText('header icon');
82
+
83
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
84
+ });
85
+
16
86
  it('DSTU2 - without severity field', () => {
17
87
  const defaultProps = {
18
88
  fhirResource: exampleCondition,