<?php
$thumbnail = $patient->profile_picture_base64;
$initials = !$thumbnail ? substr($patient->name_first, 0, 1) . substr($patient->name_last, 0, 1) : '';
$online = $patient->is_online ? 'online' : '';
$patientName = implode(', ', array_filter([$patient->name_last, $patient->name_first])) .
    ($patient->name_nickname ? ' (' . $patient->name_nickname . ')' : '');

$confirmedCell = empty($patient->cell_number) ? '-' : $patient->cell_number;
$hasConfirmedEmail = empty($patient->email_address) ? false:true;
$confirmedEmail = empty($patient->email_address) ? '-' : $patient->email_address;

$location = implode(', ', array_filter([$patient->home_address_city, $patient->home_address_state]));
$location = empty($location) ? '-' : $location;

$mcpName = $patient->mcp ? implode(', ', array_filter([$patient->mcp->name_last, $patient->mcp->name_first])) : null;
$cmName = $patient->cm ? implode(', ', array_filter([$patient->cm->name_last, $patient->cm->name_first])) : null;

$memberSince = date_diff(date_create($patient->created_at), date_create('now'))->days;
if ($memberSince > 30) $memberSince = date('F, Y', strtotime($patient->created_at));
else if ($memberSince > 1) $memberSince .= ' days ago';
else if ($memberSince === 1) $memberSince = 'yesterday';
else if ($memberSince === 0) $memberSince = 'today';

$addressParts = [];
if (!!$patient->mailing_address_line1) $addressParts[] = trim($patient->mailing_address_line1);
if (!!$patient->mailing_address_line2) $addressParts[] = trim($patient->mailing_address_line2);
$addressParts = implode(", ", $addressParts) . "<br/>";
$addressPart2 = [];
if (!!$patient->mailing_address_city) $addressPart2[] = trim($patient->mailing_address_city);
if (!!$patient->mailing_address_state) $addressPart2[] = trim($patient->mailing_address_state);
$addressParts .= implode(", ", $addressPart2);
?>
<style media="screen">
    .header-info h6 {
        font-size: 1rem !important;
        margin-bottom: 0;
    }
    .patient-header label {
        margin-bottom: 0 !important;
    }
    @media screen and (max-width:1400px){
        .header-coverage-status {
            max-width:305px;
        }
    }
