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
@@ -9,37 +9,14 @@ import fhirVersions from '../fhirResourceVersions';
9
9
  import {
10
10
  Root,
11
11
  Header,
12
- Title,
13
12
  Body,
14
- Value,
15
13
  ValueSection,
16
14
  Table,
17
15
  TableHeader,
18
- TableCell,
19
16
  TableRow,
20
- MissingValue,
21
17
  } from '../../ui';
22
- import CodeableConcept from '../../datatypes/CodeableConcept/CodeableConcept';
23
-
24
- const DosageInstruction = props => {
25
- const empty = <MissingValue />;
26
- const {
27
- timing = empty,
28
- route = empty,
29
- doseQuantity = empty,
30
- additionalInstructions = empty,
31
- } = props.item;
32
- return (
33
- <TableRow>
34
- <TableCell data-testid="dosageTiming">{timing}</TableCell>
35
- <TableCell data-testid="dosageRoute">{route}</TableCell>
36
- <TableCell data-testid="dosageQuantity">{doseQuantity}</TableCell>
37
- <TableCell data-testid="dosageAdditionalInstructions">
38
- <CodeableConcept fhirData={additionalInstructions} />
39
- </TableCell>
40
- </TableRow>
41
- );
42
- };
18
+ import Accordion from '../../containers/Accordion';
19
+ import DosageInstruction from './DosageInstruction';
43
20
 
44
21
  const commonDTO = fhirResource => {
45
22
  const typeCoding = _get(fhirResource, 'type.coding.0');
@@ -182,8 +159,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
182
159
  }
183
160
  };
184
161
 
