fhir-react 0.3.5 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.stylelintrc +6 -2
  4. package/README.md +19 -1
  5. package/build/index.js +15 -11
  6. package/build/style.css +9 -8
  7. package/package.json +55 -54
  8. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  9. package/src/assets/containers/Coverage/coverage.svg +4 -0
  10. package/src/assets/containers/{ResourceCategory/resource-placeholder.svg → Generic/generic.svg} +0 -0
  11. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  12. package/src/assets/containers/MedicationOrder/medication-order.svg +5 -0
  13. package/src/assets/containers/MedicationRequest/medication-request.svg +5 -0
  14. package/src/assets/containers/Organization/organization.svg +5 -0
  15. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  16. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  17. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  18. package/src/assets/containers/ResourceCategory/resource-category.svg +3 -0
  19. package/src/components/containers/Accordion/Accordion.js +21 -13
  20. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  21. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  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/Identifier/Identifier.js +7 -3
  25. package/src/components/datatypes/Reference/Reference.js +7 -1
  26. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +81 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -5
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +5 -4
  32. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +107 -1
  33. package/src/components/resources/Appointment/Appointment.js +2 -1
  34. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  35. package/src/components/resources/Binary/Binary.js +1 -2
  36. package/src/components/resources/Binary/Binary.stories.js +10 -4
  37. package/src/components/resources/Binary/Binary.test.js +67 -0
  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 +12 -78
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +2 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +31 -5
  44. package/src/components/resources/CarePlan/CarePlan.test.js +114 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +72 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  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/CareTeam.js +55 -0
  50. package/src/components/resources/Claim/Claim.css +2 -11
  51. package/src/components/resources/Claim/Claim.js +158 -309
  52. package/src/components/resources/Claim/Claim.stories.js +37 -5
  53. package/src/components/resources/Claim/Claim.test.js +104 -1
  54. package/src/components/resources/Claim/Diagnosis.js +61 -0
  55. package/src/components/resources/Claim/Insurance.js +58 -0
  56. package/src/components/resources/Claim/Item.js +79 -0
  57. package/src/components/resources/Claim/Items.js +29 -0
  58. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  59. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  60. package/src/components/resources/ClaimResponse/ClaimResponse.js +137 -83
  61. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  62. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  63. package/src/components/resources/ClaimResponse/Item.js +44 -9
  64. package/src/components/resources/ClaimResponse/Items.js +5 -4
  65. package/src/components/resources/Condition/Condition.js +3 -3
  66. package/src/components/resources/Condition/Condition.test.js +37 -4
  67. package/src/components/resources/Coverage/Coverage.js +97 -69
  68. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  69. package/src/components/resources/Coverage/Coverage.test.js +111 -4
  70. package/src/components/resources/Device/Device.js +2 -1
  71. package/src/components/resources/Device/Device.stories.js +33 -5
  72. package/src/components/resources/Device/Device.test.js +108 -1
  73. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +7 -2
  74. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +5 -4
  75. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +107 -1
  76. package/src/components/resources/DocumentReference/DocumentReference.js +7 -2
  77. package/src/components/resources/DocumentReference/DocumentReference.stories.js +3 -2
  78. package/src/components/resources/DocumentReference/DocumentReference.test.js +113 -1
  79. package/src/components/resources/Encounter/Encounter.js +2 -1
  80. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  81. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +2 -0
  82. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +7 -2
  84. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +3 -2
  85. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +108 -1
  86. package/src/components/resources/Generic/Generic.js +20 -7
  87. package/src/components/resources/Generic/Generic.stories.js +2 -1
  88. package/src/components/resources/Generic/Generic.test.js +26 -7
  89. package/src/components/resources/Goal/Goal.js +3 -5
  90. package/src/components/resources/Goal/Goal.stories.js +5 -4
  91. package/src/components/resources/Goal/Goal.test.js +101 -1
  92. package/src/components/resources/Immunization/Immunization.js +2 -2
  93. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  94. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  95. package/src/components/resources/List/Entries.js +3 -3
  96. package/src/components/resources/List/List.js +135 -88
  97. package/src/components/resources/List/List.stories.js +38 -5
  98. package/src/components/resources/List/List.test.js +105 -1
  99. package/src/components/resources/Location/Location.js +65 -47
  100. package/src/components/resources/Location/Location.stories.js +11 -4
  101. package/src/components/resources/Location/Location.test.js +106 -4
  102. package/src/components/resources/Medication/Medication.js +91 -51
  103. package/src/components/resources/Medication/Medication.stories.js +37 -7
  104. package/src/components/resources/Medication/Medication.test.js +113 -4
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +86 -62
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  107. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  108. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  109. package/src/components/resources/MedicationDispense/MedicationDispense.js +68 -68
  110. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  111. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +115 -66
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  114. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  115. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +1 -2
  117. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +102 -4
  118. package/src/components/resources/MedicationRequest/MedicationRequest.js +3 -4
  119. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +11 -6
  120. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +100 -4
  121. package/src/components/resources/MedicationStatement/MedicationDosage.js +2 -2
  122. package/src/components/resources/MedicationStatement/MedicationStatement.js +8 -2
  123. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +5 -4
  124. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +108 -1
  125. package/src/components/resources/Observation/Observation.js +2 -1
  126. package/src/components/resources/Observation/Observation.test.js +30 -1
  127. package/src/components/resources/Organization/Organization.js +56 -37
  128. package/src/components/resources/Organization/Organization.stories.js +15 -2
  129. package/src/components/resources/Organization/Organization.test.js +109 -1
  130. package/src/components/resources/Patient/Patient.js +2 -0
  131. package/src/components/resources/Patient/Patient.test.js +31 -2
  132. package/src/components/resources/Practitioner/Practitioner.js +2 -1
  133. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  134. package/src/components/resources/PractitionerRole/PractitionerRole.js +50 -29
  135. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  136. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  137. package/src/components/resources/Procedure/Procedure.js +2 -2
  138. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  139. package/src/components/resources/Questionnaire/Group.js +53 -0
  140. package/src/components/resources/Questionnaire/Items.js +45 -0
  141. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  142. package/src/components/resources/Questionnaire/Questionnaire.js +31 -170
  143. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  145. package/src/components/resources/Questionnaire/Questions.js +40 -0
  146. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  147. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  148. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  149. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  150. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  151. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +52 -236
  152. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  154. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  155. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  156. package/src/components/resources/ReferralRequest/ReferralRequest.js +65 -40
  157. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  158. package/src/components/resources/RelatedPerson/RelatedPerson.js +151 -0
  159. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  160. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  161. package/src/components/resources/RelatedPerson/index.js +3 -0
  162. package/src/components/resources/ResearchStudy/ResearchStudy.js +160 -130
  163. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  164. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  165. package/src/components/resources/ResourceCategory/ResourceCategory.js +7 -12
  166. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +13 -2
  167. package/src/components/resources/ResourceCategory/ResourceCategory.test.js +77 -18
  168. package/src/components/ui/index.js +32 -12
  169. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  170. package/src/fixtures/example-icons.jsx +81 -11
  171. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  172. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  173. package/src/style.scss +3 -1
