{% extends "base.html" %}

{% block title %}
Add/Search patients
{% endblock %}

{% block content %}
  <h2>Add/Search patients</h2>
  <form action="." method="GET">{% csrf_token %}
    <label for="q">Search: </label>
    <input type="text" name="q" value="{{ query|escape }}">
    <input type="submit">
  </form>

  {% if query %}
    <h2>Results for "{{ query|escape }}":</h2>

    {% if results %}
      <table>
      <thead>
          <tr>
              <th></th>
              <th>姓名</th>
              <th>病歷號</th>
              <th>性別</th>
              <th>生日</th>
              <th>地址</th>
              <th>電話</th>
              <th>身份證號</th>
              <th>Memo</th>
              <th>Delete</th>
              <th>Edit</th>
          </td>
      </thead>
      <tbody>
      {% for patient in results %}
        <tr>
            <td><a href='/patient/detail/{{patient.id}}/'><img src="/site_media/img/actions/document-open.png" alt="Detail" border=0 title="{{patient.name}}'s treatments"/></a></td>
            <td>{{ patient.name }}</td>
            <td>{{ patient.medical_records }}</td>
            <td>{{ patient.get_gender_display }}</td>
            <td>{{ patient.birthday }}</td>
            <td>{{ patient.address }}</td>
            <td>{{ patient.phone }}</td>
            <td>{{ patient.id_cards }}</td>
            <td>{{ patient.memo }}</td>
            <td><a href='/patient/delete/{{patient.id}}/'><img src="/site_media/img/actions/edit-delete.png" alt="Delete" border=0 title="Delete {{patient.name}}"/></a></td>
            <td><a href='/patient/update/{{patient.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title="Edit {{patient.name}}"/></a></td>
        </tr>
      {% endfor %}
      </tbody>
      </table>
    {% else %}
      <p>No patient found.
      <a href='/patient/add/?ChartNo={{query}}/'>Add a patient</a>
      </p>
    {% endif %}
  {% endif %}{% endblock %}