fhir-react 0.3.7 → 0.3.10

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 (179) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.storybook/main.js +5 -0
  4. package/.storybook/manager.js +6 -0
  5. package/.storybook/preview.js +7 -0
  6. package/.stylelintrc +6 -2
  7. package/README.md +19 -1
  8. package/build/index.js +15 -11
  9. package/build/style.css +9 -9
  10. package/package.json +59 -57
  11. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  12. package/src/assets/containers/Generic/generic.svg +3 -0
  13. package/src/assets/containers/MedicationDispense/medication-dispense.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/Accordion/Accordion.stories.js +74 -58
  19. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  20. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  21. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
  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/Reference/Reference.js +7 -5
  25. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  26. package/src/components/defaultArgTypes.js +12 -0
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
  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.stories.js +51 -62
  35. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  36. package/src/components/resources/Binary/Binary.js +2 -1
  37. package/src/components/resources/Binary/Binary.stories.js +27 -21
  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 +59 -115
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
  44. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
  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/Claim.js +9 -1
  50. package/src/components/resources/Claim/Claim.stories.js +36 -49
  51. package/src/components/resources/Claim/Claim.test.js +32 -1
  52. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  53. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  54. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  55. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
  56. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  57. package/src/components/resources/ClaimResponse/Item.js +44 -9
  58. package/src/components/resources/ClaimResponse/Items.js +5 -4
  59. package/src/components/resources/Condition/Condition.js +10 -3
  60. package/src/components/resources/Condition/Condition.stories.js +47 -62
  61. package/src/components/resources/Condition/Condition.test.js +37 -4
  62. package/src/components/resources/Coverage/Coverage.js +9 -1
  63. package/src/components/resources/Coverage/Coverage.stories.js +38 -50
  64. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  65. package/src/components/resources/Device/Device.js +9 -1
  66. package/src/components/resources/Device/Device.stories.js +40 -52
  67. package/src/components/resources/Device/Device.test.js +36 -1
  68. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
  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.stories.js +25 -29
  73. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  74. package/src/components/resources/Encounter/Encounter.js +9 -1
  75. package/src/components/resources/Encounter/Encounter.stories.js +43 -59
  76. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  77. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  78. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
  79. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  80. package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
  81. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  82. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  84. package/src/components/resources/Generic/Generic.js +21 -7
  85. package/src/components/resources/Generic/Generic.stories.js +22 -12
  86. package/src/components/resources/Generic/Generic.test.js +26 -7
  87. package/src/components/resources/Goal/Goal.js +9 -3
  88. package/src/components/resources/Goal/Goal.stories.js +35 -49
  89. package/src/components/resources/Goal/Goal.test.js +32 -1
  90. package/src/components/resources/Immunization/Immunization.js +9 -2
  91. package/src/components/resources/Immunization/Immunization.stories.js +38 -51
  92. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  93. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  94. package/src/components/resources/List/Entries.js +3 -3
  95. package/src/components/resources/List/List.js +137 -88
  96. package/src/components/resources/List/List.stories.js +69 -40
  97. package/src/components/resources/List/List.test.js +105 -1
  98. package/src/components/resources/Location/Location.js +66 -47
  99. package/src/components/resources/Location/Location.stories.js +25 -13
  100. package/src/components/resources/Location/Location.test.js +106 -4
  101. package/src/components/resources/Medication/Medication.js +9 -1
  102. package/src/components/resources/Medication/Medication.stories.js +42 -64
  103. package/src/components/resources/Medication/Medication.test.js +36 -1
  104. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  107. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  108. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  109. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
  110. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  111. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  114. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  115. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  117. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  118. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
  119. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  120. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  121. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
  122. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  123. package/src/components/resources/Observation/Observation.js +3 -1
  124. package/src/components/resources/Observation/Observation.stories.js +39 -33
  125. package/src/components/resources/Observation/Observation.test.js +30 -1
  126. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  127. package/src/components/resources/Organization/Organization.js +10 -2
  128. package/src/components/resources/Organization/Organization.stories.js +40 -52
  129. package/src/components/resources/Organization/Organization.test.js +36 -1
  130. package/src/components/resources/Patient/Patient.js +4 -0
  131. package/src/components/resources/Patient/Patient.stories.js +36 -28
  132. package/src/components/resources/Patient/Patient.test.js +31 -2
  133. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  134. package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
  135. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  136. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  137. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
  138. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  139. package/src/components/resources/Procedure/Procedure.js +3 -2
  140. package/src/components/resources/Procedure/Procedure.stories.js +33 -25
  141. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  142. package/src/components/resources/Questionnaire/Group.js +53 -0
  143. package/src/components/resources/Questionnaire/Items.js +45 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  145. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  146. package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
  147. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  148. package/src/components/resources/Questionnaire/Questions.js +40 -0
  149. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  150. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  151. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  152. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  154. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  155. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
  156. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  157. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  158. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  159. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  160. package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
  161. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  162. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  163. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -0
  164. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  165. package/src/components/resources/RelatedPerson/index.js +3 -0
  166. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  167. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
  168. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  169. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  170. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
  171. package/src/components/ui/index.js +48 -31
  172. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  173. package/src/fixtures/example-icons.jsx +42 -0
  174. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  175. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  176. package/src/style.scss +14 -1
  177. package/.storybook/addons.js +0 -1
  178. package/.storybook/config.js +0 -26
  179. package/.storybook/presets.js +0 -1
