fhir-react 0.3.7 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.storybook/main.js +5 -0
  4. package/.storybook/manager.js +6 -0
  5. package/.storybook/preview.js +7 -0
  6. package/.stylelintrc +6 -2
  7. package/README.md +19 -1
  8. package/build/index.js +15 -11
  9. package/build/style.css +9 -9
  10. package/package.json +59 -57
  11. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  12. package/src/assets/containers/Generic/generic.svg +3 -0
  13. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  14. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  15. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  16. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  17. package/src/components/containers/Accordion/Accordion.js +44 -13
  18. package/src/components/containers/Accordion/Accordion.stories.js +74 -58
  19. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  20. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  21. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
  22. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  23. package/src/components/datatypes/Coding/Coding.js +7 -3
  24. package/src/components/datatypes/Reference/Reference.js +7 -5
  25. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  26. package/src/components/defaultArgTypes.js +12 -0
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
  32. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  33. package/src/components/resources/Appointment/Appointment.js +9 -1
  34. package/src/components/resources/Appointment/Appointment.stories.js +51 -62
  35. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  36. package/src/components/resources/Binary/Binary.js +2 -1
  37. package/src/components/resources/Binary/Binary.stories.js +27 -21
  38. package/src/components/resources/Bundle/Bundle.css +7 -0
  39. package/src/components/resources/Bundle/Bundle.js +15 -11
  40. package/src/components/resources/Bundle/Bundle.stories.js +59 -115
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
  44. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
  47. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  48. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  49. package/src/components/resources/Claim/Claim.js +9 -1
  50. package/src/components/resources/Claim/Claim.stories.js +36 -49
  51. package/src/components/resources/Claim/Claim.test.js +32 -1
  52. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  53. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  54. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  55. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
  56. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  57. package/src/components/resources/ClaimResponse/Item.js +44 -9
  58. package/src/components/resources/ClaimResponse/Items.js +5 -4
  59. package/src/components/resources/Condition/Condition.js +10 -3
  60. package/src/components/resources/Condition/Condition.stories.js +47 -62
  61. package/src/components/resources/Condition/Condition.test.js +37 -4
  62. package/src/components/resources/Coverage/Coverage.js +9 -1
  63. package/src/components/resources/Coverage/Coverage.stories.js +38 -50
  64. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  65. package/src/components/resources/Device/Device.js +9 -1
  66. package/src/components/resources/Device/Device.stories.js +40 -52
  67. package/src/components/resources/Device/Device.test.js +36 -1
  68. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
  70. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  71. package/src/components/resources/DocumentReference/DocumentReference.js +9 -2
  72. package/src/components/resources/DocumentReference/DocumentReference.stories.js +25 -29
  73. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  74. package/src/components/resources/Encounter/Encounter.js +9 -1
  75. package/src/components/resources/Encounter/Encounter.stories.js +43 -59
  76. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  77. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  78. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
  79. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  80. package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
  81. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  82. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  84. package/src/components/resources/Generic/Generic.js +21 -7
  85. package/src/components/resources/Generic/Generic.stories.js +22 -12
  86. package/src/components/resources/Generic/Generic.test.js +26 -7
  87. package/src/components/resources/Goal/Goal.js +9 -3
  88. package/src/components/resources/Goal/Goal.stories.js +35 -49
  89. package/src/components/resources/Goal/Goal.test.js +32 -1
  90. package/src/components/resources/Immunization/Immunization.js +9 -2
  91. package/src/components/resources/Immunization/Immunization.stories.js +38 -51
  92. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  93. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  94. package/src/components/resources/List/Entries.js +3 -3
  95. package/src/components/resources/List/List.js +137 -88
  96. package/src/components/resources/List/List.stories.js +69 -40
  97. package/src/components/resources/List/List.test.js +105 -1
  98. package/src/components/resources/Location/Location.js +66 -47
  99. package/src/components/resources/Location/Location.stories.js +25 -13
  100. package/src/components/resources/Location/Location.test.js +106 -4
  101. package/src/components/resources/Medication/Medication.js +9 -1
  102. package/src/components/resources/Medication/Medication.stories.js +42 -64
  103. package/src/components/resources/Medication/Medication.test.js +36 -1
  104. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  107. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  108. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  109. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
  110. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  111. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  114. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  115. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  117. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  118. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
  119. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  120. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  121. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
  122. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  123. package/src/components/resources/Observation/Observation.js +3 -1
  124. package/src/components/resources/Observation/Observation.stories.js +39 -33
  125. package/src/components/resources/Observation/Observation.test.js +30 -1
  126. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  127. package/src/components/resources/Organization/Organization.js +10 -2
  128. package/src/components/resources/Organization/Organization.stories.js +40 -52
  129. package/src/components/resources/Organization/Organization.test.js +36 -1
  130. package/src/components/resources/Patient/Patient.js +4 -0
  131. package/src/components/resources/Patient/Patient.stories.js +36 -28
  132. package/src/components/resources/Patient/Patient.test.js +31 -2
  133. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  134. package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
  135. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  136. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  137. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
  138. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  139. package/src/components/resources/Procedure/Procedure.js +3 -2
  140. package/src/components/resources/Procedure/Procedure.stories.js +33 -25
  141. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  142. package/src/components/resources/Questionnaire/Group.js +53 -0
  143. package/src/components/resources/Questionnaire/Items.js +45 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  145. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  146. package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
  147. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  148. package/src/components/resources/Questionnaire/Questions.js +40 -0
  149. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  150. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  151. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  152. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  154. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  155. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
  156. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  157. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  158. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  159. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  160. package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
  161. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  162. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  163. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -0
  164. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  165. package/src/components/resources/RelatedPerson/index.js +3 -0
  166. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  167. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
  168. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  169. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  170. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
  171. package/src/components/ui/index.js +48 -31
  172. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  173. package/src/fixtures/example-icons.jsx +42 -0
  174. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  175. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  176. package/src/style.scss +14 -1
  177. package/.storybook/addons.js +0 -1
  178. package/.storybook/config.js +0 -26
  179. package/.storybook/presets.js +0 -1
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import fhirVersions from '../fhirResourceVersions';
3
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
4
 
