{% load widget_tweaks %}

{% if form.errors %}
<pre style="display: none">
errors:
{% for field in form %}
{% if field.errors %}- {{field.name}} {{ field.errors|striptags }}{% endif %}
{% endfor %}
</pre>
{% endif %}

<form action="{{ request.get_full_path }}" method="post">
  {% csrf_token %}

  Modèle : {{ form.template_filename }}

<h3>Patient</h3>

<ul>
 <li>{{ object.first_name }} <span class="lastname">{{ object.last_name }}</span></li>
 {% if object.birthdate %}
 <li>Date de naissance : {{ object.birthdate|date:"d/m/Y" }}</li>
 {% endif %}
</ul>

<h3>Adresse</h3>
<p><strong>Commentaire :</strong> <br />
{{ object.policyholder.contact_comment }}
</p>

<ul class="addresses">
  {% for address in object.addresses.all %}
  <li>
  <span>{{ address.display_name }} {% if address.phone %}(Tél : {{ address.phone }}){% endif %}</span>
  <pre>{{ address.comment }}</pre>
  <ul>
    {% if address.recipient %}
    <li><input type="radio" name="contact" id="contact_{{ address.id }}_{{ contact.id }}"
               {% if address.recipient %}data-address-recipient="{{ address.recipient }}"{% endif %}
               {% if address.street %}data-address-street="{{ address.street }}"{% endif %}
               {% if address.number %}data-address-number="{{ address.number }}"{% endif %}
               {% if address.address_complement %}data-address-address-complement="{{ address.address_complement }}"{% endif %}
               {% if address.zip_code %}data-address-zip-code="{{ address.zip_code }}"{% endif %}
               {% if address.city %}data-address-city="{{ address.city }}"{% endif %}
               {% if address.phone %}data-address-phone="{{ address.phone }}"{% endif %}
               {% if contact.gender %}data-contact-gender={% if contact.gender == 1 %}"Monsieur"{% elif contact.gender == 2 %}"Madame"{% endif %}{% endif %}
               {% if contact.first_name %}data-contact-first-name="{{ contact.first_name }}"{% endif %}
               {% if contact.last_name %}data-contact-last-name="{{ contact.last_name }}"{% endif %}
               ><label for="contact_{{ address.id }}_{{ contact.id }}">{{ address.recipient }} (DESTINATAIRE)</label></input></li>
    {% endif %}
    {% for contact in address.patientcontact_set.all  %}
    <li><input type="radio" name="contact" id="contact_{{ address.id }}_{{ contact.id }}"
               {% if address.street %}data-address-street="{{ address.street }}"{% endif %}
               {% if address.number %}data-address-number="{{ address.number }}"{% endif %}
               {% if address.address_complement %}data-address-address-complement="{{ address.address_complement }}"{% endif %}
               {% if address.zip_code %}data-address-zip-code="{{ address.zip_code }}"{% endif %}
               {% if address.city %}data-address-city="{{ address.city }}"{% endif %}
               {% if address.phone %}data-address-phone="{{ address.phone }}"{% endif %}
               {% if contact.gender %}data-contact-gender={% if contact.gender == 1 %}"Monsieur"{% elif contact.gender == 2 %}"Madame"{% endif %}{% endif %}
               {% if contact.first_name %}data-contact-first-name="{{ contact.first_name }}"{% endif %}
               {% if contact.last_name %}data-contact-last-name="{{ contact.last_name }}"{% endif %}
       ><label for="contact_{{ address.id }}_{{ contact.id }}">{% if contact.gender == 1 %}M. {% elif contact.gender == 2 %}Mme {% endif %}{% if contact.first_name %}{{ contact.first_name }} {% endif %}<span class="lastname">{{ contact.last_name }}</span>{% if contact.mobile %} (Perso : {{ contact.mobile }}){% endif %}{% if contact.phone %} (Pro : {{ contact.phone }}){% endif %}{% if contact.id == object.id %} (PATIENT){% endif %}{% if object.policyholder.id == contact.id %} (ASSURE){% endif %}</label></input></li>
    {% endfor %}
  </ul>
  </li>
  {% endfor %}
</ul>

{{ form.address }}

<p><label>Téléphone : </label><input id="id_phone_address" type="text" name="phone_address" value=""/></p>

{% if appointment %}
<h3>Rendez-vous</h3>

<ul>
 <li>Date : {{ appointment.date }}</li>
 <li>Heure : {{ appointment.begin_hour }}</li>
 {% if appointment.workers %}
 <li>Intervenant(s) :
      {% for worker in appointment.workers %}
        {{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if forloop.last %}.{% else %}, {% endif %}
      {% endfor %}
 </li>
 {% endif %}
</ul>

{% endif %}

</form>
