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
@@ -14,8 +14,7 @@ import _has from 'lodash/has';
14
14
  import { isNotEmptyArray } from '../../../utils';
15
15
  import { Value } from '../../ui';
16
16
 
17
- const Procedure = props => {
18
- const { fhirResource, fhirIcons } = props;
17
+ const Procedure = ({ fhirResource, fhirIcons, onClick, rawOnClick }) => {
19
18
  const display =
20
19
  _get(fhirResource, 'code.coding[0].display') ||
21
20
  _get(fhirResource, 'code.text');
@@ -125,6 +124,8 @@ const Procedure = props => {
125
124
  />
126
125
  }
127
126
  bodyContent={<Body tableData={tableData} />}
127
+ onClick={onClick}
128
+ rawOnClick={rawOnClick}
128
129
  />
129
130
  </Root>
130
131
  );
@@ -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 Procedure from './Procedure';
5
5
 
@@ -14,39 +14,47 @@ import r4Example3 from '../../../fixtures/r4/resources/procedure/example3.json';
14
14
  import fhirIcons from '../../../fixtures/example-icons';
15
15
  import ProcedureIcon from '../../../assets/containers/Procedure/procedure.svg';
16
16
 
17
- export default { title: 'Procedure' };
17
+ export default {
18
+ title: 'Procedure',
19
+ component: Procedure,
20
+ argTypes: {
21
+ ...defaultArgTypes,
22
+ },
23
+ };
24
+
25
+ const Template = args => <Procedure {...args} />;
18
26
 
19
- export const DefaultVisualizationDSTU2 = () => {
20
- const fhirResource = object('Resource', example1);
21
- return (
22
- <Procedure
23
- fhirResource={fhirResource}
24
- fhirIcons={require('../../../assets/containers/Procedure/procedure.svg')}
25
- />
26
- );
27
+ export const DefaultVisualizationDSTU2 = Template.bind({});
28
+ DefaultVisualizationDSTU2.args = {
29
+ fhirResource: example1,
30
+ fhirIcons: require('../../../assets/containers/Procedure/procedure.svg'),
27
31
  };
28
32
 
29
- export const ExampleOfSTU3 = () => {
30
- const fhirResource = object('Resource', stu3Example1);
31
- return <Procedure fhirResource={fhirResource} fhirIcons={ProcedureIcon} />;
33
+ export const ExampleOfSTU3 = Template.bind({});
34
+ ExampleOfSTU3.args = {
35
+ fhirResource: stu3Example1,
36
+ fhirIcons: ProcedureIcon,
32
37
  };
33
38
 
34
- export const Example2OfSTU3 = () => {
35
- const fhirResource = object('Resource', stu3Example2);
36
- return <Procedure fhirResource={fhirResource} fhirIcons={fhirIcons} />;
39
+ export const Example2OfSTU3 = Template.bind({});
40
+ Example2OfSTU3.args = {
41
+ fhirResource: stu3Example2,
42
+ fhirIcons: fhirIcons,
37
43
  };
38
44
 
39
- export const Example1OfR4 = () => {
40
- const fhirResource = object('Resource', r4Example1);
41
- return <Procedure fhirResource={fhirResource} fhirIcons={false} />;
45
+ export const Example1OfR4 = Template.bind({});
46
+ Example1OfR4.args = {
47
+ fhirResource: r4Example1,
48
+ fhirIcons: false,
42
49
  };
43
50
 
44
- export const Example2OfR4 = () => {
45
- const fhirResource = object('Resource', r4Example2);
46
- return <Procedure fhirResource={fhirResource} fhirIcons={'random text'} />;
51
+ export const Example2OfR4 = Template.bind({});
52
+ Example2OfR4.args = {
53
+ fhirResource: r4Example2,
54
+ fhirIcons: 'random text',
47
55
  };
48
56
 
49
- export const Example3OfR4 = () => {
50
- const fhirResource = object('Resource', r4Example3);
51
- return <Procedure fhirResource={fhirResource} />;
57
+ export const Example3OfR4 = Template.bind({});
58
+ Example3OfR4.args = {
59
+ fhirResource: r4Example3,
52
60
  };
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import dstu2Example1 from '../../../fixtures/dstu2/resources/procedure/example1.json';
4
4
  import r4Example2 from '../../../fixtures/r4/resources/procedure/example2.json';
5
5
  import r4Example3 from '../../../fixtures/r4/resources/procedure/example3.json';
6
- import { render } from '@testing-library/react';
6
+ import { fireEvent, render } from '@testing-library/react';
7
7
  import stu3Example1 from '../../../fixtures/stu3/resources/procedure/example1.json';
8
8
  import fhirIcons from '../../../fixtures/example-icons';
9
9
  import fhirVersions from '../fhirResourceVersions';
@@ -168,4 +168,33 @@ describe('Procedure should render component correctly', () => {
168
168
  'Eerste neo-adjuvante',
169
169
  );
170
170
  });
171
+
172
+ it('should fire custom onClick function', () => {
173
+ const defaultProps = { fhirResource: r4Example3 };
174
+
175
+ const onClick = jest.fn();
176
+ const { getByRole } = render(
177
+ <Procedure {...defaultProps} onClick={onClick} />,
178
+ );
179
+ const accordion = getByRole('button');
180
+ fireEvent.click(accordion);
181
+
182
+ const attribute = accordion.getAttribute('data-bs-toggle');
183
+ expect(attribute).not.toEqual('collapse');
184
+ expect(onClick).toHaveBeenCalled();
185
+ });
186
+
187
+ it('should not fire custom onClick function', () => {
188
+ const defaultProps = { fhirResource: r4Example3 };
189
+
190
+ const onClick = 'test';
191
+ const { getByRole } = render(
192
+ <Procedure {...defaultProps} onClick={onClick} />,
193
+ );
194
+ const accordion = getByRole('button');
195
+ fireEvent.click(accordion);
196
+
197
+ const attribute = accordion.getAttribute('data-bs-toggle');
198
+ expect(attribute).toEqual('collapse');
199
+ });
171
200
  });
@@ -0,0 +1,53 @@
1
+ import _get from 'lodash/get';
2
+ import { MissingValue } from '../../ui';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+ import Questions from './Questions';
6
+ import { getQuestionText } from './getQuestionText';
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 text = getQuestionText(item);
15
+ let nestedItems = _get(item, 'item', []);
16
+ nestedItems = nestedItems.map(prepareItems);
17
+ const isGroup = _get(item, 'isGroup');
18
+ return (
19
+ <ul
20
+ key={`questionnaire-item-${i}`}
21
+ className="fhir-resource__Questionnaire-list"
22
+ >
23
+ <li
24
+ className={
25
+ isChild
26
+ ? 'fhir-resource__Questionnaire-list-title-question'
27
+ : 'fhir-resource__Questionnaire-list-title'
28
+ }
29
+ data-testid={`linkId-${item.linkId}`}
30
+ >
31
+ {text ? text : <MissingValue />}
32
+ </li>
33
+ {!isGroup && (
34
+ <li>
35
+ <Questions questions={nestedItems} prepareItems={prepareItems} />
36
+ </li>
37
+ )}
38
+ {isGroup && (
39
+ <li>
40
+ <Group data={nestedItems} prepareItems={prepareItems} isChild />
41
+ </li>
42
+ )}
43
+ </ul>
44
+ );
45
+ });
46
+ };
47
+
48
+ Group.propTypes = {
49
+ data: PropTypes.array,
50
+ prepareItems: PropTypes.func.isRequired,
51
+ };
52
+
53
+ 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
+ ...item,
11
+ item: _get(item, 'question') || _get(item, 'group') || [],
12
+ isGroup: !!_get(item, 'group'),
13
+ });
14
+ return <Group data={data} prepareItems={prepareItems} />;
15
+ }
16
+
17
+ if (fhirVersion === fhirVersions.STU3) {
18
+ const prepareItems = item => ({
19
+ ...item,
20
+ isGroup: _get(item, 'type') === 'group',
21
+ });
22
+ return <Group data={data} prepareItems={prepareItems} />;
23
+ }
24
+
25
+ if (fhirVersion === fhirVersions.R4) {
26
+ const prepareItems = item => ({
27
+ ...item,
28
+ isGroup: _get(item, 'type') === 'group',
29
+ });
30
+ return <Group data={data} prepareItems={prepareItems} />;
31
+ }
32
+
33
+ return null;
34
+ };
35
+
36
+ Items.propTypes = {
37
+ data: PropTypes.array,
38
+ fhirVersion: PropTypes.oneOf([
39
+ fhirVersions.DSTU2,
40
+ fhirVersions.STU3,
41
+ fhirVersions.R4,
42
+ ]).isRequired,
43
+ };
44
+
45
+ export default Items;
@@ -1,21 +1,41 @@
1
1
  .fhir-resource__Questionnaire-list {
2
2
  list-style: none;
3
- border: 1px solid #f0f0f0;
4
3
  padding: 2px;
5
4
  margin: 2px;
6
5
  }
