fhir-react 0.3.7 → 0.3.8

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 (138) 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 +7 -7
  7. package/package.json +55 -54
  8. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  9. package/src/assets/containers/Generic/generic.svg +3 -0
  10. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  11. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  12. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  13. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  14. package/src/components/containers/Accordion/Accordion.js +21 -13
  15. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  16. package/src/components/datatypes/Coding/Coding.js +7 -3
  17. package/src/components/datatypes/Reference/Reference.js +7 -5
  18. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  19. package/src/components/resources/AdverseEvent/AdverseEvent.js +81 -42
  20. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  21. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  22. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +7 -1
  23. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  24. package/src/components/resources/Appointment/Appointment.js +2 -1
  25. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  26. package/src/components/resources/Bundle/Bundle.css +7 -0
  27. package/src/components/resources/Bundle/Bundle.js +15 -11
  28. package/src/components/resources/Bundle/Bundle.stories.js +12 -78
  29. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  30. package/src/components/resources/CarePlan/CarePlan.js +2 -1
  31. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  32. package/src/components/resources/CareTeam/CareTeam.js +72 -50
  33. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  34. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  35. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  36. package/src/components/resources/Claim/Claim.js +2 -1
  37. package/src/components/resources/Claim/Claim.test.js +32 -1
  38. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  39. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  40. package/src/components/resources/ClaimResponse/ClaimResponse.js +137 -83
  41. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  42. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  43. package/src/components/resources/ClaimResponse/Item.js +44 -9
  44. package/src/components/resources/ClaimResponse/Items.js +5 -4
  45. package/src/components/resources/Condition/Condition.js +3 -3
  46. package/src/components/resources/Condition/Condition.test.js +37 -4
  47. package/src/components/resources/Coverage/Coverage.js +2 -1
  48. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  49. package/src/components/resources/Device/Device.js +2 -1
  50. package/src/components/resources/Device/Device.test.js +36 -1
  51. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +7 -2
  52. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  53. package/src/components/resources/DocumentReference/DocumentReference.js +7 -2
  54. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  55. package/src/components/resources/Encounter/Encounter.js +2 -1
  56. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  57. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +2 -0
  58. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  59. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +7 -2
  60. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  61. package/src/components/resources/Generic/Generic.js +20 -7
  62. package/src/components/resources/Generic/Generic.stories.js +2 -1
  63. package/src/components/resources/Generic/Generic.test.js +26 -7
  64. package/src/components/resources/Goal/Goal.js +2 -3
  65. package/src/components/resources/Goal/Goal.test.js +32 -1
  66. package/src/components/resources/Immunization/Immunization.js +2 -2
  67. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  68. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  69. package/src/components/resources/List/Entries.js +3 -3
  70. package/src/components/resources/List/List.js +135 -88
  71. package/src/components/resources/List/List.stories.js +38 -5
  72. package/src/components/resources/List/List.test.js +105 -1
  73. package/src/components/resources/Location/Location.js +65 -47
  74. package/src/components/resources/Location/Location.stories.js +11 -4
  75. package/src/components/resources/Location/Location.test.js +106 -4
  76. package/src/components/resources/Medication/Medication.js +2 -1
  77. package/src/components/resources/Medication/Medication.test.js +36 -1
  78. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +86 -62
  79. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  80. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  81. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  82. package/src/components/resources/MedicationDispense/MedicationDispense.js +68 -68
  83. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  84. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  85. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +115 -66
  86. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  87. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  88. package/src/components/resources/MedicationOrder/MedicationOrder.js +2 -3
  89. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  90. package/src/components/resources/MedicationRequest/MedicationRequest.js +2 -1
  91. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  92. package/src/components/resources/MedicationStatement/MedicationStatement.js +7 -2
  93. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  94. package/src/components/resources/Observation/Observation.js +2 -1
  95. package/src/components/resources/Observation/Observation.test.js +30 -1
  96. package/src/components/resources/Organization/Organization.js +3 -2
  97. package/src/components/resources/Organization/Organization.test.js +36 -1
  98. package/src/components/resources/Patient/Patient.js +2 -0
  99. package/src/components/resources/Patient/Patient.test.js +31 -2
  100. package/src/components/resources/Practitioner/Practitioner.js +2 -1
  101. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  102. package/src/components/resources/PractitionerRole/PractitionerRole.js +50 -29
  103. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  104. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  105. package/src/components/resources/Procedure/Procedure.js +2 -2
  106. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  107. package/src/components/resources/Questionnaire/Group.js +53 -0
  108. package/src/components/resources/Questionnaire/Items.js +45 -0
  109. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  110. package/src/components/resources/Questionnaire/Questionnaire.js +31 -170
  111. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  112. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  113. package/src/components/resources/Questionnaire/Questions.js +40 -0
  114. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  115. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  116. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  117. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  118. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  119. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +52 -236
  120. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  121. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  122. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  123. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  124. package/src/components/resources/ReferralRequest/ReferralRequest.js +65 -40
  125. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  126. package/src/components/resources/RelatedPerson/RelatedPerson.js +151 -0
  127. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  128. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  129. package/src/components/resources/RelatedPerson/index.js +3 -0
  130. package/src/components/resources/ResearchStudy/ResearchStudy.js +160 -130
  131. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  132. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  133. package/src/components/ui/index.js +22 -9
  134. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  135. package/src/fixtures/example-icons.jsx +42 -0
  136. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  137. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  138. package/src/style.scss +3 -1
