Skip to content

Commit

Permalink
feat: skip special bundle parameters of chain search
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Sep 16, 2023
1 parent 7d9eae2 commit bb393cf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 28 deletions.
41 changes: 31 additions & 10 deletions api/FHIRApiService/search/chain-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ function checkIsChainAndGetChainParent(resourceType, param) {

let chainRefResourceList = [];

if (resourceType === "Bundle" &&
(param.startsWith("composition") || param.startsWith("message"))) {

let paramPath = paramSplit.slice(0, 2).join(".");
paramSplit = [paramPath, ...paramSplit.slice(2)];
}

// 1. Check the first parameter present in string
// 1.1 Must be parameter of resource type.
// 2. Record every reference resourceType
Expand All @@ -153,12 +160,28 @@ function checkIsChainAndGetChainParent(resourceType, param) {
if (!paramType) return { status: false };
else if (paramType !== "reference") return { status: false };

let paramRefResources = resourceIncludeRef[resourceType].find((v) =>
paramsSearchFields[firstParam][0].startsWith(v.path)
).resourceList;
let paramRefResources;

if (resourceType === "Bundle") {
if (firstParam.startsWith("composition")) {
let compositionFirstParam = firstParam.split(".")[1];
paramRefResources = resourceIncludeRef["Composition"].find((v) =>
v.path.startsWith(compositionFirstParam)
).resourceList;
} else if (firstParam.startsWith("message")) {
let messageFirstParam = firstParam.split(".")[1];
paramRefResources = resourceIncludeRef["MessageHeader"].find((v) =>
v.path.startsWith(messageFirstParam)
).resourceList;
}
} else {
paramRefResources = resourceIncludeRef[resourceType].find((v) =>
paramsSearchFields[firstParam][0].startsWith(v.path)
).resourceList;
}

if (selfParam.includes(":")) {
if (!paramRefResources.includes(specificResource))
if (!paramRefResources.includes(specificResource) && !paramRefResources.includes("Resource"))
return { status: false };
else paramRefResources = [specificResource];
}
Expand Down Expand Up @@ -215,9 +238,8 @@ function getChainParentJoinQuery(chainParent, value) {
pipeline.push({
$unwind: {
path: hasParent
? `$stage${i - 1}Ref${
parent.parent
}-${previousKey}.${v}`
? `$stage${i - 1}Ref${parent.parent
}-${previousKey}.${v}`
: `\$${v}`,
preserveNullAndEmptyArrays: true
}
Expand All @@ -232,9 +254,8 @@ function getChainParentJoinQuery(chainParent, value) {
refId: {
$substr: [
hasParent
? `$stage${i - 1}Ref${
parent.parent
}-${previousKey}.${parent.field}`
? `$stage${i - 1}Ref${parent.parent
}-${previousKey}.${parent.field}`
: `\$${parent.field}`,
parent.resource.length + 1,
-1
Expand Down
44 changes: 26 additions & 18 deletions api/FHIRApiService/search/searchParameterCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,34 @@ class SearchParameterCreator {

for (let key in this.query) {
try {
if (key.includes(".")) {
let isChain = checkIsChainAndGetChainParent(
this.resourceType,
key
);
if (isChain.status) {
this.query["isChain"] = true;
let splitDotLength = key.split(".").length;
if (splitDotLength >= 2) {
if ((key.startsWith("composition") || key.startsWith("message")) &&
splitDotLength === 2) {

let joinQuery = getChainParentJoinQuery(
isChain.chainParent,
this.query[key]
);
this.paramsSearch[key](this.query);

if (!_.get(this.query, "chain"))
this.query["chain"] = [];
this.query["chain"] = [
...this.query["chain"],
joinQuery
];
delete this.query[key];
} else {
let isChain = checkIsChainAndGetChainParent(
this.resourceType,
key
);
if (isChain.status) {
this.query["isChain"] = true;

let joinQuery = getChainParentJoinQuery(
isChain.chainParent,
this.query[key]
);

if (!_.get(this.query, "chain"))
this.query["chain"] = [];
this.query["chain"] = [
...this.query["chain"],
joinQuery
];
delete this.query[key];
}
}
} else {
this.paramsSearch[key](this.query);
Expand Down

0 comments on commit bb393cf

Please sign in to comment.