185
- const MedicationDispense = props => {
186
- const { fhirResource, fhirVersion } = props;
162
+ const MedicationDispense = ({
163
+ fhirResource,
164
+ fhirVersion,
165
+ fhirIcons,
166
+ onClick,
167
+ rawOnClick,
168
+ }) => {
187
169
  let fhirResourceData = {};
188
170
  try {
189
171
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -201,49 +183,69 @@ const MedicationDispense = props => {
201
183
  whenPrepared,
202
184
  } = fhirResourceData;
203
185
 
186
+ const tableData = [
187
+ {
188
+ label: 'Medication',
189
+ testId: 'medicationCoding',
190
+ data: medicationCoding && <Coding fhirData={medicationCoding} />,
191
+ status: medicationCoding,
192
+ },
193
+ {
194
+ label: 'Prepared',
195
+ testId: 'whenPrepared',
196
+ data: whenPrepared && <Date fhirData={whenPrepared} isBlack />,
197
+ status: whenPrepared,
198
+ },
199
+ {
200
+ label: 'Type',
201
+ testId: 'typeCoding',
202
+ data: typeCoding && <Coding fhirData={typeCoding} />,
203
+ status: typeCoding,
204
+ },
205
+ ];
206
+
204
207
  return (
205
208
  <Root name="MedicationDispense">
206
- {medicationTitle && (
207
- <Header>
208
- <Title>{medicationTitle}</Title>
209
- </Header>
210
- )}
211
- <Body>
212
- {medicationCoding && (
213
- <Value label="Medication" data-testid="medicationCoding">
214
- <Coding fhirData={medicationCoding} />
215
- </Value>
216
- )}
217
- {whenPrepared && (
218
- <Value label="Prepared" data-testid="whenPrepared">
219
- <Date fhirData={whenPrepared} />
220
- </Value>
221
- )}
222
- {typeCoding && (
223
- <Value label="Type" data-testid="typeCoding">
224
- <Coding fhirData={typeCoding} />
225
- </Value>
226
- )}
227
- {hasDosageInstruction && (
228
- <ValueSection label="Dosage instruction">
229
- <Table>
230
- <thead>
231
- <TableRow>
232
- <TableHeader>Timing</TableHeader>
233
- <TableHeader>Route</TableHeader>
234
- <TableHeader>Dose quantity</TableHeader>
235
- <TableHeader>Additional instructions</TableHeader>
236
- </TableRow>
237
- </thead>
238
- <tbody data-testid="hasDosageInstruction">
239
- {dosageInstructionData.map((item, i) => (
240
- <DosageInstruction key={`item-${i}`} item={item} />
241
- ))}
242
- </tbody>
243
- </Table>
244
- </ValueSection>
245
- )}
246
- </Body>
209
+ <Accordion
210
+ headerContent={
211
+ <Header
212
+ resourceName="MedicationDispense"
213
+ title={medicationTitle}
214
+ icon={fhirIcons}
215
+ />
216
+ }
217
+ bodyContent={
218
+ <Body tableData={tableData}>
219
+ {hasDosageInstruction && (
220
+ <ValueSection
221
+ label="Dosage instruction"
222
+ marginTop={medicationCoding || whenPrepared || typeCoding}
223
+ >
224
+ <Table>
225
+ <thead>
226
+ <TableRow>
227
+ <TableHeader>Timing</TableHeader>
228
+ <TableHeader>Route</TableHeader>
229
+ <TableHeader>Dose quantity</TableHeader>
230
+ <TableHeader>Additional instructions</TableHeader>
231
+ </TableRow>
232
+ </thead>
233
+ <tbody
234
+ data-testid="hasDosageInstruction"
235
+ className="border-top-0"
236
+ >
237
+ {dosageInstructionData.map((item, i) => (
238
+ <DosageInstruction key={`item-${i}`} item={item} />
239
+ ))}
240
+ </tbody>
241
+ </Table>
242
+ </ValueSection>
243
+ )}
244
+ </Body>
245
+ }
246
+ onClick={onClick}
247
+ rawOnClick={rawOnClick}
248
+ />
247
249
  </Root>
248
250
  );
249
251
  };
@@ -10,6 +10,8 @@ import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/ex
10
10
  import stu3Example2 from '../../../fixtures/stu3/resources/medicationDispense/example2.json';
11
11
  import R4Example1 from '../../../fixtures/r4/resources/medicationDispense/example1.json';
12
12
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
13
+ import fhirIcons from '../../../fixtures/example-icons';
14
+ import MedicationDispenseIcon from '../../../assets/containers/MedicationDispense/medication-dispense.svg';
13
15
 
14
16
  export default {
15
17
  title: 'MedicationDispense',
@@ -21,6 +23,7 @@ export const DefaultVisualizationDSTU2 = () => {
21
23
  <MedicationDispense
22
24
  fhirResource={fhirResource}
23
25
  fhirVersion={fhirVersions.DSTU2}
26
+ fhirIcons={require('../../../assets/containers/MedicationDispense/medication-dispense.svg')}
24
27
  />
25
28
  );
26
29
  };
@@ -31,6 +34,7 @@ export const Example2OfDSTU2 = () => {
31
34
  <MedicationDispense
32
35
  fhirResource={fhirResource}
33
36
  fhirVersion={fhirVersions.DSTU2}
37
+ fhirIcons={MedicationDispenseIcon}
34
38
  />
35
39
  );
36
40
  };
@@ -41,6 +45,7 @@ export const Example1OfSTU3 = () => {
41
45
  <MedicationDispense
42
46
  fhirResource={fhirResource}
43
47
  fhirVersion={fhirVersions.STU3}
48
+ fhirIcons={fhirIcons}
44
49
  />
45
50
  );
46
51
  };
@@ -51,6 +56,7 @@ export const Example2OfSTU3 = () => {
51
56
  <MedicationDispense
52
57
  fhirResource={fhirResource}
53
58
  fhirVersion={fhirVersions.STU3}
59
+ fhirIcons={false}
54
60
  />
55
61
  );
56
62
  };
@@ -61,6 +67,7 @@ export const Example1OfR4 = () => {
61
67
  <MedicationDispense
62
68
  fhirResource={fhirResource}
63
69
  fhirVersion={fhirVersions.R4}
70
+ fhirIcons={'random text'}
64
71
  />
65
72
  );
66
73
  };
@@ -1,13 +1,85 @@
1
1
  import React from 'react';
2
- import { render, within } from '@testing-library/react';
2
+ import { fireEvent, render, within } from '@testing-library/react';
3
3
  import MedicationDispense from './MedicationDispense';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import dstu2Example1 from '../../../fixtures/dstu2/resources/medicationDispense/example1.json';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/medicationDispense/example1.json';
8
8
  import R4Example2 from '../../../fixtures/r4/resources/medicationDispense/example2.json';
9
+ import fhirIcons from '../../../fixtures/example-icons';
9
10
 
