fhir-react 0.3.6 → 0.3.9

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 (160) 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 +11 -10
  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/Generic/generic.svg +3 -0
  11. package/src/assets/containers/Medication/medication.svg +5 -0
  12. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  13. package/src/assets/containers/Organization/organization.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/ResourceContainer/ResourceContainer.css +4 -0
  19. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  20. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +23 -1
  21. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  22. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  23. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  24. package/src/components/datatypes/Coding/Coding.js +7 -3
  25. package/src/components/datatypes/Identifier/Identifier.js +7 -3
  26. package/src/components/datatypes/Reference/Reference.js +7 -1
  27. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  28. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  29. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  30. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  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.test.js +36 -1
  35. package/src/components/resources/Binary/Binary.js +2 -1
  36. package/src/components/resources/Bundle/Bundle.css +7 -0
  37. package/src/components/resources/Bundle/Bundle.js +15 -11
  38. package/src/components/resources/Bundle/Bundle.stories.js +12 -78
  39. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  40. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  41. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  42. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  43. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  44. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  45. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  46. package/src/components/resources/Claim/CareTeam.js +55 -0
  47. package/src/components/resources/Claim/Claim.css +2 -11
  48. package/src/components/resources/Claim/Claim.js +165 -309
  49. package/src/components/resources/Claim/Claim.stories.js +37 -5
  50. package/src/components/resources/Claim/Claim.test.js +104 -1
  51. package/src/components/resources/Claim/Diagnosis.js +61 -0
  52. package/src/components/resources/Claim/Insurance.js +58 -0
  53. package/src/components/resources/Claim/Item.js +79 -0
  54. package/src/components/resources/Claim/Items.js +29 -0
  55. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  56. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  57. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  58. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  59. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  60. package/src/components/resources/ClaimResponse/Item.js +44 -9
  61. package/src/components/resources/ClaimResponse/Items.js +5 -4
  62. package/src/components/resources/Condition/Condition.js +10 -3
  63. package/src/components/resources/Condition/Condition.test.js +37 -4
  64. package/src/components/resources/Coverage/Coverage.js +104 -69
  65. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  66. package/src/components/resources/Coverage/Coverage.test.js +111 -4
  67. package/src/components/resources/Device/Device.js +9 -1
  68. package/src/components/resources/Device/Device.test.js +36 -1
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  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.test.js +42 -1
  73. package/src/components/resources/Encounter/Encounter.js +9 -1
  74. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  75. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  76. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  77. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  78. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  79. package/src/components/resources/Generic/Generic.js +21 -7
  80. package/src/components/resources/Generic/Generic.stories.js +2 -1
  81. package/src/components/resources/Generic/Generic.test.js +26 -7
  82. package/src/components/resources/Goal/Goal.js +9 -3
  83. package/src/components/resources/Goal/Goal.test.js +32 -1
  84. package/src/components/resources/Immunization/Immunization.js +9 -2
  85. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  86. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  87. package/src/components/resources/List/Entries.js +3 -3
  88. package/src/components/resources/List/List.js +137 -88
  89. package/src/components/resources/List/List.stories.js +38 -5
  90. package/src/components/resources/List/List.test.js +105 -1
  91. package/src/components/resources/Location/Location.js +66 -47
  92. package/src/components/resources/Location/Location.stories.js +11 -4
  93. package/src/components/resources/Location/Location.test.js +106 -4
  94. package/src/components/resources/Medication/Medication.js +98 -51
  95. package/src/components/resources/Medication/Medication.stories.js +37 -7
  96. package/src/components/resources/Medication/Medication.test.js +114 -5
  97. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  98. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  99. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  100. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  101. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  102. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  103. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  104. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  105. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  106. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  107. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  108. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  109. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  110. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  111. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  112. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  113. package/src/components/resources/Observation/Observation.js +3 -1
  114. package/src/components/resources/Observation/Observation.test.js +30 -1
  115. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  116. package/src/components/resources/Organization/Organization.js +63 -37
  117. package/src/components/resources/Organization/Organization.stories.js +15 -2
  118. package/src/components/resources/Organization/Organization.test.js +109 -1
  119. package/src/components/resources/Patient/Patient.js +4 -0
  120. package/src/components/resources/Patient/Patient.test.js +31 -2
  121. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  122. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  123. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  124. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  125. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  126. package/src/components/resources/Procedure/Procedure.js +3 -2
  127. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  128. package/src/components/resources/Questionnaire/Group.js +53 -0
  129. package/src/components/resources/Questionnaire/Items.js +45 -0
  130. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  131. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  132. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  133. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  134. package/src/components/resources/Questionnaire/Questions.js +40 -0
  135. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  136. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  137. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  138. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  139. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  140. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  141. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  142. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  143. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  144. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  145. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  146. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  147. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  148. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  149. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  150. package/src/components/resources/RelatedPerson/index.js +3 -0
  151. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  152. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  153. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  154. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  155. package/src/components/ui/index.js +56 -32
  156. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  157. package/src/fixtures/example-icons.jsx +63 -0
  158. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  159. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  160. package/src/style.scss +14 -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 ClaimResponse from './ClaimResponse';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -10,8 +10,84 @@ import stu3Example2 from '../../../fixtures/stu3/resources/claimResponse/example
