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
@@ -0,0 +1,156 @@
1
+ import React from 'react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
+ import RelatedPerson from './RelatedPerson';
4
+ import fhirVersions from '../fhirResourceVersions';
5
+
6
+ import example1 from '../../../fixtures/dstu2/resources/relatedPerson/example1.json';
7
+ import example2 from '../../../fixtures/stu3/resources/relatedPerson/example1.json';
8
+ import example3 from '../../../fixtures/r4/resources/relatedPerson/example1.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
10
+
11
+ describe('should render component correctly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirResource: example1,
15
+ fhirVersion: fhirVersions.DSTU2,
16
+ };
17
+
18
+ const { getByAltText } = render(<RelatedPerson {...defaultProps} />);
19
+ const headerIcon = getByAltText('related person');
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
+ fhirResource: example1,
27
+ fhirVersion: fhirVersions.DSTU2,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<RelatedPerson {...defaultProps} />);
32
+ const headerIcon = getByTestId('placeholder');
33
+
34
+ expect(headerIcon).toBeTruthy();
35
+ });
36
+
37
+ it('component with the img as a fhirIcons props should render an img', () => {
38
+ const defaultProps = {
39
+ fhirResource: example1,
40
+ fhirVersion: fhirVersions.DSTU2,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/RelatedPerson/related-person.svg')}
44
+ alt="related person"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<RelatedPerson {...defaultProps} />);
50
+ const headerIcon = getByAltText('related person');
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
+ fhirResource: example1,
58
+ fhirVersion: fhirVersions.DSTU2,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<RelatedPerson {...defaultProps} />);
63
+ const headerIcon = getByAltText('related person');
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
+ fhirResource: example1,
73
+ fhirVersion: fhirVersions.DSTU2,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<RelatedPerson {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
83
+ it('should render with DSTU2 source data', () => {
84
+ const defaultProps = {
85
+ fhirResource: example1,
86
+ fhirVersion: fhirVersions.DSTU2,
87
+ };
88
+ const { getByTestId } = render(<RelatedPerson {...defaultProps} />);
89
+
90
+ expect(getByTestId('gender').textContent).toEqual('female');
91
+ expect(getByTestId('address').textContent).toEqual(
92
+ '43, Place du Marché Sainte CatherineParis, 75004 FRA',
93
+ );
94
+ expect(getByTestId('telephone').textContent).toEqual('+33 (237) 998327');
95
+ });
96
+
97
+ it('should render with STU3 source data', () => {
98
+ const defaultProps = {
99
+ fhirResource: example2,
100
+ fhirVersion: fhirVersions.STU3,
101
+ };
102
+ const { getByTestId } = render(<RelatedPerson {...defaultProps} />);
103
+
104
+ expect(getByTestId('gender').textContent).toEqual('female');
105
+ expect(getByTestId('birthDate').textContent).toEqual('1963');
106
+ expect(getByTestId('telephone').textContent).toEqual('+31201234567');
107
+ });
108
+
109
+ it('should render with R4 source data', () => {
110
+ const defaultProps = {
111
+ fhirResource: example3,
112
+ fhirVersion: fhirVersions.R4,
113
+ };
114
+ const { getByTestId } = render(<RelatedPerson {...defaultProps} />);
115
+
116
+ expect(getByTestId('gender').textContent).toEqual('female');
117
+ expect(getByTestId('birthDate').textContent).toEqual('1973-05-31');
118
+ expect(getByTestId('address').textContent).toEqual('2222 Home Street ');
119
+ expect(getByTestId('telephone').textContent).toEqual('555-555-2003');
120
+ });
121
+
122
+ it('should fire custom onClick function', () => {
123
+ const defaultProps = {
124
+ fhirResource: example3,
125
+ fhirVersion: fhirVersions.R4,
126
+ };
127
+
128
+ const onClick = jest.fn();
129
+ const { getByRole } = render(
130
+ <RelatedPerson {...defaultProps} onClick={onClick} />,
131
+ );
132
+ const accordion = getByRole('button');
133
+ fireEvent.click(accordion);
134
+
135
+ const attribute = accordion.getAttribute('data-bs-toggle');
136
+ expect(attribute).not.toEqual('collapse');
137
+ expect(onClick).toHaveBeenCalled();
138
+ });
139
+
140
+ it('should not fire custom onClick function', () => {
141
+ const defaultProps = {
142
+ fhirResource: example3,
143
+ fhirVersion: fhirVersions.R4,
144
+ };
145
+
146
+ const onClick = 'test';
147
+ const { getByRole } = render(
148
+ <RelatedPerson {...defaultProps} onClick={onClick} />,
149
+ );
150
+ const accordion = getByRole('button');
151
+ fireEvent.click(accordion);
152
+
153
+ const attribute = accordion.getAttribute('data-bs-toggle');
154
+ expect(attribute).toEqual('collapse');
155
+ });
156
+ });
@@ -0,0 +1,3 @@
1
+ import RelatedPerson from './RelatedPerson';
2
+
3
+ export default RelatedPerson;
@@ -13,16 +13,8 @@ import _get from 'lodash/get';
13
13
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
14
14
  import fhirVersions from '../fhirResourceVersions';