@@ -55,7 +55,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
55
55
  }
56
56
  };
57
57
 
58
- const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
58
+ const Organization = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
59
59
  let fhirResourceData = {};
60
60
  try {
61
61
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -79,7 +79,7 @@ const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
79
79
  {
80
80
  label: 'Identifiers',
81
81
  testId: 'identifier',
82
- data: identifier && <Identifier fhirData={identifier} noCursive />,
82
+ data: identifier && <Identifier fhirData={identifier} />,
83
83
  status: identifier,
84
84
  },
85
85
  {
@@ -127,6 +127,7 @@ const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
127
127
  )
128
128
  }
129
129
  bodyContent={<Body tableData={tableData} />}
130
+ onClick={onClick}
130
131
  />
131
132
  </Root>
132
133
  );
@@ -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 Organization from './Organization';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -201,4 +201,39 @@ describe('should render Organization component properly', () => {
201
201
  'No additional data',
202
202
  );
203
203
  });
204
+
205
+ it('should fire custom onClick function', () => {
206
+ const defaultProps = {
207
+ fhirResource: r4Example3,
208
+ fhirVersion: fhirVersions.R4,
209
+ };
210
+
211
+ const onClick = jest.fn();
212
+ const { getByRole } = render(
213
+ <Organization {...defaultProps} onClick={onClick} />,
214
+ );
215
+ const accordion = getByRole('button');
216
+ fireEvent.click(accordion);
217
+
218
+ const attribute = accordion.getAttribute('data-bs-toggle');
219
+ expect(attribute).not.toEqual('collapse');
220
+ expect(onClick).toHaveBeenCalled();
221
+ });
222
+
223
+ it('should not fire custom onClick function', () => {
224
+ const defaultProps = {
225
+ fhirResource: r4Example3,
226
+ fhirVersion: fhirVersions.R4,
227
+ };
228
+
229
+ const onClick = 'test';
230
+ const { getByRole } = render(
231
+ <Organization {...defaultProps} onClick={onClick} />,
232
+ );
233
+ const accordion = getByRole('button');
234
+ fireEvent.click(accordion);
235
+
236
+ const attribute = accordion.getAttribute('data-bs-toggle');
237
+ expect(attribute).toEqual('collapse');
238
+ });
204
239
  });
