fhir-react 0.3.7 → 0.3.10

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 (179) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.storybook/main.js +5 -0
  4. package/.storybook/manager.js +6 -0
  5. package/.storybook/preview.js +7 -0
  6. package/.stylelintrc +6 -2
  7. package/README.md +19 -1
  8. package/build/index.js +15 -11
  9. package/build/style.css +9 -9
  10. package/package.json +59 -57
  11. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  12. package/src/assets/containers/Generic/generic.svg +3 -0
  13. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  14. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  15. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  16. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  17. package/src/components/containers/Accordion/Accordion.js +44 -13
  18. package/src/components/containers/Accordion/Accordion.stories.js +74 -58
  19. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  20. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  21. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
  22. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  23. package/src/components/datatypes/Coding/Coding.js +7 -3
  24. package/src/components/datatypes/Reference/Reference.js +7 -5
  25. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  26. package/src/components/defaultArgTypes.js +12 -0
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
  32. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  33. package/src/components/resources/Appointment/Appointment.js +9 -1
  34. package/src/components/resources/Appointment/Appointment.stories.js +51 -62
  35. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  36. package/src/components/resources/Binary/Binary.js +2 -1
  37. package/src/components/resources/Binary/Binary.stories.js +27 -21
  38. package/src/components/resources/Bundle/Bundle.css +7 -0
  39. package/src/components/resources/Bundle/Bundle.js +15 -11
  40. package/src/components/resources/Bundle/Bundle.stories.js +59 -115
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
  44. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
  47. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  48. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  49. package/src/components/resources/Claim/Claim.js +9 -1
  50. package/src/components/resources/Claim/Claim.stories.js +36 -49
  51. package/src/components/resources/Claim/Claim.test.js +32 -1
  52. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  53. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  54. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  55. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
  56. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  57. package/src/components/resources/ClaimResponse/Item.js +44 -9
  58. package/src/components/resources/ClaimResponse/Items.js +5 -4
  59. package/src/components/resources/Condition/Condition.js +10 -3
  60. package/src/components/resources/Condition/Condition.stories.js +47 -62
  61. package/src/components/resources/Condition/Condition.test.js +37 -4
  62. package/src/components/resources/Coverage/Coverage.js +9 -1
  63. package/src/components/resources/Coverage/Coverage.stories.js +38 -50
  64. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  65. package/src/components/resources/Device/Device.js +9 -1
  66. package/src/components/resources/Device/Device.stories.js +40 -52
  67. package/src/components/resources/Device/Device.test.js +36 -1
  68. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
  70. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  71. package/src/components/resources/DocumentReference/DocumentReference.js +9 -2
  72. package/src/components/resources/DocumentReference/DocumentReference.stories.js +25 -29
  73. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  74. package/src/components/resources/Encounter/Encounter.js +9 -1
  75. package/src/components/resources/Encounter/Encounter.stories.js +43 -59
  76. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  77. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  78. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
  79. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  80. package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
  81. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  82. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  84. package/src/components/resources/Generic/Generic.js +21 -7
  85. package/src/components/resources/Generic/Generic.stories.js +22 -12
  86. package/src/components/resources/Generic/Generic.test.js +26 -7
  87. package/src/components/resources/Goal/Goal.js +9 -3
  88. package/src/components/resources/Goal/Goal.stories.js +35 -49
  89. package/src/components/resources/Goal/Goal.test.js +32 -1
  90. package/src/components/resources/Immunization/Immunization.js +9 -2
  91. package/src/components/resources/Immunization/Immunization.stories.js +38 -51
  92. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  93. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  94. package/src/components/resources/List/Entries.js +3 -3
  95. package/src/components/resources/List/List.js +137 -88
  96. package/src/components/resources/List/List.stories.js +69 -40
  97. package/src/components/resources/List/List.test.js +105 -1
  98. package/src/components/resources/Location/Location.js +66 -47
  99. package/src/components/resources/Location/Location.stories.js +25 -13
  100. package/src/components/resources/Location/Location.test.js +106 -4
  101. package/src/components/resources/Medication/Medication.js +9 -1
  102. package/src/components/resources/Medication/Medication.stories.js +42 -64
  103. package/src/components/resources/Medication/Medication.test.js +36 -1
  104. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  107. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  108. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  109. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
  110. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  111. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  114. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  115. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  117. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  118. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
  119. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  120. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  121. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
  122. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  123. package/src/components/resources/Observation/Observation.js +3 -1
  124. package/src/components/resources/Observation/Observation.stories.js +39 -33
  125. package/src/components/resources/Observation/Observation.test.js +30 -1
  126. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  127. package/src/components/resources/Organization/Organization.js +10 -2
  128. package/src/components/resources/Organization/Organization.stories.js +40 -52
  129. package/src/components/resources/Organization/Organization.test.js +36 -1
  130. package/src/components/resources/Patient/Patient.js +4 -0
  131. package/src/components/resources/Patient/Patient.stories.js +36 -28
  132. package/src/components/resources/Patient/Patient.test.js +31 -2
  133. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  134. package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
  135. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  136. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  137. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
  138. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  139. package/src/components/resources/Procedure/Procedure.js +3 -2
  140. package/src/components/resources/Procedure/Procedure.stories.js +33 -25
  141. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  142. package/src/components/resources/Questionnaire/Group.js +53 -0
  143. package/src/components/resources/Questionnaire/Items.js +45 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  145. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  146. package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
  147. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  148. package/src/components/resources/Questionnaire/Questions.js +40 -0
  149. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  150. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  151. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  152. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  154. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  155. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
  156. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  157. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  158. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  159. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  160. package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
  161. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  162. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  163. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -0
  164. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  165. package/src/components/resources/RelatedPerson/index.js +3 -0
  166. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  167. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
  168. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  169. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  170. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
  171. package/src/components/ui/index.js +48 -31
  172. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  173. package/src/fixtures/example-icons.jsx +42 -0
  174. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  175. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  176. package/src/style.scss +14 -1
  177. package/.storybook/addons.js +0 -1
  178. package/.storybook/config.js +0 -26
  179. package/.storybook/presets.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import MedicationAdministration from './MedicationAdministration';