@@ -19,8 +19,7 @@ export const hasValue = data => {
19
19
  return false;
20
20
  };
21
21
 
22
- const CodeableConcept = props => {
23
- const { fhirData } = props;
22
+ const CodeableConcept = ({ fhirData, isCursive = false }) => {
24
23
  if (!_isObject(fhirData)) return null;
25
24
 
26
25
  const data = Array.isArray(fhirData) ? fhirData : [fhirData];
@@ -40,7 +39,11 @@ const CodeableConcept = props => {
40
39
  </span>
41
40
  )}
42
41
  {coding.map((codingData, j) => (
43
- <Coding key={`codingData-${j}`} fhirData={codingData} />
42
+ <Coding
43
+ key={`codingData-${j}`}
44
+ fhirData={codingData}
45
+ isCursive={isCursive}
46
+ />
44
47
  ))}
45
48
  </div>
46
49
  );
@@ -4,8 +4,7 @@ import _get from 'lodash/get';
4
4
 
5
5
  import './Coding.css';
6
6
 
7
- const Coding = props => {
8
- const { fhirData } = props;
7
+ const Coding = ({ fhirData, isCursive = false }) => {
9
8
  const display = _get(fhirData, 'display', '');
10
9
  const code = _get(fhirData, 'code', '');
11
10
  const system = _get(fhirData, 'system', '');
@@ -14,7 +13,12 @@ const Coding = props => {
14
13
  <div className="fhir-datatype__Coding">
15
14
  <span className="fhir-datatype__Coding__title">{display}</span>&nbsp;
16
15
  {hasAdditionalInfo && (
17
- <span className="fhir-datatype__Coding__code" title={system}>
16
+ <span
17
+ className={`${
18
+ isCursive ? 'fst-italic' : ''
19
+ } fhir-datatype__Coding__code`}
20
+ title={system}
21
+ >
18
22
  ({code || '?'})
19
23
  </span>
20
24
  )}
@@ -7,17 +7,19 @@ const Reference = props => {
7
7
  const { fhirData } = props;
8
8
  const display = _get(fhirData, 'display');
9
9
  const reference = _get(fhirData, 'reference', '');
10
+
10
11
  return (
11
12
  <div
12
13
  className="fhir-datatype__Reference d-inline-block"
13
14
  data-testid={props['data-testid']}
14
15
  >
15
16
  {display && <span className="mr-2 pe-1">{display}</span>}
16
- {reference.startsWith('http://') || reference.startsWith('https://') ? (
17
- <a href={reference}>{reference}</a>
18
- ) : (
19
- <span>{reference}</span>
20
- )}
17
+ {!display &&
18
+ (reference.startsWith('http://') || reference.startsWith('https://') ? (
19
+ <a href={reference}>{reference}</a>
20
+ ) : (
21
+ <span>{reference}</span>
22
+ ))}
21
23
  </div>
22
24
  );
23
25
  };
@@ -3,8 +3,7 @@ import _get from 'lodash/get';
3
3
 
4
4
  import './Telecom.css';
5
5
 
6
- const Telecom = props => {
7
- const { fhirData } = props;
6
+ const Telecom = ({ fhirData, noSystemData = false }) => {
8
7
  if (Array.isArray(fhirData)) {
9
8
  return (
10
9
  <div className="fhir-datatype__Telecom">
@@ -12,7 +11,7 @@ const Telecom = props => {
12
11
  const system = _get(item, 'system', '');
13
12
  return (
14
13
  <div className="fhir-datatype__Telecom__item" key={`phone-${i}`}>
15
- {system && (
14
+ {!noSystemData && system && (
16
15
  <span className="fhir-datatype__Telecom__item-label">
17
16
  {system}
18
17
  </span>
@@ -0,0 +1,12 @@
1
+ export const defaultArgTypes = {
2
+ fhirVersion: {
3
+ table: {
4
+ disable: true,
5
+ },
6
+ },
7
+ fhirIcons: {
8
+ table: {
9
+ disable: true,
10
+ },
11
+ },
12
+ };
@@ -2,11 +2,19 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _get from 'lodash/get';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
- import { Root, Header, Title, Body, Value } from '../../ui';
5
+ import {
6
+ Root,
7
+ Header,
8
+ Body,
9
+ ValueSection,
10
+ ValueSectionItem,
11
+ Value,
12
+ } from '../../ui';
6
13
  import Reference from '../../datatypes/Reference';
7
14
  import Date from '../../datatypes/Date';
8
15
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
9
16
  import CodeableConcept, { hasValue } from '../../datatypes/CodeableConcept';
17
+ import Accordion from '../../containers/Accordion';
10
18
 
11
19
  const commonDTO = fhirResource => {
12
20
  const subject = _get(fhirResource, 'subject');
@@ -63,8 +71,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
63
71
  }
64
72
  };
65
73
 
66
- const AdverseEvent = props => {
67
- const { fhirResource, fhirVersion } = props;
74
+ const AdverseEvent = ({
75
+ fhirResource,
76
+ fhirVersion,
77
+ fhirIcons,
78
+ onClick,
79
+ rawOnClick,
80
+ }) => {
68
81
  let fhirResourceData = {};
69
82
  try {
70
83
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -86,47 +99,80 @@ const AdverseEvent = props => {
86
99
  hasEvent,
87
100
  } = fhirResourceData;
88
101
 
102
+ const tableData = [
103
+ {
104
+ label: 'Event',
105
+ testId: 'event',
106
+ data: hasEventType && <CodeableConcept fhirData={eventType} />,
107
+ status: hasEventType,
108
+ },
109
+ {
110
+ label: 'Event',
111
+ testId: 'event',
112
+ data: hasEvent && <CodeableConcept fhirData={event} />,
113
+ status: hasEvent,
114
+ },
115
+ {
116
+ label: 'Seriousness',
117
+ testId: 'hasSeriousness',
118
+ data: hasSeriousness && (
119
+ <CodeableConcept fhirData={seriousness} isCursive />
120
+ ),
121
+ status: hasSeriousness,
122
+ },
123
+ {
124
+ label: 'Actuality',
125
+ testId: 'actuality',
126
+ data: actuality,
127
+ status: actuality,
128
+ },
129
+ ];
130
+
89
131
  return (
90
132
  <Root name="AdverseEvent">
91
- <Header>
92
- {subject && (
93
- <Title>
94
- <Reference fhirData={subject} />
95
- </Title>
96
- )}
97
- </Header>
98
- <Body>
99
- {date && (
100
- <Value label="Date" data-testid="date">
101
- <Date fhirData={date} />
102
- </Value>
103
- )}
104
- {hasEventType && (
105
- <Value label="Type" data-testid="type">
106
- <CodeableConcept fhirData={eventType} />
107
- </Value>
108
- )}
109
- {hasEvent && (
110
- <Value label="Event" data-testid="event">
111
- <CodeableConcept fhirData={event} />
112
- </Value>
113
- )}
114
- {description && (
115
- <Value label="Description" data-testid="description">
116
- {description}
117
- </Value>
118
- )}
119
- {hasSeriousness && (
120
- <Value label="Seriousness" data-testid="hasSeriousness">
121
- <CodeableConcept fhirData={seriousness} />
122
- </Value>
123
- )}
124
- {actuality && (
125
- <Value label="Actuality" data-testid="actuality">
126
- {actuality}
127
- </Value>
128
- )}
129
- </Body>
133
+ <Accordion
134
+ headerContent={
135
+ <Header
136
+ resourceName={'AdverseEvent'}
137
+ title={subject && <Reference fhirData={subject} />}
138
+ icon={fhirIcons}
139
+ additionalContent={
140
+ date && (
141
+ <Value label="Date" data-testid="date">
142
+ <Date fhirData={date} isBlack />
143
+ </Value>
144
+ )
145
+ }
146
+ />
147
+ }
148
+ bodyContent={
149
+ <Body>
150
+ {description && (
151
+ <ValueSection
152
+ label="Comment"
153
+ data-testid="description"
154
+ marginBottom
155
+ >
156
+ <span className="text-secondary">{description}</span>
157
+ </ValueSection>
158
+ )}
159
+ {tableData.map(
160
+ (item, index) =>
161
+ item.status && (
162
+ <ValueSectionItem
163
+ key={`adverse-event-item-${index}`}
164
+ label={item.label}
165
+ data-testid={item.testId}
166
+ >
167
+ {item.data}
168
+ </ValueSectionItem>
169
+ ),
170
+ )}
171
+ </Body>
172
+ }
173
+ onClick={onClick}
174
+ rawOnClick={rawOnClick}
175
+ />
130
176
  </Root>
131
177
  );
132
178
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import AdverseEvent from './AdverseEvent';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -7,20 +7,28 @@ import fhirVersions from '../fhirResourceVersions';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/adverseEvent/example1.json';
8
8
  import r4Example1 from '../../../fixtures/r4/resources/adverseEvent/example1.json';
9
9
 
10
+ import fhirIcons from '../../../fixtures/example-icons';
11
+
10
12
  export default {
11
13
  title: 'AdverseEvent',
14
+ component: AdverseEvent,
15
+ argTypes: {
16
+ ...defaultArgTypes,
17
+ },
12
18
  };
13
19
 
14
- export const DefaultVisualizationSTU3 = () => {
15
- const fhirResource = object('Resource', stu3Example1);
16
- return (
17
- <AdverseEvent fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
18
- );
20
+ const Template = args => <AdverseEvent {...args} />;
21
+
22
+ export const DefaultVisualizationSTU3 = Template.bind({});
23
+ DefaultVisualizationSTU3.args = {
24
+ fhirVersion: fhirVersions.STU3,
25
+ fhirResource: stu3Example1,
26
+ fhirIcons: fhirIcons,
19
27
  };
20
28
 
21
- export const Example1ofR4 = () => {
22
- const fhirResource = object('Resource', r4Example1);
23
- return (
24
- <AdverseEvent fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
25
- );
29
+ export const Example1ofR4 = Template.bind({});
30
+ Example1ofR4.args = {
31
+ fhirVersion: fhirVersions.R4,
32
+ fhirResource: r4Example1,
33
+ fhirIcons: false,
26
34
  };
@@ -1,12 +1,84 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
3
  import AdverseEvent from './AdverseEvent';
4
4
  import fhirVersions from '../fhirResourceVersions';
5
5
 
6
6
  import stu3Example1 from '../../../fixtures/stu3/resources/adverseEvent/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/adverseEvent/example1.json';
8
+ import fhirIcons from '../../../fixtures/example-icons';
8
9
 
9
10
  describe('should render component correctly', () => {
11
+ it('component without a fhirIcons props should render a default icon', () => {
12
+ const defaultProps = {
13
+ fhirVersion: fhirVersions.STU3,
14
+ fhirResource: stu3Example1,
15
+ };
16
+
17
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
18
+ const headerIcon = getByAltText('adverse event');
19
+
20
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
21
+ });
22
+
23
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
24
+ const defaultProps = {
25
+ fhirVersion: fhirVersions.STU3,
26
+ fhirResource: stu3Example1,
27
+ fhirIcons: false,
28
+ };
29
+
30
+ const { getByTestId } = render(<AdverseEvent {...defaultProps} />);
31
+ const headerIcon = getByTestId('placeholder');
32
+
33
+ expect(headerIcon).toBeTruthy();
34
+ });
35
+
36
+ it('component with the img as a fhirIcons props should render an img', () => {
37
+ const defaultProps = {
38
+ fhirVersion: fhirVersions.STU3,
39
+ fhirResource: stu3Example1,
40
+ fhirIcons: (
41
+ <img
42
+ src={require('../assets/containers/AdverseEvent/adverse-event.svg')}
43
+ alt="adverse event"
44
+ />
45
+ ),
46
+ };
47
+
48
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
49
+ const headerIcon = getByAltText('adverse event');
50
+
51
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
52
+ });
53
+
54
+ it('component with the resources object as a fhirIcons props should render an img', () => {
55
+ const defaultProps = {
56
+ fhirVersion: fhirVersions.STU3,
57
+ fhirResource: stu3Example1,
58
+ fhirIcons: fhirIcons,
59
+ };
60
+
61
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
62
+ const headerIcon = getByAltText('adverse event');
63
+
64
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
65
+ });
66
+
67
+ it('component with the url as a fhirIcons props should render an img', () => {
68
+ const avatarSrc =
69
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
70
+ const defaultProps = {
71
+ fhirVersion: fhirVersions.STU3,
72
+ fhirResource: stu3Example1,
73
+ fhirIcons: avatarSrc,
74
+ };
75
+
76
+ const { getByAltText } = render(<AdverseEvent {...defaultProps} />);
77
+ const headerIcon = getByAltText('header icon');
78
+
79
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
80
+ });
81
+
10
82
  it('should render with STU3 source data', () => {
11
83
  const defaultProps = {
12
84
  fhirResource: stu3Example1,
@@ -18,7 +90,7 @@ describe('should render component correctly', () => {
18
90
 
19
91
  expect(getByTestId('date').textContent).toEqual('1/29/2017');
20
92
 
21
- expect(getByTestId('type').textContent).toContain('304386008');
93
+ expect(getByTestId('event').textContent).toContain('304386008');
22
94
 
23
95
  expect(getByTestId('description').textContent).toContain(
24
96
  'This was a mild rash',
@@ -44,4 +116,39 @@ describe('should render component correctly', () => {
44
116
 
45
117
  expect(getByTestId('actuality').textContent).toEqual('actual');
46
118
  });
119
+
120
+ it('should fire custom onClick function', () => {
121
+ const defaultProps = {
122
+ fhirResource: r4Example1,
123
+ fhirVersion: fhirVersions.R4,
124
+ };
125
+
126
+ const onClick = jest.fn();
127
+ const { getByRole } = render(
128
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
129
+ );
130
+ const accordion = getByRole('button');
131
+ fireEvent.click(accordion);
132
+
133
+ const attribute = accordion.getAttribute('data-bs-toggle');
134
+ expect(attribute).not.toEqual('collapse');
135
+ expect(onClick).toHaveBeenCalled();
136
+ });
137
+
138
+ it('should not fire custom onClick function', () => {
139
+ const defaultProps = {
140
+ fhirResource: r4Example1,
141
+ fhirVersion: fhirVersions.R4,
142
+ };
143
+
144
+ const onClick = 'test';
145
+ const { getByRole } = render(
146
+ <AdverseEvent {...defaultProps} onClick={onClick} />,
147
+ );
148
+ const accordion = getByRole('button');
149
+ fireEvent.click(accordion);
150
+
151
+ const attribute = accordion.getAttribute('data-bs-toggle');
152
+ expect(attribute).toEqual('collapse');
153
+ });
47
154
  });
@@ -123,7 +123,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
123
123
  }
124
124
  };
125
125
 
126
- const AllergyIntolerance = ({ fhirResource, fhirVersion, fhirIcons }) => {
126
+ const AllergyIntolerance = ({
127
+ fhirResource,
128
+ fhirVersion,
129
+ fhirIcons,
130
+ onClick,
131
+ rawOnClick,
132
+ }) => {
127
133
  let fhirResourceData = {};
128
134
  try {
129
135
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -231,6 +237,8 @@ const AllergyIntolerance = ({ fhirResource, fhirVersion, fhirIcons }) => {
231
237
  />
232
238
  }
233
239
  bodyContent={<Body tableData={tableData} />}
240
+ onClick={onClick}
241
+ rawOnClick={rawOnClick}
234
242
  />
235
243
  </Root>
236
244
  );
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import AllergyIntolerance from './AllergyIntolerance';
5
5
 
@@ -14,88 +14,64 @@ import fhirIcons from '../../../fixtures/example-icons';
14
14
  import fhirVersions from '../fhirResourceVersions';
15
15
  import AllergyIntoleranceIcon from '../../../assets/containers/AllergyIntolerance/allergy-intolerance.svg';
16
16
 
17
- export default { title: 'AllergyIntolerance' };
17
+ export default {
18
+ title: 'AllergyIntolerance',
19
+ component: AllergyIntolerance,
20
+ argTypes: {
21
+ ...defaultArgTypes,
22
+ },
23
+ };
24
+
25
+ const Template = args => <AllergyIntolerance {...args} />;
18
26
 
19
- export const DefaultVisualizationDSTU2 = () => {
20
- const fhirResource = object('Resource', exampleAllergyIntoleranceDSTU2);
21
- return (
22
- <AllergyIntolerance
23
- fhirVersion={fhirVersions.DSTU2}
24
- fhirResource={fhirResource}
25
- fhirIcons={require('../../../assets/containers/AllergyIntolerance/allergy-intolerance.svg')}
26
- />
27
- );
27
+ export const DefaultVisualizationDSTU2 = Template.bind({});
28
+ DefaultVisualizationDSTU2.args = {
29
+ fhirVersion: fhirVersions.DSTU2,
30
+ fhirResource: exampleAllergyIntoleranceDSTU2,
31
+ fhirIcons: require('../../../assets/containers/AllergyIntolerance/allergy-intolerance.svg'),
28
32
  };
29
33
 
30
- export const Example2ofDSTU2 = () => {
31
- const fhirResource = object('Resource', example2AllergyIntoleranceDSTU2);
32
- return (
33
- <AllergyIntolerance
34
- fhirVersion={fhirVersions.DSTU2}
35
- fhirResource={fhirResource}
36
- fhirIcons={AllergyIntoleranceIcon}
37
- />
38
- );
34
+ export const Example2ofDSTU2 = Template.bind({});
35
+ Example2ofDSTU2.args = {
36
+ fhirVersion: fhirVersions.DSTU2,
37
+ fhirResource: example2AllergyIntoleranceDSTU2,
38
+ fhirIcons: AllergyIntoleranceIcon,
39
39
  };
40
40
 
41
- export const ExampleDiagnosticReportSTU3 = () => {
42
- const fhirResource = object('Resource', exampleAllergyIntoleranceSTU3);
43
- return (
44
- <AllergyIntolerance
45
- fhirVersion={fhirVersions.STU3}
46
- fhirResource={fhirResource}
47
- fhirIcons={fhirIcons}
48
- />
49
- );
41
+ export const ExampleDiagnosticReportSTU3 = Template.bind({});
42
+ ExampleDiagnosticReportSTU3.args = {
43
+ fhirVersion: fhirVersions.STU3,
44
+ fhirResource: exampleAllergyIntoleranceSTU3,
45
+ fhirIcons: fhirIcons,
50
46
  };
51
47
 
52
- export const Example2DiagnosticReportSTU3 = () => {
53
- const fhirResource = object('Resource', example2AllergyIntoleranceSTU3);
54
- return (
55
- <AllergyIntolerance
56
- fhirVersion={fhirVersions.STU3}
57
- fhirResource={fhirResource}
58
- fhirIcons={false}
59
- />
60
- );
48
+ export const Example2DiagnosticReportSTU3 = Template.bind({});
49
+ Example2DiagnosticReportSTU3.args = {
50
+ fhirVersion: fhirVersions.STU3,
51
+ fhirResource: example2AllergyIntoleranceSTU3,
52
+ fhirIcons: false,
61
53
  };
62
54
 
63
- export const Example1R4 = () => {
64
- const fhirResource = object('Resource', example1AllergyIntoleranceR4);
65
- return (
66
- <AllergyIntolerance
67
- fhirVersion={fhirVersions.R4}
68
- fhirResource={fhirResource}
69
- fhirIcons={'random text'}
70
- />
71
- );
55
+ export const Example1R4 = Template.bind({});
56
+ Example1R4.args = {
57
+ fhirVersion: fhirVersions.R4,
58
+ fhirResource: example1AllergyIntoleranceR4,
59
+ fhirIcons: 'random text',
72
60
  };
73
61
 
74
- export const Example2R4 = () => {
75
- const fhirResource = object('Resource', example2AllergyIntoleranceR4);
76
- return (
77
- <AllergyIntolerance
78
- fhirVersion={fhirVersions.R4}
79
- fhirResource={fhirResource}
80
- fhirIcons={fhirIcons}
81
- />
82
- );
62
+ export const Example2R4 = Template.bind({});
63
+ Example2R4.args = {
64
+ fhirVersion: fhirVersions.R4,
65
+ fhirResource: example2AllergyIntoleranceR4,
83
66
  };
84
67
 
85
- export const Example3R4 = () => {
86
- const fhirResource = object('Resource', example3AllergyIntoleranceR4);
87
- return (
88
- <AllergyIntolerance
89
- fhirVersion={fhirVersions.R4}
90
- fhirResource={fhirResource}
91
- fhirIcons={fhirIcons}
92
- />
93
- );
68
+ export const Example3R4 = Template.bind({});
69
+ Example3R4.args = {
70
+ fhirVersion: fhirVersions.R4,
71
+ fhirResource: example3AllergyIntoleranceR4,
94
72
  };
95
73
 
96
- export const ExampleWithoutFhirVersionProperty = () => {
97
- const fhirResource = object('Resource', example2AllergyIntoleranceSTU3);
98
- return (
99
- <AllergyIntolerance fhirResource={fhirResource} fhirIcons={fhirIcons} />
100
- );
74
+ export const ExampleWithoutFhirVersionProperty = Template.bind({});
75
+ ExampleWithoutFhirVersionProperty.args = {
76
+ fhirResource: example2AllergyIntoleranceSTU3,
101
77
  };
@@ -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
  import AllergyIntolerance from './AllergyIntolerance';
4
4
 
5
5
  import exampleAllergyIntoleranceDSTU2 from '../../../fixtures/dstu2/resources/allergyIntolerance/example1.json';
@@ -201,4 +201,39 @@ describe('should render component correctly', () => {
201
201
 
202
202
  expect(queryByTestId('asserter')).toBeNull();
203
203
  });
204
+
205
+ it('should fire custom onClick function', () => {
206
+ const defaultProps = {
207
+ fhirResource: example2AllergyIntoleranceR4,
208
+ fhirVersion: fhirVersions.R4,
209
+ };
210
+
211
+ const onClick = jest.fn();
212
+ const { getByRole } = render(
213
+ <AllergyIntolerance {...defaultProps} onClick={onClick} />,
214
+ );
215
+ const accordion = getByRole('button');
216
+ fireEvent.click(accordion);
217
+
218
+ const attribute = accordion.getAttribute('data-bs-toggle');
219
+ expect(attribute).not.toEqual('collapse');
220
+ expect(onClick).toHaveBeenCalled();
221
+ });
222
+
223
+ it('should not fire custom onClick function', () => {
224
+ const defaultProps = {
225
+ fhirResource: example2AllergyIntoleranceR4,
226
+ fhirVersion: fhirVersions.R4,
227
+ };
228
+
229
+ const onClick = 'test';
230
+ const { getByRole } = render(
231
+ <AllergyIntolerance {...defaultProps} onClick={onClick} />,
232
+ );
233
+ const accordion = getByRole('button');
234
+ fireEvent.click(accordion);
235
+
236
+ const attribute = accordion.getAttribute('data-bs-toggle');
237
+ expect(attribute).toEqual('collapse');
238
+ });
204
239
  });