Skip to content

Commit

Permalink
Merge pull request #105 from Asymmetrik/feature/common-args
Browse files Browse the repository at this point in the history
Adding additional common search parameters.
  • Loading branch information
jonterrylee authored Dec 3, 2018
2 parents f0a9719 + f48f195 commit ac5462e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/server/profiles/common.arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
}
};

Expand Down Expand Up @@ -106,6 +130,6 @@ module.exports.common_args = {
type: 'token',
definition: 'https://www.hl7.org/fhir/searchparameter-registry.html#resource',
documentation: undefined
}
},
};

60 changes: 60 additions & 0 deletions src/server/utils/sanitize.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
});

});

0 comments on commit ac5462e

Please sign in to comment.