fhir-react 0.3.12 → 1.0.0

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 (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/build/index.js +15 -16
  4. package/build/style.css +1 -1
  5. package/package.json +10 -10
  6. package/src/components/containers/Accordion/Accordion.js +5 -4
  7. package/src/components/containers/ResourceContainer/ResourceContainer.css +1 -3
  8. package/src/components/datatypes/Date/Date.js +1 -0
  9. package/src/components/datatypes/DatePeriod/DatePeriod.js +2 -2
  10. package/src/components/resources/AdverseEvent/AdverseEvent.test.js +2 -2
  11. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.js +17 -2
  12. package/src/components/resources/AllergyIntolerance/AllergyIntolerance.test.js +8 -4
  13. package/src/components/resources/CarePlan/CarePlan.test.js +4 -4
  14. package/src/components/resources/CareTeam/CareTeam.test.js +4 -4
  15. package/src/components/resources/Claim/Claim.test.js +6 -6
  16. package/src/components/resources/ClaimResponse/ClaimResponse.test.js +6 -6
  17. package/src/components/resources/Condition/Condition.js +25 -3
  18. package/src/components/resources/Condition/Condition.test.js +5 -5
  19. package/src/components/resources/DiagnosticReport/DiagnosticReport.test.js +4 -2
  20. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.js +3 -1
  21. package/src/components/resources/ExplanationOfBenefit/ExplanationOfBenefit.test.js +7 -7
  22. package/src/components/resources/Goal/Goal.test.js +2 -2
  23. package/src/components/resources/Immunization/Immunization.js +8 -2
  24. package/src/components/resources/MedicationAdministration/MedicationAdministration.test.js +7 -7
  25. package/src/components/resources/MedicationDispense/MedicationDispense.test.js +2 -2
  26. package/src/components/resources/MedicationRequest/MedicationRequest.test.js +4 -4
  27. package/src/components/resources/Observation/Observation.js +25 -3
  28. package/src/components/resources/Observation/Observation.test.js +2 -1
  29. package/src/components/resources/Patient/Patient.js +1 -1
  30. package/src/components/resources/Patient/Patient.test.js +6 -6
  31. package/src/components/resources/Procedure/Procedure.test.js +1 -1
  32. package/src/components/resources/QuestionnaireResponse/QuestionnaireResponse.test.js +4 -4
  33. package/src/components/resources/ResearchStudy/ResearchStudy.test.js +1 -1
  34. package/src/components/ui/index.js +5 -1
  35. package/src/fixtures/r4/resources/observation/example3.json +6 -1
  36. package/src/utils/formatDate.js +3 -0
  37. package/src/utils/formatDate.test.js +2 -2
  38. package/src/utils/getResourceDate.js +9 -0
@@ -11,6 +11,7 @@ import _get from 'lodash/get';
11
11
  import _has from 'lodash/has';
12
12
  import fhirVersions from '../fhirResourceVersions';
13
13
  import { Value } from '../../ui';
14
+ import { getResourceDate } from '../../../utils/getResourceDate';
14
15
 
15
16
  const commonDTO = fhirResource => {
16
17
  const title =
@@ -228,6 +229,11 @@ const Immunization = ({
228
229
  },
229
230
  ];
230
231
 
232
+ const immunizationDatesPaths = ['occurrenceDateTime'];
233
+
234
+ const headerDate =
235
+ getResourceDate(fhirResource, immunizationDatesPaths) || providedDate;
236
+
231
237
  return (
232
238
  <Root name="Immunization">
233
239
  <Accordion
@@ -235,9 +241,9 @@ const Immunization = ({
235
241
  <Header
236
242
  resourceName="Immunization"
237
243
  additionalContent={
238
- providedDate && (
244
+ headerDate && (
239
245
  <Value label="Start date" data-testid="headerStartDate">
240
- <Date fhirData={providedDate} isBlack />
246
+ <Date fhirData={headerDate} isBlack />
241
247
  </Value>
242
248
  )
243
249
  }
@@ -111,9 +111,9 @@ describe('should render MedicationAdministration component properly', () => {
111
111
  'Practitioner/example',
112
112
  );
113
113
 
114
- expect(getByTestId('periodTimeStart').textContent).toEqual('1/15/2015');
114
+ expect(getByTestId('periodTimeStart').textContent).toEqual('01/15/2015');
115
115
 
116
- expect(getByTestId('periodTimeEnd').textContent).toEqual('1/15/2015');
116
+ expect(getByTestId('periodTimeEnd').textContent).toEqual('01/15/2015');
117
117
 
118
118
  expect(getByTestId('dosageRoute').textContent).toContain(
119
119
  'Intravenous route',
@@ -139,7 +139,7 @@ describe('should render MedicationAdministration component properly', () => {
139
139
 
140
140
  expect(getByTestId('practitioner').textContent).toContain('Patrick Pump');
141
141
 
142
- expect(getByTestId('periodTimeStart').textContent).toEqual('1/15/2015');
142
+ expect(getByTestId('periodTimeStart').textContent).toEqual('01/15/2015');
143
143
 
144
144
  expect(getByTestId('periodTimeEnd').textContent).toEqual('-');
145
145
 
@@ -164,8 +164,8 @@ describe('should render MedicationAdministration component properly', () => {
164
164
  expect(getByTestId('status').textContent).toContain('on-hold');
165
165
  expect(getByTestId('patient').textContent).toContain('Donald Duck');
166
166
  expect(queryByTestId('practitioner')).toBeNull();
167
- expect(getByTestId('periodTimeStart').textContent).toEqual('1/15/2015');
168
- expect(getByTestId('periodTimeEnd').textContent).toEqual('1/15/2015');
167
+ expect(getByTestId('periodTimeStart').textContent).toEqual('01/15/2015');
168
+ expect(getByTestId('periodTimeEnd').textContent).toEqual('01/15/2015');
169
169
  expect(getByTestId('dosageRoute').textContent).toContain('-');
170
170
  expect(getByTestId('dosageQuantity').textContent).toEqual('-');
171
171
  });
@@ -184,8 +184,8 @@ describe('should render MedicationAdministration component properly', () => {
184
184
  expect(getByTestId('status').textContent).toContain('completed');
185
185
  expect(getByTestId('patient').textContent).toContain('Donald Duck');
186
186
  expect(getByTestId('practitioner').textContent).toContain('Patrick Pump');
187
- expect(getByTestId('periodTimeStart').textContent).toEqual('1/15/2015');
188
- expect(getByTestId('periodTimeEnd').textContent).toEqual('1/15/2015');
187
+ expect(getByTestId('periodTimeStart').textContent).toEqual('01/15/2015');
188
+ expect(getByTestId('periodTimeEnd').textContent).toEqual('01/15/2015');
189
189
  expect(getByTestId('dosageRoute').textContent).toContain('Oral Route');
190
190
  expect(getByTestId('dosageQuantity').textContent).toEqual('2 TAB');
191
191
  });
@@ -93,7 +93,7 @@ describe('should render Device component properly', () => {
93
93
 
94
94
  expect(getByTestId('title').textContent).toEqual('prescribed medication');
95
95
  expect(getByTestId('typeCoding').textContent).toContain('Part Fill');
96
- expect(getByTestId('whenPrepared').textContent).toContain('3/1/2015');
96
+ expect(getByTestId('whenPrepared').textContent).toContain('03/01/2015');
97
97
  expect(getByTestId('hasDosageInstruction').textContent).toContain(
98
98
  'or after food',
99
99
  );
@@ -132,7 +132,7 @@ describe('should render Device component properly', () => {
132
132
  expect(container).not.toBeNull();
133
133
 
134
134
  expect(getByTestId('title').textContent).toContain('Novolog 100u/ml');
135
- expect(getByTestId('whenPrepared').textContent).toEqual('1/15/2015');
135
+ expect(getByTestId('whenPrepared').textContent).toEqual('01/15/2015');
136
136
  expect(
137
137
  within(getByTestId('hasDosageInstruction'))
138
138
  .queryAllByTestId('dosageTiming')
@@ -95,7 +95,7 @@ describe('should render MedicationRequest component properly', () => {
95
95
  'Take one tablet',
96
96
  );
97
97
  expect(getByTestId('requester').textContent).toContain('Patrick Pump');
98
- expect(getByTestId('created').textContent).toEqual('3/1/2015');
98
+ expect(getByTestId('created').textContent).toEqual('03/01/2015');
99
99
  expect(getByTestId('intent').textContent).toEqual('order');
100
100
  });
101
101
  it('should render with STU3 source data in which medicationReference key does not exist', () => {
@@ -126,7 +126,7 @@ describe('should render MedicationRequest component properly', () => {
126
126
  'Take one tablet',
127
127
  );
128
128
  expect(getByTestId('requester').textContent).toContain('Patrick Pump');
129
- expect(getByTestId('created').textContent).toEqual('3/1/2015');
129
+ expect(getByTestId('created').textContent).toEqual('03/01/2015');
130
130
  expect(getByTestId('intent').textContent).toEqual('order');
131
131
  });
132
132
 
@@ -146,7 +146,7 @@ describe('should render MedicationRequest component properly', () => {
146
146
  'Take 4 tablets daily',
147
147
  );
148
148
  expect(getByTestId('requester').textContent).toContain('Patrick Pump');
149
- expect(getByTestId('created').textContent).toEqual('1/15/2015');
149
+ expect(getByTestId('created').textContent).toEqual('01/15/2015');
150
150
  expect(getByTestId('intent').textContent).toEqual('order');
151
151
  });
152
152
 
@@ -168,7 +168,7 @@ describe('should render MedicationRequest component properly', () => {
168
168
  '6 mg PO daily for remission',
169
169
  );
170
170
  expect(getByTestId('requester').textContent).toContain('Patrick Pump');
171
- expect(getByTestId('created').textContent).toEqual('1/15/2015');
171
+ expect(getByTestId('created').textContent).toEqual('01/15/2015');
172
172
  expect(getByTestId('intent').textContent).toEqual('order');
173
173
  });
174
174
 
@@ -17,6 +17,8 @@ import {
17
17
  Value,
18
18
  } from '../../ui';
19
19
  import Reference from '../../datatypes/Reference';
20
+ import { getResourceDate } from '../../../utils/getResourceDate';
21
+ import Annotation from "../../datatypes/Annotation";
20
22
 
21
23
  const Observation = ({
22
24
  fhirResource,
@@ -29,7 +31,7 @@ const Observation = ({
29
31
  const codeCodingDisplay = _get(fhirResource, 'code.coding.0.display');
30
32
  const codeText = _get(fhirResource, 'code.text', '');
31
33
  const valueQuantityValue = _get(fhirResource, 'valueQuantity.value', '');
32
- const issued = _get(fhirResource, 'issued', '');
34
+ // const issued = _get(fhirResource, 'issued', '');
33
35
  const valueQuantityUnit = _get(fhirResource, 'valueQuantity.unit', '');
34
36
  const status = _get(fhirResource, 'status', '');
35
37
  const valueCodeableConceptText = _get(
@@ -49,6 +51,9 @@ const Observation = ({
49
51
  let valueQuantityValueNumber = valueQuantityValue;
50
52
 
51
53
  const subject = _get(fhirResource, 'subject');
54
+ const note = _get(fhirResource, 'note');
55
+ const hasNote = Array.isArray(note);
56
+
52
57
  const tableData = [
53
58
  {
54
59
  label: 'Issued on',
@@ -70,8 +75,25 @@ const Observation = ({
70
75
  )),
71
76
  status: !_isEmpty(valueCodeableConceptCoding),
72
77
  },
78
+ {
79
+ label: 'Notes',
80
+ testId: 'hasNote',
81
+ data: hasNote && <Annotation fhirData={note} />,
82
+ status: hasNote,
83
+ },
73
84
  ];
74
85
 
86
+ const observationDatesPaths = [
87
+ 'effectiveDateTime',
88
+ 'effectivePeriod.start',
89
+ 'effectiveDateTime',
90
+ 'issued',
91
+ 'valuePeriod.start',
92
+ 'valueDateTime',
93
+ ];
94
+
95
+ const headerDate = getResourceDate(fhirResource, observationDatesPaths);
96
+
75
97
  return (
76
98
  <Root name="Observation">
77
99
  <Accordion
@@ -79,9 +101,9 @@ const Observation = ({
79
101
  <Header
80
102
  resourceName="Observation"
81
103
  additionalContent={
82
- issued && (
104
+ headerDate && (
83
105
  <Value label="Start date" data-testid="headerStartDate">
84
- <Date fhirData={issued} isBlack />
106
+ <Date fhirData={headerDate} isBlack />
85
107
  </Value>
86
108
  )
87
109
  }
@@ -129,9 +129,10 @@ describe('should render component correctly', () => {
129
129
  );
130
130
  expect(getByTestId('status').textContent).toEqual('final');
131
131
  expect(getByTestId('secondaryStatus').textContent).toEqual('YES');
132
- expect(getByTestId('issuedOn').textContent).toEqual('5/18/2016');
132
+ expect(getByTestId('issuedOn').textContent).toEqual('05/18/2016');
133
133
  expect(getByTestId('subject').textContent).toContain('Patient/infant');
134
134
  expect(queryByText(/373066001/g)).not.toBeNull();
135
+ expect(getByTestId('hasNote').textContent).toContain('Was exposed to second-hand smoke.');
135
136
  });
136
137
 
137
138
  test('should display not rounded value', () => {
@@ -132,7 +132,7 @@ function Patient(props) {
132
132
  {patientGender || 'unknown'}
133
133
  </span>
134
134
  {', '}
135
- <span data-testid="patientBirthDate">{patientBirthDate}</span>
135
+ <Date testId="patientBirthDate" fhirData={patientBirthDate} />
136
136
  </span>
137
137
  )
138
138
  }
@@ -88,7 +88,7 @@ describe('should render component correctly', () => {
88
88
  'Jason Argonaut (usual)',
89
89
  );
90
90
  expect(getByTestId('patientGender').textContent).toEqual('male');
91
- expect(getByTestId('patientBirthDate').textContent).toEqual('1985-08-01');
91
+ expect(getByTestId('patientBirthDate').textContent).toEqual('08/01/1985');
92
92
  expect(getByTestId('patientAddress').textContent).toEqual(
93
93
  '1979 Milky Way Dr.Verona, WI 53593 US',
94
94
  );
@@ -99,7 +99,7 @@ describe('should render component correctly', () => {
99
99
  expect(queryByTestId('deceasedInfo')).toBeNull();
100
100
  });
101
101
 
102
- test('DSTU3', () => {
102
+ test('STU3', () => {
103
103
  const defaultProps = {
104
104
  fhirResource: examplePatientSTU3,
105
105
  };
@@ -111,14 +111,14 @@ describe('should render component correctly', () => {
111
111
  'John, X Doe (usual)',
112
112
  );
113
113
  expect(getByTestId('patientGender').textContent).toEqual('male');
114
- expect(getByTestId('patientBirthDate').textContent).toEqual('2014-06-01');
114
+ expect(getByTestId('patientBirthDate').textContent).toEqual('06/01/2014');
115
115
  expect(getByTestId('patientAddress').textContent).toEqual(' 05 99999 ');
116
116
  expect(getByTestId('patientPhones').textContent).toEqual('-');
117
117
  expect(queryByTestId('activeStatus')).toBeNull();
118
118
  expect(queryByTestId('deceasedInfo')).toBeNull();
119
119
  });
120
120
 
121
- test('DSTU3 resource which contains communication key data', () => {
121
+ test('STU3 resource which contains communication key data', () => {
122
122
  const defaultProps = {
123
123
  fhirResource: example2PatientSTU3,
124
124
  };
@@ -138,7 +138,7 @@ describe('should render component correctly', () => {
138
138
  'Peter, James Chalmers (official)',
139
139
  );
140
140
  expect(getByTestId('patientGender').textContent).toEqual('male');
141
- expect(getByTestId('patientBirthDate').textContent).toEqual('1974-12-25');
141
+ expect(getByTestId('patientBirthDate').textContent).toEqual('12/25/1974');
142
142
  expect(getByTestId('patientAddress').textContent).toContain(
143
143
  'PleasantVille, Vic 3999',
144
144
  );
@@ -154,7 +154,7 @@ describe('should render component correctly', () => {
154
154
  fhirResource: example3PatientR4,
155
155
  };
156
156
  const { getByTestId } = render(<Patient {...defaultProps} />);
157
- expect(getByTestId('deceasedInfo').textContent).toEqual('2/14/2015');
157
+ expect(getByTestId('deceasedInfo').textContent).toEqual('02/14/2015');
158
158
  });
159
159
 
160
160
  it('should fire custom onClick function', () => {
@@ -131,7 +131,7 @@ describe('Procedure should render component correctly', () => {
131
131
  'Insertion of intracardiac pacemaker (procedure)',
132
132
  );
133
133
  expect(getByTestId('status').textContent).toEqual('completed');
134
- expect(getByTestId('providedDate').textContent).toEqual('4/5/2015');
134
+ expect(getByTestId('providedDate').textContent).toEqual('04/05/2015');
135
135
  expect(getByTestId('hasCoding').textContent).toContain(
136
136
  'Insertion of intracardiac',
137
137
  );
@@ -23,7 +23,7 @@ describe('QuestionnaireResponse should render component correctly', () => {
23
23
  'Questionnaire Response',
24
24
  );
25
25
  expect(getByTestId('status').textContent).toEqual('completed');
26
- expect(getByTestId('dateTime').textContent).toEqual('6/18/2013');
26
+ expect(getByTestId('dateTime').textContent).toEqual('06/18/2013');
27
27
  expect(getByTestId('subject').textContent).toEqual('Roel');
28
28
  expect(getByTestId('author').textContent).toEqual('Practitioner/f201');
29
29
 
@@ -34,7 +34,7 @@ describe('QuestionnaireResponse should render component correctly', () => {
34
34
  'What is your gender?Male ',
35
35
  );
36
36
  expect(getByTestId('linkId-2.2').textContent).toEqual(
37
- 'What is your date of birth?3/13/1960 ',
37
+ 'What is your date of birth?03/13/1960 ',
38
38
  );
39
39
  expect(getByTestId('linkId-2.3').textContent).toEqual(
40
40
  'What is your country of birth?The Netherlands ',
@@ -72,7 +72,7 @@ describe('QuestionnaireResponse should render component correctly', () => {
72
72
  'Questionnaire Response',
73
73
  );
74
74
  expect(getByTestId('status').textContent).toEqual('completed');
75
- expect(getByTestId('dateTime').textContent).toEqual('2/19/2013');
75
+ expect(getByTestId('dateTime').textContent).toEqual('02/19/2013');
76
76
 
77
77
  expect(getByTestId('answer-nameOfChild-0').textContent).toContain(
78
78
  'Cathy Jones',
@@ -90,7 +90,7 @@ describe('QuestionnaireResponse should render component correctly', () => {
90
90
  'Questionnaire Response',
91
91
  );
92
92
  expect(getByTestId('status').textContent).toEqual('completed');
93
- expect(getByTestId('dateTime').textContent).toEqual('6/18/2013');
93
+ expect(getByTestId('dateTime').textContent).toEqual('06/18/2013');
94
94
  expect(getByTestId('subject').textContent).toEqual('Roel');
95
95
  expect(getByTestId('author').textContent).toEqual('Practitioner/f201');
96
96
 
@@ -120,7 +120,7 @@ describe('should render ResearchStudy component properly', () => {
120
120
 
121
121
  expect(title).toEqual('Example study');
122
122
  expect(status).toEqual('completed');
123
- expect(period).toEqual('2/1/2015 - 2/21/2015');
123
+ expect(period).toEqual('02/01/2015 - 02/21/2015');
124
124
  expect(category).toEqual('Gene expression (GENE)');
125
125
  expect(focus).toEqual('Prostate cancer (PRC)');
126
126
  expect(protocol).toEqual('PlanDefinition/pdf1');
@@ -17,6 +17,7 @@ export const Header = ({
17
17
  children,
18
18
  capitalize = false,
19
19
  isNoIcon = false,
20
+ rawButton,
20
21
  }) => {
21
22
  const rightItemsClass = 'align-items-center flex-fill d-flex';
22
23
 
@@ -66,7 +67,7 @@ export const Header = ({
66
67
  </div>
67
68
  )}
68
69
  </div>
69
- {(additionalContent || rightAdditionalContent) && (
70
+ {additionalContent || rightAdditionalContent ? (
70
71
  <div
71
72
  className={`fhir-ui__${resourceName}-Header__additional-content w-100 justify-content-start d-flex ${
72
73
  additionalContent ? ' pt-2' : ''
@@ -77,8 +78,11 @@ export const Header = ({
77
78
  className={`fhir-ui__${resourceName}-Header__rightAdditionalContent justify-content-md-end mx-0 ${rightItemsClass}`}
78
79
  >
79
80
  {rightAdditionalContent}
81
+ {rawButton}
80
82
  </div>
81
83
  </div>
84
+ ) : (
85
+ <div className="d-flex justify-content-end">{rawButton}</div>
82
86
  )}
83
87
  </div>
84
88
  )}
@@ -46,5 +46,10 @@
46
46
  }
47
47
  ],
48
48
  "text": "YES"
49
- }
49
+ },
50
+ "note": [
51
+ {
52
+ "text": "Was exposed to second-hand smoke."
53
+ }
54
+ ]
50
55
  }
@@ -18,6 +18,9 @@ const whichOptions = date => {
18
18
  };
19
19
  }
20
20
  return {
21
+ day: '2-digit',
22
+ month: '2-digit',
23
+ year: 'numeric',
21
24
  timeZone: 'UTC',
22
25
  };
23
26
  };
@@ -13,10 +13,10 @@ describe('Date format function', () => {
13
13
  });
14
14
  it('should return US date format', () => {
15
15
  const date = '2021-03-14';
16
- expect(formatDate(date, locale)).toEqual('3/14/2021');
16
+ expect(formatDate(date, locale)).toEqual('03/14/2021');
17
17
  });
18
18
  it('should return US date format given full timestamp', () => {
19
19
  const date = '2021-03-14T13:28:17-05:00';
20
- expect(formatDate(date, locale)).toEqual('3/14/2021');
20
+ expect(formatDate(date, locale)).toEqual('03/14/2021');
21
21
  });
22
22
  });
@@ -0,0 +1,9 @@
1
+ import _get from 'lodash/get';
2
+
3
+ export const getResourceDate = (resource, paths) => {
4
+ return paths?.reduce((acc, path) => {
5
+ const dataTemp = _get(resource, path);
6
+ if (dataTemp && !acc) acc = dataTemp;
7
+ return acc;
8
+ }, null);
9
+ };