{% extends 'dossiers/patientrecord_tab.html' %}
{% block content %}
<form method="post" action="tab1"  id="general-form" class="patientrecordform">{% csrf_token %}
<div class="left">
  <ul>
    <li>
    <label>N° dossier papier :</label> {{ object.paper_id|default_if_none:"Non renseigné" }}
    <button id="update-paper-id-btn" type='button' class="icon-edit" title="Modifier"></button>
    </li>
    <li><label>N° dossier informatique :</label> <span class="lightgray">{{ object.id }}</span></li>
    <li><label>Nom :</label> <span class="lastname">{{ object.last_name }}</span></li>
    <li><label>Prénom :</label> {{ object.first_name }}</li>
    <li><label>Genre :</label> {{ object.get_gender_display|default_if_none:"Non renseigné" }}</li>
    <li><label>Date de naissance :</label> {% if object.birthdate %}{{ object.birthdate|date:"d/m/Y" }} ({{ object.age }}){% else %}Non renseignée{% endif %}</li>
    <li>
      {% if nb_place_of_lifes == 1 %}
      <label>Lieux de vie :</label>
      {% elif nb_place_of_lifes > 1 %}
      <label class="highlight">{{ nb_place_of_lifes }} lieux de vie :</label>
      {% else %}
      <label class="highlight">Aucun lieu de vie n'est indiqué.</label>
      {% endif %}
      {% if object.contact_comment %}<p>{{ object.contact_comment|linebreaks }}</p>{% endif %}
        {% if object.addresses.all %}
        <ul>
          {% for address in object.addresses.all %}
          {% if address.place_of_life %}<li>✔ {{ address.display_name }}</li>{% endif %}
          {% endfor %}
        </ul>
        {% endif %}
    </li>
    <li><label>Date de contact :</label> {{ initial_state.date_selected|date:"d/m/Y" }}</li>
    <li><label>Date de création :</label> {{ object.created|date:"d/m/Y" }}</li>
    <li><label>Lieu de socialisation :</label> {{ object.school|default_if_none:"Non renseigné" }}</li>
    <li><label>Coordinateurs :</label>
        {% if object.coordinators.all %}
        <ul>
          {% for coordinator in object.coordinators.all %}
          <li>{{ coordinator.first_name }} <span class="lastname">{{ coordinator.last_name }}</span></li>
          {% endfor %}
        </ul>
        {% else %}Aucun{% endif %}
    </li>
      <li><label>Commentaire </label> <button class="save enable-on-change btn-maj">✔</button><br/>
      {{ form.comment }}
      </li>
    </ul>
  </div>
  <div class="right">
    <ul>
      <li><label>Dernier acte :</label>
      {% if last_rdv %}
      {% if last_rdv.is_absent %}<span style="font-weight: bold;">{% endif %}
        {{ last_rdv.start_datetime|date:"d/m/Y" }} -
        {% for participant in last_rdv.participants %}
        <span class="lastname">{{ participant.last_name }}</span> -
        {% endfor %}
        {{ last_rdv.act_type }}
        {% else %}
        Aucun
        {% endif %}
        {% if last_rdv.is_absent %} ({{ last_rdv.act_state }})</span>{% endif %}
      </li>
      <li><label>Prochain rendez-vous :</label>
      {% if next_rdv %}
      {% if next_rdv.is_absent %}<span style="font-weight: bold;">{% endif %}
        {{ next_rdv.start_datetime|date:"d/m/Y" }} -
        {% for participant in next_rdv.participants.all %}
        <span class="lastname">{{ participant.last_name }}</span> -
        {% endfor %}
        {{ next_rdv.act_type }}
        {% else %}
        Aucun
        {% endif %}
        {% if next_rdv.is_absent %} ({{ next_rdv.act.get_state }})</span>{% endif %}
      </li>
    </ul>
    <div class="etat">
      {% if future_state %}
      <h4>État à venir du dossier :  {{ current_state.status.name.lower }}</h4>
      <p>à partir du : {{ current_state.date_selected|date:"d/m/Y" }}</p>
      {% else %}
      <h4>État courant du dossier :  {{ current_state.status.name.lower }}</h4>
      <p>depuis le : {{ current_state.date_selected|date:"d/m/Y" }}</p>
      {% endif %}
      {% if current_state.comment %}<p><label>Commentaire :</label> {{ current_state.comment }}</p>{% endif %}
      {% for state in status %}
      <button type="button" id="{{ state.0 }}">{{ state.1 }}</button>
      {% endfor %}
      <button type="button" id="patientrecord-history">Historique</button>
      <hr/>
      <p id="confidential-msg" style="display: none; font-size: 10px;">Confidentialité mise à jour</p>
      {{ form.confidential.label_tag }} : <span class="autosubmit">{{ form.confidential }}</span>
      <p id="pause-msg" style="display: none; font-size: 10px;">Pause facturation mise à jour</p>
      {{ form.pause.label_tag }} : <span class="autosubmit">{{ form.pause }}</span>
      <br/>
      <span class="js-expandable">
      <label class="js-click-to-expand">Commentaire de la pause facturation {% if object.pause_comment %}<span title="Un commentaire existe" class="icon-comment" style="display: inline"></span>{% endif %}</label>
      <span class="js-to-expand">
        <button class="save enable-on-change btn-maj">✔</button><br/>
        {{ form.pause_comment }}
      </span>
    </div>
  </form>

    {% if object.service.name == "CMPP" %}
    <div class="notifs">
    <h4>Information sur la prise en charge</h4>
    <ul>
    <li><span{% if hc_status.1 %} class="highlight"{% endif %}>{{ hc_status.0 }}</span></li>
    {% if object.pause %}<li><span class="highlight">Le dossier est en pause facturation.</span></li>{% endif %}
    {% if missing_policy %}<li><span class="highlight">Informations d'assuré social manquantes.</span></li>{% endif %}
    {% if missing_birthdate %}<li><span class="highlight">Date de naissance manquante.</span></li>{% endif %}
    {% if object.policyholder.ame %}<li><span class="highlight">Le contact assuré est AME.</span></li>{% endif %}
    </div>
    {% endif %}


    <form method="post" action="{% url "create_directory" service object.id %}" id="create-directory-form">{% csrf_token %}
      <button>Créer répertoire patient</button>
    </form>
</div>
{% endblock %}
