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.
- package/.circleci/config.yml +1 -1
- package/.eslintrc +10 -1
- package/.stylelintrc +6 -2
- package/README.md +19 -1
- package/build/index.js +15 -11
- package/build/style.css +9 -8
- package/package.json +55 -54
- package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
- package/src/assets/containers/Coverage/coverage.svg +4 -0
- package/src/assets/containers/{ResourceCategory/resource-placeholder.svg → Generic/generic.svg} +0 -0
- package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
- package/src/assets/containers/MedicationOrder/medication-order.svg +5 -0
- package/src/assets/containers/MedicationRequest/medication-request.svg +5 -0
- package/src/assets/containers/Organization/organization.svg +5 -0
- package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
- package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
- package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
- package/src/assets/containers/ResourceCategory/resource-category.svg +3 -0
- package/src/components/containers/Accordion/Accordion.js +21 -13
- package/src/components/datatypes/Attachment/Attachment.css +5 -0
- package/src/components/datatypes/Attachment/Attachment.js +7 -2
- package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
- package/src/components/datatypes/Coding/Coding.js +7 -3
- package/src/components/datatypes/Identifier/Identifier.js +7 -3
- package/src/components/datatypes/Reference/Reference.js +7 -1
- package/src/components/datatypes/Telecom/Telecom.js +2 -3
- package/src/components/resources/AdverseEvent/AdverseEvent.js +81 -42
- package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
- package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -5
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +5 -4
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +107 -1
- package/src/components/resources/Appointment/Appointment.js +2 -1
- package/src/components/resources/Appointment/Appointment.test.js +36 -1
- package/src/components/resources/Binary/Binary.js +1 -2
- package/src/components/resources/Binary/Binary.stories.js +10 -4
- package/src/components/resources/Binary/Binary.test.js +67 -0
- package/src/components/resources/Bundle/Bundle.css +7 -0
- package/src/components/resources/Bundle/Bundle.js +15 -11
- package/src/components/resources/Bundle/Bundle.stories.js +12 -78
- package/src/components/resources/Bundle/Bundle.test.js +0 -3
- package/src/components/resources/CarePlan/CarePlan.js +2 -1
- package/src/components/resources/CarePlan/CarePlan.stories.js +31 -5
- package/src/components/resources/CarePlan/CarePlan.test.js +114 -6
- package/src/components/resources/CareTeam/CareTeam.js +72 -50
- package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
- package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
- package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
- package/src/components/resources/Claim/CareTeam.js +55 -0
- package/src/components/resources/Claim/Claim.css +2 -11
- package/src/components/resources/Claim/Claim.js +158 -309
- package/src/components/resources/Claim/Claim.stories.js +37 -5
- package/src/components/resources/Claim/Claim.test.js +104 -1
- package/src/components/resources/Claim/Diagnosis.js +61 -0
- package/src/components/resources/Claim/Insurance.js +58 -0
- package/src/components/resources/Claim/Item.js +79 -0
- package/src/components/resources/Claim/Items.js +29 -0
- package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
- package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
- package/src/components/resources/ClaimResponse/ClaimResponse.js +137 -83
- package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
- package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
- package/src/components/resources/ClaimResponse/Item.js +44 -9
- package/src/components/resources/ClaimResponse/Items.js +5 -4
- package/src/components/resources/Condition/Condition.js +3 -3
- package/src/components/resources/Condition/Condition.test.js +37 -4
- package/src/components/resources/Coverage/Coverage.js +97 -69
- package/src/components/resources/Coverage/Coverage.stories.js +31 -5
- package/src/components/resources/Coverage/Coverage.test.js +111 -4
- package/src/components/resources/Device/Device.js +2 -1
- package/src/components/resources/Device/Device.stories.js +33 -5
- package/src/components/resources/Device/Device.test.js +108 -1
- package/src/components/resources/DiagnosticReport/DiagnosticReport.js +7 -2
- package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +5 -4
- package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +107 -1
- package/src/components/resources/DocumentReference/DocumentReference.js +7 -2
- package/src/components/resources/DocumentReference/DocumentReference.stories.js +3 -2
- package/src/components/resources/DocumentReference/DocumentReference.test.js +113 -1
- package/src/components/resources/Encounter/Encounter.js +2 -1
- package/src/components/resources/Encounter/Encounter.test.js +36 -1
- package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +2 -0
- package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +7 -2
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +3 -2
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +108 -1
- package/src/components/resources/Generic/Generic.js +20 -7
- package/src/components/resources/Generic/Generic.stories.js +2 -1
- package/src/components/resources/Generic/Generic.test.js +26 -7
- package/src/components/resources/Goal/Goal.js +3 -5
- package/src/components/resources/Goal/Goal.stories.js +5 -4
- package/src/components/resources/Goal/Goal.test.js +101 -1
- package/src/components/resources/Immunization/Immunization.js +2 -2
- package/src/components/resources/Immunization/Immunization.test.js +36 -1
- package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
- package/src/components/resources/List/Entries.js +3 -3
- package/src/components/resources/List/List.js +135 -88
- package/src/components/resources/List/List.stories.js +38 -5
- package/src/components/resources/List/List.test.js +105 -1
- package/src/components/resources/Location/Location.js +65 -47
- package/src/components/resources/Location/Location.stories.js +11 -4
- package/src/components/resources/Location/Location.test.js +106 -4
- package/src/components/resources/Medication/Medication.js +91 -51
- package/src/components/resources/Medication/Medication.stories.js +37 -7
- package/src/components/resources/Medication/Medication.test.js +113 -4
- package/src/components/resources/MedicationAdministration/MedicationAdministration.js +86 -62
- package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
- package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
- package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
- package/src/components/resources/MedicationDispense/MedicationDispense.js +68 -68
- package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
- package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +115 -66
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
- package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -4
- package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +1 -2
- package/src/components/resources/MedicationOrder/MedicationOrder.test.js +102 -4
- package/src/components/resources/MedicationRequest/MedicationRequest.js +3 -4
- package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +11 -6
- package/src/components/resources/MedicationRequest/MedicationRequest.test.js +100 -4
- package/src/components/resources/MedicationStatement/MedicationDosage.js +2 -2
- package/src/components/resources/MedicationStatement/MedicationStatement.js +8 -2
- package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +5 -4
- package/src/components/resources/MedicationStatement/MedicationStatement.test.js +108 -1
- package/src/components/resources/Observation/Observation.js +2 -1
- package/src/components/resources/Observation/Observation.test.js +30 -1
- package/src/components/resources/Organization/Organization.js +56 -37
- package/src/components/resources/Organization/Organization.stories.js +15 -2
- package/src/components/resources/Organization/Organization.test.js +109 -1
- package/src/components/resources/Patient/Patient.js +2 -0
- package/src/components/resources/Patient/Patient.test.js +31 -2
- package/src/components/resources/Practitioner/Practitioner.js +2 -1
- package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
- package/src/components/resources/PractitionerRole/PractitionerRole.js +50 -29
- package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
- package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
- package/src/components/resources/Procedure/Procedure.js +2 -2
- package/src/components/resources/Procedure/Procedure.test.js +30 -1
- package/src/components/resources/Questionnaire/Group.js +53 -0
- package/src/components/resources/Questionnaire/Items.js +45 -0
- package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
- package/src/components/resources/Questionnaire/Questionnaire.js +31 -170
- package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
- package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
- package/src/components/resources/Questionnaire/Questions.js +40 -0
- package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
- package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
- package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
- package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
- package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
- package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +52 -236
- package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
- package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
- package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
- package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
- package/src/components/resources/ReferralRequest/ReferralRequest.js +65 -40
- package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
- package/src/components/resources/RelatedPerson/RelatedPerson.js +151 -0
- package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
- package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
- package/src/components/resources/RelatedPerson/index.js +3 -0
- package/src/components/resources/ResearchStudy/ResearchStudy.js +160 -130
- package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
- package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
- package/src/components/resources/ResourceCategory/ResourceCategory.js +7 -12
- package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +13 -2
- package/src/components/resources/ResourceCategory/ResourceCategory.test.js +77 -18
- package/src/components/ui/index.js +32 -12
- package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
- package/src/fixtures/example-icons.jsx +81 -11
- package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
- package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
- package/src/style.scss +3 -1
|
@@ -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 MedicationStatement from './MedicationStatement';
|
|
4
4
|
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,
|
|
@@ -96,4 +168,39 @@ describe('should render MedicationStatement component correctly', () => {
|
|
|
96
168
|
'#med0309',
|
|
97
169
|
);
|
|
98
170
|
});
|
|
171
|
+
|
|
172
|
+
it('should fire custom onClick function', () => {
|
|
173
|
+
const defaultProps = {
|
|
174
|
+
fhirResource: r4Example1,
|
|
175
|
+
fhirVersion: fhirVersions.R4,
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const onClick = jest.fn();
|
|
179
|
+
const { getByRole } = render(
|
|
180
|
+
<MedicationStatement {...defaultProps} onClick={onClick} />,
|
|
181
|
+
);
|
|
182
|
+
const accordion = getByRole('button');
|
|
183
|
+
fireEvent.click(accordion);
|
|
184
|
+
|
|
185
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
186
|
+
expect(attribute).not.toEqual('collapse');
|
|
187
|
+
expect(onClick).toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should not fire custom onClick function', () => {
|
|
191
|
+
const defaultProps = {
|
|
192
|
+
fhirResource: r4Example1,
|
|
193
|
+
fhirVersion: fhirVersions.R4,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const onClick = 'test';
|
|
197
|
+
const { getByRole } = render(
|
|
198
|
+
<MedicationStatement {...defaultProps} onClick={onClick} />,
|
|
199
|
+
);
|
|
200
|
+
const accordion = getByRole('button');
|
|
201
|
+
fireEvent.click(accordion);
|
|
202
|
+
|
|
203
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
204
|
+
expect(attribute).toEqual('collapse');
|
|
205
|
+
});
|
|
99
206
|
});
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '../../ui';
|
|
19
19
|
import Reference from '../../datatypes/Reference';
|
|
20
20
|
|
|
21
|
-
const Observation = ({ fhirResource, fhirIcons }) => {
|
|
21
|
+
const Observation = ({ fhirResource, fhirIcons, onClick }) => {
|
|
22
22
|
const effectiveDate = _get(fhirResource, 'effectiveDateTime');
|
|
23
23
|
const codeCodingDisplay = _get(fhirResource, 'code.coding.0.display');
|
|
24
24
|
const codeText = _get(fhirResource, 'code.text', '');
|
|
@@ -114,6 +114,7 @@ const Observation = ({ fhirResource, fhirIcons }) => {
|
|
|
114
114
|
/>
|
|
115
115
|
</Body>
|
|
116
116
|
}
|
|
117
|
+
onClick={onClick}
|
|
117
118
|
/>
|
|
118
119
|
</Root>
|
|
119
120
|
);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
|
|
3
3
|
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { render } from '@testing-library/react';
|
|
5
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
6
6
|
import Observation from './Observation';
|
|
7
7
|
|
|
8
8
|
import exampleObservationIssued from '../../../fixtures/dstu2/resources/observation/example-issued.json';
|
|
@@ -148,4 +148,33 @@ describe('should render component correctly', () => {
|
|
|
148
148
|
expect(getByTestId('valueQuantityUnit')).not.toBeNull();
|
|
149
149
|
expect(getByTestId('valueQuantityUnit').textContent).toEqual('mmol/l');
|
|
150
150
|
});
|
|
151
|
+
|
|
152
|
+
it('should fire custom onClick function', () => {
|
|
153
|
+
const defaultProps = { fhirResource: example1ObservationExcessR4 };
|
|
154
|
+
|
|
155
|
+
const onClick = jest.fn();
|
|
156
|
+
const { getByRole } = render(
|
|
157
|
+
<Observation {...defaultProps} onClick={onClick} />,
|
|
158
|
+
);
|
|
159
|
+
const accordion = getByRole('button');
|
|
160
|
+
fireEvent.click(accordion);
|
|
161
|
+
|
|
162
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
163
|
+
expect(attribute).not.toEqual('collapse');
|
|
164
|
+
expect(onClick).toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should not fire custom onClick function', () => {
|
|
168
|
+
const defaultProps = { fhirResource: example1ObservationExcessR4 };
|
|
169
|
+
|
|
170
|
+
const onClick = 'test';
|
|
171
|
+
const { getByRole } = render(
|
|
172
|
+
<Observation {...defaultProps} onClick={onClick} />,
|
|
173
|
+
);
|
|
174
|
+
const accordion = getByRole('button');
|
|
175
|
+
fireEvent.click(accordion);
|
|
176
|
+
|
|
177
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
178
|
+
expect(attribute).toEqual('collapse');
|
|
179
|
+
});
|
|
151
180
|
});
|
|
@@ -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,
|
|
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 =
|
|
58
|
-
const { fhirResource, fhirVersion } = props;
|
|
58
|
+
const Organization = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
|
|
59
59
|
let fhirResourceData = {};
|
|
60
60
|
try {
|
|
61
61
|
fhirResourceData = resourceDTO(fhirVersion, fhirResource);
|
|
@@ -74,42 +74,61 @@ 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} />,
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
onClick={onClick}
|
|
131
|
+
/>
|
|
113
132
|
</Root>
|
|
114
133
|
);
|
|
115
134
|
};
|
|
@@ -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
|
|
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
|
|
60
|
+
<Organization
|
|
61
|
+
fhirResource={fhirResource}
|
|
62
|
+
fhirVersion={fhirVersions.STU3}
|
|
63
|
+
fhirIcons={'random text'}
|
|
64
|
+
/>
|
|
52
65
|
);
|
|
53
66
|
};
|
|
54
67
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
3
3
|
|
|
4
4
|
import Organization from './Organization';
|
|
5
5
|
import fhirVersions from '../fhirResourceVersions';
|
|
@@ -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,
|
|
@@ -128,4 +201,39 @@ describe('should render Organization component properly', () => {
|
|
|
128
201
|
'No additional data',
|
|
129
202
|
);
|
|
130
203
|
});
|
|
204
|
+
|
|
205
|
+
it('should fire custom onClick function', () => {
|
|
206
|
+
const defaultProps = {
|
|
207
|
+
fhirResource: r4Example3,
|
|
208
|
+
fhirVersion: fhirVersions.R4,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const onClick = jest.fn();
|
|
212
|
+
const { getByRole } = render(
|
|
213
|
+
<Organization {...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: r4Example3,
|
|
226
|
+
fhirVersion: fhirVersions.R4,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const onClick = 'test';
|
|
230
|
+
const { getByRole } = render(
|
|
231
|
+
<Organization {...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
|
+
});
|
|
131
239
|
});
|
|
@@ -46,6 +46,7 @@ function Patient(props) {
|
|
|
46
46
|
renderName,
|
|
47
47
|
patientSimple,
|
|
48
48
|
fhirIcons,
|
|
49
|
+
onClick,
|
|
49
50
|
} = props;
|
|
50
51
|
|
|
51
52
|
const id = getId(fhirResource);
|
|
@@ -146,6 +147,7 @@ function Patient(props) {
|
|
|
146
147
|
/>
|
|
147
148
|
}
|
|
148
149
|
bodyContent={<Body tableData={tableData} />}
|
|
150
|
+
onClick={onClick}
|
|
149
151
|
/>
|
|
150
152
|
</Root>
|
|
151
153
|
);
|
|
@@ -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 Patient from './Patient';
|
|
4
4
|
|
|
5
5
|
import examplePatient from '../../../fixtures/dstu2/resources/patient/example.json';
|
|
@@ -38,7 +38,7 @@ describe('should render component correctly', () => {
|
|
|
38
38
|
fhirResource: examplePatient,
|
|
39
39
|
fhirIcons: (
|
|
40
40
|
<img
|
|
41
|
-
src={require('../assets/containers/
|
|
41
|
+
src={require('../assets/containers/Patient/patient.svg')}
|
|
42
42
|
alt="patient"
|
|
43
43
|
/>
|
|
44
44
|
),
|
|
@@ -156,4 +156,33 @@ describe('should render component correctly', () => {
|
|
|
156
156
|
const { getByTestId } = render(<Patient {...defaultProps} />);
|
|
157
157
|
expect(getByTestId('deceasedInfo').textContent).toEqual('2/14/2015');
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
it('should fire custom onClick function', () => {
|
|
161
|
+
const defaultProps = { fhirResource: example3PatientR4 };
|
|
162
|
+
|
|
163
|
+
const onClick = jest.fn();
|
|
164
|
+
const { getByRole } = render(
|
|
165
|
+
<Patient {...defaultProps} onClick={onClick} />,
|
|
166
|
+
);
|
|
167
|
+
const accordion = getByRole('button');
|
|
168
|
+
fireEvent.click(accordion);
|
|
169
|
+
|
|
170
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
171
|
+
expect(attribute).not.toEqual('collapse');
|
|
172
|
+
expect(onClick).toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('should not fire custom onClick function', () => {
|
|
176
|
+
const defaultProps = { fhirResource: example3PatientR4 };
|
|
177
|
+
|
|
178
|
+
const onClick = 'test';
|
|
179
|
+
const { getByRole } = render(
|
|
180
|
+
<Patient {...defaultProps} onClick={onClick} />,
|
|
181
|
+
);
|
|
182
|
+
const accordion = getByRole('button');
|
|
183
|
+
fireEvent.click(accordion);
|
|
184
|
+
|
|
185
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
186
|
+
expect(attribute).toEqual('collapse');
|
|
187
|
+
});
|
|
159
188
|
});
|
|
@@ -82,7 +82,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
|
|
85
|
+
const Practitioner = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
|
|
86
86
|
let fhirResourceData = {};
|
|
87
87
|
try {
|
|
88
88
|
fhirResourceData = resourceDTO(fhirVersion, fhirResource);
|
|
@@ -160,6 +160,7 @@ const Practitioner = ({ fhirResource, fhirVersion, fhirIcons }) => {
|
|
|
160
160
|
/>
|
|
161
161
|
}
|
|
162
162
|
bodyContent={<Body tableData={tableData} />}
|
|
163
|
+
onClick={onClick}
|
|
163
164
|
/>
|
|
164
165
|
</Root>
|
|
165
166
|
);
|
|
@@ -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 Practitioner from './Practitioner';
|
|
4
4
|
import fhirVersions from '../fhirResourceVersions';
|
|
5
5
|
|
|
@@ -170,4 +170,39 @@ describe('Practitioner should render component correctly', () => {
|
|
|
170
170
|
);
|
|
171
171
|
jest.restoreAllMocks();
|
|
172
172
|
});
|
|
173
|
+
|
|
174
|
+
it('should fire custom onClick function', () => {
|
|
175
|
+
const defaultProps = {
|
|
176
|
+
fhirVersion: fhirVersions.R4,
|
|
177
|
+
fhirResource: stu3Example1,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const onClick = jest.fn();
|
|
181
|
+
const { getByRole } = render(
|
|
182
|
+
<Practitioner {...defaultProps} onClick={onClick} />,
|
|
183
|
+
);
|
|
184
|
+
const accordion = getByRole('button');
|
|
185
|
+
fireEvent.click(accordion);
|
|
186
|
+
|
|
187
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
188
|
+
expect(attribute).not.toEqual('collapse');
|
|
189
|
+
expect(onClick).toHaveBeenCalled();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should not fire custom onClick function', () => {
|
|
193
|
+
const defaultProps = {
|
|
194
|
+
fhirVersion: fhirVersions.R4,
|
|
195
|
+
fhirResource: stu3Example1,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const onClick = 'test';
|
|
199
|
+
const { getByRole } = render(
|
|
200
|
+
<Practitioner {...defaultProps} onClick={onClick} />,
|
|
201
|
+
);
|
|
202
|
+
const accordion = getByRole('button');
|
|
203
|
+
fireEvent.click(accordion);
|
|
204
|
+
|
|
205
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
206
|
+
expect(attribute).toEqual('collapse');
|
|
207
|
+
});
|
|
173
208
|
});
|