<?php

use App\Models\Page;

$medicationsAddedOnIntake = Page::where('client_id', $patient->id)
    ->where('category', 'MEDICATION')
    ->whereRaw("(is_active IS TRUE AND  added_reason_category = 'ADDED_ON_INTAKE') ") //TODO fix query
    ->get();

$medicationsRemovedOnIntake = Page::where('client_id', $patient->id)
    ->where('category', 'MEDICATION')
    ->whereRaw("(is_active IS FALSE AND deactivated_during_note_uid  = ? AND deactivation_reason_category = 'REMOVED_ON_INTAKE')", [$note->uid])
    ->get();

?>

<?php if(!count($medicationsAddedOnIntake)): ?>
    <div>No medications</div>
<?php else: ?>
    <div><h1><?php echo count($medicationsAddedOnIntake); ?></h1></div>
    <div class="d-flex">
        <table>
            <thead>
            <tr>
                <th>Medication</th>
                <th>Dose</th>
                <th>Route</th>
                <th>Frequency</th>
                <th></th>
            </tr>
            </thead>
            <?php foreach($medicationsAddedOnIntake as $medOnIntake): ?>
            <tr>
                <td><?php echo $medOnIntake->key ?></td>
                <td><?php echo $medOnIntake->data_dose ?></td>
                <td><?php echo $medOnIntake->data_route ?></td>
                <td><?php echo $medOnIntake->data_frequency ?></td>
                <td></td>
            </tr>
            <?php endforeach; ?>

        </table>
    </div>
<?php endif; ?>