10
11
  describe('should render Device component properly', () => {
12
+ it('component without a fhirIcons props should render a default icon', () => {
13
+ const defaultProps = {
14
+ fhirVersion: fhirVersions.DSTU2,
15
+ fhirResource: dstu2Example1,
16
+ };
17
+
18
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
19
+ const headerIcon = getByAltText('medication dispense');
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.DSTU2,
27
+ fhirResource: dstu2Example1,
28
+ fhirIcons: false,
29
+ };
30
+
31
+ const { getByTestId } = render(<MedicationDispense {...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.DSTU2,
40
+ fhirResource: dstu2Example1,
41
+ fhirIcons: (
42
+ <img
43
+ src={require('../assets/containers/MedicationDispense/medication-dispense.svg')}
44
+ alt="medication dispense"
45
+ />
46
+ ),
47
+ };
48
+
49
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
50
+ const headerIcon = getByAltText('medication dispense');
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.DSTU2,
58
+ fhirResource: dstu2Example1,
59
+ fhirIcons: fhirIcons,
60
+ };
61
+
62
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
63
+ const headerIcon = getByAltText('medication dispense');
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.DSTU2,
73
+ fhirResource: dstu2Example1,
74
+ fhirIcons: avatarSrc,
75
+ };
76
+
77
+ const { getByAltText } = render(<MedicationDispense {...defaultProps} />);
78
+ const headerIcon = getByAltText('header icon');
79
+
80
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
81
+ });
82
+
11
83
  it('should render with DSTU2 source data', () => {
12
84
  const defaultProps = {
13
85
  fhirResource: dstu2Example1,
@@ -84,4 +156,39 @@ describe('should render Device component properly', () => {
84
156
  ),
85
157
  ).toEqual(['Ordered(ordered)', 'Ordered(ordered)', 'Ordered(ordered)']);
86
158
  });
159
+
160
+ it('should fire custom onClick function', () => {
161
+ const defaultProps = {
162
+ fhirResource: R4Example2,
163
+ fhirVersion: fhirVersions.R4,
164
+ };
165
+
166
+ const onClick = jest.fn();
167
+ const { getByRole } = render(
168
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
169
+ );
170
+ const accordion = getByRole('button');
171
+ fireEvent.click(accordion);
172
+
173
+ const attribute = accordion.getAttribute('data-bs-toggle');
174
+ expect(attribute).not.toEqual('collapse');
175
+ expect(onClick).toHaveBeenCalled();
176
+ });
177
+
178
+ it('should not fire custom onClick function', () => {
179
+ const defaultProps = {
180
+ fhirResource: R4Example2,
181
+ fhirVersion: fhirVersions.R4,
182
+ };
183
+
184
+ const onClick = 'test';
185
+ const { getByRole } = render(
186
+ <MedicationDispense {...defaultProps} onClick={onClick} />,
187
+ );
188
+ const accordion = getByRole('button');
189
+ fireEvent.click(accordion);
190
+
191
+ const attribute = accordion.getAttribute('data-bs-toggle');
192
+ expect(attribute).toEqual('collapse');
193
+ });
87
194
  });
@@ -8,14 +8,14 @@ import { getExtension, isBoolean } from './utils';
8
8
  import {
9
9
  Root,
10
10
  Header,
11
- Title,
12
- Value,
13
11
  Body,
14
12
  Badge,
15
13
  ValueSection,
14
+ ValueSectionItem,
16
15
  } from '../../ui';
17
16
  import Reference from '../../datatypes/Reference';
18
17
  import CodeableConcept from '../../datatypes/CodeableConcept';
18
+ import Accordion from '../../containers/Accordion';
19
19
 
20
20
  const commonDTO = fhirResource => {
21
21
  const id = _get(fhirResource, 'id');
@@ -103,8 +103,14 @@ const resourceDTO = (fhirVersion, fhirResource, withDaVinciPDex) => {
103
103
  }
104
104
  };
105
105
 
