{% extends "layout_bs4.html" %}

{% block title %}
  {{ super() }} - {{ institute.display_name }} - {{ case.display_name }} - {{ variant.display_name }}
{% endblock %}

{% set pheno_hpos = [] %}
{% set pheno_features = [] %}
{% set pheno_omims = [] %}

{% for pheno in case.phenotype_terms if not pheno.phenotype_id in pheno_hpos %}
  {% do pheno_hpos.append(pheno.phenotype_id) %}
  {% do pheno_features.append(pheno.feature) %}
{% endfor %}
{% for pheno in case.phenotype_groups if not pheno.phenotype_id in pheno_hpos %}
  {% do pheno_hpos.append(pheno.phenotype_id) %}
  {% do pheno_features.append(pheno.feature) %}
{% endfor %}
{% for omim_id in case.diagnosis_phenotypes %}
  {% do pheno_omims.append(omim_id) %}
{% endfor %}

{% block top_nav %}
  <li class="nav-item">
    <a class="nav-link" href="{{ url_for('cases.cases', institute_id=institute._id) }}">
      {{ institute.display_name }}
    </a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="{{ url_for('cases.case', institute_id=institute._id, case_name=case.display_name) }}">
      {{ case.display_name }}
    </a>
  </li>
  <li class="nav-item">
    {% if cancer %}
      <a class="nav-link" href="{{ url_for('variants.cancer_variants', institute_id=institute._id, case_name=case.display_name, variant_type=variant.variant_type) }}">
        {{ variant.variant_type|capitalize }} cancer variants
      </a>
    {% else %}
      <a class="nav-link" href="{{ url_for('variants.variants', institute_id=institute._id, case_name=case.display_name, variant_type=variant.variant_type, gene_panels=case.panels|selectattr('is_default')|map(attribute='panel_name')|list) }}">
        {{ variant.variant_type|capitalize }} SNV and INDELs
      </a>
    {% endif %}
  </li>
  <li class="nav-item active">
    <p class="navbar-text">{{ variant.display_name|truncate(20, True) }}</p>
  </li>
{% endblock %}

{% block content_main %}

 <!-- clinvar form -->

<div class="container" id="main">
  <h3>Clinvar submission page</h3><br>
  <a href="https://www.ncbi.nlm.nih.gov/clinvar/intro/" target="_blank">Clinvar</a> is a freely accessible archive of clinically relevant variants.
    Contributing to this database helps improving data sharing and increasing the number of genetic diagnoses worldwide.<br>
    The form present on this page mirrors the fields on the Clinvar submission spreadsheets. After collecting all the required fields for submitting one or more variants to Clinvar, the info is subsequently processed into comma separated files, ready to be uploaded in the submission process.<br>
    Link to the official Clinvar <a href="https://www.ncbi.nlm.nih.gov/clinvar/docs/spreadsheet/#sub_info" target="_blank">documentation</a>.
  <br><br>
    {% if pheno_hpos|length >0 or pheno_omims|length >0 %}
      <form action="{{ url_for('variant.clinvar', institute_id=institute._id, case_name=case.display_name, variant_id=variant._id) }}" method="POST" id="clivar_form">
        <input type="hidden" name="main_var" value="{{ variant._id }}">
        <input type="hidden" name="case_id" value="{{ case._id }}">
          <div class="d-flex justify-content-between">
            <div>
              <input type="checkbox" id="all_vars" name="all_vars" value="all_vars">
              <label for="submit_all">Submit all pinned variants for this case</label>
            </div>
            <br>
          </div>
          <div class="row">
            {{ panel_variant('main_var') }}
          </div>
          <div class="row" id="other_vars" style="display: none">
            {{ panel_variant('other_vars') }}
          </div>
          <div class="col-xs-6 col-sm-6 col-md-12">
            <div class="form-group text-center">
              <button class="btn btn-lg btn-info" data-toggle="modal" value="submit">Add variants to Clinvar submission</button>
            </div>
          </div>
      </form>
{% else %}
    Can't submit to clinvar without specifying at least a phenotype for this case! <a class="btn btn-default" href="{{ url_for('cases.case', institute_id=institute._id, case_name=case.display_name) }}">
      Back to case
    </a>
  {% endif %}
</div>
{% endblock %}

