<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <template id="report_patient_detail">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
                <t t-call="web.external_layout">
                    <div class="page">
                        <div class="oe_structure"/>
                        <div class="row">
                            <div class="col-xs-8">
                                <table class="table table-condensed" style="border: 3px solid black !important;">
                                    <tr>
                                        <td width="40%">
                                            <p style="text-align:center;padding-top:10px;">
                                                <img t-if="not o.image"
                                                     t-att-src="'/web/static/src/img/placeholder.png'" height="140"
                                                     border="1" width="120"/>
                                                <img t-if="o.image"
                                                     t-att-src="'data:image/png;base64,%s' % to_text(o.image)"
                                                     height="140" border="1" width="120"/>
                                            </p>
                                        </td>
                                        <td width="60%">
                                            <table>
                                                <tr>
                                                    <td colspan="3" class="text-center">
                                                        <span t-field="o.name"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <span>
                                                            <strong>Age:</strong>
                                                        </span>
                                                    </td>
                                                    <td>
                                                        <span>:</span>
                                                    </td>
                                                    <td>
                                                        <span t-field="o.age"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <span>
                                                            <strong>Reference:</strong>
                                                        </span>
                                                    </td>
                                                    <td>
                                                        <span>:</span>
                                                    </td>
                                                    <td>
                                                        <span t-field="o.reference"/>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <br/>

                        <t t-if="o.appointment_ids">
                            <span>Appointment Details</span>
                            <table class="table table-sm o_main_table" name="appointment">
                                <thead>
                                    <tr>
                                        <th name="th_reference" class="text-start">
                                            <span>Reference</span>
                                        </th>
                                        <th name="th_age" class="text-start">
                                            <span>Age</span>
                                        </th>
                                        <th name="th_doctor" class="text-start">
                                            <span>Doctor</span>
                                        </th>
                                    </tr>
                                </thead>
                                <t t-set="appointment_count" t-value="0"/>
                                <t t-foreach="o.appointment_ids" t-as="line">
                                    <t t-set="appointment_count" t-value="appointment_count + 1"/>
                                    <tr>
                                        <td>
                                            <span t-field="line.name"/>
                                        </td>
                                        <td>
                                            <span t-field="line.age"/>
                                        </td>
                                        <td>
                                            <span t-field="line.doctor_id.doctor_name"/>
                                        </td>
                                    </tr>
                                </t>

                                <tr>
                                    <td colspan="2">
                                        <strong>Total Appointments</strong>
                                    </td>
                                    <td>
                                        <t t-esc="appointment_count"/>
                                    </td>
                                </tr>
                            </table>
                        </t>

                    </div>
                </t>
            </t>
        </t>
    </template>

</odoo>
