<?php
include('head.php');
include('header.php');
include('sidebar.php');
//$stmt = $pdo->prepare("SELECT * FROM tblphysicians where isDeleted='N' order by id DESC");
// $stmt = $pdo->prepare("SELECT tblphysicians.firstName, tblphysicians.lastName,
// COALESCE(tblphysiciansaddress.email, tblphysicians.email) AS email, 
// COALESCE(tblphysiciansaddress.fax, tblphysicians.fax) AS fax,
// tblphysicians.license, COALESCE(tblphysiciansaddress.phone, tblphysicians.phone) AS phone,
// COALESCE(tblphysiciansaddress.streetAddress, tblphysicians.streetAddress) AS streetAddress,
// COALESCE(tblphysiciansaddress.city, tblphysicians.city) AS city, 
// COALESCE(tblphysiciansaddress.province, tblphysicians.province) AS province,
// COALESCE(tblphysiciansaddress.postalCode, tblphysicians.postalCode) AS postalCode, 
// tblphysicians.createdBy, tblphysicians.assignedTo, tblphysicians.physicianType, tblphysicians.createdAt, tblphysicians.id 
// FROM tblphysicians LEFT JOIN tblphysiciansaddress ON tblphysicians.id = tblphysiciansaddress.physicianId AND tblphysiciansaddress.addressType = 'Primary' 
// WHERE tblphysicians.isDeleted = 'N' ORDER BY tblphysicians.id DESC;");
$stmt = $pdo->prepare("SELECT tblphysicians.firstName, tblphysicians.lastName,
tblphysiciansaddress.email AS email, 
tblphysiciansaddress.fax AS fax,
tblphysicians.license, tblphysiciansaddress.phone AS phone,
tblphysiciansaddress.streetAddress AS streetAddress,
tblphysiciansaddress.city AS city, 
tblphysiciansaddress.province AS province,
tblphysiciansaddress.postalCode AS postalCode, 
tblphysicians.createdBy, tblphysicians.assignedTo, tblphysicians.physicianType, tblphysicians.createdAt, tblphysicians.id 
FROM tblphysicians LEFT JOIN tblphysiciansaddress ON tblphysicians.id = tblphysiciansaddress.physicianId AND tblphysiciansaddress.addressType = 'Primary' 
WHERE tblphysicians.isDeleted = 'N' and tblphysiciansaddress.isDeleted = 'N' ORDER BY tblphysicians.id DESC;");
$stmt->execute();
$patients = $stmt->fetchAll();
?>
<style>
    .card-header.mgtop.inlineflex {
        padding: 20px;
    }

    a.white {
        color: white;
    }

    .mgtop {
        margin-top: 20px;
        margin-bottom: 20px;
    }

    #example_wrapper select:not([size]) {
        width: 10%;
        margin: 10px;
    }

    .rxtitle {
        font-size: 24px;
        font-weight: 600;
    }

    table a.btn {
        /* background: none; */
        height: max-content;
        width: max-content;
        display: inline-flex;
    }

    .dt-length,
    .dt-search {
        display: flex;
        vertical-align: middle;
        align-items: center;
    }

    .customdewidth {
        margin-left: 15%;
        margin-top: 80px;
        width: 85%;
        background-color: whitesmoke;
    }

    aside {
        width: 15%;
    }

    .deindexpage .dt-search {
        float: right;
    }

    .rxtitle {
        color: #1a70b8;
    }
</style>

<section class="bgcolordefault deindexpage">
    <div class="container-fluid customdewidth">
        <div class="row">
            <div class="col-md-12">


                <div class="page-header mgtop">
                    <h1 class="rxtitle">
                        Physicians
                        <a href="add_physician.php" class="btn float-right btn-primary">Add New Physician</a>
                    </h1>
                </div>
                <div class="card">

                    <!-- /.card-header -->
                    <div class="card-body">

                        <table id="example" class="table table-striped table-bordered" style="width:100%;">
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th class="text-center">Fax</th>
                                    <th class="text-center">License</th>
                                    <th class="text-center">Phone</th>

                                    <th>Primary Address</th>
                                    <!-- <th>Added By</th> -->
                                    <th>Assigned To</th>
                                    <th>Type</th>
                                    <!-- <th class="text-center">Created At</th> -->
                                 
                                        <th class="text-center">Action</th>
                                   
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($patients as $pd) {
                                    ?>
                                    <tr>
                                        <td><?= $pd['firstName']; ?>     <?= $pd['lastName']; ?></td>
                                        <td><?= $pd['email']; ?></td>
                                        <td class="text-center"><?= $pd['fax']; ?></td>
                                        <td><?= $pd['license']; ?></td>
                                        <td class="text-center"><?= $pd['phone']; ?></td>
                                        <td><?= $pd['streetAddress']; ?>     <?= $pd['city']; ?>     <?= $pd['province']; ?>
                                            <?= $pd['postalCode']; ?></td>
                                        <!-- <td><?= getuserName($pdo, $pd['createdBy']); ?></td> -->
                                        <td><?= getuserName($pdo, $pd['assignedTo']); ?></td>
                                        <td><?= $pd['physicianType']; ?></td>
                                        <!-- <td class="text-center"><?= $pd['createdAt']; ?></td> -->
                                        <?php if ($_SESSION['empType'] == 'S' || $_SESSION['empType'] == 'A') { ?>
                                            <td class="text-center">
                                                <a href="view_physician.php?id=<?= $pd['id']; ?>" class="blue"
                                                title="View Profile"><i class='fa fa-eye'></i></a>&nbsp;
                                                <?php if ($_SESSION['empType'] == 'S' || $_SESSION['empType'] == 'A') { ?>
                                                <a href="edit_physician.php?id=<?= $pd['id']; ?>" class="blue"
                                                title="Edit Profile"><i class="fa fa-edit"></i></a>
                                                <?php } ?>
                                            </td>
                                        <?php } ?>
                                    </tr>
                                <?php } ?>

                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>Name</th>
                                    <th>Email</th>
                                    <th>Fax</th>
                                    <th>License</th>
                                    <th class="text-center">Phone</th>
                                    <th>Address</th>
                                    <!-- <th>Added By</th> -->
                                    <th>Assigned To</th>
                                    <th>Type</th>
                                    <!-- <th class="text-center">Created At</th> -->
                                  
                                        <th class="text-center">Action</th>
                                   
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <!-- /.card-body -->
                </div>

            </div>
        </div>
    </div>
</section>
<script>
    $('#example').dataTable({
        "order": [],
        "pageLength": 100,
        // Your other options here...
    });

</script>
<?php include('footer.php');