fhir-react 0.3.7 → 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 +7 -7
- package/package.json +55 -54
- 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 +21 -13
- 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/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 +7 -1
- package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
- package/src/components/resources/Appointment/Appointment.js +2 -1
- package/src/components/resources/Appointment/Appointment.test.js +36 -1
- 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.test.js +42 -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/Claim.js +2 -1
- 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 +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 +2 -1
- package/src/components/resources/Coverage/Coverage.test.js +36 -1
- package/src/components/resources/Device/Device.js +2 -1
- package/src/components/resources/Device/Device.test.js +36 -1
- package/src/components/resources/DiagnosticReport/DiagnosticReport.js +7 -2
- package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
- package/src/components/resources/DocumentReference/DocumentReference.js +7 -2
- package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -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.test.js +36 -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 +2 -3
- package/src/components/resources/Goal/Goal.test.js +32 -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 +2 -1
- package/src/components/resources/Medication/Medication.test.js +36 -1
- 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 +2 -3
- package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
- package/src/components/resources/MedicationRequest/MedicationRequest.js +2 -1
- package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
- package/src/components/resources/MedicationStatement/MedicationStatement.js +7 -2
- package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -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 +3 -2
- package/src/components/resources/Organization/Organization.test.js +36 -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/ui/index.js +22 -9
- 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 +3 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Group from './Group';
|
|
5
|
+
import Answers from './Answers';
|
|
6
|
+
import { getQuestionText } from './getQuestionText';
|
|
7
|
+
|
|
8
|
+
const Questions = ({ questions, prepareItems }) => {
|
|
9
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ul className="fhir-resource__QuestionnaireResponse-questions-list">
|
|
15
|
+
{questions.map(prepareItems).map((item, i) => {
|
|
16
|
+
const text = getQuestionText(item);
|
|
17
|
+
const hasGroup = item.isGroup;
|
|
18
|
+
const answers = _get(item, 'answer', []);
|
|
19
|
+
return (
|
|
20
|
+
<li
|
|
21
|
+
key={`questionnaire-response-questions-item-${i}`}
|
|
22
|
+
data-testid={`linkId-${item.linkId}`}
|
|
23
|
+
>
|
|
24
|
+
<div className="fhir-resource__QuestionnaireResponse-questions-list-element">
|
|
25
|
+
{text}
|
|
26
|
+
</div>
|
|
27
|
+
{answers && <Answers data={item.answer} />}
|
|
28
|
+
{hasGroup && (
|
|
29
|
+
<Group data={item.group} prepareItems={prepareItems} isChild />
|
|
30
|
+
)}
|
|
31
|
+
</li>
|
|
32
|
+
);
|
|
33
|
+
})}
|
|
34
|
+
</ul>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Questions.propTypes = {
|
|
39
|
+
questions: PropTypes.array,
|
|
40
|
+
prepareItems: PropTypes.func.isRequired,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default Questions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
import Coding from '../../datatypes/Coding';
|
|
3
|
+
import { MissingValue } from '../../ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
export const getQuestionText = item => {
|
|
7
|
+
let text = _get(item, 'text');
|
|
8
|
+
if (!text) {
|
|
9
|
+
// DSTU2
|
|
10
|
+
const groupConcept = _get(item, 'concept.0');
|
|
11
|
+
if (groupConcept) {
|
|
12
|
+
text = <Coding fhirData={groupConcept} />;
|
|
13
|
+
}
|
|
14
|
+
text = text ? text : <MissingValue />;
|
|
15
|
+
// STU3
|
|
16
|
+
const groupCode = _get(item, 'code.0');
|
|
17
|
+
if (!text && groupCode) {
|
|
18
|
+
text = <Coding fhirData={groupCode} />;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return text;
|
|
22
|
+
};
|
|
@@ -9,13 +9,15 @@ import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
|
|
|
9
9
|
import {
|
|
10
10
|
Root,
|
|
11
11
|
Body,
|
|
12
|
-
Value,
|
|
13
12
|
Table,
|
|
14
13
|
TableRow,
|
|
15
14
|
TableHeader,
|
|
16
15
|
TableCell,
|
|
17
16
|
MissingValue,
|
|
17
|
+
Header,
|
|
18
|
+
ValueSection,
|
|
18
19
|
} from '../../ui';
|
|
20
|
+
import Accordion from '../../containers/Accordion';
|
|
19
21
|
|
|
20
22
|
const commonDTO = fhirResource => {
|
|
21
23
|
const typeCoding = _get(fhirResource, 'type.coding.0');
|
|
@@ -68,8 +70,7 @@ const resourceDTO = (fhirVersion, fhirResource) => {
|
|
|
68
70
|
}
|
|
69
71
|
};
|
|
70
72
|
|
|
71
|
-
const ReferralRequest =
|
|
72
|
-
const { fhirResource, fhirVersion } = props;
|
|
73
|
+
const ReferralRequest = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
|
|
73
74
|
let fhirResourceData = {};
|
|
74
75
|
try {
|
|
75
76
|
fhirResourceData = resourceDTO(fhirVersion, fhirResource);
|
|
@@ -87,45 +88,69 @@ const ReferralRequest = props => {
|
|
|
87
88
|
description,
|
|
88
89
|
} = fhirResourceData;
|
|
89
90
|
|
|
91
|
+
const tableData = [
|
|
92
|
+
{
|
|
93
|
+
testId: 'dateSent',
|
|
94
|
+
data: <Date fhirData={dateSent} isBlack />,
|
|
95
|
+
status: dateSent,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
testId: 'subject',
|
|
99
|
+
data: <span>{subject}</span>,
|
|
100
|
+
status: subject,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
testId: 'requester',
|
|
104
|
+
data: <span>{requester}</span>,
|
|
105
|
+
status: requester,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
testId: 'status',
|
|
109
|
+
data: <span>{status}</span>,
|
|
110
|
+
status: status,
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
90
114
|
return (
|
|
91
115
|
<Root name="ReferralRequest">
|
|
92
|
-
<
|
|
93
|
-
{
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
</
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
<Accordion
|
|
117
|
+
headerContent={
|
|
118
|
+
<Header
|
|
119
|
+
resourceName="ReferralRequest"
|
|
120
|
+
title={typeCoding && <Coding fhirData={typeCoding} />}
|
|
121
|
+
icon={fhirIcons}
|
|
122
|
+
/>
|
|
123
|
+
}
|
|
124
|
+
bodyContent={
|
|
125
|
+
<Body>
|
|
126
|
+
<Table>
|
|
127
|
+
<thead>
|
|
128
|
+
<TableRow>
|
|
129
|
+
<TableHeader>Request sent</TableHeader>
|
|
130
|
+
<TableHeader>Patient</TableHeader>
|
|
131
|
+
<TableHeader>Requester</TableHeader>
|
|
132
|
+
<TableHeader>Status</TableHeader>
|
|
133
|
+
</TableRow>
|
|
134
|
+
</thead>
|
|
135
|
+
<tbody className="border-top-0">
|
|
136
|
+
<TableRow>
|
|
137
|
+
{tableData.map((element, index) => (
|
|
138
|
+
<TableCell key={index} data-testid={element.testId}>
|
|
139
|
+
{element.status ? element.data : <MissingValue />}
|
|
140
|
+
</TableCell>
|
|
141
|
+
))}
|
|
142
|
+
</TableRow>
|
|
143
|
+
</tbody>
|
|
144
|
+
</Table>
|
|
145
|
+
{description && (
|
|
146
|
+
<ValueSection label={reason} data-testid="reason" marginTop>
|
|
147
|
+
<small className="text-secondary">{description}</small>
|
|
148
|
+
</ValueSection>
|
|
149
|
+
)}
|
|
150
|
+
</Body>
|
|
151
|
+
}
|
|
152
|
+
onClick={onClick}
|
|
153
|
+
/>
|
|
129
154
|
</Root>
|
|
130
155
|
);
|
|
131
156
|
};
|
|
@@ -1,12 +1,85 @@
|
|
|
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 ReferralRequest from './ReferralRequest';
|
|
5
5
|
import fhirVersions from '../fhirResourceVersions';
|
|
6
6
|
import dstu2Example1 from '../../../fixtures/dstu2/resources/referralRequest/example1.json';
|
|
7
7
|
import stu3Example1 from '../../../fixtures/stu3/resources/referralRequest/example1.json';
|
|
8
8
|
|
|
9
|
+
import fhirIcons from '../../../fixtures/example-icons';
|
|
10
|
+
|
|
9
11
|
describe('should render ReferralRequest component properly', () => {
|
|
12
|
+
it('component without a fhirIcons props should render a default icon', () => {
|
|
13
|
+
const defaultProps = {
|
|
14
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
15
|
+
fhirResource: dstu2Example1,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const { getByAltText } = render(<ReferralRequest {...defaultProps} />);
|
|
19
|
+
const headerIcon = getByAltText('referral request');
|
|
20
|
+
|
|
21
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('component with a false as a fhirIcons props should render a placeholder', () => {
|
|
25
|
+
const defaultProps = {
|
|
26
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
27
|
+
fhirResource: dstu2Example1,
|
|
28
|
+
fhirIcons: false,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const { getByTestId } = render(<ReferralRequest {...defaultProps} />);
|
|
32
|
+
const headerIcon = getByTestId('placeholder');
|
|
33
|
+
|
|
34
|
+
expect(headerIcon).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('component with the img as a fhirIcons props should render an img', () => {
|
|
38
|
+
const defaultProps = {
|
|
39
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
40
|
+
fhirResource: dstu2Example1,
|
|
41
|
+
fhirIcons: (
|
|
42
|
+
<img
|
|
43
|
+
src={require('../assets/containers/ReferralRequest/referral-request.svg')}
|
|
44
|
+
alt="referral request"
|
|
45
|
+
/>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const { getByAltText } = render(<ReferralRequest {...defaultProps} />);
|
|
50
|
+
const headerIcon = getByAltText('referral request');
|
|
51
|
+
|
|
52
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('component with the resources object as a fhirIcons props should render an img', () => {
|
|
56
|
+
const defaultProps = {
|
|
57
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
58
|
+
fhirResource: dstu2Example1,
|
|
59
|
+
fhirIcons: fhirIcons,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const { getByAltText } = render(<ReferralRequest {...defaultProps} />);
|
|
63
|
+
const headerIcon = getByAltText('referral request');
|
|
64
|
+
|
|
65
|
+
expect(headerIcon.getAttribute('src')).toContain('IMAGE_MOCK');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('component with the url as a fhirIcons props should render an img', () => {
|
|
69
|
+
const avatarSrc =
|
|
70
|
+
'https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1';
|
|
71
|
+
const defaultProps = {
|
|
72
|
+
fhirVersion: fhirVersions.DSTU2,
|
|
73
|
+
fhirResource: dstu2Example1,
|
|
74
|
+
fhirIcons: avatarSrc,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const { getByAltText } = render(<ReferralRequest {...defaultProps} />);
|
|
78
|
+
const headerIcon = getByAltText('header icon');
|
|
79
|
+
|
|
80
|
+
expect(headerIcon.getAttribute('src')).toContain(avatarSrc);
|
|
81
|
+
});
|
|
82
|
+
|
|
10
83
|
it('should render with DSTU2 source data', () => {
|
|
11
84
|
const defaultProps = {
|
|
12
85
|
fhirResource: dstu2Example1,
|
|
@@ -18,16 +91,11 @@ describe('should render ReferralRequest component properly', () => {
|
|
|
18
91
|
);
|
|
19
92
|
expect(container).not.toBeNull();
|
|
20
93
|
|
|
21
|
-
expect(getByTestId('
|
|
22
|
-
'Referral for service',
|
|
23
|
-
);
|
|
94
|
+
expect(getByTestId('title').textContent).toContain('Referral for service');
|
|
24
95
|
expect(getByTestId('dateSent').textContent).toContain('2/14/2014');
|
|
25
96
|
expect(getByTestId('reason').textContent).toContain(
|
|
26
97
|
'For consideration of Grommets',
|
|
27
98
|
);
|
|
28
|
-
expect(getByTestId('description').textContent).toContain(
|
|
29
|
-
'In the past 2 years Beverly',
|
|
30
|
-
);
|
|
31
99
|
expect(getByTestId('subject').textContent).toContain('Beverly Weaver');
|
|
32
100
|
expect(getByTestId('requester').textContent).toEqual('Serena Shrink');
|
|
33
101
|
});
|
|
@@ -43,17 +111,49 @@ describe('should render ReferralRequest component properly', () => {
|
|
|
43
111
|
);
|
|
44
112
|
expect(container).not.toBeNull();
|
|
45
113
|
|
|
46
|
-
expect(getByTestId('
|
|
114
|
+
expect(getByTestId('title').textContent).toContain(
|
|
47
115
|
'Patient referral to specialist',
|
|
48
116
|
);
|
|
49
117
|
expect(getByTestId('dateSent').textContent).toContain('2/14/2014');
|
|
50
118
|
expect(getByTestId('reason').textContent).toContain(
|
|
51
119
|
'For consideration of Grommets',
|
|
52
120
|
);
|
|
53
|
-
expect(getByTestId('description').textContent).toContain(
|
|
54
|
-
'In the past 2 years Beverly',
|
|
55
|
-
);
|
|
56
121
|
expect(getByTestId('subject').textContent).toContain('Beverly Weaver');
|
|
57
122
|
expect(getByTestId('requester').textContent).toEqual('Serena Shrink');
|
|
58
123
|
});
|
|
124
|
+
|
|
125
|
+
it('should fire custom onClick function', () => {
|
|
126
|
+
const defaultProps = {
|
|
127
|
+
fhirResource: stu3Example1,
|
|
128
|
+
fhirVersion: fhirVersions.STU3,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const onClick = jest.fn();
|
|
132
|
+
const { getByRole } = render(
|
|
133
|
+
<ReferralRequest {...defaultProps} onClick={onClick} />,
|
|
134
|
+
);
|
|
135
|
+
const accordion = getByRole('button');
|
|
136
|
+
fireEvent.click(accordion);
|
|
137
|
+
|
|
138
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
139
|
+
expect(attribute).not.toEqual('collapse');
|
|
140
|
+
expect(onClick).toHaveBeenCalled();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should not fire custom onClick function', () => {
|
|
144
|
+
const defaultProps = {
|
|
145
|
+
fhirResource: stu3Example1,
|
|
146
|
+
fhirVersion: fhirVersions.STU3,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const onClick = 'test';
|
|
150
|
+
const { getByRole } = render(
|
|
151
|
+
<ReferralRequest {...defaultProps} onClick={onClick} />,
|
|
152
|
+
);
|
|
153
|
+
const accordion = getByRole('button');
|
|
154
|
+
fireEvent.click(accordion);
|
|
155
|
+
|
|
156
|
+
const attribute = accordion.getAttribute('data-bs-toggle');
|
|
157
|
+
expect(attribute).toEqual('collapse');
|
|
158
|
+
});
|
|
59
159
|
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import _get from 'lodash/get';
|
|
4
|
+
|
|
5
|
+
import Telecom from '../../datatypes/Telecom';
|
|
6
|
+
import Address from '../../datatypes/Address';
|
|
7
|
+
import Accordion from '../../containers/Accordion';
|
|
8
|
+
import { Root, Header, MissingValue, Body } from '../../ui';
|
|
9
|
+
import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
|
|
10
|
+
import Reference from '../../datatypes/Reference';
|
|
11
|
+
import fhirVersions from '../fhirResourceVersions';
|
|
12
|
+
import HumanName from '../../datatypes/HumanName';
|
|
13
|
+
|
|
14
|
+
const commonDTO = fhirResource => {
|
|
15
|
+
const patient = _get(fhirResource, 'patient');
|
|
16
|
+
const birthDate = _get(fhirResource, 'birthDate');
|
|
17
|
+
const gender = _get(fhirResource, 'gender');
|
|
18
|
+
const address = _get(fhirResource, 'address[0]');
|
|
19
|
+
const relatedPersonTelecom = _get(fhirResource, 'telecom', []).filter(
|
|
20
|
+
telecom => telecom.system === 'phone',
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
patient,
|
|
25
|
+
birthDate,
|
|
26
|
+
gender,
|
|
27
|
+
address,
|
|
28
|
+
relatedPersonTelecom,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const dstu2DTO = fhirResource => {
|
|
33
|
+
const name = _get(fhirResource, 'name');
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const stu3r4DTO = fhirResource => {
|
|
41
|
+
const name = _get(fhirResource, 'name')[0];
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const resourceDTO = (fhirVersion, fhirResource) => {
|
|
49
|
+
switch (fhirVersion) {
|
|
50
|
+
case fhirVersions.DSTU2: {
|
|
51
|
+
return {
|
|
52
|
+
...commonDTO(fhirResource),
|
|
53
|
+
...dstu2DTO(fhirResource),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case fhirVersions.STU3:
|
|
58
|
+
case fhirVersions.R4: {
|
|
59
|
+
return {
|
|
60
|
+
...commonDTO(fhirResource),
|
|
61
|
+
...stu3r4DTO(fhirResource),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
throw Error('Unrecognized the fhir version property type.');
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const RelatedPerson = ({ fhirResource, fhirVersion, fhirIcons, onClick }) => {
|
|
71
|
+
let fhirResourceData = {};
|
|
72
|
+
try {
|
|
73
|
+
fhirResourceData = resourceDTO(fhirVersion, fhirResource);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.warn(error.message);
|
|
76
|
+
return <UnhandledResourceDataStructure resourceName="RelatedPerson" />;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
patient,
|
|
81
|
+
name,
|
|
82
|
+
birthDate,
|
|
83
|
+
gender,
|
|
84
|
+
address,
|
|
85
|
+
relatedPersonTelecom,
|
|
86
|
+
} = fhirResourceData;
|
|
87
|
+
|
|
88
|
+
const tableData = [
|
|
89
|
+
{
|
|
90
|
+
label: 'Patient',
|
|
91
|
+
testId: 'patient',
|
|
92
|
+
data: patient && <Reference fhirData={patient} />,
|
|
93
|
+
status: patient,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
label: 'Address',
|
|
97
|
+
testId: 'address',
|
|
98
|
+
data: address && <Address fhirData={address} />,
|
|
99
|
+
status: address,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
label: 'Telephone',
|
|
103
|
+
testId: 'telephone',
|
|
104
|
+
data: !relatedPersonTelecom ? (
|
|
105
|
+
<MissingValue />
|
|
106
|
+
) : (
|
|
107
|
+
relatedPersonTelecom.map((telecom, index) => (
|
|
108
|
+
<Telecom key={index} fhirData={telecom} />
|
|
109
|
+
))
|
|
110
|
+
),
|
|
111
|
+
status: relatedPersonTelecom,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Root name="RelatedPerson">
|
|
117
|
+
<Accordion
|
|
118
|
+
headerContent={
|
|
119
|
+
<Header
|
|
120
|
+
resourceName="RelatedPerson"
|
|
121
|
+
additionalContent={
|
|
122
|
+
(birthDate || gender) && (
|
|
123
|
+
<span className="text-gray-600">
|
|
124
|
+
{gender && (
|
|
125
|
+
<span data-testid="gender" className="text-capitalize">
|
|
126
|
+
{gender || 'unknown'}
|
|
127
|
+
</span>
|
|
128
|
+
)}
|
|
129
|
+
{gender && birthDate && ', '}
|
|
130
|
+
{birthDate && (
|
|
131
|
+
<span data-testid="birthDate">{birthDate}</span>
|
|
132
|
+
)}
|
|
133
|
+
</span>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
icon={fhirIcons}
|
|
137
|
+
title={<HumanName fhirData={name} isTitle />}
|
|
138
|
+
/>
|
|
139
|
+
}
|
|
140
|
+
bodyContent={<Body tableData={tableData} />}
|
|
141
|
+
onClick={onClick}
|
|
142
|
+
/>
|
|
143
|
+
</Root>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
RelatedPerson.propTypes = {
|
|
148
|
+
fhirResource: PropTypes.shape({}).isRequired,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export default RelatedPerson;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { object } from '@storybook/addon-knobs';
|
|
3
|
+
|
|
4
|
+
import RelatedPerson from './RelatedPerson';
|
|
5
|
+
import fhirVersions from '../fhirResourceVersions';
|
|
6
|
+
|
|
7
|
+
import exampleDSTU2 from '../../../fixtures/dstu2/resources/relatedPerson/example1.json';
|
|
8
|
+
import exampleSTU3 from '../../../fixtures/stu3/resources/relatedPerson/example1.json';
|
|
9
|
+
import exampleR4 from '../../../fixtures/r4/resources/relatedPerson/example1.json';
|
|
10
|
+
|
|
11
|
+
import fhirIcons from '../../../fixtures/example-icons';
|
|
12
|
+
|
|
13
|
+
export default { title: 'RelatedPerson' };
|
|
14
|
+
|
|
15
|
+
export const ExampleDSTU2 = () => {
|
|
16
|
+
const fhirResource = object('Resource', exampleDSTU2);
|
|
17
|
+
return (
|
|
18
|
+
<RelatedPerson
|
|
19
|
+
fhirResource={fhirResource}
|
|
20
|
+
fhirVersion={fhirVersions.DSTU2}
|
|
21
|
+
fhirIcons={fhirIcons}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ExampleSTU3 = () => {
|
|
27
|
+
const fhirResource = object('Resource', exampleSTU3);
|
|
28
|
+
return (
|
|
29
|
+
<RelatedPerson
|
|
30
|
+
fhirResource={fhirResource}
|
|
31
|
+
fhirVersion={fhirVersions.STU3}
|
|
32
|
+
fhirIcons={false}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const ExampleR4 = () => {
|
|
38
|
+
const fhirResource = object('Resource', exampleR4);
|
|
39
|
+
return (
|
|
40
|
+
<RelatedPerson
|
|
41
|
+
fhirResource={fhirResource}
|
|
42
|
+
fhirVersion={fhirVersions.R4}
|
|
43
|
+
fhirIcons={'random text'}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
};
|