@@ -46,6 +46,7 @@ function Patient(props) {
46
46
  renderName,
47
47
  patientSimple,
48
48
  fhirIcons,
49
+ onClick,
49
50
  } = props;
50
51
 
51
52
  const id = getId(fhirResource);
@@ -146,6 +147,7 @@ function Patient(props) {
146
147
  />
147
148
  }
148
149
  bodyContent={<Body tableData={tableData} />}
150
+ onClick={onClick}
149
151
  />
150
152
  </Root>
151
153
  );
@@ -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 Patient from './Patient';
4
4
 
5
5
  import examplePatient from '../../../fixtures/dstu2/resources/patient/example.json';
@@ -38,7 +38,7 @@ describe('should render component correctly', () => {
38
38
  fhirResource: examplePatient,
39
39
  fhirIcons: (
40
40
  <img
41
- src={require('../assets/containers/ExplanationOfBenefit/explanation-of-benefit.svg.svg')}
41
+ src={require('../assets/containers/Patient/patient.svg')}
42
42
  alt="patient"
43
43
  />
44
44
  ),
@@ -156,4 +156,33 @@ describe('should render component correctly', () => {
156
156
  const { getByTestId } = render(<Patient {...defaultProps} />);
157
157
  expect(getByTestId('deceasedInfo').textContent).toEqual('2/14/2015');
158
158
  });
159
+
160
+ it('should fire custom onClick function', () => {
161
+ const defaultProps = { fhirResource: example3PatientR4 };
162
+
163
+ const onClick = jest.fn();
164
+ const { getByRole } = render(
165
+ <Patient {...defaultProps} onClick={onClick} />,
166
+ );
167
+ const accordion = getByRole('button');
168
+ fireEvent.click(accordion);
169
+
170
+ const attribute = accordion.getAttribute('data-bs-toggle');
171
+ expect(attribute).not.toEqual('collapse');
172
+ expect(onClick).toHaveBeenCalled();
173
+ });
174
+
175
+ it('should not fire custom onClick function', () => {
176
+ const defaultProps = { fhirResource: example3PatientR4 };
177
+
178
+ const onClick = 'test';
179
+ const { getByRole } = render(
180
+ <Patient {...defaultProps} onClick={onClick} />,
181
+ );
182
+ const accordion = getByRole('button');
183
+ fireEvent.click(accordion);
184
+
185
+ const attribute = accordion.getAttribute('data-bs-toggle');
186
+ expect(attribute).toEqual('collapse');
187
+ });
159
188
  });
@@ -82,7 +82,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
82
82
  }
83
83
  };
84
84
 
85
- const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
85
+ const Practitioner = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
86
86
  let fhirResourceData = {};
87
87
  try {
88
88
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -160,6 +160,7 @@ const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
160
160
  />
161
161
  }
162
162
  bodyContent={<Body tableData={tableData} />}
163
+ onClick={onClick}
163
164
  />
164
165
  </Root>
165
166
  );
@@ -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 Practitioner from './Practitioner';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -170,4 +170,39 @@ describe('Practitioner should render component correctly', () => {
170
170
  );
171
171
  jest.restoreAllMocks();
172
172
  });
173
+
174
+ it('should fire custom onClick function', () => {
175
+ const defaultProps = {
176
+ fhirVersion: fhirVersions.R4,
177
+ fhirResource: stu3Example1,
178
+ };
179
+
180
+ const onClick = jest.fn();
181
+ const { getByRole } = render(
182
+ <Practitioner {...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).not.toEqual('collapse');
189
+ expect(onClick).toHaveBeenCalled();
190
+ });
191
+
192
+ it('should not fire custom onClick function', () => {
193
+ const defaultProps = {
194
+ fhirVersion: fhirVersions.R4,
195
+ fhirResource: stu3Example1,
196
+ };
197
+
198
+ const onClick = 'test';
199
+ const { getByRole } = render(
200
+ <Practitioner {...defaultProps} onClick={onClick} />,
201
+ );
202
+ const accordion = getByRole('button');
203
+ fireEvent.click(accordion);
204
+
205
+ const attribute = accordion.getAttribute('data-bs-toggle');
206
+ expect(attribute).toEqual('collapse');
207
+ });
173
208
  });
