fhir-react 0.3.0 → 0.3.4

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 (47) hide show
  1. package/.github/workflows/publish_npmjs.yml +2 -0
  2. package/README.md +88 -5
  3. package/build/bootstrap-reboot.min.css +394 -0
  4. package/build/index.js +43 -0
  5. package/build/style.css +31 -0
  6. package/package.json +3 -2
  7. package/src/assets/containers/Patient/patient.svg +6 -0
  8. package/src/components/containers/Accordion/Accordion.js +7 -3
  9. package/src/components/datatypes/HeaderIcon/HeaderIcon.js +67 -22
  10. package/src/components/resources/Appointment/Appointment.js +3 -3
  11. package/src/components/resources/Appointment/Appointment.stories.js +28 -5
  12. package/src/components/resources/Appointment/Appointment.test.js +72 -0
  13. package/src/components/resources/Condition/Condition.js +1 -2
  14. package/src/components/resources/Condition/Condition.stories.js +9 -19
  15. package/src/components/resources/Condition/Condition.test.js +71 -1
  16. package/src/components/resources/Encounter/Encounter.js +3 -4
  17. package/src/components/resources/Encounter/Encounter.stories.js +27 -5
  18. package/src/components/resources/Encounter/Encounter.test.js +72 -0
  19. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +26 -10
  20. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +8 -0
  21. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +80 -3
  22. package/src/components/resources/ExplanationOfBenefit/SupportingInfo.js +21 -6
  23. package/src/components/resources/Immunization/Immunization.js +1 -2
  24. package/src/components/resources/Immunization/Immunization.stories.js +6 -9
  25. package/src/components/resources/Immunization/Immunization.test.js +71 -1
  26. package/src/components/resources/Observation/Observation.js +3 -3
  27. package/src/components/resources/Observation/Observation.stories.js +14 -5
  28. package/src/components/resources/Observation/Observation.test.js +67 -0
  29. package/src/components/resources/Patient/Patient.js +9 -6
  30. package/src/components/resources/Patient/Patient.stories.js +12 -5
  31. package/src/components/resources/Patient/Patient.test.js +67 -0
  32. package/src/components/resources/Practitioner/Practitioner.js +3 -13
  33. package/src/components/resources/Practitioner/Practitioner.stories.js +19 -3
  34. package/src/components/resources/Practitioner/Practitioner.test.js +72 -0
  35. package/src/components/resources/Procedure/Procedure.js +1 -2
  36. package/src/components/resources/Procedure/Procedure.stories.js +11 -5
  37. package/src/components/resources/Procedure/Procedure.test.js +71 -1
  38. package/src/components/resources/ResourceCategory/ResourceCategory.js +6 -3
  39. package/src/components/resources/ResourceCategory/ResourceCategory.test.js +1 -1
  40. package/src/components/supportedFhirResourceList.js +2 -0
  41. package/src/components/ui/index.js +33 -25
  42. package/src/fixtures/example-icons.jsx +48 -10
  43. package/src/fixtures/r4/resources/explanationOfBenefit/c4bbExample.json +18 -2
  44. package/src/index.js +1 -0
  45. package/src/utils/convertCamelCaseToSentence.js +9 -0
  46. package/src/utils/convertCamelCaseToSentence.test.js +9 -0
  47. package/webpack.config.js +10 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fhir-react",
3
- "version": "0.3.0",
3
+ "version": "0.3.4",
4
4
  "description": "React component library for displaying FHIR Resources ",
5
5
  "main": "build/index.js",
6
6
  "peerDependencies": {
@@ -17,7 +17,8 @@
17
17
  "md5": "^2.2.1",
18
18
  "pretty-bytes": "^5.3.0",
19
19
  "prop-types": "^15.7.2",
20
- "react": "^17.0.1"
20
+ "react": "^17.0.1",
21
+ "svg-url-loader": "^7.1.1"
21
22
  },
