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
@@ -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,12 @@ 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
+ }) => {
187
168
  let fhirResourceData = {};
188
169
  try {
189
170
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -201,49 +182,68 @@ const MedicationDispense = props => {
201
182
  whenPrepared,
202
183
  } = fhirResourceData;
203
184
 
185
+ const tableData = [
186
+ {
187
+ label: 'Medication',
188
+ testId: 'medicationCoding',
189
+ data: medicationCoding && <Coding fhirData={medicationCoding} />,
190
+ status: medicationCoding,
191
+ },
192
+ {
193
+ label: 'Prepared',
194
+ testId: 'whenPrepared',
195
+ data: whenPrepared && <Date fhirData={whenPrepared} isBlack />,
196
+ status: whenPrepared,
197
+ },
198
+ {
199
+ label: 'Type',
200
+ testId: 'typeCoding',
201
+ data: typeCoding && <Coding fhirData={typeCoding} />,
202
+ status: typeCoding,
203
+ },
204
+ ];
205
+
204
206
  return (
205
207
  <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>
208
+ <Accordion
209
+ headerContent={
210
+ <Header
211
+ resourceName="MedicationDispense"
212
+ title={medicationTitle}
213
+ icon={fhirIcons}
214
+ />
215
+ }
216
+ bodyContent={
217
+ <Body tableData={tableData}>
218
+ {hasDosageInstruction && (
219
+ <ValueSection
220
+ label="Dosage instruction"
221
+ marginTop={medicationCoding || whenPrepared || typeCoding}
222
+ >
223
+ <Table>
224
+ <thead>
225
+ <TableRow>
226
+ <TableHeader>Timing</TableHeader>
227
+ <TableHeader>Route</TableHeader>
228
+ <TableHeader>Dose quantity</TableHeader>
229
+ <TableHeader>Additional instructions</TableHeader>
230
+ </TableRow>
231
+ </thead>
232
+ <tbody
233
+ data-testid="hasDosageInstruction"
234
+ className="border-top-0"
235
+ >
236
+ {dosageInstructionData.map((item, i) => (
237
+ <DosageInstruction key={`item-${i}`} item={item} />
238
+ ))}
239
+ </tbody>
240
+ </Table>
241
+ </ValueSection>
242
+ )}
243
+ </Body>
244
+ }
245
+ onClick={onClick}
246
+ />
247
247
  </Root>
248
248
  );
249
249
  };
@@ -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,13 @@ 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
+ }) => {
108
113
  let fhirResourceData = {};
109
114
  try {
110
115
  fhirResourceData = resourceDTO(fhirVersion, fhirResource, withDaVinciPDex);
@@ -138,72 +143,116 @@ const MedicationKnowledge = props => {
138
143
  : amountDisplay;
139
144
  }
140
145
 
146
+ const tableData = [
147
+ {
148
+ label: 'Code',
149
+ testId: 'code',
150
+ data: code && <CodeableConcept fhirData={code} isCursive />,
151
+ status: code,
152
+ },
153
+ {
154
+ label: 'Manufacturer',
155
+ testId: 'manufacturer',
156
+ data: manufacturer && <Reference fhirData={manufacturer} />,
157
+ status: manufacturer,
158
+ },
159
+ {
160
+ label: 'Amount',
161
+ testId: 'amount',
162
+ data: amountDisplay,
163
+ status: amountDisplay,
164
+ },
165
+ {
166
+ label: 'Synonym',
167
+ testId: 'synonym',
168
+ data: synonym,
169
+ status: synonym,
170
+ },
171
+ ];
172
+
173
+ const usdfExtensionsData = [
174
+ {
175
+ label: 'Prior Authorization',
176
+ testId: 'usdfPriorAuthorization',
177
+ data:
178
+ isBoolean(usdfPriorAuthorization) && usdfPriorAuthorization === true
179
+ ? 'yes'
180
+ : 'no',
181
+ status: isBoolean(usdfPriorAuthorization),
182
+ },
183
+ {
184
+ label: 'Step Therapy Limit',
185
+ testId: 'usdfStepTherapyLimit',
186
+ data:
187
+ isBoolean(usdfStepTherapyLimit) && usdfStepTherapyLimit === true
188
+ ? 'yes'
189
+ : 'no',
190
+ status: isBoolean(usdfStepTherapyLimit),
191
+ },
192
+ {
193
+ label: 'Quantity Limit',
194
+ testId: 'usdfQuantityLimit',
195
+ data:
196
+ isBoolean(usdfQuantityLimit) && usdfQuantityLimit === true
197
+ ? 'yes'
198
+ : 'no',
199
+ status: isBoolean(usdfQuantityLimit),
200
+ },
201
+ {
202
+ label: 'Plan ID',
203
+ testId: 'usdfPlanID',
204
+ data: usdfPlanID,
205
+ status: usdfPlanID,
206
+ },
207
+ {
208
+ label: 'Drug Tier ID',
209
+ testId: 'usdfDrugTierID',
210
+ data: usdfDrugTierID && <CodeableConcept fhirData={usdfDrugTierID} />,
211
+ status: usdfDrugTierID,
212
+ },
213
+ ];
214
+
141
215
  return (
142
216
  <Root name="MedicationKnowledge">
143
- <Header>
144
- <Title>
145
- {id ? `Medication knowledge ID: ${id}` : 'Medication 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"
217
+ <Accordion
218
+ headerContent={
219
+ <Header
220
+ resourceName="MedicationKnowledge"
221
+ title={
222
+ id
223
+ ? `Medication knowledge ID: ${id} `
224
+ : 'MedicationOrder knowledge '
225
+ }
226
+ badges={status && <Badge data-testid="status">{status}</Badge>}
227
+ icon={fhirIcons}
228
+ />
229
+ }
230
+ bodyContent={
231
+ <Body tableData={tableData}>
232
+ {hasExtensions && (
233
+ <ValueSection
234
+ label="USDF extensions"
235
+ data-testid="usdfExtensions"
236
+ marginTop
185
237
  >
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>
238
+ {usdfExtensionsData.map(
239
+ (item, index) =>
240
+ item.status && (
241
+ <ValueSectionItem
242
+ key={`usdf-extension-item-${index}`}
243
+ label={item.label}
244
+ data-testid={item.testId}
245
+ >
246
+ {item.data}
247
+ </ValueSectionItem>
248
+ ),
249
+ )}
250
+ </ValueSection>
203
251
  )}
204
- </ValueSection>
205
- )}
206
- </Body>
252
+ </Body>
253
+ }
254
+ onClick={onClick}
255
+ />
207
256
  </Root>
208
257
  );
209
258
  };
@@ -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
  };