fhir-react 0.3.4 → 0.3.7

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 (84) hide show
  1. package/README.md +1 -1
  2. package/build/bootstrap-reboot.min.css +8 -2
  3. package/build/index.js +7 -7
  4. package/build/style.css +6 -6
  5. package/package.json +1 -1
  6. package/src/assets/containers/Binary/binary.svg +9 -0
  7. package/src/assets/containers/Coverage/coverage.svg +4 -0
  8. package/src/assets/containers/MedicationOrder/medication-order.svg +5 -0
  9. package/src/assets/containers/MedicationRequest/medication-request.svg +5 -0
  10. package/src/assets/containers/Organization/organization.svg +5 -0
  11. package/src/assets/containers/ResourceCategory/{resource-placeholder.svg → resource-category.svg} +0 -0
  12. package/src/components/containers/Accordion/Accordion.js +10 -9
  13. package/src/components/datatypes/Annotation/Annotation.js +4 -4
  14. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  15. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  16. package/src/components/datatypes/CodeableConcept/CodeableConcept.css +4 -1
  17. package/src/components/datatypes/Coding/Coding.css +0 -1
  18. package/src/components/datatypes/Identifier/Identifier.js +7 -3
  19. package/src/components/datatypes/Reference/Reference.css +3 -0
  20. package/src/components/datatypes/Reference/Reference.js +7 -1
  21. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +86 -77
  22. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +12 -1
  23. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +71 -0
  24. package/src/components/resources/Binary/Binary.js +30 -20
  25. package/src/components/resources/Binary/Binary.stories.js +12 -5
  26. package/src/components/resources/Binary/Binary.test.js +67 -0
  27. package/src/components/resources/CarePlan/CarePlan.js +111 -96
  28. package/src/components/resources/CarePlan/CarePlan.stories.js +31 -5
  29. package/src/components/resources/CarePlan/CarePlan.test.js +74 -2
  30. package/src/components/resources/CarePlan/CarePlanActivity.js +6 -2
  31. package/src/components/resources/Claim/CareTeam.js +55 -0
  32. package/src/components/resources/Claim/Claim.css +2 -11
  33. package/src/components/resources/Claim/Claim.js +157 -309
  34. package/src/components/resources/Claim/Claim.stories.js +37 -5
  35. package/src/components/resources/Claim/Claim.test.js +72 -0
  36. package/src/components/resources/Claim/Diagnosis.js +61 -0
  37. package/src/components/resources/Claim/Insurance.js +58 -0
  38. package/src/components/resources/Claim/Item.js +79 -0
  39. package/src/components/resources/Claim/Items.js +29 -0
  40. package/src/components/resources/Coverage/Coverage.js +96 -69
  41. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  42. package/src/components/resources/Coverage/Coverage.test.js +75 -3
  43. package/src/components/resources/Device/Device.js +54 -34
  44. package/src/components/resources/Device/Device.stories.js +33 -5
  45. package/src/components/resources/Device/Device.test.js +72 -0
  46. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +53 -43
  47. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +8 -1
  48. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +71 -0
  49. package/src/components/resources/DocumentReference/DocumentReference.js +101 -65
  50. package/src/components/resources/DocumentReference/DocumentReference.stories.js +5 -0
  51. package/src/components/resources/DocumentReference/DocumentReference.test.js +71 -0
  52. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +47 -38
  53. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +5 -0
  54. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +72 -0
  55. package/src/components/resources/Goal/Goal.js +103 -85
  56. package/src/components/resources/Goal/Goal.stories.js +38 -7
  57. package/src/components/resources/Goal/Goal.test.js +70 -3
  58. package/src/components/resources/Medication/Medication.js +90 -51
  59. package/src/components/resources/Medication/Medication.stories.js +37 -7
  60. package/src/components/resources/Medication/Medication.test.js +77 -3
  61. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +1 -1
  62. package/src/components/resources/MedicationOrder/MedicationOrder.js +45 -28
  63. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +67 -0
  64. package/src/components/resources/MedicationRequest/MedicationRequest.js +64 -44
  65. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +21 -5
  66. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +67 -0
  67. package/src/components/resources/MedicationStatement/MedicationDetails.js +52 -0
  68. package/src/components/resources/MedicationStatement/MedicationDosage.js +46 -0
  69. package/src/components/resources/MedicationStatement/MedicationStatement.js +66 -118
  70. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +7 -0
  71. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +103 -6
  72. package/src/components/resources/Organization/Organization.js +55 -37
  73. package/src/components/resources/Organization/Organization.stories.js +15 -2
  74. package/src/components/resources/Organization/Organization.test.js +73 -0
  75. package/src/components/resources/ResourceCategory/ResourceCategory.js +7 -12
  76. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +13 -2
  77. package/src/components/resources/ResourceCategory/ResourceCategory.test.js +77 -18
  78. package/src/components/ui/bootstrap-reboot.min.css +8 -2
  79. package/src/components/ui/index.js +22 -4
  80. package/src/fixtures/example-icons.jsx +46 -11
  81. package/src/style.scss +1 -0
  82. package/src/utils/formatDate.js +6 -4
  83. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.css +0 -4
  84. package/src/components/resources/CarePlan/CarePlan.css +0 -7