10
10
  import r4Example1 from '../../../fixtures/r4/resources/claimResponse/example1.json';
11
11
  import r4Example2 from '../../../fixtures/r4/resources/claimResponse/example2.json';
12
12
  import r4Example3 from '../../../fixtures/r4/resources/claimResponse/example3.json';
13
+ import fhirIcons from '../../../fixtures/example-icons';
13
14
 
14
15
  describe('should render the ClaimResponse component properly', () => {
16
+ it('component without a fhirIcons props should render a default icon', () => {
17
+ const defaultProps = {
18
+ fhirVersion: fhirVersions.DSTU2,
19
+ fhirResource: dstu2Example1,
20
+ };
21
+
22
+ const { getByAltText } = render(<ClaimResponse {...defaultProps} />);
23
+ const headerIcon = getByAltText('claim response');
24
+
25
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
26
+ });
27
+
28
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
29
+ const defaultProps = {
30
+ fhirVersion: fhirVersions.DSTU2,
31
+ fhirResource: dstu2Example1,
32
+ fhirIcons: false,
33
+ };
34
+
35
+ const { getByTestId } = render(<ClaimResponse {...defaultProps} />);
36
+ const headerIcon = getByTestId('placeholder');
37
+
38
+ expect(headerIcon).toBeTruthy();
39
+ });
40
+
41
+ it('component with the img as a fhirIcons props should render an img', () => {
42
+ const defaultProps = {
43
+ fhirVersion: fhirVersions.DSTU2,
44
+ fhirResource: dstu2Example1,
45
+ fhirIcons: (
46
+ <img
47
+ src={require('../assets/containers/ClaimResponse/claim-response.svg')}
48
+ alt="clipboard with a symmetrical cross and a return arrow"
49
+ />
50
+ ),
51
+ };
52
+
53
+ const { getByAltText } = render(<ClaimResponse {...defaultProps} />);
54
+ const headerIcon = getByAltText(
55
+ 'clipboard with a symmetrical cross and a return arrow',
56
+ );
57
+
58
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
59
+ });
60
+
61
+ it('component with the resources object as a fhirIcons props should render an img', () => {
62
+ const defaultProps = {
63
+ fhirVersion: fhirVersions.DSTU2,
64
+ fhirResource: dstu2Example1,
65
+ fhirIcons: fhirIcons,
66
+ };
67
+
68
+ const { getByAltText } = render(<ClaimResponse {...defaultProps} />);
69
+ const headerIcon = getByAltText(
70
+ 'clipboard with a symmetrical cross and a return arrow',
71
+ );
72
+
73
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
74
+ });
75
+
76
+ it('component with the url as a fhirIcons props should render an img', () => {
77
+ const avatarSrc =
78
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
79
+ const defaultProps = {
80
+ fhirVersion: fhirVersions.DSTU2,
81
+ fhirResource: dstu2Example1,
82
+ fhirIcons: avatarSrc,
83
+ };
84
+
85
+ const { getByAltText } = render(<ClaimResponse {...defaultProps} />);
86
+ const headerIcon = getByAltText('header icon');
87
+
88
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
89
+ });
90
+
15
91
  it('with DSTU2 source data', () => {
16
92
  const defaultProps = {
17
93
  fhirResource: dstu2Example1,
@@ -262,4 +338,39 @@ describe('should render the ClaimResponse component properly', () => {
262
338
  ' (expense)',
263
339
  ]);
264
340
  });
341
+
342
+ it('should fire custom onClick function', () => {
343
+ const defaultProps = {
344
+ fhirResource: r4Example3,
345
+ fhirVersion: fhirVersions.R4,
346
+ };
347
+
348
+ const onClick = jest.fn();
349
+ const { getAllByRole } = render(
350
+ <ClaimResponse {...defaultProps} onClick={onClick} />,
351
+ );
352
+ const accordion = getAllByRole('button')[0];
353
+ fireEvent.click(accordion);
354
+
355
+ const attribute = accordion.getAttribute('data-bs-toggle');
356
+ expect(attribute).not.toEqual('collapse');
357
+ expect(onClick).toHaveBeenCalled();
358
+ });
359
+
360
+ it('should not fire custom onClick function', () => {
361
+ const defaultProps = {
362
+ fhirResource: r4Example3,
363
+ fhirVersion: fhirVersions.R4,
364
+ };
365
+
366
+ const onClick = 'test';
367
+ const { getAllByRole } = render(
368
+ <ClaimResponse {...defaultProps} onClick={onClick} />,
369
+ );
370
+ const accordion = getAllByRole('button')[0];
371
+ fireEvent.click(accordion);
372
+
373
+ const attribute = accordion.getAttribute('data-bs-toggle');
374
+ expect(attribute).toEqual('collapse');
375
+ });
265
376
  });