<!--This panel returns one table for each pinned vat to include in the submission.-->
{% macro panel_variant(var_type) %}
  {% for pinned in pinned_vars %}
    {% if var_type=='main_var' and pinned._id == variant._id or var_type=='other_vars' and not pinned._id == variant._id %}
    <input type="hidden" name="category@{{pinned._id}}" value={{pinned.category or 'snv' }}>
    <input type ="hidden" name="local_id@{{pinned._id}}" value="{{pinned._id}}">
    <input type ="hidden" name="linking_id@{{pinned._id}}" value="{{pinned._id}}">
    <input type="hidden" name="chromosome@{{pinned._id}}" value="{{ pinned.chromosome }}">
    {% if pinned.category != 'sv' %}
      <input type="hidden" name="start@{{pinned._id}}" value="{{ pinned.position }}">
      <input type="hidden" name="stop@{{pinned._id}}" value="{{ pinned.position }}">
    {% endif %}
    <input type="hidden" name="ref@{{pinned._id}}" value="{{ pinned.reference }}">
    <input type="hidden" name="alt@{{pinned._id}}" value="{{ pinned.alternative }}">
    <br><br>
        <div class="card panel-default">
          <div class="panel-heading">
            <h5>
            {% if pinned.category == 'snv' %}
              <span class="badge badge-success float-left">snv</span>
            {% else %}
              <span class="badge badge-warning float-left">sv</span>
            {% endif %}
            {% if pinned.simple_id|length > 25 and pinned.cytoband_start %}
              #Variant --> {{ pinned.sub_category+"("+pinned.chromosome+pinned.cytoband_start+"-"+pinned.end_chrom+pinned.cytoband_end+")" }}
            {% elif pinned.simple_id|length > 25 %}
              #Variant --> {{ pinned.sub_category+"(chr."+pinned.chromosome+")" }}
            {% else %}
              #Variant --> {{ pinned.simple_id }}
            {% endif %}
            </h5>
          </div>
          <table class="table table-bordered table-fixed">
            <tbody>
              <tr>
                <td>
                  <table class="table table-fixed">
                    {% if pinned.category == 'snv' %}
                      <tr>
                        <td style="width:30%">
                          Gene symbol(s):
                        </td>
                        <td>
                          {% set gene_symbols = [] %}
                          {% for gene in pinned.genes %}
                            {% do gene_symbols.append(gene.hgnc_symbol) %}
                            {% if pinned.genes|length == 1 %}
                              <strong>{{ pinned.genes[0].hgnc_symbol }}</strong><br>
                            {% else %}
                              {% for gene in pinned.genes %}
                              <strong>{{ gene.hgnc_symbol+";" }}</strong>
                              {% endfor %}
                            {% endif %}
                          {% endfor %}
                            <input type="hidden" name="gene_symbol@{{pinned._id}}" value="{{ ';'.join(gene_symbols) }}">
                        </td>
                      </tr>
                    {% endif %}
                    <tr>
                      <td>Coordinates:</td>
                      {% if pinned.simple_id|length > 25 and pinned.cytoband_start %}
                        <td><strong>{{ pinned.sub_category + "(" + pinned.chromosome+pinned.cytoband_start+"-"+pinned.end_chrom+pinned.cytoband_end +"), length:"+ pinned.length|string  }}</strong></td>
                      {% elif pinned.simple_id|length > 25 %}
                        <td><strong>chr{{ pinned.chromosome }}:{{pinned.position}} ({{ pinned.sub_category }})</strong></td>
                      {% else %}
                        <td><strong>chr{{ pinned.chromosome }}:{{pinned.position}} ({{ pinned.reference }} -> {{ pinned.alternative }})</strong></td>
                      {% endif %}
                    </tr>
                    {% if pinned.category == 'snv' %}
                      <tr>
                        <td>Transcripts & HGVS:<br>(optional)
                        </td>
                        <td>
                          {% for gene in pinned.genes %}
                            {% for transcript in gene.transcripts %}
                              {% if transcript.refseq_id and transcript.coding_sequence_name %}
                                <input type="radio" id="{{pinned._id+"_"+transcript.refseq_id}}" name="ref_seq@{{pinned._id}}" value="{{transcript.refseq_id+"|"+transcript.coding_sequence_name}}" {% if transcript.is_primary == True %} checked {% endif %}>
                                <label for="{{pinned._id+"_"+transcript.refseq_id}}">{{transcript.refseq_id}} | {{transcript.coding_sequence_name}}</label><br>
                              {% endif %}
                            {% endfor %}
                          {% endfor %} <!--end of gene-->
                        </td>
                      </tr>
                    {% endif %}
                    <tr>
                      <td >Variant model of inheritance <br>
                        {% for model in pinned.genetic_models|sort %}
                          <span class="badge badge-info">{{ model }}</span>
                        {% endfor %}
                      </td>
                      <td>
                        <select id="Mode of inheritance_{{pinned._id}}" name="inheritance_mode@{{pinned._id}}">
                          {% if 'AR_hom' in pinned.genetic_models or 'AR_hom_dn' in pinned.genetic_models or 'AR_comp' in pinned.genetic_models or 'AR_comp_d' in pinned.genetic_models %}
                            <option value="Autosomal recessive inheritance" selected>Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance">X-linked inheritance</option>
                            <option value="
                            -limited autosomal dominant">Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance">Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance">Y-linked inheritance</option>
                          {% elif 'XR' in pinned.genetic_models or 'XR_dn' in pinned.genetic_models %}
                            <option value="Autosomal recessive inheritance">Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance" selected>X-linked inheritance</option>
                            <option value="Sex-limited autosomal dominant">Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance">Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance">Y-linked inheritance</option>
                          {% elif 'XD' in pinned.genetic_models or 'XD_dn' in pinned.genetic_models %}
                            <option value="Autosomal recessive inheritance">Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance">X-linked inheritance</option>
                            <option value="Sex-limited autosomal dominant" selected>Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance">Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance">Y-linked inheritance</option>
                          {% elif pinned.chromosome == 'MT' %}
                            <option value="Autosomal recessive inheritance">Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance">X-linked inheritance</option>
                            <option value="Sex-limited autosomal dominant">Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance" selected>Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance">Y-linked inheritance</option>
                          {% elif pinned.chromosome == 'Y' %}
                            <option value="Autosomal recessive inheritance">Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance">X-linked inheritance</option>
                            <option value="Sex-limited autosomal dominant">Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance">Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance" selected>Y-linked inheritance</option>
                          {% else %}
                            <option value="Autosomal recessive inheritance" selected>Autosomal recessive inheritance</option>
                            <option value="Autosomal dominant">Autosomal dominant inheritance</option>
                            <option value="X-linked inheritance">X-linked inheritance</option>
                            <option value="Sex-limited autosomal dominant">Sex-limited autosomal dominant</option>
                            <option value="Mitochondrial inheritance">Mitochondrial inheritance</option>
                            <option value="Y-linked inheritance">Y-linked inheritance</option>
                          {% endif %}
                          <option value="Autosomal unknown">Autosomal unknown</option>
                          <option value="Codominant">Codominant</option>
                          <option value="Genetic anticipation">Genetic anticipation</option>
                          <option value="Oligogenic">Oligogenic</option>
                          <option value="Somatic mutation">Somatic mutation</option>
                          <option value="Sporadic">Sporadic</option>
                          <option value="Other">Other</option>
                        </select>
                      </td>
                    </tr>
                    {% if pinned.dbsnp_id and pinned.category == 'snv'%}
                    {% set dbsnp_id = pinned.dbsnp_id.split(':')[0] %} <!-- sometimes snps look like this rs65544478:some_stuff -->
                      <tr>
                        <td>var. identifier</td>
                        <td><input type="text" id="Variation identifiers_{{pinned._id}}" name="variations_ids@{{pinned._id}}" value="{{dbsnp_id}}" size=14 pattern="rs[0-9]+"></td>
                      </tr>
                    {% endif %}
                    <tr>
                      <td style="width:40%">Clinical significance:</td>
                      <td>
                        <select id="Clinical significance_{{pinned._id}}" name="clinsig@{{pinned._id}}">
                            <option value="Pathogenic" {% if pinned.acmg_classification == 4 %} selected {% endif %}>Pathogenic</option>
                            <option value="Likely Pathogenic" {% if pinned.acmg_classification == 3 %} selected {% endif %} >Likely Pathogenic</option>
                            <option value="Likely benign" {% if pinned.acmg_classification == 2 %} selected {% endif %} >Likely benign</option>
                            <option value="Benign" {% if pinned.acmg_classification == 1 %} selected {% endif %} >Benign</option>
                            <option value="Uncertain significance" {% if pinned.acmg_classification == 0 %} selected {% endif %} >Uncertain significance</option>
                        </select>
                      </td>
                    </tr>
                    <tr>
                      <td>Comment on clinical significance</td>
                      <td>
                        <textarea name="clinsig_comment@{{pinned._id}}" placeholder="(optional)" rows="3" cols="40"></textarea>
                      </td>
                    </tr>
                  </table>
                </td>
                <td>
                  <table class="table table-fixed">
                    <tr>
                      <td>Date last evaluated</td>
                      <td><input type="text" id="Date last evaluated_{{pinned._id}}" name="last_evaluated@{{pinned._id}}" placeholder="yyyy-mm-dd" value="{{today}}" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))" ></td>
                    </tr>
                    <tr>
                      <td>Functional consequence:<br>(based on experimental evidence, leave blank if unsure)</td>
                      <td>
                        <select id="_{{pinned._id}}" name="funct_conseq@{{pinned._id}}" onChange="changeTextBox(this.options[this.selectedIndex].value, 'funct_cons', this.id);">
                            <option value="-" selected> - </option>
                          {% if pinned.category == 'snv' %}
                            <option value="Dominant negative variant">Dominant negative variant</option>
                            <option value="Gain of funtion variant">Gain of funtion variant</option>
                            <option value="Lethal variant">Lethal variant</option>
                            <option value="Loss of function variant">Loss of function variant</option>
                            <option value="Null mutation">Null mutation</option>
                            <option value="Level of transcript variant">Affecting transcript level</option>
                            <option value="Transcript processing variant">Affecting transcript processing</option>
                            <option value="Transcript stability variant">Affecting transcript stability</option>
                            <option value="Decreased transcription rate variant">Dicreasing transcr. rate</option>
                            <option value="Increased transcription rate variant">Increasing transcr. rate</option>
                          {% elif pinned.category == 'sv' %}
                            <option value="Copy number decrease">Copy number decrease</option>
                            <option value="Copy number increase">Copy number increase</option>
                            <option value="Regulatory region translocation">Regulatory region translocation</option>
                            <option value="Transctipt translocation">Transctipt translocation</option>
                            <option value="Short tandem repeat change">Short tandem repeat change</option>
                            <option value="Feature elongation">Feature elongation</option>
                            <option value="Feature truncation">Feature truncation</option>
                            <option value="Gene variant">Gene fusion, transcr. or transl. variant</option>
                            <option value="Regulatory region variant">Regulatory region variant</option>
                            <option value="Intergenic variant">Intergenic variant</option>
                          {% endif %}
                          <option value="Regulatory region ablation">Regulatory region ablation</option>
                          <option value="Regulatory region amplification">Regulatory region amplification</option>
                          <option value="Transcript ablation">Transcript ablation</option>
                          <option value="Transcript amplification">Transcript amplification</option>
                        </select>
                      </td>
                    </tr>
                    <tr style="display:none" id="line_{{pinned._id}}">
                      <td>Additional comments on functional consequence(s)</td>
                      <td>
                        <textarea id="Comment on functional consequence_{{pinned._id}}" name="funct_conseq_comment@{{pinned._id}}" placeholder="(optional) " rows="3" cols="30" disabled="true"></textarea>
                      </td>
                    </tr>
                    <tr>
                      <td style="width:30%">Condition HPO term(s):<br>(associated to the variant)</td>
                      <td>
                        {% for hpo in pheno_hpos %}
                          <input type="checkbox" id="conditions@{{pinned._id}}" value="HPO_{{hpo}}" name="conditions@{{pinned._id}}"><a href="http://hpo.jax.org/app/browse/term/{{hpo}}"
                            target="_blank" class="text-blue"> {{ hpo }} - {{pheno_features[loop.index -1]}}</a></input><br>
                        {% else %}
                          No preselected HPO term available.
                        {% endfor %}
                      </td>
                    </tr>
                    <tr>
                      <td style="width:30%">OMIM diagnoses:<br>(associated to the variant)</td>
                      <td>
                        {% for omim in pheno_omims %}
                          <input type="checkbox" id="conditions@{{pinned._id}}" value="OMIM_{{omim}}" name="conditions@{{pinned._id}}"><a href="http://omim.org/entry/{{omim}}"
                            target="_blank" class="text-blue"> {{ omim }} </a></input><br>
                        {% else %}
                          No preselected OMIM diagnosis available.
                        {% endfor %}
                      </td>
                    </tr>
                    <tr>
                      <td style="width:30%">Additional comments describing condition:</td>
                      <td>
                        <textarea name="condition_comment@{{pinned._id}}" placeholder="(optional)" rows="3" cols="30"></textarea>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </tbody>
          </table>

          <!--SV-related fields-->
          {% if pinned.category == 'sv' %}
          <table class="table table-bordered table-fixed">
              <tr>
                <td style="width:33%">
                  <table class="table table-fixed">
                    <tr>
                      <td>Type of structural variant:</td>
                      <td>
                        <select name="var_type@{{pinned._id}}" id="_{{pinned._id}}" onChange="changeTextBox(this.options[this.selectedIndex].value, 'sv_type', this.id);">
                        {% if pinned.sub_category == 'del' %}
                          <option value="duplication">duplication</option>
                          <option value="deletion" selected>deletion</option>
                          <option value="insertion">insertion</option>
                          <option value="inversion">inversion</option>
                          <option value="translocation">translocation</option>
                          <option value="translocation">complex</option>
                        {% elif pinned.sub_category == 'ins' %}
                          <option value="duplication">duplication</option>
                          <option value="deletion">deletion</option>
                          <option value="insertion" selected>insertion</option>
                          <option value="inversion">inversion</option>
                          <option value="translocation">translocation</option>
                          <option value="translocation">complex</option>
                        {% else %}
                          <option value="duplication">duplication</option>
                          <option value="deletion">deletion</option>
                          <option value="insertion">insertion</option>
                          <option value="inversion">inversion</option>
                          <option value="translocation">translocation</option>
                          <option value="translocation">complex</option>
                        {% endif %}
                        </select>
                      </td>
                    </tr>
                    {% if pinned.sub_category == 'del'%}
                      <tr style="display:''" id="copies_{{pinned._id}}">
                    {%else%}
                      <tr style="display:none" id="copies_{{pinned._id}}">
                    {% endif %}
                      <td>Copy number</td>
                      <td><input type="text" name="ncopy@{{pinned._id}}" value="" size=5 pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Reference copy number</td>
                      <td><input type="text" name="ref_copy@{{pinned._id}}" value="2" size=5 pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Breakpoint 1</td>
                      <td><input type="text" name="breakpoint1@{{pinned._id}}" value="{{pinned.position}}" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Breakpoint 2</td>
                      <td><input type="text" name="breakpoint2@{{pinned._id}}" value="{{pinned.end}}" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                  </table>
                </td>
                <td style="width:33%">
                  <br><br>
                  <table class="table table-fixed">
                    <tr>
                      <td>Outer start*</td>
                      <td><input type="text" name="outer_start@{{pinned._id}}" value="" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Inner start*</td>
                      <td><input type="text" name="inner_start@{{pinned._id}}" value="" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Inner stop*</td>
                      <td><input type="text" name="inner_stop@{{pinned._id}}" value="" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                    <tr>
                      <td>Outer stop*</td>
                      <td><input type="text" name="outer_stop@{{pinned._id}}" value="" size=20 placeholder="(optional)" pattern="[0-9]+"></td>
                    </tr>
                  </table>
                  <a href="https://www.ncbi.nlm.nih.gov/dbvar/content/overview/#representation" target="_blank">* How to display uncertainty of breakpoint locations</a>
                </td>
                <td style="width:40%">
                  <table class="table table-fixed">
                    <tr>
                      <td>Comments on this variant<br>
                        <textarea name="variant_comment@{{pinned._id}}" placeholder="(optional)" rows="10" cols="40"></textarea>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
          </table>

          {% endif %}
          <!--end of SV fields-->

          <a href="#more_variant_{{pinned._id}}" data-toggle="collapse">More optional fields</a><hr>
          <div id="more_variant_{{pinned._id}}" class="collapse">
            <table class="table table-fixed">
              <tbody>
                <tr>
                  <td>
                    <table>
                      <tr>
                        <td>Assertion method:</td>
                        <td><input type="text" name="assertion_method@{{pinned._id}}" placeholder="optional (Submitter's or other publication)" size="40" value="ACMG Guidelines, 2015"></td>
                      </tr>
                      <tr>
                        <td>Assertion citation</td>
                        <td>
                          <textarea name="assertion_method_cit@{{pinned._id}}" placeholder="(optional)" rows="3" cols="40">doi: 10.1038/gim.2015.30</textarea>
                        </td>
                      </tr>
                      <tr>
                        <td style="width:30%">Clinical significance citations<br>(with identifier)</td>
                        <td>
                          <textarea name="clinsig_cit@{{pinned._id}}" placeholder="(optional) e.g. PMID:123456,  PMCID:PMC3385229, NBK:56955" rows="3" cols="40"></textarea>
                        </td>
                      </tr>
                    </table>
                  </td>
                  <td>
                    <table>
                      <tr>
                        <td>Method</td>
                        <td>
                          <textarea name="assertion_method@{{pinned._id}}" placeholder="(optional) Free text describing the experimental method used to generate support." rows="3" cols="40"></textarea>
                        </td>
                      </tr>
                      <tr>
                        <td style="width:30%">Comments on clinical significance</td>
                        <td>
                          <textarea name="clinsig_comment@{{pinned._id}}" placeholder="(optional)" rows="3" cols="40"></textarea>
                        </td>
                      </tr>
                      <tr>
                        <td>Drug response condition(s)</td>
                        <td>
                          <textarea name="drug_response@{{pinned._id}}" placeholder="(optional) The condition for which the drug response is relevant. Separate multiple conditions by a semicolon." rows="3" cols="40"></textarea>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>

      {% for individual in case.individuals %}
        {% if individual.phenotype == 2 %}
          {% for sample in pinned.samples %}
            {% if sample.display_name == individual.display_name and sample.genotype_call != '0/0' and sample.genotype_call != './.' %}
              <div class="form-group" id="cdata_checkbox_{{pinned._id}}" >
                <div class="col-12 card">
                  <div class="form-check">
                    <label data-toggle="collapse" class="form-check-label" class="form-check-input" data-target="#casedata_{{pinned._id}}" aria-expanded="false" aria-controls="collapseOne">
                      <input type="checkbox" class="form-check-input" name="casedata_{{pinned._id}}" id="_{{pinned._id}}"/>Submit case data for this variant
                    </label>
                  </div>
                </div>
              </div>

              <div id="casedata_{{pinned._id}}" class="collapse">
                <input type="hidden" name="collection_method@{{pinned._id}}" value="clinical testing">
                <input type="hidden" name="individual_id@{{pinned._id}}" value="{{ individual.display_name }}">
                <input type="hidden" name="linking_id@{{ pinned._id }}" value="{{ pinned._id }}">
                <div class="card">
                  {% if pinned.simple_id|length > 25 and  pinned.cytoband_start%}
                    <div class="card-header">Subject {{ individual.display_name }}, variant {{ pinned.sub_category+"("+pinned.chromosome+pinned.cytoband_start+"-"+pinned.end_chrom+pinned.cytoband_end+")" }}</div>
                  {% elif pinned.simple_id|length > 25 %}
                    <div class="card-header">Subject {{ individual.display_name }}, variant {{ pinned.sub_category+"(chr."+pinned.chromosome+")" }}</div>
                  {% else %}
                    <div class="card-header">Subject {{ individual.display_name }}, variant {{ pinned.simple_id }}</div>
                  {% endif %}
                  <table class="table table-bordered table-fixed">
                    <tbody class="border-top">
                      <tr>
                        <td>
                          <table class="table table-fixed">
                            <tr>
                              <td>Affected?
                                <select name="is_affected@{{ pinned._id }}" id="affected_status">
                                  <option value="yes" selected>yes</option>
                                  <option value="no">no</option>
                                  <option value="unknown">?</option>
                                </select>
                              </td>
                              <td style="width:50%">Ethnicity
                                <select name="ethnicity@{{pinned._id}}" id="ethnicity">
                                  <option value="" selected>unspecified</option>
                                  <option value="Causasians">Causasian</option>
                                  <option value="African American">African American</option>
                                  <option value="European Caucasoid">European Caucasoid</option>
                                  <option value="American Indian or Alaska Native">American Indian / Alaska</option>
                                  <option value="Ashkenazi Jew">Ashkenazi Jew</option>
                                  <option value="Chinese">Chinese</option>
                                  <option value="Hawaii">Hawaii or pacific island</option>
                                  <option value="Hispanic Americans">Hispanic Americans</option>
                                  <option value="SE Asia">South East Asian</option>
                                  <option value="mixed">mixed ethnic group</option>
                                  <option value="none">none</option>
                                </select>
                              </td>
                            </tr>
                          </table>
                          <table class="table table-fixed">
                            <tr>
                              <td>sex
                                {% if individual.sex == "1" %}
                                  <input type="hidden" name="sex@{{pinned._id}}" value="male">
                                  <strong>male</strong>
                                {% else %}
                                  <input type="hidden" name="sex@{{pinned._id}}" value="female">
                                  <strong>female</strong>
                                {% endif %}
                              </td>
                              <td>
                                Age:<input type="text" name="age@{{pinned._id}}" value="" size=5>
                              </td>
                            </tr>
                            <tr>
                              <td>Allele origin
                                <select name="allele_origin@{{ pinned._id }}" id="allele_origin">
                                  <option value="germline">germline</option>
                                  <option value="de novo">de novo</option>
                                  <option value="somatic">somatic</option>
                                  <option value="maternal">maternal</option>
                                  <option value="paternal">paternal</option>
                                  <option value="inherited">inherited</option>
                                  <option value="unknown">unknown</option>
                                  <option value="uniparental">uniparental</option>
                                  <option value="biparental">biparental</option>
                                </select>
                              </td>
                              <td>Zygosity
                                {% for sample in pinned.samples %}
                                  {% if sample.display_name == individual.display_name %}
                                    <strong>({{ sample.genotype_call }})</strong><br>
                                    <select name="zygosity@{{pinned._id}}" id="zygosity">
                                      <option value="hemizygote" {%if sample.genotype_call == '1/1' and pinned.chromosome in ['X','Y'] %} selected {%endif%}>hemizygote</option>
                                      <option value="homozygote" {%if sample.genotype_call == '1/1' %} selected {%endif%}>homozygote</option>
                                      <option value="compound heterozygote" {%if sample.genotype_call != '1/1'%} selected {%endif%}>compound heterozygote</option>
                                      <option value="single heterozygote">single heterozygote</option>
                                    </select>
                                  {% endif %}
                                {% endfor %}
                              </td>
                            </tr>
                          </table>
                          {% if pinned.category == 'sv' %}
                            <table class="table table-fixed">
                              <tr>
                                <td colspan=2>Structural variant analysis:</td>
                                <td colspan=2>
                                  <select name="sv_analysis_method@{{pinned._id}}" id="sv_method">
                                    <option value="Paired-end mapping" selected>Paired-end mapping</option>
                                    <option value="Read depth">Read depth</option>
                                    <option value="One end anchored assembly">One end anchored assembly</option>
                                    <option value="Sequence alignment,">Sequence alignment</option>
                                    <option value="Curated">Curated</option>
                                  </select>
                                </td>
                              </tr>
                            </table>
                          {% endif %}
                          <table class="table table-fixed">
                            <tr>
                              <td>Was {{individual.display_name}} a proband?<br>
                                <select name="is_proband@{{pinned._id}}" id="proband">
                                  <option value="yes" selected>yes</option>
                                  <option value="no">no</option>
                                </select>
                              </td>
                              <td>Family history?<br>
                                <select name="fam_history@{{pinned._id}}" id="f_history">
                                  <option value="yes" >yes</option>
                                  <option value="no" selected>no</option>
                                </select>
                              </td>
                            </td>
                            <tr>
                              <td>Was this a secondary finding?<br>
                                <select name="is_secondary_finding@{{pinned._id}}" id="secondary">
                                  <option value="yes" >yes</option>
                                  <option value="no" selected>no</option>
                                </select>
                              </td>
                              <td>Mosaicism observed?<br>
                                <select name="is_mosaic@{{pinned._id}}" id="mosaicism">
                                  <option value="yes" >yes</option>
                                  <option value="no" selected>no</option>
                                </select>
                              </td>
                            </tr>
                          </table>

                          <table class="table table-fixed">
                            <tr>
                              <td >Co-occurrences same gene<br>
                                <textarea name="co_occurr_gene@{{pinned._id}}" placeholder="(optional) Full HGVS expressions" rows="3" cols="30"></textarea>
                              </td>
                              <td >Co-occurrences other genes<br>
                                <textarea name="co_occurr_other@{{pinned._id}}" placeholder="(optional) Full HGVS expressions" rows="3" cols="30"></textarea>
                              </td>
                            </tr>
                            <tr>
                              <td>Date variant was reported to submitter</td>
                              <td><input type="text" name="reported_at@{{pinned._id}}" placeholder="yyyy-mm-dd" value="{{ case.analysis_date.date() }}" pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))"></td>
                            </tr>
                            <tr>
                              <td>Tissue where genetic material was extracted from</td>
                              <td><input type="text" name="tissue@{{pinned._id}}" placeholder="(optional)" value=""></td>
                            </tr>
                          </table>
                        </td>
                        <td>
                          <table class="table table-fixed">
                            <tr>
                              <td style="width:30%">Clinical features<br>(HPO terms. ONLY if different from variant's HPO terms)</td>
                              <td>
                                {% for hpo in pheno_hpos %}
                                  <input type="checkbox" id="clin_features@{{pinned._id}}" value="HPO_{{hpo}}" name="clin_features@{{pinned._id}}"><a href="http://hpo.jax.org/app/browse/term/{{hpo}}"
                                    target="_blank" class="text-blue"> {{ hpo }} - {{pheno_features[loop.index -1]}}</a></input><br>
                                {% else %}
                                  No preselected HPO term available.
                                {% endfor %}
                              </td>
                            </tr>
                            <tr>
                              <td>Testing laboratory</td>
                              <td>
                                <input type="text" name="testing_lab@{{pinned._id}}" placeholder="(optional)" size=40>
                              </td>
                            </tr>
                            <tr>
                              <td>Platform type</td>
                              <td>
                                <input type="text" name="platform_type@{{pinned._id}}" placeholder="(optional)" value="next-gen sequencing" size=30>
                              </td>
                            </tr>
                            <tr>
                              <td>Platform name</td>
                              <td>
                                {% if individual.analysis_type == 'wes' %}
                                  <input type="text" name="platform_name@{{pinned._id}}" placeholder="(optional)" value="Whole exome sequencing, Illumina" size=30>
                                {% else %}
                                  <input type="text" name="platform_name@{{pinned._id}}" placeholder="(optional)" value="Whole genome sequencing, Illumina">
                                {% endif %}
                              </td>
                            </tr>
                            <tr>
                              <td>Method</td>
                              <td>
                                <textarea name="method@{{pinned._id}}" placeholder="(optional) Free text describing the experimental method used to generate support." rows="3" cols="40"></textarea>
                              </td>
                            </tr>
                            <tr>
                              <td>Method purpose</td>
                              <td>
                                <select name="method_purpose@{{pinned._id}}">
                                  <option value="discovery" selected>discovery</option>
                                  <option value="validation">validation</option>
                                  <option value="assert pathogenicity">assert pathogenicity</option>
                                </select>
                              </td>
                            </tr>
                            <tr>
                              <td>Method citations</td>
                              <td>
                                <textarea name="method_cit@{{pinned._id}}" placeholder="(optional) PMID:....;PMID:..." rows="3" cols="40"></textarea>
                              </td>
                            </tr>
                          </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            {% elif sample.display_name == individual.display_name %}
              No case data harboring this allelic variant!<br>
            {% endif %}
          {% endfor %}
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endfor %}

