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 { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
 
4
4
  import MedicationRequest from './MedicationRequest';
5
5
 
@@ -87,7 +87,7 @@ describe('should render MedicationRequest component properly', () => {
87
87
  );
88
88
  expect(container).not.toBeNull();
89
89
 
90
- expect(getByTestId('title').textContent).toContain('Medication/med0316');
90
+ expect(getByTestId('title').textContent).toContain('prescribed medication');
91
91
  expect(getByTestId('reasonCode').textContent).toContain(
92
92
  'Essential hypertension',
93
93
  );
@@ -118,7 +118,7 @@ describe('should render MedicationRequest component properly', () => {
118
118
  );
119
119
  expect(container).not.toBeNull();
120
120
 
121
- expect(getByTestId('title').textContent).toContain('Medication/med0316');
121
+ expect(getByTestId('title').textContent).toContain('prescribed medication');
122
122
  expect(getByTestId('reasonCode').textContent).toContain(
123
123
  'Essential hypertension',
124
124
  );
@@ -160,7 +160,7 @@ describe('should render MedicationRequest component properly', () => {
160
160
  );
161
161
  expect(container).not.toBeNull();
162
162
 
163
- expect(getByTestId('title').textContent).toContain('#med0304');
163
+ expect(getByTestId('title').textContent).toContain('Myleran 2mg tablet');
164
164
  expect(getByTestId('reasonCode').textContent).toContain(
165
165
  'Chronic myeloid Leukemia',
166
166
  );
@@ -171,4 +171,33 @@ describe('should render MedicationRequest component properly', () => {
171
171
  expect(getByTestId('created').textContent).toEqual('1/15/2015');
172
172
  expect(getByTestId('intent').textContent).toEqual('order');
173
173
  });
174
+
175
+ it('should fire custom onClick function', () => {
176
+ const defaultProps = { fhirResource: r4Example3 };
177
+
178
+ const onClick = jest.fn();
179
+ const { getByRole } = render(
180
+ <MedicationRequest {...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).not.toEqual('collapse');
187
+ expect(onClick).toHaveBeenCalled();
188
+ });
189
+
190
+ it('should not fire custom onClick function', () => {
191
+ const defaultProps = { fhirResource: r4Example3 };
192
+
193
+ const onClick = 'test';
194
+ const { getByRole } = render(
195
+ <MedicationRequest {...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
+ });
174
203
  });
@@ -107,8 +107,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
107
107
  }
108
108
  };
109
109
 
110
- const MedicationStatement = props => {
111
- const { fhirResource, fhirVersion, fhirIcons } = props;
110
+ const MedicationStatement = ({
111
+ fhirResource,
112
+ fhirVersion,
113
+ fhirIcons,
114
+ onClick,
115
+ rawOnClick,
116
+ }) => {
112
117
  let fhirResourceData = {};
113
118
  try {
114
119
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -200,6 +205,8 @@ const MedicationStatement = props => {
200
205
  })}
201
206
  </Body>
202
207
  }
208
+ onClick={onClick}
209
+ rawOnClick={rawOnClick}
203
210
  />
204
211
  </Root>
205
212
  );
@@ -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 MedicationStatement from './MedicationStatement';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -14,59 +14,45 @@ import MedicationStatementIcon from '../../../assets/containers/MedicationStatem
14
14
 
15
15
  export default {
16
16
  title: 'MedicationStatement',
17
+ component: MedicationStatement,
18
+ argTypes: {
19
+ ...defaultArgTypes,
20
+ },
17
21
  };
18
22
 
19
- export const DefaultVisualizationDSTU2 = () => {
20
- const fhirResource = object('Resource', dstu2Example1);
21
- return (
22
- <MedicationStatement
23
- fhirVersion={fhirVersions.DSTU2}
24
- fhirResource={fhirResource}
25
- fhirIcons={require('../../../assets/containers/MedicationStatement/medication-statement.svg')}
26
- />
27
- );
23
+ const Template = args => <MedicationStatement {...args} />;
24
+
25
+ export const DefaultVisualizationDSTU2 = Template.bind({});
26
+ DefaultVisualizationDSTU2.args = {
27
+ fhirVersion: fhirVersions.DSTU2,
28
+ fhirResource: dstu2Example1,
29
+ fhirIcons: require('../../../assets/containers/MedicationStatement/medication-statement.svg'),
28
30
  };
29
31
 
30
- export const ExampleOfSTU3 = () => {
31
- const fhirResource = object('Resource', stu3Example1);
32
- return (
33
- <MedicationStatement
34
- fhirVersion={fhirVersions.STU3}
35
- fhirResource={fhirResource}
36
- fhirIcons={MedicationStatementIcon}
37
- />
38
- );
32
+ export const ExampleOfSTU3 = Template.bind({});
33
+ ExampleOfSTU3.args = {
34
+ fhirVersion: fhirVersions.STU3,
35
+ fhirResource: stu3Example1,
36
+ fhirIcons: MedicationStatementIcon,
39
37
  };
40
38
 
41
- export const Example2OfSTU3 = () => {
42
- const fhirResource = object('Resource', stu3Example2);
43
- return (
44
- <MedicationStatement
45
- fhirVersion={fhirVersions.STU3}
46
- fhirResource={fhirResource}
47
- fhirIcons={fhirIcons}
48
- />
49
- );
39
+ export const Example2OfSTU3 = Template.bind({});
40
+ Example2OfSTU3.args = {
41
+ fhirVersion: fhirVersions.STU3,
42
+ fhirResource: stu3Example2,
43
+ fhirIcons: fhirIcons,
50
44
  };
51
45
 
52
- export const Example1OfR4 = () => {
53
- const fhirResource = object('Resource', r4Example1);
54
- return (
55
- <MedicationStatement
56
- fhirVersion={fhirVersions.R4}
57
- fhirResource={fhirResource}
58
- fhirIcons={false}
59
- />
60
- );
46
+ export const Example1OfR4 = Template.bind({});
47
+ Example1OfR4.args = {
48
+ fhirVersion: fhirVersions.R4,
49
+ fhirResource: r4Example1,
50
+ fhirIcons: false,
61
51
  };
62
52
 
63
- export const Example2OfR4 = () => {
64
- const fhirResource = object('Resource', r4Example2);
65
- return (
66
- <MedicationStatement
67
- fhirVersion={fhirVersions.R4}
68
- fhirResource={fhirResource}
69
- fhirIcons={'random text'}
70
- />
71
- );
53
+ export const Example2OfR4 = Template.bind({});
54
+ Example2OfR4.args = {
55
+ fhirVersion: fhirVersions.R4,
56
+ fhirResource: r4Example2,
57
+ fhirIcons: 'random text',
72
58
  };
@@ -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 MedicationStatement from './MedicationStatement';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
  import example1MedicationStatement from '../../../fixtures/dstu2/resources/medicationStatement/example1.json';
@@ -168,4 +168,39 @@ describe('should render MedicationStatement component correctly', () => {
168
168
  '#med0309',
169
169
  );
170
170
  });
171
+
172
+ it('should fire custom onClick function', () => {
173
+ const defaultProps = {
174
+ fhirResource: r4Example1,
175
+ fhirVersion: fhirVersions.R4,
176
+ };
177
+
178
+ const onClick = jest.fn();
179
+ const { getByRole } = render(
180
+ <MedicationStatement {...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).not.toEqual('collapse');
187
+ expect(onClick).toHaveBeenCalled();
188
+ });
189
+
190
+ it('should not fire custom onClick function', () => {
191
+ const defaultProps = {
192
+ fhirResource: r4Example1,
193
+ fhirVersion: fhirVersions.R4,
194
+ };
195
+
196
+ const onClick = 'test';
197
+ const { getByRole } = render(
198
+ <MedicationStatement {...defaultProps} onClick={onClick} />,
199
+ );
200
+ const accordion = getByRole('button');
201
+ fireEvent.click(accordion);
202
+
203
+ const attribute = accordion.getAttribute('data-bs-toggle');
204
+ expect(attribute).toEqual('collapse');
205
+ });
171
206
  });
@@ -18,7 +18,7 @@ import {
18
18
  } from '../../ui';
19
19
  import Reference from '../../datatypes/Reference';
20
20
 
21
- const Observation = ({ fhirResource, fhirIcons }) => {
21
+ const Observation = ({ fhirResource, fhirIcons, onClick, rawOnClick }) => {
22
22
  const effectiveDate = _get(fhirResource, 'effectiveDateTime');
23
23
  const codeCodingDisplay = _get(fhirResource, 'code.coding.0.display');
24
24
  const codeText = _get(fhirResource, 'code.text', '');
@@ -114,6 +114,8 @@ const Observation = ({ fhirResource, fhirIcons }) => {
114
114
  />
115
115
  </Body>
116
116
  }
117
+ onClick={onClick}
118
+ rawOnClick={rawOnClick}
117
119
  />
118
120
  </Root>
119
121
  );
@@ -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 Observation from './Observation';
5
5
 
@@ -15,51 +15,57 @@ import example3ObservationExcessR4 from '../../../fixtures/r4/resources/observat
15
15
  import ObservationIcon from '../../../assets/containers/Observation/observation.svg';
16
16
  import fhirIcons from '../../../fixtures/example-icons';
17
17
 
18
- export default { title: 'Observation' };
18
+ export default {
19
+ title: 'Observation',
20
+ component: Observation,
21
+ argTypes: {
22
+ ...defaultArgTypes,
23
+ },
24
+ };
25
+
26
+ const Template = args => <Observation {...args} />;
19
27
 
20
- export const DefaultVisualizationDSTU2 = () => {
21
- const fhirResource = object('Resource', exampleObservationIssued);
22
- return (
23
- <Observation
24
- fhirResource={fhirResource}
25
- fhirIcons={require('../../../assets/containers/Observation/observation.svg')}
26
- />
27
- );
28
+ export const DefaultVisualizationDSTU2 = Template.bind({});
29
+ DefaultVisualizationDSTU2.args = {
30
+ fhirResource: exampleObservationIssued,
31
+ fhirIcons: require('../../../assets/containers/Observation/observation.svg'),
28
32
  };
29
33
 
30
- export const ExampleWithoutIssuedDSTU2 = () => {
31
- const fhirResource = object('Resource', exampleObservation);
32
- return (
33
- <Observation fhirResource={fhirResource} fhirIcons={ObservationIcon} />
34
- );
34
+ export const ExampleWithoutIssuedDSTU2 = Template.bind({});
35
+ ExampleWithoutIssuedDSTU2.args = {
36
+ fhirResource: exampleObservation,
37
+ fhirIcons: ObservationIcon,
35
38
  };
36
39
 
37
- export const ExampleWithIssuedSTU3 = () => {
38
- const fhirResource = object('Resource', exampleObservationExcessSTU3);
39
- return <Observation fhirResource={fhirResource} fhirIcons={fhirIcons} />;
40
+ export const ExampleWithIssuedSTU3 = Template.bind({});
41
+ ExampleWithIssuedSTU3.args = {
42
+ fhirResource: exampleObservationExcessSTU3,
43
+ fhirIcons: fhirIcons,
40
44
  };
41
45
 
42
- export const ExampleWithoutIssuedSTU3 = () => {
43
- const fhirResource = object('Resource', exampleObservationSTU3);
44
- return <Observation fhirResource={fhirResource} fhirIcons={false} />;
46
+ export const ExampleWithoutIssuedSTU3 = Template.bind({});
47
+ ExampleWithoutIssuedSTU3.args = {
48
+ fhirResource: exampleObservationSTU3,
49
+ fhirIcons: false,
45
50
  };
46
51
 
47
- export const Example3OfSTU3 = () => {
48
- const fhirResource = object('Resource', example3ObservationExcessSTU3);
49
- return <Observation fhirResource={fhirResource} fhirIcons={'random text'} />;
52
+ export const Example3OfSTU3 = Template.bind({});
53
+ Example3OfSTU3.args = {
54
+ fhirResource: example3ObservationExcessSTU3,
55
+ fhirIcons: 'random text',
50
56
  };
51
57
 
52
- export const Example1OfR4 = () => {
53
- const fhirResource = object('Resource', example1ObservationExcessR4);
54
- return <Observation fhirResource={fhirResource} />;
58
+ export const Example1OfR4 = Template.bind({});
59
+ Example1OfR4.args = {
60
+ fhirResource: example1ObservationExcessR4,
55
61
  };
56
62
 
57
- export const Example2OfR4 = () => {
58
- const fhirResource = object('Resource', example2ObservationExcessR4);
59
- return <Observation fhirResource={fhirResource} />;
63
+ export const Example2OfR4 = Template.bind({});
64
+ Example2OfR4.args = {
65
+ fhirResource: example2ObservationExcessR4,
60
66
  };
61
67
 
62
- export const Example3OfR4 = () => {
63
- const fhirResource = object('Resource', example3ObservationExcessR4);
64
- return <Observation fhirResource={fhirResource} />;
68
+ export const Example3OfR4 = Template.bind({});
69
+ Example3OfR4.args = {
70
+ fhirResource: example3ObservationExcessR4,
65
71
  };
@@ -2,7 +2,7 @@
2
2
  // NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
3
3
 
4
4
  import React from 'react';
5
- import { render } from '@testing-library/react';
5
+ import { fireEvent, render } from '@testing-library/react';
6
6
  import Observation from './Observation';
7
7
 
8
8
  import exampleObservationIssued from '../../../fixtures/dstu2/resources/observation/example-issued.json';
@@ -148,4 +148,33 @@ describe('should render component correctly', () => {
148
148
  expect(getByTestId('valueQuantityUnit')).not.toBeNull();
149
149
  expect(getByTestId('valueQuantityUnit').textContent).toEqual('mmol/l');
150
150
  });
151
+
152
+ it('should fire custom onClick function', () => {
153
+ const defaultProps = { fhirResource: example1ObservationExcessR4 };
154
+
155
+ const onClick = jest.fn();
156
+ const { getByRole } = render(
157
+ <Observation {...defaultProps} onClick={onClick} />,
158
+ );
159
+ const accordion = getByRole('button');
160
+ fireEvent.click(accordion);
161
+
162
+ const attribute = accordion.getAttribute('data-bs-toggle');
163
+ expect(attribute).not.toEqual('collapse');
164
+ expect(onClick).toHaveBeenCalled();
165
+ });
166
+
167
+ it('should not fire custom onClick function', () => {
168
+ const defaultProps = { fhirResource: example1ObservationExcessR4 };
169
+
170
+ const onClick = 'test';
171
+ const { getByRole } = render(
172
+ <Observation {...defaultProps} onClick={onClick} />,
173
+ );
174
+ const accordion = getByRole('button');
175
+ fireEvent.click(accordion);
176
+
177
+ const attribute = accordion.getAttribute('data-bs-toggle');
178
+ expect(attribute).toEqual('collapse');
179
+ });
151
180
  });
@@ -44,7 +44,7 @@ const observationValuePoint = (actualValue, unit, small) => {
44
44
  >
45
45
  {!small && (
46
46
  <span
47
- className={`position-absolute top-0 translate-middle ps-2 ${
47
+ className={`position-absolute top-0 translate-middle ps-sm-2 ps-0 pe-4 pe-sm-0 ${
48
48
  small ? 'pb-4 fs-1' : 'pb-5 fs-4'
49
49
  } w-max-content`}
50
50
  data-testid="valuePoint"
@@ -55,7 +55,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
55
55
  }
56
56
  };
57
57
 
58
- const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
58
+ const Organization = ({
59
+ fhirResource,
60
+ fhirVersion,
61
+ fhirIcons,
62
+ onClick,
63
+ rawOnClick,
64
+ }) => {
59
65
  let fhirResourceData = {};
60
66
  try {
61
67
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -79,7 +85,7 @@ const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
79
85
  {
80
86
  label: 'Identifiers',
81
87
  testId: 'identifier',
82
- data: identifier && <Identifier fhirData={identifier} noCursive />,
88
+ data: identifier && <Identifier fhirData={identifier} />,
83
89
  status: identifier,
84
90
  },
85
91
  {
@@ -127,6 +133,8 @@ const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
127
133
  )
128
134
  }
129
135
  bodyContent={<Body tableData={tableData} />}
136
+ onClick={onClick}
137
+ rawOnClick={rawOnClick}
130
138
  />
131
139
  </Root>
132
140
  );
@@ -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 Organization from './Organization';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -19,69 +19,57 @@ import OrganizationIcon from '../../../assets/containers/Organization/organizati
19
19
 
20
20
  export default {
21
21
  title: 'Organization',
22
+ component: Organization,
23
+ argTypes: {
24
+ ...defaultArgTypes,
25
+ },
22
26
  };
23
27
 
24
- export const DefaultVisualizationDSTU2 = () => {
25
- const fhirResource = object('Resource', dstu2Example1);
26
- return (
27
- <Organization
28
- fhirResource={fhirResource}
29
- fhirVersion={fhirVersions.DSTU2}
30
- fhirIcons={OrganizationIcon}
31
- />
32
- );
28
+ const Template = args => <Organization {...args} />;
29
+
30
+ export const DefaultVisualizationDSTU2 = Template.bind({});
31
+ DefaultVisualizationDSTU2.args = {
32
+ fhirVersion: fhirVersions.DSTU2,
33
+ fhirResource: dstu2Example1,
34
+ fhirIcons: require('../../../assets/containers/Organization/organization.svg'),
33
35
  };
34
36
 
35
- export const Example2OfDSTU2 = () => {
36
- const fhirResource = object('Resource', dstu2Example2);
37
- return (
38
- <Organization
39
- fhirResource={fhirResource}
40
- fhirVersion={fhirVersions.DSTU2}
41
- fhirIcons={fhirIcons}
42
- />
43
- );
37
+ export const Example2OfDSTU2 = Template.bind({});
38
+ Example2OfDSTU2.args = {
39
+ fhirVersion: fhirVersions.DSTU2,
40
+ fhirResource: dstu2Example2,
41
+ fhirIcons: OrganizationIcon,
44
42
  };
45
43
 
46
- export const Example1OfSTU3 = () => {
47
- const fhirResource = object('Resource', stu3Example1);
48
- return (
49
- <Organization
50
- fhirResource={fhirResource}
51
- fhirVersion={fhirVersions.STU3}
52
- fhirIcons={false}
53
- />
54
- );
44
+ export const Example1OfSTU3 = Template.bind({});
45
+ Example1OfSTU3.args = {
46
+ fhirVersion: fhirVersions.STU3,
47
+ fhirResource: stu3Example1,
48
+ fhirIcons: fhirIcons,
55
49
  };
56
50
 
57
- export const Example2OfSTU3 = () => {
58
- const fhirResource = object('Resource', stu3Example2);
59
- return (
60
- <Organization
61
- fhirResource={fhirResource}
62
- fhirVersion={fhirVersions.STU3}
63
- fhirIcons={'random text'}
64
- />
65
- );
51
+ export const Example2OfSTU3 = Template.bind({});
52
+ Example2OfSTU3.args = {
53
+ fhirVersion: fhirVersions.STU3,
54
+ fhirResource: stu3Example2,
55
+ fhirIcons: false,
66
56
  };
67
57
 
68
- export const Example1OfR4 = () => {
69
- const fhirResource = object('Resource', r4Example1);
70
- return (
71
- <Organization fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
72
- );
58
+ export const Example1OfR4 = Template.bind({});
59
+ Example1OfR4.args = {
60
+ fhirVersion: fhirVersions.R4,
61
+ fhirResource: r4Example1,
62
+ fhirIcons: 'random text',
73
63
  };
74
64
 
75
- export const Example2OfR4 = () => {
76
- const fhirResource = object('Resource', r4Example2);
77
- return (
78
- <Organization fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
79
- );
65
+ export const Example2OfR4 = Template.bind({});
66
+ Example2OfR4.args = {
67
+ fhirVersion: fhirVersions.R4,
68
+ fhirResource: r4Example2,
80
69
  };
81
70
 
82
- export const Example3OfR4 = () => {
83
- const fhirResource = object('Resource', r4Example3);
84
- return (
85
- <Organization fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
86
- );
71
+ export const Example3OfR4 = Template.bind({});
72
+ Example3OfR4.args = {
73
+ fhirVersion: fhirVersions.R4,
74
+ fhirResource: r4Example3,
87
75
  };
@@ -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,8 @@ function Patient(props) {
46
46
  renderName,
47
47
  patientSimple,
48
48
  fhirIcons,
49
+ onClick,
50
+ rawOnClick,
49
51
  } = props;
50
52
 
51
53
  const id = getId(fhirResource);
@@ -146,6 +148,8 @@ function Patient(props) {
146
148
  />
147
149
  }
148
150
  bodyContent={<Body tableData={tableData} />}
151
+ onClick={onClick}
152
+ rawOnClick={rawOnClick}
149
153
  />
150
154
  </Root>
151
155
  );