106
- const MedicationKnowledge = props => {
107
- const { fhirResource, fhirVersion, withDaVinciPDex = false } = props;
106
+ const MedicationKnowledge = ({
107
+ fhirResource,
108
+ fhirVersion,
109
+ withDaVinciPDex = false,
110
+ fhirIcons,
111
+ onClick,
112
+ rawOnClick,
113
+ }) => {
108
114
  let fhirResourceData = {};
109
115
  try {
110
116
  fhirResourceData = resourceDTO(fhirVersion, fhirResource, withDaVinciPDex);
@@ -138,72 +144,117 @@ const MedicationKnowledge = props => {
138
144
  : amountDisplay;
139
145
  }
140
146
 
147
+ const tableData = [
148
+ {
149
+ label: 'Code',
150
+ testId: 'code',
151
+ data: code && <CodeableConcept fhirData={code} isCursive />,
152
+ status: code,
153
+ },
154
+ {
155
+ label: 'Manufacturer',
156
+ testId: 'manufacturer',
157
+ data: manufacturer && <Reference fhirData={manufacturer} />,
158
+ status: manufacturer,
159
+ },
160
+ {
161
+ label: 'Amount',
162
+ testId: 'amount',
163
+ data: amountDisplay,
164
+ status: amountDisplay,
165
+ },
166
+ {
167
+ label: 'Synonym',
168
+ testId: 'synonym',
169
+ data: synonym,
170
+ status: synonym,
171
+ },
172
+ ];
173
+
174
+ const usdfExtensionsData = [
175
+ {
176
+ label: 'Prior Authorization',
177
+ testId: 'usdfPriorAuthorization',
178
+ data:
179
+ isBoolean(usdfPriorAuthorization) && usdfPriorAuthorization === true
180
+ ? 'yes'
181
+ : 'no',
182
+ status: isBoolean(usdfPriorAuthorization),
183
+ },
184
+ {
185
+ label: 'Step Therapy Limit',
186
+ testId: 'usdfStepTherapyLimit',
187
+ data:
188
+ isBoolean(usdfStepTherapyLimit) && usdfStepTherapyLimit === true
189
+ ? 'yes'
190
+ : 'no',
191
+ status: isBoolean(usdfStepTherapyLimit),
192
+ },
193
+ {
194
+ label: 'Quantity Limit',
195
+ testId: 'usdfQuantityLimit',
196
+ data:
197
+ isBoolean(usdfQuantityLimit) && usdfQuantityLimit === true
198
+ ? 'yes'
199
+ : 'no',
200
+ status: isBoolean(usdfQuantityLimit),
201
+ },
202
+ {
203
+ label: 'Plan ID',
204
+ testId: 'usdfPlanID',
205
+ data: usdfPlanID,
206
+ status: usdfPlanID,
207
+ },
208
+ {
209
+ label: 'Drug Tier ID',
210
+ testId: 'usdfDrugTierID',
211
+ data: usdfDrugTierID && <CodeableConcept fhirData={usdfDrugTierID} />,
212
+ status: usdfDrugTierID,
213
+ },
214
+ ];
215
+
141
216
  return (
142
217
  <Root name="MedicationKnowledge">
143
- <Header>
144
- <Title>
145
- {id ? `Medication knowledge ID: ${id}` : 'MedicationOrder knowledge'}{' '}
146
- {status && <Badge data-testid="status">{status}</Badge>}
147
- </Title>
148
- </Header>
149
- <Body>
150
- {code && (
151
- <Value label="Code" data-testid="code">
152
- <CodeableConcept fhirData={code} />
153
- </Value>
154
- )}
155
- {manufacturer && (
156
- <Value label="Manufacturer" data-testid="manufacturer">
157
- <Reference fhirData={manufacturer} />
158
- </Value>
159
- )}
160
- {amountDisplay && (
161
- <Value label="Amount" data-testid="amount">
162
- {amountDisplay}
163
- </Value>
164
- )}
165
- {synonym && (
166
- <Value label="Synonym" data-testid="synonym">
167
- {synonym}
168
- </Value>
169
- )}
170
-
171
- {hasExtensions && (
172
- <ValueSection label="USDF extensions" data-testid="usdfExtensions">
173
- {isBoolean(usdfPriorAuthorization) && (
174
- <Value
175
- label="Prior Authorization"
176
- data-testid="usdfPriorAuthorization"
177
- >
178
- {usdfPriorAuthorization === true ? 'yes' : 'no'}
179
- </Value>
180
- )}
181
- {isBoolean(usdfStepTherapyLimit) && (
182
- <Value
183
- label="Step Therapy Limit"
184
- data-testid="usdfStepTherapyLimit"
218
+ <Accordion
219
+ headerContent={
220
+ <Header
221
+ resourceName="MedicationKnowledge"
222
+ title={
223
+ id
224
+ ? `Medication knowledge ID: ${id} `
225
+ : 'MedicationOrder knowledge '
226
+ }
227
+ badges={status && <Badge data-testid="status">{status}</Badge>}
228
+ icon={fhirIcons}
229
+ />
230
+ }
231
+ bodyContent={
232
+ <Body tableData={tableData}>
233
+ {hasExtensions && (
234
+ <ValueSection
235
+ label="USDF extensions"
236
+ data-testid="usdfExtensions"
237
+ marginTop
185
238
  >
186
- {usdfStepTherapyLimit === true ? 'yes' : 'no'}
187
- </Value>
188
- )}
189
- {isBoolean(usdfQuantityLimit) && (
190
- <Value label="Quantity Limit" data-testid="usdfQuantityLimit">
191
- {usdfQuantityLimit === true ? 'yes' : 'no'}
192
- </Value>
193
- )}
194
- {usdfPlanID && (
195
- <Value label="Plan ID" data-testid="usdfPlanID">
196
- {usdfPlanID}
197
- </Value>
198
- )}
199
- {usdfDrugTierID && (
200
- <Value label="Drug Tier ID" data-testid="usdfDrugTierID">
201
- <CodeableConcept fhirData={usdfDrugTierID} />
202
- </Value>
239
+ {usdfExtensionsData.map(
240
+ (item, index) =>
241
+ item.status && (
242
+ <ValueSectionItem
243
+ key={`usdf-extension-item-${index}`}
244
+ label={item.label}
245
+ data-testid={item.testId}
246
+ >
247
+ {item.data}
248
+ </ValueSectionItem>
249
+ ),
250
+ )}
251
+ </ValueSection>
203
252
  )}
204
- </ValueSection>
205
- )}
206
- </Body>
253
+ </Body>
254
+ }
255
+ onClick={onClick}
256
+ rawOnClick={rawOnClick}
257
+ />
207
258
  </Root>
208
259
  );
209
260
  };
@@ -8,6 +8,8 @@ import example1R4 from '../../../fixtures/r4/resources/medicationKnowledge/examp
8
8
  import example2R4 from '../../../fixtures/r4/resources/medicationKnowledge/example2.json';
9
9
  import example3R4 from '../../../fixtures/r4/resources/medicationKnowledge/example3.json';
10
10
  import example4R4 from '../../../fixtures/r4/resources/medicationKnowledge/example4.json';
11
+ import fhirIcons from '../../../fixtures/example-icons';
12
+ import MedicationKnowledgeIcon from '../../../assets/containers/MedicationKnowledge/medication-knowledge.svg';
11
13
 
12
14
  export default {
13
15
  title: 'MedicationKnowledge',
@@ -19,6 +21,7 @@ export const DefaultVisualizationR4 = () => {
19
21
  <MedicationKnowledge
20
22
  fhirVersion={fhirVersions.R4}
21
23
  fhirResource={fhirResource}
24
+ fhirIcons={require('../../../assets/containers/MedicationKnowledge/medication-knowledge.svg')}
22
25
  />
23
26
  );
24
27
  };
@@ -28,6 +31,7 @@ export const ExampleR4WithoutDaVinciPDex = () => {
28
31
  <MedicationKnowledge
29
32
  fhirVersion={fhirVersions.R4}
30
33
  fhirResource={fhirResource}
34
+ fhirIcons={MedicationKnowledgeIcon}
31
35
  />
32
36
  );
33
37
  };
@@ -38,6 +42,7 @@ export const ExampleR4WithDaVinciPDex = () => {
38
42
  fhirVersion={fhirVersions.R4}
39
43
  fhirResource={fhirResource}
40
44
  withDaVinciPDex
45
+ fhirIcons={fhirIcons}
41
46
  />
42
47
  );
43
48
  };
@@ -58,6 +63,7 @@ export const Example3R4WithDaVinciPDex = () => {
58
63
  fhirVersion={fhirVersions.R4}
59
64
  fhirResource={fhirResource}
60
65
  withDaVinciPDex
66
+ fhirIcons={false}
61
67
  />
62
68
  );
63
69
  };