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 Device from './Device';
5
5
 
@@ -15,68 +15,56 @@ import fhirIcons from '../../../fixtures/example-icons';
15
15
 
16
16
  export default {
17
17
  title: 'Device',
18
+ component: Device,
19
+ argTypes: {
20
+ ...defaultArgTypes,
21
+ },
18
22
  };
19
23
 
20
- export const DefaultVisualizationDSTU2 = () => {
21
- const fhirResource = object('Resource', dstu2Example1);
22
- return (
23
- <Device
24
- fhirResource={fhirResource}
25
- fhirVersion={fhirVersions.DSTU2}
26
- fhirIcons={require('../../../assets/containers/Device/device.svg')}
27
- />
28
- );
24
+ const Template = args => <Device {...args} />;
25
+
26
+ export const DefaultVisualizationDSTU2 = Template.bind({});
27
+ DefaultVisualizationDSTU2.args = {
28
+ fhirVersion: fhirVersions.DSTU2,
29
+ fhirResource: dstu2Example1,
30
+ fhirIcons: require('../../../assets/containers/Device/device.svg'),
29
31
  };
30
32
 
31
- export const ExampleOfDSTU2 = () => {
32
- const fhirResource = object('Resource', dstu2Example2);
33
- return (
34
- <Device
35
- fhirResource={fhirResource}
36
- fhirVersion={fhirVersions.DSTU2}
37
- fhirIcons={DeviceIcon}
38
- />
39
- );
33
+ export const ExampleOfDSTU2 = Template.bind({});
34
+ ExampleOfDSTU2.args = {
35
+ fhirVersion: fhirVersions.DSTU2,
36
+ fhirResource: dstu2Example2,
37
+ fhirIcons: DeviceIcon,
40
38
  };
41
39
 
42
- export const Example1OfSTU3 = () => {
43
- const fhirResource = object('Resource', stu3Example1);
44
- return (
45
- <Device
46
- fhirResource={fhirResource}
47
- fhirVersion={fhirVersions.STU3}
48
- fhirIcons={fhirIcons}
49
- />
50
- );
40
+ export const Example1OfSTU3 = Template.bind({});
41
+ Example1OfSTU3.args = {
42
+ fhirVersion: fhirVersions.STU3,
43
+ fhirResource: stu3Example1,
44
+ fhirIcons: fhirIcons,
51
45
  };
52
- export const Example2OfSTU3 = () => {
53
- const fhirResource = object('Resource', stu3Example2);
54
- return (
55
- <Device
56
- fhirResource={fhirResource}
57
- fhirVersion={fhirVersions.STU3}
58
- fhirIcons={false}
59
- />
60
- );
46
+
47
+ export const Example2OfSTU3 = Template.bind({});
48
+ Example2OfSTU3.args = {
49
+ fhirVersion: fhirVersions.STU3,
50
+ fhirResource: stu3Example2,
51
+ fhirIcons: false,
61
52
  };
62
53
 
63
- export const Example1OfR4 = () => {
64
- const fhirResource = object('Resource', r4Example1);
65
- return (
66
- <Device
67
- fhirResource={fhirResource}
68
- fhirVersion={fhirVersions.R4}
69
- fhirIcons={'random text'}
70
- />
71
- );
54
+ export const Example1OfR4 = Template.bind({});
55
+ Example1OfR4.args = {
56
+ fhirVersion: fhirVersions.R4,
57
+ fhirResource: r4Example1,
58
+ fhirIcons: 'random text',
72
59
  };
73
60
 
74
- export const Example2OfR4 = () => {
75
- const fhirResource = object('Resource', r4Example2);
76
- return <Device fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
61
+ export const Example2OfR4 = Template.bind({});
62
+ Example2OfR4.args = {
63
+ fhirVersion: fhirVersions.R4,
64
+ fhirResource: r4Example2,
77
65
  };
78
66
 
79
- export const ExampleWithoutFHIRVersionProperty = () => {
80
- const fhirResource = object('Resource', stu3Example2);
81
- return <Device fhirResource={fhirResource} />;
67
+ export const ExampleWithoutFHIRVersionProperty = Template.bind({});
68
+ ExampleWithoutFHIRVersionProperty.args = {
69
+ fhirResource: stu3Example2,
82
70
  };
@@ -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 Device from './Device';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -137,4 +137,39 @@ describe('should render Device component properly', () => {
137
137
 
138
138
  expect(getByTestId('uniqueId').textContent).toEqual('-');
139
139
  });
140
+
141
+ it('should fire custom onClick function', () => {
142
+ const defaultProps = {
143
+ fhirResource: r4Example2,
144
+ fhirVersion: fhirVersions.R4,
145
+ };
146
+
147
+ const onClick = jest.fn();
148
+ const { getByRole } = render(
149
+ <Device {...defaultProps} onClick={onClick} />,
150
+ );
151
+ const accordion = getByRole('button');
152
+ fireEvent.click(accordion);
153
+
154
+ const attribute = accordion.getAttribute('data-bs-toggle');
155
+ expect(attribute).not.toEqual('collapse');
156
+ expect(onClick).toHaveBeenCalled();
157
+ });
158
+
159
+ it('should fire custom onClick function', () => {
160
+ const defaultProps = {
161
+ fhirResource: r4Example2,
162
+ fhirVersion: fhirVersions.R4,
163
+ };
164
+
165
+ const onClick = 'test';
166
+ const { getByRole } = render(
167
+ <Device {...defaultProps} onClick={onClick} />,
168
+ );
169
+ const accordion = getByRole('button');
170
+ fireEvent.click(accordion);
171
+
172
+ const attribute = accordion.getAttribute('data-bs-toggle');
173
+ expect(attribute).toEqual('collapse');
174
+ });
140
175
  });
@@ -93,8 +93,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
93
93
  }
94
94
  };
95
95
 
96
- const DiagnosticReport = props => {
97
- const { fhirResource, fhirVersion, fhirIcons } = props;
96
+ const DiagnosticReport = ({
97
+ fhirResource,
98
+ fhirVersion,
99
+ fhirIcons,
100
+ onClick,
101
+ rawOnClick,
102
+ }) => {
98
103
  let fhirResourceData = {};
99
104
  try {
100
105
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -165,6 +170,8 @@ const DiagnosticReport = props => {
165
170
  />
166
171
  }
167
172
  bodyContent={<Body tableData={tableData} />}
173
+ onClick={onClick}
174
+ rawOnClick={rawOnClick}
168
175
  />
169
176
  </Root>
170
177
  );
@@ -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 DiagnosticReport from './DiagnosticReport';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -12,64 +12,52 @@ import example3DiagnosticReportR4 from '../../../fixtures/r4/resources/diagnosti
12
12
  import fhirIcons from '../../../fixtures/example-icons';
13
13
  import DiagnosticReportIcon from '../../../assets/containers/DiagnosticReport/diagnostic-report.svg';
14
14
 
15
- export default { title: 'DiagnosticReport' };
15
+ export default {
16
+ title: 'DiagnosticReport',
17
+ component: DiagnosticReport,
18
+ argTypes: {
19
+ ...defaultArgTypes,
20
+ },
21
+ };
22
+
23
+ const Template = args => <DiagnosticReport {...args} />;
16
24
 
17
- export const DefaultVisualizationDSTU2 = () => {
18
- const fhirResource = object('Resource', exampleDiagnosticReportDSTU2);
19
- return (
20
- <DiagnosticReport
21
- fhirVersion={fhirVersions.DSTU2}
22
- fhirResource={fhirResource}
23
- fhirIcons={require('../../../assets/containers/DiagnosticReport/diagnostic-report.svg')}
24
- />
25
- );
25
+ export const DefaultVisualizationDSTU2 = Template.bind({});
26
+ DefaultVisualizationDSTU2.args = {
27
+ fhirVersion: fhirVersions.DSTU2,
28
+ fhirResource: exampleDiagnosticReportDSTU2,
29
+ fhirIcons: require('../../../assets/containers/DiagnosticReport/diagnostic-report.svg'),
26
30
  };
27
31
 
28
- export const ExampleDiagnosticReportSTU3 = () => {
29
- const fhirResource = object('Resource', exampleDiagnosticReportSTU3);
30
- return (
31
- <DiagnosticReport
32
- fhirVersion={fhirVersions.STU3}
33
- fhirResource={fhirResource}
34
- fhirIcons={DiagnosticReportIcon}
35
- />
36
- );
32
+ export const ExampleDiagnosticReportSTU3 = Template.bind({});
33
+ ExampleDiagnosticReportSTU3.args = {
34
+ fhirVersion: fhirVersions.STU3,
35
+ fhirResource: exampleDiagnosticReportSTU3,
36
+ fhirIcons: DiagnosticReportIcon,
37
37
  };
38
38
 
39
- export const ExampleDiagnosticReportR4 = () => {
40
- const fhirResource = object('Resource', exampleDiagnosticReportR4);
41
- return (
42
- <DiagnosticReport
43
- fhirVersion={fhirVersions.R4}
44
- fhirResource={fhirResource}
45
- fhirIcons={fhirIcons}
46
- />
47
- );
39
+ export const ExampleDiagnosticReportR4 = Template.bind({});
40
+ ExampleDiagnosticReportR4.args = {
41
+ fhirVersion: fhirVersions.R4,
42
+ fhirResource: exampleDiagnosticReportR4,
43
+ fhirIcons: fhirIcons,
48
44
  };
49
45
 
50
- export const Example2DiagnosticReportR4 = () => {
51
- const fhirResource = object('Resource', example2DiagnosticReportR4);
52
- return (
53
- <DiagnosticReport
54
- fhirVersion={fhirVersions.R4}
55
- fhirResource={fhirResource}
56
- fhirIcons={false}
57
- />
58
- );
46
+ export const Example2DiagnosticReportR4 = Template.bind({});
47
+ Example2DiagnosticReportR4.args = {
48
+ fhirVersion: fhirVersions.R4,
49
+ fhirResource: example2DiagnosticReportR4,
50
+ fhirIcons: false,
59
51
  };
60
52
 
61
- export const Example3DiagnosticReportR4 = () => {
62
- const fhirResource = object('Resource', example3DiagnosticReportR4);
63
- return (
64
- <DiagnosticReport
65
- fhirVersion={fhirVersions.R4}
66
- fhirResource={fhirResource}
67
- fhirIcons={'random text'}
68
- />
69
- );
53
+ export const Example3DiagnosticReportR4 = Template.bind({});
54
+ Example3DiagnosticReportR4.args = {
55
+ fhirVersion: fhirVersions.R4,
56
+ fhirResource: example3DiagnosticReportR4,
57
+ fhirIcons: 'random text',
70
58
  };
71
59
 
72
- export const ExampleWithoutFhirVersionProperty = () => {
73
- const fhirResource = object('Resource', exampleDiagnosticReportSTU3);
74
- return <DiagnosticReport fhirResource={fhirResource} fhirIcons={fhirIcons} />;
60
+ export const ExampleWithoutFhirVersionProperty = Template.bind({});
61
+ ExampleWithoutFhirVersionProperty.args = {
62
+ fhirResource: exampleDiagnosticReportSTU3,
75
63
  };
@@ -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
  import DiagnosticReport from './DiagnosticReport';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -152,4 +152,39 @@ describe('should render component correctly', () => {
152
152
 
153
153
  expect(getByTestId('performer').textContent).toContain('Todd Ashby');
154
154
  });
155
+
156
+ it('should fire custom onClick function', () => {
157
+ const defaultProps = {
158
+ fhirResource: example2DiagnosticReportR4,
159
+ fhirVersion: fhirVersions.R4,
160
+ };
161
+
162
+ const onClick = jest.fn();
163
+ const { getByRole } = render(
164
+ <DiagnosticReport {...defaultProps} onClick={onClick} />,
165
+ );
166
+ const accordion = getByRole('button');
167
+ fireEvent.click(accordion);
168
+
169
+ const attribute = accordion.getAttribute('data-bs-toggle');
170
+ expect(attribute).not.toEqual('collapse');
171
+ expect(onClick).toHaveBeenCalled();
172
+ });
173
+
174
+ it('should not fire custom onClick function', () => {
175
+ const defaultProps = {
176
+ fhirResource: example2DiagnosticReportR4,
177
+ fhirVersion: fhirVersions.R4,
178
+ };
179
+
180
+ const onClick = 'test';
181
+ const { getByRole } = render(
182
+ <DiagnosticReport {...defaultProps} onClick={onClick} />,
183
+ );
184
+ const accordion = getByRole('button');
185
+ fireEvent.click(accordion);
186
+
187
+ const attribute = accordion.getAttribute('data-bs-toggle');
188
+ expect(attribute).toEqual('collapse');
189
+ });
155
190
  });
@@ -216,8 +216,13 @@ const Content = props => {
216
216
  );
217
217
  };
218
218
 
219
- const DocumentReference = props => {
220
- const { fhirVersion, fhirResource, fhirIcons } = props;
219
+ const DocumentReference = ({
220
+ fhirVersion,
221
+ fhirResource,
222
+ fhirIcons,
223
+ onClick,
224
+ rawOnClick,
225
+ }) => {
221
226
  let fhirResourceData = {};
222
227
  try {
223
228
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -337,6 +342,8 @@ const DocumentReference = props => {
337
342
  {hasContent && <Content content={content} />}
338
343
  </Body>
339
344
  }
345
+ onClick={onClick}
346
+ rawOnClick={rawOnClick}
340
347
  />
341
348
  </Root>
342
349
  );
@@ -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 fhirVersions from '../fhirResourceVersions';
5
5
  import DocumentReference from './DocumentReference';
@@ -10,37 +10,33 @@ import example1DocumentReferenceR4 from '../../../fixtures/r4/resources/document
10
10
  import fhirIcons from '../../../fixtures/example-icons';
11
11
  import DocumentReferenceIcon from '../../../assets/containers/DocumentReference/document-reference.svg';
12
12
 
13
- export default { title: 'Document Reference' };
13
+ export default {
14
+ title: 'DocumentReference',
15
+ component: DocumentReference,
16
+ argTypes: {
17
+ ...defaultArgTypes,
18
+ },
19
+ };
20
+
21
+ const Template = args => <DocumentReference {...args} />;
14
22
 
15
- export const DefaultVisualizationDSTU2 = () => {
16
- const fhirResource = object('Resource', exampleDocumentReference);
17
- return (
18
- <DocumentReference
19
- fhirResource={fhirResource}
20
- fhirVersion={fhirVersions.DSTU2}
21
- fhirIcons={require('../../../assets/containers/DocumentReference/document-reference.svg')}
22
- />
23
- );
23
+ export const DefaultVisualizationDSTU2 = Template.bind({});
24
+ DefaultVisualizationDSTU2.args = {
25
+ fhirVersion: fhirVersions.DSTU2,
26
+ fhirResource: exampleDocumentReference,
27
+ fhirIcons: require('../../../assets/containers/DocumentReference/document-reference.svg'),
24
28
  };
25
29
 
26
- export const ExampleSTU3 = () => {
27
- const fhirResource = object('Resource', exampleDocumentReferenceSTU3);
28
- return (
29
- <DocumentReference
30
- fhirResource={fhirResource}
31
- fhirVersion={fhirVersions.STU3}
32
- fhirIcons={DocumentReferenceIcon}
33
- />
34
- );
30
+ export const ExampleSTU3 = Template.bind({});
31
+ ExampleSTU3.args = {
32
+ fhirVersion: fhirVersions.STU3,
33
+ fhirResource: exampleDocumentReferenceSTU3,
34
+ fhirIcons: DocumentReferenceIcon,
35
35
  };
36
36
 
37
- export const ExampleR4 = () => {
38
- const fhirResource = object('Resource', example1DocumentReferenceR4);
39
- return (
40
- <DocumentReference
41
- fhirResource={fhirResource}
42
- fhirVersion={fhirVersions.R4}
43
- fhirIcons={fhirIcons}
44
- />
45
- );
37
+ export const ExampleR4 = Template.bind({});
38
+ ExampleR4.args = {
39
+ fhirVersion: fhirVersions.R4,
40
+ fhirResource: example1DocumentReferenceR4,
41
+ fhirIcons: fhirIcons,
46
42
  };
@@ -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 { nbspRegex } from '../../../testUtils';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -268,4 +268,45 @@ describe('should render the DocumentReference component properly', () => {
268
268
  const urls = getAllByTestId('content.url').map(node => node.textContent);
269
269
  expect(urls).toEqual(['Binary/07a6483f-732b-461e-86b6-edb665c45510']);
270
270
  });
271
+
272
+ it('should fire custom onClick function', () => {
273
+ const resource = JSON.parse(JSON.stringify(r4Example1));
274
+ resource.content[0].attachment.url =
275
+ 'http://example.org/xds/mhd/Binary/07a6483f-732b-461e-86b6-edb665c45510';
276
+
277
+ const onClick = jest.fn();
278
+ const { getByRole } = render(
279
+ <DocumentReference
280
+ fhirResource={resource}
281
+ fhirVersion={fhirVersions.R4}
282
+ onClick={onClick}
283
+ />,
284
+ );
285
+ const accordion = getByRole('button');
286
+ fireEvent.click(accordion);
287
+
288
+ const attribute = accordion.getAttribute('data-bs-toggle');
289
+ expect(attribute).not.toEqual('collapse');
290
+ expect(onClick).toHaveBeenCalled();
291
+ });
292
+
293
+ it('should not fire custom onClick function', () => {
294
+ const resource = JSON.parse(JSON.stringify(r4Example1));
295
+ resource.content[0].attachment.url =
296
+ 'http://example.org/xds/mhd/Binary/07a6483f-732b-461e-86b6-edb665c45510';
297
+
298
+ const onClick = 'test';
299
+ const { getByRole } = render(
300
+ <DocumentReference
301
+ fhirResource={resource}
302
+ fhirVersion={fhirVersions.R4}
303
+ onClick={onClick}
304
+ />,
305
+ );
306
+ const accordion = getByRole('button');
307
+ fireEvent.click(accordion);
308
+
309
+ const attribute = accordion.getAttribute('data-bs-toggle');
310
+ expect(attribute).toEqual('collapse');
311
+ });
271
312
  });
@@ -160,7 +160,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
160
160
  }
161
161
  };
162
162
 
163
- const Encounter = ({ fhirResource, fhirVersion, fhirIcons }) => {
163
+ const Encounter = ({
164
+ fhirResource,
165
+ fhirVersion,
166
+ fhirIcons,
167
+ onClick,
168
+ rawOnClick,
169
+ }) => {
164
170
  let fhirResourceData = {};
165
171
  try {
166
172
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -229,6 +235,8 @@ const Encounter = ({ fhirResource, fhirVersion, fhirIcons }) => {
229
235
  )}
230
236
  </Body>
231
237
  }
238
+ onClick={onClick}
239
+ rawOnClick={rawOnClick}
232
240
  />
233
241
  </Root>
234
242
  );
@@ -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 Encounter from './Encounter';
5
5
 
@@ -16,78 +16,62 @@ import EncounterIcon from '../../../assets/containers/Encounter/encounter.svg';
16
16
 
17
17
  export default {
18
18
  title: 'Encounter',
19
+ component: Encounter,
20
+ argTypes: {
21
+ ...defaultArgTypes,
22
+ },
19
23
  };
20
24
 
21
- export const DefaultVisualizationDSTU2 = () => {
22
- const fhirResource = object('Resource', example1);
23
- return (
24
- <Encounter
25
- fhirVersion={fhirVersions.DSTU2}
26
- fhirResource={fhirResource}
27
- fhirIcons={require('../../../assets/containers/Encounter/encounter.svg')}
28
- />
29
- );
25
+ const Template = args => <Encounter {...args} />;
26
+
27
+ export const DefaultVisualizationDSTU2 = Template.bind({});
28
+ DefaultVisualizationDSTU2.args = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: example1,
31
+ fhirIcons: require('../../../assets/containers/Encounter/encounter.svg'),
30
32
  };
31
33
 
32
- export const ExampleWithoutParticipantsDSTU2 = () => {
33
- const fhirResource = object('Resource', example2);
34
- return (
35
- <Encounter
36
- fhirVersion={fhirVersions.DSTU2}
37
- fhirResource={fhirResource}
38
- fhirIcons={EncounterIcon}
39
- />
40
- );
34
+ export const ExampleWithoutParticipantsDSTU2 = Template.bind({});
35
+ ExampleWithoutParticipantsDSTU2.args = {
36
+ fhirVersion: fhirVersions.DSTU2,
37
+ fhirResource: example2,
38
+ fhirIcons: EncounterIcon,
41
39
  };
42
40
 
43
- export const ExampleSTU3 = () => {
44
- const fhirResource = object('Resource', example_STU3);
45
- return (
46
- <Encounter
47
- fhirVersion={fhirVersions.STU3}
48
- fhirResource={fhirResource}
49
- fhirIcons={fhirIcons}
50
- />
51
- );
41
+ export const ExampleSTU3 = Template.bind({});
42
+ ExampleSTU3.args = {
43
+ fhirVersion: fhirVersions.STU3,
44
+ fhirResource: example_STU3,
45
+ fhirIcons: fhirIcons,
52
46
  };
53
47
 
54
- export const ExampleWithoutParticipantSTU3 = () => {
55
- const fhirResource = object('Resource', example2_STU3);
56
- return (
57
- <Encounter
58
- fhirVersion={fhirVersions.STU3}
59
- fhirResource={fhirResource}
60
- fhirIcons={false}
61
- />
62
- );
48
+ export const ExampleWithoutParticipantSTU3 = Template.bind({});
49
+ ExampleWithoutParticipantSTU3.args = {
50
+ fhirVersion: fhirVersions.STU3,
51
+ fhirResource: example2_STU3,
52
+ fhirIcons: false,
63
53
  };
64
54
 
65
- export const ExampleWithoutParticipantR4 = () => {
66
- const fhirResource = object('Resource', example1_R4);
67
- return (
68
- <Encounter
69
- fhirVersion={fhirVersions.R4}
70
- fhirResource={fhirResource}
71
- fhirIcons={'random text'}
72
- />
73
- );
55
+ export const ExampleWithoutParticipantR4 = Template.bind({});
56
+ ExampleWithoutParticipantR4.args = {
57
+ fhirVersion: fhirVersions.R4,
58
+ fhirResource: example1_R4,
59
+ fhirIcons: 'random text',
74
60
  };
75
61
 
76
- export const Example2ofR4 = () => {
77
- const fhirResource = object('Resource', example2_R4);
78
- return (
79
- <Encounter fhirVersion={fhirVersions.R4} fhirResource={fhirResource} />
80
- );
62
+ export const Example2ofR4 = Template.bind({});
63
+ Example2ofR4.args = {
64
+ fhirVersion: fhirVersions.R4,
65
+ fhirResource: example2_R4,
81
66
  };
82
67
 
83
- export const Example3ofR4 = () => {
84
- const fhirResource = object('Resource', example3_R4);
85
- return (
86
- <Encounter fhirVersion={fhirVersions.R4} fhirResource={fhirResource} />
87
- );
68
+ export const Example3ofR4 = Template.bind({});
69
+ Example3ofR4.args = {
70
+ fhirVersion: fhirVersions.R4,
71
+ fhirResource: example3_R4,
88
72
  };
89
73
 
90
- export const ExampleWithoutFHIRVersionProperty = () => {
91
- const fhirResource = object('Resource', example2_STU3);
92
- return <Encounter fhirResource={fhirResource} />;
74
+ export const ExampleWithoutFHIRVersionProperty = Template.bind({});
75
+ ExampleWithoutFHIRVersionProperty.args = {
76
+ fhirResource: example2_STU3,
93
77
  };