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
@@ -5,8 +5,9 @@ import _get from 'lodash/get';
5
5
  import Reference from '../../datatypes/Reference';
6
6
  import fhirVersions from '../fhirResourceVersions';
7
7
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
8
- import { Root, Header, Title, Body, Value, Badge } from '../../ui';
8
+ import { Root, Header, Body, Badge } from '../../ui';
9
9
  import CodeableConcept from '../../datatypes/CodeableConcept/CodeableConcept';
10
+ import Accordion from '../../containers/Accordion';
10
11
 
11
12
  const commonDTO = fhirResource => {
12
13
  const status = _get(fhirResource, 'active') === true ? 'active' : '';
@@ -42,8 +43,12 @@ const resourceDTO = (fhirVersion, fhirResource) => {
42
43
  }
43
44
  };
44
45
 
45
- const PractitionerRole = props => {
46
- const { fhirResource, fhirVersion } = props;
46
+ const PractitionerRole = ({
47
+ fhirResource,
48
+ fhirVersion,
49
+ fhirIcons,
50
+ onClick,
51
+ }) => {
47
52
  let fhirResourceData = {};
48
53
  try {
49
54
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -58,34 +63,50 @@ const PractitionerRole = props => {
58
63
  organization,
59
64
  practitioner,
60
65
  } = fhirResourceData;
66
+
67
+ const tableData = [
68
+ {
69
+ label: 'Practitioner',
70
+ testId: 'practitioner',
71
+ data: practitioner && <Reference fhirData={practitioner} />,
72
+ status: practitioner,
73
+ },
74
+ {
75
+ label: 'Organization',
76
+ testId: 'organization',
77
+ data: organization && <Reference fhirData={organization} />,
78
+ status: organization,
79
+ },
80
+ {
81
+ label: 'Specialties',
82
+ testId: 'specialties',
83
+ data: specialties.length > 0 && (
84
+ <CodeableConcept fhirData={specialties} isCursive />
85
+ ),
86
+ status: specialties.length > 0,
87
+ },
88
+ {
89
+ label: 'Roles',
90
+ testId: 'roles',
91
+ data: codes.length > 0 && <CodeableConcept fhirData={codes} isCursive />,
92
+ status: codes.length > 0,
93
+ },
94
+ ];
95
+
61
96
  return (
62
97
  <Root name="PractitionerRole">
63
- <Header>
64
- <Title>Practitioner roles and specialties</Title>
65
- {status && <Badge data-testid="status">{status}</Badge>}
66
- </Header>
67
- <Body>
68
- {practitioner && (
69
- <Value label="Practitioner" data-testid="practitioner">
70
- <Reference fhirData={practitioner} />
71
- </Value>
72
- )}
73
- {organization && (
74
- <Value label="Organization" data-testid="organization">
75
- <Reference fhirData={organization} />
76
- </Value>
77
- )}
78
- {specialties.length > 0 && (
79
- <Value label="Specialties" data-testid="specialties">
80
- <CodeableConcept fhirData={specialties} />
81
- </Value>
82
- )}
83
- {codes.length > 0 && (
84
- <Value label="Roles" data-testid="roles">
85
- <CodeableConcept fhirData={codes} />
86
- </Value>
87
- )}
88
- </Body>
98
+ <Accordion
99
+ headerContent={
100
+ <Header
101
+ resourceName="PractitionerRole"
102
+ title="Practitioner roles and specialties"
103
+ badges={status && <Badge data-testid="status">{status}</Badge>}
104
+ icon={fhirIcons}
105
+ />
106
+ }
107
+ bodyContent={<Body tableData={tableData} />}
108
+ onClick={onClick}
109
+ />
89
110
  </Root>
90
111
  );
91
112
  };
@@ -12,6 +12,8 @@ import r4Example1 from '../../../fixtures/r4/resources/practitionerRole/example1
12
12
  import r4Example2 from '../../../fixtures/r4/resources/practitionerRole/example2.json';
13
13
  import r4Example3 from '../../../fixtures/r4/resources/practitionerRole/example3.json';
14
14
  import r4Example4 from '../../../fixtures/r4/resources/practitionerRole/example4.json';
15
+ import fhirIcons from '../../../fixtures/example-icons';
16
+ import PractitionerRoleIcon from '../../../assets/containers/PractitionerRole/practitioner-role.svg';
15
17
 
16
18
  export default { title: 'PractitionerRole' };
17
19
 
@@ -21,6 +23,7 @@ export const ExampleOfSTU3 = () => {
21
23
  <PractitionerRole
22
24
  fhirVersion={fhirVersions.STU3}
23
25
  fhirResource={fhirResource}
26
+ fhirIcons={require('../../../assets/containers/PractitionerRole/practitioner-role.svg')}
24
27
  />
25
28
  );
26
29
  };
@@ -31,6 +34,7 @@ export const Example2OfSTU3 = () => {
31
34
  <PractitionerRole
32
35
  fhirVersion={fhirVersions.STU3}
33
36
  fhirResource={fhirResource}
37
+ fhirIcons={PractitionerRoleIcon}
34
38
  />
35
39
  );
36
40
  };
