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.
- package/.circleci/config.yml +1 -1
- package/.eslintrc +10 -1
- package/.storybook/main.js +5 -0
- package/.storybook/manager.js +6 -0
- package/.storybook/preview.js +7 -0
- package/.stylelintrc +6 -2
- package/README.md +19 -1
- package/build/index.js +15 -11
- package/build/style.css +9 -9
- package/package.json +59 -57
- package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
- package/src/assets/containers/Generic/generic.svg +3 -0
- package/src/assets/containers/MedicationDispense/medication-dispense.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/components/containers/Accordion/Accordion.js +44 -13
- package/src/components/containers/Accordion/Accordion.stories.js +74 -58
- package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
- package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
- package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
- package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
- package/src/components/datatypes/Coding/Coding.js +7 -3
- package/src/components/datatypes/Reference/Reference.js +7 -5
- package/src/components/datatypes/Telecom/Telecom.js +2 -3
- package/src/components/defaultArgTypes.js +12 -0
- package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
- package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
- package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
- package/src/components/resources/Appointment/Appointment.js +9 -1
- package/src/components/resources/Appointment/Appointment.stories.js +51 -62
- package/src/components/resources/Appointment/Appointment.test.js +36 -1
- package/src/components/resources/Binary/Binary.js +2 -1
- package/src/components/resources/Binary/Binary.stories.js +27 -21
- 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 +59 -115
- package/src/components/resources/Bundle/Bundle.test.js +0 -3
- package/src/components/resources/CarePlan/CarePlan.js +9 -1
- package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
- package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
- package/src/components/resources/CareTeam/CareTeam.js +79 -50
- package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
- package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
- package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
- package/src/components/resources/Claim/Claim.js +9 -1
- package/src/components/resources/Claim/Claim.stories.js +36 -49
- package/src/components/resources/Claim/Claim.test.js +32 -1
- 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 +144 -83
- package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
- 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 +10 -3
- package/src/components/resources/Condition/Condition.stories.js +47 -62
- package/src/components/resources/Condition/Condition.test.js +37 -4
- package/src/components/resources/Coverage/Coverage.js +9 -1
- package/src/components/resources/Coverage/Coverage.stories.js +38 -50
- package/src/components/resources/Coverage/Coverage.test.js +36 -1
- package/src/components/resources/Device/Device.js +9 -1
- package/src/components/resources/Device/Device.stories.js +40 -52
- package/src/components/resources/Device/Device.test.js +36 -1
- package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
- package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
- package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
- package/src/components/resources/DocumentReference/DocumentReference.js +9 -2
- package/src/components/resources/DocumentReference/DocumentReference.stories.js +25 -29
- package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
- package/src/components/resources/Encounter/Encounter.js +9 -1
- package/src/components/resources/Encounter/Encounter.stories.js +43 -59
- package/src/components/resources/Encounter/Encounter.test.js +36 -1
- package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
- package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
- package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
- package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
- package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
- package/src/components/resources/Generic/Generic.js +21 -7
- package/src/components/resources/Generic/Generic.stories.js +22 -12
- package/src/components/resources/Generic/Generic.test.js +26 -7
- package/src/components/resources/Goal/Goal.js +9 -3
- package/src/components/resources/Goal/Goal.stories.js +35 -49
- package/src/components/resources/Goal/Goal.test.js +32 -1
- package/src/components/resources/Immunization/Immunization.js +9 -2
- package/src/components/resources/Immunization/Immunization.stories.js +38 -51
- 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 +137 -88
- package/src/components/resources/List/List.stories.js +69 -40
- package/src/components/resources/List/List.test.js +105 -1
- package/src/components/resources/Location/Location.js +66 -47
- package/src/components/resources/Location/Location.stories.js +25 -13
- package/src/components/resources/Location/Location.test.js +106 -4
- package/src/components/resources/Medication/Medication.js +9 -1
- package/src/components/resources/Medication/Medication.stories.js +42 -64
- package/src/components/resources/Medication/Medication.test.js +36 -1
- package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
- package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
- 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 +70 -68
- package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
- package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
- package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
- package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
- package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
- package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
- package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
- package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
- package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
- package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
- package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
- package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
- package/src/components/resources/Observation/Observation.js +3 -1
- package/src/components/resources/Observation/Observation.stories.js +39 -33
- package/src/components/resources/Observation/Observation.test.js +30 -1
- package/src/components/resources/Observation/ObservationGraph.js +1 -1
- package/src/components/resources/Organization/Organization.js +10 -2
- package/src/components/resources/Organization/Organization.stories.js +40 -52
- package/src/components/resources/Organization/Organization.test.js +36 -1
- package/src/components/resources/Patient/Patient.js +4 -0
- package/src/components/resources/Patient/Patient.stories.js +36 -28
- package/src/components/resources/Patient/Patient.test.js +31 -2
- package/src/components/resources/Practitioner/Practitioner.js +9 -1
- package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
- package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
- package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
- package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
- package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
- package/src/components/resources/Procedure/Procedure.js +3 -2
- package/src/components/resources/Procedure/Procedure.stories.js +33 -25
- 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 +38 -170
- package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
- 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 +54 -236
- package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
- 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 +72 -40
- package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
- package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
- package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
- package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -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 +167 -130
- package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
- package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
- package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
- package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
- package/src/components/ui/index.js +48 -31
- package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
- package/src/fixtures/example-icons.jsx +42 -0
- package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
- package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
- package/src/style.scss +14 -1
- package/.storybook/addons.js +0 -1
- package/.storybook/config.js +0 -26
- package/.storybook/presets.js +0 -1
|
@@ -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 Questionnaire from './Questionnaire';
|
|
5
5
|
import fhirVersions from '../fhirResourceVersions';
|
|
@@ -13,7 +13,151 @@ import stu3Example2 from '../../../fixtures/stu3/resources/questionnaire/example
|
|
|
13
13
|
import r4Example1 from '../../../fixtures/r4/resources/questionnaire/example1.json';
|
|
14
14
|
import r4Example2 from '../../../fixtures/r4/resources/questionnaire/example2.json';
|
|
15
15
|
|
|
16
|
+
import fhirIcons from '../../../fixtures/example-icons';
|
|
17
|
+
|
|
16
18
|
describe('Questionnaire should render component correctly', () => {
|
|
19
|
+
it('component without a fhirIcons props should render a default icon', () => {
|
|
20
|
+
const defaultProps = {
|
|
21
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
22
|
+
fhirResource: dstu2Example1,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
26
|
+
const headerIcon = getByAltText('questionnaire');
|
|
27
|
+
|
|
28
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('component with a false as a fhirIcons props should render a placeholder', () => {
|
|
32
|
+
const defaultProps = {
|
|
33
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
34
|
+
fhirResource: dstu2Example1,
|
|
35
|
+
fhirIcons: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const { getByTestId } = render(<Questionnaire {...defaultProps} />);
|
|
39
|
+
const headerIcon = getByTestId('placeholder');
|
|
40
|
+
|
|
41
|
+
expect(headerIcon).toBeTruthy();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('component with the img as a fhirIcons props should render an img', () => {
|
|
45
|
+
const defaultProps = {
|
|
46
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
47
|
+
fhirResource: dstu2Example1,
|
|
48
|
+
fhirIcons: (
|
|
49
|
+
<img
|
|
50
|
+
src={require('../assets/containers/Questionnaire/questionnaire.svg')}
|
|
51
|
+
alt="clipboard and pen"
|
|
52
|
+
/>
|
|
53
|
+
),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
57
|
+
const headerIcon = getByAltText('clipboard and pen');
|
|
58
|
+
|
|
59
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('component with the resources object as a fhirIcons props should render an img', () => {
|
|
63
|
+
const defaultProps = {
|
|
64
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
65
|
+
fhirResource: dstu2Example1,
|
|
66
|
+
fhirIcons: fhirIcons,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
70
|
+
const headerIcon = getByAltText('clipboard and pen');
|
|
71
|
+
|
|
72
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('component with the url as a fhirIcons props should render an img', () => {
|
|
76
|
+
const avatarSrc =
|
|
77
|
+
'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
|
|
78
|
+
const defaultProps = {
|
|
79
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
80
|
+
fhirResource: dstu2Example1,
|
|
81
|
+
fhirIcons: avatarSrc,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
85
|
+
const headerIcon = getByAltText('header icon');
|
|
86
|
+
|
|
87
|
+
expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('component without a fhirIcons props should render a default icon', () => {
|
|
91
|
+
const defaultProps = {
|
|
92
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
93
|
+
fhirResource: dstu2Example1,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
97
|
+
const headerIcon = getByAltText('questionnaire');
|
|
98
|
+
|
|
99
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('component with a false as a fhirIcons props should render a placeholder', () => {
|
|
103
|
+
const defaultProps = {
|
|
104
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
105
|
+
fhirResource: dstu2Example1,
|
|
106
|
+
fhirIcons: false,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const { getByTestId } = render(<Questionnaire {...defaultProps} />);
|
|
110
|
+
const headerIcon = getByTestId('placeholder');
|
|
111
|
+
|
|
112
|
+
expect(headerIcon).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('component with the img as a fhirIcons props should render an img', () => {
|
|
116
|
+
const defaultProps = {
|
|
117
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
118
|
+
fhirResource: dstu2Example1,
|
|
119
|
+
fhirIcons: (
|
|
120
|
+
<img
|
|
121
|
+
src={require('../assets/containers/Questionnaire/questionnaire.svg')}
|
|
122
|
+
alt="clipboard and pen"
|
|
123
|
+
/>
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
128
|
+
const headerIcon = getByAltText('clipboard and pen');
|
|
129
|
+
|
|
130
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('component with the resources object as a fhirIcons props should render an img', () => {
|
|
134
|
+
const defaultProps = {
|
|
135
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
136
|
+
fhirResource: dstu2Example1,
|
|
137
|
+
fhirIcons: fhirIcons,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
141
|
+
const headerIcon = getByAltText('clipboard and pen');
|
|
142
|
+
|
|
143
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('component with the url as a fhirIcons props should render an img', () => {
|
|
147
|
+
const avatarSrc =
|
|
148
|
+
'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
|
|
149
|
+
const defaultProps = {
|
|
150
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
151
|
+
fhirResource: dstu2Example1,
|
|
152
|
+
fhirIcons: avatarSrc,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const { getByAltText } = render(<Questionnaire {...defaultProps} />);
|
|
156
|
+
const headerIcon = getByAltText('header icon');
|
|
157
|
+
|
|
158
|
+
expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
|
|
159
|
+
});
|
|
160
|
+
|
|
17
161
|
it('should render component correctly with DSTU2 source data', () => {
|
|
18
162
|
const defaultProps = {
|
|
19
163
|
fhirResource: dstu2Example1,
|
|
@@ -34,16 +178,16 @@ describe('Questionnaire should render component correctly', () => {
|
|
|
34
178
|
|
|
35
179
|
// contain id and test of questions of subgroup
|
|
36
180
|
expect(String(getByTestId('linkId-2.1').textContent).trim()).toEqual(
|
|
37
|
-
'
|
|
181
|
+
'What is your gender?',
|
|
38
182
|
);
|
|
39
183
|
expect(String(getByTestId('linkId-2.2').textContent).trim()).toEqual(
|
|
40
|
-
'
|
|
184
|
+
'What is your date of birth?',
|
|
41
185
|
);
|
|
42
186
|
expect(String(getByTestId('linkId-2.3').textContent).trim()).toEqual(
|
|
43
|
-
'
|
|
187
|
+
'What is your country of birth?',
|
|
44
188
|
);
|
|
45
189
|
expect(String(getByTestId('linkId-2.4').textContent).trim()).toEqual(
|
|
46
|
-
'
|
|
190
|
+
'What is your marital status?',
|
|
47
191
|
);
|
|
48
192
|
});
|
|
49
193
|
|
|
@@ -90,21 +234,21 @@ describe('Questionnaire should render component correctly', () => {
|
|
|
90
234
|
|
|
91
235
|
// contain subgroup description
|
|
92
236
|
expect(String(getByTestId('linkId-2').textContent).trim()).toContain(
|
|
93
|
-
'
|
|
237
|
+
'General questions',
|
|
94
238
|
);
|
|
95
239
|
|
|
96
240
|
// contain id and test of questions of subgroup
|
|
97
241
|
expect(String(getByTestId('linkId-2.1').textContent).trim()).toContain(
|
|
98
|
-
'
|
|
242
|
+
'What is your gender?',
|
|
99
243
|
);
|
|
100
244
|
expect(String(getByTestId('linkId-2.2').textContent).trim()).toEqual(
|
|
101
|
-
'
|
|
245
|
+
'What is your date of birth?',
|
|
102
246
|
);
|
|
103
247
|
expect(String(getByTestId('linkId-2.3').textContent).trim()).toEqual(
|
|
104
|
-
'
|
|
248
|
+
'What is your country of birth?',
|
|
105
249
|
);
|
|
106
250
|
expect(String(getByTestId('linkId-2.4').textContent).trim()).toEqual(
|
|
107
|
-
'
|
|
251
|
+
'What is your marital status?',
|
|
108
252
|
);
|
|
109
253
|
});
|
|
110
254
|
|
|
@@ -151,21 +295,21 @@ describe('Questionnaire should render component correctly', () => {
|
|
|
151
295
|
|
|
152
296
|
// contain subgroup description
|
|
153
297
|
expect(String(getByTestId('linkId-2').textContent).trim()).toContain(
|
|
154
|
-
'
|
|
298
|
+
'General questions',
|
|
155
299
|
);
|
|
156
300
|
|
|
157
301
|
// contain id and test of questions of subgroup
|
|
158
302
|
expect(String(getByTestId('linkId-2.1').textContent).trim()).toContain(
|
|
159
|
-
'
|
|
303
|
+
'What is your gender?',
|
|
160
304
|
);
|
|
161
305
|
expect(String(getByTestId('linkId-2.2').textContent).trim()).toEqual(
|
|
162
|
-
'
|
|
306
|
+
'What is your date of birth?',
|
|
163
307
|
);
|
|
164
308
|
expect(String(getByTestId('linkId-2.3').textContent).trim()).toEqual(
|
|
165
|
-
'
|
|
309
|
+
'What is your country of birth?',
|
|
166
310
|
);
|
|
167
311
|
expect(String(getByTestId('linkId-2.4').textContent).trim()).toEqual(
|
|
168
|
-
'
|
|
312
|
+
'What is your marital status?',
|
|
169
313
|
);
|
|
170
314
|
});
|
|
171
315
|
|
|
@@ -196,4 +340,39 @@ describe('Questionnaire should render component correctly', () => {
|
|
|
196
340
|
String(getByTestId('linkId-1.1.1.1.1').textContent).trim(),
|
|
197
341
|
).toContain('Angina Pectoris');
|
|
198
342
|
});
|
|
343
|
+
|
|
344
|
+
it('should fire custom onClick function', () => {
|
|
345
|
+
const defaultProps = {
|
|
346
|
+
fhirResource: r4Example1,
|
|
347
|
+
fhirVersion: fhirVersions.R4,
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const onClick = jest.fn();
|
|
351
|
+
const { getByRole } = render(
|
|
352
|
+
<Questionnaire {...defaultProps} onClick={onClick} />,
|
|
353
|
+
);
|
|
354
|
+
const accordion = getByRole('button');
|
|
355
|
+
fireEvent.click(accordion);
|
|
356
|
+
|
|
357
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
358
|
+
expect(attribute).not.toEqual('collapse');
|
|
359
|
+
expect(onClick).toHaveBeenCalled();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should not fire custom onClick function', () => {
|
|
363
|
+
const defaultProps = {
|
|
364
|
+
fhirResource: r4Example1,
|
|
365
|
+
fhirVersion: fhirVersions.R4,
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const onClick = 'test';
|
|
369
|
+
const { getByRole } = render(
|
|
370
|
+
<Questionnaire {...defaultProps} onClick={onClick} />,
|
|
371
|
+
);
|
|
372
|
+
const accordion = getByRole('button');
|
|
373
|
+
fireEvent.click(accordion);
|
|
374
|
+
|
|
375
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
376
|
+
expect(attribute).toEqual('collapse');
|
|
377
|
+
});
|
|
199
378
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Group from './Group';
|
|
4
|
+
import { getQuestionText } from './getQuestionText';
|
|
5
|
+
|
|
6
|
+
const Questions = ({ questions, prepareItems }) => {
|
|
7
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<ul className="fhir-resource__Questionnaire-questions-list">
|
|
13
|
+
{questions.map((item, i) => {
|
|
14
|
+
const text = getQuestionText(item);
|
|
15
|
+
return (
|
|
16
|
+
text && (
|
|
17
|
+
<li
|
|
18
|
+
key={`questionnaire-questions-item-${i}`}
|
|
19
|
+
data-testid={`linkId-${item.linkId}`}
|
|
20
|
+
>
|
|
21
|
+
<div className="fhir-resource__Questionnaire-questions-list-element">
|
|
22
|
+
{text}
|
|
23
|
+
</div>
|
|
24
|
+
{item.item && item.item.length > 0 && (
|
|
25
|
+
<Group data={item.item} prepareItems={prepareItems} isChild />
|
|
26
|
+
)}
|
|
27
|
+
</li>
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
})}
|
|
31
|
+
</ul>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Questions.propTypes = {
|
|
36
|
+
questions: PropTypes.array,
|
|
37
|
+
prepareItems: PropTypes.func.isRequired,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default Questions;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
import Coding from '../../datatypes/Coding';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
export const getQuestionText = item => {
|
|
6
|
+
let text = _get(item, 'text');
|
|
7
|
+
if (!text) {
|
|
8
|
+
// DSTU2
|
|
9
|
+
const groupConcept = _get(item, 'concept.0');
|
|
10
|
+
if (groupConcept) {
|
|
11
|
+
text = <Coding fhirData={groupConcept} />;
|
|
12
|
+
}
|
|
13
|
+
// STU3 & R4
|
|
14
|
+
const groupCode = _get(item, 'code.0');
|
|
15
|
+
if (!text && groupCode) {
|
|
16
|
+
text = <Coding fhirData={groupCode} />;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return text;
|
|
20
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Date from '../../datatypes/Date';
|
|
2
|
+
import Coding from '../../datatypes/Coding';
|
|
3
|
+
import Attachment from '../../datatypes/Attachment';
|
|
4
|
+
import Quantity from '../../datatypes/Quantity';
|
|
5
|
+
import _get from 'lodash/get';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import Group from './Group';
|
|
8
|
+
|
|
9
|
+
const answerTypes = {
|
|
10
|
+
valueString: value => value,
|
|
11
|
+
valueDecimal: value => value,
|
|
12
|
+
valueInteger: value => value,
|
|
13
|
+
valueDate: value => <Date fhirData={value} isBlack />,
|
|
14
|
+
valueDateTime: value => <Date fhirData={value} isBlack />,
|
|
15
|
+
valueCoding: value => <Coding fhirData={value} />,
|
|
16
|
+
valueAttachment: value => <Attachment fhirData={value} />,
|
|
17
|
+
valueQuantity: value => <Quantity fhirData={value} />,
|
|
18
|
+
valueBoolean: value => (value ? 'Yes' : 'No'),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const Answers = props => {
|
|
22
|
+
const { data, prepareItems } = props;
|
|
23
|
+
if (!Array.isArray(data)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<div className="fhir-resource__QuestionnaireResponse-questions-list-item-details">
|
|
28
|
+
{data.map(answer => {
|
|
29
|
+
return Object.keys(answer).map((answerKey, i) => {
|
|
30
|
+
const toRender = [];
|
|
31
|
+
if (typeof answerTypes[answerKey] === 'function') {
|
|
32
|
+
toRender.push(
|
|
33
|
+
<div
|
|
34
|
+
key={`questionnaire-response-answer-item-${i}`}
|
|
35
|
+
className="fhir-resource__QuestionnaireResponse-questions-list-item-details-el"
|
|
36
|
+
data-testid={`${props['data-testid']}-${i}`}
|
|
37
|
+
>
|
|
38
|
+
{answerTypes[answerKey](answer[answerKey])}{' '}
|
|
39
|
+
</div>,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (_get(answer, 'item')) {
|
|
43
|
+
toRender.push(
|
|
44
|
+
<Group
|
|
45
|
+
key={`questionnaire-response-answer-group-item-${i}`}
|
|
46
|
+
data={answer.item}
|
|
47
|
+
prepareItems={prepareItems}
|
|
48
|
+
isChild
|
|
49
|
+
/>,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return toRender;
|
|
53
|
+
});
|
|
54
|
+
})}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default Answers;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
import { MissingValue } from '../../ui';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import Answers from './Answers';
|
|
6
|
+
import Questions from './Questions';
|
|
7
|
+
|
|
8
|
+
const Group = ({ data, prepareItems, isChild = false }) => {
|
|
9
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return data.map(prepareItems).map((item, i) => {
|
|
14
|
+
const title =
|
|
15
|
+
_get(item, 'title') ||
|
|
16
|
+
_get(item, 'text') ||
|
|
17
|
+
_get(item, '_linkId.fhir_comments.0');
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<ul
|
|
21
|
+
key={`questionnaire-response-item-${i}`}
|
|
22
|
+
className="fhir-resource__QuestionnaireResponse-list"
|
|
23
|
+
>
|
|
24
|
+
<li
|
|
25
|
+
className={
|
|
26
|
+
isChild
|
|
27
|
+
? 'fhir-resource__QuestionnaireResponse-list-title-question'
|
|
28
|
+
: 'fhir-resource__QuestionnaireResponse-list-title'
|
|
29
|
+
}
|
|
30
|
+
data-testid={`linkId-${item.linkId}`}
|
|
31
|
+
>
|
|
32
|
+
{title || <MissingValue />}
|
|
33
|
+
</li>
|
|
34
|
+
{item.isGroup && (
|
|
35
|
+
<li>
|
|
36
|
+
<Group data={item.group} prepareItems={prepareItems} isChild />
|
|
37
|
+
</li>
|
|
38
|
+
)}
|
|
39
|
+
{!item.isGroup && (
|
|
40
|
+
<>
|
|
41
|
+
{item.question && (
|
|
42
|
+
<li>
|
|
43
|
+
<Questions
|
|
44
|
+
questions={item.question}
|
|
45
|
+
prepareItems={prepareItems}
|
|
46
|
+
/>
|
|
47
|
+
</li>
|
|
48
|
+
)}
|
|
49
|
+
{item.answer && (
|
|
50
|
+
<li>
|
|
51
|
+
<Answers
|
|
52
|
+
data={item.answer}
|
|
53
|
+
prepareItems={prepareItems}
|
|
54
|
+
data-testid={`answer-${item.linkId}`}
|
|
55
|
+
/>
|
|
56
|
+
</li>
|
|
57
|
+
)}
|
|
58
|
+
</>
|
|
59
|
+
)}
|
|
60
|
+
</ul>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Group.propTypes = {
|
|
66
|
+
data: PropTypes.array,
|
|
67
|
+
prepareItems: PropTypes.func.isRequired,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default Group;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fhirVersions from '../fhirResourceVersions';
|
|
2
|
+
import _get from 'lodash/get';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import Group from './Group';
|
|
6
|
+
|
|
7
|
+
const Items = ({ fhirVersion, data }) => {
|
|
8
|
+
if (fhirVersion === fhirVersions.DSTU2) {
|
|
9
|
+
const prepareItems = item => {
|
|
10
|
+
return {
|
|
11
|
+
...item,
|
|
12
|
+
isGroup: !!_get(item, 'group'),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (data.isGroup) {
|
|
17
|
+
return <Group data={data.data} prepareItems={prepareItems} />;
|
|
18
|
+
}
|
|
19
|
+
return (
|
|
20
|
+
<Group data={[{ question: data.data }]} prepareItems={prepareItems} />
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (fhirVersion === fhirVersions.STU3 || fhirVersion === fhirVersions.R4) {
|
|
25
|
+
const prepareItems = item => ({
|
|
26
|
+
...item,
|
|
27
|
+
group: !!_get(item, 'item') ? _get(item, 'item') : null,
|
|
28
|
+
isGroup: !!_get(item, 'item'),
|
|
29
|
+
});
|
|
30
|
+
return <Group data={[{ question: data }]} prepareItems={prepareItems} />;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Items.propTypes = {
|
|
37
|
+
data: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
38
|
+
fhirVersion: PropTypes.oneOf([
|
|
39
|
+
fhirVersions.DSTU2,
|
|
40
|
+
fhirVersions.STU3,
|
|
41
|
+
fhirVersions.R4,
|
|
42
|
+
]).isRequired,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Items;
|
|
@@ -1,21 +1,45 @@
|
|
|
1
1
|
.fhir-resource__QuestionnaireResponse-list {
|
|
2
2
|
list-style: none;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
padding: 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.fhir-resource__QuestionnaireResponse-list:first-of-type {
|
|
8
|
+
padding-top: 20px;
|
|
6
9
|
}
|
|
7
10
|
|
|
8
11
|
.fhir-resource__QuestionnaireResponse-list-title {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
padding: 2px 2px 8px 2px;
|
|
13
|
+
font-weight: bold;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.fhir-resource__QuestionnaireResponse-list-title-question {
|
|
17
|
+
background: #f8f9fa;
|
|
18
|
+
align-items: center;
|
|
19
|
+
margin-bottom: 56px;
|
|
20
|
+
padding-left: 16px;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
color: #adb5bd;
|
|
11
23
|
}
|
|
12
24
|
|
|
13
25
|
.fhir-resource__QuestionnaireResponse-questions-list {
|
|
14
26
|
list-style: none;
|
|
27
|
+
padding-left: 0;
|
|
28
|
+
display: block;
|
|
29
|
+
color: #adb5bd;
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
.fhir-resource__QuestionnaireResponse-questions-list li {
|
|
18
|
-
|
|
33
|
+
display: block;
|
|
34
|
+
margin-bottom: 56px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.fhir-resource__QuestionnaireResponse-questions-list-element {
|
|
38
|
+
background: #f8f9fa;
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
width: 100%;
|
|
41
|
+
padding-left: 16px;
|
|
42
|
+
margin-bottom: 56px;
|
|
19
43
|
}
|
|
20
44
|
|
|
21
45
|
.fhir-resource__QuestionnaireResponse-questions-list li:last-child {
|
|
@@ -23,11 +47,12 @@
|
|
|
23
47
|
}
|
|
24
48
|
|
|
25
49
|
.fhir-resource__QuestionnaireResponse-questions-list-item-details {
|
|
26
|
-
margin
|
|
50
|
+
margin: -30px 0;
|
|
27
51
|
}
|
|
28
52
|
|
|
29
53
|
.fhir-resource__QuestionnaireResponse-questions-list-item-details-el {
|
|
30
54
|
display: inline-block;
|
|
55
|
+
color: black;
|
|
31
56
|
margin-right: 15px;
|
|
32
|
-
|
|
57
|
+
margin-left: 20px;
|
|
33
58
|
}
|