fhir-react 0.3.7 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.storybook/main.js +5 -0
  4. package/.storybook/manager.js +6 -0
  5. package/.storybook/preview.js +7 -0
  6. package/.stylelintrc +6 -2
  7. package/README.md +19 -1
  8. package/build/index.js +15 -11
  9. package/build/style.css +9 -9
  10. package/package.json +59 -57
  11. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  12. package/src/assets/containers/Generic/generic.svg +3 -0
  13. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  14. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  15. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  16. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  17. package/src/components/containers/Accordion/Accordion.js +44 -13
  18. package/src/components/containers/Accordion/Accordion.stories.js +74 -58
  19. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  20. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  21. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
  22. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  23. package/src/components/datatypes/Coding/Coding.js +7 -3
  24. package/src/components/datatypes/Reference/Reference.js +7 -5
  25. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  26. package/src/components/defaultArgTypes.js +12 -0
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
  32. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  33. package/src/components/resources/Appointment/Appointment.js +9 -1
  34. package/src/components/resources/Appointment/Appointment.stories.js +51 -62
  35. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  36. package/src/components/resources/Binary/Binary.js +2 -1
  37. package/src/components/resources/Binary/Binary.stories.js +27 -21
  38. package/src/components/resources/Bundle/Bundle.css +7 -0
  39. package/src/components/resources/Bundle/Bundle.js +15 -11
  40. package/src/components/resources/Bundle/Bundle.stories.js +59 -115
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
  44. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
  47. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  48. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  49. package/src/components/resources/Claim/Claim.js +9 -1
  50. package/src/components/resources/Claim/Claim.stories.js +36 -49
  51. package/src/components/resources/Claim/Claim.test.js +32 -1
  52. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  53. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  54. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  55. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
  56. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  57. package/src/components/resources/ClaimResponse/Item.js +44 -9
  58. package/src/components/resources/ClaimResponse/Items.js +5 -4
  59. package/src/components/resources/Condition/Condition.js +10 -3
  60. package/src/components/resources/Condition/Condition.stories.js +47 -62
  61. package/src/components/resources/Condition/Condition.test.js +37 -4
  62. package/src/components/resources/Coverage/Coverage.js +9 -1
  63. package/src/components/resources/Coverage/Coverage.stories.js +38 -50
  64. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  65. package/src/components/resources/Device/Device.js +9 -1
  66. package/src/components/resources/Device/Device.stories.js +40 -52
  67. package/src/components/resources/Device/Device.test.js +36 -1
  68. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
  70. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  71. package/src/components/resources/DocumentReference/DocumentReference.js +9 -2
  72. package/src/components/resources/DocumentReference/DocumentReference.stories.js +25 -29
  73. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  74. package/src/components/resources/Encounter/Encounter.js +9 -1
  75. package/src/components/resources/Encounter/Encounter.stories.js +43 -59
  76. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  77. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  78. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
  79. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  80. package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
  81. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  82. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  84. package/src/components/resources/Generic/Generic.js +21 -7
  85. package/src/components/resources/Generic/Generic.stories.js +22 -12
  86. package/src/components/resources/Generic/Generic.test.js +26 -7
  87. package/src/components/resources/Goal/Goal.js +9 -3
  88. package/src/components/resources/Goal/Goal.stories.js +35 -49
  89. package/src/components/resources/Goal/Goal.test.js +32 -1
  90. package/src/components/resources/Immunization/Immunization.js +9 -2
  91. package/src/components/resources/Immunization/Immunization.stories.js +38 -51
  92. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  93. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  94. package/src/components/resources/List/Entries.js +3 -3
  95. package/src/components/resources/List/List.js +137 -88
  96. package/src/components/resources/List/List.stories.js +69 -40
  97. package/src/components/resources/List/List.test.js +105 -1
  98. package/src/components/resources/Location/Location.js +66 -47
  99. package/src/components/resources/Location/Location.stories.js +25 -13
  100. package/src/components/resources/Location/Location.test.js +106 -4
  101. package/src/components/resources/Medication/Medication.js +9 -1
  102. package/src/components/resources/Medication/Medication.stories.js +42 -64
  103. package/src/components/resources/Medication/Medication.test.js +36 -1
  104. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  107. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  108. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  109. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
  110. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  111. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  114. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  115. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  117. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  118. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
  119. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  120. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  121. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
  122. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  123. package/src/components/resources/Observation/Observation.js +3 -1
  124. package/src/components/resources/Observation/Observation.stories.js +39 -33
  125. package/src/components/resources/Observation/Observation.test.js +30 -1
  126. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  127. package/src/components/resources/Organization/Organization.js +10 -2
  128. package/src/components/resources/Organization/Organization.stories.js +40 -52
  129. package/src/components/resources/Organization/Organization.test.js +36 -1
  130. package/src/components/resources/Patient/Patient.js +4 -0
  131. package/src/components/resources/Patient/Patient.stories.js +36 -28
  132. package/src/components/resources/Patient/Patient.test.js +31 -2
  133. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  134. package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
  135. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  136. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  137. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
  138. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  139. package/src/components/resources/Procedure/Procedure.js +3 -2
  140. package/src/components/resources/Procedure/Procedure.stories.js +33 -25
  141. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  142. package/src/components/resources/Questionnaire/Group.js +53 -0
  143. package/src/components/resources/Questionnaire/Items.js +45 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  145. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  146. package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
  147. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  148. package/src/components/resources/Questionnaire/Questions.js +40 -0
  149. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  150. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  151. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  152. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  154. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  155. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
  156. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  157. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  158. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  159. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  160. package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
  161. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  162. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  163. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -0
  164. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  165. package/src/components/resources/RelatedPerson/index.js +3 -0
  166. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  167. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
  168. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  169. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  170. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
  171. package/src/components/ui/index.js +48 -31
  172. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  173. package/src/fixtures/example-icons.jsx +42 -0
  174. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  175. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  176. package/src/style.scss +14 -1
  177. package/.storybook/addons.js +0 -1
  178. package/.storybook/config.js +0 -26
  179. package/.storybook/presets.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import Patient from './Patient';
