Skip to content

Commit

Permalink
feat: add general string query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 28, 2022
1 parent a3a761b commit 7cb186e
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
10 changes: 9 additions & 1 deletion models/FHIR/queryBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ function stringExact(str) {
return str;
}


/**
*
* @param {string} item The query value
* @param {string} type postfix of field e.g. field of parameter of phone in Patient is `telecom` but use query value with `telecom.value`
* @param {string} field
* @param {string} required The fixed system e.g. phone is telecom and email is email
* @param {*} isCodeableConcept if is codeable concept
* @returns
*/
function tokenQuery(item, type, field, required , isCodeableConcept = false) {
let queryBuilder = {};
let system = "";
Expand Down
33 changes: 33 additions & 0 deletions models/FHIR/searchParameterQueryBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const queryBuild = require('./queryBuild');
const _ = require('_');

function getStringQuery(query, paramsSearchFields, queryFieldName) {
if (!_.isArray(query[queryFieldName])) {
query[queryFieldName] = [query[queryFieldName]];
}
for (let item of query[queryFieldName]) {
let buildQs = {
$or: []
};
for (let field of paramsSearchFields[queryFieldName]) {
let buildResult = queryBuild.stringQuery(item, field);
buildQs.$or = [...buildQs.$or, ...buildResult.$or];
}
query.$and.push({
...buildQs
});
}
delete query[queryFieldName];
}

function getFixedTokenQuery() {

}

function getTokenQuery(query, paramsSearchFields, queryFieldName) {

}

module.exports = {
getStringQuery: getStringQuery
};
81 changes: 81 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node ./build/init.js",
"release": "standard-version",
"lint" : "eslint --ignore-path .gitignore ."
"lint": "eslint --ignore-path .gitignore ."
},
"standard-version": {
"skip": {
Expand Down Expand Up @@ -47,6 +47,7 @@
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"passport-local": "^1.0.0",
"query-string": "^7.1.0",
"rootpath": "^0.1.2",
"uid-generator": "^2.0.0",
"uuid": "^8.3.2",
Expand Down

0 comments on commit 7cb186e

Please sign in to comment.