15
15
 
16
- import {
17
- Badge,
18
- BadgeSecondary,
19
- Body,
20
- Header,
21
- MissingValue,
22
- Root,
23
- Title,
24
- Value,
25
- } from '../../ui';
16
+ import { Badge, Body, Header, MissingValue, Root, Value } from '../../ui';
17
+ import Accordion from '../../containers/Accordion';
26
18
 
27
19
  const commonDTO = fhirResource => {
28
20
  const title = _get(fhirResource, 'title', 'Research Study');
@@ -102,8 +94,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
102
94
  }
103
95
  };
104
96
 
105
- const ResearchStudy = props => {
106
- const { fhirResource, fhirVersion } = props;
97
+ const ResearchStudy = ({
98
+ fhirResource,
99
+ fhirVersion,
100
+ fhirIcons,
101
+ onClick,
102
+ rawOnClick,
103
+ }) => {
107
104
  let fhirResourceData = {};
108
105
  try {
109
106
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -140,126 +137,166 @@ const ResearchStudy = props => {
140
137
  const hasComments = comments.length > 0;
141
138
  const hasArms = arms.length > 0;
142
139
 
140
+ const tableData = [
141
+ {
142
+ label: 'Part of another study',
143
+ testId: 'partOf',
144
+ data: partOfReference && <Reference fhirData={partOfReference} />,
145
+ status: partOfReference,
146
+ },
147
+ {
148
+ label: 'Category',
149
+ testId: 'category',
150
+ data: categoryCoding && <Coding fhirData={categoryCoding} />,
151
+ status: categoryCoding,
152
+ },
153
+ {
154
+ label: 'Keywords',
155
+ testId: 'keywords',
156
+ data: hasKeywords && <CodeableConcept fhirData={keywordConcepts} />,
157
+ status: hasKeywords,
158
+ },
159
+ {
160
+ label: 'Description',
161
+ testId: 'description',
162
+ data: description && <Markdown fhirData={description} />,
163
+ status: description,
164
+ },
165
+ {
166
+ label: 'Focus',
167
+ testId: 'focus',
168
+ data: focusCoding && <Coding fhirData={focusCoding} />,
169
+ status: focusCoding,
170
+ },
171
+ {
172
+ label: 'Enrollment',
173
+ testId: 'enrollment',
174
+ data:
175
+ hasEnrollment &&
176
+ enrollmentReferences.map((enrollmentReference, idx) => (
177
+ <div key={idx} data-testid="enrollmentReference">
178
+ <Reference fhirData={enrollmentReference} />
179
+ </div>
180
+ )),
181
+ status: hasEnrollment,
182
+ },
183
+ {
184
+ label: 'Protocol',
185
+ testId: 'protocol',
186
+ data: protocolReference && <Reference fhirData={protocolReference} />,
187
+ status: protocolReference,
188
+ },
189
+ {
190
+ label: 'Study paths',
191
+ testId: 'arms',
192
+ data: hasArms && (
193
+ <ul>
194
+ {arms.map((arm, idx) => (
195
+ <li key={idx}>
196
+ <div data-testid="arms.name">{arm.name}</div>
197
+ <Coding fhirData={arm.coding} />
198
+ <div data-testid="arms.description">{arm.description}</div>
199
+ </li>
200
+ ))}
201
+ </ul>
202
+ ),
203
+ status: hasArms,
204
+ },
205
+ {
206
+ label: 'Comments',
207
+ testId: 'comments',
208
+ data: hasComments && <Annotation fhirData={comments} />,
209
+ status: hasComments,
210
+ },
211
+ {
212
+ label: 'Contacts',
213
+ testId: 'contacts',
214
+ data:
215
+ hasContacts &&
216
+ contacts.map((contact, idx) => (
217
+ <div key={idx}>
218
+ <div data-testid="contactsName">{contact.name}</div>
219
+ <div data-testid="contactsTelecom">
220
+ <Telecom fhirData={contact.telecoms} />
221
+ </div>
222
+ </div>
223
+ )),
224
+ status: hasContacts,
225
+ },
226
+ {
227
+ label: 'Principal investigator',
228
+ testId: 'principalInvestigator',
229
+ data: principalInvestigatorReference && (
230
+ <Reference fhirData={principalInvestigatorReference} />
231
+ ),
232
+ status: principalInvestigatorReference,
233
+ },
234
+ {
235
+ label: 'Sponsor',
236
+ testId: 'sponsor',
237
+ data: sponsorReference && <Reference fhirData={sponsorReference} />,
238
+ status: sponsorReference,
239
+ },
240
+ {
241
+ label: 'Sites',
242
+ testId: 'sites',
243
+ data:
244
+ hasSites &&
245
+ siteReferences.map((siteReference, idx) => (
246
+ <div key={idx} data-testid="siteReference">
247
+ <Reference fhirData={siteReference} />
248
+ </div>
249
+ )),
250
+ status: hasSites,
251
+ },
252
+ {
253
+ label: 'Location',
254
+ testId: 'location',
255
+ data: location && <CodeableConcept fhirData={location} />,
256
+ status: location,
257
+ },
258
+ {
259
+ label: 'Primary Purpose Type',
260
+ testId: 'primaryPurposeType',
261
+ data: primaryPurposeType && (
262
+ <CodeableConcept fhirData={primaryPurposeType} />
263
+ ),
264
+ status: primaryPurposeType,
265
+ },
266
+ ];
267
+
143
268
  return (
144
269
  <Root name="ResearchStudy">
145
- <Header>
146
- {title && <Title data-testid="title">{title}</Title>}
147
- {status && <Badge data-testid="status">{status}</Badge>}
148
- {hasPeriod && (
149
- <BadgeSecondary data-testid="period">
150
- {period.start ? (
151
- <DateType fhirData={period.start} />
152
- ) : (
153
- <MissingValue />
154
- )}
155
- {' - '}
156
- {period.end ? <DateType fhirData={period.end} /> : <MissingValue />}
157
- </BadgeSecondary>
158
- )}
159
- </Header>
160
- <Body>
161
- {partOfReference && (
162
- <Value label="Part of another study" data-testid="partOf">
163
- <Reference fhirData={partOfReference} />
164
- </Value>
165
- )}
166
- {categoryCoding && (
167
- <Value label="Category" data-testid="category">
168
- <Coding fhirData={categoryCoding} />
169
- </Value>
170
- )}
171
- {hasKeywords && (
172
- <Value label="Keywords" data-testid="keywords">
173
- <CodeableConcept fhirData={keywordConcepts} />
174
- </Value>
175
- )}
176
- {description && (
177
- <Value label="Description" data-testid="description">
178
- <Markdown fhirData={description} />
179
- </Value>
180
- )}
181
- {focusCoding && (
182
- <Value label="Focus" data-testid="focus">
183
- <Coding fhirData={focusCoding} />
184
- </Value>
185
- )}
186
- {hasEnrollment && (
187
- <Value label="Enrollment" data-testid="enrollment">
188
- {enrollmentReferences.map((enrollmentReference, idx) => (
189
- <div key={idx} data-testid="enrollmentReference">
190
- <Reference fhirData={enrollmentReference} />
191
- </div>
192
- ))}
193
- </Value>
194
- )}
195
- {protocolReference && (
196
- <Value label="Protocol" data-testid="protocol">
197
- <Reference fhirData={protocolReference} />
198
- </Value>
199
- )}
200
- {hasArms && (
201
- <Value label="Study paths" data-testid="arms">
202
- <ul>
203
- {arms.map((arm, idx) => (
204
- <li key={idx}>
205
- <div data-testid="arms.name">{arm.name}</div>
206
- <Coding fhirData={arm.coding} />
207
- <div data-testid="arms.description">{arm.description}</div>
208
- </li>
209
- ))}
210
- </ul>
211
- </Value>
212
- )}
213
- {hasComments && (
214
- <Value label="Comments" data-testid="comments">
215
- <Annotation fhirData={comments} />
216
- </Value>
217
- )}
218
- {hasContacts && (
219
- <Value label="Contacts" data-testid="contacts">
220
- {contacts.map((contact, idx) => (
221
- <div key={idx}>
222
- <div data-testid="contactsName">{contact.name}</div>
223
- <div data-testid="contactsTelecom">
224
- <Telecom fhirData={contact.telecoms} />
225
- </div>
226
- </div>
227
- ))}
228
- </Value>
229
- )}
230
- {principalInvestigatorReference && (
231
- <Value
232
- label="Principal investigator"
233
- data-testid="principalInvestigator"
234
- >
235
- <Reference fhirData={principalInvestigatorReference} />
236
- </Value>
237
- )}
238
- {sponsorReference && (
239
- <Value label="Sponsor" data-testid="sponsor">
240
- <Reference fhirData={sponsorReference} />
241
- </Value>
242
- )}
243
- {hasSites && (
244
- <Value label="Sites" data-testid="sites">
245
- {siteReferences.map((siteReference, idx) => (
246
- <div key={idx} data-testid="siteReference">
247
- <Reference fhirData={siteReference} />
248
- </div>
249
- ))}
250
- </Value>
251
- )}
252
- {location && (
253
- <Value label="Location" data-testid="location">
254
- <CodeableConcept fhirData={location} />
255
- </Value>
256
- )}
257
- {primaryPurposeType && (
258
- <Value label="Primary Purpose Type" data-testid="primaryPurposeType">
259
- <CodeableConcept fhirData={primaryPurposeType} />
260
- </Value>
261
- )}
262
- </Body>
270
+ <Accordion
271
+ headerContent={
272
+ <Header
273
+ resourceName="ResearchStudy"
274
+ title={title}
275
+ badges={status && <Badge data-testid="status">{status}</Badge>}
276
+ additionalContent={
277
+ hasPeriod && (
278
+ <Value data-testid="period">
279
+ {period.start ? (
280
+ <DateType fhirData={period.start} isBlack />
281
+ ) : (
282
+ <MissingValue />
283
+ )}
284
+ {' - '}
285
+ {period.end ? (
286
+ <DateType fhirData={period.end} isBlack />
287
+ ) : (
288
+ <MissingValue />
289
+ )}
290
+ </Value>
291
+ )
292
+ }
293
+ icon={fhirIcons}
294
+ />
295
+ }
296
+ bodyContent={<Body tableData={tableData} />}
297
+ onClick={onClick}
298
+ rawOnClick={rawOnClick}
299
+ />
263
300
  </Root>
264
301
  );
265
302
  };
@@ -6,6 +6,7 @@ import fhirVersions from '../fhirResourceVersions';
6
6
 
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/researchStudy/example-1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/researchStudy/example1.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  export default {
11
12
  title: 'ResearchStudy',
@@ -17,6 +18,7 @@ export const ExampleOfSTU3 = () => {
17
18
  <ResearchStudy
18
19
  fhirVersion={fhirVersions.STU3}
19
20
  fhirResource={fhirResource}
21
+ fhirIcons={fhirIcons}
20
22
  />
21
23
  );
22
24
  };
@@ -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 ResearchStudy from './ResearchStudy';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -7,8 +7,80 @@ import stu3Example1 from '../../../fixtures/stu3/resources/researchStudy/example
7
7
  import r4Example1 from '../../../fixtures/r4/resources/researchStudy/example1.json';
8
8
 
9
9
  import { nbspRegex } from '../../../testUtils';
10
+ import fhirIcons from '../../../fixtures/example-icons';
10
11
 
11
12
  describe('should render ResearchStudy component properly', () => {
13
+ it('component without a fhirIcons props should render a default icon', () => {
14
+ const defaultProps = {
15
+ fhirVersion: fhirVersions.STU3,
16
+ fhirResource: stu3Example1,
17
+ };
18
+
19
+ const { getByAltText } = render(<ResearchStudy {...defaultProps} />);
20
+ const headerIcon = getByAltText('research study');
21
+
22
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
23
+ });
24
+
25
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
26
+ const defaultProps = {
27
+ fhirVersion: fhirVersions.STU3,
28
+ fhirResource: stu3Example1,
29
+ fhirIcons: false,
30
+ };
31
+
32
+ const { getByTestId } = render(<ResearchStudy {...defaultProps} />);
33
+ const headerIcon = getByTestId('placeholder');
34
+
35
+ expect(headerIcon).toBeTruthy();
36
+ });
37
+
38
+ it('component with the img as a fhirIcons props should render an img', () => {
39
+ const defaultProps = {
40
+ fhirVersion: fhirVersions.STU3,
41
+ fhirResource: stu3Example1,
42
+ fhirIcons: (
43
+ <img
44
+ src={require('../assets/containers/ResearchStudy/research-study.svg')}
45
+ alt="finger pointing something in a book"
46
+ />
47
+ ),
48
+ };
49
+
50
+ const { getByAltText } = render(<ResearchStudy {...defaultProps} />);
51
+ const headerIcon = getByAltText('finger pointing something in a book');
52
+
53
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
54
+ });
55
+
56
+ it('component with the resources object as a fhirIcons props should render an img', () => {
57
+ const defaultProps = {
58
+ fhirVersion: fhirVersions.STU3,
59
+ fhirResource: stu3Example1,
60
+ fhirIcons: fhirIcons,
61
+ };
62
+
63
+ const { getByAltText } = render(<ResearchStudy {...defaultProps} />);
64
+ const headerIcon = getByAltText('finger pointing something in a book');
65
+
66
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
67
+ });
68
+
69
+ it('component with the url as a fhirIcons props should render an img', () => {
70
+ const avatarSrc =
71
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
72
+ const defaultProps = {
73
+ fhirVersion: fhirVersions.STU3,
74
+ fhirResource: stu3Example1,
75
+ fhirIcons: avatarSrc,
76
+ };
77
+
78
+ const { getByAltText } = render(<ResearchStudy {...defaultProps} />);
79
+ const headerIcon = getByAltText('header icon');
80
+
81
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
82
+ });
83
+
12
84
  it('with STU3 source data', () => {
13
85
  const defaultProps = {
14
86
  fhirResource: stu3Example1,
@@ -82,4 +154,39 @@ describe('should render ResearchStudy component properly', () => {
82
154
  const status = getByTestId('status').textContent;
83
155
  expect(status).toEqual('completed');
84
156
  });
157
+
158
+ it('should fire custom onClick function', () => {
159
+ const defaultProps = {
160
+ fhirResource: stu3Example1,
161
+ fhirVersion: fhirVersions.STU3,
162
+ };
163
+
164
+ const onClick = jest.fn();
165
+ const { getByRole } = render(
166
+ <ResearchStudy {...defaultProps} onClick={onClick} />,
167
+ );
168
+ const accordion = getByRole('button');
169
+ fireEvent.click(accordion);
170
+
171
+ const attribute = accordion.getAttribute('data-bs-toggle');
172
+ expect(attribute).not.toEqual('collapse');
173
+ expect(onClick).toHaveBeenCalled();
174
+ });
175
+
176
+ it('should not fire custom onClick function', () => {
177
+ const defaultProps = {
178
+ fhirResource: stu3Example1,
179
+ fhirVersion: fhirVersions.STU3,
180
+ };
181
+
182
+ const onClick = 'test';
183
+ const { getByRole } = render(
184
+ <ResearchStudy {...defaultProps} onClick={onClick} />,
185
+ );
186
+ const accordion = getByRole('button');
187
+ fireEvent.click(accordion);
188
+
189
+ const attribute = accordion.getAttribute('data-bs-toggle');
190
+ expect(attribute).toEqual('collapse');
191
+ });
85
192
  });
@@ -15,7 +15,7 @@ const ResourceCategory = ({ title, itemsCount, fhirIcons }) => {
15
15
  <Root name="ResourceCategory">
16
16
  <button
17
17
  type="button"
18
- className="btn d-flex align-items-center justify-content-between w-100 py-4 px-4 bg-white"
18
+ className="btn d-flex align-items-center justify-content-between w-100 px-md-4 py-md-4 bg-white"
19
19
  >
20
20
  <div className="d-flex gap-2">
21
21
  <Header