@@ -5,8 +5,9 @@ import _get from 'lodash/get';
5
5
  import Reference from '../../datatypes/Reference';
6
6
  import fhirVersions from '../fhirResourceVersions';
7
7
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
8
- import { Root, Header, Title, Body, Value, Badge } from '../../ui';
8
+ import { Root, Header, Body, Badge } from '../../ui';
9
9
  import CodeableConcept from '../../datatypes/CodeableConcept/CodeableConcept';
10
+ import Accordion from '../../containers/Accordion';
10
11
 
11
12
  const commonDTO = fhirResource => {
12
13
  const status = _get(fhirResource, 'active') === true ? 'active' : '';
@@ -42,8 +43,12 @@ const resourceDTO = (fhirVersion, fhirResource) => {
42
43
  }
43
44
  };
44
45
 
45
- const PractitionerRole = props => {
46
- const { fhirResource, fhirVersion } = props;
46
+ const PractitionerRole = ({
47
+ fhirResource,
48
+ fhirVersion,
49
+ fhirIcons,
50
+ onClick,
51
+ }) => {
47
52
  let fhirResourceData = {};
48
53
  try {
49
54
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -58,34 +63,50 @@ const PractitionerRole = props => {
58
63
  organization,
59
64
  practitioner,
60
65
  } = fhirResourceData;
66
+
67
+ const tableData = [
68
+ {
69
+ label: 'Practitioner',
70
+ testId: 'practitioner',
71
+ data: practitioner && <Reference fhirData={practitioner} />,
72
+ status: practitioner,
73
+ },
74
+ {
75
+ label: 'Organization',
76
+ testId: 'organization',
77
+ data: organization && <Reference fhirData={organization} />,
78
+ status: organization,
79
+ },
80
+ {
81
+ label: 'Specialties',
82
+ testId: 'specialties',
83
+ data: specialties.length > 0 && (
84
+ <CodeableConcept fhirData={specialties} isCursive />
85
+ ),
86
+ status: specialties.length > 0,
87
+ },
88
+ {
89
+ label: 'Roles',
90
+ testId: 'roles',
91
+ data: codes.length > 0 && <CodeableConcept fhirData={codes} isCursive />,
92
+ status: codes.length > 0,
93
+ },
94
+ ];
95
+
61
96
  return (
62
97
  <Root name="PractitionerRole">
63
- <Header>
64
- <Title>Practitioner roles and specialties</Title>
65
- {status && <Badge data-testid="status">{status}</Badge>}
66
- </Header>
67
- <Body>
68
- {practitioner && (
69
- <Value label="Practitioner" data-testid="practitioner">
70
- <Reference fhirData={practitioner} />
71
- </Value>
72
- )}
73
- {organization && (
74
- <Value label="Organization" data-testid="organization">
75
- <Reference fhirData={organization} />
76
- </Value>
77
- )}
78
- {specialties.length > 0 && (
79
- <Value label="Specialties" data-testid="specialties">
80
- <CodeableConcept fhirData={specialties} />
81
- </Value>
82
- )}
83
- {codes.length > 0 && (
84
- <Value label="Roles" data-testid="roles">
85
- <CodeableConcept fhirData={codes} />
86
- </Value>
87
- )}
88
- </Body>
98
+ <Accordion
99
+ headerContent={
100
+ <Header
101
+ resourceName="PractitionerRole"
102
+ title="Practitioner roles and specialties"
103
+ badges={status && <Badge data-testid="status">{status}</Badge>}
104
+ icon={fhirIcons}
105
+ />
106
+ }
107
+ bodyContent={<Body tableData={tableData} />}
108
+ onClick={onClick}
109
+ />
89
110
  </Root>
90
111
  );
91
112
  };
@@ -12,6 +12,8 @@ import r4Example1 from '../../../fixtures/r4/resources/practitionerRole/example1
12
12
  import r4Example2 from '../../../fixtures/r4/resources/practitionerRole/example2.json';
13
13
  import r4Example3 from '../../../fixtures/r4/resources/practitionerRole/example3.json';
14
14
  import r4Example4 from '../../../fixtures/r4/resources/practitionerRole/example4.json';
15
+ import fhirIcons from '../../../fixtures/example-icons';
16
+ import PractitionerRoleIcon from '../../../assets/containers/PractitionerRole/practitioner-role.svg';
15
17
 
16
18
  export default { title: 'PractitionerRole' };
17
19
 
@@ -21,6 +23,7 @@ export const ExampleOfSTU3 = () => {
21
23
  <PractitionerRole
22
24
  fhirVersion={fhirVersions.STU3}
23
25
  fhirResource={fhirResource}
26
+ fhirIcons={require('../../../assets/containers/PractitionerRole/practitioner-role.svg')}
24
27
  />
25
28
  );
26
29
  };
@@ -31,6 +34,7 @@ export const Example2OfSTU3 = () => {
31
34
  <PractitionerRole
32
35
  fhirVersion={fhirVersions.STU3}
33
36
  fhirResource={fhirResource}
37
+ fhirIcons={PractitionerRoleIcon}
34
38
  />
35
39
  );
36
40
  };
