fhir-react 0.3.6 → 0.3.9

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 (160) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.stylelintrc +6 -2
  4. package/README.md +19 -1
  5. package/build/index.js +15 -11
  6. package/build/style.css +11 -10
  7. package/package.json +55 -54
  8. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  9. package/src/assets/containers/Coverage/coverage.svg +4 -0
  10. package/src/assets/containers/Generic/generic.svg +3 -0
  11. package/src/assets/containers/Medication/medication.svg +5 -0
  12. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  13. package/src/assets/containers/Organization/organization.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/ResourceContainer/ResourceContainer.css +4 -0
  19. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  20. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +23 -1
  21. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  22. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  23. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  24. package/src/components/datatypes/Coding/Coding.js +7 -3
  25. package/src/components/datatypes/Identifier/Identifier.js +7 -3
  26. package/src/components/datatypes/Reference/Reference.js +7 -1
  27. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  28. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  29. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  30. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  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.test.js +36 -1
  35. package/src/components/resources/Binary/Binary.js +2 -1
  36. package/src/components/resources/Bundle/Bundle.css +7 -0
  37. package/src/components/resources/Bundle/Bundle.js +15 -11
  38. package/src/components/resources/Bundle/Bundle.stories.js +12 -78
  39. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  40. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  41. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  42. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  43. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  44. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  45. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  46. package/src/components/resources/Claim/CareTeam.js +55 -0
  47. package/src/components/resources/Claim/Claim.css +2 -11
  48. package/src/components/resources/Claim/Claim.js +165 -309
  49. package/src/components/resources/Claim/Claim.stories.js +37 -5
  50. package/src/components/resources/Claim/Claim.test.js +104 -1
  51. package/src/components/resources/Claim/Diagnosis.js +61 -0
  52. package/src/components/resources/Claim/Insurance.js +58 -0
  53. package/src/components/resources/Claim/Item.js +79 -0
  54. package/src/components/resources/Claim/Items.js +29 -0
  55. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  56. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  57. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  58. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  59. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  60. package/src/components/resources/ClaimResponse/Item.js +44 -9
  61. package/src/components/resources/ClaimResponse/Items.js +5 -4
  62. package/src/components/resources/Condition/Condition.js +10 -3
  63. package/src/components/resources/Condition/Condition.test.js +37 -4
  64. package/src/components/resources/Coverage/Coverage.js +104 -69
  65. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  66. package/src/components/resources/Coverage/Coverage.test.js +111 -4
  67. package/src/components/resources/Device/Device.js +9 -1
  68. package/src/components/resources/Device/Device.test.js +36 -1
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  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.test.js +42 -1
  73. package/src/components/resources/Encounter/Encounter.js +9 -1
  74. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  75. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  76. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  77. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  78. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  79. package/src/components/resources/Generic/Generic.js +21 -7
  80. package/src/components/resources/Generic/Generic.stories.js +2 -1
  81. package/src/components/resources/Generic/Generic.test.js +26 -7
  82. package/src/components/resources/Goal/Goal.js +9 -3
  83. package/src/components/resources/Goal/Goal.test.js +32 -1
  84. package/src/components/resources/Immunization/Immunization.js +9 -2
  85. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  86. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  87. package/src/components/resources/List/Entries.js +3 -3
  88. package/src/components/resources/List/List.js +137 -88
  89. package/src/components/resources/List/List.stories.js +38 -5
  90. package/src/components/resources/List/List.test.js +105 -1
  91. package/src/components/resources/Location/Location.js +66 -47
  92. package/src/components/resources/Location/Location.stories.js +11 -4
  93. package/src/components/resources/Location/Location.test.js +106 -4
  94. package/src/components/resources/Medication/Medication.js +98 -51
  95. package/src/components/resources/Medication/Medication.stories.js +37 -7
  96. package/src/components/resources/Medication/Medication.test.js +114 -5
  97. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  98. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  99. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  100. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  101. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  102. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  103. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  104. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  105. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  106. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  107. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  108. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  109. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  110. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  111. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  112. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  113. package/src/components/resources/Observation/Observation.js +3 -1
  114. package/src/components/resources/Observation/Observation.test.js +30 -1
  115. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  116. package/src/components/resources/Organization/Organization.js +63 -37
  117. package/src/components/resources/Organization/Organization.stories.js +15 -2
  118. package/src/components/resources/Organization/Organization.test.js +109 -1
  119. package/src/components/resources/Patient/Patient.js +4 -0
  120. package/src/components/resources/Patient/Patient.test.js +31 -2
  121. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  122. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  123. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  124. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  125. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  126. package/src/components/resources/Procedure/Procedure.js +3 -2
  127. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  128. package/src/components/resources/Questionnaire/Group.js +53 -0
  129. package/src/components/resources/Questionnaire/Items.js +45 -0
  130. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  131. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  132. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  133. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  134. package/src/components/resources/Questionnaire/Questions.js +40 -0
  135. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  136. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  137. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  138. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  139. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  140. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  141. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  142. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  143. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  144. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  145. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  146. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  147. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  148. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  149. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  150. package/src/components/resources/RelatedPerson/index.js +3 -0
  151. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  152. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  153. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  154. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  155. package/src/components/ui/index.js +56 -32
  156. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  157. package/src/fixtures/example-icons.jsx +63 -0
  158. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  159. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  160. package/src/style.scss +14 -1
