Skip to content

Commit

Permalink
feat: isic-display-ui add hierarchical diagnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
volishevko committed Nov 28, 2024
1 parent 9f88d81 commit 642925d
Show file tree
Hide file tree
Showing 19 changed files with 5,777 additions and 358 deletions.
6 changes: 6 additions & 0 deletions sources/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,10 @@ export default {
MULTI_LESION_TYPE_PRIORITY: {
FIRST: "dermoscopic"
},
DIAGNOSIS_SEPARATOR: ":",
FILTER_ELEMENT_TYPE: {
CHECKBOX: "checkbox",
TREE_CHECKBOX: "treeCheckbox",
RANGE_CHECKBOX: "rangeCheckbox",
},
};
28 changes: 27 additions & 1 deletion sources/models/appliedFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function prepareDataForList() {
switch (filter.view) {
case "checkbox":
case "rangeCheckbox":
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX:
{
result.push(webix.copy(filter));
break;
Expand Down Expand Up @@ -83,6 +84,7 @@ function processNewFilter(filter) {
switch (filter.view) {
case "checkbox":
case "rangeCheckbox":
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX:
{
let checkboxId = util.getOptionId(filter.key, filter.optionId ?? filter.value);
if (filter.remove) {
Expand Down Expand Up @@ -356,6 +358,20 @@ function _groupFiltersByKey() {
});
break;
}
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX: {
let itemFromResult = result.find(comparedItem => comparedItem.key === `${item.key}_${item.diagnosisLevel}`, true);
if (!itemFromResult) {
itemFromResult = {
view: item.view,
key: `${item.key}_${item.diagnosisLevel}`,
datatype: item.datatype,
values: []
};
result.push(itemFromResult);
}
itemFromResult.values.push(_prepareOptionNameForApi(item.value, `${item.key}_${item.diagnosisLevel}`));
break;
}
default:
{
break;
Expand All @@ -369,6 +385,7 @@ function _prepareCondition(filter) {
let result = [];
switch (filter.view) {
case "checkbox":
case constants.FILTER_ELEMENT_TYPE.TREE_CHECKBOX:
{
_prepareValuesCondition(filter, result);
break;
Expand Down Expand Up @@ -473,6 +490,14 @@ function convertAppliedFiltersToParams() {
return JSON.stringify(getFiltersArray().map(filter => filter.id));
}

function getAppliedCollectionsForApi() {
const filtersArray = getFiltersArray();
const appliedCollections = filtersArray
.filter(filter => filter.key === constants.COLLECTION_KEY);
const result = appliedCollections.map(collection => collection.optionId);
return result.length > 0 ? result.join(",") : "";
}

export default {
getFiltersArray,
processNewFilters,
Expand All @@ -489,7 +514,8 @@ export default {
getFilterValue,
getShowedFiltersCollection,
getFiltersFromURL,
convertAppliedFiltersToParams
convertAppliedFiltersToParams,
getAppliedCollectionsForApi,
};

// TODO: rewrite example
Expand Down
42 changes: 0 additions & 42 deletions sources/models/collectionsModel.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import constants from "../constants";
import filtersModel from "./appliedFilters";

const allCollections = [];
let allCollectionsNextLink = null;
let allCollectionsPrevLink = null;
const pinnedCollections = [];
let pinnedCollectionsNextLink = null;
let pinnedCollectionsPrevLink = null;

function getAllCollections() {
return allCollections;
}

function getAllCollectionsNextLink() {
return allCollectionsNextLink;
}

function getAllCollectionsPrevLink() {
return allCollectionsPrevLink;
}

function setAllCollectionsData(collectionsData) {
allCollections.push(...collectionsData.results);
allCollectionsNextLink = collectionsData.next;
allCollectionsPrevLink = collectionsData.previous;
}

function clearAllCollections() {
allCollections.length = 0;
}

function getPinnedCollections() {
return pinnedCollections;
}
Expand Down Expand Up @@ -59,25 +31,11 @@ function updateCollections(buckets) {
});
}

function getAppliedCollectionsForApi() {
const appliedFilters = filtersModel.getFiltersArray();
const appliedCollections = appliedFilters
.filter(filter => filter.key === constants.COLLECTION_KEY);
const result = appliedCollections.map(collection => collection.optionId);
return result.length > 0 ? result.join(",") : "";
}

export default {
getAllCollections,
getAllCollectionsNextLink,
getAllCollectionsPrevLink,
setAllCollectionsData,
clearAllCollections,
getPinnedCollections,
getPinnedCollectionsNextLink,
getPinnedCollectionsPrevLink,
setPinnedCollections,
clearPinnedCollections,
updateCollections,
getAppliedCollectionsForApi
};
122 changes: 122 additions & 0 deletions sources/models/diagnosis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* @typedef {Object} Diagnosis
* @property {number} level
* @property {string | null} parent
* @property {string} concatenate
* @property {Array | null} children
*/
import diagnosisFlat from "./iddx-flat.json";
import diagnosisTree from "./iddx-tree.json";

const CONCATENATE_SEPARATOR = "::";
const diagnosisArray = [];
const displayDiagnosis = [];

function getDiagnosisFlat() {
return diagnosisFlat;
}

function getDiagnosisDataForFilters() {
const data = convertDiagnosisToTreeArray(diagnosisTree);
return data;
}

function convertDiagnosisToTreeArray(tree) {
const dataForFilters = [];
const diagnosisKeys = Object.keys(tree);
diagnosisKeys.forEach((k) => {
const diagnosisItem = {};
diagnosisItem.id = diagnosisFlat[k].concatenate.replaceAll(CONCATENATE_SEPARATOR, "|");
diagnosisItem.name = k;
diagnosisItem.type = "treeCheckbox";
diagnosisItem.datatype = "string";
diagnosisItem.level = diagnosisFlat[k].level;
diagnosisItem.data = diagnosisFlat[k].children
? convertDiagnosisToTreeArray(tree[k].children)
: null;
diagnosisItem.parent = diagnosisFlat[k].parent;
dataForFilters.push(diagnosisItem);
});
return dataForFilters;
}

function getDiagnosisConcatenateValue(id) {
return diagnosisFlat[id]?.concatenate.replaceAll(CONCATENATE_SEPARATOR, "|");
}

function getDiagnosisValuesByLevel(filterKey) {
const diagnosisValues = [];
if (diagnosisArray.length === 0) {
const diagnosisFlatKeys = Object.keys(diagnosisFlat);
diagnosisFlatKeys.forEach((k) => {
const diagnosisItem = {...diagnosisFlat[k]};
diagnosisItem.id = k;
diagnosisArray.push(diagnosisItem);
});
}
switch (filterKey) {
case "diagnosis_1": {
diagnosisValues.push(
...diagnosisArray
.filter(d => d.level === 1)
.map(d => d.id)
);
break;
}
case "diagnosis_2": {
diagnosisValues.push(
...diagnosisArray
.filter(d => d.level === 2)
.map(d => d.id)
);
break;
}
case "diagnosis_3": {
diagnosisValues.push(
...diagnosisArray
.filter(d => d.level === 3)
.map(d => d.id)
);
break;
}
case "diagnosis_4": {
diagnosisValues.push(
...diagnosisArray
.filter(d => d.level === 4)
.map(d => d.id)
);
break;
}
case "diagnosis_5": {
diagnosisValues.push(
...diagnosisArray
.filter(d => d.level === 5)
.map(d => d.id)
);
break;
}
default: {
break;
}
}
return diagnosisValues;
}

function addDisplayDiagnosis(dArray) {
displayDiagnosis.push(...dArray);
}

function getDisplayDiagnosis() {
return displayDiagnosis;
}

const diagnosisModel = {
getDiagnosisFlat,
getDiagnosisDataForFilters,
getDiagnosisConcatenateValue,
getDiagnosisValuesByLevel,
addDisplayDiagnosis,
getDisplayDiagnosis,
};

export default diagnosisModel;
Loading

0 comments on commit 642925d

Please sign in to comment.