Skip to content

Commit 3a1da6e

Browse files
committed
RNGR-41 Minor fix and update test cases
1 parent c90d26a commit 3a1da6e

File tree

3 files changed

+137
-14
lines changed

3 files changed

+137
-14
lines changed

src/operations/common/resourcePreparer.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,41 @@ class ResourcePreparer {
4949
* @param {ParsedArgs} parsedArgs
5050
* @param {Resource} element
5151
* @param {string} resourceType
52+
* @param {boolean} rawResources
5253
* @return {Resource}
5354
*/
54-
selectSpecificElements ({ parsedArgs, element, resourceType }) {
55+
selectSpecificElements ({ parsedArgs, element, resourceType, rawResources = false }) {
5556
/**
5657
* @type {string[]|null}
5758
*/
5859
const properties_to_return_list = parsedArgs.get('_elements').queryParameterValue.values;
59-
/**
60-
* @type {Resource}
61-
*/
62-
const element_to_return = element.create({});
63-
if (properties_to_return_list) {
60+
61+
let element_to_return = null;
62+
63+
if (rawResources) {
64+
element_to_return = Object.keys(element)
65+
.filter((key) => properties_to_return_list.includes(key))
66+
.reduce((acc, key) => {
67+
acc[key] = element[key];
68+
return acc;
69+
}, {});
70+
element_to_return.resourceType = resourceType;
71+
}
72+
else {
6473
/**
65-
* @type {string}
74+
* @type {Resource}
6675
*/
67-
for (const property of properties_to_return_list) {
68-
if (property in element_to_return) {
69-
// for handling non-writable field 'resourceType'
70-
if (property !== 'resourceType') {
71-
element_to_return[`${property}`] = element[`${property}`];
76+
element_to_return = element.create({});
77+
if (properties_to_return_list) {
78+
/**
79+
* @type {string}
80+
*/
81+
for (const property of properties_to_return_list) {
82+
if (property in element_to_return) {
83+
// for handling non-writable field 'resourceType'
84+
if (property !== 'resourceType') {
85+
element_to_return[`${property}`] = element[`${property}`];
86+
}
7287
}
7388
}
7489
}
@@ -91,14 +106,15 @@ class ResourcePreparer {
91106
* @returns {Promise<Resource[]>}
92107
*/
93108
async prepareResourceAsync({ parsedArgs, element, resourceType, rawResources }) {
94-
if (parsedArgs.get('_elements') && !parsedArgs.get('_isGraphQLRequest') && !rawResources) {
109+
if (parsedArgs.get('_elements') && !parsedArgs.get('_isGraphQLRequest')) {
95110
/**
96111
* @type {Resource}
97112
*/
98113
element = this.selectSpecificElements({
99114
parsedArgs,
100115
element,
101-
resourceType
116+
resourceType,
117+
rawResources
102118
});
103119
}
104120
if (!parsedArgs.get('_elements') || parsedArgs.get('_isGraphQLRequest')) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
[
2+
{
3+
"author": [
4+
{
5+
"extension": [
6+
{
7+
"id": "sourceId",
8+
"url": "https://www.icanbwell.com/sourceId",
9+
"valueString": "Organization/078cf112-f802-4e4b-9b62-ed44cdf05d27"
10+
},
11+
{
12+
"id": "uuid",
13+
"url": "https://www.icanbwell.com/uuid",
14+
"valueString": "Organization/078cf112-f802-4e4b-9b62-ed44cdf05d27"
15+
},
16+
{
17+
"id": "sourceAssigningAuthority",
18+
"url": "https://www.icanbwell.com/sourceAssigningAuthority",
19+
"valueString": "bwell"
20+
}
21+
],
22+
"reference": "Organization/078cf112-f802-4e4b-9b62-ed44cdf05d27",
23+
"type": "Organization",
24+
"display": "bwell Connected Health"
25+
}
26+
],
27+
"id": "composition1",
28+
"subject": {
29+
"extension": [
30+
{
31+
"id": "sourceId",
32+
"url": "https://www.icanbwell.com/sourceId",
33+
"valueString": "Patient/e8cfea6f-7051-5c11-b306-b995e6f6adf0"
34+
},
35+
{
36+
"id": "uuid",
37+
"url": "https://www.icanbwell.com/uuid",
38+
"valueString": "Patient/e8cfea6f-7051-5c11-b306-b995e6f6adf0"
39+
},
40+
{
41+
"id": "sourceAssigningAuthority",
42+
"url": "https://www.icanbwell.com/sourceAssigningAuthority",
43+
"valueString": "bwell"
44+
}
45+
],
46+
"reference": "Patient/e8cfea6f-7051-5c11-b306-b995e6f6adf0",
47+
"type": "Patient"
48+
},
49+
"resourceType": "Composition"
50+
},
51+
{
52+
"author": [
53+
{
54+
"extension": [
55+
{
56+
"id": "sourceId",
57+
"url": "https://www.icanbwell.com/sourceId",
58+
"valueString": "Organization/enrichHashReference"
59+
},
60+
{
61+
"id": "uuid",
62+
"url": "https://www.icanbwell.com/uuid",
63+
"valueString": "Organization/d3ef9af3-b21f-58f5-b953-4f665ccc35f9"
64+
},
65+
{
66+
"id": "sourceAssigningAuthority",
67+
"url": "https://www.icanbwell.com/sourceAssigningAuthority",
68+
"valueString": "bwell"
69+
}
70+
],
71+
"reference": "Organization/enrichHashReference"
72+
}
73+
],
74+
"id": "composition2",
75+
"subject": {
76+
"extension": [
77+
{
78+
"id": "sourceId",
79+
"url": "https://www.icanbwell.com/sourceId",
80+
"valueString": "Patient/5c51ffc6-b79e-4d0c-8eca-216d9e1d2c30"
81+
},
82+
{
83+
"id": "uuid",
84+
"url": "https://www.icanbwell.com/uuid",
85+
"valueString": "Patient/5c51ffc6-b79e-4d0c-8eca-216d9e1d2c30"
86+
},
87+
{
88+
"id": "sourceAssigningAuthority",
89+
"url": "https://www.icanbwell.com/sourceAssigningAuthority",
90+
"valueString": "bwell"
91+
}
92+
],
93+
"reference": "Patient/5c51ffc6-b79e-4d0c-8eca-216d9e1d2c30",
94+
"type": "Patient"
95+
},
96+
"resourceType": "Composition"
97+
}
98+
]

src/tests/search/search.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const compositionResource2 = require('./fixtures/Composition/composition2.json')
99
const expectedCompositionResource = require('./fixtures/expected/expectedComposition.json');
1010
const expectedCompositionResourceWithHashReference = require('./fixtures/expected/expectedCompositionHashRef.json');
1111
const expectedCompositionResourceWithGlobalId = require('./fixtures/expected/expectedCompositionGlobalId.json');
12+
const expectedCompositionResourceWithElementsParam = require('./fixtures/expected/expectedCompositionWithElementsParam.json');
1213

1314
const { commonBeforeEach, commonAfterEach, getHeaders, createTestRequest } = require('../common');
1415

@@ -43,6 +44,10 @@ describe('Search list Tests', () => {
4344
// noinspection JSUnresolvedFunction
4445
expect(resp).toHaveResponse(expectedCompositionResource);
4546

47+
resp = await request.get('/4_0_0/Composition?_elements=author,id,subject').set(getHeaders());
48+
// noinspection JSUnresolvedFunction
49+
expect(resp).toHaveResponse(expectedCompositionResourceWithElementsParam);
50+
4651
// enrichers works for get list
4752
resp = await request
4853
.get('/4_0_0/Composition?_hash_references=true&_metaUuid=true')
@@ -82,6 +87,10 @@ describe('Search list Tests', () => {
8287
// noinspection JSUnresolvedFunction
8388
expect(resp).toHaveResponse(expectedCompositionResource);
8489

90+
resp = await request.get('/4_0_0/Composition?_elements=author,id,subject').set(getHeaders());
91+
// noinspection JSUnresolvedFunction
92+
expect(resp).toHaveResponse(expectedCompositionResourceWithElementsParam);
93+
8594
// enrichers works for get list
8695
resp = await request
8796
.get('/4_0_0/Composition?_hash_references=true&_metaUuid=true')

0 commit comments

Comments
 (0)