@@ -3,42 +3,13 @@ import PropTypes from 'prop-types';
3
3
 
4
4
  import _get from 'lodash/get';
5
5
  import _has from 'lodash/has';
6
- import Date from '../../datatypes/Date';
7
6
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
8
7
  import fhirVersions from '../fhirResourceVersions';
9
- import Annotation from '../../datatypes/Annotation';
10
- import Reference from '../../datatypes/Reference';
11
- import {
12
- Root,
13
- Header,
14
- Title,
15
- Badge,
16
- BadgeSecondary,
17
- Body,
18
- Value,
19
- ValueSection,
20
- } from '../../ui';
21
-
22
- const MedicationDetails = props => {
23
- const { medication, expiration, ingredient } = props;
24
- return (
25
- <div>
26
- <h5>{medication} </h5>
27
- <Value label="Expiration date">{expiration}</Value>
28
- {ingredient && (
29
- <Value label="Ingredient">
30
- <ul>
31
- {ingredient.map((item, i) => (
32
- <li key={`item-${i}`}>
33
- {_get(item, 'itemCodeableConcept.coding.0.display', '')}
34
- </li>
35
- ))}
36
- </ul>
37
- </Value>
38
- )}
39
- </div>
40
- );
41
- };
8
+ import Accordion from '../../containers/Accordion';
9
+ import DatePeriod from '../../datatypes/DatePeriod/DatePeriod';
10
+ import MedicationDetails from './MedicationDetails';
11
+ import { Root, Header, Badge, Body } from '../../ui';
12
+ import MedicationDosage from './MedicationDosage';
42
13
 
43
14
  const DEFAULT_TITLE = 'Medication Statement';
44
15
 
@@ -137,7 +108,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
137
108
  };
138
109
 
