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 { fhirVersions } from '../../../index';
5
5
 
@@ -7,8 +7,79 @@ import List from './List';
7
7
 
8
8
  import example1Dstu2 from '../../../fixtures/dstu2/resources/list/example1.json';
9
9
  import example2R4 from '../../../fixtures/r4/resources/list/example2.json';
10
+ import fhirIcons from '../../../fixtures/example-icons';
10
11
 
11
12
  describe('should render List component properly', () => {
13
+ it('component without a fhirIcons props should render a default icon', () => {
14
+ const defaultProps = {
15
+ fhirVersion: fhirVersions.DSTU2,
16
+ fhirResource: example1Dstu2,
17
+ };
18
+
19
+ const { getByAltText } = render(<List {...defaultProps} />);
20
+ const headerIcon = getByAltText('list');
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
+ fhirVersion: fhirVersions.DSTU2,
28
+ fhirResource: example1Dstu2,
29
+ fhirIcons: false,
30
+ };
31
+
32
+ const { getByTestId } = render(<List {...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
+ fhirVersion: fhirVersions.DSTU2,
41
+ fhirResource: example1Dstu2,
42
+ fhirIcons: (
43
+ <img
44
+ src={require('../assets/containers/List/list.svg')}
45
+ alt="checklist"
46
+ />
47
+ ),
48
+ };
49
+
50
+ const { getByAltText } = render(<List {...defaultProps} />);
51
+ const headerIcon = getByAltText('checklist');
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
+ fhirVersion: fhirVersions.DSTU2,
59
+ fhirResource: example1Dstu2,
60
+ fhirIcons: fhirIcons,
61
+ };
62
+
63
+ const { getByAltText } = render(<List {...defaultProps} />);
64
+ const headerIcon = getByAltText('checklist');
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
+ fhirVersion: fhirVersions.DSTU2,
74
+ fhirResource: example1Dstu2,
75
+ fhirIcons: avatarSrc,
76
+ };
77
+
78
+ const { getByAltText } = render(<List {...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: example1Dstu2,
@@ -92,4 +163,37 @@ describe('should render List component properly', () => {
92
163
  );
93
164
  expect(getByTestId('usdfPlanIDType').textContent).toContain('HIOS-PLAN-ID');
94
165
  });
166
+
167
+ it('should fire custom onClick function', () => {
168
+ const defaultProps = {
169
+ fhirResource: example2R4,
170
+ fhirVersion: fhirVersions.R4,
171
+ withDaVinciPDex: true,
172
+ };
173
+
174
+ const onClick = jest.fn();
175
+ const { getByRole } = render(<List {...defaultProps} onClick={onClick} />);
176
+ const accordion = getByRole('button');
177
+ fireEvent.click(accordion);
178
+
179
+ const attribute = accordion.getAttribute('data-bs-toggle');
180
+ expect(attribute).not.toEqual('collapse');
181
+ expect(onClick).toHaveBeenCalled();
182
+ });
183
+
184
+ it('should not fire custom onClick function', () => {
185
+ const defaultProps = {
186
+ fhirResource: example2R4,
187
+ fhirVersion: fhirVersions.R4,
188
+ withDaVinciPDex: true,
189
+ };
190
+
191
+ const onClick = 'test';
192
+ const { getByRole } = render(<List {...defaultProps} onClick={onClick} />);
193
+ const accordion = getByRole('button');
194
+ fireEvent.click(accordion);
195
+
196
+ const attribute = accordion.getAttribute('data-bs-toggle');
197
+ expect(attribute).toEqual('collapse');
198
+ });
95
199
  });
@@ -2,14 +2,14 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _get from 'lodash/get';
4
4
 
5
- import { Root, Header, Title, Badge, Body, Value } from '../../ui';
5
+ import { Root, Header, Badge, Body } from '../../ui';
6
6
  import Address from '../../datatypes/Address';
7
7
  import Telecom from '../../datatypes/Telecom';
8
8
  import CodeableConcept from '../../datatypes/CodeableConcept';
9
9
  import Reference from '../../datatypes/Reference';
10
+ import Accordion from '../../containers/Accordion';
10
11
 
11
- const Location = props => {
12
- const { fhirResource } = props;
12
+ const Location = ({ fhirResource, fhirIcons, onClick, rawOnClick }) => {
13
13
  const name = _get(fhirResource, 'name');
14
14
  const status = _get(fhirResource, 'status');
15
15
  const description = _get(fhirResource, 'description');
@@ -19,52 +19,71 @@ const Location = props => {
19
19
  const physicalType = _get(fhirResource, 'physicalType');
20
20
  const mode = _get(fhirResource, 'mode');
21
21
  const managingOrganization = _get(fhirResource, 'managingOrganization');
22
+
23
+ const tableData = [
24
+ {
25
+ label: 'Type',
26
+ testId: 'type',
27
+ data: type && <CodeableConcept fhirData={type} isCursive />,
28
+ status: type,
29
+ },
30
+ {
31
+ label: 'Physical type',
32
+ testId: 'physicalType',
33
+ data: physicalType && (
34
+ <CodeableConcept fhirData={physicalType} isCursive />
35
+ ),
36
+ status: physicalType,
37
+ },
38
+ {
39
+ label: 'Location mode',
40
+ testId: 'mode',
41
+ data: mode,
42
+ status: mode,
43
+ },
44
+ {
45
+ label: 'Description',
46
+ testId: 'description',
47
+ data: description,
48
+ status: description,
49
+ },
50
+ {
51
+ label: 'Address',
52
+ testId: 'address',
53
+ data: address && <Address fhirData={address} />,
54
+ status: address,
55
+ },
56
+ {
57
+ label: 'Telecom',
58
+ testId: 'telecom',
59
+ data: telecom && <Telecom fhirData={telecom} noSystemData />,
60
+ status: telecom,
61
+ },
62
+ {
63
+ label: 'Managing organization',
64
+ testId: 'managingOrganization',
65
+ data: managingOrganization && (
66
+ <Reference fhirData={managingOrganization} />
67
+ ),
68
+ status: managingOrganization,
69
+ },
70
+ ];
71
+
22
72
  return (
23
73
  <Root name="Location">
24
- <Header>
25
- {name && <Title>{name}</Title>}
26
- {status && <Badge data-testid="status">{status}</Badge>}
27
- </Header>
28
- <Body>
29
- {type && (
30
- <Value label="Type" data-testid="type">
31
- <CodeableConcept fhirData={type} />
32
- </Value>
33
- )}
34
- {physicalType && (
35
- <Value label="Physical type" data-testid="physicalType">
36
- <CodeableConcept fhirData={physicalType} />
37
- </Value>
38
- )}
39
- {mode && (
40
- <Value label="Location mode" data-testid="mode">
41
- {mode}
42
- </Value>
43
- )}
44
- {description && (
45
- <Value label="Description" data-testid="description">
46
- {description}
47
- </Value>
48
- )}
49
- {address && (
50
- <Value label="Address" data-testid="address">
51
- <Address fhirData={address} />
52
- </Value>
53
- )}
54
- {telecom && (
55
- <Value label="Telecom" data-testid="telecom">
56
- <Telecom fhirData={telecom} />
57
- </Value>
58
- )}
59
- {managingOrganization && (
60
- <Value
61
- label="Managing organization"
62
- data-testid="managingOrganization"
63
- >
64
- <Reference fhirData={managingOrganization} />
65
- </Value>
66
- )}
67
- </Body>
74
+ <Accordion
75
+ headerContent={
76
+ <Header
77
+ resourceName="Location"
78
+ title={name}
79
+ badges={status && <Badge data-testid="status">{status}</Badge>}
80
+ icon={fhirIcons}
81
+ />
82
+ }
83
+ bodyContent={<Body tableData={tableData} />}
84
+ onClick={onClick}
85
+ rawOnClick={rawOnClick}
86
+ />
68
87
  </Root>
69
88
  );
70
89
  };
@@ -7,6 +7,8 @@ import dstu2Example1 from '../../../fixtures/dstu2/resources/location/example1.j
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/location/example1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/location/example1.json';
9
9
  import r4Example2 from '../../../fixtures/r4/resources/location/example2.json';
10
+ import fhirIcons from '../../../fixtures/example-icons';
11
+ import LocationIcon from '../../../assets/containers/Location/location.svg';
10
12
 
11
13
  export default {
12
14
  title: 'Location',
@@ -14,20 +16,25 @@ export default {
14
16
 
15
17
  export const DefaultVisualizationDSTU2 = () => {
16
18
  const fhirResource = object('Resource', dstu2Example1);
17
- return <Location fhirResource={fhirResource} />;
19
+ return (
20
+ <Location
21
+ fhirResource={fhirResource}
22
+ fhirIcons={require('../../../assets/containers/Location/location.svg')}
23
+ />
24
+ );
18
25
  };
19
26
 
20
27
  export const ExampleOfSTU3 = () => {
21
28
  const fhirResource = object('Resource', stu3Example1);
22
- return <Location fhirResource={fhirResource} />;
29
+ return <Location fhirResource={fhirResource} fhirIcons={LocationIcon} />;
23
30
  };
24
31
 
25
32
  export const Example1OfR4 = () => {
26
33
  const fhirResource = object('Resource', r4Example1);
27
- return <Location fhirResource={fhirResource} />;
34
+ return <Location fhirResource={fhirResource} fhirIcons={fhirIcons} />;
28
35
  };
29
36
 
30
37
  export const Example2OfR4 = () => {
31
38
  const fhirResource = object('Resource', r4Example2);
32
- return <Location fhirResource={fhirResource} />;
39
+ return <Location fhirResource={fhirResource} fhirIcons={false} />;
33
40
  };
@@ -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 Location from './Location';
5
5
 
@@ -7,8 +7,81 @@ import dstu2Example1 from '../../../fixtures/dstu2/resources/location/example1.j
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/location/example1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/location/example1.json';
9
9
  import r4Example2 from '../../../fixtures/r4/resources/location/example2.json';
10
+ import fhirVersions from '../fhirResourceVersions';
11
+ import fhirIcons from '../../../fixtures/example-icons';
10
12
 
11
13
  describe('should render Location component properly', () => {
14
+ it('component without a fhirIcons props should render a default icon', () => {
15
+ const defaultProps = {
16
+ fhirVersion: fhirVersions.DSTU2,
17
+ fhirResource: dstu2Example1,
18
+ };
19
+
20
+ const { getByAltText } = render(<Location {...defaultProps} />);
21
+ const headerIcon = getByAltText('location');
22
+
23
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
24
+ });
25
+
26
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
27
+ const defaultProps = {
28
+ fhirVersion: fhirVersions.DSTU2,
29
+ fhirResource: dstu2Example1,
30
+ fhirIcons: false,
31
+ };
32
+
33
+ const { getByTestId } = render(<Location {...defaultProps} />);
34
+ const headerIcon = getByTestId('placeholder');
35
+
36
+ expect(headerIcon).toBeTruthy();
37
+ });
38
+
39
+ it('component with the img as a fhirIcons props should render an img', () => {
40
+ const defaultProps = {
41
+ fhirVersion: fhirVersions.DSTU2,
42
+ fhirResource: dstu2Example1,
43
+ fhirIcons: (
44
+ <img
45
+ src={require('../assets/containers/Location/location.svg')}
46
+ alt="location marker"
47
+ />
48
+ ),
49
+ };
50
+
51
+ const { getByAltText } = render(<Location {...defaultProps} />);
52
+ const headerIcon = getByAltText('location marker');
53
+
54
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
55
+ });
56
+
57
+ it('component with the resources object as a fhirIcons props should render an img', () => {
58
+ const defaultProps = {
59
+ fhirVersion: fhirVersions.DSTU2,
60
+ fhirResource: dstu2Example1,
61
+ fhirIcons: fhirIcons,
62
+ };
63
+
64
+ const { getByAltText } = render(<Location {...defaultProps} />);
65
+ const headerIcon = getByAltText('location marker');
66
+
67
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
68
+ });
69
+
70
+ it('component with the url as a fhirIcons props should render an img', () => {
71
+ const avatarSrc =
72
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
73
+ const defaultProps = {
74
+ fhirVersion: fhirVersions.DSTU2,
75
+ fhirResource: dstu2Example1,
76
+ fhirIcons: avatarSrc,
77
+ };
78
+
79
+ const { getByAltText } = render(<Location {...defaultProps} />);
80
+ const headerIcon = getByAltText('header icon');
81
+
82
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
83
+ });
84
+
12
85
  it('should render with DSTU2 source data', () => {
13
86
  const defaultProps = {
14
87
  fhirResource: dstu2Example1,
@@ -31,7 +104,7 @@ describe('should render Location component properly', () => {
31
104
 
32
105
  expect(getByTestId('address').textContent).toContain('Galapagosweg 91');
33
106
 
34
- expect(getByTestId('telecom').textContent).toContain('fax2329');
107
+ expect(getByTestId('telecom').textContent).toContain('2329');
35
108
 
36
109
  expect(queryByTestId('type')).toBeNull();
37
110
 
@@ -66,7 +139,7 @@ describe('should render Location component properly', () => {
66
139
 
67
140
  expect(getByTestId('address').textContent).toContain('Galapagosweg 91');
68
141
 
69
- expect(getByTestId('telecom').textContent).toContain('fax2329');
142
+ expect(getByTestId('telecom').textContent).toContain('2329');
70
143
 
71
144
  expect(queryByTestId('type')).toBeNull();
72
145
 
@@ -101,7 +174,7 @@ describe('should render Location component properly', () => {
101
174
 
102
175
  expect(getByTestId('address').textContent).toContain('Galapagosweg 91');
103
176
 
104
- expect(getByTestId('telecom').textContent).toContain('fax2329');
177
+ expect(getByTestId('telecom').textContent).toContain('2329');
105
178
 
106
179
  expect(queryByTestId('type')).toBeNull();
107
180
 
@@ -146,4 +219,33 @@ describe('should render Location component properly', () => {
146
219
  'Organization/f001',
147
220
  );
148
221
  });
222
+
223
+ it('should fire custom onClick function', () => {
224
+ const defaultProps = { fhirResource: r4Example1 };
225
+
226
+ const onClick = jest.fn();
227
+ const { getByRole } = render(
228
+ <Location {...defaultProps} onClick={onClick} />,
229
+ );
230
+ const accordion = getByRole('button');
231
+ fireEvent.click(accordion);
232
+
233
+ const attribute = accordion.getAttribute('data-bs-toggle');
234
+ expect(attribute).not.toEqual('collapse');
235
+ expect(onClick).toHaveBeenCalled();
236
+ });
237
+
238
+ it('should not fire custom onClick function', () => {
239
+ const defaultProps = { fhirResource: r4Example1 };
240
+
241
+ const onClick = 'test';
242
+ const { getByRole } = render(
243
+ <Location {...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).toEqual('collapse');
250
+ });
149
251
  });
@@ -5,18 +5,17 @@ import _get from 'lodash/get';
5
5
  import {
6
6
  Root,
7
7
  Header,
8
- Title,
9
8
  Badge,
10
9
  Body,
11
10
  ValueSection,
12
- Value,
13
- BadgeSecondary,
11
+ ValueSectionItem,
14
12
  } from '../../ui';
15
13
  import Coding from '../../datatypes/Coding';
16
14
  import Reference from '../../datatypes/Reference';
17
15
  import fhirVersions from '../fhirResourceVersions';
18
16
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
19
17
  import Attachment from '../../datatypes/Attachment';
18
+ import Accordion from '../../containers/Accordion';
20
19
 
21
20
  const commonDTO = fhirResource => {
22
21
  let title = _get(fhirResource, 'code.coding.0');
@@ -158,13 +157,18 @@ const Ingredient = props => {
158
157
  <Coding fhirData={itemDisplay} />
159
158
  </label>
160
159
  <Reference fhirData={reference} />
161
- {hasAmount && <BadgeSecondary>{amount}</BadgeSecondary>}
160
+ {hasAmount && <span>, {amount}</span>}
162
161
  </div>
163
162
  );
164
163
  };
165
164
 
166
- const Medication = props => {
167
- const { fhirResource, fhirVersion } = props;
165
+ const Medication = ({
166
+ fhirResource,
167
+ fhirVersion,
168
+ fhirIcons,
169
+ onClick,
170
+ rawOnClick,
171
+ }) => {
168
172
  let fhirResourceData = {};
169
173
  try {
170
174
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -187,54 +191,97 @@ const Medication = props => {
187
191
  status,
188
192
  } = fhirResourceData;
189
193
 
194
+ const tableData = [
195
+ {
196
+ label: 'Manufacturer',
197
+ testId: 'manufacturer',
198
+ data: manufacturer && <Reference fhirData={manufacturer} />,
199
+ status: manufacturer,
200
+ },
201
+ ];
202
+
203
+ const productData = [
204
+ {
205
+ label: 'Form',
206
+ testId: 'product-form',
207
+ data:
208
+ productForm &&
209
+ productForm.map((item, i) => (
210
+ <Coding key={`item-${i}`} fhirData={item} />
211
+ )),
212
+ status: productForm,
213
+ },
214
+ {
215
+ label: 'Ingredient',
216
+ testId: 'product-ingredient',
217
+ data:
218
+ hasProductIngredient &&
219
+ productIngredient.map((item, i) => (
220
+ <Ingredient key={`item-${i}`} {...item} />
221
+ )),
222
+ status: hasProductIngredient,
223
+ },
224
+ {
225
+ label: 'Package container',
226
+ testId: 'package-container',
227
+ data:
228
+ hasPackageCoding &&
229
+ packageCoding.map((item, i) => (
230
+ <Coding key={`item-${i}`} fhirData={item} />
231
+ )),
232
+ status: hasPackageCoding,
233
+ },
234
+ {
235
+ label: 'Images',
236
+ testId: 'product-images',
237
+ data:
238
+ hasImages &&
239
+ images.map((item, i) => (
240
+ <Attachment key={`item-${i}`} fhirData={item} isImage />
241
+ )),
242
+ status: hasImages,
243
+ },
244
+ ];
245
+
190
246
  return (
191
247
  <Root name="Medication">
192
- <Header>
193
- <Title>
194
- <Coding fhirData={title} />
195
- </Title>
196
- {isBrand && <Badge>Brand</Badge>}
197
- {status && <Badge>{status}</Badge>}
198
- </Header>
199
- <Body>
200
- {manufacturer && (
201
- <Value label="Manufacturer" data-testid="manufacturer">
202
- <Reference fhirData={manufacturer} />
203
- </Value>
204
- )}
205
- {hasProduct && (
206
- <ValueSection label="Product">
207
- {productForm && (
208
- <Value label="Form" data-testid="product-form">
209
- {productForm.map((item, i) => (
210
- <Coding key={`item-${i}`} fhirData={item} />
211
- ))}
212
- </Value>
213
- )}
214
- {hasProductIngredient && (
215
- <Value label="Ingredient" data-testid="product-ingredient">
216
- {productIngredient.map((item, i) => (
217
- <Ingredient key={`item-${i}`} {...item} />
218
- ))}
219
- </Value>
220
- )}
221
- {hasPackageCoding && (
222
- <Value label="Package container" data-testid="package-container">
223
- {packageCoding.map((item, i) => (
224
- <Coding key={`item-${i}`} fhirData={item} />
225
- ))}
226
- </Value>
227
- )}
228
- {hasImages && (
229
- <Value label="Images" data-testid="product-images">
230
- {images.map((item, i) => (
231
- <Attachment key={`item-${i}`} fhirData={item} />
232
- ))}
233
- </Value>
248
+ <Accordion
249
+ headerContent={
250
+ <Header
251
+ resourceName="Medication"
252
+ badges={
253
+ <>
254
+ {isBrand && <Badge data-testid="brand-badge">Brand</Badge>}
255
+ {status && <Badge data-testid="status">{status}</Badge>}
256
+ </>
257
+ }
258
+ title={<Coding fhirData={title} />}
259
+ icon={fhirIcons}
260
+ />
261
+ }
262
+ bodyContent={
263
+ <Body tableData={tableData}>
264
+ {hasProduct && (
265
+ <ValueSection label="Product" marginTop={manufacturer}>
266
+ {productData.map(
267
+ (item, index) =>
268
+ item.status && (
269
+ <ValueSectionItem
270
+ key={`product-item-${index}`}
271
+ label={item.label}
272
+ data-testid={item.testId}
273
+ >
274
+ {item.data}
275
+ </ValueSectionItem>
276
+ ),
277
+ )}
278
+ </ValueSection>
234
279
  )}
235
- </ValueSection>
236
- )}
237
- </Body>
280
+ </Body>
281
+ }
282
+ onClick={onClick}
283
+ rawOnClick={rawOnClick}
284
+ />
238
285
  </Root>
239
286
  );
240
287
  };