4
5
  import CarePlan from './CarePlan';
5
6
 
@@ -9,73 +10,62 @@ import example2CarePlanSTU3 from '../../../fixtures/stu3/resources/carePlan/exam
9
10
  import weightLossCarePlanR4 from '../../../fixtures/r4/resources/carePlan/weightLossPlan.json';
10
11
  import pregnancyCarePlanR4 from '../../../fixtures/r4/resources/carePlan/pregnancyPlan.json';
11
12
  import heartOperationCarePlanR4 from '../../../fixtures/r4/resources/carePlan/heartOperationPlan.json';
12
- import fhirVersions from '../fhirResourceVersions';
13
+
13
14
  import CarePlanIcon from '../../../assets/containers/CarePlan/care-plan.svg';
14
15
  import fhirIcons from '../../../fixtures/example-icons';
15
16
 
16
- export default { title: 'CarePlan' };
17
+ export default {
18
+ title: 'CarePlan',
19
+ component: CarePlan,
20
+ argTypes: {
21
+ ...defaultArgTypes,
22
+ },
23
+ };
24
+
25
+ const Template = args => <CarePlan {...args} />;
17
26
 
18
- export const DefaultVisualizationDSTU2 = () => {
19
- const fhirResource = object('Resource', exampleCarePlanDSTU2);
20
- return (
21
- <CarePlan
22
- fhirVersion={fhirVersions.DSTU2}
23
- fhirResource={fhirResource}
24
- fhirIcons={require('../../../assets/containers/CarePlan/care-plan.svg')}
25
- />
26
- );
27
+ export const DefaultVisualizationDSTU2 = Template.bind({});
28
+ DefaultVisualizationDSTU2.args = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: exampleCarePlanDSTU2,
31
+ fhirIcons: require('../../../assets/containers/CarePlan/care-plan.svg'),
27
32
  };
28
33
 
