fhir-react 0.3.6 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.stylelintrc +6 -2
  4. package/README.md +19 -1
  5. package/build/index.js +15 -11
  6. package/build/style.css +11 -10
  7. package/package.json +55 -54
  8. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  9. package/src/assets/containers/Coverage/coverage.svg +4 -0
  10. package/src/assets/containers/Generic/generic.svg +3 -0
  11. package/src/assets/containers/Medication/medication.svg +5 -0
  12. package/src/assets/containers/MedicationDispense/medication-dispense.svg +5 -0
  13. package/src/assets/containers/Organization/organization.svg +5 -0
  14. package/src/assets/containers/PractitionerRole/practitioner-role.svg +5 -0
  15. package/src/assets/containers/ReferralRequest/referral-request.svg +8 -0
  16. package/src/assets/containers/RelatedPerson/related-person.svg +6 -0
  17. package/src/components/containers/Accordion/Accordion.js +44 -13
  18. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  19. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  20. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +23 -1
  21. package/src/components/datatypes/Attachment/Attachment.css +5 -0
  22. package/src/components/datatypes/Attachment/Attachment.js +7 -2
  23. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  24. package/src/components/datatypes/Coding/Coding.js +7 -3
  25. package/src/components/datatypes/Identifier/Identifier.js +7 -3
  26. package/src/components/datatypes/Reference/Reference.js +7 -1
  27. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  28. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  29. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +12 -2
  30. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  32. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +36 -1
  33. package/src/components/resources/Appointment/Appointment.js +9 -1
  34. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  35. package/src/components/resources/Binary/Binary.js +2 -1
  36. package/src/components/resources/Bundle/Bundle.css +7 -0
  37. package/src/components/resources/Bundle/Bundle.js +15 -11
  38. package/src/components/resources/Bundle/Bundle.stories.js +12 -78
  39. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  40. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  41. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  42. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  43. package/src/components/resources/CareTeam/CareTeam.stories.js +20 -3
  44. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  45. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  46. package/src/components/resources/Claim/CareTeam.js +55 -0
  47. package/src/components/resources/Claim/Claim.css +2 -11
  48. package/src/components/resources/Claim/Claim.js +165 -309
  49. package/src/components/resources/Claim/Claim.stories.js +37 -5
  50. package/src/components/resources/Claim/Claim.test.js +104 -1
  51. package/src/components/resources/Claim/Diagnosis.js +61 -0
  52. package/src/components/resources/Claim/Insurance.js +58 -0
  53. package/src/components/resources/Claim/Item.js +79 -0
  54. package/src/components/resources/Claim/Items.js +29 -0
  55. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  56. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  57. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  58. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +15 -2
  59. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  60. package/src/components/resources/ClaimResponse/Item.js +44 -9
  61. package/src/components/resources/ClaimResponse/Items.js +5 -4
  62. package/src/components/resources/Condition/Condition.js +10 -3
  63. package/src/components/resources/Condition/Condition.test.js +37 -4
  64. package/src/components/resources/Coverage/Coverage.js +104 -69
  65. package/src/components/resources/Coverage/Coverage.stories.js +31 -5
  66. package/src/components/resources/Coverage/Coverage.test.js +111 -4
  67. package/src/components/resources/Device/Device.js +9 -1
  68. package/src/components/resources/Device/Device.test.js +36 -1
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  70. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +36 -1
  71. package/src/components/resources/DocumentReference/DocumentReference.js +9 -2
  72. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  73. package/src/components/resources/Encounter/Encounter.js +9 -1
  74. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  75. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  76. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  77. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  78. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  79. package/src/components/resources/Generic/Generic.js +21 -7
  80. package/src/components/resources/Generic/Generic.stories.js +2 -1
  81. package/src/components/resources/Generic/Generic.test.js +26 -7
  82. package/src/components/resources/Goal/Goal.js +9 -3
  83. package/src/components/resources/Goal/Goal.test.js +32 -1
  84. package/src/components/resources/Immunization/Immunization.js +9 -2
  85. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  86. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  87. package/src/components/resources/List/Entries.js +3 -3
  88. package/src/components/resources/List/List.js +137 -88
  89. package/src/components/resources/List/List.stories.js +38 -5
  90. package/src/components/resources/List/List.test.js +105 -1
  91. package/src/components/resources/Location/Location.js +66 -47
  92. package/src/components/resources/Location/Location.stories.js +11 -4
  93. package/src/components/resources/Location/Location.test.js +106 -4
  94. package/src/components/resources/Medication/Medication.js +98 -51
  95. package/src/components/resources/Medication/Medication.stories.js +37 -7
  96. package/src/components/resources/Medication/Medication.test.js +114 -5
  97. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  98. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +7 -0
  99. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  100. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  101. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  102. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +7 -0
  103. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  104. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  105. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +6 -0
  106. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  107. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  108. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  109. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  110. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  111. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  112. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  113. package/src/components/resources/Observation/Observation.js +3 -1
  114. package/src/components/resources/Observation/Observation.test.js +30 -1
  115. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  116. package/src/components/resources/Organization/Organization.js +63 -37
  117. package/src/components/resources/Organization/Organization.stories.js +15 -2
  118. package/src/components/resources/Organization/Organization.test.js +109 -1
  119. package/src/components/resources/Patient/Patient.js +4 -0
  120. package/src/components/resources/Patient/Patient.test.js +31 -2
  121. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  122. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  123. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  124. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +7 -0
  125. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  126. package/src/components/resources/Procedure/Procedure.js +3 -2
  127. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  128. package/src/components/resources/Questionnaire/Group.js +53 -0
  129. package/src/components/resources/Questionnaire/Items.js +45 -0
  130. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  131. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  132. package/src/components/resources/Questionnaire/Questionnaire.stories.js +8 -0
  133. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  134. package/src/components/resources/Questionnaire/Questions.js +40 -0
  135. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  136. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  137. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  138. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  139. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  140. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  141. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +8 -0
  142. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  143. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  144. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  145. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  146. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  147. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  148. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +46 -0
  149. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  150. package/src/components/resources/RelatedPerson/index.js +3 -0
  151. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  152. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +2 -0
  153. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  154. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  155. package/src/components/ui/index.js +56 -32
  156. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  157. package/src/fixtures/example-icons.jsx +63 -0
  158. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  159. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  160. package/src/style.scss +14 -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,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