@@ -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 Coverage from './Coverage';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -8,8 +8,80 @@ import exampleCoverage from '../../../fixtures/dstu2/resources/coverage/example1
8
8
  import exampleCoverageStu3 from '../../../fixtures/stu3/resources/coverage/example1.json';
9
9
  import example2CoverageStu3 from '../../../fixtures/stu3/resources/coverage/example2.json';
10
10
  import exampleCoverageR4 from '../../../fixtures/r4/resources/coverage/example1.json';
11
+ import fhirIcons from '../../../fixtures/example-icons';
11
12
 
12
13
  describe('should render component correctly', () => {
14
+ it('component without a fhirIcons props should render a default icon', () => {
15
+ const defaultProps = {
16
+ fhirVersion: fhirVersions.DSTU2,
17
+ fhirResource: exampleCoverage,
18
+ };
19
+
20
+ const { getByAltText } = render(<Coverage {...defaultProps} />);
21
+ const headerIcon = getByAltText('coverage');
22
+
23
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
24
+ });
25
+
26
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
27
+ const defaultProps = {
28
+ fhirVersion: fhirVersions.DSTU2,
29
+ fhirResource: exampleCoverage,
30
+ fhirIcons: false,
31
+ };
32
+
33
+ const { getByTestId } = render(<Coverage {...defaultProps} />);
34
+ const headerIcon = getByTestId('placeholder');
35
+
36
+ expect(headerIcon).toBeTruthy();
37
+ });
38
+
39
+ it('component with the img as a fhirIcons props should render an img', () => {
40
+ const defaultProps = {
41
+ fhirVersion: fhirVersions.DSTU2,
42
+ fhirResource: exampleCoverage,
43
+ fhirIcons: (
44
+ <img
45
+ src={require('../assets/containers/Coverage/coverage.svg')}
46
+ alt="coverage"
47
+ />
48
+ ),
49
+ };
50
+
51
+ const { getByAltText } = render(<Coverage {...defaultProps} />);
52
+ const headerIcon = getByAltText('coverage');
53
+
54
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
55
+ });
56
+
57
+ it('component with the resources object as a fhirIcons props should render an img', () => {
58
+ const defaultProps = {
59
+ fhirVersion: fhirVersions.DSTU2,
60
+ fhirResource: exampleCoverage,
61
+ fhirIcons: fhirIcons,
62
+ };
63
+
64
+ const { getByAltText } = render(<Coverage {...defaultProps} />);
65
+ const headerIcon = getByAltText('coverage');
66
+
67
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
68
+ });
69
+
70
+ it('component with the url as a fhirIcons props should render an img', () => {
71
+ const avatarSrc =
72
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
73
+ const defaultProps = {
74
+ fhirVersion: fhirVersions.DSTU2,
75
+ fhirResource: exampleCoverage,
76
+ fhirIcons: avatarSrc,
77
+ };
78
+
79
+ const { getByAltText } = render(<Coverage {...defaultProps} />);
80
+ const headerIcon = getByAltText('header icon');
81
+
82
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
83
+ });
84
+
13
85
  it('should render with DSTU2 source data', () => {
14
86
  const defaultProps = {
15
87
  fhirResource: exampleCoverage,
@@ -18,7 +90,7 @@ describe('should render component correctly', () => {
18
90
  const { getByTestId } = render(<Coverage {...defaultProps} />);
19
91
 
20
92
  expect(getByTestId('title').textContent.replace(nbspRegex, ' ')).toContain(
21
- 'Coverage Identifier: 12345',
93
+ 'Coverage',
22
94
  );
23
95
  expect(getByTestId('issuer').textContent).toContain('Organization/2');
24
96
  expect(getByTestId('planId').textContent).toContain('CBI35');
@@ -35,7 +107,7 @@ describe('should render component correctly', () => {
35
107
  const { getByTestId } = render(<Coverage {...defaultProps} />);
36
108
 
37
109
  expect(getByTestId('title').textContent.replace(nbspRegex, ' ')).toContain(
38
- 'Coverage Identifier: 12345',
110
+ 'Coverage',
39
111
  );
40
112
  expect(getByTestId('issuer').textContent).toContain('Organization/2');
41
113
  expect(getByTestId('planId').textContent).toContain('B37FC');
@@ -70,7 +142,7 @@ describe('should render component correctly', () => {
70
142
  );
71
143
 
72
144
  expect(getByTestId('title').textContent.replace(nbspRegex, ' ')).toContain(
73
- 'Coverage Identifier: 12345',
145
+ 'Coverage',
74
146
  );
75
147
  expect(getByTestId('issuer').textContent).toContain('Organization/2');
76
148
  expect(queryAllByTestId('planId').length).toEqual(0);
@@ -79,4 +151,39 @@ describe('should render component correctly', () => {
79
151
  expect(getByTestId('type').textContent).toContain('extended healthcare');
80
152
  expect(queryAllByTestId('details').length).toEqual(0);
81
153
  });
154
+
155
+ it('should fire custom onClick function', () => {
156
+ const defaultProps = {
157
+ fhirResource: exampleCoverageR4,
158
+ fhirVersion: fhirVersions.R4,
159
+ };
160
+
161
+ const onClick = jest.fn();
162
+ const { getByRole } = render(
163
+ <Coverage {...defaultProps} onClick={onClick} />,
164
+ );
165
+ const accordion = getByRole('button');
166
+ fireEvent.click(accordion);
167
+
168
+ const attribute = accordion.getAttribute('data-bs-toggle');
169
+ expect(attribute).not.toEqual('collapse');
170
+ expect(onClick).toHaveBeenCalled();
171
+ });
172
+
173
+ it('should not fire custom onClick function', () => {
174
+ const defaultProps = {
175
+ fhirResource: exampleCoverageR4,
176
+ fhirVersion: fhirVersions.R4,
177
+ };
178
+
179
+ const onClick = 'test';
180
+ const { getByRole } = render(
181
+ <Coverage {...defaultProps} onClick={onClick} />,
182
+ );
183
+ const accordion = getByRole('button');
184
+ fireEvent.click(accordion);
185
+
186
+ const attribute = accordion.getAttribute('data-bs-toggle');
187
+ expect(attribute).toEqual('collapse');
188
+ });
82
189
  });
@@ -102,7 +102,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
102
102
  }
103
103
  };
104
104
 
105
- const Device = ({ fhirResource, fhirVersion, fhirIcons }) => {
105
+ const Device = ({
106
+ fhirResource,
107
+ fhirVersion,
108
+ fhirIcons,
109
+ onClick,
110
+ rawOnClick,
111
+ }) => {
106
112
  let fhirResourceData = {};
107
113
  try {
108
114
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -178,6 +184,8 @@ const Device = ({ fhirResource, fhirVersion, fhirIcons }) => {
178
184
  ))}
179
185
  </Body>
180
186
  }
187
+ onClick={onClick}
188
+ rawOnClick={rawOnClick}
181
189
  />
182
190
  </Root>
183
191
  );
@@ -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 { 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 { 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 { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import Encounter from './Encounter';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
  import example1 from '../../../fixtures/dstu2/resources/encounter/example.json';
@@ -198,4 +198,39 @@ describe('should render component correctly', () => {
198
198
  );
199
199
  jest.restoreAllMocks();
200
200
  });
201
+
202
+ it('should fire custom onClick function', () => {
203
+ const defaultProps = {
204
+ fhirResource: example2_STU3,
205
+ fhirVersion: fhirVersions.R4,
206
+ };
207
+
208
+ const onClick = jest.fn();
209
+ const { getByRole } = render(
210
+ <Encounter {...defaultProps} onClick={onClick} />,
211
+ );
212
+ const accordion = getByRole('button');
213
+ fireEvent.click(accordion);
214
+
215
+ const attribute = accordion.getAttribute('data-bs-toggle');
216
+ expect(attribute).not.toEqual('collapse');
217
+ expect(onClick).toHaveBeenCalled();
218
+ });
219
+
220
+ it('should not fire custom onClick function', () => {
221
+ const defaultProps = {
222
+ fhirResource: example2_STU3,
223
+ fhirVersion: fhirVersions.R4,
224
+ };
225
+
226
+ const onClick = 'test';
227
+ const { getByRole } = render(
228
+ <Encounter {...defaultProps} onClick={onClick} />,
229
+ );
230
+ const accordion = getByRole('button');
231
+ fireEvent.click(accordion);
232
+
233
+ const attribute = accordion.getAttribute('data-bs-toggle');
234
+ expect(attribute).toEqual('collapse');
235
+ });
201
236
  });
@@ -233,6 +233,8 @@ const ExplanationOfBenefit = ({
233
233
  fhirVersion,
234
234
  withCarinBBProfile = false,
235
235
  fhirIcons,
236
+ onClick,
237
+ rawOnClick,
236
238
  }) => {
237
239
  let fhirResourceData = {};
238
240
  try {
@@ -546,6 +548,8 @@ const ExplanationOfBenefit = ({
546
548
  {hasCareTeam && <CareTeam fhirData={careTeam} />}
547
549
  </Body>
548
550
  }
551
+ onClick={onClick}
552
+ rawOnClick={rawOnClick}
549
553
  />
550
554
  </Root>
551
555
  );
@@ -8,7 +8,7 @@ import exampleC4BB from '../../../fixtures/r4/resources/explanationOfBenefit/c4b
8
8
  import exampleC4BBExtendedDiagnosis from '../../../fixtures/r4/resources/explanationOfBenefit/c4bbExtendedDiagnosis.json';
9
9
  import fhirVersions from '../fhirResourceVersions';
10
10
  import { nbspRegex } from '../../../testUtils';
11
- import { render } from '@testing-library/react';
11
+ import { fireEvent, render } from '@testing-library/react';
12
12
  import fhirIcons from '../../../fixtures/example-icons';
13
13
 
14
14
  describe('should render ExplanationOfBenefit component properly', () => {
@@ -331,4 +331,41 @@ describe('should render ExplanationOfBenefit component properly', () => {
331
331
  expect(getByTestId('diagnosisOnAdmission').textContent).toContain('?');
332
332
  expect(queryByTestId('diagnosisPackageCode')).toBeNull();
333
333
  });
334
+
335
+ it('should fire custom onClick function', () => {
336
+ const defaultProps = {
337
+ fhirResource: exampleC4BBExtendedDiagnosis,
338
+ fhirVersion: fhirVersions.R4,
339
+ withCarinBBProfile: true,
340
+ };
341
+
342
+ const onClick = jest.fn();
343
+ const { getByRole } = render(
344
+ <ExplanationOfBenefit {...defaultProps} onClick={onClick} />,
345
+ );
346
+ const accordion = getByRole('button');
347
+ fireEvent.click(accordion);
348
+
349
+ const attribute = accordion.getAttribute('data-bs-toggle');
350
+ expect(attribute).not.toEqual('collapse');
351
+ expect(onClick).toHaveBeenCalled();
352
+ });
353
+
354
+ it('should not fire custom onClick function', () => {
355
+ const defaultProps = {
356
+ fhirResource: exampleC4BBExtendedDiagnosis,
357
+ fhirVersion: fhirVersions.R4,
358
+ withCarinBBProfile: true,
359
+ };
360
+
361
+ const onClick = 'test';
362
+ const { getByRole } = render(
363
+ <ExplanationOfBenefit {...defaultProps} onClick={onClick} />,
364
+ );
365
+ const accordion = getByRole('button');
366
+ fireEvent.click(accordion);
367
+
368
+ const attribute = accordion.getAttribute('data-bs-toggle');
369
+ expect(attribute).toEqual('collapse');
370
+ });
334
371
  });
@@ -70,8 +70,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
70
70
  }
71
71
  };
72
72
 
73
- const FamilyMemberHistory = props => {
74
- const { fhirResource, fhirVersion, fhirIcons } = props;
73
+ const FamilyMemberHistory = ({
74
+ fhirResource,
75
+ fhirVersion,
76
+ fhirIcons,
77
+ onClick,
78
+ rawOnClick,
79
+ }) => {
75
80
  let fhirResourceData = {};
76
81
  try {
77
82
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -135,6 +140,8 @@ const FamilyMemberHistory = props => {
135
140
  />
136
141
  }
137
142
  bodyContent={<Body tableData={tableData} />}
143
+ onClick={onClick}
144
+ rawOnClick={rawOnClick}
138
145
  />
139
146
  </Root>
140
147
  );
@@ -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 FamilyMemberHistory from './FamilyMemberHistory';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -110,4 +110,39 @@ describe('should render FamilyMemberHistory component correctly', () => {
110
110
  expect(getByTestId('hasRelationship').textContent).toContain('father');
111
111
  expect(getByTestId('noteText').textContent).toContain('Was fishing at');
112
112
  });
113
+
114
+ it('should fire custom onClick function', () => {
115
+ const defaultProps = {
116
+ fhirResource: example1STU3,
117
+ fhirVersion: fhirVersions.STU3,
118
+ };
119
+
120
+ const onClick = jest.fn();
121
+ const { getByRole } = render(
122
+ <FamilyMemberHistory {...defaultProps} onClick={onClick} />,
123
+ );
124
+ const accordion = getByRole('button');
125
+ fireEvent.click(accordion);
126
+
127
+ const attribute = accordion.getAttribute('data-bs-toggle');
128
+ expect(attribute).not.toEqual('collapse');
129
+ expect(onClick).toHaveBeenCalled();
130
+ });
131
+
132
+ it('should not fire custom onClick function', () => {
133
+ const defaultProps = {
134
+ fhirResource: example1STU3,
135
+ fhirVersion: fhirVersions.STU3,
136
+ };
137
+
138
+ const onClick = 'test';
139
+ const { getByRole } = render(
140
+ <FamilyMemberHistory {...defaultProps} onClick={onClick} />,
141
+ );
142
+ const accordion = getByRole('button');
143
+ fireEvent.click(accordion);
144
+
145
+ const attribute = accordion.getAttribute('data-bs-toggle');
146
+ expect(attribute).toEqual('collapse');
147
+ });
113
148
  });
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import _get from 'lodash/get';
3
3
 
4
- import { Root, Header, Title, Body } from '../../ui';
4
+ import { Root, Header } from '../../ui';
5
+ import Accordion from '../../containers/Accordion';
5
6
 
6
- const Generic = props => {
7
- const { fhirResource } = props;
7
+ const Generic = ({ fhirResource, fhirIcons, onClick, rawOnClick }) => {
8
8
  const title = fhirResource
9
9
  ? `${fhirResource.resourceType}/${fhirResource.id}`
10
10
  : `Unknown Resource`;
@@ -14,10 +14,24 @@ const Generic = props => {
14
14
 
15
15
  return (
16
16
  <Root>
17
- <Header>
18
- <Title>{title}</Title>
19
- </Header>
20
- {code && <Body>{code && <p>{code}</p>}</Body>}
17
+ <Accordion
18
+ headerContent={
19
+ <Header
20
+ resourceName={'Generic'}
21
+ title={title}
22
+ icon={fhirIcons}
23
+ additionalContent={
24
+ code && (
25
+ <span className="text-secondary" data-testid="code">
26
+ {code}
27
+ </span>
28
+ )
29
+ }
30
+ />
31
+ }
32
+ onClick={onClick}
33
+ rawOnClick={rawOnClick}
34
+ />
21
35
  </Root>
22
36
  );
23
37
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { object } from '@storybook/addon-knobs';
3
3
 
4
4
  import Generic from './Generic';
5
+ import fhirIcons from '../../../fixtures/example-icons';
5
6
 
6
7
  export default { title: 'Generic' };
7
8
 
@@ -14,5 +15,5 @@ export const DefaultVisualization = () => {
14
15
  },
15
16
  };
16
17
  const fhirResource = object('Resource', exampleResource);
17
- return <Generic fhirResource={fhirResource} />;
18
+ return <Generic fhirResource={fhirResource} fhirIcons={fhirIcons} />;
18
19
  };