@@ -41,6 +45,7 @@ export const Example3OfSTU3 = () => {
41
45
  <PractitionerRole
42
46
  fhirVersion={fhirVersions.STU3}
43
47
  fhirResource={fhirResource}
48
+ fhirIcons={fhirIcons}
44
49
  />
45
50
  );
46
51
  };
@@ -61,6 +66,7 @@ export const Example2OfR4 = () => {
61
66
  <PractitionerRole
62
67
  fhirVersion={fhirVersions.R4}
63
68
  fhirResource={fhirResource}
69
+ fhirIcons={false}
64
70
  />
65
71
  );
66
72
  };
@@ -71,6 +77,7 @@ export const Example3OfR4 = () => {
71
77
  <PractitionerRole
72
78
  fhirVersion={fhirVersions.R4}
73
79
  fhirResource={fhirResource}
80
+ fhirIcons={'random text'}
74
81
  />
75
82
  );
76
83
  };
@@ -1,13 +1,85 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import PractitionerRole from './PractitionerRole';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import stu3Example1 from '../../../fixtures/stu3/resources/practitionerRole/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/practitionerRole/example1.json';
8
8
  import r4Example2 from '../../../fixtures/r4/resources/practitionerRole/example3.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  describe('PractitionerRole should render component correctly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirVersion: fhirVersions.STU3,