22
23
  "scripts": {
23
24
  "test": "NODE_ENV=test jest",
@@ -0,0 +1,6 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M0 12C0 8.27247 0 6.4087 0.608964 4.93853C1.42092 2.97831 2.97831 1.42092 4.93853 0.608964C6.4087 0 8.27247 0 12 0C15.7275 0 17.5913 0 19.0615 0.608964C21.0217 1.42092 22.5791 2.97831 23.391 4.93853C24 6.4087 24 8.27247 24 12C24 15.7275 24 17.5913 23.391 19.0615C22.5791 21.0217 21.0217 22.5791 19.0615 23.391C17.5913 24 15.7275 24 12 24C8.27247 24 6.4087 24 4.93853 23.391C2.97831 22.5791 1.42092 21.0217 0.608964 19.0615C0 17.5913 0 15.7275 0 12Z" fill="#F8F9FA"/>
3
+ <path d="M12 11C13.933 11 15.5 9.433 15.5 7.5C15.5 5.567 13.933 4 12 4C10.067 4 8.5 5.567 8.5 7.5C8.5 9.433 10.067 11 12 11Z" stroke="#3D8BFD" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M9.5 5C10.0015 5.63268 10.6029 6.13588 11.268 6.47953C11.9332 6.82317 12.6485 7.00019 13.3712 7C14.1033 7.00035 14.8277 6.81885 15.5 6.46662" stroke="#3D8BFD" stroke-linejoin="round"/>
5
+ <path d="M4 20C4 18.1435 4.84285 16.363 6.34315 15.0503C7.84344 13.7375 9.87827 13 12 13C14.1217 13 16.1566 13.7375 17.6569 15.0503C19.1571 16.363 20 18.1435 20 20" stroke="#3D8BFD" stroke-linecap="round" stroke-linejoin="round"/>
6
+ </svg>
@@ -1,5 +1,6 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Chevron } from '../../ui';
3
+ import uniqueId from 'lodash/uniqueId';
3
4
 
4
5
  const CHEVRON_DOWN_COLOR = '#6f83a9';
5
6
  const CHEVRON_UP_COLOR = '#2a6fd7';