5
5
 
@@ -9,57 +9,50 @@ import r4Example1 from '../../../fixtures/r4/resources/medicationAdministration/
9
9
  import r4Example2 from '../../../fixtures/r4/resources/medicationAdministration/example2.json';
10
10
  import r4Example3 from '../../../fixtures/r4/resources/medicationAdministration/example3.json';
11
11
  import fhirVersions from '../fhirResourceVersions';
12
+ import fhirIcons from '../../../fixtures/example-icons';
13
+ import MedicationAdministrationIcon from '../../../assets/containers/MedicationAdministration/medication-administration.svg';
12
14
 
13
15
  export default {
14
16
  title: 'MedicationAdministration',
17
+ component: MedicationAdministration,
18
+ argTypes: {
19
+ ...defaultArgTypes,
20
+ },
15
21
  };
16
22
 
17
- export const DefaultVisualizationDSTU2 = () => {
18
- const fhirResource = object('Resource', dstu2Example1);
19
- return (
20
- <MedicationAdministration
21
- fhirVersion={fhirVersions.DSTU2}
22
- fhirResource={fhirResource}
23
- />
24
- );
23
+ const Template = args => <MedicationAdministration {...args} />;
24
+
25
+ export const DefaultVisualizationDSTU2 = Template.bind({});
26
+ DefaultVisualizationDSTU2.args = {
27
+ fhirVersion: fhirVersions.DSTU2,
28
+ fhirResource: dstu2Example1,
29
+ fhirIcons: require('../../../assets/containers/MedicationAdministration/medication-administration.svg'),
25
30
  };
26
31
 
27
- export const ExampleOfSTU3 = () => {
28
- const fhirResource = object('Resource', stu3Example1);
29
- return (
30
- <MedicationAdministration
31
- fhirVersion={fhirVersions.STU3}
32
- fhirResource={fhirResource}
33
- />
34
- );
32
+ export const ExampleOfSTU3 = Template.bind({});
33
+ ExampleOfSTU3.args = {
34
+ fhirVersion: fhirVersions.STU3,
35
+ fhirResource: stu3Example1,
36
+ fhirIcons: MedicationAdministrationIcon,
35
37
  };
36
38
 
37
- export const Example1OfR4 = () => {
38
- const fhirResource = object('Resource', r4Example1);
39
- return (
40
- <MedicationAdministration
41
- fhirVersion={fhirVersions.R4}
42
- fhirResource={fhirResource}
43
- />
44
- );
39
+ export const Example1OfR4 = Template.bind({});
40
+ Example1OfR4.args = {
41
+ fhirVersion: fhirVersions.R4,
42
+ fhirResource: r4Example1,
43
+ fhirIcons: fhirIcons,
45
44
  };
46
45
 
47
- export const Example2OfR4 = () => {
48
- const fhirResource = object('Resource', r4Example2);
49
- return (
50
- <MedicationAdministration
51
- fhirVersion={fhirVersions.R4}
52
- fhirResource={fhirResource}
53
- />
54
- );
46
+ export const Example2OfR4 = Template.bind({});
47
+ Example2OfR4.args = {
48
+ fhirVersion: fhirVersions.R4,
49
+ fhirResource: r4Example2,
50
+ fhirIcons: false,
55
51
  };
56
52
 
57
- export const Example3OfR4 = () => {
58
- const fhirResource = object('Resource', r4Example3);
59
- return (
60
- <MedicationAdministration
61
- fhirVersion={fhirVersions.R4}
62
- fhirResource={fhirResource}
63
- />
64
- );
53
+ export const Example3OfR4 = Template.bind({});
54
+ Example3OfR4.args = {
55
+ fhirVersion: fhirVersions.R4,
56
+ fhirResource: r4Example3,
57
+ fhirIcons: 'random text',
65
58
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
 
4
4
  import MedicationAdministration from './MedicationAdministration';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -7,8 +7,89 @@ import dstu2Example1 from '../../../fixtures/dstu2/resources/medicationAdministr
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/medicationAdministration/example1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/medicationAdministration/example1.json';
9
9
  import r4Example2 from '../../../fixtures/r4/resources/medicationAdministration/example3.json';
10
+ import fhirIcons from '../../../fixtures/example-icons';
10
11
 
11
12
  describe('should render MedicationAdministration component properly', () => {
13
+ it('component without a fhirIcons props should render a default icon', () => {
14
+ const defaultProps = {
15
+ fhirVersion: fhirVersions.DSTU2,
16
+ fhirResource: dstu2Example1,
17
+ };
18
+
19
+ const { getByAltText } = render(
20
+ <MedicationAdministration {...defaultProps} />,
21
+ );
22
+ const headerIcon = getByAltText('medication administration');
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(
35
+ <MedicationAdministration {...defaultProps} />,
36
+ );
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: dstu2Example1,
46
+ fhirIcons: (
47
+ <img
48
+ src={require('../assets/containers/MedicationAdministration/medication-administration.svg')}
49
+ alt="pill gets swallowed"
50
+ />
51
+ ),
52
+ };
53
+
54
+ const { getByAltText } = render(
55
+ <MedicationAdministration {...defaultProps} />,
56
+ );
57
+ const headerIcon = getByAltText('pill gets swallowed');
58
+
59
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
60
+ });
61
+
62
+ it('component with the resources object as a fhirIcons props should render an img', () => {
63
+ const defaultProps = {
64
+ fhirVersion: fhirVersions.DSTU2,
65
+ fhirResource: dstu2Example1,
66
+ fhirIcons: fhirIcons,
67
+ };
68
+
69
+ const { getByAltText } = render(
70
+ <MedicationAdministration {...defaultProps} />,
71
+ );
72
+ const headerIcon = getByAltText('pill gets swallowed');
73
+
74
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
75
+ });
76
+
77
+ it('component with the url as a fhirIcons props should render an img', () => {
78
+ const avatarSrc =
79
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
80
+ const defaultProps = {
81
+ fhirVersion: fhirVersions.DSTU2,
82
+ fhirResource: dstu2Example1,
83
+ fhirIcons: avatarSrc,
84
+ };
85
+
86
+ const { getByAltText } = render(
87
+ <MedicationAdministration {...defaultProps} />,
88
+ );
89
+ const headerIcon = getByAltText('header icon');
90
+
91
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
92
+ });
12
93
  it('should render with DSTU2 source data', () => {
13
94
  const defaultProps = {
14
95
  fhirResource: dstu2Example1,
@@ -108,4 +189,39 @@ describe('should render MedicationAdministration component properly', () => {
108
189
  expect(getByTestId('dosageRoute').textContent).toContain('Oral Route');
109
190
  expect(getByTestId('dosageQuantity').textContent).toEqual('2 TAB');
110
191
  });
192
+
193
+ it('should fire custom onClick function', () => {
194
+ const defaultProps = {
195
+ fhirResource: r4Example2,
196
+ fhirVersion: fhirVersions.R4,
197
+ };
198
+
199
+ const onClick = jest.fn();
200
+ const { getByRole } = render(
201
+ <MedicationAdministration {...defaultProps} onClick={onClick} />,
202
+ );
203
+ const accordion = getByRole('button');
204
+ fireEvent.click(accordion);
205
+
206
+ const attribute = accordion.getAttribute('data-bs-toggle');
207
+ expect(attribute).not.toEqual('collapse');
208
+ expect(onClick).toHaveBeenCalled();
209
+ });
210
+
211
+ it('should not fire custom onClick function', () => {
212
+ const defaultProps = {
213
+ fhirResource: r4Example2,
214
+ fhirVersion: fhirVersions.R4,
215
+ };
216
+
217
+ const onClick = 'test';
218
+ const { getByRole } = render(
219
+ <MedicationAdministration {...defaultProps} onClick={onClick} />,
220
+ );
221
+ const accordion = getByRole('button');
222
+ fireEvent.click(accordion);
223
+
224
+ const attribute = accordion.getAttribute('data-bs-toggle');
225
+ expect(attribute).toEqual('collapse');
226
+ });
111
227
  });
@@ -0,0 +1,25 @@
1
+ import { MissingValue, TableCell, TableRow } from '../../ui';
2
+ import CodeableConcept from '../../datatypes/CodeableConcept';
3
+ import React from 'react';
4
+
5
+ const DosageInstruction = props => {
6
+ const empty = <MissingValue />;
7
+ const {
8
+ timing = empty,
9
+ route = empty,
10
+ doseQuantity = empty,
11
+ additionalInstructions = empty,
12
+ } = props.item;
13
+ return (
14
+ <TableRow>
15
+ <TableCell data-testid="dosageTiming">{timing}</TableCell>
16
+ <TableCell data-testid="dosageRoute">{route}</TableCell>
17
+ <TableCell data-testid="dosageQuantity">{doseQuantity}</TableCell>
18
+ <TableCell data-testid="dosageAdditionalInstructions">
19
+ <CodeableConcept fhirData={additionalInstructions} />
20
+ </TableCell>
21
+ </TableRow>
22
+ );
23
+ };
24
+
25
+ export default DosageInstruction;
@@ -9,37 +9,14 @@ import fhirVersions from '../fhirResourceVersions';
9
9
  import {
10
10
  Root,
11
11
  Header,
12
- Title,
13
12
  Body,
14
- Value,
15
13
  ValueSection,
16
14
  Table,
17
15
  TableHeader,
18
- TableCell,
19
16
  TableRow,
20
- MissingValue,
21
17
  } from '../../ui';
22
- import CodeableConcept from '../../datatypes/CodeableConcept/CodeableConcept';
23
-
24
- const DosageInstruction = props => {
25
- const empty = <MissingValue />;
26
- const {
27
- timing = empty,
28
- route = empty,
29
- doseQuantity = empty,
30
- additionalInstructions = empty,
31
- } = props.item;
32
- return (
33
- <TableRow>
34
- <TableCell data-testid="dosageTiming">{timing}</TableCell>
35
- <TableCell data-testid="dosageRoute">{route}</TableCell>
36
- <TableCell data-testid="dosageQuantity">{doseQuantity}</TableCell>
37
- <TableCell data-testid="dosageAdditionalInstructions">
38
- <CodeableConcept fhirData={additionalInstructions} />
39
- </TableCell>
40
- </TableRow>
41
- );
42
- };
18
+ import Accordion from '../../containers/Accordion';
19
+ import DosageInstruction from './DosageInstruction';
43
20
 
44
21
  const commonDTO = fhirResource => {
45
22
  const typeCoding = _get(fhirResource, 'type.coding.0');
@@ -182,8 +159,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
182
159
  }
183
160
  };
184
161
 
185
- const MedicationDispense = props => {
186
- const { fhirResource, fhirVersion } = props;
162
+ const MedicationDispense = ({
163
+ fhirResource,
164
+ fhirVersion,
165
+ fhirIcons,
166
+ onClick,
167
+ rawOnClick,
168
+ }) => {
187
169
  let fhirResourceData = {};
188
170
  try {
189
171
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -201,49 +183,69 @@ const MedicationDispense = props => {
201
183
  whenPrepared,
202
184
  } = fhirResourceData;
203
185
 
186
+ const tableData = [
187
+ {
188
+ label: 'Medication',
189
+ testId: 'medicationCoding',
190
+ data: medicationCoding && <Coding fhirData={medicationCoding} />,
191
+ status: medicationCoding,
192
+ },
193
+ {
194
+ label: 'Prepared',
195
+ testId: 'whenPrepared',
196
+ data: whenPrepared && <Date fhirData={whenPrepared} isBlack />,
197
+ status: whenPrepared,
198
+ },
199
+ {
200
+ label: 'Type',
201
+ testId: 'typeCoding',
202
+ data: typeCoding && <Coding fhirData={typeCoding} />,
203
+ status: typeCoding,
204
+ },
205
+ ];
206
+
204
207
  return (
205
208
  <Root name="MedicationDispense">
206
- {medicationTitle && (
207
- <Header>
208
- <Title>{medicationTitle}</Title>
209
- </Header>
210
- )}
211
- <Body>
212
- {medicationCoding && (
213
- <Value label="Medication" data-testid="medicationCoding">
214
- <Coding fhirData={medicationCoding} />
215
- </Value>
216
- )}
217
- {whenPrepared && (
218
- <Value label="Prepared" data-testid="whenPrepared">
219
- <Date fhirData={whenPrepared} />
220
- </Value>
221
- )}
222
- {typeCoding && (
223
- <Value label="Type" data-testid="typeCoding">
224
- <Coding fhirData={typeCoding} />
225
- </Value>
226
- )}
227
- {hasDosageInstruction && (
228
- <ValueSection label="Dosage instruction">
229
- <Table>
230
- <thead>
231
- <TableRow>
232
- <TableHeader>Timing</TableHeader>
233
- <TableHeader>Route</TableHeader>
234
- <TableHeader>Dose quantity</TableHeader>
235
- <TableHeader>Additional instructions</TableHeader>
236
- </TableRow>
237
- </thead>
238
- <tbody data-testid="hasDosageInstruction">
239
- {dosageInstructionData.map((item, i) => (
240
- <DosageInstruction key={`item-${i}`} item={item} />
241
- ))}
242
- </tbody>
243
- </Table>
244
- </ValueSection>
245
- )}
246
- </Body>
209
+ <Accordion
210
+ headerContent={
211
+ <Header
212
+ resourceName="MedicationDispense"
213
+ title={medicationTitle}
214
+ icon={fhirIcons}
215
+ />
216
+ }
217
+ bodyContent={
218
+ <Body tableData={tableData}>
219
+ {hasDosageInstruction && (
220
+ <ValueSection
221
+ label="Dosage instruction"
222
+ marginTop={medicationCoding || whenPrepared || typeCoding}
223
+ >
224
+ <Table>
225
+ <thead>
226
+ <TableRow>
227
+ <TableHeader>Timing</TableHeader>
228
+ <TableHeader>Route</TableHeader>
229
+ <TableHeader>Dose quantity</TableHeader>
230
+ <TableHeader>Additional instructions</TableHeader>
231
+ </TableRow>
232
+ </thead>
233
+ <tbody
234
+ data-testid="hasDosageInstruction"
235
+ className="border-top-0"
236
+ >
237
+ {dosageInstructionData.map((item, i) => (
238
+ <DosageInstruction key={`item-${i}`} item={item} />
239
+ ))}
240
+ </tbody>
241
+ </Table>
242
+ </ValueSection>
243
+ )}
244
+ </Body>
245
+ }
246
+ onClick={onClick}
247
+ rawOnClick={rawOnClick}
248
+ />
247
249
  </Root>
248
250
  );
249
251
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import MedicationDispense from './MedicationDispense';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -10,72 +10,61 @@ import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/ex
10
10
  import stu3Example2 from '../../../fixtures/stu3/resources/medicationDispense/example2.json';
11
11
  import R4Example1 from '../../../fixtures/r4/resources/medicationDispense/example1.json';
12
12
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
13
+ import fhirIcons from '../../../fixtures/example-icons';
14
+ import MedicationDispenseIcon from '../../../assets/containers/MedicationDispense/medication-dispense.svg';
13
15
 
14
16
  export default {
15
17
  title: 'MedicationDispense',
18
+ component: MedicationDispense,
19
+ argTypes: {
20
+ ...defaultArgTypes,
21
+ },
16
22
  };
17
23
 
18
- export const DefaultVisualizationDSTU2 = () => {
19
- const fhirResource = object('Resource', dstu2Example1);
20
- return (
21
- <MedicationDispense
22
- fhirResource={fhirResource}
23
- fhirVersion={fhirVersions.DSTU2}
24
- />
25
- );
24
+ const Template = args => <MedicationDispense {...args} />;
25
+
26
+ export const DefaultVisualizationDSTU2 = Template.bind({});
27
+ DefaultVisualizationDSTU2.args = {
28
+ fhirVersion: fhirVersions.DSTU2,
29
+ fhirResource: dstu2Example1,
30
+ fhirIcons: require('../../../assets/containers/MedicationDispense/medication-dispense.svg'),
26
31
  };
27
32
 
28
- export const Example2OfDSTU2 = () => {
29
- const fhirResource = object('Resource', dstu2Example2);
30
- return (
31
- <MedicationDispense
32
- fhirResource={fhirResource}
33
- fhirVersion={fhirVersions.DSTU2}
34
- />
35
- );
33
+ export const Example2OfDSTU2 = Template.bind({});
34
+ Example2OfDSTU2.args = {
35
+ fhirVersion: fhirVersions.DSTU2,
36
+ fhirResource: dstu2Example2,
37
+ fhirIcons: MedicationDispenseIcon,
36
38
  };
37
39
 
38
- export const Example1OfSTU3 = () => {
39
- const fhirResource = object('Resource', stu3Example1);
40
- return (
41
- <MedicationDispense
42
- fhirResource={fhirResource}
43
- fhirVersion={fhirVersions.STU3}
44
- />
45
- );
40
+ export const Example1OfSTU3 = Template.bind({});
41
+ Example1OfSTU3.args = {
42
+ fhirVersion: fhirVersions.DSTU2,
43
+ fhirResource: stu3Example1,
44
+ fhirIcons: fhirIcons,
46
45
  };
47
46
 
48
- export const Example2OfSTU3 = () => {
49
- const fhirResource = object('Resource', stu3Example2);
50
- return (
51
- <MedicationDispense
52
- fhirResource={fhirResource}
53
- fhirVersion={fhirVersions.STU3}
54
- />
55
- );
47
+ export const Example2OfSTU3 = Template.bind({});
48
+ Example2OfSTU3.args = {
49
+ fhirVersion: fhirVersions.STU3,
50
+ fhirResource: stu3Example2,
51
+ fhirIcons: false,
56
52
  };
57
53
 
58
- export const Example1OfR4 = () => {
59
- const fhirResource = object('Resource', R4Example1);
60
- return (
61
- <MedicationDispense
62
- fhirResource={fhirResource}
63
- fhirVersion={fhirVersions.R4}
64
- />
65
- );
54
+ export const Example1OfR4 = Template.bind({});
55
+ Example1OfR4.args = {
56
+ fhirVersion: fhirVersions.R4,
57
+ fhirResource: R4Example1,
58
+ fhirIcons: 'random text',
66
59
  };
67
60
 
68
- export const Example2OfR4 = () => {
69
- const fhirResource = object('Resource', R4Example2);
70
- return (
71
- <MedicationDispense
72
- fhirResource={fhirResource}
73
- fhirVersion={fhirVersions.R4}
74
- />
75
- );
61
+ export const Example2OfR4 = Template.bind({});
62
+ Example2OfR4.args = {
63
+ fhirVersion: fhirVersions.R4,
64
+ fhirResource: R4Example2,
76
65
  };
77
66
 
78
- export const ExampleWithoutFhirVersionProperty = () => {
79
- const fhirResource = object('Resource', stu3Example1);
80
- return <MedicationDispense fhirResource={fhirResource} />;
67
+ export const ExampleWithoutFhirVersionProperty = Template.bind({});
68
+ ExampleWithoutFhirVersionProperty.args = {
69
+ fhirResource: stu3Example1,
81
70
  };
@@ -1,13 +1,85 @@
1
1
  import React from 'react';
2
- import { render, within } from '@testing-library/react';
2
+ import { fireEvent, render, within } from '@testing-library/react';
3
3
  import MedicationDispense from './MedicationDispense';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import dstu2Example1 from '../../../fixtures/dstu2/resources/medicationDispense/example1.json';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/example1.json';
8
8
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  describe('should render Device component properly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirVersion: fhirVersions.DSTU2,
15
+ fhirResource: dstu2Example1,
16
+ };
17
+
18
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
19
+ const headerIcon = getByAltText('medication dispense');
20
+
21
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
22
+ });
23
+
24
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
25
+ const defaultProps = {
26
+ fhirVersion: fhirVersions.DSTU2,
27
+ fhirResource: dstu2Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<MedicationDispense {...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
+ fhirVersion: fhirVersions.DSTU2,
40
+ fhirResource: dstu2Example1,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/MedicationDispense/medication-dispense.svg')}
44
+ alt="medication dispense"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
50
+ const headerIcon = getByAltText('medication dispense');
51
+
52
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
53
+ });
54
+
55
+ it('component with the resources object as a fhirIcons props should render an img', () => {
56
+ const defaultProps = {
57
+ fhirVersion: fhirVersions.DSTU2,
58
+ fhirResource: dstu2Example1,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
63
+ const headerIcon = getByAltText('medication dispense');
64
+
65
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
66
+ });
67
+
68
+ it('component with the url as a fhirIcons props should render an img', () => {
69
+ const avatarSrc =
70
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
71
+ const defaultProps = {
72
+ fhirVersion: fhirVersions.DSTU2,
73
+ fhirResource: dstu2Example1,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
11
83
  it('should render with DSTU2 source data', () => {
12
84
  const defaultProps = {
13
85
  fhirResource: dstu2Example1,
@@ -84,4 +156,39 @@ describe('should render Device component properly', () => {
84
156
  ),
85
157
  ).toEqual(['Ordered(ordered)', 'Ordered(ordered)', 'Ordered(ordered)']);
86
158
  });
159
+
160
+ it('should fire custom onClick function', () => {
161
+ const defaultProps = {
162
+ fhirResource: R4Example2,
163
+ fhirVersion: fhirVersions.R4,
164
+ };
165
+
166
+ const onClick = jest.fn();
167
+ const { getByRole } = render(
168
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
169
+ );
170
+ const accordion = getByRole('button');
171
+ fireEvent.click(accordion);
172
+
173
+ const attribute = accordion.getAttribute('data-bs-toggle');
174
+ expect(attribute).not.toEqual('collapse');
175
+ expect(onClick).toHaveBeenCalled();
176
+ });
177
+
178
+ it('should not fire custom onClick function', () => {
179
+ const defaultProps = {
180
+ fhirResource: R4Example2,
181
+ fhirVersion: fhirVersions.R4,
182
+ };
183
+
184
+ const onClick = 'test';
185
+ const { getByRole } = render(
186
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
187
+ );
188
+ const accordion = getByRole('button');
189
+ fireEvent.click(accordion);
190
+
191
+ const attribute = accordion.getAttribute('data-bs-toggle');
192
+ expect(attribute).toEqual('collapse');
193
+ });
87
194
  });