@@ -41,6 +45,7 @@ export const Example3OfSTU3 = () => {
41
45
  <PractitionerRole
42
46
  fhirVersion={fhirVersions.STU3}
43
47
  fhirResource={fhirResource}
48
+ fhirIcons={fhirIcons}
44
49
  />
45
50
  );
46
51
  };
@@ -61,6 +66,7 @@ export const Example2OfR4 = () => {
61
66
  <PractitionerRole
62
67
  fhirVersion={fhirVersions.R4}
63
68
  fhirResource={fhirResource}
69
+ fhirIcons={false}
64
70
  />
65
71
  );
66
72
  };
@@ -71,6 +77,7 @@ export const Example3OfR4 = () => {
71
77
  <PractitionerRole
72
78
  fhirVersion={fhirVersions.R4}
73
79
  fhirResource={fhirResource}
80
+ fhirIcons={'random text'}
74
81
  />
75
82
  );
76
83
  };
@@ -1,13 +1,85 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import PractitionerRole from './PractitionerRole';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import stu3Example1 from '../../../fixtures/stu3/resources/practitionerRole/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/practitionerRole/example1.json';
8
8
  import r4Example2 from '../../../fixtures/r4/resources/practitionerRole/example3.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  describe('PractitionerRole should render component correctly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirVersion: fhirVersions.STU3,
