<?php

use App\Models\Point;

$category = 'DISCLAIMERS';
$endPoint = 'upsertNoteSingleton';

$point = Point::where('added_in_note_id', $note->id)->where('category', $category)->orderBy('id', 'DESC')->first();
$contentData = [
    "consent_for_telehealth_visit" => false,
    "eduction_provided_for_covid" => false,
    "communicated_dietary_ls_exercise_risks" => false,
    "importance_of_calling_911" => false,
    "assessment_is_virtual" => false,
    "assessment_baseD_on_patient_inputs" => false,
];
if (!!@$point->data) {
    $contentData = json_decode($point->data, true);
}
?>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["consent_for_telehealth_visit"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Patient consent for telehealth visit obtained.</span>
</div>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["eduction_provided_for_covid"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Education provided for COVID risks, steps for prevention, and eliminating exposure.</span>
</div>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["communicated_dietary_ls_exercise_risks"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Communicated possible risks involved with dietary and lifestyle changes, and in particular with exercise prescription.</span>
</div>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["importance_of_calling_911"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Patient verbalizes the importance of calling 911 if experiencing chest pain, dizziness or lightheadedness while exercising.</span>
</div>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["assessment_is_virtual"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Patient understands that this assessment is done virtually and therefore a complete physical assessment was not completed, and is not a replacement for a visit with their primary care physician.</span>
</div>

<div class="d-flex align-items-baseline mb-2">
    <div class="align-self-stretch min-width-30px">
        @if(@($contentData["assessment_based_on_patient_inputs"]))
            <i class="fa fa-check"></i>
        @else
            -
        @endif
    </div>
    <span class="flex-grow-1">Patient understands this assessment was completed using the information they provided only. All questions addressed.</span>
</div>

@if($note->hcp_pro_id == $patient->mcp_pro_id && $patient->is_enrolled_in_cm === 'YES')
    <p class="mb-2">Patient elects to participate in Chronic Care Management.</p>
@endif

@if($note->hcp_pro_id == $patient->mcp_pro_id && $patient->is_enrolled_in_rm === 'YES') {{-- correct --}}
    <p class="mb-2">Patient elects to participate in Remote Patient Monitoring.</p>
@endif

<?php
$supplyOrders = \App\Models\SupplyOrder::where('client_id', $note->client->id)
    ->where('is_cancelled', false)
    ->where('note_id', $note->id)
    ->get();
?>
@if($supplyOrders && count($supplyOrders))
    <p>The following supplies were ordered during this visit:</p>
    <ol class="mb-2">
        @foreach($supplyOrders as $so)
            <li>{{$so->product->title}}</li>
        @endforeach
    </ol>
@endif

<?php
$erxs = \App\Models\Erx::where('client_id', $note->client->id)
    ->where('note_id', $note->id)
    ->orderBy('created_at', 'desc')
    ->where(function ($q) {
        $q->whereNull('pro_declared_status')
            ->orWhere('pro_declared_status', '<>', 'CANCELLED');
    })
    ->get();
?>
@if($erxs && count($erxs))
    <p>The following e-prescriptions were ordered during this visit:</p>
    <ol class="mb-2">
        @foreach($erxs as $erx)
            <?php $parsed = json_decode($erx->clinical_detail_json); ?>
            @if($erx->erx_category === 'LAB' || $erx->erx_category === 'IMAGING' || $erx->erx_category === 'DRUG')
                <li>
                    @if($erx->erx_category === 'LAB' || $erx->erx_category === 'IMAGING')
                        <div class="d-flex align-items-baseline">
                            <span>{{$erx->erx_category}}:</span>
                            <div class="pl-2 flex-grow-1">
                                @if($parsed && @($parsed->items) && count($parsed->items))
                                    @foreach($parsed->items as $t)
                                        @if(@($t->tests) && count($t->tests))
                                            @foreach($t->tests as $tx)
                                                <div>{{$tx->desc}}</div>
                                            @endforeach
                                        @endif
                                    @endforeach
                                @endif
                            </div>
                        </div>
                    @elseif($erx->erx_category === 'DRUG')
                        <div class="d-flex align-items-baseline">
                            <span>{{$erx->erx_category}}:</span>
                            <div class="pl-2 flex-grow-1">
                                @if($parsed && @($parsed->items) && count($parsed->items))
                                    @foreach($parsed->items as $t)
                                        <div>{{$t->medication}}</div>
                                    @endforeach
                                @endif
                            </div>
                        </div>
                    @endif
                </li>
            @endif
        @endforeach
    </ol>
@endif

@if($note->method == 'AUDIO' || $note->method == 'VIDEO')
    <p class="mb-2">The visit was conducted with the use of an interactive <b>{{$note->method}}</b> telecommunications system that permits real time communication
        between the patient and the provider. Patient consent for telehealth visit was obtained.</p>
    <?php /*
    <p class="mb-2">Originating Site: <b>{{$note->hcpCompanyPro && $note->hcpCompanyPro->company ? $note->hcpCompanyPro->company->name : '-'}}</b></p>
    <p class="mb-2">Distant Site: <b>Patient Home</b></p>
    */ ?>
@endif