139
110
  const MedicationStatement = props => {
140
- const { fhirResource, fhirVersion } = props;
111
+ const { fhirResource, fhirVersion, fhirIcons } = props;
141
112
  let fhirResourceData = {};
142
113
  try {
143
114
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -165,94 +136,71 @@ const MedicationStatement = props => {
165
136
 
166
137
  return (
167
138
  <Root name="MedicationStatement">
168
- <Header>
169
- <Title>{title}</Title>
170
- {status && <Badge data-testid="hasStatus">{status}</Badge>}
171
- {hasEffectivePeriod && (
172
- <BadgeSecondary data-testid="hasEffectivePeriod">
173
- from <Date fhirData={statusDesc.from} /> {'to '}
174
- <Date fhirData={statusDesc.to} />
175
- <span>{reported}</span>
176
- </BadgeSecondary>
177
- )}
178
- </Header>
179
- <Body>
180
- {hasMedications && (
181
- <Value label="Medications">
182
- {contained.map((medication, i) => {
183
- const hasMedicationDetails = _has(
184
- medication,
185
- 'code.coding[0].display',
186
- );
187
- if (hasMedicationDetails) {
188
- return (
189
- <MedicationDetails
190
- key={`item-${i}`}
191
- medication={_get(medication, 'code.coding[0].display')}
192
- expiration={_get(
193
- medication,
194
- 'package.batch[0].expirationDate',
195
- )}
196
- ingredient={_get(medication, 'ingredient', [])}
139
+ <Accordion
140
+ headerContent={
141
+ <Header
142
+ icon={fhirIcons}
143
+ resourceName="MedicationStatement"
144
+ badges={status && <Badge data-testid="hasStatus">{status}</Badge>}
145
+ title={title}
146
+ additionalContent={
147
+ hasEffectivePeriod && (
148
+ <>
149
+ <DatePeriod
150
+ periodBeginLabel="Start date"
151
+ periodBeginDate={statusDesc.from}
152
+ periodBeginTestId="startDate"
153
+ periodEndLabel="End date"
154
+ periodEndDate={statusDesc.to}
155
+ periodEndTestId="endDate"
197
156
  />
157
+ <span>{reported}</span>
158
+ </>
159
+ )
160
+ }
161
+ />
162
+ }
163
+ bodyContent={
164
+ <Body>
165
+ {hasMedications &&
166
+ contained.map((medication, i) => {
167
+ const hasMedicationDetails = _has(
168
+ medication,
169
+ 'code.coding[0].display',
198
170
  );
199
- }
200
- return null;
201
- })}
202
- </Value>
203
- )}
204
- {medicationReference && (
205
- <Value label="Medication Reference" data-testid="medicationReference">
206
- <Reference fhirData={medicationReference} />
207
- </Value>
208
- )}
209
- {hasReasonCode && (
210
- <Value label="Reason" data-testid="hasReasonCode">
211
- <ul>
212
- {reasonCode.map((item, i) => {
213
- const display = _get(item, 'coding.0.display');
214
- if (display) {
215
- return <li key={`item-${i}`}>{display}</li>;
171
+ if (hasMedicationDetails) {
172
+ return (
173
+ <MedicationDetails
174
+ key={`item-${i}`}
175
+ itemNumber={`item-${i}`}
176
+ medication={_get(medication, 'code.coding[0].display')}
177
+ expiration={_get(
178
+ medication,
179
+ 'package.batch[0].expirationDate',
180
+ )}
181
+ ingredient={_get(medication, 'ingredient', [])}
182
+ medicationReference={medicationReference}
183
+ hasReasonCode={hasReasonCode}
184
+ reasonCode={reasonCode}
185
+ />
186
+ );
216
187
  }
217
188
  return null;
218
189
  })}
219
- </ul>
220
- </Value>
221
- )}
222
- {hasDosage && (
223
- <ValueSection label="Dosage" data-testid="dosage">
224
- {fhirResource.dosage.map((dosage, i) => {
225
- const text = _get(dosage, 'text');
226
- const additionalInstructionText = _get(
227
- dosage,
228
- 'additionalInstruction[0].text',
229
- );
230
- const route =
231
- _get(dosage, 'route.coding[0].display') ||
232
- `${_get(dosage, 'route.text', '')} ${_get(dosage, 'text', '')}`;
233
- const hasRoute = route.trim() !== '';
234
- return (
235
- <div key={`dosage-${i}`}>
236
- <Value label="Instructions" data-testid="dosageInstruction">
237
- {text}
238
- </Value>
239
- {additionalInstructionText && (
240
- <Value label="Additional Instruction">
241
- {additionalInstructionText}
242
- </Value>
243
- )}
244
- {hasRoute && <Value label="Route">{route}</Value>}
245
- </div>
246
- );
247
- })}
248
- </ValueSection>
249
- )}
250
- {hasNote && (
251
- <Value label="Notes" data-testid="hasNote">
252
- <Annotation fhirData={note} />
253
- </Value>
254
- )}
255
- </Body>
190
+ {hasDosage &&
191
+ fhirResource.dosage.map((dosage, i) => {
192
+ return (
193
+ <MedicationDosage
194
+ key={`dosage-${i}`}
195
+ dosage={dosage}
196
+ hasNote={hasNote}
197
+ note={note}
198
+ />
199
+ );
200
+ })}
201
+ </Body>
202
+ }
203
+ />
256
204
  </Root>
257
205
  );
258
206
  };
@@ -9,6 +9,8 @@ import stu3Example1 from '../../../fixtures/stu3/resources/medicationStatement/e
9
9
  import stu3Example2 from '../../../fixtures/stu3/resources/medicationStatement/example2.json';
10
10
  import r4Example1 from '../../../fixtures/r4/resources/medicationStatement/example1.json';
11
11
  import r4Example2 from '../../../fixtures/r4/resources/medicationStatement/example2.json';
12
+ import fhirIcons from '../../../fixtures/example-icons';
13
+ import MedicationStatementIcon from '../../../assets/containers/MedicationStatement/medication-statement.svg';
12
14
 
13
15
  export default {
14
16
  title: 'MedicationStatement',
@@ -20,6 +22,7 @@ export const DefaultVisualizationDSTU2 = () => {
20
22
  <MedicationStatement
21
23
  fhirVersion={fhirVersions.DSTU2}
22
24
  fhirResource={fhirResource}
25
+ fhirIcons={require('../../../assets/containers/MedicationStatement/medication-statement.svg')}
23
26
  />
24
27
  );
25
28
  };
@@ -30,6 +33,7 @@ export const ExampleOfSTU3 = () => {
30
33
  <MedicationStatement
31
34
  fhirVersion={fhirVersions.STU3}
32
35
  fhirResource={fhirResource}
36
+ fhirIcons={MedicationStatementIcon}
33
37
  />
34
38
  );
35
39
  };
@@ -40,6 +44,7 @@ export const Example2OfSTU3 = () => {
40
44
  <MedicationStatement
41
45
  fhirVersion={fhirVersions.STU3}
42
46
  fhirResource={fhirResource}
47
+ fhirIcons={fhirIcons}
43
48
  />
44
49
  );
45
50
  };
@@ -50,6 +55,7 @@ export const Example1OfR4 = () => {
50
55
  <MedicationStatement
51
56
  fhirVersion={fhirVersions.R4}
52
57
  fhirResource={fhirResource}
58
+ fhirIcons={false}
53
59
  />
54
60
  );
55
61
  };
@@ -60,6 +66,7 @@ export const Example2OfR4 = () => {
60
66
  <MedicationStatement
61
67
  fhirVersion={fhirVersions.R4}
62
68
  fhirResource={fhirResource}
69
+ fhirIcons={'random text'}
63
70
  />
64
71
  );
65
72
  };
@@ -5,8 +5,80 @@ import fhirVersions from '../fhirResourceVersions';
5
5
  import example1MedicationStatement from '../../../fixtures/dstu2/resources/medicationStatement/example1.json';
6
6
  import stu3Example from '../../../fixtures/stu3/resources/medicationStatement/example1.json';
7
7
  import r4Example1 from '../../../fixtures/r4/resources/medicationStatement/example1.json';
8
+ import fhirIcons from '../../../fixtures/example-icons';
8
9
 
9
10
  describe('should render MedicationStatement component correctly', () => {
11
+ it('component without a fhirIcons props should render a default icon', () => {
12
+ const defaultProps = {
13
+ fhirResource: example1MedicationStatement,
14
+ fhirVersion: fhirVersions.DSTU2,
15
+ };
16
+
17
+ const { getByAltText } = render(<MedicationStatement {...defaultProps} />);
18
+ const headerIcon = getByAltText('medication statement');
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
+ fhirResource: example1MedicationStatement,
26
+ fhirVersion: fhirVersions.DSTU2,
27
+ fhirIcons: false,
28
+ };
29
+
30
+ const { getByTestId } = render(<MedicationStatement {...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
+ fhirResource: example1MedicationStatement,
39
+ fhirVersion: fhirVersions.DSTU2,
40
+ fhirIcons: (
41
+ <img
42
+ src={require('../assets/containers/MedicationStatement/medication-statement.svg')}
43
+ alt="medication statement"
44
+ />
45
+ ),
46
+ };
47
+
48
+ const { getByAltText } = render(<MedicationStatement {...defaultProps} />);
49
+ const headerIcon = getByAltText('medication statement');
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
+ fhirResource: example1MedicationStatement,
57
+ fhirVersion: fhirVersions.DSTU2,
58
+ fhirIcons: fhirIcons,
59
+ };
60
+
61
+ const { getByAltText } = render(<MedicationStatement {...defaultProps} />);
62
+ const headerIcon = getByAltText('medication statement');
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
+ fhirResource: example1MedicationStatement,
72
+ fhirVersion: fhirVersions.DSTU2,
73
+ fhirIcons: avatarSrc,
74
+ };
75
+
76
+ const { getByAltText } = render(<MedicationStatement {...defaultProps} />);
77
+ const headerIcon = getByAltText('header icon');
78
+
79
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
80
+ });
81
+
10
82
  it('with DSTU2 source data', () => {
11
83
  const defaultProps = {
12
84
  fhirResource: example1MedicationStatement,
@@ -19,7 +91,7 @@ describe('should render MedicationStatement component correctly', () => {
19
91
  expect(getByTestId('title').textContent).toContain(
20
92
  'amphetamine-dextroamphetamine',
21
93
  );
22
- expect(getByTestId('hasEffectivePeriod').textContent).toContain('from');
94
+ expect(getByTestId('startDate').textContent).toContain('4/19/2016');
23
95
  expect(queryByTestId('medicationReference')).toBeNull();
24
96
 
25
97
  expect(getByTestId('dosageInstruction').textContent).toContain(
@@ -32,19 +104,35 @@ describe('should render MedicationStatement component correctly', () => {
32
104
  fhirResource: stu3Example,
33
105
  fhirVersion: fhirVersions.STU3,
34
106
  };
35
- const { getByTestId, queryAllByTestId } = render(
107
+ const { getByTestId, queryAllByTestId, queryByTestId } = render(
36
108
  <MedicationStatement {...defaultProps} />,
37
109
  );
38
110
 
39
111
  expect(getByTestId('title').textContent).toEqual('Medication Statement');
40
- expect(queryAllByTestId('hasEffectivePeriod')).toHaveLength(0);
112
+ expect(queryAllByTestId('startDate')).toHaveLength(0);
113
+ expect(queryAllByTestId('endDate')).toHaveLength(0);
41
114
 
42
115
  expect(getByTestId('dosageInstruction').textContent).toContain(
43
116
  '1-2 tablets once daily',
44
117
  );
45
118
 
46
- expect(getByTestId('hasNote').textContent).toContain('occasional');
119
+ const ingredients = queryAllByTestId('ingredient-item').map(
120
+ x => x.textContent,
121
+ );
122
+ expect(ingredients).toHaveLength(2);
123
+ expect(ingredients).toEqual([
124
+ 'Acetaminophen 500 MG',
125
+ 'Diphenhydramine Hydrochloride 25 mg',
126
+ ]);
127
+
128
+ expect(getByTestId('dosageInstruction').textContent).toContain(
129
+ '1-2 tablets once daily at bedtime as needed for restless legs',
130
+ );
47
131
 
132
+ expect(queryByTestId('medicationReference').textContent).toContain(
133
+ '#med0309',
134
+ );
135
+ expect(getByTestId('hasNote').textContent).toContain('occasional');
48
136
  expect(getByTestId('hasReasonCode').textContent).toContain('Legs');
49
137
  });
50
138
 
@@ -58,14 +146,23 @@ describe('should render MedicationStatement component correctly', () => {
58
146
  );
59
147
 
60
148
  expect(getByTestId('title').textContent).toEqual('Medication Statement');
61
- expect(queryAllByTestId('hasEffectivePeriod')).toHaveLength(0);
149
+ expect(queryAllByTestId('startDate')).toHaveLength(0);
150
+ expect(queryAllByTestId('endDate')).toHaveLength(0);
62
151
 
63
152
  expect(getByTestId('dosageInstruction').textContent).toContain(
64
153
  '1-2 tablets once daily',
65
154
  );
66
155
 
67
- expect(getByTestId('hasNote').textContent).toContain('occasional');
156
+ const ingredients = queryAllByTestId('ingredient-item').map(
157
+ x => x.textContent,
158
+ );
159
+ expect(ingredients).toHaveLength(2);
160
+ expect(ingredients).toEqual([
161
+ 'Acetaminophen 500 MG',
162
+ 'Diphenhydramine Hydrochloride 25 mg',
163
+ ]);
68
164
 
165
+ expect(getByTestId('hasNote').textContent).toContain('occasional');
69
166
  expect(getByTestId('hasReasonCode').textContent).toContain('Legs');
70
167
  expect(getByTestId('medicationReference').textContent).toContain(
71
168
  '#med0309',
@@ -8,7 +8,8 @@ import Telecom from '../../datatypes/Telecom';
8
8
  import Identifier from '../../datatypes/Identifier';
9
9
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
10
10
  import fhirVersions from '../fhirResourceVersions';
11
- import { Root, Header, Title, Body, Value, NotEnoughData } from '../../ui';
11
+ import { Root, Header, Body, NotEnoughData } from '../../ui';
12
+ import Accordion from '../../containers/Accordion';
12
13
 
13
14
  const commonDTO = fhirResource => {
14
15
  const identifier = _get(fhirResource, 'identifier', '');
@@ -54,8 +55,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
54
55
  }
55
56
  };
56
57
 
57
- const Organization = props => {
58
- const { fhirResource, fhirVersion } = props;
58
+ const Organization = ({ fhirResource, fhirVersion, fhirIcons }) => {
59
59
  let fhirResourceData = {};
60
60
  try {
61
61
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -74,42 +74,60 @@ const Organization = props => {
74
74
  const hasTelecom = Array.isArray(telecom) && telecom.length > 0;
75
75
  const hasTypes = Array.isArray(typeCodings) && typeCodings.length > 0;
76
76
  const notEnoughData = !hasAddresses && !hasTelecom && !hasTypes;
77
+
78
+ const tableData = [
79
+ {
80
+ label: 'Identifiers',
81
+ testId: 'identifier',
82
+ data: identifier && <Identifier fhirData={identifier} noCursive />,
83
+ status: identifier,
84
+ },
85
+ {
86
+ label: 'Addresses',
87
+ testId: 'address',
88
+ data:
89
+ hasAddresses &&
90
+ addresses.map((item, i) => (
91
+ <Address key={`item-${i}`} fhirData={item} />
92
+ )),
93
+ status: hasAddresses,
94
+ },
95
+ {
96
+ label: 'Contacts',
97
+ testId: 'contact',
98
+ data:
99
+ hasTelecom &&
100
+ telecom.map((item, i) => <Telecom key={`item-${i}`} fhirData={item} />),
101
+ status: hasTelecom,
102
+ },
103
+ {
104
+ label: 'Type',
105
+ testId: 'type',
106
+ data:
107
+ hasTypes &&
108
+ typeCodings.map((typeCoding, idx) => (
109
+ <Coding key={idx} fhirData={typeCoding} />
110
+ )),
111
+ status: hasTypes,
112
+ },
113
+ {
114
+ label: '',
115
+ testId: '',
116
+ data: notEnoughData && <NotEnoughData data-testid="NotEnoughData" />,
117
+ status: notEnoughData,
118
+ },
119
+ ];
120
+
77
121
  return (
78
122
  <Root name="Organization">
79
- {name && (
80
- <Header>
81
- <Title>{name}</Title>
82
- </Header>
83
- )}
84
- <Body>
85
- {identifier && (
86
- <Value label="Identifiers" data-testid="identifier">
87
- <Identifier fhirData={identifier} />
88
- </Value>
89
- )}
90
- {hasAddresses && (
91
- <Value label="Addresses" data-testid="address">
92
- {addresses.map((item, i) => (
93
- <Address key={`item-${i}`} fhirData={item} />
94
- ))}
95
- </Value>
96
- )}
97
- {hasTelecom && (
98
- <Value label="Contacts" data-testid="contact">
99
- {telecom.map((item, i) => (
100
- <Telecom key={`item-${i}`} fhirData={item} />
101
- ))}
102
- </Value>
103
- )}
104
- {hasTypes && (
105
- <Value label="Type" data-testid="type">
106
- {typeCodings.map((typeCoding, idx) => (
107
- <Coding key={idx} fhirData={typeCoding} />
108
- ))}
109
- </Value>
110
- )}
111
- {notEnoughData && <NotEnoughData data-testid="NotEnoughData" />}
112
- </Body>
123
+ <Accordion
124
+ headerContent={
125
+ name && (
126
+ <Header resourceName="Organization" title={name} icon={fhirIcons} />
127
+ )
128
+ }
129
+ bodyContent={<Body tableData={tableData} />}
130
+ />
113
131
  </Root>
114
132
  );
115
133
  };
@@ -14,6 +14,9 @@ import r4Example1 from '../../../fixtures/r4/resources/organization/example1.jso
14
14
  import r4Example2 from '../../../fixtures/r4/resources/organization/example2.json';
15
15
  import r4Example3 from '../../../fixtures/r4/resources/organization/example3.json';
16
16
 
17
+ import fhirIcons from '../../../fixtures/example-icons';
18
+ import OrganizationIcon from '../../../assets/containers/Organization/organization.svg';
19
+
17
20
  export default {
18
21
  title: 'Organization',
19
22
  };
@@ -24,6 +27,7 @@ export const DefaultVisualizationDSTU2 = () => {
24
27
  <Organization
25
28
  fhirResource={fhirResource}
26
29
  fhirVersion={fhirVersions.DSTU2}
30
+ fhirIcons={OrganizationIcon}
27
31
  />
28
32
  );
29
33
  };
@@ -34,6 +38,7 @@ export const Example2OfDSTU2 = () => {
34
38
  <Organization
35
39
  fhirResource={fhirResource}
36
40
  fhirVersion={fhirVersions.DSTU2}
41
+ fhirIcons={fhirIcons}
37
42
  />
38
43
  );
39
44
  };
@@ -41,14 +46,22 @@ export const Example2OfDSTU2 = () => {
41
46
  export const Example1OfSTU3 = () => {
42
47
  const fhirResource = object('Resource', stu3Example1);
43
48
  return (
44
- <Organization fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
49
+ <Organization
50
+ fhirResource={fhirResource}
51
+ fhirVersion={fhirVersions.STU3}
52
+ fhirIcons={false}
53
+ />
45
54
  );
46
55
  };
47
56
 
48
57
  export const Example2OfSTU3 = () => {
49
58
  const fhirResource = object('Resource', stu3Example2);
50
59
  return (
51
- <Organization fhirResource={fhirResource} fhirVersion={fhirVersions.STU3} />
60
+ <Organization
61
+ fhirResource={fhirResource}
62
+ fhirVersion={fhirVersions.STU3}
63
+ fhirIcons={'random text'}
64
+ />
52
65
  );
53
66
  };
54
67
 
@@ -14,7 +14,80 @@ import r4Example1 from '../../../fixtures/r4/resources/organization/example1.jso
14
14
  import r4Example2 from '../../../fixtures/r4/resources/organization/example2.json';
15
15
  import r4Example3 from '../../../fixtures/r4/resources/organization/example3.json';
16
16
 
17
+ import fhirIcons from '../../../fixtures/example-icons';
18
+
17
19
  describe('should render Organization component properly', () => {
20
+ it('component without a fhirIcons props should render a default icon', () => {
21
+ const defaultProps = {
22
+ fhirVersion: fhirVersions.DSTU2,
23
+ fhirResource: dstu2Example1,
24
+ };
25
+
26
+ const { getByAltText } = render(<Organization {...defaultProps} />);
27
+ const headerIcon = getByAltText('organization');
28
+
29
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
30
+ });
31
+
32
+ it('component with a false as a fhirIcons props should render a placeholder', () => {
33
+ const defaultProps = {
34
+ fhirVersion: fhirVersions.DSTU2,
35
+ fhirResource: dstu2Example1,
36
+ fhirIcons: false,
37
+ };
38
+
39
+ const { getByTestId } = render(<Organization {...defaultProps} />);
40
+ const headerIcon = getByTestId('placeholder');
41
+
42
+ expect(headerIcon).toBeTruthy();
43
+ });
44
+
45
+ it('component with the img as a fhirIcons props should render an img', () => {
46
+ const defaultProps = {
47
+ fhirVersion: fhirVersions.DSTU2,
48
+ fhirResource: dstu2Example1,
49
+ fhirIcons: (
50
+ <img
51
+ src={require('../assets/containers/Organization/organization.svg')}
52
+ alt="organization"
53
+ />
54
+ ),
55
+ };
56
+
57
+ const { getByAltText } = render(<Organization {...defaultProps} />);
58
+ const headerIcon = getByAltText('organization');
59
+
60
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
61
+ });
62
+
63
+ it('component with the resources object as a fhirIcons props should render an img', () => {
64
+ const defaultProps = {
65
+ fhirVersion: fhirVersions.DSTU2,
66
+ fhirResource: dstu2Example1,
67
+ fhirIcons: fhirIcons,
68
+ };
69
+
70
+ const { getByAltText } = render(<Organization {...defaultProps} />);
71
+ const headerIcon = getByAltText('organization');
72
+
73
+ expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
74
+ });
75
+
76
+ it('component with the url as a fhirIcons props should render an img', () => {
77
+ const avatarSrc =
78
+ 'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
79
+ const defaultProps = {
80
+ fhirVersion: fhirVersions.DSTU2,
81
+ fhirResource: dstu2Example1,
82
+ fhirIcons: avatarSrc,
83
+ };
84
+
85
+ const { getByAltText } = render(<Organization {...defaultProps} />);
86
+ const headerIcon = getByAltText('header icon');
87
+
88
+ expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
89
+ });
90
+
18
91
  it('should render with DSTU2 source data', () => {
19
92
  const defaultProps = {
20
93
  fhirResource: dstu2Example1,