15
+ fhirResource: stu3Example1,
16
+ };
17
+
18
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
19
+ const headerIcon = getByAltText('practitioner role');
20
+
21
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
22
+ });
23
+
24
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
25
+ const defaultProps = {
26
+ fhirVersion: fhirVersions.STU3,
27
+ fhirResource: stu3Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<PractitionerRole {...defaultProps} />);
32
+ const headerIcon = getByTestId('placeholder');
33
+
34
+ expect(headerIcon).toBeTruthy();
35
+ });
36
+
37
+ it('component with the img as a fhirIcons props should render an img', () => {
38
+ const defaultProps = {
39
+ fhirVersion: fhirVersions.STU3,
40
+ fhirResource: stu3Example1,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/PractitionerRole/practitioner-role.svg')}
44
+ alt="practitioner role"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
50
+ const headerIcon = getByAltText('practitioner role');
51
+
52
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
53
+ });
54
+
55
+ it('component with the resources object as a fhirIcons props should render an img', () => {
56
+ const defaultProps = {
57
+ fhirVersion: fhirVersions.STU3,
58
+ fhirResource: stu3Example1,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
63
+ const headerIcon = getByAltText('practitioner role');
64
+
65
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
66
+ });
67
+
68
+ it('component with the url as a fhirIcons props should render an img', () => {
69
+ const avatarSrc =
70
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
71
+ const defaultProps = {
72
+ fhirVersion: fhirVersions.STU3,
73
+ fhirResource: stu3Example1,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
11
83
  it('should render component correctly with STU3 source data', () => {
12
84
  const defaultProps = {
13
85
  fhirVersion: fhirVersions.STU3,
@@ -100,4 +172,39 @@ describe('PractitionerRole should render component correctly', () => {
100
172
  );
101
173
  jest.restoreAllMocks();
102
174
  });
175
+
176
+ it('should fire custom onClick function', () => {
177
+ const defaultProps = {
178
+ fhirVersion: fhirVersions.R4,
179
+ fhirResource: stu3Example1,
180
+ };
181
+
182
+ const onClick = jest.fn();
183
+ const { getByRole } = render(
184
+ <PractitionerRole {...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).not.toEqual('collapse');
191
+ expect(onClick).toHaveBeenCalled();
192
+ });
193
+
194
+ it('should not fire custom onClick function', () => {
195
+ const defaultProps = {
196
+ fhirVersion: fhirVersions.R4,
197
+ fhirResource: stu3Example1,
198
+ };
199
+
200
+ const onClick = 'test';
201
+ const { getByRole } = render(
202
+ <PractitionerRole {...defaultProps} onClick={onClick} />,
203
+ );
204
+ const accordion = getByRole('button');
205
+ fireEvent.click(accordion);
206
+
207
+ const attribute = accordion.getAttribute('data-bs-toggle');
208
+ expect(attribute).toEqual('collapse');
209
+ });
103
210
  });
@@ -14,8 +14,7 @@ import _has from 'lodash/has';
14
14
  import { isNotEmptyArray } from '../../../utils';
15
15
  import { Value } from '../../ui';
16
16
 
17
- const Procedure = props => {
18
- const { fhirResource, fhirIcons } = props;
17
+ const Procedure = ({ fhirResource, fhirIcons, onClick }) => {
19
18
  const display =
20
19
  _get(fhirResource, 'code.coding[0].display') ||
21
20
  _get(fhirResource, 'code.text');
@@ -125,6 +124,7 @@ const Procedure = props => {
125
124
  />
126
125
  }
127
126
  bodyContent={<Body tableData={tableData} />}
127
+ onClick={onClick}
128
128
  />
129
129
  </Root>
130
130
  );
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import dstu2Example1 from '../../../fixtures/dstu2/resources/procedure/example1.json';
4
4
  import r4Example2 from '../../../fixtures/r4/resources/procedure/example2.json';
5
5
  import r4Example3 from '../../../fixtures/r4/resources/procedure/example3.json';
6
- import { render } from '@testing-library/react';
6
+ import { fireEvent, render } from '@testing-library/react';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/procedure/example1.json';
8
8
  import fhirIcons from '../../../fixtures/example-icons';
9
9
  import fhirVersions from '../fhirResourceVersions';
@@ -168,4 +168,33 @@ describe('Procedure should render component correctly', () => {
168
168
  'Eerste neo-adjuvante',
169
169
  );
170
170
  });
171
+
172
+ it('should fire custom onClick function', () => {
173
+ const defaultProps = { fhirResource: r4Example3 };
174
+
175
+ const onClick = jest.fn();
176
+ const { getByRole } = render(
177
+ <Procedure {...defaultProps} onClick={onClick} />,
178
+ );
179
+ const accordion = getByRole('button');
180
+ fireEvent.click(accordion);
181
+
182
+ const attribute = accordion.getAttribute('data-bs-toggle');
183
+ expect(attribute).not.toEqual('collapse');
184
+ expect(onClick).toHaveBeenCalled();
185
+ });
186
+
187
+ it('should not fire custom onClick function', () => {
188
+ const defaultProps = { fhirResource: r4Example3 };
189
+
190
+ const onClick = 'test';
191
+ const { getByRole } = render(
192
+ <Procedure {...defaultProps} onClick={onClick} />,
193
+ );
194
+ const accordion = getByRole('button');
195
+ fireEvent.click(accordion);
196
+
197
+ const attribute = accordion.getAttribute('data-bs-toggle');
198
+ expect(attribute).toEqual('collapse');
199
+ });
171
200
  });
@@ -0,0 +1,53 @@
1
+ import _get from 'lodash/get';
2
+ import { MissingValue } from '../../ui';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+ import Questions from './Questions';
6
+ import { getQuestionText } from './getQuestionText';
7
+
8
+ const Group = ({ data, prepareItems, isChild = false }) => {
9
+ if (!Array.isArray(data) || data.length === 0) {
10
+ return null;
11
+ }
12
+
13
+ return data.map(prepareItems).map((item, i) => {
14
+ const text = getQuestionText(item);
15
+ let nestedItems = _get(item, 'item', []);
16
+ nestedItems = nestedItems.map(prepareItems);
17
+ const isGroup = _get(item, 'isGroup');
18
+ return (
19
+ <ul
20
+ key={`questionnaire-item-${i}`}
21
+ className="fhir-resource__Questionnaire-list"
22
+ >
23
+ <li
24
+ className={
25
+ isChild
26
+ ? 'fhir-resource__Questionnaire-list-title-question'
27
+ : 'fhir-resource__Questionnaire-list-title'
28
+ }
29
+ data-testid={`linkId-${item.linkId}`}
30
+ >
31
+ {text ? text : <MissingValue />}
32
+ </li>
33
+ {!isGroup && (
34
+ <li>
35
+ <Questions questions={nestedItems} prepareItems={prepareItems} />
36
+ </li>
37
+ )}
38
+ {isGroup && (
39
+ <li>
40
+ <Group data={nestedItems} prepareItems={prepareItems} isChild />
41
+ </li>
42
+ )}
43
+ </ul>
44
+ );
45
+ });
46
+ };
47
+
48
+ Group.propTypes = {
49
+ data: PropTypes.array,
50
+ prepareItems: PropTypes.func.isRequired,
51
+ };
52
+
53
+ export default Group;
@@ -0,0 +1,45 @@
1
+ import fhirVersions from '../fhirResourceVersions';
2
+ import _get from 'lodash/get';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+ import Group from './Group';
6
+
7
+ const Items = ({ fhirVersion, data }) => {
8
+ if (fhirVersion === fhirVersions.DSTU2) {
9
+ const prepareItems = item => ({
10
+ ...item,
11
+ item: _get(item, 'question') || _get(item, 'group') || [],
12
+ isGroup: !!_get(item, 'group'),
13
+ });
14
+ return <Group data={data} prepareItems={prepareItems} />;
15
+ }
16
+
17
+ if (fhirVersion === fhirVersions.STU3) {
18
+ const prepareItems = item => ({
19
+ ...item,
20
+ isGroup: _get(item, 'type') === 'group',
21
+ });
22
+ return <Group data={data} prepareItems={prepareItems} />;
23
+ }
24
+
25
+ if (fhirVersion === fhirVersions.R4) {
26
+ const prepareItems = item => ({
27
+ ...item,
28
+ isGroup: _get(item, 'type') === 'group',
29
+ });
30
+ return <Group data={data} prepareItems={prepareItems} />;
31
+ }
32
+
33
+ return null;
34
+ };
35
+
36
+ Items.propTypes = {
37
+ data: PropTypes.array,
38
+ fhirVersion: PropTypes.oneOf([
39
+ fhirVersions.DSTU2,
40
+ fhirVersions.STU3,
41
+ fhirVersions.R4,
42
+ ]).isRequired,
43
+ };
44
+
45
+ export default Items;