Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Added second call to API to get appliedConcept
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmydjabali committed Oct 7, 2021
1 parent 5c96240 commit e361e27
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions src/app/services/termSearchService.service.ts
Expand Up @@ -13,6 +13,7 @@ import { ExploreSearchService } from './api/medco-node/explore-search.service';
import { TreeNodeService } from './tree-node.service';
import { ErrorHelper } from '../utilities/error-helper';
import { DropMode } from '../models/drop-mode';
import { TreeNode } from '../models/tree-models/tree-node';

interface NodeFullPath {
name: string;
Expand Down Expand Up @@ -49,6 +50,43 @@ export class TermSearchService {
this.results = [];
}

addInResults(node: TreeNode, displayNameList: string[], searchConceptInfo?: TreeNode[]) {
const formattedResult = {
name: node.name,
fullPath: displayNameList.reverse().reduce((result, displayName) => [
...result, {
name: displayName,
isBold: !result.find(({ isBold }) => isBold) && displayName.toLowerCase().indexOf(this.termSearch.toLowerCase()) !== -1

}], []).reverse()
};
let resultIndex = -1;
if (!this.results.find(({ name: resultName }) => resultName === node.name)) { // Not found in this.results, add
resultIndex = this.results.push(formattedResult) - 1;
} else { // Found in this.results, replace
resultIndex = this.results.findIndex(({ name: resultName }) => resultName === node.name);
this.results[resultIndex] = formattedResult;
}
const dataObject = {
...node,
...(searchConceptInfo ? { appliedConcept: searchConceptInfo[0] } : {}),
dropMode: DropMode.TreeNode,
metadata: undefined,
path: `/I2B2${node.path}`,
isModifier: () => !!searchConceptInfo
};

setTimeout(() => {
const elems = document.querySelectorAll('.term-search p-accordionTab.ui-ontology-elements');
const elem = elems[resultIndex];
const handleDragstart = (function (event) {
event.stopPropagation();
this.treeNodeService.selectedTreeNode = dataObject;
}).bind(this);
elem.addEventListener('dragstart', handleDragstart);
}, 0);
}

search() {
this.exploreSearchService = this.injector.get(ExploreSearchService);

Expand All @@ -62,38 +100,13 @@ export class TermSearchService {
this.exploreSearchService.exploreSearchConceptInfo(value).subscribe((searchResult) => {
displayNameList[pathListIndex] = searchResult[0].displayName;
if (displayNameList.filter((_value) => !!_value).length === pathList.length) {
const formattedResult = {
name: node.name,
fullPath: displayNameList.reverse().reduce((result, displayName) => [
...result, {
name: displayName,
isBold: !result.find(({ isBold }) => isBold) && displayName.toLowerCase().indexOf(this.termSearch.toLowerCase()) !== -1
}], []).reverse()
};
let resultIndex = -1;
if (!this.results.find(({ name: resultName }) => resultName === node.name)) { // Not found in this.results, add
resultIndex = this.results.push(formattedResult) - 1;
} else { // Found in this.results, replace
resultIndex = this.results.findIndex(({ name: resultName }) => resultName === node.name);
this.results[resultIndex] = formattedResult;
if (node.nodeType.toLowerCase().indexOf('modifier') === -1) {
this.addInResults(node, displayNameList);
} else {
this.exploreSearchService.exploreSearchConceptInfo(`/I2B2${node.appliedPath}`).subscribe((searchConceptInfo) => {
this.addInResults(node, displayNameList, searchConceptInfo);
})
}
setTimeout(() => {
const elems = document.querySelectorAll('.term-search p-accordionTab.ui-ontology-elements');
const elem = elems[resultIndex];
const handleDragstart = (function (event) {
event.stopPropagation();
const dataObject = {
...node,
dropMode: DropMode.TreeNode,
metadata: undefined,
path: `/I2B2${node.path}`
};
console.log('dataObject', dataObject);
console.log('this.treeNodeService', this.treeNodeService);
this.treeNodeService.selectedTreeNode = dataObject;
}).bind(this);
elem.addEventListener('dragstart', handleDragstart);
}, 0);
}
});
});
Expand All @@ -104,14 +117,14 @@ export class TermSearchService {
}

onSearch() {
// this.search();
this.search();
}

onTermChange(event: any) {
this.results = [];
this.termSearch = event.target.value;
if (this.termSearch.length > 2) {
this.search();
// this.search();
}
}

Expand Down

0 comments on commit e361e27

Please sign in to comment.