fhir-react 0.3.4 → 0.3.7

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 (84) hide show
  1. package/README.md +1 -1
  2. package/build/bootstrap-reboot.min.css +8 -2
  3. package/build/index.js +7 -7
  4. package/build/style.css +6 -6
  5. package/package.json +1 -1
  6. package/src/assets/containers/Binary/binary.svg +9 -0
  7. package/src/assets/containers/Coverage/coverage.svg +4 -0
  8. package/src/assets/containers/MedicationOrder/medication-order.svg +5 -0
  9. package/src/assets/containers/MedicationRequest/medication-request.svg +5 -0
  10. package/src/assets/containers/Organization/organization.svg +5 -0
  11. package/src/assets/containers/ResourceCategory/{resource-placeholder.svg → resource-category.svg} +0 -0
  12. package/src/components/containers/Accordion/Accordion.js +10 -9
  13. package/src/components/datatypes/Annotation/Annotation.js +4 -4
  14. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  15. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  16. package/src/components/datatypes/CodeableConcept/CodeableConcept.css +4 -1
  17. package/src/components/datatypes/Coding/Coding.css +0 -1
  18. package/src/components/datatypes/Identifier/Identifier.js +7 -3
  19. package/src/components/datatypes/Reference/Reference.css +3 -0
  20. package/src/components/datatypes/Reference/Reference.js +7 -1
  21. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +86 -77
  22. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +12 -1
  23. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +71 -0
  24. package/src/components/resources/Binary/Binary.js +30 -20
  25. package/src/components/resources/Binary/Binary.stories.js +12 -5
  26. package/src/components/resources/Binary/Binary.test.js +67 -0
  27. package/src/components/resources/CarePlan/CarePlan.js +111 -96
  28. package/src/components/resources/CarePlan/CarePlan.stories.js +31 -5
  29. package/src/components/resources/CarePlan/CarePlan.test.js +74 -2
  30. package/src/components/resources/CarePlan/CarePlanActivity.js +6 -2
  31. package/src/components/resources/Claim/CareTeam.js +55 -0
  32. package/src/components/resources/Claim/Claim.css +2 -11
  33. package/src/components/resources/Claim/Claim.js +157 -309
  34. package/src/components/resources/Claim/Claim.stories.js +37 -5
  35. package/src/components/resources/Claim/Claim.test.js +72 -0
  36. package/src/components/resources/Claim/Diagnosis.js +61 -0
  37. package/src/components/resources/Claim/Insurance.js +58 -0
  38. package/src/components/resources/Claim/Item.js +79 -0
  39. package/src/components/resources/Claim/Items.js +29 -0
  40. package/src/components/resources/Coverage/Coverage.js +96 -69
  41. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  42. package/src/components/resources/Coverage/Coverage.test.js +75 -3
  43. package/src/components/resources/Device/Device.js +54 -34
  44. package/src/components/resources/Device/Device.stories.js +33 -5
  45. package/src/components/resources/Device/Device.test.js +72 -0
  46. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +53 -43
  47. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +8 -1
  48. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +71 -0
  49. package/src/components/resources/DocumentReference/DocumentReference.js +101 -65
  50. package/src/components/resources/DocumentReference/DocumentReference.stories.js +5 -0
  51. package/src/components/resources/DocumentReference/DocumentReference.test.js +71 -0
  52. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +47 -38
  53. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +5 -0
  54. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +72 -0
  55. package/src/components/resources/Goal/Goal.js +103 -85
  56. package/src/components/resources/Goal/Goal.stories.js +38 -7
  57. package/src/components/resources/Goal/Goal.test.js +70 -3
  58. package/src/components/resources/Medication/Medication.js +90 -51
  59. package/src/components/resources/Medication/Medication.stories.js +37 -7
  60. package/src/components/resources/Medication/Medication.test.js +77 -3
  61. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +1 -1
  62. package/src/components/resources/MedicationOrder/MedicationOrder.js +45 -28
  63. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +67 -0
  64. package/src/components/resources/MedicationRequest/MedicationRequest.js +64 -44
  65. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +21 -5
  66. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +67 -0
  67. package/src/components/resources/MedicationStatement/MedicationDetails.js +52 -0
  68. package/src/components/resources/MedicationStatement/MedicationDosage.js +46 -0
  69. package/src/components/resources/MedicationStatement/MedicationStatement.js +66 -118
  70. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +7 -0
  71. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +103 -6
  72. package/src/components/resources/Organization/Organization.js +55 -37
  73. package/src/components/resources/Organization/Organization.stories.js +15 -2
  74. package/src/components/resources/Organization/Organization.test.js +73 -0
  75. package/src/components/resources/ResourceCategory/ResourceCategory.js +7 -12
  76. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +13 -2
  77. package/src/components/resources/ResourceCategory/ResourceCategory.test.js +77 -18
  78. package/src/components/ui/bootstrap-reboot.min.css +8 -2
  79. package/src/components/ui/index.js +22 -4
  80. package/src/fixtures/example-icons.jsx +46 -11
  81. package/src/style.scss +1 -0
  82. package/src/utils/formatDate.js +6 -4
  83. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.css +0 -4
  84. package/src/components/resources/CarePlan/CarePlan.css +0 -7