@@ -8,6 +9,9 @@ const Accordion = props => {
8
9
  const { headerContent, bodyContent } = props;
9
10
  const [rotate, setRotate] = useState(false);
10
11
  const handleAccordionClick = () => setRotate(!rotate);
12
+ const accordionId = uniqueId(
13
+ `accordion-type-${headerContent.props.resourceName || 'default'}-`,
14
+ );
11
15
 
12
16
  const isAccordionOpenable = () => {
13
17
  let childrenCondition = false;
@@ -49,9 +53,9 @@ const Accordion = props => {
49
53
  isAccordionOpenable() ? '' : 'pe-none'
50
54
  }`}
51
55
  type="button"
52
- data-bs-target="#collapseTarget"
56
+ data-bs-target={`#${accordionId}`}
53
57
  data-bs-toggle={isAccordionOpenable() ? 'collapse' : null}
54
- aria-controls="collapseTarget"
58
+ aria-controls={accordionId}
55
59
  aria-expanded="false"
56
60
  onClick={handleAccordionClick}
57
61
  >
@@ -65,7 +69,7 @@ const Accordion = props => {
65
69
  </div>
66
70
  <div
67
71
  className="fhir-container__Accordion__data accordion-collapse collapse"
68
- id="collapseTarget"
72
+ id={accordionId}
69
73
  >
70
74
  <div className="fhir-container__Accordion__data-text accordion-body ps-4 pt-3 pe-4 border-top">
71
75
  {bodyContent}
@@ -1,31 +1,76 @@
1
1
  import React from 'react';
2
- import { isUrl } from '../../../utils/isUrl';
2
+ import { useState, useEffect, useRef } from 'react';
3
+ import { convertCamelCaseToSentence } from '../../../utils/convertCamelCaseToSentence';
3
4
 
4
- const HeaderIcon = ({ headerIcon }) => {
5
- const PlaceholderImage = () => {
6
- return <div className="header-icon__placeholder rounded-1" />;
5
+ const PlaceholderImage = () => {
6
+ return (
7
+ <div
8
+ className="header-icon__placeholder rounded-1"
9
+ data-testid="placeholder"
10
+ />
11
+ );
12
+ };
13
+
14
+ const defaultIconOrPlaceholder = (headerIcon, resourceName) => {
15
+ let imageSrc;
16
+ const svgFileName =
17
+ resourceName && convertCamelCaseToSentence(resourceName).replace(/ /g, '-');
18
+ try {
19
+ imageSrc = require(`../../../assets/containers/${resourceName}/${svgFileName}.svg`);
20
+ } catch (err) {
21
+ imageSrc = null;
22
+ }
23
+ return imageSrc && headerIcon !== false ? (
24
+ <img
25
+ className="header-icon__image"
26
+ src={imageSrc}
27
+ alt={convertCamelCaseToSentence(resourceName)}
28
+ />
29
+ ) : (
30
+ <PlaceholderImage />
31
+ );
32
+ };
33
+
34
+ const useImageError = () => {
35
+ const [error, setError] = useState(false);
36
+ const ref = useRef();
37
+
38
+ const onError = () => {
39
+ setError(true);
7
40
  };
8
41
 
9
- const Image = () => {
10
- if (
11
- React.isValidElement(headerIcon) &&
12
- typeof headerIcon.type === 'string'
13
- ) {
14
- return headerIcon;
42
+ useEffect(() => {
43
+ if (ref.current && ref.current.error) {
44
+ onError();
15
45
  }
16
- if (isUrl(headerIcon)) {
17
- return (
18
- <img
19
- className="header-icon__image"
20
- src={headerIcon}
21
- alt="header icon"
22
- />
23
- );
24
- }
25
- return <PlaceholderImage />;
26
- };
46
+ });
47
+
48
+ return [ref, error, onError];
49
+ };
50
+
51
+ const HeaderIcon = ({ headerIcon, resourceName }) => {
52
+ const [ref, error, onError] = useImageError();
53
+ if (!headerIcon) {
54
+ return defaultIconOrPlaceholder(headerIcon, resourceName);
55
+ }
56
+ if (headerIcon[resourceName]) {
57
+ return headerIcon[resourceName];
58
+ }
59
+ if (React.isValidElement(headerIcon) && typeof headerIcon.type === 'string') {
60
+ return headerIcon;
61
+ }
27
62
 
28
- return <Image />;
63
+ return !error ? (
64
+ <img
65
+ ref={ref}
66
+ onError={onError}
67
+ className="header-icon__image"
68
+ src={headerIcon}
69
+ alt="header icon"
70
+ />
71
+ ) : (
72
+ defaultIconOrPlaceholder(headerIcon, resourceName)
73
+ );
29
74
  };
30
75
 
31
76
  export default HeaderIcon;
@@ -144,8 +144,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
144
144
  }
145
145
  };
146
146
 
147
- const Appointment = props => {
148
- const { fhirResource, fhirVersion } = props;
147
+ const Appointment = ({ fhirResource, fhirVersion, fhirIcons }) => {
149
148
  const {
150
149
  description,
151
150
  status,
@@ -208,7 +207,7 @@ const Appointment = props => {
208
207
  <Accordion
209
208
  headerContent={
210
209
  <Header
211
- resourceName={fhirResource.resourceName}
210
+ resourceName="Appointment"
212
211
  additionalContent={
213
212
  start && (
214
213
  <Value label="Start date" data-testid="headerStartDate">
@@ -218,6 +217,7 @@ const Appointment = props => {
218
217
  }
219
218
  badges={status && <Badge data-testid="status">{status}</Badge>}
220
219
  title={description}
220
+ icon={fhirIcons}
221
221
  />
222
222
  }
223
223
  bodyContent={
@@ -13,38 +13,61 @@ import example1AppointmentR4 from '../../../fixtures/r4/resources/appointment/ex
13
13
  import example2AppointmentR4 from '../../../fixtures/r4/resources/appointment/example2.json';
14
14
  import example3AppointmentR4 from '../../../fixtures/r4/resources/appointment/example3.json';
15
15
 
16
+ import fhirIcons from '../../../fixtures/example-icons';
17
+ import AppointmentIcon from '../../../assets/containers/Appointment/appointment.svg';
18
+
16
19
  export default { title: 'Appointment' };
17
20
 
18
21
  export const DefaultVisualizationDSTU2 = () => {
19
22
  const fhirResource = object('Resource', exampleAppointmentDSTU2);
20
23
  return (
21
- <Appointment fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
24
+ <Appointment
25
+ fhirResource={fhirResource}
26
+ fhirVersion={fhirVersions.DSTU2}
27
+ fhirIcons={require('../../../assets/containers/Appointment/appointment.svg')}
28
+ />
22
29
  );
23
30
  };
24
31
 
25
32
  export const Example2OfDSTU2 = () => {
26
33
  const fhirResource = object('Resource', example2AppointmentDSTU2);
27
34
  return (
28
- <Appointment fhirResource={fhirResource} fhirVersion={fhirVersions.DSTU2} />
35
+ <Appointment
36
+ fhirResource={fhirResource}
37
+ fhirVersion={fhirVersions.DSTU2}
38
+ fhirIcons={AppointmentIcon}
39
+ />
29
40
  );
30
41
  };
31
42
 
32
43
  export const Example1OfSTU3 = () => {
33
44
  const fhirResource = object('Resource', example1AppointmentSTU3);
34
45
  return (
35
- <Appointment fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
46
+ <Appointment
47
+ fhirResource={fhirResource}
48
+ fhirVersion={fhirVersions.STU3}
49
+ fhirIcons={fhirIcons}
50
+ />
36
51
  );
37
52
  };
38
53
  export const Example2OfSTU3 = () => {
39
54
  const fhirResource = object('Resource', example2AppointmentSTU3);
40
55
  return (
41
- <Appointment fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
56
+ <Appointment
57
+ fhirResource={fhirResource}
58
+ fhirVersion={fhirVersions.STU3}
59
+ fhirIcons={false}
60
+ />
42
61
  );
43
62
  };
44
63
  export const Example3OfSTU3 = () => {
45
64
  const fhirResource = object('Resource', example3AppointmentSTU3);
46
65
  return (
47
- <Appointment fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
66
+ <Appointment
67
+ fhirResource={fhirResource}
68
+ fhirVersion={fhirVersions.STU3}
69
+ fhirIcons={'random text'}
70
+ />
48
71
  );
49
72
  };
50
73
 
@@ -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,
@@ -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,
@@ -160,8 +160,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
160
160
  }
161
161
  };
162
162
 
163
- const Encounter = props => {
164
- const { fhirResource, fhirVersion } = props;
163
+ const Encounter = ({ fhirResource, fhirVersion, fhirIcons }) => {
165
164
  let fhirResourceData = {};
166
165
  try {
167
166
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -177,7 +176,6 @@ const Encounter = props => {
177
176
  encounterType,
178
177
  resourceClass,
179
178
  resourceStatus,
180
- resourceName,
181
179
  participant,
182
180
  } = fhirResourceData;
183
181
 
@@ -207,7 +205,7 @@ const Encounter = props => {
207
205
  <Accordion
208
206
  headerContent={
209
207
  <Header
210
- resourceName={resourceName}
208
+ resourceName={'Encounter'}
211
209
  additionalContent={
212
210
  periodStart && (
213
211
  <Value label="Start date" data-testid="headerStartDate">
@@ -221,6 +219,7 @@ const Encounter = props => {
221
219
  )
222
220
  }
223
221
  title={locationDisplay}
222
+ icon={fhirIcons}
224
223
  />
225
224
  }
226
225
  bodyContent={
@@ -11,6 +11,8 @@ import example1_R4 from '../../../fixtures/r4/resources/encounter/example1.json'
11
11
  import example2_R4 from '../../../fixtures/r4/resources/encounter/example2.json';
12
12
  import example3_R4 from '../../../fixtures/r4/resources/encounter/example3.json';
13
13
  import fhirVersions from '../fhirResourceVersions';
14
+ import fhirIcons from '../../../fixtures/example-icons';
15
+ import EncounterIcon from '../../../assets/containers/Encounter/encounter.svg';
14
16
 
15
17
  export default {
16
18
  title: 'Encounter',
@@ -19,35 +21,55 @@ export default {
19
21
  export const DefaultVisualizationDSTU2 = () => {
20
22
  const fhirResource = object('Resource', example1);
21
23
  return (
22
- <Encounter fhirVersion={fhirVersions.DSTU2} fhirResource={fhirResource} />
24
+ <Encounter
25
+ fhirVersion={fhirVersions.DSTU2}
26
+ fhirResource={fhirResource}
27
+ fhirIcons={require('../../../assets/containers/Encounter/encounter.svg')}
28
+ />
23
29
  );
24
30
  };
25
31
 
26
32
  export const ExampleWithoutParticipantsDSTU2 = () => {
27
33
  const fhirResource = object('Resource', example2);
28
34
  return (
29
- <Encounter fhirVersion={fhirVersions.DSTU2} fhirResource={fhirResource} />
35
+ <Encounter
36
+ fhirVersion={fhirVersions.DSTU2}
37
+ fhirResource={fhirResource}
38
+ fhirIcons={EncounterIcon}
39
+ />
30
40
  );
31
41
  };
32
42
 
33
43
  export const ExampleSTU3 = () => {
34
44
  const fhirResource = object('Resource', example_STU3);
35
45
  return (
36
- <Encounter fhirVersion={fhirVersions.STU3} fhirResource={fhirResource} />
46
+ <Encounter
47
+ fhirVersion={fhirVersions.STU3}
48
+ fhirResource={fhirResource}
49
+ fhirIcons={fhirIcons}
50
+ />
37
51
  );
38
52
  };
39
53
 
40
54
  export const ExampleWithoutParticipantSTU3 = () => {
41
55
  const fhirResource = object('Resource', example2_STU3);
42
56
  return (
43
- <Encounter fhirVersion={fhirVersions.STU3} fhirResource={fhirResource} />
57
+ <Encounter
58
+ fhirVersion={fhirVersions.STU3}
59
+ fhirResource={fhirResource}
60
+ fhirIcons={false}
61
+ />
44
62
  );
45
63
  };
46
64
 
47
65
  export const ExampleWithoutParticipantR4 = () => {
48
66
  const fhirResource = object('Resource', example1_R4);
49
67
  return (
50
- <Encounter fhirVersion={fhirVersions.R4} fhirResource={fhirResource} />
68
+ <Encounter
69
+ fhirVersion={fhirVersions.R4}
70
+ fhirResource={fhirResource}
71
+ fhirIcons={'random text'}
72
+ />
51
73
  );
52
74
  };
53
75