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.
Files changed (179) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.eslintrc +10 -1
  3. package/.storybook/main.js +5 -0
  4. package/.storybook/manager.js +6 -0
  5. package/.storybook/preview.js +7 -0
  6. package/.stylelintrc +6 -2
  7. package/README.md +19 -1
  8. package/build/index.js +15 -11
  9. package/build/style.css +9 -9
  10. package/package.json +59 -57
  11. package/src/assets/containers/AdverseEvent/adverse-event.svg +6 -0
  12. package/src/assets/containers/Generic/generic.svg +3 -0
  13. package/src/assets/containers/MedicationDispense/medication-dispense.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/Accordion/Accordion.stories.js +74 -58
  19. package/src/components/containers/ResourceContainer/ResourceContainer.css +4 -0
  20. package/src/components/containers/ResourceContainer/ResourceContainer.js +28 -37
  21. package/src/components/containers/ResourceContainer/ResourceContainer.stories.js +46 -22
  22. package/src/components/datatypes/CodeableConcept/CodeableConcept.js +6 -3
  23. package/src/components/datatypes/Coding/Coding.js +7 -3
  24. package/src/components/datatypes/Reference/Reference.js +7 -5
  25. package/src/components/datatypes/Telecom/Telecom.js +2 -3
  26. package/src/components/defaultArgTypes.js +12 -0
  27. package/src/components/resources/AdverseEvent/AdverseEvent.js +88 -42
  28. package/src/components/resources/AdverseEvent/AdverseEvent.stories.js +19 -11
  29. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +109 -2
  30. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +9 -1
  31. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.stories.js +46 -70
  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.stories.js +51 -62
  35. package/src/components/resources/Appointment/Appointment.test.js +36 -1
  36. package/src/components/resources/Binary/Binary.js +2 -1
  37. package/src/components/resources/Binary/Binary.stories.js +27 -21
  38. package/src/components/resources/Bundle/Bundle.css +7 -0
  39. package/src/components/resources/Bundle/Bundle.js +15 -11
  40. package/src/components/resources/Bundle/Bundle.stories.js +59 -115
  41. package/src/components/resources/Bundle/Bundle.test.js +0 -3
  42. package/src/components/resources/CarePlan/CarePlan.js +9 -1
  43. package/src/components/resources/CarePlan/CarePlan.stories.js +44 -54
  44. package/src/components/resources/CarePlan/CarePlan.test.js +42 -6
  45. package/src/components/resources/CareTeam/CareTeam.js +79 -50
  46. package/src/components/resources/CareTeam/CareTeam.stories.js +25 -14
  47. package/src/components/resources/CareTeam/CareTeam.test.js +109 -1
  48. package/src/components/resources/CareTeam/CareTeamParticipants.js +1 -1
  49. package/src/components/resources/Claim/Claim.js +9 -1
  50. package/src/components/resources/Claim/Claim.stories.js +36 -49
  51. package/src/components/resources/Claim/Claim.test.js +32 -1
  52. package/src/components/resources/ClaimResponse/AddedItem.js +61 -11
  53. package/src/components/resources/ClaimResponse/AddedItems.js +5 -9
  54. package/src/components/resources/ClaimResponse/ClaimResponse.js +144 -83
  55. package/src/components/resources/ClaimResponse/ClaimResponse.stories.js +44 -41
  56. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +112 -1
  57. package/src/components/resources/ClaimResponse/Item.js +44 -9
  58. package/src/components/resources/ClaimResponse/Items.js +5 -4
  59. package/src/components/resources/Condition/Condition.js +10 -3
  60. package/src/components/resources/Condition/Condition.stories.js +47 -62
  61. package/src/components/resources/Condition/Condition.test.js +37 -4
  62. package/src/components/resources/Coverage/Coverage.js +9 -1
  63. package/src/components/resources/Coverage/Coverage.stories.js +38 -50
  64. package/src/components/resources/Coverage/Coverage.test.js +36 -1
  65. package/src/components/resources/Device/Device.js +9 -1
  66. package/src/components/resources/Device/Device.stories.js +40 -52
  67. package/src/components/resources/Device/Device.test.js +36 -1
  68. package/src/components/resources/DiagnosticReport/DiagnosticReport.js +9 -2
  69. package/src/components/resources/DiagnosticReport/DiagnosticReport.stories.js +38 -50
  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.stories.js +25 -29
  73. package/src/components/resources/DocumentReference/DocumentReference.test.js +42 -1
  74. package/src/components/resources/Encounter/Encounter.js +9 -1
  75. package/src/components/resources/Encounter/Encounter.stories.js +43 -59
  76. package/src/components/resources/Encounter/Encounter.test.js +36 -1
  77. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +4 -0
  78. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.stories.js +53 -67
  79. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +38 -1
  80. package/src/components/resources/ExplanationOfBenefitGraph/ExplanationOfBenefitGraph.stories.js +74 -38
  81. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.js +9 -2
  82. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.stories.js +22 -28
  83. package/src/components/resources/FamilyMemberHistory/FamilyMemberHistory.test.js +36 -1
  84. package/src/components/resources/Generic/Generic.js +21 -7
  85. package/src/components/resources/Generic/Generic.stories.js +22 -12
  86. package/src/components/resources/Generic/Generic.test.js +26 -7
  87. package/src/components/resources/Goal/Goal.js +9 -3
  88. package/src/components/resources/Goal/Goal.stories.js +35 -49
  89. package/src/components/resources/Goal/Goal.test.js +32 -1
  90. package/src/components/resources/Immunization/Immunization.js +9 -2
  91. package/src/components/resources/Immunization/Immunization.stories.js +38 -51
  92. package/src/components/resources/Immunization/Immunization.test.js +36 -1
  93. package/src/components/resources/List/DrugTierDefinitionExtension.js +79 -35
  94. package/src/components/resources/List/Entries.js +3 -3
  95. package/src/components/resources/List/List.js +137 -88
  96. package/src/components/resources/List/List.stories.js +69 -40
  97. package/src/components/resources/List/List.test.js +105 -1
  98. package/src/components/resources/Location/Location.js +66 -47
  99. package/src/components/resources/Location/Location.stories.js +25 -13
  100. package/src/components/resources/Location/Location.test.js +106 -4
  101. package/src/components/resources/Medication/Medication.js +9 -1
  102. package/src/components/resources/Medication/Medication.stories.js +42 -64
  103. package/src/components/resources/Medication/Medication.test.js +36 -1
  104. package/src/components/resources/MedicationAdministration/MedicationAdministration.js +88 -62
  105. package/src/components/resources/MedicationAdministration/MedicationAdministration.stories.js +34 -41
  106. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +117 -1
  107. package/src/components/resources/MedicationDispense/DosageInstruction.js +25 -0
  108. package/src/components/resources/MedicationDispense/MedicationDispense.js +70 -68
  109. package/src/components/resources/MedicationDispense/MedicationDispense.stories.js +41 -52
  110. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +108 -1
  111. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.js +117 -66
  112. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.stories.js +51 -54
  113. package/src/components/resources/MedicationKnowledge/MedicationKnowledge.test.js +110 -1
  114. package/src/components/resources/MedicationOrder/MedicationOrder.js +3 -3
  115. package/src/components/resources/MedicationOrder/MedicationOrder.stories.js +11 -4
  116. package/src/components/resources/MedicationOrder/MedicationOrder.test.js +35 -4
  117. package/src/components/resources/MedicationRequest/MedicationRequest.js +8 -1
  118. package/src/components/resources/MedicationRequest/MedicationRequest.stories.js +27 -30
  119. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +33 -4
  120. package/src/components/resources/MedicationStatement/MedicationStatement.js +9 -2
  121. package/src/components/resources/MedicationStatement/MedicationStatement.stories.js +32 -46
  122. package/src/components/resources/MedicationStatement/MedicationStatement.test.js +36 -1
  123. package/src/components/resources/Observation/Observation.js +3 -1
  124. package/src/components/resources/Observation/Observation.stories.js +39 -33
  125. package/src/components/resources/Observation/Observation.test.js +30 -1
  126. package/src/components/resources/Observation/ObservationGraph.js +1 -1
  127. package/src/components/resources/Organization/Organization.js +10 -2
  128. package/src/components/resources/Organization/Organization.stories.js +40 -52
  129. package/src/components/resources/Organization/Organization.test.js +36 -1
  130. package/src/components/resources/Patient/Patient.js +4 -0
  131. package/src/components/resources/Patient/Patient.stories.js +36 -28
  132. package/src/components/resources/Patient/Patient.test.js +31 -2
  133. package/src/components/resources/Practitioner/Practitioner.js +9 -1
  134. package/src/components/resources/Practitioner/Practitioner.stories.js +39 -52
  135. package/src/components/resources/Practitioner/Practitioner.test.js +36 -1
  136. package/src/components/resources/PractitionerRole/PractitionerRole.js +52 -29
  137. package/src/components/resources/PractitionerRole/PractitionerRole.stories.js +45 -58
  138. package/src/components/resources/PractitionerRole/PractitionerRole.test.js +108 -1
  139. package/src/components/resources/Procedure/Procedure.js +3 -2
  140. package/src/components/resources/Procedure/Procedure.stories.js +33 -25
  141. package/src/components/resources/Procedure/Procedure.test.js +30 -1
  142. package/src/components/resources/Questionnaire/Group.js +53 -0
  143. package/src/components/resources/Questionnaire/Items.js +45 -0
  144. package/src/components/resources/Questionnaire/Questionnaire.css +24 -5
  145. package/src/components/resources/Questionnaire/Questionnaire.js +38 -170
  146. package/src/components/resources/Questionnaire/Questionnaire.stories.js +50 -57
  147. package/src/components/resources/Questionnaire/Questionnaire.test.js +194 -15
  148. package/src/components/resources/Questionnaire/Questions.js +40 -0
  149. package/src/components/resources/Questionnaire/getQuestionText.js +20 -0
  150. package/src/components/resources/QuestionnaireResponse/Answers.js +59 -0
  151. package/src/components/resources/QuestionnaireResponse/Group.js +70 -0
  152. package/src/components/resources/QuestionnaireResponse/Items.js +45 -0
  153. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.css +33 -8
  154. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.js +54 -236
  155. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.stories.js +46 -58
  156. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +38 -3
  157. package/src/components/resources/QuestionnaireResponse/Questions.js +43 -0
  158. package/src/components/resources/QuestionnaireResponse/getQuestionText.js +22 -0
  159. package/src/components/resources/ReferralRequest/ReferralRequest.js +72 -40
  160. package/src/components/resources/ReferralRequest/ReferralRequest.stories.js +20 -20
  161. package/src/components/resources/ReferralRequest/ReferralRequest.test.js +111 -11
  162. package/src/components/resources/RelatedPerson/RelatedPerson.js +158 -0
  163. package/src/components/resources/RelatedPerson/RelatedPerson.stories.js +42 -0
  164. package/src/components/resources/RelatedPerson/RelatedPerson.test.js +156 -0
  165. package/src/components/resources/RelatedPerson/index.js +3 -0
  166. package/src/components/resources/ResearchStudy/ResearchStudy.js +167 -130
  167. package/src/components/resources/ResearchStudy/ResearchStudy.stories.js +18 -14
  168. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +108 -1
  169. package/src/components/resources/ResourceCategory/ResourceCategory.js +1 -1
  170. package/src/components/resources/ResourceCategory/ResourceCategory.stories.js +40 -27
  171. package/src/components/ui/index.js +48 -31
  172. package/src/fixtures/dstu2/resources/relatedPerson/example1.json +79 -0
  173. package/src/fixtures/example-icons.jsx +42 -0
  174. package/src/fixtures/r4/resources/relatedPerson/example1.json +64 -0
  175. package/src/fixtures/stu3/resources/relatedPerson/example1.json +43 -0
  176. package/src/style.scss +14 -1
  177. package/.storybook/addons.js +0 -1
  178. package/.storybook/config.js +0 -26
  179. package/.storybook/presets.js +0 -1