@@ -9,8 +9,80 @@ import stu3Example1 from '../../../fixtures/stu3/resources/medication/example1.j
9
9
  import stu3Example2 from '../../../fixtures/stu3/resources/medication/example2.json';
10
10
  import r4Example1 from '../../../fixtures/r4/resources/medication/example1.json';
11
11
  import r4Example2 from '../../../fixtures/r4/resources/medication/example2.json';
12
+ import fhirIcons from '../../../fixtures/example-icons';
12
13
 
13
14
  describe('should render Medication component properly', () => {
15
+ it('component without a fhirIcons props should render a default icon', () => {
16
+ const defaultProps = {
17
+ fhirVersion: fhirVersions.DSTU2,
18
+ fhirResource: dstu2Example1,
19
+ };
20
+
21
+ const { getByAltText } = render(<Medication {...defaultProps} />);
22
+ const headerIcon = getByAltText('medication');
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: dstu2Example1,
31
+ fhirIcons: false,
32
+ };
33
+
34
+ const { getByTestId } = render(<Medication {...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: dstu2Example1,
44
+ fhirIcons: (
45
+ <img
46
+ src={require('../assets/containers/Medication/medication.svg')}
47
+ alt="medication"
48
+ />
49
+ ),
50
+ };
51
+
52
+ const { getByAltText } = render(<Medication {...defaultProps} />);
53
+ const headerIcon = getByAltText('medication');
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: dstu2Example1,
62
+ fhirIcons: fhirIcons,
63
+ };
64
+
65
+ const { getByAltText } = render(<Medication {...defaultProps} />);
66
+ const headerIcon = getByAltText('medication');
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: dstu2Example1,
77
+ fhirIcons: avatarSrc,
78
+ };
79
+
80
+ const { getByAltText } = render(<Medication {...defaultProps} />);
81
+ const headerIcon = getByAltText('header icon');
82
+
83
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
84
+ });
85
+
14
86
  it('should render with DSTU2 source data', () => {
15
87
  const defaultProps = {
16
88
  fhirResource: dstu2Example1,
@@ -41,7 +113,9 @@ describe('should render Medication component properly', () => {
41
113
  fhirVersion: fhirVersions.STU3,
42
114
  };
43
115
 
44
- const { container, getByTestId } = render(<Medication {...defaultProps} />);
116
+ const { container, getByTestId, getByAltText } = render(
117
+ <Medication {...defaultProps} />,
118
+ );
45
119
  expect(container).not.toBeNull();
46
120
 
47
121
  expect(getByTestId('title').textContent).toContain(
@@ -56,8 +130,8 @@ describe('should render Medication component properly', () => {
56
130
  );
57
131
  expect(getByTestId('package-container').textContent).toContain('Vial');
58
132
 
59
- expect(getByTestId('product-images').textContent).toContain(
60
- 'Vancomycin Image',
133
+ expect(getByAltText('Vancomycin Image').src).toContain(
134
+ 'https://www.drugs.com/images/pills/fio/AKN07410.JPG',
61
135
  );
62
136
  });
63
137
 
@@ -142,7 +142,7 @@ const MedicationKnowledge = props => {
142
142
  <Root name="MedicationKnowledge">
143
143
  <Header>
144
144
  <Title>
145
- {id ? `Medication knowledge ID: ${id}` : 'Medication knowledge'}{' '}
145
+ {id ? `Medication knowledge ID: ${id}` : 'MedicationOrder knowledge'}{' '}
146
146
  {status && <Badge data-testid="status">{status}</Badge>}
147
147
  </Title>
148
148
  </Header>
@@ -1,14 +1,16 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _get from 'lodash/get';
4
+ import Accordion from '../../containers/Accordion/Accordion';
4
5
  import Reference from '../../datatypes/Reference';
5
6
  import CodeableConcept from '../../datatypes/CodeableConcept';
6
7
  import Coding from '../../datatypes/Coding';
7
8
 
8
- import { Root, Header, Title, Body, Value } from '../../ui';
9
+ import { Root, Header, Body } from '../../ui';
9
10
 
10
11
  const MedicationOrder = props => {
11
- const { fhirResource } = props;
12
+ const { fhirResource, fhirIcons } = props;
13
+
12
14
  const medicationReference = _get(fhirResource, 'medicationReference');
13
15
  const medicationCodeableConcept = _get(
14
16
  fhirResource,
@@ -22,34 +24,49 @@ const MedicationOrder = props => {
22
24
  const dosageInstruction = _get(fhirResource, 'dosageInstruction');
23
25
  const hasDosageInstruction =
24
26
  Array.isArray(dosageInstruction) && dosageInstruction.length > 0;
27
+
28
+ const tableData = [
29
+ {
30
+ label: 'Medication',
31
+ testId: 'medication',
32
+ data: showMedicationCodeableConcept && (
33
+ <Coding fhirData={medicationCodeableConcept} />
34
+ ),
35
+ status: showMedicationCodeableConcept,
36
+ },
37
+ {
38
+ label: 'Reason',
39
+ testId: 'reasonCode',
40
+ data: reasonCode && <CodeableConcept fhirData={reasonCode} />,
41
+ status: reasonCode,
42
+ },
43
+ {
44
+ label: 'Dosage',
45
+ testId: 'hasDosageInstruction',
46
+ data:
47
+ hasDosageInstruction &&
48
+ dosageInstruction.map((item, i) => (
49
+ <p key={`dosage-instruction-item-${i}`}>{item.text}</p>
50
+ )),
51
+ status: hasDosageInstruction,
52
+ },
53
+ ];
25
54
  return (
26
55
  <Root name="MedicationOrder">
27
- <Header>
28
- <Title>
29
- {medicationReference && <Reference fhirData={medicationReference} />}
30
- </Title>
31
- </Header>
32
- <Body>
33
- {showMedicationCodeableConcept && (
34
- <Value label="Medication" data-testid="medication">
35
- <Coding fhirData={medicationCodeableConcept} />
36
- </Value>
37
- )}
38
- {reasonCode && (
39
- <Value label="Reason" data-testid="reasonCode">
40
- <CodeableConcept fhirData={reasonCode} />
41
- </Value>
42
- )}
43
- {hasDosageInstruction && (
44
- <Value label="Dosage" data-testid="hasDosageInstruction">
45
- <ul>
46
- {dosageInstruction.map((item, i) => (
47
- <li key={`item-${i}`}>{item.text}</li>
48
- ))}
49
- </ul>
50
- </Value>
51
- )}
52
- </Body>
56
+ <Accordion
57
+ headerContent={
58
+ <Header
59
+ icon={fhirIcons}
60
+ resourceName="MedicationOrder"
61
+ title={
62
+ medicationReference && (
63
+ <Reference fhirData={medicationReference} />
64
+ )
65
+ }
66
+ />
67
+ }
68
+ bodyContent={<Body tableData={tableData} />}
69
+ />
53
70
  </Root>
54
71
  );
55
72
  };
@@ -4,8 +4,75 @@ import { render } from '@testing-library/react';
4
4
  import MedicationOrder from './MedicationOrder';
5
5
 
6
6
  import example from '../../../fixtures/dstu2/resources/medicationOrder/example.json';
7
+ import fhirIcons from '../../../fixtures/example-icons';
7
8
 
8
9
  describe('should render MedicationOrder component properly', () => {
10
+ it('component without a fhirIcons props should render a default icon', () => {
11
+ const defaultProps = {
12
+ fhirResource: example,
13
+ };
14
+
15
+ const { getByAltText } = render(<MedicationOrder {...defaultProps} />);
16
+ const headerIcon = getByAltText('medication order');
17
+
18
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
19
+ });
20
+
21
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
22
+ const defaultProps = {
23
+ fhirResource: example,
24
+ fhirIcons: false,
25
+ };
26
+
27
+ const { getByTestId } = render(<MedicationOrder {...defaultProps} />);
28
+ const headerIcon = getByTestId('placeholder');
29
+
30
+ expect(headerIcon).toBeTruthy();
31
+ });
32
+
33
+ it('component with the img as a fhirIcons props should render an img', () => {
34
+ const defaultProps = {
35
+ fhirResource: example,
36
+ fhirIcons: (
37
+ <img
38
+ src={require('../assets/containers/MedicationOrder/medication-order.svg')}
39
+ alt="medication order"
40
+ />
41
+ ),
42
+ };
43
+
44
+ const { getByAltText } = render(<MedicationOrder {...defaultProps} />);
45
+ const headerIcon = getByAltText('medication order');
46
+
47
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
48
+ });
49
+
50
+ it('component with the resources object as a fhirIcons props should render an img', () => {
51
+ const defaultProps = {
52
+ fhirResource: example,
53
+ fhirIcons: fhirIcons,
54
+ };
55
+
56
+ const { getByAltText } = render(<MedicationOrder {...defaultProps} />);
57
+ const headerIcon = getByAltText('medication order');
58
+
59
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
60
+ });
61
+
62
+ it('component with the url as a fhirIcons props should render an img', () => {
63
+ const avatarSrc =
64
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
65
+ const defaultProps = {
66
+ fhirResource: example,
67
+ fhirIcons: avatarSrc,
68
+ };
69
+
70
+ const { getByAltText } = render(<MedicationOrder {...defaultProps} />);
71
+ const headerIcon = getByAltText('header icon');
72
+
73
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
74
+ });
75
+
9
76
  it('should render with DSTU2 source data', () => {
10
77
  const defaultProps = {
11
78
  fhirResource: example,
@@ -1,15 +1,15 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _get from 'lodash/get';
4
+ import Accordion from '../../containers/Accordion/Accordion';
4
5
  import Reference from '../../datatypes/Reference';
5
6
  import CodeableConcept from '../../datatypes/CodeableConcept';
6
7
  import Coding from '../../datatypes/Coding';
7
8
  import Date from '../../datatypes/Date';
8
9
 
9
- import { Root, Header, Title, Body, Value } from '../../ui';
10
+ import { Root, Header, Body } from '../../ui';
10
11
 
11
- const MedicationRequest = props => {
12
- const { fhirResource } = props;
12
+ const MedicationRequest = ({ fhirResource, fhirIcons }) => {
13
13
  const medicationReference = _get(fhirResource, 'medicationReference');
14
14
  const medicationCodeableConcept = _get(
15
15
  fhirResource,
@@ -25,49 +25,69 @@ const MedicationRequest = props => {
25
25
  _get(fhirResource, 'requester.agent') || _get(fhirResource, 'requester');
26
26
  const created = _get(fhirResource, 'authoredOn');
27
27
  const intent = _get(fhirResource, 'intent');
28
+ const tableData = [
29
+ {
30
+ label: 'Medication',
31
+ testId: 'medication',
32
+ data: showMedicationCodeableConcept && (
33
+ <Coding fhirData={medicationCodeableConcept} />
34
+ ),
35
+ status: showMedicationCodeableConcept,
36
+ },
37
+ {
38
+ label: 'Requester',
39
+ testId: 'requester',
40
+ data: requester && <Reference fhirData={requester} />,
41
+ status: requester,
42
+ },
43
+ {
44
+ label: 'Created',
45
+ testId: 'created',
46
+ data: created && <Date fhirData={created} />,
47
+ status: created,
48
+ },
49
+ {
50
+ label: 'Type of request',
51
+ testId: 'intent',
52
+ data: intent,
53
+ status: intent,
54
+ },
55
+ {
56
+ label: 'Reason',
57
+ testId: 'reasonCode',
58
+ data: reasonCode && <CodeableConcept fhirData={reasonCode} />,
59
+ status: reasonCode,
60
+ },
61
+ {
62
+ label: 'Dosage',
63
+ testId: 'hasDosageInstruction',
64
+ data:
65
+ hasDosageInstruction &&
66
+ dosageInstruction.map((item, i) => (
67
+ <p key={`dosage-instruction-item-${i}`}>{item.text}</p>
68
+ )),
69
+ status: hasDosageInstruction,
70
+ },
71
+ ];
72
+
28
73
  return (
29
74
  <Root name="MedicationRequest">
30
- <Header>
31
- <Title>
32
- {medicationReference && <Reference fhirData={medicationReference} />}
33
- </Title>
34
- </Header>
35
- <Body>
36
- {showMedicationCodeableConcept && (
37
- <Value label="Medication" data-testid="medication">
38
- <Coding fhirData={medicationCodeableConcept} />
39
- </Value>
40
- )}
41
- {requester && (
42
- <Value label="Requester" data-testid="requester">
43
- <Reference fhirData={requester} />
44
- </Value>
45
- )}
46
- {created && (
47
- <Value label="Created" data-testid="created">
48
- <Date fhirData={created} />
49
- </Value>
50
- )}
51
- {intent && (
52
- <Value label="Type of request" data-testid="intent">
53
- {intent}
54
- </Value>
55
- )}
56
- {reasonCode && (
57
- <Value label="Reason" data-testid="reasonCode">
58
- <CodeableConcept fhirData={reasonCode} />
59
- </Value>
60
- )}
61
- {hasDosageInstruction && (
62
- <Value label="Dosage" data-testid="hasDosageInstruction">
63
- <ul>
64
- {dosageInstruction.map((item, i) => (
65
- <li key={`item-${i}`}>{item.text}</li>
66
- ))}
67
- </ul>
68
- </Value>
69
- )}
70
- </Body>
75
+ <Accordion
76
+ headerContent={
77
+ <Header
78
+ icon={fhirIcons}
79
+ resourceName="MedicationRequest"
80
+ title={
81
+ medicationReference ? (
82
+ <Reference fhirData={medicationReference} />
83
+ ) : (
84
+ 'Medication request'
85
+ )
86
+ }
87
+ />
88
+ }
89
+ bodyContent={<Body tableData={tableData} />}
90
+ />
71
91
  </Root>
72
92
  );
73
93
  };
@@ -8,6 +8,8 @@ import stu3Example2 from '../../../fixtures/stu3/resources/medicationRequest/exa
8
8
  import R4Example1 from '../../../fixtures/r4/resources/medicationRequest/example1.json';
9
9
  import R4Example2 from '../../../fixtures/r4/resources/medicationRequest/example2.json';
10
10
  import R4Example3 from '../../../fixtures/r4/resources/medicationRequest/example3.json';
11
+ import fhirIcons from '../../../fixtures/example-icons';
12
+ import MedicationRequestIcon from '../../../assets/containers/MedicationRequest/medication-request.svg';
11
13
 
12
14
  export default {
13
15
  title: 'MedicationRequest',
@@ -15,25 +17,39 @@ export default {
15
17
 
16
18
  export const DefaultVisualizationSTU3 = () => {
17
19
  const fhirResource = object('Resource', stu3Example1);
18
- return <MedicationRequest fhirResource={fhirResource} />;
20
+ return (
21
+ <MedicationRequest
22
+ fhirResource={fhirResource}
23
+ fhirIcons={require('../../../assets/containers/MedicationRequest/medication-request.svg')}
24
+ />
25
+ );
19
26
  };
20
27
 
21
28
  export const Example2OfSTU3 = () => {
22
29
  const fhirResource = object('Resource', stu3Example2);
23
- return <MedicationRequest fhirResource={fhirResource} />;
30
+ return (
31
+ <MedicationRequest
32
+ fhirResource={fhirResource}
33
+ fhirIcons={MedicationRequestIcon}
34
+ />
35
+ );
24
36
  };
25
37
 
26
38
  export const Example1OfR4 = () => {
27
39
  const fhirResource = object('Resource', R4Example1);
28
- return <MedicationRequest fhirResource={fhirResource} />;
40
+ return (
41
+ <MedicationRequest fhirResource={fhirResource} fhirIcons={fhirIcons} />
42
+ );
29
43
  };
30
44
 
31
45
  export const Example2OfR4 = () => {
32
46
  const fhirResource = object('Resource', R4Example2);
33
- return <MedicationRequest fhirResource={fhirResource} />;
47
+ return <MedicationRequest fhirResource={fhirResource} fhirIcons={false} />;
34
48
  };
35
49
 
36
50
  export const Example3OfR4 = () => {
37
51
  const fhirResource = object('Resource', R4Example3);
38
- return <MedicationRequest fhirResource={fhirResource} />;
52
+ return (
53
+ <MedicationRequest fhirResource={fhirResource} fhirIcons={'random text'} />
54
+ );
39
55
  };
@@ -8,8 +8,75 @@ import stu3Example2 from '../../../fixtures/stu3/resources/medicationRequest/exa
8
8
  import r4Example1 from '../../../fixtures/r4/resources/medicationRequest/example1.json';
9
9
  import r4Example2 from '../../../fixtures/r4/resources/medicationRequest/example2.json';
10
10
  import r4Example3 from '../../../fixtures/r4/resources/medicationRequest/example3.json';
11
+ import fhirIcons from '../../../fixtures/example-icons';
11
12
 
12
13
  describe('should render MedicationRequest component properly', () => {
14
+ it('component without a fhirIcons props should render a default icon', () => {
15
+ const defaultProps = {
16
+ fhirResource: stu3Example1,
17
+ };
18
+
19
+ const { getByAltText } = render(<MedicationRequest {...defaultProps} />);
20
+ const headerIcon = getByAltText('medication request');
21
+
22
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
23
+ });
24
+
25
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
26
+ const defaultProps = {
27
+ fhirResource: stu3Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<MedicationRequest {...defaultProps} />);
32
+ const headerIcon = getByTestId('placeholder');
33
+
34
+ expect(headerIcon).toBeTruthy();
35
+ });
36
+
37
+ it('component with the img as a fhirIcons props should render an img', () => {
38
+ const defaultProps = {
39
+ fhirResource: stu3Example1,
40
+ fhirIcons: (
41
+ <img
42
+ src={require('../assets/containers/MedicationOrder/medication-request.svg')}
43
+ alt="medication request"
44
+ />
45
+ ),
46
+ };
47
+
48
+ const { getByAltText } = render(<MedicationRequest {...defaultProps} />);
49
+ const headerIcon = getByAltText('medication request');
50
+
51
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
52
+ });
53
+
54
+ it('component with the resources object as a fhirIcons props should render an img', () => {
55
+ const defaultProps = {
56
+ fhirResource: stu3Example1,
57
+ fhirIcons: fhirIcons,
58
+ };
59
+
60
+ const { getByAltText } = render(<MedicationRequest {...defaultProps} />);
61
+ const headerIcon = getByAltText('medication request');
62
+
63
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
64
+ });
65
+
66
+ it('component with the url as a fhirIcons props should render an img', () => {
67
+ const avatarSrc =
68
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
69
+ const defaultProps = {
70
+ fhirResource: stu3Example1,
71
+ fhirIcons: avatarSrc,
72
+ };
73
+
74
+ const { getByAltText } = render(<MedicationRequest {...defaultProps} />);
75
+ const headerIcon = getByAltText('header icon');
76
+
77
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
78
+ });
79
+
13
80
  it('should render with STU3 source data', () => {
14
81
  const defaultProps = {
15
82
  fhirResource: stu3Example1,
@@ -0,0 +1,52 @@
1
+ import { ValueSection, ValueSectionItem } from '../../ui';
2
+ import React from 'react';
3
+ import Reference from '../../datatypes/Reference';
4
+ import _get from 'lodash/get';
5
+
6
+ const MedicationDetails = props => {
7
+ const {
8
+ medication,
9
+ expiration,
10
+ ingredient,
11
+ medicationReference,
12
+ hasReasonCode,
13
+ reasonCode,
14
+ } = props;
15
+ return (
16
+ <ValueSection label={medication} marginBottom>
17
+ <ValueSectionItem label="Expiration date" data-testid="expirationDate">
18
+ {expiration}
19
+ </ValueSectionItem>
20
+ {ingredient && (
21
+ <ValueSectionItem label="Ingredient" data-testid="ingredient">
22
+ {ingredient.map((item, i) => (
23
+ <div key={`item-${i}`} data-testid="ingredient-item">
24
+ {_get(item, 'itemCodeableConcept.coding.0.display', '')}
25
+ </div>
26
+ ))}
27
+ </ValueSectionItem>
28
+ )}
29
+ {medicationReference && (
30
+ <ValueSectionItem
31
+ label="Medication reference"
32
+ data-testid="medicationReference"
33
+ >
34
+ {<Reference fhirData={medicationReference} />}
35
+ </ValueSectionItem>
36
+ )}
37
+ {hasReasonCode && (
38
+ <ValueSectionItem label="Reasons" data-testid="hasReasonCode">
39
+ {reasonCode.map((item, i) => {
40
+ const display = _get(item, 'coding.0.display');
41
+ if (display) {
42
+ return <div key={`item-${i}`}>{display}</div>;
43
+ }
44
+ return null;
45
+ })}
46
+ </ValueSectionItem>
47
+ )}
48
+ </ValueSection>
49
+ );
50
+ };
51
+
52
+ export default MedicationDetails;
@@ -0,0 +1,46 @@
1
+ import { ValueSection, ValueSectionItem } from '../../ui';
2
+ import React from 'react';
3
+ import _get from 'lodash/get';
4
+
5
+ const MedicationDosage = props => {
6
+ const { dosage, hasNote, note, itemNumber } = props;
7
+
8
+ const instructions = _get(dosage, 'text');
9
+ const additionalInstructionText = _get(
10
+ dosage,
11
+ 'additionalInstruction[0].text',
12
+ );
13
+ const route =
14
+ _get(dosage, 'route.coding[0].display') ||
15
+ `${_get(dosage, 'route.text', '')} ${_get(dosage, 'text', '')}`;
16
+ const hasRoute = route.trim() !== '';
17
+
18
+ return (
19
+ <ValueSection label="Dosage" key={itemNumber}>
20
+ <ValueSectionItem label="Instructions" data-testid="dosageInstruction">
21
+ {instructions}
22
+ </ValueSectionItem>
23
+ {additionalInstructionText && (
24
+ <ValueSectionItem
25
+ label="Additional instruction"
26
+ data-testid="additionalInstruction"
27
+ >
28
+ {additionalInstructionText}
29
+ </ValueSectionItem>
30
+ )}
31
+ {hasRoute && (
32
+ <ValueSectionItem label="Route" data-testid="route">
33
+ {route}
34
+ </ValueSectionItem>
35
+ )}
36
+ {hasNote && (
37
+ <ValueSectionItem label="Notes" data-testid="hasNote">
38
+ {note.map((item, i) => (
39
+ <div key={`note-${i}`}>{item.text}</div>
40
+ ))}
41
+ </ValueSectionItem>
42
+ )}
43
+ </ValueSection>
44
+ );
45
+ };
46
+ export default MedicationDosage;