15
+ fhirResource: stu3Example1,
16
+ };
17
+
18
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
19
+ const headerIcon = getByAltText('practitioner role');
20
+
21
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
22
+ });
23
+
24
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
25
+ const defaultProps = {
26
+ fhirVersion: fhirVersions.STU3,
27
+ fhirResource: stu3Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<PractitionerRole {...defaultProps} />);
32
+ const headerIcon = getByTestId('placeholder');
33
+
34
+ expect(headerIcon).toBeTruthy();
35
+ });
36
+
37
+ it('component with the img as a fhirIcons props should render an img', () => {
38
+ const defaultProps = {
39
+ fhirVersion: fhirVersions.STU3,
40
+ fhirResource: stu3Example1,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/PractitionerRole/practitioner-role.svg')}
44
+ alt="practitioner role"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
50
+ const headerIcon = getByAltText('practitioner role');
51
+
52
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
53
+ });
54
+
55
+ it('component with the resources object as a fhirIcons props should render an img', () => {
56
+ const defaultProps = {
57
+ fhirVersion: fhirVersions.STU3,
58
+ fhirResource: stu3Example1,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
63
+ const headerIcon = getByAltText('practitioner role');
64
+
65
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
66
+ });
67
+
68
+ it('component with the url as a fhirIcons props should render an img', () => {
69
+ const avatarSrc =
70
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
71
+ const defaultProps = {
72
+ fhirVersion: fhirVersions.STU3,
73
+ fhirResource: stu3Example1,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<PractitionerRole {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
11
83
  it('should render component correctly with STU3 source data', () => {
12
84
  const defaultProps = {
13
85
  fhirVersion: fhirVersions.STU3,
@@ -100,4 +172,39 @@ describe('PractitionerRole should render component correctly', () => {
100
172
  );
101
173
  jest.restoreAllMocks();
102
174
  });
175
+
176
+ it('should fire custom onClick function', () => {
177
+ const defaultProps = {
178
+ fhirVersion: fhirVersions.R4,
179
+ fhirResource: stu3Example1,
180
+ };
181
+
182
+ const onClick = jest.fn();
183
+ const { getByRole } = render(
184
+ <PractitionerRole {...defaultProps} onClick={onClick} />,
185
+ );
186
+ const accordion = getByRole('button');
187
+ fireEvent.click(accordion);
188
+
189
+ const attribute = accordion.getAttribute('data-bs-toggle');
190
+ expect(attribute).not.toEqual('collapse');
191
+ expect(onClick).toHaveBeenCalled();
192
+ });
193
+
194
+ it('should not fire custom onClick function', () => {
195
+ const defaultProps = {
196
+ fhirVersion: fhirVersions.R4,
197
+ fhirResource: stu3Example1,
198
+ };
199
+
200
+ const onClick = 'test';
201
+ const { getByRole } = render(
202
+ <PractitionerRole {...defaultProps} onClick={onClick} />,
203
+ );
204
+ const accordion = getByRole('button');
205
+ fireEvent.click(accordion);
206
+
207
+ const attribute = accordion.getAttribute('data-bs-toggle');
208
+ expect(attribute).toEqual('collapse');
209
+ });
103
210
  });
@@ -14,8 +14,7 @@ import _has from 'lodash/has';
14
14
  import { isNotEmptyArray } from '../../../utils';
15
15
  import { Value } from '../../ui';
16
16
 
17
- const Procedure = props => {
18
- const { fhirResource, fhirIcons } = props;
17
+ const Procedure = ({ fhirResource, fhirIcons, onClick }) => {
19
18
  const display =
20
19
  _get(fhirResource, 'code.coding[0].display') ||
21
20
  _get(fhirResource, 'code.text');
@@ -125,6 +124,7 @@ const Procedure = props => {
125
124
  />
126
125
  }
127
126
  bodyContent={<Body tableData={tableData} />}
127
+ onClick={onClick}
128
128
  />
129
129
  </Root>
130
130
  );
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import dstu2Example1 from '../../../fixtures/dstu2/resources/procedure/example1.json';
4
4
  import r4Example2 from '../../../fixtures/r4/resources/procedure/example2.json';
5
5
  import r4Example3 from '../../../fixtures/r4/resources/procedure/example3.json';
6
- import { render } from '@testing-library/react';
6
+ import { fireEvent, render } from '@testing-library/react';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/procedure/example1.json';
8
8
  import fhirIcons from '../../../fixtures/example-icons';
9
9
  import fhirVersions from '../fhirResourceVersions';
@@ -168,4 +168,33 @@ describe('Procedure should render component correctly', () => {
168
168
  'Eerste neo-adjuvante',
169
169
  );
170
170
  });
171
+
172
+ it('should fire custom onClick function', () => {
173
+ const defaultProps = { fhirResource: r4Example3 };
174
+
175
+ const onClick = jest.fn();
176
+ const { getByRole } = render(
177
+ <Procedure {...defaultProps} onClick={onClick} />,
178
+ );
179
+ const accordion = getByRole('button');
180
+ fireEvent.click(accordion);
181
+
182
+ const attribute = accordion.getAttribute('data-bs-toggle');
183
+ expect(attribute).not.toEqual('collapse');
184
+ expect(onClick).toHaveBeenCalled();
185
+ });
186
+
187
+ it('should not fire custom onClick function', () => {
188
+ const defaultProps = { fhirResource: r4Example3 };
189
+
190
+ const onClick = 'test';
191
+ const { getByRole } = render(
192
+ <Procedure {...defaultProps} onClick={onClick} />,
193
+ );
194
+ const accordion = getByRole('button');
195
+ fireEvent.click(accordion);
196
+
197
+ const attribute = accordion.getAttribute('data-bs-toggle');
198
+ expect(attribute).toEqual('collapse');
199
+ });
171
200
  });
@@ -0,0 +1,53 @@
1
+ import _get from 'lodash/get';
2
+ import { MissingValue } from '../../ui';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+ import Questions from './Questions';
6
+ import { getQuestionText } from './getQuestionText';
7
+
8
+ const Group = ({ data, prepareItems, isChild = false }) => {
9
+ if (!Array.isArray(data) || data.length === 0) {
10
+ return null;
11
+ }
12
+
13
+ return data.map(prepareItems).map((item, i) => {
14
+ const text = getQuestionText(item);
15
+ let nestedItems = _get(item, 'item', []);
16
+ nestedItems = nestedItems.map(prepareItems);
17
+ const isGroup = _get(item, 'isGroup');
18
+ return (
19
+ <ul
20
+ key={`questionnaire-item-${i}`}
21
+ className="fhir-resource__Questionnaire-list"
22
+ >
23
+ <li
24
+ className={
25
+ isChild
26
+ ? 'fhir-resource__Questionnaire-list-title-question'
27
+ : 'fhir-resource__Questionnaire-list-title'
28
+ }
29
+ data-testid={`linkId-${item.linkId}`}
30
+ >
31
+ {text ? text : <MissingValue />}
32
+ </li>
33
+ {!isGroup && (
34
+ <li>
35
+ <Questions questions={nestedItems} prepareItems={prepareItems} />
36
+ </li>
37
+ )}
38
+ {isGroup && (
39
+ <li>
40
+ <Group data={nestedItems} prepareItems={prepareItems} isChild />
41
+ </li>
42
+ )}
43
+ </ul>
44
+ );
45
+ });
46
+ };
47
+
48
+ Group.propTypes = {
49
+ data: PropTypes.array,
50
+ prepareItems: PropTypes.func.isRequired,
51
+ };
52
+
53
+ export default Group;
@@ -0,0 +1,45 @@
1
+ import fhirVersions from '../fhirResourceVersions';
2
+ import _get from 'lodash/get';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+ import Group from './Group';
6
+
7
+ const Items = ({ fhirVersion, data }) => {
8
+ if (fhirVersion === fhirVersions.DSTU2) {
9
+ const prepareItems = item => ({
10
+ ...item,
11
+ item: _get(item, 'question') || _get(item, 'group') || [],
12
+ isGroup: !!_get(item, 'group'),
13
+ });
14
+ return <Group data={data} prepareItems={prepareItems} />;
15
+ }
16
+
17
+ if (fhirVersion === fhirVersions.STU3) {
18
+ const prepareItems = item => ({
19
+ ...item,
20
+ isGroup: _get(item, 'type') === 'group',
21
+ });
22
+ return <Group data={data} prepareItems={prepareItems} />;
23
+ }
24
+
25
+ if (fhirVersion === fhirVersions.R4) {
26
+ const prepareItems = item => ({
27
+ ...item,
28
+ isGroup: _get(item, 'type') === 'group',
29
+ });
30
+ return <Group data={data} prepareItems={prepareItems} />;
31
+ }
32
+
33
+ return null;
34
+ };
35
+
36
+ Items.propTypes = {
37
+ data: PropTypes.array,
38
+ fhirVersion: PropTypes.oneOf([
39
+ fhirVersions.DSTU2,
40
+ fhirVersions.STU3,
41
+ fhirVersions.R4,
42
+ ]).isRequired,
43
+ };
44
+
45
+ export default Items;
@@ -1,21 +1,41 @@
1
1
  .fhir-resource__Questionnaire-list {
2
2
  list-style: none;
3
- border: 1px solid #f0f0f0;
4
3
  padding: 2px;
5
4
  margin: 2px;
6
5
  }
7
6
 
8
7
  .fhir-resource__Questionnaire-list-title {
9
- background-color: #f6f6f6;
10
- padding: 2px 2px 4px 2px;
8
+ padding: 2px 2px 8px 2px;
9
+ font-weight: bold;
10
+ }
11
+
12
+ .fhir-resource__Questionnaire-list-title-question {
13
+ background: #f8f9fa;
14
+ align-items: center;
15
+ margin-bottom: 56px;
16
+ padding-left: 16px;
17
+ border-radius: 4px;
18
+ color: #adb5bd;
11
19
  }
12
20
 
13
21
  .fhir-resource__Questionnaire-questions-list {
14
22
  list-style: none;
23
+ padding-left: 0;
24
+ display: block;
25
+ color: #adb5bd;
15
26
  }
16
27
 
17
28
  .fhir-resource__Questionnaire-questions-list li {
18
- border-bottom: 1px solid #f5f5f5;
29
+ display: block;
30
+ margin-bottom: 56px;
31
+ }
32
+
33
+ .fhir-resource__Questionnaire-questions-list-element {
34
+ background: #f8f9fa;
35
+ border-radius: 4px;
36
+ width: 100%;
37
+ padding-left: 16px;
38
+ margin-bottom: 56px;
19
39
  }
20
40
 
21
41
  .fhir-resource__Questionnaire-questions-list li:last-child {
@@ -24,7 +44,6 @@
24
44
 
25
45
  .fhir-resource__Questionnaire-questions-list-item-details {
26
46
  font-size: 80%;
27
- color: #606060;
28
47
  }
29
48
 
30
49
  .fhir-resource__Questionnaire-questions-list-item-details-el {