@@ -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,5 +1,5 @@
1
1
  import React from 'react';
2
- import { object } from '@storybook/addon-knobs';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
3
3
 
4
4
  import ReferralRequest from './ReferralRequest';
5
5
 
@@ -9,29 +9,29 @@ import fhirVersions from '../fhirResourceVersions';
9
9
 
10
10
  export default {
11
11
  title: 'ReferralRequest',
12
+ component: ReferralRequest,
13
+ argTypes: {
14
+ ...defaultArgTypes,
15
+ },
12
16
  };
13
17
 
14
- export const DefaultVisualizationDSTU2 = () => {
15
- const fhirResource = object('Resource', dstu2Example1);
16
- return (
17
- <ReferralRequest
18
- fhirVersion={fhirVersions.DSTU2}
19
- fhirResource={fhirResource}
20
- />
21
- );
18
+ const Template = args => <ReferralRequest {...args} />;
19
+
20
+ export const DefaultVisualizationDSTU2 = Template.bind({});
21
+ DefaultVisualizationDSTU2.args = {
22
+ fhirVersion: fhirVersions.DSTU2,
23
+ fhirResource: dstu2Example1,
24
+ fhirIcons: require('../../../assets/containers/ReferralRequest/referral-request.svg'),
22
25
  };
23
26
 
24
- export const ExampleOfSTU3 = () => {
25
- const fhirResource = object('Resource', stu3Example1);
26
- return (
27
- <ReferralRequest
28
- fhirVersion={fhirVersions.STU3}
29
- fhirResource={fhirResource}
30
- />
31
- );
27
+ export const ExampleOfSTU3 = Template.bind({});
28
+ ExampleOfSTU3.args = {
29
+ fhirVersion: fhirVersions.STU3,
30
+ fhirResource: stu3Example1,
31
+ fhirIcons: false,
32
32
  };
33
33
 
34
- export const ExampleWithoutFhirVersionProperty = () => {
35
- const fhirResource = object('Resource', stu3Example1);
36
- return <ReferralRequest fhirResource={fhirResource} />;
34
+ export const ExampleWithoutFhirVersionProperty = Template.bind({});
35
+ ExampleWithoutFhirVersionProperty.args = {
36
+ fhirResource: stu3Example1,
37
37
  };
@@ -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,42 @@
1
+ import React from 'react';
2
+ import { defaultArgTypes } from '../../defaultArgTypes';
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 {
14
+ title: 'RelatedPerson',
15
+ component: RelatedPerson,
16
+ argTypes: {
17
+ ...defaultArgTypes,
18
+ },
19
+ };
20
+
21
+ const Template = args => <RelatedPerson {...args} />;
22
+
23
+ export const ExampleDSTU2 = Template.bind({});
24
+ ExampleDSTU2.args = {
25
+ fhirVersion: fhirVersions.DSTU2,
26
+ fhirResource: exampleDSTU2,
27
+ fhirIcons: fhirIcons,
28
+ };
29
+
30
+ export const ExampleSTU3 = Template.bind({});
31
+ ExampleSTU3.args = {
32
+ fhirVersion: fhirVersions.STU3,
33
+ fhirResource: exampleSTU3,
34
+ fhirIcons: false,
35
+ };
36
+
37
+ export const ExampleR4 = Template.bind({});
38
+ ExampleR4.args = {
39
+ fhirVersion: fhirVersions.R4,
40
+ fhirResource: exampleR4,
41
+ fhirIcons: 'random text',
42
+ };