From f8f3ae1b959b608edfc25c7491801a4a929508c5 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Wed, 8 Mar 2023 15:08:15 +0100
Subject: [PATCH] fix: skip non supported parc feat: add preferred parc/spc

---
 src/atlasComponents/sapi/sapi.service.ts | 14 ++++++++++++--
 src/state/atlasSelection/effects.ts      | 12 ++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/atlasComponents/sapi/sapi.service.ts b/src/atlasComponents/sapi/sapi.service.ts
index 38945b970..84d6f4299 100644
--- a/src/atlasComponents/sapi/sapi.service.ts
+++ b/src/atlasComponents/sapi/sapi.service.ts
@@ -29,6 +29,11 @@ type PaginatedResponse<T> = {
   pages?: number
 }
 
+const parcBanList: string[] = [
+  "https://identifiers.org/neurovault.image:23262",
+  "https://doi.org/10.1016/j.jneumeth.2020.108983/mni152",
+]
+
 @Injectable({
   providedIn: 'root'
 })
@@ -319,7 +324,12 @@ export class SAPI{
 
   public getAllParcellations(atlas: SxplrAtlas): Observable<SxplrParcellation[]> {
     return forkJoin(
-      translateV3Entities.retrieveAtlas(atlas).parcellations.map(
+      translateV3Entities.retrieveAtlas(atlas).parcellations.filter(
+        p => {
+          const { ['@id']: id } = p
+          return !parcBanList.includes(id)
+        }
+      ).map(
         parc => this.v3Get("/parcellations/{parcellation_id}", { path: { parcellation_id: parc["@id"] } }).pipe(
           switchMap(v => translateV3Entities.translateParcellation(v))
         )
@@ -328,7 +338,7 @@ export class SAPI{
   }
 
   #tmplToParcMap = new Map<string, SxplrParcellation[]>()
-  public getSupportedParcellations(atlas: SxplrAtlas, template: SxplrTemplate): Observable<any|SxplrParcellation[]> {
+  public getSupportedParcellations(atlas: SxplrAtlas, template: SxplrTemplate): Observable<SxplrParcellation[]> {
     if (!template) {
       return throwError(`template cannot be empty!`)
     }
diff --git a/src/state/atlasSelection/effects.ts b/src/state/atlasSelection/effects.ts
index 1786b5cca..639b970e9 100644
--- a/src/state/atlasSelection/effects.ts
+++ b/src/state/atlasSelection/effects.ts
@@ -26,6 +26,12 @@ type OnTmplParcHookArg = {
   }
 }
 
+const prefParcId = [
+  "minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290"
+]
+
+const prefSpcId = []
+
 @Injectable()
 export class Effect {
 
@@ -131,10 +137,11 @@ export class Effect {
                 if (parcs.length === 0) {
                   throw new Error(`Cannot find any supported parcellations for template ${template.name}`)
                 }
+                const selectParc = parcs.find(p => prefParcId.includes(p.id)) || parcs[0]
                 return {
                   atlas: currAtlas,
                   template,
-                  parcellation: parcs[0]
+                  parcellation: selectParc
                 }
               })
             )
@@ -145,9 +152,10 @@ export class Effect {
                 if (templates.length === 0) {
                   throw new Error(`Cannot find any supported templates for parcellation ${parcellation.name}`)
                 }
+                const selectTmpl = templates.find(tmp => prefSpcId.includes(tmp.id)) || templates[0]
                 return {
                   atlas: currAtlas,
-                  template: templates[0],
+                  template: selectTmpl,
                   parcellation
                 }
               })
-- 
GitLab