7
6
 
8
7
  .fhir-resource__Questionnaire-list-title {
9
- background-color: #f6f6f6;
10
- padding: 2px 2px 4px 2px;
8
+ padding: 2px 2px 8px 2px;
9
+ font-weight: bold;
10
+ }
11
+
12
+ .fhir-resource__Questionnaire-list-title-question {
13
+ background: #f8f9fa;
14
+ align-items: center;
15
+ margin-bottom: 56px;
16
+ padding-left: 16px;
17
+ border-radius: 4px;
18
+ color: #adb5bd;
11
19
  }
12
20
 
13
21
  .fhir-resource__Questionnaire-questions-list {
14
22
  list-style: none;
23
+ padding-left: 0;
24
+ display: block;
25
+ color: #adb5bd;
15
26
  }
16
27
 
17
28
  .fhir-resource__Questionnaire-questions-list li {
18
- border-bottom: 1px solid #f5f5f5;
29
+ display: block;
30
+ margin-bottom: 56px;
31
+ }
32
+
33
+ .fhir-resource__Questionnaire-questions-list-element {
34
+ background: #f8f9fa;
35
+ border-radius: 4px;
36
+ width: 100%;
37
+ padding-left: 16px;
38
+ margin-bottom: 56px;
19
39
  }
20
40
 
