From d135bef10d7827e91de9a53c82a2720981cff9d2 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 12 Oct 2021 12:37:22 +0200
Subject: [PATCH] hotfix: ieeg

---
 .../bsFeatures/ieeg/ieegCmp/ieeg.component.ts | 39 +++++++++----------
 .../ieeg/ieegCmp/ieeg.template.html           | 19 +++------
 .../bsFeatures/ieeg/ieegCtrl.directive.ts     |  2 +-
 .../regionalFeatures/bsFeatures/ieeg/type.ts  | 30 ++++++++------
 .../regionalFeatures/bsFeatures/type.ts       |  2 +-
 5 files changed, 44 insertions(+), 48 deletions(-)

diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.component.ts b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.component.ts
index 4694a4342..338ce1fc1 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.component.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.component.ts
@@ -6,7 +6,7 @@ import { viewerStateAddUserLandmarks, viewerStateChangeNavigation, viewreStateRe
 import { BsRegionInputBase } from "../../bsRegionInputBase";
 import { REGISTERED_FEATURE_INJECT_DATA } from "../../constants";
 import { BsFeatureService, TFeatureCmpInput } from "../../service";
-import { TBSDEtail, TBSSummary, SIIBRA_FEATURE_KEY, TContactPoint, TElectrode } from '../type'
+import { SIIBRA_FEATURE_KEY, TContactPoint, TElectrode, TBSIeegSessionDetail } from '../type'
 import { ARIA_LABELS, CONST } from 'common/constants'
 
 @Component({
@@ -24,7 +24,7 @@ export class BsFeatureIEEGCmp extends BsRegionInputBase implements OnDestroy{
 
   private featureId: string
 
-  private results: (TBSSummary & TBSDEtail)[] = []
+  private results: TBSIeegSessionDetail[] = []
   constructor(
     private store: Store<any>,
     svc: BsFeatureService,
@@ -35,12 +35,13 @@ export class BsFeatureIEEGCmp extends BsRegionInputBase implements OnDestroy{
     this.subs.push(
       this.results$.subscribe(results => {
         this.results = results
+        console.log(results)
         this.loadLandmarks()
       })
     )
   }
 
-  public results$: Observable<(TBSSummary & TBSDEtail)[]>  = this.region$.pipe(
+  public results$: Observable<TBSIeegSessionDetail[]>  = this.region$.pipe(
     switchMap(() => this.getFeatureInstancesList(SIIBRA_FEATURE_KEY).pipe(
       switchMap(arr => forkJoin(arr.filter(it => {
         if (!this.featureId) return true
@@ -109,23 +110,21 @@ export class BsFeatureIEEGCmp extends BsRegionInputBase implements OnDestroy{
     }[]
 
     for (const detail of this.results) {
-      for (const subjectKey in detail.electrodes){
-        const electrodes = detail.electrodes[subjectKey]
-        for (const electrodId in electrodes) {
-          const electrode = electrodes[electrodId]
-          if (!electrode.inRoi) continue
-          
-          for (const cpKey in electrode.contact_points) {
-            const cp = electrode.contact_points[cpKey]
-            lms.push({
-              "@id": `${detail.name}:${subjectKey}#${cpKey}`,
-              id: `${detail.name}:${subjectKey}#${cpKey}`,
-              name: `${detail.name}:${subjectKey}#${cpKey}`,
-              position: cp.location,
-              color: cp.inRoi ? [255, 100, 100]: [255, 255, 255],
-              showInSliceView: this.openElectrodeSet.has(electrode)
-            })
-          }
+      const subjectKey = detail.sub_id
+      for (const electrodeId in detail.electrodes){
+        const electrode = detail.electrodes[electrodeId]
+        if (!electrode.inRoi) continue
+        for (const cpKey in electrode.contact_points) {
+          const cp = electrode.contact_points[cpKey]
+          const id=`${detail.name}:${subjectKey}#${cpKey}`
+          lms.push({
+            "@id": id,
+            id: id,
+            name: id,
+            position: cp.location,
+            color: cp.inRoi ? [255, 100, 100]: [255, 255, 255],
+            showInSliceView: this.openElectrodeSet.has(electrode)
+          })
         }
       }
     }
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.template.html b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.template.html
index be044298e..2622d200a 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.template.html
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCmp/ieeg.template.html
@@ -4,21 +4,12 @@
 
 <ng-template #contenttmpl>
   <ng-container *ngFor="let result of results$ | async">
-    <ng-container *ngFor="let subjectKeyVal of result | getProperty : 'electrodes' | keyvalue">
+    <ng-container *ngFor="let electrodeKeyVal of result | getProperty : 'electrodes' | keyvalue">
+      <ng-template [ngIf]="electrodeKeyVal.value.inRoi">
+        <ng-container *ngTemplateOutlet="electrodeTmpl; context: { $implicit: electrodeKeyVal.value }">
+        </ng-container>
+      </ng-template>
 
-      <ng-container *ngFor="let electrodeKeyVal of subjectKeyVal.value | keyvalue; let first = first">
-
-        <!-- subject id -->
-        <!-- <h4 *ngIf="first" class="mat-h4">
-          {{ subjectKeyVal.key }}
-        </h4> -->
-
-        <!-- electrodes -->
-        <ng-template [ngIf]="electrodeKeyVal.value.inRoi">
-          <ng-container *ngTemplateOutlet="electrodeTmpl; context: { $implicit: electrodeKeyVal.value }">
-          </ng-container>
-        </ng-template>
-      </ng-container>
     </ng-container>
   </ng-container>
 </ng-template>
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCtrl.directive.ts b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCtrl.directive.ts
index 85997dcd7..e7e79ef4a 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCtrl.directive.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/ieegCtrl.directive.ts
@@ -14,7 +14,7 @@ import { SIIBRA_FEATURE_KEY } from './type'
 
 export class BsFeatureIEEGDirective extends BsRegionInputBase implements IRegionalFeatureReadyDirective, OnDestroy{
 
-  public results$: Observable<IBSSummaryResponse['IEEG_Dataset'][]>  = this.region$.pipe(
+  public results$: Observable<IBSSummaryResponse['IEEG_Session'][]>  = this.region$.pipe(
     switchMap(() => this.getFeatureInstancesList(SIIBRA_FEATURE_KEY).pipe(
       catchError(() => of([]))
     )),
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/type.ts b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/type.ts
index 9029bf61d..8300f694d 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/type.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/ieeg/type.ts
@@ -19,21 +19,27 @@ export type TElectrode = {
   inRoi?: boolean
 }
 
-export type TBSDEtail = {
-  'kg_id': string
-  'electrodes': {
-    [key: string]: {
-      [key: string]: TElectrode
-    }
-  }
+export type TBSIeegSessionSummary = {
+  '@id': string
+  name: string
+  description: string
+  origin_datainfos: {
+    urls: {
+      doi: string
+    }[]
+  }[]
 }
-export type _TBSDEtail = {
-  '__kg_id': string
-  '__contact_points': {
-    [key: string]: TContactPoint
+
+type TDetail = {
+  sub_id: string
+  electrodes: {
+    [key: string]: TElectrode
   }
+  inRoi?: boolean
 }
 
-export const SIIBRA_FEATURE_KEY = 'IEEG_Dataset'
+export type TBSIeegSessionDetail = TBSIeegSessionSummary & TDetail
+
+export const SIIBRA_FEATURE_KEY = 'IEEG_Session'
 export const _SIIBRA_FEATURE_KEY = 'IEEG_Electrode'
 export const IEEG_FEATURE_NAME = 'iEEG recordings'
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/type.ts b/src/atlasComponents/regionalFeatures/bsFeatures/type.ts
index b16d5dcad..84731e489 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/type.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/type.ts
@@ -1,7 +1,7 @@
 import { IHasId } from "src/util/interfaces";
 import { TBSDetail as TReceptorDetail, TBSSummary as TReceptorSummary } from "./receptor/type";
 import { KG_REGIONAL_FEATURE_KEY, TBSDetail as TKGDetail, TBSSummary as TKGSummary } from './kgRegionalFeature/type'
-import { SIIBRA_FEATURE_KEY, TBSSummary as TIEEGSummary, TBSDEtail as TIEEGDetail } from './ieeg/type'
+import { SIIBRA_FEATURE_KEY, TBSSummary as TIEEGSummary, TBSIeegSessionDetail as TIEEGDetail } from './ieeg/type'
 import { Observable } from "rxjs";
 import { InjectionToken } from "@angular/core";
 
-- 
GitLab