private setupRouteHandling()

in pathology/viewer/src/stores/image-viewer-page.store.ts [714:808]


    private setupRouteHandling() {
        this.activatedRoute.queryParams
            .pipe(
                takeUntil(this.destroy$),
                distinctUntilChanged(),
                tap((params: ImageViewerPageParams) => {
                    const url = this.router.url;
                    if (!url.startsWith(DEFAULT_VIEWER_URL)) return;

                    let {cohortName, series} = params;
                    if (series) {
                      // Support legacy URLs
                      series = addDicomStorePrefixIfMissing(series);
                    }

                    if (!environment.IMAGE_DICOM_STORE_BASE_URL) {
                        this.router.navigate(['/config']);
                        return;
                    }

                    if (!series && !cohortName) {
                        this.router.navigate(['/search']);
                        return;
                    }

                    if (cohortName) {
                        if (!series) {
                            const queryParams: CohortPageParams = { cohortName };
                            this.router.navigate(['/cohorts'], { queryParams });
                            return;
                        }
                        this.cohortService.fetchPathologyCohort(cohortName);
                    }
                    if (!series) {
                        this.router.navigate(['/search']);
                        return;
                    }
                    // Check the base URL is one of the configured DICOM Stores.
                    try {
                        dicomIdToDicomStore(series);
                    } catch (e) {
                        this.dialogService.error(
                            'For your safety loading this slide was blocked. The DICOM store specified in your browser URL is not on the ones that were configured.')
                            .subscribe(() => {
                                this.router.navigate(['/search']);
                            });
                        return;
                    }

                    const indexSeries = series.indexOf('/series/');

                    let study: string =
                        indexSeries === -1 ? series : series.slice(0, indexSeries);

                    if (this.caseId !== study) {
                        this.caseId = '';
                    }
                    if (!this.caseId) {
                        this.caseId = study;
                        study = '';
                    }



                    if (this.caseId && this.caseId !== study) {
                        this.slideApiService.getSlidesForCase(this.caseId)
                            .subscribe((slides) => {
                                const slideDescriptorsByCaseId =
                                    this.slideDescriptorsByCaseId$.value;
                                slideDescriptorsByCaseId.set(this.caseId, slides);
                                this.slideDescriptorsByCaseId$.next(
                                    slideDescriptorsByCaseId);
                            });
                    }

                    const splitViewSlideDescriptors = series.split(',').map((a => {
                        if (!a) return undefined;
                        return { id: a };
                    }));

                    if (splitViewSlideDescriptors.length === 3) {
                        splitViewSlideDescriptors.push(undefined);
                    }


                    this.multiViewScreens$.next(splitViewSlideDescriptors.length);
                    this.splitViewSlideDescriptors$.next(splitViewSlideDescriptors);
                    this.selectedSplitViewSlideDescriptor$.next(
                        splitViewSlideDescriptors[this.multiViewScreenSelectedIndex$
                            .value] ??
                        splitViewSlideDescriptors[0]);
                }),
            )
            .subscribe();
    }