<commit_before>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import UtilsNew from "../../../core/utilsNew.js";
import LitUtils from "../../commons/utils/lit-utils.js";
import OpencgaCatalogUtils from "../../../core/clients/opencga/opencga-catalog-utils.js";
import "../../clinical/clinical-analysis-update.js";
import "../../clinical/interpretation/clinical-interpretation-manager.js";
import "../../clinical/clinical-analysis-consent-editor.js";
import "../../clinical/clinical-analysis-audit-browser.js";
import "../../commons/view/detail-tabs.js";
import "../../individual/individual-view.js";
import "../../loading-spinner.js";

class VariantInterpreterLanding extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            clinicalAnalysis: {
                type: Object
            },
            opencgaSession: {
                type: Object
            },
            // clinicalAnalysisId: {
            //     type: String
            // },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._config = this.getDefaultConfig();
    }

    update(changedProperties) {
        this._config = this.getDefaultConfig();

        if (changedProperties.has("opencgaSession")) {
            this.writeMode = OpencgaCatalogUtils.checkPermissions(this.opencgaSession.study, this.opencgaSession.user.id, "WRITE_CLINICAL_ANALYSIS");
        }

        if (changedProperties.has("config")) {
            this._config.items = UtilsNew.mergeArray(this._config.items, this.config.tabs, false, true);
        }

        super.update(changedProperties);
    }

    onClinicalAnalysisUpdate(e) {
        LitUtils.dispatchEventCustom(this, "clinicalAnalysisUpdate", null, null, {
            clinicalAnalysis: e.detail.clinicalAnalysis
        });
    }

    render() {
        // Check if project exists
        if (!this.opencgaSession?.project) {
            return html`
                <div class="guard-page">
                    <i class="fas fa-lock fa-5x"></i>
                    <h3>No public projects available to browse. Please login to continue.</h3>
                </div>
            `;
        }

        // Check if clinicalAnalysis is not available yet
        if (!this.clinicalAnalysis) {
            return html`
                <div style="margin-top:48px">
                    <loading-spinner></loading-spinner>
                </div>
            `;
        }

        // Check if we have permissions to edit a clinical analysis
        /* if (!OpencgaCatalogUtils.checkPermissions(this.opencgaSession.study, this.opencgaSession.user.id, "WRITE_CLINICAL_ANALYSIS")) {
            return html`
                <div class="guard-page">
                    <i class="fas fa-lock fa-5x"></i>
                    <h3>You do not have permissions to edit this case.</h3>
                </div>
            `;
        } */

        return html`
            <detail-tabs
                .data="${this.clinicalAnalysis}"
                .config="${this._config}"
                .opencgaSession="${this.opencgaSession}">
            </detail-tabs>
        `;
    }

    getDefaultConfig() {
        return {
            display: {
                align: "center",
            },
            items: [
                {
                    id: "general",
                    name: "General Info",
                    active: this.writeMode,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="General Info - ${clinicalAnalysis?.id ?? ""}" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <clinical-analysis-update
                                        .clinicalAnalysis="${clinicalAnalysis}"
                                        .opencgaSession="${opencgaSession}">
                                    </clinical-analysis-update>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "interpretations",
                    name: "Interpretation Manager",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Interpretation Manager" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <clinical-interpretation-manager
                                        .clinicalAnalysis="${clinicalAnalysis}"
                                        .opencgaSession="${opencgaSession}"
                                        @clinicalAnalysisUpdate="${this.onClinicalAnalysisUpdate}">
                                    </clinical-interpretation-manager>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "clinical",
                    name: "Clinical",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Clinical" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <individual-view
                                        .individual="${clinicalAnalysis.proband}"
                                        .opencgaSession="${opencgaSession}">
                                    </individual-view>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "consent",
                    name: "Consent",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Consent - ${clinicalAnalysis?.proband.id || ""}" class="bg-white"></tool-header><commit_msg>wc: rename general info and clinical tabs (#235)<commit_after>/*
 * Copyright 2015-2016 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {LitElement, html} from "lit";
import UtilsNew from "../../../core/utilsNew.js";
import LitUtils from "../../commons/utils/lit-utils.js";
import OpencgaCatalogUtils from "../../../core/clients/opencga/opencga-catalog-utils.js";
import "../../clinical/clinical-analysis-update.js";
import "../../clinical/interpretation/clinical-interpretation-manager.js";
import "../../clinical/clinical-analysis-consent-editor.js";
import "../../clinical/clinical-analysis-audit-browser.js";
import "../../commons/view/detail-tabs.js";
import "../../individual/individual-view.js";
import "../../loading-spinner.js";

class VariantInterpreterLanding extends LitElement {

    constructor() {
        super();

        // Set status and init private properties
        this._init();
    }

    createRenderRoot() {
        return this;
    }

    static get properties() {
        return {
            clinicalAnalysis: {
                type: Object
            },
            opencgaSession: {
                type: Object
            },
            // clinicalAnalysisId: {
            //     type: String
            // },
            config: {
                type: Object
            }
        };
    }

    _init() {
        this._config = this.getDefaultConfig();
    }

    update(changedProperties) {
        this._config = this.getDefaultConfig();

        if (changedProperties.has("opencgaSession")) {
            this.writeMode = OpencgaCatalogUtils.checkPermissions(this.opencgaSession.study, this.opencgaSession.user.id, "WRITE_CLINICAL_ANALYSIS");
        }

        if (changedProperties.has("config")) {
            this._config.items = UtilsNew.mergeArray(this._config.items, this.config.tabs, false, true);
        }

        super.update(changedProperties);
    }

    onClinicalAnalysisUpdate(e) {
        LitUtils.dispatchEventCustom(this, "clinicalAnalysisUpdate", null, null, {
            clinicalAnalysis: e.detail.clinicalAnalysis
        });
    }

    render() {
        // Check if project exists
        if (!this.opencgaSession?.project) {
            return html`
                <div class="guard-page">
                    <i class="fas fa-lock fa-5x"></i>
                    <h3>No public projects available to browse. Please login to continue.</h3>
                </div>
            `;
        }

        // Check if clinicalAnalysis is not available yet
        if (!this.clinicalAnalysis) {
            return html`
                <div style="margin-top:48px">
                    <loading-spinner></loading-spinner>
                </div>
            `;
        }

        // Check if we have permissions to edit a clinical analysis
        /* if (!OpencgaCatalogUtils.checkPermissions(this.opencgaSession.study, this.opencgaSession.user.id, "WRITE_CLINICAL_ANALYSIS")) {
            return html`
                <div class="guard-page">
                    <i class="fas fa-lock fa-5x"></i>
                    <h3>You do not have permissions to edit this case.</h3>
                </div>
            `;
        } */

        return html`
            <detail-tabs
                .data="${this.clinicalAnalysis}"
                .config="${this._config}"
                .opencgaSession="${this.opencgaSession}">
            </detail-tabs>
        `;
    }

    getDefaultConfig() {
        return {
            display: {
                align: "center",
            },
            items: [
                {
                    id: "general",
                    name: "Case Manager",
                    active: this.writeMode,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Case Manager - ${clinicalAnalysis?.id ?? ""}" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <clinical-analysis-update
                                        .clinicalAnalysis="${clinicalAnalysis}"
                                        .opencgaSession="${opencgaSession}">
                                    </clinical-analysis-update>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "interpretations",
                    name: "Interpretation Manager",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Interpretation Manager" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <clinical-interpretation-manager
                                        .clinicalAnalysis="${clinicalAnalysis}"
                                        .opencgaSession="${opencgaSession}"
                                        @clinicalAnalysisUpdate="${this.onClinicalAnalysisUpdate}">
                                    </clinical-interpretation-manager>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "clinical",
                    name: "Clinical Data",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Clinical Data" class="bg-white"></tool-header>
                                <div style="padding: 0px 20px">
                                    <individual-view
                                        .individual="${clinicalAnalysis.proband}"
                                        .opencgaSession="${opencgaSession}">
                                    </individual-view>
                                </div>
                            </div>
                        `;
                    }
                },
                {
                    id: "consent",
                    name: "Consent",
                    active: false,
                    render: (clinicalAnalysis, active, opencgaSession) => {
                        return html`
                            <div class="col-md-10 col-md-offset-1">
                                <tool-header title="Consent - ${clinicalAnalysis?.proband.id || ""}" class="bg-white"></tool-header>
{'fraction_non_alphanumeric': 0.11199348401547546, 'fraction_numerical': 0.005769361297766918, 'mean_word_length': 1.225007550588946, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '140663', 'n_tokens_mistral': 3695, 'n_tokens_neox': 3360, 'n_words': 742}