diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts index 51ea824139a920943ebcc57f3b4a117da74c2129..473a830af001bb96e532fb38d2f516afb92390b7 100644 --- a/src/ui/parcellationRegion/region.base.ts +++ b/src/ui/parcellationRegion/region.base.ts @@ -90,19 +90,31 @@ export class RegionBase { const filteredRsInOtherTmpls = [] for (const bundledObj of regionsInOtherTemplates) { const { template, parcellation, region } = bundledObj - const idx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => { + + /** + * trying to find duplicate region + * with same templateId, and same hemisphere + */ + const sameEntityIdx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => { return _template['@id'] === template['@id'] - && getRegionHemisphere(_region) !== getRegionHemisphere(region) + && getRegionHemisphere(_region) === getRegionHemisphere(region) }) - if ( idx < 0 ) { + /** + * if doesn't exist, just push to output + */ + if ( sameEntityIdx < 0 ) { filteredRsInOtherTmpls.push(bundledObj) } else { - const { parcellation: currentParc } = filteredRsInOtherTmpls[idx] + + /** + * if exists, only append the latest version + */ + const { parcellation: currentParc } = filteredRsInOtherTmpls[sameEntityIdx] /** * if the new element is newer than existing item */ if (isNewerThan(parcellations, parcellation, currentParc)) { - filteredRsInOtherTmpls.splice(idx, 1) + filteredRsInOtherTmpls.splice(sameEntityIdx, 1) filteredRsInOtherTmpls.push(bundledObj) } }