29
- export const ExampleCarePlanSTU3 = () => {
30
- const fhirResource = object('Resource', exampleCarePlanSTU3);
31
- return (
32
- <CarePlan
33
- fhirVersion={fhirVersions.STU3}
34
- fhirResource={fhirResource}
35
- fhirIcons={CarePlanIcon}
36
- />
37
- );
34
+ export const ExampleCarePlanSTU3 = Template.bind({});
35
+ ExampleCarePlanSTU3.args = {
36
+ fhirVersion: fhirVersions.STU3,
37
+ fhirResource: exampleCarePlanSTU3,
38
+ fhirIcons: CarePlanIcon,
38
39
  };
39
40
 
40
- export const Example2CarePlanSTU3 = () => {
41
- const fhirResource = object('Resource', example2CarePlanSTU3);
42
- return (
43
- <CarePlan
44
- fhirVersion={fhirVersions.STU3}
45
- fhirResource={fhirResource}
46
- fhirIcons={fhirIcons}
47
- />
48
- );
41
+ export const Example2CarePlanSTU3 = Template.bind({});
42
+ Example2CarePlanSTU3.args = {
43
+ fhirVersion: fhirVersions.STU3,
44
+ fhirResource: example2CarePlanSTU3,
45
+ fhirIcons: fhirIcons,
49
46
  };
50
47
 
51
- export const WeightLossCarePlanR4 = () => {
52
- const fhirResource = object('Resource', weightLossCarePlanR4);
53
- return (
54
- <CarePlan
55
- fhirVersion={fhirVersions.R4}
56
- fhirResource={fhirResource}
57
- fhirIcons={false}
58
- />
59
- );
48
+ export const WeightLossCarePlanR4 = Template.bind({});
49
+ WeightLossCarePlanR4.args = {
50
+ fhirVersion: fhirVersions.R4,
51
+ fhirResource: weightLossCarePlanR4,
52
+ fhirIcons: false,
60
53
  };
61
54
 
62
- export const PregnancyCarePlanR4 = () => {
63
- const fhirResource = object('Resource', pregnancyCarePlanR4);
64
- return (
65
- <CarePlan
66
- fhirVersion={fhirVersions.R4}
67
- fhirResource={fhirResource}
68
- fhirIcons={'random text'}
69
- />
70
- );
55
+ export const PregnancyCarePlanR4 = Template.bind({});
56
+ PregnancyCarePlanR4.args = {
57
+ fhirVersion: fhirVersions.R4,
58
+ fhirResource: pregnancyCarePlanR4,
59
+ fhirIcons: 'random text',
71
60
  };
72
61
 
73
- export const HeartOperatioCarePlanR4 = () => {
74
- const fhirResource = object('Resource', heartOperationCarePlanR4);
75
- return <CarePlan fhirVersion={fhirVersions.R4} fhirResource={fhirResource} />;
62
+ export const HeartOperatioCarePlanR4 = Template.bind({});
63
+ HeartOperatioCarePlanR4.args = {
64
+ fhirVersion: fhirVersions.R4,
65
+ fhirResource: heartOperationCarePlanR4,
76
66
  };
77
67
 
78
- export const ExampleWithoutFhirVersionProperty = () => {
79
- const fhirResource = object('Resource', example2CarePlanSTU3);
80
- return <CarePlan fhirResource={fhirResource} />;
68
+ export const ExampleWithoutFhirVersionProperty = Template.bind({});
69
+ ExampleWithoutFhirVersionProperty.args = {
70
+ fhirResource: example2CarePlanSTU3,
81
71
  };
@@ -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 CarePlan from './CarePlan';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -111,8 +111,9 @@ describe('should render component correctly', () => {
111
111
  expect(getByTestId('activity').textContent).toContain('3141-9');
112
112
  expect(getByTestId('intent').textContent).toEqual('plan');
113
113
  expect(getByTestId('description').textContent).toContain('Manage obesity');
114
- expect(getByTestId('subject').textContent).toContain('Peter James');
115
- expect(getByTestId('subject').textContent).toContain('Patient/example');
114
+ expect(getByTestId('subject').textContent).toContain(
115
+ 'Peter James Chalmers',
116
+ );
116
117
  expect(getByTestId('author').textContent).toContain('Dr Adam Careful');
117
118
  expect(getByTestId('periodEnd').textContent).toEqual('6/1/2017');
118
119
  expect(getByTestId('basedOn').textContent).toEqual(
@@ -136,8 +137,9 @@ describe('should render component correctly', () => {
136
137
  expect(getByTestId('intent').textContent).toEqual('plan');
137
138
  expect(getByTestId('goals').textContent).toEqual('Goal/example');
138
139
  expect(getByTestId('description').textContent).toContain('Manage obesity');
139
- expect(getByTestId('subject').textContent).toContain('Peter James');
140
- expect(getByTestId('subject').textContent).toContain('Patient/example');
140
+ expect(getByTestId('subject').textContent).toContain(
141
+ 'Peter James Chalmers',
142
+ );
141
143
  expect(getByTestId('author').textContent).toContain('Dr Adam Careful');
142
144
  expect(getByTestId('periodEnd').textContent).toEqual('6/1/2017');
143
145
  expect(getByTestId('basedOn').textContent).toEqual(
@@ -160,8 +162,42 @@ describe('should render component correctly', () => {
160
162
  expect(getByTestId('intent').textContent).toEqual('plan');
161
163
  expect(getByTestId('goals').textContent).toEqual('#goal');
162
164
  expect(getByTestId('subject').textContent).toContain('Eve Everywoman');
163
- expect(getByTestId('subject').textContent).toContain('Patient/1');
164
165
  expect(getByTestId('periodStart').textContent).toEqual('1/1/2013');
165
166
  expect(getByTestId('periodEnd').textContent).toEqual('10/1/2013');
166
167
  });
168
+
169
+ it('should fire custom onClick function', () => {
170
+ const defaultProps = {
171
+ fhirResource: example2CarePlanR4,
172
+ fhirVersion: fhirVersions.R4,
173
+ };
174
+
175
+ const onClick = jest.fn();
176
+ const { getByRole } = render(
177
+ <CarePlan {...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 = {
189
+ fhirResource: example2CarePlanR4,
190
+ fhirVersion: fhirVersions.R4,
191
+ };
192
+
193
+ const onClick = 'test';
194
+ const { getByRole } = render(
195
+ <CarePlan {...defaultProps} onClick={onClick} />,
196
+ );
197
+ const accordion = getByRole('button');
198
+ fireEvent.click(accordion);
199
+
200
+ const attribute = accordion.getAttribute('data-bs-toggle');
201
+ expect(attribute).toEqual('collapse');
202
+ });
167
203
  });
@@ -4,8 +4,7 @@ import {
4
4
  Header,
5
5
  MissingValue,
6
6
  Root,
7
- Title,
8
- Value,
7
+ ValueSection,
9
8
  } from '../../ui';
10
9
 
11
10
  import CareTeamParticipants from './CareTeamParticipants';
@@ -16,6 +15,7 @@ import React from 'react';
16
15
  import Reference from '../../datatypes/Reference';
17
16
  import _get from 'lodash/get';
18
17
  import fhirVersions from '../fhirResourceVersions';
18
+ import Accordion from '../../containers/Accordion';
19
19
 
20
20
  const commonDTO = fhirResource => {
21
21
  // Default value for title - "Care team"
@@ -83,8 +83,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
83
83
  }
84
84
  };
85
85
 
86
- const CareTeam = props => {
87
- const { fhirResource, fhirVersion } = props;
86
+ const CareTeam = ({
87
+ fhirResource,
88
+ fhirVersion,
89
+ fhirIcons,
90
+ onClick,
91
+ rawOnClick,
92
+ }) => {
88
93
  const {
89
94
  name,
90
95
  status,
@@ -98,54 +103,78 @@ const CareTeam = props => {
98
103
  } = resourceDTO(fhirVersion, fhirResource);
99
104
  const hasParticipants = participants.length > 0;
100
105
 
106
+ const tableData = [
107
+ {
108
+ label: 'Category',
109
+ testId: 'category',
110
+ data: category && <CodableConcept fhirData={category} isCursive />,
111
+ status: category,
112
+ },
113
+ {
114
+ label: 'Subject',
115
+ testId: 'subject',
116
+ data: subject && <Reference fhirData={subject} />,
117
+ status: subject,
118
+ },
119
+ {
120
+ label: 'Encounter',
121
+ testId: 'encounter',
122
+ data: encounter && <Reference fhirData={encounter} />,
123
+ status: encounter,
124
+ },
125
+ {
126
+ label: 'Managing organization',
127
+ testId: 'managingOrganization',
128
+ data: managingOrganization && (
129
+ <Reference fhirData={managingOrganization} />
130
+ ),
131
+ status: managingOrganization,
132
+ },
133
+ {
134
+ label: 'Care Period Start',
135
+ testId: 'periodStart',
136
+ data: periodStart ? (
137
+ <DateType fhirData={periodStart} isBlack />
138
+ ) : (
139
+ <MissingValue />
140
+ ),
141
+ status: periodStart,
142
+ },
143
+ {
144
+ label: 'Care Period End',
145
+ testId: 'periodEnd',
146
+ data: periodEnd ? (
147
+ <DateType fhirData={periodEnd} isBlack />
148
+ ) : (
149
+ <MissingValue />
150
+ ),
151
+ status: periodEnd,
152
+ },
153
+ ];
154
+
101
155
  return (
102
156
  <Root name="CareTeam">
103
- <Header>
104
- {name && <Title>{name}</Title>}
105
- {status && <Badge data-testid="status">{status}</Badge>}
106
- </Header>
107
- <Body>
108
- {category && (
109
- <Value label="Category" data-testid="category">
110
- <CodableConcept fhirData={category} />
111
- </Value>
112
- )}
113
- {subject && (
114
- <Value label="Subject" data-testid="subject">
115
- <Reference fhirData={subject} />
116
- </Value>
117
- )}
118
- {encounter && (
119
- <Value label="Encounter" data-testid="encounter">
120
- <Reference fhirData={encounter} />
121
- </Value>
122
- )}
123
- {managingOrganization && (
124
- <Value
125
- label="Managing organization"
126
- data-testid="managingOrganization"
127
- >
128
- <Reference fhirData={managingOrganization} />
129
- </Value>
130
- )}
131
- {periodStart && (
132
- <Value label="Care Period Start" data-testid="periodStart">
133
- {periodStart ? (
134
- <DateType fhirData={periodStart} />
135
- ) : (
136
- <MissingValue />
137
- )}
138
- </Value>
139
- )}
140
- {periodEnd && (
141
- <Value label="Care Period End" data-testid="periodEnd">
142
- {periodEnd ? <DateType fhirData={periodEnd} /> : <MissingValue />}
143
- </Value>
144
- )}
145
- {hasParticipants && (
146
- <CareTeamParticipants participants={participants} />
147
- )}
148
- </Body>
157
+ <Accordion
158
+ headerContent={
159
+ <Header
160
+ resourceName={'CareTeam'}
161
+ icon={fhirIcons}
162
+ title={name}
163
+ badges={status && <Badge data-testid="status">{status}</Badge>}
164
+ />
165
+ }
166
+ bodyContent={
167
+ <Body tableData={tableData}>
168
+ <ValueSection>
169
+ {hasParticipants && (
170
+ <CareTeamParticipants participants={participants} />
171
+ )}
172
+ </ValueSection>
173
+ </Body>
174
+ }
175
+ onClick={onClick}
176
+ rawOnClick={rawOnClick}
177
+ />
149
178
  </Root>
150
179
  );
151
180
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import CareTeam from './CareTeam';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -7,25 +7,36 @@ import example_STU3 from '../../../fixtures/stu3/resources/careTeam/example1.jso
7
7
  import example2_STU3 from '../../../fixtures/stu3/resources/careTeam/example2.json';
8
8
  import example_R4 from '../../../fixtures/r4/resources/careTeam/example1.json';
9
9
 
10
+ import fhirIcons from '../../../fixtures/example-icons';
11
+ import CareTeamIcon from '../../../assets/containers/CareTeam/care-team.svg';
12
+
10
13
  export default {
11
14
  title: 'CareTeam',
15
+ component: CareTeam,
16
+ argTypes: {
17
+ ...defaultArgTypes,
18
+ },
12
19
  };
13
20
 
14
- export const ExampleSTU3 = () => {
15
- const fhirResource = object('Resource', example_STU3);
16
- return (
17
- <CareTeam fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
18
- );
21
+ const Template = args => <CareTeam {...args} />;
22
+
23
+ export const ExampleSTU3 = Template.bind({});
24
+ ExampleSTU3.args = {
25
+ fhirVersion: fhirVersions.STU3,
26
+ fhirResource: example_STU3,
27
+ fhirIcons: CareTeamIcon,
19
28
  };
20
29
 
21
- export const Example2OfSTU3 = () => {
22
- const fhirResource = object('Resource', example2_STU3);
23
- return (
24
- <CareTeam fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
25
- );
30
+ export const Example2OfSTU3 = Template.bind({});
31
+ Example2OfSTU3.args = {
32
+ fhirVersion: fhirVersions.STU3,
33
+ fhirResource: example2_STU3,
34
+ fhirIcons: fhirIcons,
26
35
  };
27
36
 
28
- export const ExampleR4 = () => {
29
- const fhirResource = object('Resource', example_R4);
30
- return <CareTeam fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
37
+ export const ExampleR4 = Template.bind({});
38
+ ExampleR4.args = {
39
+ fhirVersion: fhirVersions.R4,
40
+ fhirResource: example_R4,
41
+ fhirIcons: false,
31
42
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
 
4
4
  import CareTeam from './CareTeam';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -8,7 +8,80 @@ import stu3Example1 from '../../../fixtures/stu3/resources/careTeam/example1.jso
8
8
  import stu3Example2 from '../../../fixtures/stu3/resources/careTeam/example2.json';
9
9
  import r4Example1 from '../../../fixtures/r4/resources/careTeam/example1.json';
10
10
 
11
+ import fhirIcons from '../../../fixtures/example-icons';
12
+
11
13
  describe('should render the CareTeam component properly', () => {
14
+ it('component without a fhirIcons props should render a default icon', () => {
15
+ const defaultProps = {
16
+ fhirVersion: fhirVersions.STU3,
17
+ fhirResource: stu3Example1,
18
+ };
19
+
20
+ const { getByAltText } = render(<CareTeam {...defaultProps} />);
21
+ const headerIcon = getByAltText('care team');
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.STU3,
29
+ fhirResource: stu3Example1,
30
+ fhirIcons: false,
31
+ };
32
+
33
+ const { getByTestId } = render(<CareTeam {...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.STU3,
42
+ fhirResource: stu3Example1,
43
+ fhirIcons: (
44
+ <img
45
+ src={require('../assets/containers/CareTeam/care-team.svg')}
46
+ alt="group of people"
47
+ />
48
+ ),
49
+ };
50
+
51
+ const { getByAltText } = render(<CareTeam {...defaultProps} />);
52
+ const headerIcon = getByAltText('group of people');
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.STU3,
60
+ fhirResource: stu3Example1,
61
+ fhirIcons: fhirIcons,
62
+ };
63
+
64
+ const { getByAltText } = render(<CareTeam {...defaultProps} />);
65
+ const headerIcon = getByAltText('group of people');
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.STU3,
75
+ fhirResource: stu3Example1,
76
+ fhirIcons: avatarSrc,
77
+ };
78
+
79
+ const { getByAltText } = render(<CareTeam {...defaultProps} />);
80
+ const headerIcon = getByAltText('header icon');
81
+
82
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
83
+ });
84
+
12
85
  it('should render with STU3 source data', () => {
13
86
  const defaultProps = {
14
87
  fhirResource: stu3Example1,
@@ -117,4 +190,39 @@ describe('should render the CareTeam component properly', () => {
117
190
  );
118
191
  expect(periodEnds).toEqual(['-', '1/1/2013']);
119
192
  });
193
+
194
+ it('should fire custom onClick function', () => {
195
+ const defaultProps = {
196
+ fhirResource: r4Example1,
197
+ fhirVersion: fhirVersions.R4,
198
+ };
199
+
200
+ const onClick = jest.fn();
201
+ const { getByRole } = render(
202
+ <CareTeam {...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).not.toEqual('collapse');
209
+ expect(onClick).toHaveBeenCalled();
210
+ });
211
+
212
+ it('should not fire custom onClick function', () => {
213
+ const defaultProps = {
214
+ fhirResource: r4Example1,
215
+ fhirVersion: fhirVersions.R4,
216
+ };
217
+
218
+ const onClick = 'test';
219
+ const { getByRole } = render(
220
+ <CareTeam {...defaultProps} onClick={onClick} />,
221
+ );
222
+ const accordion = getByRole('button');
223
+ fireEvent.click(accordion);
224
+
225
+ const attribute = accordion.getAttribute('data-bs-toggle');
226
+ expect(attribute).toEqual('collapse');
227
+ });
120
228
  });
@@ -20,7 +20,7 @@ const CareTeamParticipants = props => {
20
20
  <TableHeader>End</TableHeader>
21
21
  </TableRow>
22
22
  </thead>
23
- <tbody>{allParticipants}</tbody>
23
+ <tbody className="border-top-0">{allParticipants}</tbody>
24
24
  </Table>
25
25
  </ValueSection>
26
26
  );
@@ -298,7 +298,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
298
298
  }
299
299
  };
300
300
 
301
- const Claim = ({ fhirResource, fhirVersion, fhirIcons }) => {
301
+ const Claim = ({
302
+ fhirResource,
303
+ fhirVersion,
304
+ fhirIcons,
305
+ onClick,
306
+ rawOnClick,
307
+ }) => {
302
308
  let fhirResourceData = {};
303
309
  try {
304
310
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -481,6 +487,8 @@ const Claim = ({ fhirResource, fhirVersion, fhirIcons }) => {
481
487
  {items && <Items items={items} />}
482
488
  </Body>
483
489
  }
490
+ onClick={onClick}
491
+ rawOnClick={rawOnClick}
484
492
  />
485
493
  </Root>
486
494
  );