Skip to content

Commit

Permalink
feat: support ? match any single character
Browse files Browse the repository at this point in the history
- Refactoring get wildcard query
  • Loading branch information
Chinlinlee committed Apr 24, 2023
1 parent 52519bf commit 3845e38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,24 @@ function commaValue(iKey, iValue) {
return $or;
}

async function wildCardFirst(iValue) {
return new Promise((resolve) => {
iValue = iValue.replace(/\*/gi, ".*");
return resolve(new RegExp(iValue, "gi"));
});
}
async function wildCard(iValue) {
return new Promise((resolve) => {
iValue = "^" + iValue;
iValue = iValue.replace(/\*/gi, ".*");
return resolve(new RegExp(iValue, "gi"));
});
/**
*
* @param {string} value
* @returns
*/
function getWildCardQuery(value) {
let wildCardIndex = value.indexOf("*");
let questionIndex = value.indexOf("?");

if (wildCardIndex >= 0 || questionIndex >= 0) {
value = value.replace(/\*/gm, ".*");
value = value.replace(/\?/gm, ".");
value = value.replace(/\^/gm, "\\^");
value = "^" + value;
return new RegExp(value, "gm");
}

return value;
}

/**
Expand All @@ -218,15 +224,7 @@ async function convertRequestQueryToMongoQuery(iQuery) {
let value = commaValue(nowKey, iQuery[nowKey]);
for (let x = 0; x < value.length; x++) {
let nowValue = value[x][nowKey];
let wildCardFunc = {};
wildCardFunc[nowValue.indexOf("*")] = wildCard;
wildCardFunc["0"] = wildCardFirst;
wildCardFunc["-1"] = (value) => {
return value;
};
value[x][nowKey] = await wildCardFunc[nowValue.indexOf("*")](
nowValue
);
value[x][nowKey] = getWildCardQuery(nowValue);

try {
let keySplit = nowKey.split(".");
Expand Down
Binary file not shown.

0 comments on commit 3845e38

Please sign in to comment.