{% extends "base.html" %}

{% block title %}
List treatments
{% endblock %}

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

    <table>
    <thead>
        <tr>
            <th>Patient ID</th><td>{{ patient.id }}</td>
            <th>姓名</th><td>{{ patient.name }}</td>
            <th>病歷號</th><td>{{ patient.medical_records }}</td>
            <th>性別</th><td>{{ patient.get_gender_display }}</td>
            <th>生日</th><td>{{ patient.birthday }}</td>
            <td rowspan=2>
                <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>
                <a href='/patient/print/{{patient.id}}/' target='_blank'><img src="/site_media/img/actions/document-print.png" alt="Print" border=0 title='Print summary'/></a>
            </td>
        </tr>
        <tr>
            <th>地址</th><td>{{ patient.address }}</td>
            <th>電話</th><td>{{ patient.phone }}</td>
            <th>身份證號</th><td>{{ patient.id_cards }}</td>
            <th>Memo</th><td>{{ patient.memo }}</td>
            <th></th><td>
            {% if patient.dead %}
            <em>{{patient.dead}}已死亡</em>
            {% endif %}
            </td>
        </tr>
        <tr>
            <th>身高(cm)</th><td>{{ patient.height }}</td>
            <th>體重(kg)</th><td>{{ patient.weight }}</td>
            <!-- 
            <th>已追蹤日期</th><td>{{ patient.last_followup }}</td>
            <th>預追蹤日期</th><td>{{ patient.next_followup }}</td>
            -->
        </tr>
    </thead>
    </table>
    <a href=/query/heightweight/{{patient.id}}/>身高體重</a>
    <hr/>
    {% if patient.priortreatment_set.all %}
    <table>
    <thead>
        <tr>
            <th>Prior Treatment ID</th>
            <th>Start Date</th>
            <th>Treatment</th>
            <th>Period</th>
            <th>Dose(cGy)</th>
            <th>Memo</th>
            <th>Delete</th>
            <th>Edit</th>
        </tr>
    </thead>
    <tbody>
        {% for prior in patient.priortreatment_set.all|dictsort:"date" %}
        <tr>
            <td>{{ prior.id }}</td>
            <td>{{ prior.date }}</td>
            <td>{{ prior.get_treatment_display }}</td>
            <td>{{ prior.get_period_display }}</td>
            <td>{{ prior.dose }}</td>
            <td>{{ prior.memo }}</td>
            <td><a href='/prior/delete/{{prior.id}}/'><img src="/site_media/img/actions/edit-delete.png" alt="Delete" border=0 title='Delete prior treatment'/></a></td>
            <td><a href='/prior/update/{{prior.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title='Edit prior treatment'/></a></td>
        </tr>
        {% endfor %}
    </tbody>
    </table>
    {% endif %}

    <a href=/prior/create/{{patient.id}}/>Add prior treatment</a>
    <a href=/prior/op_note/{{patient.id}}/>手術紀錄查詢</a>
    <a href=/prior/oncrt_query/{{patient.id}}/>放射記錄摘要查詢</a>

    {% if patient.pathexam_set.all %}
    <table>
    <thead>
        <tr>
            <th>病理號</th>
            <th>報告日</th>
            <th>報告</th>
        </tr>
    </thead>
    <tbody>
        {% for path in patient.pathexam_set.all|dictsort:"path_code" %}
        <tr>
            <td>{{ path.path_code }}</td>
            <td>{{ path.report_date }}</td>
            <td>{{ path.report }}</td>
        </tr>
        {% endfor %}
    </tbody>
    </table>
    {% endif %}
    <a href=/prior/path_exam/{{patient.id}}/>病理報告查詢</a>

    <div style="background: red">
    <hr/>
    {% if treatments %}
    <table>
    <thead>
        <tr>
            <th>Detail</th>
            <th>ID</th>
            <th>Date</th>
            <th>Oncologist</th>
            <th>Surgeon</th>
            <th>記帳別</th>
            <th>Disease Stage</th>
            <th>Primary tumor site</th>
            <th>已</th>
            <th>待</th>
            <th>Memo</th>
            <th>Delete</th>
            <th>Edit</th>
            <th>Print</th>
        </tr>
    </thead>
    <tbody>
        {% for treatment in treatments %}
        <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>{%if treatment.date_started == treatment.date_completed%}{{treatment.date_completed}}{%else%}{{treatment.date_started}} ~ {{treatment.date_completed}}{%endif%}</td>
            <td>{{ treatment.oncologist }}</td>
            <td>{{ treatment.surgeon }}</td>
            <td>{{ treatment.get_accounting_display }}</td>
            <td>{{ treatment.disease_stage }}</td>
            <td>{% if treatment.disease_stage_id == 5 %} <!-- metastatic? -->
            {{ treatment.primary_tumor_site }}
            {% endif %}</td>
            <td>{{ treatment.input }}</td>
            <td>{{ treatment.output }}</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></td>
            <td><a href='/treatment/update/{{treatment.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title='Edit treatment'/></a></td>
            <td><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></td>
        </tr>
        {% endfor %}
    </tbody>
    </table>
    {% endif %}
    <a href=/treatment/create/{{patient.id}}/><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>New treatment</a>
    </div>

    <hr/>

    {% if patient.followup_set.all %}
    <table>
    <thead>
        <tr>
            <th>Date</th>
            <th>Memo</th>
            <th>Delete</th>
            <th>Edit</th>
        </tr>
    </thead>
    <tbody>
        {% for followup in patient.followup_set.all|dictsort:"date" %}
        <tr>
            <td>{{ followup.date }}</td>
            <td>{{ followup.memo }}</td>
            <td><a href='/followup/delete/{{followup.id}}/'><img src="/site_media/img/actions/edit-delete.png" alt="Delete" border=0 title='Delete followup'/></a></td>
            <td><a href='/followup/update/{{followup.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title='Edit followup'/></a></td>
        </tr>followup
        {% endfor %}
    </tbody>
    </table>
    {% endif %}

    <a href=/followup/create/{{patient.id}}/>New Follow-up</a>

    <hr/>

    {% if patient.medicalrecord_set.all %}
    Last Medical Records
    <table>
    <thead>
      <thead>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
      </thead>
    </thead>
    <tbody>
        {% for mr in patient.medicalrecord_set.all|dictsortreversed:"InDate" %}
        {%if forloop.counter0 < 5%}
        <tr>
            <td>{{ mr.Record }}</td>
            <td>{{ mr.HospName }}</td>
            <td>{{ mr.DeptName }}</td>
            <td>{{ mr.InDate }}</td>
            <td>
              {%if mr.WardName%}{{mr.WardName}}{%endif%}
              {%if mr.RoomName%}{{mr.RoomName}}{%endif%}
              {%if mr.BedName%}{{mr.BedName}}{%endif%}
              {%if mr.OutDate%}{{mr.OutDate}}出 {%endif%}
              {%if mr.SpecialCureName%}{{mr.SpecialCureName}}{%endif%}
            </td>
            <td>{{ mr.MainDrName }}</td>
            <td>{{ mr.MainDiagnosisName }}</td>
            <td>{{ mr.StatusName }}</td>
        </tr>
        {%endif%}
        {% endfor %}
    </tbody>
    </table>
    {% endif %}
    <hr/>
    {% if pacsimages %}
    PACS Images (CT/MRI)
    <table>
      <thead>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th>標示為不適用</th>
      </thead>
    <tbody>
        {% for p in pacsimages %}
        <tr>
            <td>{{ p.RequestSheetNo }}</td>
            <td>{{ p.ExamDate }}</td>
            <td>{{ p.LinkOrderName }}</td>
            <td>{{ p.Modality }}</td>
            <td>{{ p.VerifiedStateString }}</td>
            <td>{{ p.get_Saved_display }}</td>
            <td><a href='/followup/markimages/{{p.patient.id}}/{{p.ExamDate}}/'><img src="/site_media/img/actions/mail-mark-junk.png" alt="N/A" border=0 title='Mark N/A'/></a></td>
        </tr>
        {% endfor %}
    </tbody>
    </table>
    {% endif %}


{% endblock %}