@@ -1,12 +1,84 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import AdverseEvent from './AdverseEvent';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import stu3Example1 from '../../../fixtures/stu3/resources/adverseEvent/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/adverseEvent/example1.json';
8
+ import fhirIcons from '../../../fixtures/example-icons';
8
9
 
9
10
  describe('should render component correctly', () => {
11
+ it('component without a fhirIcons props should render a default icon', () => {
12
+ const defaultProps = {
13
+ fhirVersion: fhirVersions.STU3,
14
+ fhirResource: stu3Example1,
15
+ };
16
+
17
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
18
+ const headerIcon = getByAltText('adverse event');
19
+
20
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
21
+ });
22
+
23
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
24
+ const defaultProps = {
25
+ fhirVersion: fhirVersions.STU3,
26
+ fhirResource: stu3Example1,
27
+ fhirIcons: false,
28
+ };
29
+
30
+ const { getByTestId } = render(<AdverseEvent {...defaultProps} />);
31
+ const headerIcon = getByTestId('placeholder');
32
+
33
+ expect(headerIcon).toBeTruthy();
34
+ });
35
+
36
+ it('component with the img as a fhirIcons props should render an img', () => {
37
+ const defaultProps = {
38
+ fhirVersion: fhirVersions.STU3,
39
+ fhirResource: stu3Example1,
40
+ fhirIcons: (
41
+ <img
42
+ src={require('../assets/containers/AdverseEvent/adverse-event.svg')}
43
+ alt="adverse event"
44
+ />
45
+ ),
46
+ };
47
+
48
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
49
+ const headerIcon = getByAltText('adverse event');
50
+
51
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
52
+ });
53
+
54
+ it('component with the resources object as a fhirIcons props should render an img', () => {
55
+ const defaultProps = {
56
+ fhirVersion: fhirVersions.STU3,
57
+ fhirResource: stu3Example1,
58
+ fhirIcons: fhirIcons,
59
+ };
60
+
61
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
62
+ const headerIcon = getByAltText('adverse event');
63
+
64
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
65
+ });
66
+
67
+ it('component with the url as a fhirIcons props should render an img', () => {
68
+ const avatarSrc =
69
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
70
+ const defaultProps = {
71
+ fhirVersion: fhirVersions.STU3,
72
+ fhirResource: stu3Example1,
73
+ fhirIcons: avatarSrc,
74
+ };
75
+
76
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
77
+ const headerIcon = getByAltText('header icon');
78
+
79
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
80
+ });
81
+
10
82
  it('should render with STU3 source data', () => {
11
83
  const defaultProps = {
12
84
  fhirResource: stu3Example1,
@@ -18,7 +90,7 @@ describe('should render component correctly', () => {
18
90
 
19
91
  expect(getByTestId('date').textContent).toEqual('1/29/2017');
20
92
 
21
- expect(getByTestId('type').textContent).toContain('304386008');
93
+ expect(getByTestId('event').textContent).toContain('304386008');
22
94
 
23
95
  expect(getByTestId('description').textContent).toContain(
24
96
  'This was a mild rash',
@@ -44,4 +116,39 @@ describe('should render component correctly', () => {
44
116
 
45
117
  expect(getByTestId('actuality').textContent).toEqual('actual');
46
118
  });
119
+
120
+ it('should fire custom onClick function', () => {
121
+ const defaultProps = {
122
+ fhirResource: r4Example1,
123
+ fhirVersion: fhirVersions.R4,
124
+ };
125
+
126
+ const onClick = jest.fn();
127
+ const { getByRole } = render(
128
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
129
+ );
130
+ const accordion = getByRole('button');
131
+ fireEvent.click(accordion);
132
+
133
+ const attribute = accordion.getAttribute('data-bs-toggle');
134
+ expect(attribute).not.toEqual('collapse');
135
+ expect(onClick).toHaveBeenCalled();
136
+ });
137
+
138
+ it('should not fire custom onClick function', () => {
139
+ const defaultProps = {
140
+ fhirResource: r4Example1,
141
+ fhirVersion: fhirVersions.R4,
142
+ };
143
+
144
+ const onClick = 'test';
145
+ const { getByRole } = render(
146
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
147
+ );
148
+ const accordion = getByRole('button');
149
+ fireEvent.click(accordion);
150
+
151
+ const attribute = accordion.getAttribute('data-bs-toggle');
152
+ expect(attribute).toEqual('collapse');
153
+ });
47
154
  });
@@ -123,9 +123,12 @@ const resourceDTO = (fhirVersion, fhirResource) => {
123
123
  }
124
124
  };
125
125
 
126
- const AllergyIntolerance = props => {
127
- const { fhirResource, fhirVersion, fhirIcons } = props;
128
- const headerIcon = fhirIcons && fhirIcons['AllergyIntolerance'];
126
+ const AllergyIntolerance = ({
127
+ fhirResource,
128
+ fhirVersion,
129
+ fhirIcons,
130
+ onClick,
131
+ }) => {
129
132
  let fhirResourceData = {};
130
133
  try {
131
134
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -219,10 +222,10 @@ const AllergyIntolerance = props => {
219
222
  <Accordion
220
223
  headerContent={
221
224
  <Header
222
- resourceName="AllergyIntollerance"
225
+ resourceName="AllergyIntolerance"
223
226
  badges={status && <Badge data-testid="status">{status}</Badge>}
224
227
  title={title}
225
- icon={headerIcon}
228
+ icon={fhirIcons}
226
229
  rightAdditionalContent={
227
230
  recordedDate && (
228
231
  <BadgeSecondary data-testid="recordedDate">
@@ -233,6 +236,7 @@ const AllergyIntolerance = props => {
233
236
  />
234
237
  }
235
238
  bodyContent={<Body tableData={tableData} />}
239
+ onClick={onClick}
236
240
  />
237
241
  </Root>
238
242
  );
@@ -12,6 +12,7 @@ import example2AllergyIntoleranceR4 from '../../../fixtures/r4/resources/allergy
12
12
  import example3AllergyIntoleranceR4 from '../../../fixtures/r4/resources/allergyIntolerance/example3.json';
13
13
  import fhirIcons from '../../../fixtures/example-icons';
14
14
  import fhirVersions from '../fhirResourceVersions';
15
+ import AllergyIntoleranceIcon from '../../../assets/containers/AllergyIntolerance/allergy-intolerance.svg';
15
16
 
16
17
  export default { title: 'AllergyIntolerance' };
17
18
 
@@ -21,7 +22,7 @@ export const DefaultVisualizationDSTU2 = () => {
21
22
  <AllergyIntolerance
22
23
  fhirVersion={fhirVersions.DSTU2}
23
24
  fhirResource={fhirResource}
24
- fhirIcons={fhirIcons}
25
+ fhirIcons={require('../../../assets/containers/AllergyIntolerance/allergy-intolerance.svg')}
25
26
  />
26
27
  );
27
28
  };
@@ -32,7 +33,7 @@ export const Example2ofDSTU2 = () => {
32
33
  <AllergyIntolerance
33
34
  fhirVersion={fhirVersions.DSTU2}
34
35
  fhirResource={fhirResource}
35
- fhirIcons={fhirIcons}
36
+ fhirIcons={AllergyIntoleranceIcon}
36
37
  />
37
38
  );
38
39
  };
@@ -54,7 +55,7 @@ export const Example2DiagnosticReportSTU3 = () => {
54
55
  <AllergyIntolerance
55
56
  fhirVersion={fhirVersions.STU3}
56
57
  fhirResource={fhirResource}
57
- fhirIcons={fhirIcons}
58
+ fhirIcons={false}
58
59
  />
59
60
  );
60
61
  };
@@ -65,7 +66,7 @@ export const Example1R4 = () => {
65
66
  <AllergyIntolerance
66
67
  fhirVersion={fhirVersions.R4}
67
68
  fhirResource={fhirResource}
68
- fhirIcons={fhirIcons}
69
+ fhirIcons={'random text'}
69
70
  />
70
71
  );
71
72
  };
@@ -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 AllergyIntolerance from './AllergyIntolerance';
4
4
 
5
5
  import exampleAllergyIntoleranceDSTU2 from '../../../fixtures/dstu2/resources/allergyIntolerance/example1.json';
@@ -7,8 +7,79 @@ import exampleAllergyIntoleranceSTU3 from '../../../fixtures/stu3/resources/alle
7
7
  import exampleAllergyIntoleranceR4 from '../../../fixtures/r4/resources/allergyIntolerance/example1.json';
8
8
  import example2AllergyIntoleranceR4 from '../../../fixtures/r4/resources/allergyIntolerance/example3.json';
9
9
  import fhirVersions from '../fhirResourceVersions';
10
+ import fhirIcons from '../../../fixtures/example-icons';
10
11
 
11
12
  describe('should render component correctly', () => {
13
+ it('component without a fhirIcons props should render a default icon', () => {
14
+ const defaultProps = {
15
+ fhirResource: exampleAllergyIntoleranceDSTU2,
16
+ fhirVersion: fhirVersions.DSTU2,
17
+ };
18
+
19
+ const { getByAltText } = render(<AllergyIntolerance {...defaultProps} />);
20
+ const headerIcon = getByAltText('allergy intolerance');
21
+
22
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
23
+ });
24
+
25
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
26
+ const defaultProps = {
27
+ fhirResource: exampleAllergyIntoleranceDSTU2,
28
+ fhirVersion: fhirVersions.DSTU2,
29
+ fhirIcons: false,
30
+ };
31
+
32
+ const { getByTestId } = render(<AllergyIntolerance {...defaultProps} />);
33
+ const headerIcon = getByTestId('placeholder');
34
+
35
+ expect(headerIcon).toBeTruthy();
36
+ });
37
+
38
+ it('component with the img as a fhirIcons props should render an img', () => {
39
+ const defaultProps = {
40
+ fhirResource: exampleAllergyIntoleranceDSTU2,
41
+ fhirVersion: fhirVersions.DSTU2,
42
+ fhirIcons: (
43
+ <img
44
+ src={require('../assets/containers/AllergyIntolerance/allergy-intolerance.svg')}
45
+ alt="allergy intolerance"
46
+ />
47
+ ),
48
+ };
49
+
50
+ const { getByAltText } = render(<AllergyIntolerance {...defaultProps} />);
51
+ const headerIcon = getByAltText('allergy intolerance');
52
+
53
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
54
+ });
55
+
56
+ it('component with the resources object as a fhirIcons props should render an img', () => {
57
+ const defaultProps = {
58
+ fhirResource: exampleAllergyIntoleranceDSTU2,
59
+ fhirVersion: fhirVersions.DSTU2,
60
+ fhirIcons: fhirIcons,
61
+ };
62
+
63
+ const { getByAltText } = render(<AllergyIntolerance {...defaultProps} />);
64
+ const headerIcon = getByAltText('allergy intolerance');
65
+
66
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
67
+ });
68
+
69
+ it('component with the url as a fhirIcons props should render an img', () => {
70
+ const avatarSrc =
71
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
72
+ const defaultProps = {
73
+ fhirResource: exampleAllergyIntoleranceDSTU2,
74
+ fhirVersion: fhirVersions.DSTU2,
75
+ fhirIcons: avatarSrc,
76
+ };
77
+
78
+ const { getByAltText } = render(<AllergyIntolerance {...defaultProps} />);
79
+ const headerIcon = getByAltText('header icon');
80
+
81
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
82
+ });
12
83
  it('should render with DSTU2 source data', () => {
13
84
  const defaultProps = {
14
85
  fhirResource: exampleAllergyIntoleranceDSTU2,
@@ -130,4 +201,39 @@ describe('should render component correctly', () => {
130
201
 
131
202
  expect(queryByTestId('asserter')).toBeNull();
132
203
  });
204
+
205
+ it('should fire custom onClick function', () => {
206
+ const defaultProps = {
207
+ fhirResource: example2AllergyIntoleranceR4,
208
+ fhirVersion: fhirVersions.R4,
209
+ };
210
+
211
+ const onClick = jest.fn();
212
+ const { getByRole } = render(
213
+ <AllergyIntolerance {...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: example2AllergyIntoleranceR4,
226
+ fhirVersion: fhirVersions.R4,
227
+ };
228
+
229
+ const onClick = 'test';
230
+ const { getByRole } = render(
231
+ <AllergyIntolerance {...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
+ });
133
239
  });
@@ -144,7 +144,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
144
144
  }
145
145
  };
146
146
 
147
- const Appointment = ({ fhirResource, fhirVersion, fhirIcons }) => {
147
+ const Appointment = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
148
148
  const {
149
149
  description,
150
150
  status,
@@ -253,6 +253,7 @@ const Appointment = ({ fhirResource, fhirVersion, fhirIcons }) => {
253
253
  )}
254
254
  </Body>
255
255
  }
256
+ onClick={onClick}
256
257
  />
257
258
  </Root>
258
259
  );
@@ -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 Appointment from './Appointment';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
@@ -231,4 +231,39 @@ describe('should render component correctly', () => {
231
231
 
232
232
  expect(getByTestId('reason').textContent).toContain('Clinical Review');
233
233
  });
234
+
235
+ it('should fire custom onClick function', () => {
236
+ const defaultProps = {
237
+ fhirResource: example3AppointmentR4,
238
+ fhirVersion: fhirVersions.R4,
239
+ };
240
+
241
+ const onClick = jest.fn();
242
+ const { getByRole } = render(
243
+ <Appointment {...defaultProps} onClick={onClick} />,
244
+ );
245
+ const accordion = getByRole('button');
246
+ fireEvent.click(accordion);
247
+
248
+ const attribute = accordion.getAttribute('data-bs-toggle');
249
+ expect(attribute).not.toEqual('collapse');
250
+ expect(onClick).toHaveBeenCalled();
251
+ });
252
+
253
+ it('should not fire custom onClick function', () => {
254
+ const defaultProps = {
255
+ fhirResource: example3AppointmentR4,
256
+ fhirVersion: fhirVersions.R4,
257
+ };
258
+
259
+ const onClick = 'test';
260
+ const { getByRole } = render(
261
+ <Appointment {...defaultProps} onClick={onClick} />,
262
+ );
263
+ const accordion = getByRole('button');
264
+ fireEvent.click(accordion);
265
+
266
+ const attribute = accordion.getAttribute('data-bs-toggle');
267
+ expect(attribute).toEqual('collapse');
268
+ });
234
269
  });
@@ -7,7 +7,6 @@ import { Body, Header } from '../../ui';
7
7
 
8
8
  const Binary = props => {
9
9
  const { fhirResource, fhirIcons } = props;
10
- const headerIcon = fhirIcons && fhirIcons['Binary'];
11
10
 
12
11
  const loadBinaryFile = () => {
13
12
  switch (fhirResource.contentType) {
@@ -34,7 +33,7 @@ const Binary = props => {
34
33
  <Header
35
34
  resourceName="Binary"
36
35
  title={`Binary file: ${fhirResource.contentType}`}
37
- icon={headerIcon}
36
+ icon={fhirIcons}
38
37
  />
39
38
  }
40
39
  bodyContent={<Body>{loadBinaryFile()}</Body>}
@@ -9,6 +9,7 @@ import stu3ExamplePdf from '../../../fixtures/stu3/resources/binary/example-pdf.
9
9
  import stu3ExampleJpeg from '../../../fixtures/stu3/resources/binary/example-jpeg.json';
10
10
  import stu3ExampleJson from '../../../fixtures/stu3/resources/binary/example-json.json';
11
11
  import fhirIcons from '../../../fixtures/example-icons';
12
+ import BinaryIcon from '../../../assets/containers/Binary/binary.svg';
12
13
 
13
14
  export default {
14
15
  title: 'Binary',
@@ -16,22 +17,27 @@ export default {
16
17
 
17
18
  export const PdfDSTU2 = () => {
18
19
  const fhirResource = object('Resource', dstu2ExamplePdf);
19
- return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
20
+ return (
21
+ <Binary
22
+ fhirResource={fhirResource}
23
+ fhirIcons={require('../../../assets/containers/Binary/binary.svg')}
24
+ />
25
+ );
20
26
  };
21
27
 
22
28
  export const JpegDSTU2 = () => {
23
29
  const fhirResource = object('Resource', dstu2ExampleJpeg);
24
- return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
30
+ return <Binary fhirResource={fhirResource} fhirIcons={BinaryIcon} />;
25
31
  };
26
32
 
27
33
  export const PdfSTU3 = () => {
28
34
  const fhirResource = object('Resource', stu3ExamplePdf);
29
- return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
35
+ return <Binary fhirResource={fhirResource} fhirIcons={false} />;
30
36
  };
31
37
 
32
38
  export const JpegSTU3 = () => {
33
39
  const fhirResource = object('Resource', stu3ExampleJpeg);
34
- return <Binary fhirResource={fhirResource} fhirIcons={fhirIcons} />;
40
+ return <Binary fhirResource={fhirResource} fhirIcons={'random text'} />;
35
41
  };
36
42
 
37
43
  export const JsonSTU3 = () => {
@@ -5,8 +5,75 @@ import Binary from './Binary';
5
5
  import stu3ExamplePdf from '../../../fixtures/stu3/resources/binary/example-pdf.json';
6
6
  import stu3ExampleJpeg from '../../../fixtures/stu3/resources/binary/example-jpeg.json';
7
7
  import stu3ExampleJson from '../../../fixtures/stu3/resources/binary/example-json.json';
8
+ import fhirIcons from '../../../fixtures/example-icons';
8
9
 
9
10
  describe('should render component correctly', () => {
11
+ it('component without a fhirIcons props should render a default icon', () => {
12
+ const defaultProps = {
13
+ fhirResource: stu3ExamplePdf,
14
+ };
15
+
16
+ const { getByAltText } = render(<Binary {...defaultProps} />);
17
+ const headerIcon = getByAltText('binary');
18
+
19
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
20
+ });
21
+
22
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
23
+ const defaultProps = {
24
+ fhirResource: stu3ExamplePdf,
25
+ fhirIcons: false,
26
+ };
27
+
28
+ const { getByTestId } = render(<Binary {...defaultProps} />);
29
+ const headerIcon = getByTestId('placeholder');
30
+
31
+ expect(headerIcon).toBeTruthy();
32
+ });
33
+
34
+ it('component with the img as a fhirIcons props should render an img', () => {
35
+ const defaultProps = {
36
+ fhirResource: stu3ExamplePdf,
37
+ fhirIcons: (
38
+ <img
39
+ src={require('../assets/containers/Binary/binary.svg')}
40
+ alt="binary"
41
+ />
42
+ ),
43
+ };
44
+
45
+ const { getByAltText } = render(<Binary {...defaultProps} />);
46
+ const headerIcon = getByAltText('binary');
47
+
48
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
49
+ });
50
+
51
+ it('component with the resources object as a fhirIcons props should render an img', () => {
52
+ const defaultProps = {
53
+ fhirResource: stu3ExamplePdf,
54
+ fhirIcons: fhirIcons,
55
+ };
56
+
57
+ const { getByAltText } = render(<Binary {...defaultProps} />);
58
+ const headerIcon = getByAltText('binary');
59
+
60
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
61
+ });
62
+
63
+ it('component with the url as a fhirIcons props should render an img', () => {
64
+ const avatarSrc =
65
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
66
+ const defaultProps = {
67
+ fhirResource: stu3ExamplePdf,
68
+ fhirIcons: avatarSrc,
69
+ };
70
+
71
+ const { getByAltText } = render(<Binary {...defaultProps} />);
72
+ const headerIcon = getByAltText('header icon');
73
+
74
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
75
+ });
76
+
10
77
  it('PDF binary file', () => {
11
78
  const { container } = render(<Binary fhirResource={stu3ExamplePdf} />);
12
79
  expect(container).not.toBe(null);
@@ -1,3 +1,10 @@
1
1
  .fhir-resource__Bundle__item {
2
2
  margin-top: 10px;
3
3
  }
4
+
5
+ .fhir-resource__Bundle__rootPadding:first-of-type {
6
+ padding: 8px;
7
+ background: white;
8
+ border-radius: 0.2rem;
9
+ border: 1px solid #dee2e6;
10
+ }
@@ -4,12 +4,12 @@ import _get from 'lodash/get';
4
4
 
5
5
  import fhirVersions from '../fhirResourceVersions';
6
6
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
7
- import { Root, Header, Title, Badge, Body, BadgeSecondary } from '../../ui';
7
+ import { Root, Header, Badge, Body, BadgeSecondary } from '../../ui';
8
8
  import * as FhirResourceTypes from '../../supportedFhirResourceList';
9
9
 
10
10
  import './Bundle.css';
11
11
 
12
- export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
12
+ export default function Bundle({ fhirResource, fhirVersion }) {
13
13
  const commonDTO = fhirResource => {
14
14
  const type = _get(fhirResource, 'type', null);
15
15
  const total = _get(fhirResource, 'total');
@@ -51,11 +51,14 @@ export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
51
51
  .filter(Boolean);
52
52
 
53
53
  return (
54
- <Root name="Bundle">
55
- <Header>
56
- {type && <Title data-testid="title">{type}</Title>}
57
- {total && <Badge data-testid="total">{total}</Badge>}
58
- </Header>
54
+ <Root name="Bundle" className="fhir-resource__Bundle__rootPadding">
55
+ <Header
56
+ resourceName="Bundle"
57
+ title={type}
58
+ badges={!isNaN(total) && <Badge data-testid="total">{total}</Badge>}
59
+ capitalize
60
+ isNoIcon
61
+ />
59
62
  <Body>
60
63
  {resources.length > 0 &&
61
64
  resources.map((resource, index) => {
@@ -71,14 +74,15 @@ export default function Bundle({ fhirResource, fhirVersion, fhirIcons }) {
71
74
  key={`${resource.id}-${index}`}
72
75
  >
73
76
  {resourceType && (
74
- <BadgeSecondary data-testid="resourceType">
75
- {resourceType}
76
- </BadgeSecondary>
77
+ <div className="mx-20">
78
+ <BadgeSecondary data-testid="resourceType">
79
+ {resourceType}
80
+ </BadgeSecondary>
81
+ </div>
77
82
  )}
78
83
  <FhirComponent
79
84
  fhirResource={resource}
80
85
  fhirVersion={fhirVersion}
81
- fhirIcons={fhirIcons}
82
86
  />
83
87
  </div>
84
88
  );