</style>
<div class="px-2 pb-2 mcp-theme-1 patient-header">
    @if($patient->is_duplicate)
        <div class="alert alert-warning p-1 mb-2 border-dark mcp-theme-1 screen-only">
            <span class="text-dark">This chart is a duplicate of&nbsp;</span>
            <a class="font-weight-bold" href="/patients/view/{{ $patient->duplicateOf->uid }}">
                {{ $patient->duplicateOf->displayName() }}
            </a>
        </div>
    @endif
    <div class="d-flex justify-content-between pt-2 {{request()->route()->getName() === 'patients.view.notes.view.dashboard' ? 'sticky-note-header' : ''}}" id="patient-top-most-header">
        <div class="d-flex align-items-center header-info mb-2">

            <h6 class="font-weight-bold">{{$patientName}}</h6>
            <h6 class="ml-3">{{$patient->age_in_years}} Y {{$patient->sex}}</h6>
            <h6 class="d-inline-flex align-items-baseline ml-2">
                <span><i class="chart mr-2">#{{$patient->chart_number}}</i></span>
                <div class="on-hover-show d-inline-block on-hover-opaque">
                    <i class="fa fa-info-circle ml-1"></i>
                    <div class="on-hover-content py-2 pl-3 text-nowrap text-dark" style="left:0;right:auto;">
                        Joined
                        <?=$memberSince?>
                        @if($pro->pro_type === 'ADMIN')
                            <div class="mt-1">
                                Created by <b>{{$patient->creator ? $patient->creator->displayName() : '-'}}</b>
                            </div>
                            <div class="mt-1">
                                Created on <b>{{friendly_date_time($patient->created_at)}}</b>
                            </div>
                        @endif
                        <?php $latestMemo = $patient->latestMemo(); ?>
                        @if($latestMemo)
                            <hr class="my-2">
                            <p class="mb-1 font-weight-bold text-secondary">Last Memo: {{$latestMemo->category}}</p>
                            <div class="text-wrap mb-1">{{$latestMemo->content}}</div>
                            <div class="text-secondary text-sm mb-1">{{friendly_date_time($latestMemo->created_at)}}</div>
                            @if($latestMemo->createdBy && $latestMemo->createdBy->pro)
                                <div class="text-secondary text-sm">By {{$latestMemo->createdBy->pro->displayName()}}</div>
                            @endif
                        @endif
                    </div>
                </div>
            </h6>
            <div class="d-flex border-left pl-2 ml-2">
                <div class="mr-2">RPM: <b>{{ucwords(strtolower($patient->is_enrolled_in_rm))}}</b> {{-- correct --}}
                    @if($patient->is_enrolled_in_rm === 'NO' && $patient->why_not_enrolled_in_rm_category) {{-- correct --}}
                    <span class="text-sm">({{$patient->why_not_enrolled_in_rm_category}})</span>
                    @endif
                </div>
                <div class="mr-1">Cell. BP: <b>{{$patient->hasBPDevice()?'Yes':'No'}}</b>
                    @if($patient->most_recent_cellular_bp_sbp_mm_hg && $patient->most_recent_cellular_bp_dbp_mm_hg)
                        (<b>{{$patient->most_recent_cellular_bp_sbp_mm_hg ?: '-'}}/{{$patient->most_recent_cellular_bp_dbp_mm_hg ?: '-'}}</b>@if($patient->most_recent_cellular_bp_measurement_at), {{friendly_date_short($patient->most_recent_cellular_bp_measurement_at)}}@endif)@endif
                </div>
                <div class="mr-2">Wt.: <b>{{$patient->hasWeightScaleDevice()?'Yes':'No'}}</b>
                    @if($patient->most_recent_cellular_weight_value)
                        (<b>{{round($patient->most_recent_cellular_weight_value, 1)}}</b>@if($patient->most_recent_cellular_weight_measurement_at), {{friendly_date_short($patient->most_recent_cellular_weight_measurement_at)}}@endif)
                    @endif
                </div>
                <?php $currentCareMonth = $patient->currentCareMonth(); ?>
                @if($currentCareMonth && ($pro->pro_type === 'ADMIN' || $pro->id === $currentCareMonth->mcp_pro_id))
                    <div class="text-primary c-pointer" open-in-stag-popup mc-initer="care-month-dashboard-{{$patient->uid}}" title="Care Month: {{friendly_month($currentCareMonth->start_date)}}" popup-style="overflow-visible" href="/patients/view/{{ $patient->uid }}/care-months/view/{{$currentCareMonth->uid}}">
                        <?php $spoken = $currentCareMonth->has_anyone_interacted_with_client_about_rm_outside_note; ?>
                        <span class="">RPM comm. this mt:</span>
                        <b class="{{$spoken ? 'text-success' : ''}}">
                            {{$spoken ? 'Yes' : 'No'}}
                            @if(!$spoken)
                                <i class="fa fa-exclamation-triangle"></i>
                            @else
                                <i class="fa fa-check"></i>
                            @endif
                        </b>
                    </div>
                @endif
                <div moe class="ml-3">
                    <a href="#" start show>Edit Chart</a>
                    <form url="/api/visit/create" redir="/patients/view/{{$patient->uid}}/notes/view/[data]">
                        <p>Create a note for making changes to the chart?</p>
                        <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                        <input type="hidden" name="title" value="Note">
                        <input type="hidden" name="effectiveDate" value="{{date('Y-m-d')}}">
                        <input type="hidden" name="hcpProUid" value="{{$pro->uid}}">
                        <input type="hidden" name="visitTemplateUid" value="{{config('app.nonMedicalVisitTemplateUid')}}">
                        <input type="hidden" name="newOrFuOrNa" value="FU">
                        <input type="hidden" name="noteContactMethod" value="AUDIO">
                        <input type="hidden" name="isNonMedical" value="1">
                        <div class="d-flex">
                            <button submit class="btn btn-sm btn-primary">Yes</button>
                            <button cancel class="ml-2 btn btn-default border">No</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="d-flex align-items-start">
            <div class="d-inline-flex align-items-center flex-wrap">
                <div class="ml-1 mr-3 d-inline-flex align-items-baseline">
                    <i class="fa fa-envelope mr-1"></i>
                    @if($hasConfirmedEmail)
                        {{$confirmedEmail}}
                        <div moe relative class="ml-2">
                            <a href="#" start show><i class="fa fa-edit"></i></a>
                            <form url="/api/client/putNewEmailAddress" right>
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <label class="text-sm text-secondary mb-1">Email Address</label>
                                    <input type="email" name="newEmailAddress" class="form-control form-control-sm" value="{{$confirmedEmail}}" required>
                                </div>
                                <div>
                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                </div>
                            </form>
                        </div>
                    @else
                        @if($patient->is_email_address_waived)
                            <div class="">
                                Email Waived
                                @if($patient->email_address_waive_memo)
                                    <span class="text-secondary text-sm">({{$patient->email_address_waive_memo}})</span>
                                @endif
                            </div>
                            <div moe relative class="ml-2">
                                <a href="#" start show class="text-nowrap">Undo Waive</a>
                                <form url="/api/client/undoMarkEmailAddressAsWaived" right>
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        Undo waive?
                                    </div>
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @else
                            <div class="text-danger font-weight-bold">
                                No email
                            </div>
                            <div moe relative class="ml-2">
                                <a href="#" start show>Set</a>
                                <form url="/api/client/putNewEmailAddress" right>
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        <label class="text-sm text-secondary mb-1">Email Address</label>
                                        <input type="email" name="newEmailAddress" class="form-control form-control-sm" required>
                                    </div>
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                    </div>
                                </form>
                            </div>
                            <div moe relative class="ml-2">
                                <a href="#" start show>Waive</a>
                                <form url="/api/client/markEmailAddressAsWaived" right>
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        <label class="text-sm text-secondary mb-1">Waive Memo</label>
                                        <textarea name="memo" class="form-control form-control-sm" rows="3"></textarea>
                                    </div>
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @endif
                    @endif
                </div>
            </div>

            <div class="d-inline-flex screen-only">
                <div class="aligned-icon text-primary">
                    <i class="fa fa-link" aria-hidden="true"></i>
                </div>
                <?php $numLinkedAccounts = $patient->linkedAccounts ? count($patient->linkedAccounts) : 0; ?>
                <a href="{{route('patients.view.accounts', ['patient' => $patient])}}">
                    Accounts ({{$numLinkedAccounts}})
                </a>
            </div>

        </div>
    </div>

    <?php $hasCoverageColumn = !$patient->getPrimaryCoverage() || $patient->getPrimaryCoverageStatus() !== 'YES'; ?>

    <div class="flex-header text-dark">
        <div class="d-flex bg-light p-2 border">
            <div class="position-relative ml-2">
                <div class="screen-only">
                    <div>
                        <label class="{{ $patient->mcp && $patient->mcp->is_hcp ? '':'text-danger' }}">MCP:</label> <span class="{{ $patient->mcp && $patient->mcp->is_hcp ? '':'text-danger' }}">{{$mcpName}}</span>
                        @if($patient->has_mcp_done_onboarding_visit === 'YES')
                            <i class="fa fa-check text-sm" title="MCP Onboarding Visit Completed"></i>
                        @endif
                        @if($patient->has_mcp_done_onboarding_visit !== 'YES' && $pro->pro_type == 'ADMIN')
                            <div moe class="ml-2 hide-inside-popup">
                                <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                                @include('app.patient.partials.put-mcp-form')
                            </div>
                            @if($patient->mcp)
                                <div moe class="ml-2 hide-inside-popup">
                                    <a start show><i class="fa fa-times on-hover-opaque"></i></a>
                                    <form url="/api/client/removeMcp" class="mcp-theme-1">
                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
                                        <div class="mb-2">
                                            <label class="text-secondary text-sm">Remove MCP Pro</label>

                                        </div>
                                        <div>
                                            <button submit class="btn btn-sm btn-primary mr-1">Submit
                                            </button>
                                            <button cancel class="btn btn-sm btn-default border">
                                                Cancel
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        @endif
                        @if($patient->mcp && $pro->pro_type === 'ADMIN' && $pro->uid !== $patient->mcp->uid)
                            <form action="{{route('process-log-in-as')}}?redir={{request()->url()}}" onsubmit="window.top.localStorage.currentProUid = '{{$patient->mcp->uid}}';" method="POST" target="_top" class="d-inline-block">
                                @csrf
                                <input type="hidden" name="proUid" value="{{$patient->mcp->uid}}">
                                <button class="bg-transparent text-primary border-0 text-sm"><i class="fa fa-user on-hover-opaque"></i></button>
                            </form>
                        @endif
                        @if($patient->mcp && !$patient->mcp->is_hcp)
                            <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patient->mcp->name_first }} is no longer HCP. Reassign.</small>
                        @endif
                    </div>
                    <div>
                        @if($patient->defaultNaPro || $pro->pro_type == 'ADMIN')
                        <label>CC:</label> {{$patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '-' }}
                        @endif
                        @if($pro->pro_type == 'ADMIN')
                            <div moe class="ml-2 hide-inside-popup">
                                <a start show><i class="fa fa-edit on-hover-opaque text-sm"></i></a>
                                <form url="/api/client/putDefaultNaPro" class="mcp-theme-1">
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm">Care Coordinator</label>
                                        <select provider-search data-pro-uid="{{ @$patient->defaultNaPro->uid }}" name="defaultNaProUid" class="form-control form-control-sm">
                                            <option value=""> --select--</option>
                                            @foreach($pros as $iPro)
                                                <option value="{{$iPro->uid}}" {{ $patient->pcp && $iPro->uid === $patient->pcp->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-1">Submit
                                        </button>
                                        <button cancel class="btn btn-sm btn-default border">
                                            Cancel
                                        </button>
                                    </div>
                                </form>
                            </div>
                            @if($patient->pcp)
                                <div moe class="ml-2 hide-inside-popup">
                                    <a start show><i class="fa fa-times"></i></a>
                                    <form url="/api/client/removeDefaultNaPro" class="mcp-theme-1">
                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
                                        <div class="mb-2">
                                            <label class="text-secondary text-sm">Remove Care Coordinator</label>

                                        </div>
                                        <div>
                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        @endif
                        @if($patient->defaultNaPro && $pro->pro_type === 'ADMIN' && $pro->uid !== $patient->defaultNaPro->uid)
                            <form action="{{route('process-log-in-as')}}?redir={{request()->url()}}" onsubmit="window.top.localStorage.currentProUid = '{{$patient->defaultNaPro->uid}}';" method="POST" target="_top" class="d-inline-block">
                                @csrf
                                <input type="hidden" name="proUid" value="{{$patient->defaultNaPro->uid}}">
                                <button class="bg-transparent text-primary border-0 text-sm"><i class="fa fa-user on-hover-opaque"></i></button>
                            </form>
                        @endif
                    </div>
                    @if($patient->rd || $pro->pro_type == 'ADMIN')
                    <div class="mb-1">
                        <label>RD:</label> {{ $patient->rd ? $patient->rd->displayName() : '-'}}
                        @if($pro->pro_type === 'ADMIN')
                        <div moe class="ml-2 hide-inside-popup">
                            <a start show><i class="fa fa-edit on-hover-opaque text-sm"></i></a>
                            <form url="/api/client/putRdPro" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <label class="mb-1 text-secondary text-sm">RD Pro</label>
                                    <select class="form-control form-control-sm" name="rdProUid" provider-search provider-type="rd">
                                        <option value="">--select--</option>
                                    </select>
                                </div>
                                <div>
                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                </div>
                            </form>
                        </div>
                        @if($patient->rd)
                          <form action="{{route('process-log-in-as')}}?redir={{request()->url()}}" onsubmit="window.top.localStorage.currentProUid = '{{$patient->rd->uid}}';" method="POST" target="_top" class="d-inline-block">
                            @csrf
                            <input type="hidden" name="proUid" value="{{$patient->rd->uid}}">
                            <button class="bg-transparent text-primary border-0 text-sm"><i class="fa fa-user on-hover-opaque"></i></button>
                          </form>
                          @endif
                        @endif
                    </div>
                    @endif
                    <div class="d-flex">
                        <div>
                            <span>Status:</span>
                            {{$patient->client_engagement_status_category ? ucwords(strtolower(str_replace('_', ' ', $patient->client_engagement_status_category == 'DUMMY' ? 'Test Chart' : $patient->client_engagement_status_category))) : '-'}}

                            @if($pro->pro_type == 'ADMIN')
                                <div moe class="ml-2 hide-inside-popup">
                                    <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                                    <form url="/api/client/updateClientEngagementAssessmentStatus" class="mcp-theme-1"
                                          target="#patient-header-content">
                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
                                        <div class="mb-2">
                                            <label class="mb-1 text-secondary text-sm">Status</label>
                                            <select name="category" class="form-control form-control-sm">
                                                <option value=""> --select--</option>
                                                <option {{ $patient->client_engagement_status_category === 'ACTIVE' ? 'selected' : '' }} value="ACTIVE">
                                                    Active
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'INACTIVE' ? 'selected' : '' }} value="INACTIVE">
                                                    Inactive
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'ENTRY_ERROR' ? 'selected' : '' }} value="ENTRY_ERROR">
                                                    Entry Error
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'DUMMY' ? 'selected' : '' }} value="DUMMY">
                                                    Test Chart
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'DECEASED' ? 'selected' : '' }} value="DECEASED">
                                                    Deceased
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'DUPLICATE' ? 'selected' : '' }} value="DUPLICATE">
                                                    Duplicate
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'NO_LONGER_INTERESTED' ? 'selected' : '' }} value="NO_LONGER_INTERESTED">
                                                    No Longer Interested
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'BAD_RECORD' ? 'selected' : '' }} value="BAD_RECORD">
                                                    Bad Record
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'NO_LONGER_ELIGIBLE' ? 'selected' : '' }} value="NO_LONGER_ELIGIBLE">
                                                    No Longer Eligible
                                                </option>
                                                <option {{ $patient->client_engagement_status_category === 'NON_RESPONSIVE' ? 'selected': ''}} value="NON_RESPONSIVE">
                                                    Non-responsive
                                                </option>
                                            </select>
                                        </div>
                                        <div class="mb-2">
                                            <label class="mb-1 text-secondary text-sm">Memo</label>
                                            <textarea class="form-control form-control-sm" name="memo"></textarea>
                                        </div>
                                        <div>
                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        </div>
                        @include('app.patient.partials.quick-actions-buttons')
                    </div>
                    @if($pro->pro_type == 'ADMIN' && $patient->clientRepFollowUp && $patient->clientRepFollowUp->status === 'SCHEDULED')
                        <div>
                            <span>Next FU:</span>
                            <span>{{friendly_date($patient->clientRepFollowUp->next_follow_up_date)}} • {{$patient->clientRepFollowUp->pro->displayName()}}</span>
                        </div>
                    @endif
                </div>

                @if($hasCoverageColumn)
                    @include('layouts.patient-header-meta-info')
                @endif
            </div>
        </div>

        @if($hasCoverageColumn)
            <div class="d-flex bg-light p-2 border header-coverage-status" style="max-width: 305px;">
                @include('app.patient.coverage-status')
            </div>
        @else
            <div class="d-flex bg-light p-2 border header-coverage-status" style="max-width: 350px;">
                @include('layouts.patient-header-meta-info')
            </div>
        @endif
        <div class="bg-light p-2 border d-none">
            @if($patient->mcp && $patient->mcp->id === $pro->id || $pro->pro_type == 'ADMIN')
                <div>
                    <label>Status (mcp):</label>
                    <span>{!! $patient->mcpEngagementAssessmentStatus && $patient->mcpEngagementAssessmentStatus->status_category ? ucwords(strtolower(str_replace('_', ' ', $patient->mcpEngagementAssessmentStatus->status_category))) : '<span class="text-danger">Not
            Set</span>' !!}</span>
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-edit on-hover-opaque text-sm"></i></a>
                        <form url="/api/client/updateMcpEngagementAssessmentStatus" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Category </label>
                                <select name="category" class="form-control form-control-sm">
                                    <option value="NULL">--</option>
                                    <option value="ACTIVE">ACTIVE</option>
                                    <option value="INACTIVE">INACTIVE</option>
                                    <option value="ENTRY_ERROR">ENTRY_ERROR</option>
                                    <option value="DUMMY">DUMMY</option>
                                    <option value="DECEASED">DECEASED</option>
                                    <option value="DUPLICATE">DUPLICATE</option>
                                    <option value="NO_LONGER_INTERESTED">NO_LONGER_INTERESTED</option>
                                    <option value="BAD_RECORD">BAD_RECORD</option>
                                    <option value="NON_RESPONSIVE">Non-responsive</option>
                                </select>
                            </div>
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Memo</label>
                                <input type="text" name="memo" class="form-control form-control-sm">
                            </div>
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Detail</label>
                                <input type="text" name="detail" class="form-control form-control-sm">
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>
                </div>
            @endif

            @if($patient->defaultNaPro && $patient->defaultNaPro->id === $pro->id || $pro->pro_type == 'ADMIN')
                <div>
                    <label>Status (cc):</label>
                    <span>{!! $patient->defaultNaEngagementAssessmentStatus && $patient->defaultNaEngagementAssessmentStatus->status_category ? ucwords(strtolower(str_replace('_', ' ', $patient->defaultNaEngagementAssessmentStatus->status_category))) : '<span
            class="text-danger">Not Set</span>' !!}</span>
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-edit on-hover-opaque text-sm"></i></a>
                        <form url="/api/client/updateDefaultNaEngagementAssessmentStatus" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Category </label>
                                <select name="category" class="form-control form-control-sm">
                                    <option value="NULL">--</option>
                                    <option value="ACTIVE">ACTIVE</option>
                                    <option value="INACTIVE">INACTIVE</option>
                                    <option value="ENTRY_ERROR">ENTRY_ERROR</option>
                                    <option value="DUMMY">DUMMY</option>
                                    <option value="DECEASED">DECEASED</option>
                                    <option value="DUPLICATE">DUPLICATE</option>
                                    <option value="NO_LONGER_INTERESTED">NO_LONGER_INTERESTED</option>
                                    <option value="BAD_RECORD">BAD_RECORD</option>
                                    <option value="NON_RESPONSIVE">Non-responsive</option>
                                </select>
                            </div>
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Memo</label>
                                <input type="text" name="memo" class="form-control form-control-sm">
                            </div>
                            <div class="mb-2">
                                <label class="text-sm text-secondary mb-1">Detail</label>
                                <input type="text" name="detail" class="form-control form-control-sm">
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
                            </div>
                        </form>
                    </div>
                </div>
            @endif
        </div>

        <div class="bg-light p-2 border ml-auto" style="max-width: 215px;">
            <div>
                <div class="d-flex">
                    <label class="">Sticky Note:</label>
                    @include('app.patient.partials.sticky-notes-history')
                    <div moe relative wide class="ml-2 hide-inside-popup">
                        <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                        <form url="/api/client/updateStickyNote" class="mcp-theme-1" right>
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-secondary text-sm">Sticky Note</label>
                                <textarea name="stickyNote" class="form-control" rows="8" cols="80">{{$patient->sticky_note}}</textarea>
                            </div>
                            <div>
                                <button submit class="btn btn-sm btn-primary mr-1">Submit
                                </button>
                                <button cancel class="btn btn-sm btn-default border">
                                    Cancel
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                @if($patient->sticky_note)
                    <?php
                    $patientRecentStickyNote = App\Models\ClientStickyNote::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->limit(1)->first();
                    ?>
                    <div class="">
                        <span class="d-block text-secondary">{{ limit_string_length($patient->sticky_note ?? '-', 60) }}
                            @include('app.patient.partials.sticky-notes-view')
                        </span>
                        <div>
                            <small class="text-muted">By: {{ $patient->stickyNoteUpdatedBySession? $patient->stickyNoteUpdatedBySession->pro->displayName() : '-'  }} • At: {{ friendlier_date($patient->sticky_note_updated_at) }}</small>
                        </div>
                    </div>
                @endif
            </div>
        </div>
        <div class="bg-light p-2 border">
            <ul class="vbox align-self-start patient-header-address mb-0">
                <li class="d-flex align-items-start">
                    <span class="aligned-icon">
                        <i class="fa fa-map-marker-alt" aria-hidden="true"></i>
                    </span>
                    <div class="position-relative">
                        <?php
                        $addressParts = [];
                        if (!!$patient->mailing_address_line1) $addressParts[] = trim($patient->mailing_address_line1);
                        if (!!$patient->mailing_address_line2) $addressParts[] = trim($patient->mailing_address_line2);
                        $addressParts = implode(", ", $addressParts) . "<br/>";
                        $addressPart2 = [];
                        if (!!$patient->mailing_address_city) $addressPart2[] = trim($patient->mailing_address_city);
                        if (!!$patient->mailing_address_state) $addressPart2[] = trim($patient->mailing_address_state);
                        $addressParts .= implode(", ", $addressPart2);
                        echo $addressParts;
                        ?>
                        {{ $patient->mailing_address_zip ? $patient->mailing_address_zip : '' }}
                        @if($patient->mailing_address_memo)
                            <span class="position-relative c-pointer text-center stag-tooltip ml-2">
                                <i class="fa fa-info-circle"></i>
                                <div class="position-absolute bg-white border rounded p-2 stag-tooltip-content">
                                    <div class="text-left font-weight-bold pb-1">Special Instructions</div>
                                    <div class="text-left font-weight-normal">{{$patient->mailing_address_memo}}</div>
                                </div>
                            </span>
                        @endif
                    </div>
                </li>
                @if($patient->cell_number)
                    <li class="">
                        <span class="aligned-icon">
                            <i class="fa fa-phone-alt" aria-hidden="true"></i>
                        </span>
                        {{$patient->cell_number}}
                        <span class="small text-secondary ml-1">
                            {{ $patient->cell_number_memo ? '(' . $patient->cell_number_memo . ')' : '' }}
                        </span>
                    </li>
                @endif
                @if($patient->phone_home)
                    <li class="">
                        <span class="aligned-icon"><i class="fa fa-home" aria-hidden="true"></i></span>
                        {{$patient->phone_home}}
                    </li>
                @endif
            </ul>

        </div>

    </div>
</div>
@if($pro->pro_type === 'ADMIN')
    <?php
    $missingDefaultMCPCPAndLocation = false;
    if ($patient->is_active &&
        (!$patient->client_engagement_status_category || $patient->client_engagement_status_category === 'ACTIVE') &&
        (!$patient->default_mcp_company_pro_payer_id || !$patient->default_mcp_company_location_id)
    ) {
        $missingDefaultMCPCPAndLocation = true;
    }
    ?>
    @if($missingDefaultMCPCPAndLocation)
        <div class="mx-2 mb-2 alert alert-warning p-2 mcp-theme-1 d-flex align-items-baseline rounded-0 border-warning">
            <i class="fa fa-exclamation-triangle"></i>
            <span class="ml-2 font-weight-bold">This patient is missing the default MCP company pro and/or location!</span>
            <a href="{{route('patients.view.settings', ['patient' => $patient])}}" class="ml-2 font-weight-bold">Settings</a>
        </div>
    @endif
@endif

<?php
if($patient->latest_vitals_json) {
try {
$parsed = json_decode($patient->latest_vitals_json);
?>
<div class="mx-2 mb-2 p-2 mcp-theme-1 rounded-0 border bg-aliceblue">
    <div class="d-flex align-items-baseline flex-wrap">
        <div class="mr-2 font-weight-bold text-secondary">Latest Vitals @if($patient->latest_vitals_set_at)({{friendly_date($patient->latest_vitals_set_at)}})@endif:</div>
        <?php $hasPre = false; ?>
        @if($parsed->heightInInches)
            <div>Height {{toFeetAndInches($parsed->heightInInches, "'", '"')}}</div>
            <?php $hasPre = true; ?>
        @endif
        @if($parsed->weightPounds)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>Weight {{$parsed->weightPounds}} lbs</div>
        @endif
        @if($parsed->bmi)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>BMI {{$parsed->bmi}}</div>
        @endif
        @if($parsed->temperatureF)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>Temp. {{$parsed->bmi}} F</div>
        @endif
        @if($parsed->systolicBP && $parsed->diastolicBP)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>BP {{$parsed->systolicBP}}/{{$parsed->diastolicBP}}</div>
        @endif
        @if($parsed->pulseRatePerMinute)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>Pulse {{$parsed->pulseRatePerMinute}}/m</div>
        @endif
        @if($parsed->respirationRatePerMinute)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>Resp. {{$parsed->respirationRatePerMinute}}/m</div>
        @endif
        @if($parsed->smokingStatus)
            @if($hasPre)<span class="mr-2">,</span>@endif
            <div>{{$parsed->smokingStatus}}</div>
        @endif
    </div>
</div>
<?php
}
catch (Exception $ex) {}
}
?>