5
5
 
@@ -15,44 +15,52 @@ import example3PatientR4 from '../../../fixtures/r4/resources/patient/example3.j
15
15
  import PatientIcon from '../../../assets/containers/Patient/patient.svg';
16
16
  import fhirIcons from '../../../fixtures/example-icons';
17
17
 
18
- export default { title: 'Patient' };
18
+ export default {
19
+ title: 'Patient',
20
+ component: Patient,
21
+ argTypes: {
22
+ ...defaultArgTypes,
23
+ },
24
+ };
25
+
26
+ const Template = args => <Patient {...args} />;
19
27
 
20
- export const DefaultVisualizationDSTU2 = () => {
21
- const fhirResource = object('Resource', examplePatient);
22
- return (
23
- <Patient
24
- fhirResource={fhirResource}
25
- fhirIcons={require('../../../assets/containers/Patient/patient.svg')}
26
- />
27
- );
28
+ export const DefaultVisualizationDSTU2 = Template.bind({});
29
+ DefaultVisualizationDSTU2.args = {
30
+ fhirResource: examplePatient,
31
+ fhirIcons: require('../../../assets/containers/Patient/patient.svg'),
28
32
  };
29
33
 
30
- export const Example2OfDSTU2 = () => {
31
- const fhirResource = object('Resource', example2PatientDSTU2);
32
- return <Patient fhirResource={fhirResource} fhirIcons={PatientIcon} />;
34
+ export const Example2OfDSTU2 = Template.bind({});
35
+ Example2OfDSTU2.args = {
36
+ fhirResource: example2PatientDSTU2,
37
+ fhirIcons: PatientIcon,
33
38
  };
34
39
 
35
- export const ExampleSTU3 = () => {
36
- const fhirResource = object('Resource', examplePatientSTU3);
37
- return <Patient fhirResource={fhirResource} fhirIcons={fhirIcons} />;
40
+ export const ExampleSTU3 = Template.bind({});
41
+ ExampleSTU3.args = {
42
+ fhirResource: examplePatientSTU3,
43
+ fhirIcons: fhirIcons,
38
44
  };
39
45
 
40
- export const Example2STU3 = () => {
41
- const fhirResource = object('Resource', example2PatientSTU3);
42
- return <Patient fhirResource={fhirResource} fhirIcons={false} />;
46
+ export const Example2STU3 = Template.bind({});
47
+ Example2STU3.args = {
48
+ fhirResource: example2PatientSTU3,
49
+ fhirIcons: false,
43
50
  };
44
51
 
45
- export const Example1R4 = () => {
46
- const fhirResource = object('Resource', example1PatientR4);
47
- return <Patient fhirResource={fhirResource} fhirIcons={'random text'} />;
52
+ export const Example1R4 = Template.bind({});
53
+ Example1R4.args = {
54
+ fhirResource: example1PatientR4,
55
+ fhirIcons: 'random text',
48
56
  };
49
57
 
50
- export const Example2R4 = () => {
51
- const fhirResource = object('Resource', example2PatientR4);
52
- return <Patient fhirResource={fhirResource} />;
58
+ export const Example2R4 = Template.bind({});
59
+ Example2R4.args = {
60
+ fhirResource: example2PatientR4,
53
61
  };
54
62
 
55
- export const Example3R4 = () => {
56
- const fhirResource = object('Resource', example3PatientR4);
57
- return <Patient fhirResource={fhirResource} />;
63
+ export const Example3R4 = Template.bind({});
64
+ Example3R4.args = {
65
+ fhirResource: example3PatientR4,
58
66
  };
@@ -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,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
82
82
  }
83
83
  };
84
84
 
85
- const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
85
+ const Practitioner = ({
86
+ fhirResource,
87
+ fhirVersion,
88
+ fhirIcons,
89
+ onClick,
90
+ rawOnClick,
91
+ }) => {
86
92
  let fhirResourceData = {};
87
93
  try {
88
94
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -160,6 +166,8 @@ const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
160
166
  />
161
167
  }
162
168
  bodyContent={<Body tableData={tableData} />}
169
+ onClick={onClick}
170
+ rawOnClick={rawOnClick}
163
171
  />
164
172
  </Root>
165
173
  );
@@ -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 Practitioner from './Practitioner';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -14,66 +14,53 @@ import r4Example3 from '../../../fixtures/r4/resources/practitioner/example3.jso
14
14
  import PractitionerIcon from '../../../assets/containers/Practitioner/practitioner.svg';
15
15
  import fhirIcons from '../../../fixtures/example-icons';
16
16
 
17
- export default { title: 'Practitioner' };
17
+ export default {
18
+ title: 'Practitioner',
19
+ component: Practitioner,
20
+ argTypes: {
21
+ ...defaultArgTypes,
22
+ },
23
+ };
24
+
25
+ const Template = args => <Practitioner {...args} />;
18
26
 
19
- export const DefaultVisualizationDSTU2 = () => {
20
- const fhirResource = object('Resource', dstu2Example1);
21
- return (
22
- <Practitioner
23
- fhirVersion={fhirVersions.DSTU2}
24
- fhirResource={fhirResource}
25
- fhirIcons={require('../../../assets/containers/Practitioner/practitioner.svg')}
26
- />
27
- );
27
+ export const DefaultVisualizationDSTU2 = Template.bind({});
28
+ DefaultVisualizationDSTU2.args = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: dstu2Example1,
31
+ fhirIcons: require('../../../assets/containers/Practitioner/practitioner.svg'),
28
32
  };
29
33
 
30
- export const Example2OfDSTU2 = () => {
31
- const fhirResource = object('Resource', dstu2Example2);
32
- return (
33
- <Practitioner
34
- fhirVersion={fhirVersions.DSTU2}
35
- fhirResource={fhirResource}
36
- fhirIcons={PractitionerIcon}
37
- />
38
- );
34
+ export const Example2OfDSTU2 = Template.bind({});
35
+ Example2OfDSTU2.args = {
36
+ fhirVersion: fhirVersions.DSTU2,
37
+ fhirResource: dstu2Example2,
38
+ fhirIcons: PractitionerIcon,
39
39
  };
40
40
 
41
- export const ExampleOfSTU3 = () => {
42
- const fhirResource = object('Resource', stu3Example1);
43
- return (
44
- <Practitioner
45
- fhirVersion={fhirVersions.STU3}
46
- fhirResource={fhirResource}
47
- fhirIcons={fhirIcons}
48
- />
49
- );
41
+ export const ExampleOfSTU3 = Template.bind({});
42
+ ExampleOfSTU3.args = {
43
+ fhirVersion: fhirVersions.STU3,
44
+ fhirResource: stu3Example1,
45
+ fhirIcons: fhirIcons,
50
46
  };
51
47
 
52
- export const Example1OfR4 = () => {
53
- const fhirResource = object('Resource', r4Example1);
54
- return (
55
- <Practitioner
56
- fhirVersion={fhirVersions.R4}
57
- fhirResource={fhirResource}
58
- fhirIcons={false}
59
- />
60
- );
48
+ export const Example1OfR4 = Template.bind({});
49
+ Example1OfR4.args = {
50
+ fhirVersion: fhirVersions.R4,
51
+ fhirResource: r4Example1,
52
+ fhirIcons: false,
61
53
  };
62
54
 
63
- export const Example2OfR4 = () => {
64
- const fhirResource = object('Resource', r4Example2);
65
- return (
66
- <Practitioner
67
- fhirVersion={fhirVersions.R4}
68
- fhirResource={fhirResource}
69
- fhirIcons={'random text'}
70
- />
71
- );
55
+ export const Example2OfR4 = Template.bind({});
56
+ Example2OfR4.args = {
57
+ fhirVersion: fhirVersions.R4,
58
+ fhirResource: r4Example2,
59
+ fhirIcons: 'random text',
72
60
  };
73
61
 
74
- export const Example3OfR4 = () => {
75
- const fhirResource = object('Resource', r4Example3);
76
- return (
77
- <Practitioner fhirVersion={fhirVersions.R4} fhirResource={fhirResource} />
78
- );
62
+ export const Example3OfR4 = Template.bind({});
63
+ Example3OfR4.args = {
64
+ fhirVersion: fhirVersions.R4,
65
+ fhirResource: r4Example3,
79
66
  };
@@ -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,13 @@ 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
+ rawOnClick,
52
+ }) => {
47
53
  let fhirResourceData = {};
48
54
  try {
49
55
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -58,34 +64,51 @@ const PractitionerRole = props => {
58
64
  organization,
59
65
  practitioner,
60
66
  } = fhirResourceData;
67
+
68
+ const tableData = [
69
+ {
70
+ label: 'Practitioner',
71
+ testId: 'practitioner',
72
+ data: practitioner && <Reference fhirData={practitioner} />,
73
+ status: practitioner,
74
+ },
75
+ {
76
+ label: 'Organization',
77
+ testId: 'organization',
78
+ data: organization && <Reference fhirData={organization} />,
79
+ status: organization,
80
+ },
81
+ {
82
+ label: 'Specialties',
83
+ testId: 'specialties',
84
+ data: specialties.length > 0 && (
85
+ <CodeableConcept fhirData={specialties} isCursive />
86
+ ),
87
+ status: specialties.length > 0,
88
+ },
89
+ {
90
+ label: 'Roles',
91
+ testId: 'roles',
92
+ data: codes.length > 0 && <CodeableConcept fhirData={codes} isCursive />,
93
+ status: codes.length > 0,
94
+ },
95
+ ];
96
+
61
97
  return (
62
98
  <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>
99
+ <Accordion
100
+ headerContent={
101
+ <Header
102
+ resourceName="PractitionerRole"
103
+ title="Practitioner roles and specialties"
104
+ badges={status && <Badge data-testid="status">{status}</Badge>}
105
+ icon={fhirIcons}
106
+ />
107
+ }
108
+ bodyContent={<Body tableData={tableData} />}
109
+ onClick={onClick}
110
+ rawOnClick={rawOnClick}
111
+ />
89
112
  </Root>
90
113
  );
91
114
  };
@@ -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 PractitionerRole from './PractitionerRole';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -12,75 +12,62 @@ 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
- export default { title: 'PractitionerRole' };
18
+ export default {
19
+ title: 'PractitionerRole',
20
+ component: PractitionerRole,
21
+ argTypes: {
22
+ ...defaultArgTypes,
23
+ },
24
+ };
25
+
26
+ const Template = args => <PractitionerRole {...args} />;
17
27
 
18
- export const ExampleOfSTU3 = () => {
19
- const fhirResource = object('Resource', stu3Example1);
20
- return (
21
- <PractitionerRole
22
- fhirVersion={fhirVersions.STU3}
23
- fhirResource={fhirResource}
24
- />
25
- );
28
+ export const ExampleOfSTU3 = Template.bind({});
29
+ ExampleOfSTU3.args = {
30
+ fhirVersion: fhirVersions.STU3,
31
+ fhirResource: stu3Example1,
32
+ fhirIcons: require('../../../assets/containers/PractitionerRole/practitioner-role.svg'),
26
33
  };
27
34
 
28
- export const Example2OfSTU3 = () => {
29
- const fhirResource = object('Resource', stu3Example2);
30
- return (
31
- <PractitionerRole
32
- fhirVersion={fhirVersions.STU3}
33
- fhirResource={fhirResource}
34
- />
35
- );
35
+ export const Example2OfSTU3 = Template.bind({});
36
+ Example2OfSTU3.args = {
37
+ fhirVersion: fhirVersions.STU3,
38
+ fhirResource: stu3Example2,
39
+ fhirIcons: PractitionerRoleIcon,
36
40
  };
37
41
 
38
- export const Example3OfSTU3 = () => {
39
- const fhirResource = object('Resource', stu3Example3);
40
- return (
41
- <PractitionerRole
42
- fhirVersion={fhirVersions.STU3}
43
- fhirResource={fhirResource}
44
- />
45
- );
42
+ export const Example3OfSTU3 = Template.bind({});
43
+ Example3OfSTU3.args = {
44
+ fhirVersion: fhirVersions.STU3,
45
+ fhirResource: stu3Example3,
46
+ fhirIcons: fhirIcons,
46
47
  };
47
48
 
48
- export const Example1OfR4 = () => {
49
- const fhirResource = object('Resource', r4Example1);
50
- return (
51
- <PractitionerRole
52
- fhirVersion={fhirVersions.R4}
53
- fhirResource={fhirResource}
54
- />
55
- );
49
+ export const Example1OfR4 = Template.bind({});
50
+ Example1OfR4.args = {
51
+ fhirVersion: fhirVersions.R4,
52
+ fhirResource: r4Example1,
53
+ fhirIcons: false,
56
54
  };
57
55
 
58
- export const Example2OfR4 = () => {
59
- const fhirResource = object('Resource', r4Example2);
60
- return (
61
- <PractitionerRole
62
- fhirVersion={fhirVersions.R4}
63
- fhirResource={fhirResource}
64
- />
65
- );
56
+ export const Example2OfR4 = Template.bind({});
57
+ Example2OfR4.args = {
58
+ fhirVersion: fhirVersions.R4,
59
+ fhirResource: r4Example2,
60
+ fhirIcons: 'random text',
66
61
  };
67
62
 
68
- export const Example3OfR4 = () => {
69
- const fhirResource = object('Resource', r4Example3);
70
- return (
71
- <PractitionerRole
72
- fhirVersion={fhirVersions.R4}
73
- fhirResource={fhirResource}
74
- />
75
- );
63
+ export const Example3OfR4 = Template.bind({});
64
+ Example3OfR4.args = {
65
+ fhirVersion: fhirVersions.R4,
66
+ fhirResource: r4Example3,
76
67
  };
77
68
 
78
- export const Example4OfR4 = () => {
79
- const fhirResource = object('Resource', r4Example4);
80
- return (
81
- <PractitionerRole
82
- fhirVersion={fhirVersions.R4}
83
- fhirResource={fhirResource}
84
- />
85
- );
69
+ export const Example4OfR4 = Template.bind({});
70
+ Example4OfR4.args = {
71
+ fhirVersion: fhirVersions.R4,
72
+ fhirResource: r4Example4,
86
73
  };
@@ -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
  });