{% endmacro %}

{% block scripts %}
{{ super() }}
<script type="text/javascript">
    var div = document.getElementById("main");
    var inputs = div.getElementsByTagName("input");
    for (var i = 0, len = inputs.length; i < len; ++i) {
        if (inputs[i].type == "checkbox" & inputs[i].checked) {
          if(inputs[i].id == 'all_vars'){
            $('#other_vars').show()
          }
          else{
            //simulate a new click:
            inputs[i].click();
            inputs[i].checked = true;
          }
        }
    }

    $('#all_vars').change(function() {
      if(this.checked) {
          $('#other_vars').show()
      }
      else{
          $('#other_vars').hide()
      }
    });

    function goBack() {
      check = window.confirm("Are you sure you want to edit this submission?");
      if(check == true){
        window.history.back();
      }
    }

    function changeTextBox(selected_option, box, pinnedid)
    {
        if(box=='funct_cons')
        {
            if(selected_option == '-'){
              document.getElementById("line"+pinnedid).style.display = 'none'
              document.getElementById("Comment on functional consequence"+pinnedid).value='';
              document.getElementById("Comment on functional consequence"+pinnedid).disabled='true';
            }
            else{
              document.getElementById("Comment on functional consequence"+pinnedid).disabled='';
              document.getElementById("line"+pinnedid).style.display = ''
            }
        }
        else
        {
            if(selected_option == 'deletion' || selected_option == 'duplication'){
              document.getElementById("copies"+pinnedid).style.display = ''
            }
            else{
              document.getElementById("copies"+pinnedid).style.display = 'none'
              document.getElementById("Copy number"+pinnedid).value='';
            }
        }
    }

    function validateForm() {
      submission_id = document.forms["downloads_form"].elements["subm_id"].value
      if (submission_id == "") {
        alert("submission id must be filled in");
        document.forms["downloads_form"].elements["subm_id"].focus()
        return false;
      }
      document.forms["save_to_db"].elements["subm_id"].value = submission_id
    }

</script>

{% endblock %}
