From 9bf9f11962944490e5c2d1b6fb243925564b0d5e Mon Sep 17 00:00:00 2001 From: Jon Lee Date: Thu, 29 Nov 2018 11:26:55 -0500 Subject: [PATCH 1/2] Adding _count as a common search parameter. --- src/server/profiles/common.arguments.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/profiles/common.arguments.js b/src/server/profiles/common.arguments.js index 477a8afb7..eae39415d 100644 --- a/src/server/profiles/common.arguments.js +++ b/src/server/profiles/common.arguments.js @@ -106,6 +106,12 @@ module.exports.common_args = { type: 'token', definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', documentation: undefined + }, + _COUNT: { + name: '_count', + type: 'number', + definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', + documentation: undefined } }; From f48f1957a60cdfe0eee30ce5c35004aa3378cd5d Mon Sep 17 00:00:00 2001 From: Jon Lee Date: Mon, 3 Dec 2018 10:48:38 -0500 Subject: [PATCH 2/2] Adding additional test case and additional args --- src/server/profiles/common.arguments.js | 30 ++++++++++--- src/server/utils/sanitize.utils.test.js | 60 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/src/server/profiles/common.arguments.js b/src/server/profiles/common.arguments.js index eae39415d..8d732d559 100644 --- a/src/server/profiles/common.arguments.js +++ b/src/server/profiles/common.arguments.js @@ -40,6 +40,18 @@ module.exports.write_args = { * @description Common arguments used for search */ module.exports.search_args = { + _SORT: { + name: '_sort', + type: 'string', + definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', + documentation: undefined + }, + _COUNT: { + name: '_count', + type: 'number', + definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', + documentation: undefined + }, _INCLUDE: { name: '_include', type: 'string', @@ -51,6 +63,18 @@ module.exports.search_args = { type: 'string', definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', documentation: undefined + }, + _SUMMARY: { + name: '_summary', + type: 'token', + definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', + documentation: undefined + }, + _ELEMENTS: { + name: '_elements', + type: 'string', + definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', + documentation: undefined } }; @@ -107,11 +131,5 @@ module.exports.common_args = { definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', documentation: undefined }, - _COUNT: { - name: '_count', - type: 'number', - definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource', - documentation: undefined - } }; diff --git a/src/server/utils/sanitize.utils.test.js b/src/server/utils/sanitize.utils.test.js index 10bf3f767..61c61a4ab 100644 --- a/src/server/utils/sanitize.utils.test.js +++ b/src/server/utils/sanitize.utils.test.js @@ -29,6 +29,33 @@ const ARGS = [ } ]; +const SEARCH_ARGS = [ + { + name: '_sort', + type: 'string' + }, + { + name: '_count', + type: 'number' + }, + { + name: '_include', + type: 'string' + }, + { + name: '_revinclude', + type: 'string' + }, + { + name: '_summary', + type: 'token' + }, + { + name: '_elements', + type: 'string' + }, +]; + const REQUIRED_ARGS = [ { name: 'id', @@ -214,4 +241,37 @@ describe('Sanitize Utils Tests', () => { expect(issue.diagnostics).toEqual('age is invalid'); }); + test('should allow all common search args', () => { + + let middleware = sanitizeMiddleware(SEARCH_ARGS); + let params = { _sort: 'status', _count: '1', _include: 'Observation', _revinclude: 'Patient', _summary: 'text', _elements: 'identifier' }; + let req = { params: Object.assign(params, ARGS_PARAM) }; + let next = jest.fn(); + + // invoke our middleware + middleware(req, null, next); + + // console log error so easier to find + if (next && next.mock.calls[0][0]) { + let nextArg = next.mock.calls[0][0]; + console.log(nextArg.issue[0]); + } + + // Inspect params and make sure they are the correct type + let { _sort, _count, _include, _revinclude, _summary, _elements } = req.sanitized_args; + + expect(typeof _sort).toEqual('string'); + expect(typeof _count).toEqual('number'); + expect(typeof _include).toEqual('string'); + expect(typeof _revinclude).toEqual('string'); + expect(typeof _summary).toEqual('string'); + expect(typeof _elements).toEqual('string'); + + // Make sure next was called but without an error + expect(next).toHaveBeenCalled(); + // This should be the argument next would be invoked with + // calls[0] is the first set of arguments, calls[0][0] is the first argument + expect(next.mock.calls[0][0]).toBeUndefined(); + }); + });