68
70
  }
69
71
  };
70
72
 
71
- const ReferralRequest = props => {
72
- const { fhirResource, fhirVersion } = props;
73
+ const ReferralRequest = ({
74
+ fhirResource,
75
+ fhirVersion,
76
+ fhirIcons,
77
+ onClick,
78
+ rawOnClick,
79
+ }) => {
73
80
  let fhirResourceData = {};
74
81
  try {
75
82
  fhirResourceData = resourceDTO(fhirVersion, fhirResource);
@@ -87,45 +94,70 @@ const ReferralRequest = props => {
87
94
  description,
88
95
  } = fhirResourceData;
89
96
 
97
+ const tableData = [
98
+ {
99
+ testId: 'dateSent',
100
+ data: <Date fhirData={dateSent} isBlack />,
101
+ status: dateSent,
102
+ },
103
+ {
104
+ testId: 'subject',
105
+ data: <span>{subject}</span>,
106
+ status: subject,
107
+ },
108
+ {
109
+ testId: 'requester',
110
+ data: <span>{requester}</span>,
111
+ status: requester,
112
+ },
113
+ {
114
+ testId: 'status',
115
+ data: <span>{status}</span>,
116
+ status: status,
117
+ },
118
+ ];
119
+
90
120
  return (
91
121
  <Root name="ReferralRequest">
92
- <Body>
93
- {typeCoding && (
94
- <Value label="Type" data-testid="typeCoding">
95
- <Coding fhirData={typeCoding} />
96
- </Value>
97
- )}
98
- <div className="overflow-auto">
99
- <Table>
100
- <thead>
101
- <TableRow>
102
- <TableHeader>Request sent</TableHeader>
103
- <TableHeader>Patient</TableHeader>
104
- <TableHeader>Requester</TableHeader>
105
- <TableHeader>status</TableHeader>
106
- </TableRow>
107
- </thead>
108
- <tbody>
109
- <TableRow>
110
- <TableCell data-testid="dateSent">
111
- {dateSent ? <Date fhirData={dateSent} /> : <MissingValue />}
112
- </TableCell>
113
- <TableCell data-testid="subject">
114
- {subject ? <span>{subject}</span> : <MissingValue />}
115
- </TableCell>
116
- <TableCell data-testid="requester">
117
- {requester ? <span>{requester}</span> : <MissingValue />}
118
- </TableCell>
119
- <TableCell data-testid="status">
120
- {status ? <span>{status}</span> : <MissingValue />}
121
- </TableCell>
122
- </TableRow>
123
- </tbody>
124
- </Table>
125
- </div>
126
- {reason && <div data-testid="reason">{reason}</div>}
127
- {description && <small data-testid="description">{description}</small>}
128
- </Body>
122
+ <Accordion
123
+ headerContent={
124
+ <Header
125
+ resourceName="ReferralRequest"
126
+ title={typeCoding && <Coding fhirData={typeCoding} />}
127
+ icon={fhirIcons}
128
+ />
129
+ }
130
+ bodyContent={
131
+ <Body>
132
+ <Table>
133
+ <thead>
134
+ <TableRow>
135
+ <TableHeader>Request sent</TableHeader>
136
+ <TableHeader>Patient</TableHeader>
137
+ <TableHeader>Requester</TableHeader>
138
+ <TableHeader>Status</TableHeader>
139
+ </TableRow>
140
+ </thead>
141
+ <tbody className="border-top-0">
142
+ <TableRow>
143
+ {tableData.map((element, index) => (
144
+ <TableCell key={index} data-testid={element.testId}>
145
+ {element.status ? element.data : <MissingValue />}
146
+ </TableCell>
147
+ ))}
148
+ </TableRow>
149
+ </tbody>
150
+ </Table>
151
+ {description && (
152
+ <ValueSection label={reason} data-testid="reason" marginTop>
153
+ <small className="text-secondary">{description}</small>
154
+ </ValueSection>
155
+ )}
156
+ </Body>
157
+ }
158
+ onClick={onClick}
159
+ rawOnClick={rawOnClick}
160
+ />
129
161
  </Root>
130
162
  );
131
163
  };
@@ -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('typeCoding').textContent).toContain(
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('typeCoding').textContent).toContain(
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,158 @@
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 = ({
71
+ fhirResource,
72
+ fhirVersion,
73
+ fhirIcons,
74
+ onClick,
75
+ rawOnClick,
76
+ }) => {
77
+ let fhirResourceData = {};
78
+ try {
79
+ fhirResourceData = resourceDTO(fhirVersion, fhirResource);
80
+ } catch (error) {
81
+ console.warn(error.message);
82
+ return <UnhandledResourceDataStructure resourceName="RelatedPerson" />;
83
+ }
84
+
85
+ const {
86
+ patient,
87
+ name,
88
+ birthDate,
89
+ gender,
90
+ address,
91
+ relatedPersonTelecom,
92
+ } = fhirResourceData;
93
+
94
+ const tableData = [
95
+ {
96
+ label: 'Patient',
97
+ testId: 'patient',
98
+ data: patient && <Reference fhirData={patient} />,
99
+ status: patient,
100
+ },
101
+ {
102
+ label: 'Address',
103
+ testId: 'address',
104
+ data: address && <Address fhirData={address} />,
105
+ status: address,
106
+ },
107
+ {
108
+ label: 'Telephone',
109
+ testId: 'telephone',
110
+ data: !relatedPersonTelecom ? (
111
+ <MissingValue />
112
+ ) : (
113
+ relatedPersonTelecom.map((telecom, index) => (
114
+ <Telecom key={index} fhirData={telecom} />
115
+ ))
116
+ ),
117
+ status: relatedPersonTelecom,
118
+ },
119
+ ];
120
+
121
+ return (
122
+ <Root name="RelatedPerson">
123
+ <Accordion
124
+ headerContent={
125
+ <Header
126
+ resourceName="RelatedPerson"
127
+ additionalContent={
128
+ (birthDate || gender) && (
129
+ <span className="text-gray-600">
130
+ {gender && (
131
+ <span data-testid="gender" className="text-capitalize">
132
+ {gender || 'unknown'}
133
+ </span>
134
+ )}
135
+ {gender && birthDate && ', '}
136
+ {birthDate && (
137
+ <span data-testid="birthDate">{birthDate}</span>
138
+ )}
139
+ </span>
140
+ )
141
+ }
142
+ icon={fhirIcons}
143
+ title={<HumanName fhirData={name} isTitle />}
144
+ />
145
+ }
146
+ bodyContent={<Body tableData={tableData} />}
147
+ onClick={onClick}
148
+ rawOnClick={rawOnClick}
149
+ />
150
+ </Root>
151
+ );
152
+ };
153
+
154
+ RelatedPerson.propTypes = {
155
+ fhirResource: PropTypes.shape({}).isRequired,
156
+ };
157
+
158
+ 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
+ };