@@ -1,20 +1,40 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
 
3
- import { TableCell, TableRow } from '../../ui';
3
+ import { Chevron, TableCell, TableRow } from '../../ui';
4
4
  import Coding from '../../datatypes/Coding';
5
5
  import Money from '../../datatypes/Money';
6
6
 
7
- const Item = props => {
8
- const { item, parentSequences, level } = props;
9
-
7
+ const Item = ({ item, parentSequences, parentId, isCollapse = false }) => {
10
8
  const itemSequences = [...parentSequences, item.sequenceLinkId];
11
9
  const id = itemSequences.join('.');
10
+ const collapseId = parentSequences.length ? parentId : item.sequence;
11
+
12
+ const [rotate, setRotate] = useState(false);
13
+ const handleTableExpand = () => setRotate(!rotate);
14
+
15
+ const isExpandable =
16
+ parentSequences.length === 0 && item.subItems.length !== 0;
12
17
 
13
18
  return (
14
19
  <>
15
- <TableRow>
16
- <TableCell data-testid="items.sequence">{id}</TableCell>
17
- <TableCell data-testid="items.adjudication">
20
+ <TableRow
21
+ className={`${isCollapse ? `collapse item-${parentId}` : ''} ${
22
+ isExpandable ? 'fw-bold table-expandable-row border-top' : ''
23
+ }`}
24
+ data-bs-target={`.item-${collapseId}`}
25
+ data-bs-toggle={'collapse'}
26
+ aria-controls={id}
27
+ aria-expanded="false"
28
+ onClick={handleTableExpand}
29
+ >
30
+ <TableCell
31
+ data-testid="items.sequence"
32
+ className="col-md-2 align-self-start"
33
+ isAlignTop
34
+ >
35
+ {id}
36
+ </TableCell>
37
+ <TableCell data-testid="items.adjudication" className="col-md-8">
18
38
  {item.adjudication.map((adjudication, idx) => (
19
39
  <div
20
40
  key={idx}
@@ -29,13 +49,28 @@ const Item = props => {
29
49
  </div>
30
50
  ))}
31
51
  </TableCell>
52
+ {isExpandable ? (
53
+ <TableCell className="col-md-2" isAlignTop>
54
+ <button
55
+ className="fhir-container__Accordion__header-button w-100 p-0 border-0 rounded-1 collapsed text-dark bg-transparent shadow-none "
56
+ type="button"
57
+ >
58
+ <div className={` ${rotate ? ' header-rotate' : ''}`}>
59
+ <Chevron strokeColor={rotate ? '#2a6fd7' : '#6f83a9'} />
60
+ </div>
61
+ </button>
62
+ </TableCell>
63
+ ) : (
64
+ <TableCell style={{ width: '64px' }} className="col-md-2" />
65
+ )}
32
66
  </TableRow>
33
67
  {item.subItems.map((subItem, idx) => (
34
68
  <Item
35
69
  key={idx}
36
70
  item={subItem}
37
- level={level + 1}
38
71
  parentSequences={itemSequences}
72
+ parentId={collapseId}
73
+ isCollapse
39
74
  />
40
75
  ))}
41
76
  </>
@@ -7,17 +7,18 @@ const Items = props => {
7
7
  const { items } = props;
8
8
 
9
9
  return (
10
- <ValueSection label="Items" data-testid="items">
10
+ <ValueSection label="Items" data-testid="items" marginTop>
11
11
  <Table>
12
12
  <thead>
13
13
  <TableRow>
14
14
  <TableHeader>ID</TableHeader>
15
- <TableHeader expand>Adjudication</TableHeader>
15
+ <TableHeader>Adjudication</TableHeader>
16
+ <TableHeader></TableHeader>
16
17
  </TableRow>
17
18
  </thead>
18
- <tbody>
19
+ <tbody className="border-top-0">
19
20
  {items.map((item, idx) => (
20
- <Item key={idx} item={item} level={0} parentSequences={[]} />
21
+ <Item key={idx} item={item} parentSequences={[]} />
21
22
  ))}
22
23
  </tbody>
23
24
  </Table>
@@ -86,9 +86,14 @@ const resourceDTO = (fhirVersion, fhirResource) => {
86
86
  throw Error('Unrecognized the fhir version property type.');
87
87
  }
88
88
  };
89
- function Condition(props) {
90
- const { fhirResource, fhirVersion, fhirIcons } = props;
91
89
 
90
+ const Condition = ({
91
+ fhirResource,
92
+ fhirVersion,
93
+ fhirIcons,
94
+ onClick,
95
+ rawOnClick,
96
+ }) => {
92
97
  const {
93
98
  codeText,
94
99
  severityText,
@@ -157,10 +162,12 @@ function Condition(props) {
157
162
  />
158
163
  }
159
164
  bodyContent={<Body tableData={tableData} />}
165
+ onClick={onClick}
166
+ rawOnClick={rawOnClick}
160
167
  />
161
168
  </Root>
162
169
  );
163
- }
170
+ };
164
171
 
165
172
  Condition.propTypes = {
166
173
  fhirResource: PropTypes.shape({}).isRequired,
@@ -8,7 +8,7 @@ import exampleConditionSTU3 from '../../../fixtures/stu3/resources/condition/exa
8
8
  import exampleConditionSeverity from '../../../fixtures/dstu2/resources/condition/example-severity.json';
9
9
  import exampleConditionSeveritySTU3 from '../../../fixtures/stu3/resources/condition/example-severity.json';
10
10
  import fhirVersions from '../fhirResourceVersions';
11
- import { render } from '@testing-library/react';
11
+ import { fireEvent, render } from '@testing-library/react';
12
12
  import fhirIcons from '../../../fixtures/example-icons';
13
13
 
14
14
  describe('should render component correctly', () => {
@@ -108,9 +108,7 @@ describe('should render component correctly', () => {
108
108
  expect(getByTestId('clinicalStatus').textContent).toEqual('active');
109
109
  expect(getByTestId('severity').textContent).toEqual('Medium severity');
110
110
  expect(getByTestId('onsetDate').textContent).toEqual('8/24/2015');
111
- expect(getByTestId('asserter').textContent).toEqual(
112
- 'MOORE, NICKPractitioner/f8fedcd9e6e565a21f457909',
113
- );
111
+ expect(getByTestId('asserter').textContent).toEqual('MOORE, NICK');
114
112
  });
115
113
 
116
114
  it('STU3 - without severity field', () => {
@@ -191,4 +189,39 @@ describe('should render component correctly', () => {
191
189
  expect(getByTestId('asserter').textContent).toEqual('Practitioner/f201');
192
190
  expect(getByTestId('dateRecorded').textContent).toEqual('4/4/2013');
193
191
  });
192
+
193
+ it('should fire custom onClick function', () => {
194
+ const defaultProps = {
195
+ fhirResource: example3ConditionSeverityR4,
196
+ fhirVersion: fhirVersions.R4,
197
+ };
198
+
199
+ const onClick = jest.fn();
200
+ const { getByRole } = render(
201
+ <Condition {...defaultProps} onClick={onClick} />,
202
+ );
203
+ const accordion = getByRole('button');
204
+ fireEvent.click(accordion);
205
+
206
+ const attribute = accordion.getAttribute('data-bs-toggle');
207
+ expect(attribute).not.toEqual('collapse');
208
+ expect(onClick).toHaveBeenCalled();
209
+ });
210
+
211
+ it('should not fire custom onClick function', () => {
212
+ const defaultProps = {
213
+ fhirResource: example3ConditionSeverityR4,
214
+ fhirVersion: fhirVersions.R4,
215
+ };
216
+
217
+ const onClick = 'test';
218
+ const { getByRole } = render(
219
+ <Condition {...defaultProps} onClick={onClick} />,
220
+ );
221
+ const accordion = getByRole('button');
222
+ fireEvent.click(accordion);
223
+
224
+ const attribute = accordion.getAttribute('data-bs-toggle');
225
+ expect(attribute).toEqual('collapse');
226
+ });
194
227
  });
@@ -6,8 +6,9 @@ import Reference from '../../datatypes/Reference';
6
6
  import Coding from '../../datatypes/Coding';
7
7
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
8
8
  import fhirVersions from '../fhirResourceVersions';
9
- import { Root, Header, Title, Body, Value } from '../../ui';
9
+ import { Root, Header, Body, Value } from '../../ui';
10
10
  import Identifier from '../../datatypes/Identifier';
11
+ import Accordion from '../../containers/Accordion';
11
12
 
12
13
  const commonDTO = fhirResource => {
13
14
  const identifier = _get(fhirResource, 'identifier.0');
@@ -113,8 +114,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
113
114
  }
114
115
  };
115
116
 
116
- const Coverage = props => {
117
- const { fhirResource, fhirVersion } = props;
117
+ const Coverage = ({
118
+ fhirResource,
119
+ fhirVersion,
120
+ fhirIcons,
121
+ onClick,
122
+ rawOnClick,
123
+ }) => {
118
124
  let fhirResourceData = {};
119
125
  try {
120
126
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -138,74 +144,103 @@ const Coverage = props => {
138
144
  } = fhirResourceData;
139
145
  const issuerReferenceType = _get(issuer, 'reference');
140
146
  const issuerIdentifierType = _get(issuer, 'identifier');
147
+
148
+ const tableData = [
149
+ {
150
+ label: 'Issuer',
151
+ testId: 'issuer',
152
+ data: issuerReferenceType && <Reference fhirData={issuer} />,
153
+ status: issuerReferenceType,
154
+ },
155
+ {
156
+ label: 'Issuer',
157
+ testId: 'issuer',
158
+ data: issuerIdentifierType && <Identifier fhirData={issuer.identifier} />,
159
+ status: issuerIdentifierType,
160
+ },
161
+ {
162
+ label: 'PlanId',
163
+ testId: 'planId',
164
+ data: planId,
165
+ status: planId,
166
+ },
167
+ {
168
+ label: 'Coverage',
169
+ testId: '',
170
+ data: period && (
171
+ <>
172
+ {coverageFrom && (
173
+ <span data-testid="coverageFrom">from: {coverageFrom}</span>
174
+ )}{' '}
175
+ {coverageTo && <span data-testid="coverageTo">to: {coverageTo}</span>}
176
+ </>
177
+ ),
178
+ status: period,
179
+ },
180
+ {
181
+ label: 'Type of coverage',
182
+ testId: 'type',
183
+ data: type && <Coding fhirData={type} />,
184
+ status: type,
185
+ },
186
+ {
187
+ label: 'Details',
188
+ testId: 'details',
189
+ data: hasDetails && (
190
+ <>
191
+ <span>{details.planDescription}</span>
192
+ {details.classDescription && (
193
+ <>
194
+ {' | '}
195
+ <span>{details.classDescription}</span>
196
+ </>
197
+ )}
198
+ </>
199
+ ),
200
+ status: hasDetails,
201
+ },
202
+ {
203
+ label: 'Extension',
204
+ testId: 'extensions',
205
+ data:
206
+ hasExtension &&
207
+ extension.map((item, i) => {
208
+ const coding = Array.isArray(item.coding) ? item.coding : [];
209
+
210
+ return (
211
+ <span key={`item-${i}`}>
212
+ {item.name && <span>{item.name}</span>}
213
+ {coding.map((code, j) => (
214
+ <Coding key={`item-${j}`} fhirData={code} />
215
+ ))}
216
+ </span>
217
+ );
218
+ }),
219
+ status: hasExtension,
220
+ },
221
+ ];
222
+
141
223
  return (
142
224
  <Root name="coverage">
143
- <Header>
144
- {identifier && (
145
- <Title>
146
- Coverage <Identifier fhirData={identifier} />
147
- </Title>
148
- )}
149
- </Header>
150
- <Body>
151
- {issuerReferenceType && (
152
- <Value label="Issuer" data-testid="issuer">
153
- <Reference fhirData={issuer} />
154
- </Value>
155
- )}
156
- {issuerIdentifierType && (
157
- <Value label="Issuer" data-testid="issuer">
158
- <Identifier fhirData={issuer.identifier} />
159
- </Value>
160
- )}
161
- {planId && (
162
- <Value label="PlanId" data-testid="planId">
163
- {planId}
164
- </Value>
165
- )}
166
- {period && (
167
- <Value label="Coverage">
168
- {coverageFrom && (
169
- <span data-testid="coverageFrom">from: {coverageFrom}</span>
170
- )}{' '}
171
- {coverageTo && (
172
- <span data-testid="coverageTo">to: {coverageTo}</span>
173
- )}
174
- </Value>
175
- )}
176
- {type && (
177
- <Value label="Type of coverage" data-testid="type">
178
- <Coding fhirData={type} />
179
- </Value>
180
- )}
181
- {hasDetails && (
182
- <Value label="Details" data-testid="details">
183
- <span>{details.planDescription}</span>
184
- {details.classDescription && (
185
- <>
186
- {' | '}
187
- <span>{details.classDescription}</span>
188
- </>
189
- )}
190
- </Value>
191
- )}
192
- {hasExtension && (
193
- <Value label="Extension" data-testid="extensions">
194
- {extension.map((item, i) => {
195
- const coding = Array.isArray(item.coding) ? item.coding : [];
196
-
197
- return (
198
- <span key={`item-${i}`}>
199
- {item.name && <span>{item.name}</span>}
200
- {coding.map((code, j) => (
201
- <Coding key={`item-${j}`} fhirData={code} />
202
- ))}
203
- </span>
204
- );
205
- })}
206
- </Value>
207
- )}
208
- </Body>
225
+ <Accordion
226
+ headerContent={
227
+ <Header
228
+ resourceName="Coverage"
229
+ additionalContent={
230
+ identifier && (
231
+ <Value label="Identifier">
232
+ <Identifier fhirData={identifier} valueOnly noCursive />
233
+ </Value>
234
+ )
235
+ }
236
+ title="Coverage"
237
+ icon={fhirIcons}
238
+ />
239
+ }
240
+ bodyContent={<Body tableData={tableData} />}
241
+ onClick={onClick}
242
+ rawOnClick={rawOnClick}
243
+ />
209
244
  </Root>
210
245
  );
211
246
  };
@@ -9,38 +9,64 @@ import exampleCoverageStu3 from '../../../fixtures/stu3/resources/coverage/examp
9
9
  import example2CoverageStu3 from '../../../fixtures/stu3/resources/coverage/example2.json';
10
10
  import exampleCoverageR4 from '../../../fixtures/r4/resources/coverage/example1.json';
11
11
  import example2CoverageR4 from '../../../fixtures/r4/resources/coverage/example2.json';
12
+ import fhirIcons from '../../../fixtures/example-icons';
13
+ import CoverageIcon from '../../../assets/containers/Coverage/coverage.svg';
12
14
 
13
15
  export default { title: 'Coverage' };
14
16
 
15
17
  export const DefaultVisualizationDSTU2 = () => {
16
18
  const fhirResource = object('Resource', exampleCoverageDstu2);
17
19
  return (
18
- <Coverage fhirVersion={fhirVersions.DSTU2} fhirResource={fhirResource} />
20
+ <Coverage
21
+ fhirVersion={fhirVersions.DSTU2}
22
+ fhirResource={fhirResource}
23
+ fhirIcons={require('../../../assets/containers/Coverage/coverage.svg')}
24
+ />
19
25
  );
20
26
  };
21
27
 
22
28
  export const ExampleOfSTU3 = () => {
23
29
  const fhirResource = object('Resource', exampleCoverageStu3);
24
30
  return (
25
- <Coverage fhirVersion={fhirVersions.STU3} fhirResource={fhirResource} />
31
+ <Coverage
32
+ fhirVersion={fhirVersions.STU3}
33
+ fhirResource={fhirResource}
34
+ fhirIcons={CoverageIcon}
35
+ />
26
36
  );
27
37
  };
28
38
 
29
39
  export const Example2OfSTU3 = () => {
30
40
  const fhirResource = object('Resource', example2CoverageStu3);
31
41
  return (
32
- <Coverage fhirVersion={fhirVersions.STU3} fhirResource={fhirResource} />
42
+ <Coverage
43
+ fhirVersion={fhirVersions.STU3}
44
+ fhirResource={fhirResource}
45
+ fhirIcons={fhirIcons}
46
+ />
33
47
  );
34
48
  };
35
49
 
36
50
  export const ExampleOfR4 = () => {
37
51
  const fhirResource = object('Resource', exampleCoverageR4);
38
- return <Coverage fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
52
+ return (
53
+ <Coverage
54
+ fhirResource={fhirResource}
55
+ fhirVersion={fhirVersions.R4}
56
+ fhirIcons={false}
57
+ />
58
+ );
39
59
  };
40
60
 
41
61
  export const Example2OfR4 = () => {
42
62
  const fhirResource = object('Resource', example2CoverageR4);
43
- return <Coverage fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />;
63
+ return (
64
+ <Coverage
65
+ fhirResource={fhirResource}
66
+ fhirVersion={fhirVersions.R4}
67
+ fhirIcons={'random text'}
68
+ />
69
+ );
44
70
  };
45
71
 
46
72
  export const ExampleWithoutFhirVersionProperty = () => {