{% extends "base.html" %}
{#% load endless %#}
{% load static %}

{% block head %}

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<!-- Load js for initializing tables via their server-side options -->
<script type="text/javascript" charset="utf8" src="{% static 'js/datatableview.js' %}"></script>
<script type="text/javascript">
    $(function(){

        var xeditable_options = {};
        datatableview.initialize($('.datatable'), {
            fnRowCallback: datatableview.make_xeditable(xeditable_options),
        });
    });
</script>
{% endblock %}


{% block content %}
    <h2>List treatments</h2>

    {{ datatable }}

	{% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="?page={{ page_obj.previous_page_number }}">previous</a>
                {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                </span>
                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}">next</a>
                {% endif %}
            </span>
        </div>
    {% endif %}


    {% if object_list %}
    <table>
    <thead>
        <tr>
            <th>Detail</th>
            <th>ID</th>
            <th>Patient</th>
            <th>Date</th>
            <th>Radiat Oncol</th>
            <th>Surgeon</th>
            <th>記帳別</th>
            <th>Disease Stage</th>
            <th>Primary tumor site</th>
            <th>ICD</th>
            <th>其他診斷</th>
            <th>已</th>
            <th>待</th>
            <th>病床號</th>
            <th>Memo</th>
            <th>Delete/Edit/Print</th>
        </tr>
    </thead>
    <tbody>
        {% for treatment in object_list %}
        <tr>
            <td><a href='/treatment/detail/{{treatment.id}}/'><img src="/site_media/img/actions/document-open.png" alt="Detail" border=0 title="Treatment detail"/></a></td>
            <td>{{ treatment.id }}</td>
            <td><a href='/patient/detail/{{treatment.patient.id}}/'>{{ treatment.patient }}</a> / {{ treatment.patient.medical_records }}</td>
            <td>{%ifequal treatment.date_started treatment.date_completed%}{{treatment.date_completed}}{%else%}{{treatment.date_started}} ~ {{treatment.date_completed}}{%endifequal%}</td>
            <td>{{ treatment.oncologist }}</td>
            <td>{{ treatment.surgeon }}</td>
            <td>{{ treatment.get_accounting_display }}</td>
            <td>{{ treatment.disease_stage }}</td>
            <td>{% ifequal treatment.disease_stage_id 5 %} <!-- metastatic? -->
            {{ treatment.primary_tumor_site }}
            {% endifequal %}</td>
            {% if treatment.icd10cm %}
            <td>{{ treatment.icd10cm }}</td>
            {% else %}
            <td>{{ treatment.icd9 }}</td>
            {% endif %}
            <td>{{ treatment.other_diagnosis }}</td>
            <td>{{ treatment.input }}</td>
            <td>{{ treatment.output }}</td>
            <td>{{ treatment.bed }}</td>
            <td>{{ treatment.memo }}</td>
            <td><a href='/treatment/delete/{{treatment.id}}/'><img src="/site_media/img/actions/edit-delete.png" alt="Delete" border=0 title="Delete treatment"/></a>
                <a href='/treatment/update/{{treatment.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title="Edit treatment"/></a>
                <a href='/treatment/print/{{treatment.id}}/' target='_blank'><img src="/site_media/img/actions/document-print.png" alt="Print" border=0 title="Print treatment"/></a>
                <a href='/treatment/report/{{treatment.id}}/' target='_blank'><img src="/site_media/img/actions/edit-find-replace.png" alt="Report" border=0 title="Report treatment"/></a></td>
        </tr>
        {% endfor %}
        {#% show_pages %#}
    </tbody>
    </table>
    
	{% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="?page={{ page_obj.previous_page_number }}">previous</a>
                {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                </span>
                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}">next</a>
                {% endif %}
            </span>
        </div>
    {% endif %}

    
    {% endif %}

{% endblock %}