21
41
  .fhir-resource__Questionnaire-questions-list li:last-child {
@@ -24,7 +44,6 @@
24
44
 
25
45
  .fhir-resource__Questionnaire-questions-list-item-details {
26
46
  font-size: 80%;
27
- color: #606060;
28
47
  }
29
48
 
30
49
  .fhir-resource__Questionnaire-questions-list-item-details-el {
@@ -2,164 +2,15 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import _get from 'lodash/get';
4
4
 
5
- import { Root, Header, Title, Badge, BadgeSecondary, Body } from '../../ui';
5
+ import { Root, Header, Badge, Body, Value } from '../../ui';
6
6
  import Date from '../../datatypes/Date';
7
7
  import Coding from '../../datatypes/Coding';
8
8
 
9
9
  import './Questionnaire.css';
10
- import Reference from '../../datatypes/Reference/Reference';
11
10
  import fhirVersions from '../fhirResourceVersions';
12
11
  import UnhandledResourceDataStructure from '../UnhandledResourceDataStructure';
13
-
14
- const getQuestionText = item => {
15
- let text = _get(item, 'text');
16
- if (!text) {
17
- // DSTU2
18
- const groupConcept = _get(item, 'concept.0');
19
- if (groupConcept) {
20
- text = <Coding fhirData={groupConcept} />;
21
- }
22
- // STU3 & R4
23
- const groupCode = _get(item, 'code.0');
24
- if (!text && groupCode) {
25
- text = <Coding fhirData={groupCode} />;
26
- }
27
- }
28
- return text;
29
- };
30
-
31
- const Questions = props => {
32
- const { questions, prepareItems } = props;
33
- if (!Array.isArray(questions) || questions.length === 0) {
34
- return null;
35
- }
36
-
37
- return (
38
- <ul className="fhir-resource__Questionnaire-questions-list">
39
- {questions.map((item, i) => {
40
- const hasLinkId = item.linkId;
41
- let type = _get(item, 'type');
42
- if (type === 'group') {
43
- type = '';
44
- }
45
- const options = _get(item, 'options');
46
-
47
- const text = getQuestionText(item);
48
- const hasDetails = type || options;
49
- return (
50
- <li key={`item-${i}`} data-testid={`linkId-${item.linkId}`}>
51
- {hasLinkId && <Badge>{item.linkId}</Badge>}
52
- {text}
53
- {hasDetails && (
54
- <div className="fhir-resource__Questionnaire-questions-list-item-details">
55
- {type && (
56
- <div className="fhir-resource__Questionnaire-questions-list-item-details-el">
57
- Type: {type}
58
- </div>
59
- )}
60
- {options && (
61
- <div className="fhir-resource__Questionnaire-questions-list-item-details-el">
62
- Options: <Reference fhirData={options} />
63
- </div>
64
- )}
65
- </div>
66
- )}
67
- {item.item && (
68
- <Group data={item.item} prepareItems={prepareItems} />
69
- )}
70
- </li>
71
- );
72
- })}
73
- </ul>
74
- );
75
- };
76
-
77
- Questions.propTypes = {
78
- questions: PropTypes.array,
79
- prepareItems: PropTypes.func.isRequired,
80
- };
81
-
82
- const Group = props => {
83
- const { data, prepareItems } = props;
84
- if (!Array.isArray(data) || data.length === 0) {
85
- return null;
86
- }
87
-
88
- return data.map(prepareItems).map((item, i) => {
89
- const linkId = _get(item, 'linkId', '');
90
-
91
- const text = getQuestionText(item);
92
- let nestedItems = _get(item, 'item', []);
93
- nestedItems = nestedItems.map(prepareItems);
94
- const isGroup = _get(item, 'isGroup');
95
- return (
96
- <ul key={`item-${i}`} className="fhir-resource__Questionnaire-list">
97
- <li
98
- className="fhir-resource__Questionnaire-list-title"
99
- data-testid={`linkId-${item.linkId}`}
100
- >
101
- <Badge>{linkId}</Badge>
102
- <span>{text}</span>
103
- </li>
104
- {!isGroup && (
105
- <li>
106
- {<Questions questions={nestedItems} prepareItems={prepareItems} />}
107
- </li>
108
- )}
109
- {isGroup && (
110
- <li>
111
- <Group data={nestedItems} prepareItems={prepareItems} />
112
- </li>
113
- )}
114
- </ul>
115
- );
116
- });
117
- };
118
-
119
- Group.propTypes = {
120
- data: PropTypes.array,
121
- prepareItems: PropTypes.func.isRequired,
122
- };
123
-
124
- const Items = props => {
125
- const { fhirVersion, data } = props;
126
-
127
- if (fhirVersion === fhirVersions.DSTU2) {
128
- const prepareItems = item => ({
129
- ...item,
130
- item: _get(item, 'question') || _get(item, 'group') || [],
131
- isGroup: !!_get(item, 'group'),
132
- });
133
- return <Group data={data} prepareItems={prepareItems} />;
134
- }
135
-
136
- if (fhirVersion === fhirVersions.STU3) {
137
- const prepareItems = item => ({
138
- ...item,
139
- isGroup: _get(item, 'type') === 'group',
140
- });
141
- return <Group data={data} prepareItems={prepareItems} />;
142
- }
143
-
144
- if (fhirVersion === fhirVersions.R4) {
145
- const prepareItems = item => ({
146
- ...item,
147
- isGroup: _get(item, 'type') === 'group',
148
- });
149
- return <Group data={data} prepareItems={prepareItems} />;
150
- }
151
-
152
- return null;
153
- };
154
-
155
- Items.propTypes = {
156
- data: PropTypes.array,
157
- fhirVersion: PropTypes.oneOf([
158
- fhirVersions.DSTU2,
159
- fhirVersions.STU3,
160
- fhirVersions.R4,
161
- ]).isRequired,
162
- };
12
+ import Items from './Items';
13
+ import Accordion from '../../containers/Accordion';
163
14
 
164
15
  const commonDTO = fhirResource => {
165
16
  const status = _get(fhirResource, 'status');
@@ -224,8 +75,13 @@ const resourceDTO = (fhirVersion, fhirResource) => {
224
75
  }
225
76
  };
226
77
 
227
- const Questionnaire = props => {
228
- const { fhirResource, fhirVersion } = props;
78
+ const Questionnaire = ({
79
+ fhirResource,
80
+ fhirVersion,
81
+ fhirIcons,
82
+ onClick,
83
+ rawOnClick,
84
+ }) => {
229
85
  let fhirResourceData = {};
230
86
 
231
87
  try {
@@ -238,22 +94,34 @@ const Questionnaire = props => {
238
94
 
239
95
  return (
240
96
  <Root name="Questionnaire">
241
- <Header>
242
- <Title>{title}</Title>
243
- {status && <Badge data-testid="status">{status}</Badge>}
244
- {dateTime && (
245
- <BadgeSecondary data-testid="dateTime">
246
- <Date fhirData={dateTime} />
247
- </BadgeSecondary>
248
- )}
249
- </Header>
250
- <Body>
251
- {rootItems && (
252
- <div className="overflow-auto">
253
- <Items fhirVersion={fhirVersion} data={rootItems} />
254
- </div>
255
- )}
256
- </Body>
97
+ <Accordion
98
+ headerContent={
99
+ <Header
100
+ resourceName="Questionnaire"
101
+ title={title}
102
+ badges={status && <Badge data-testid="status">{status}</Badge>}
103
+ additionalContent={
104
+ dateTime && (
105
+ <Value label="On" data-testid="dateTime">
106
+ <Date fhirData={dateTime} isBlack />
107
+ </Value>
108
+ )
109
+ }
110
+ icon={fhirIcons}
111
+ />
112
+ }
113
+ bodyContent={
114
+ <Body>
115
+ {rootItems && (
116
+ <div className="overflow-auto">
117
+ <Items fhirVersion={fhirVersion} data={rootItems} />
118
+ </div>
119
+ )}
120
+ </Body>
121
+ }
122
+ onClick={onClick}
123
+ rawOnClick={rawOnClick}
124
+ />
257
125
  </Root>
258
126
  );
259
127
  };
@@ -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 Questionnaire from './Questionnaire';
5
5
  import fhirVersions from '../fhirResourceVersions';
@@ -15,75 +15,68 @@ import r4Example1 from '../../../fixtures/r4/resources/questionnaire/example1.js
15
15
  import r4Example2 from '../../../fixtures/r4/resources/questionnaire/example2.json';
16
16
  import r4Example3 from '../../../fixtures/r4/resources/questionnaire/example3.json';
17
17
 
18
- export default { title: 'Questionnaire' };
18
+ import fhirIcons from '../../../fixtures/example-icons';
19
+ import QuestionnaireIcon from '../../../assets/containers/Questionnaire/questionnaire.svg';
19
20
 
20
- export const DefaultVisualizationDSTU2 = () => {
21
- const fhirResource = object('Resource', dstu2Example1);
22
- return (
23
- <Questionnaire
24
- fhirResource={fhirResource}
25
- fhirVersion={fhirVersions.DSTU2}
26
- />
27
- );
21
+ export default {
22
+ title: 'Questionnaire',
23
+ component: Questionnaire,
24
+ argTypes: {
25
+ ...defaultArgTypes,
26
+ },
28
27
  };
29
28
 
30
- export const Example2OfDSTU2 = () => {
31
- const fhirResource = object('Resource', dstu2Example2);
32
- return (
33
- <Questionnaire
34
- fhirResource={fhirResource}
35
- fhirVersion={fhirVersions.DSTU2}
36
- />
37
- );
29
+ const Template = args => <Questionnaire {...args} />;
30
+
31
+ export const DefaultVisualizationDSTU2 = Template.bind({});
32
+ DefaultVisualizationDSTU2.args = {
33
+ fhirVersion: fhirVersions.DSTU2,
34
+ fhirResource: dstu2Example1,
35
+ fhirIcons: require('../../../assets/containers/Questionnaire/questionnaire.svg'),
36
+ };
37
+
38
+ export const Example2OfDSTU2 = Template.bind({});
39
+ Example2OfDSTU2.args = {
40
+ fhirVersion: fhirVersions.DSTU2,
41
+ fhirResource: dstu2Example2,
42
+ fhirIcons: QuestionnaireIcon,
38
43
  };
39
44
 
40
- export const Example3OfDSTU2 = () => {
41
- const fhirResource = object('Resource', dstu2Example3);
42
- return (
43
- <Questionnaire
44
- fhirResource={fhirResource}
45
- fhirVersion={fhirVersions.DSTU2}
46
- />
47
- );
45
+ export const Example3OfDSTU2 = Template.bind({});
46
+ Example3OfDSTU2.args = {
47
+ fhirVersion: fhirVersions.DSTU2,
48
+ fhirResource: dstu2Example3,
49
+ fhirIcons: fhirIcons,
48
50
  };
49
51
 
50
- export const Example1OfSTU3 = () => {
51
- const fhirResource = object('Resource', stu3Example1);
52
- return (
53
- <Questionnaire
54
- fhirResource={fhirResource}
55
- fhirVersion={fhirVersions.STU3}
56
- />
57
- );
52
+ export const Example1OfSTU3 = Template.bind({});
53
+ Example1OfSTU3.args = {
54
+ fhirVersion: fhirVersions.STU3,
55
+ fhirResource: stu3Example1,
56
+ fhirIcons: false,
58
57
  };
59
58
 
60
- export const Example2OfSTU3 = () => {
61
- const fhirResource = object('Resource', stu3Example2);
62
- return (
63
- <Questionnaire
64
- fhirResource={fhirResource}
65
- fhirVersion={fhirVersions.STU3}
66
- />
67
- );
59
+ export const Example2OfSTU3 = Template.bind({});
60
+ Example2OfSTU3.args = {
61
+ fhirVersion: fhirVersions.STU3,
62
+ fhirResource: stu3Example2,
63
+ fhirIcons: 'random text',
68
64
  };
69
65
 
70
- export const Example1OfR4 = () => {
71
- const fhirResource = object('Resource', r4Example1);
72
- return (
73
- <Questionnaire fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
74
- );
66
+ export const Example1OfR4 = Template.bind({});
67
+ Example1OfR4.args = {
68
+ fhirVersion: fhirVersions.R4,
69
+ fhirResource: r4Example1,
75
70
  };
76
71
 
77
- export const Example2OfR4 = () => {
78
- const fhirResource = object('Resource', r4Example2);
79
- return (
80
- <Questionnaire fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
81
- );
72
+ export const Example2OfR4 = Template.bind({});
73
+ Example2OfR4.args = {
74
+ fhirVersion: fhirVersions.R4,
75
+ fhirResource: r4Example2,
82
76
  };
83
77
 
84
- export const Example3OfR4 = () => {
85
- const fhirResource = object('Resource', r4Example3);
86
- return (
87
- <Questionnaire fhirResource={fhirResource} fhirVersion={fhirVersions.R4} />
88
- );
78
+ export const Example3OfR4 = Template.bind({});
79
+ Example3OfR4.args = {
80
+ fhirVersion: fhirVersions.R4,
81
+ fhirResource: r4Example3,
89
82
  };