<?php
/** @var App\Models\CareMonth $careMonth */
/** @var App\Models\Pro $pro */

    $leanView = request()->input('popupmode') && request()->input('fromNoteUid');

?>

@extends($leanView ? 'layouts.empty' : 'layouts.patient')

@section($leanView ? 'content' : 'inner-content')

    <div class="popup-content-container {{$leanView ? 'px-3 mx-1 pb-3' : ''}}">

    <?php
    $shortCutsObject = [];
    foreach ($pro->allShortcuts() as $shortcut) {

        // %replaceables%
        $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
        $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
        $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);

        $shortCutsObject[] = [
            "name" => $shortcut->shortcut,
            "value" => $shortcut->text
        ];
    }

    $calendarID = rand(10000, 99999);
    ?>
    <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>

    @if($patient->has_mcp_done_onboarding_visit !== 'YES')
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                    <div class="text-dark d-inline-flex align-items-center mt-2">
                        <span class="mr-2">
                            <i class="fa fa-exclamation-triangle"></i>
                            MCP Onboarding Visit Pending
                        </span>
                        @include('app.patient.care-month.care-month-update-mcp-onboarding-visit-info')
                    </div>
                </div>
            </h6>
        </div>
    @else

    <div id="care-month-container-{{$patient->uid}}">

        @if(!$leanView)
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold font-size-14">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                </div>
            </h6>
        </div>

        @endif

        <hr class="m-negator mb-0 {{ $leanView ? 'mt-0' : '' }}">

        <div class="row m-negator bg-light py-1 text-sm-incl-children">
            <div class="col-3 pl-3-5">
                <div class="d-flex align-items-baseline">
                    <span class="text-secondary">MCP:</span>
                    <span class="ml-1">{{ $careMonth->mcp ? $careMonth->mcp->displayName() : '-' }}</span>
                    @if($pro->pro_type === 'ADMIN')
                    <div moe class="ml-2 hide-inside-popup flex-grow-1">
                        <a start show><i class="fa fa-edit"></i></a>
                        <form url="/api/careMonth/assignMcpPro" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                            <div class="mb-2">
                                <label class="text-secondary text-sm">Physician Pro</label>
                                <select provider-search data-pro-uid="{{ $careMonth->mcp ? $careMonth->mcp->uid : '' }}"
                                        name="mcpProUid"
                                        class="form-control form-control-sm">
                                    <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>
                    @endif
                </div>
            </div>
            <div class="col-3">
                <span class="text-secondary">RMM:</span>
                <span class="text-nowrap">{{ $careMonth->rmmPro ? $careMonth->rmmPro->displayName() : '-' }}</span>
                @if($pro->pro_type === 'ADMIN')
                <div moe class="ml-2 hide-inside-popup flex-grow-1">
                    <a start show><i class="fa fa-edit"></i></a>
                    <form url="/api/careMonth/assignRmmPro" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <div class="mb-2">
                            <label class="text-secondary text-sm">RMM Pro</label>
                            <select provider-search data-pro-uid="{{ $careMonth->rmmPro ? $careMonth->rmmPro->uid : '' }}"
                                    name="rmmProUid"
                                    class="form-control form-control-sm">
                                <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>
                @endif
            </div>
            <div class="col-3">
                <span class="text-secondary">RME:</span>
                <span class="text-nowrap">{{ $careMonth->rmePro ? $careMonth->rmePro->displayName() : '-' }}</span>
                @if($pro->pro_type === 'ADMIN')
                <div moe class="ml-2 hide-inside-popup flex-grow-1">
                    <a start show><i class="fa fa-edit"></i></a>
                    <form url="/api/careMonth/assignRmePro" class="mcp-theme-1">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <div class="mb-2">
                            <label class="text-secondary text-sm">RME Pro</label>
                            <select provider-search data-pro-uid="{{ $careMonth->rmePro ? $careMonth->rmePro->uid : '' }}"
                                    name="rmeProUid"
                                    class="form-control form-control-sm">
                                <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>
                @endif
            </div>
        </div>

        <hr class="m-negator mt-0">

        <?php
        $rmBills = $careMonth->getBillsOfType('RM');
        $activeRMBill = false;
        $cancelledRMBills = new \Illuminate\Support\Collection();
        foreach ($rmBills as $rmBill) {
            if(!$rmBill->is_cancelled && $careMonth->rm_bill_id === $rmBill->id) {
                $activeRMBill = $rmBill;
            }
            else if($rmBill->is_cancelled) {
                $cancelledRMBills->add($rmBill);
            }
        }
        ?>

        <?php $vitalLabels = ['Ht. (in.)','Wt. (lbs.)','Temp. (F)','Pulse','Resp.','Pulse Ox.','SBP','DBP','Smoking Status', 'BMI']; ?>

        <div class="row">
            <div class="col-12">
                <div class="mt-0">

                    <div class="mb-3">
                        <div class="d-flex align-items-stretch">

                            <div class="border mr-3 px-3 pb-2 bg-light">
                                <!-- last visit -->
                                <div class="mt-2">
                                    <?php $daysDiff = -1; ?>
                                    @if($patient->most_recent_completed_mcp_note_date)
                                        <?php
                                        $careMonthLastDay = date_add(date_create($careMonth->start_date), date_interval_create_from_date_string("1 month"));
                                        $careMonthLastDay = date_sub($careMonthLastDay, date_interval_create_from_date_string("1 day"));
                                        $daysDiff = date_diff($careMonthLastDay, date_create($careMonth->most_recent_mcp_note_date))->days;
                                        ?>
                                    @endif
                                    <span class="font-weight-bold text-secondary">Last Visit:</span>
                                    <b class="{{$daysDiff === -1 ? 'text-secondary' : ($daysDiff <= config('app.maxDaysSinceLastVisit') ? 'text-success' : 'text-warning-mellow')}}">
                                        {{friendly_date($careMonth->most_recent_mcp_note_date)}}
                                        @if($daysDiff !== -1)
                                            @if($daysDiff > config('app.maxDaysSinceLastVisit'))
                                                <i class="fa fa-exclamation-triangle"></i>
                                                <span class="ml-1 text-secondary text-sm font-weight-normal">({{$daysDiff}} days ago)</span>
                                            @else
                                                <i class="fa fa-check"></i>
                                            @endif
                                        @endif
                                    </b>
                                </div>

                                <!-- days with meas. -->
                                <div class="mt-2">
                                    <span class="font-weight-bold text-secondary">Days with meas.:</span>
                                    <b class="{{$careMonth->number_of_days_with_remote_measurements >= 16 ? 'text-success' : 'text-warning-mellow'}}">
                                        {{$careMonth->number_of_days_with_remote_measurements}}
                                        @if($careMonth->number_of_days_with_remote_measurements >= 16)
                                            <i class="fa fa-check"></i>
                                        @else
                                            <i class="fa fa-exclamation-triangle"></i>
                                        @endif
                                        <span class="ml-1 text-secondary text-sm font-weight-normal">(16 needed)</span>
                                    </b>
                                    @if($careMonth->number_of_days_with_remote_measurements < 16)
                                        <div moe relative class="ml-2">
                                            <a href="#" start show class="text-sm">SMS Patient</a>
                                            <form url="/api/clientSms/createOutgoing" right="" class="mcp-theme-1" noreload="" style="display: none;">
                                                <input type="hidden" name="uid" value="{{ $patient->uid }}">
                                                <div class="mb-2">
                                                    <label for="" class="text-sm text-secondary mb-1">Cell Number</label>
                                                    <input type="text" class="form-control form-control-sm" name="cellNumber" value="{{$patient->cell_number}}">
                                                </div>
                                                <div class="mb-2">
                                                    <label for="" class="text-sm text-secondary mb-1">Message</label>
                                                    <textarea rows="5" class="form-control form-control-sm" name="message">Hi! This is {{$pro->displayName(true)}}, from Cardio 1st. Please check your blood pressure.</textarea>
                                                </div>
                                                <div class="d-flex align-items-center">
                                                    <button class="btn btn-sm btn-primary mr-2" submit="">Send</button>
                                                    <button class="btn btn-sm btn-default mr-2 border" cancel="">Cancel</button>
                                                </div>
                                            </form>
                                        </div>
                                    @endif
                                </div>
                                @if($careMonth->showMeasurementDaysWarning())
                                    <?php
                                    $moreDays = 16 - $careMonth->number_of_days_with_remote_measurements;
                                    if($moreDays < 0) $moreDays = 0;
                                    ?>
                                    @if($moreDays > 0)
                                        <div class="alert alert-warning p-2 mt-1">
                                            Need <b>{{$moreDays}} more day{{$moreDays !== 1 ? 's' : ''}}</b> with measurements before RM becomes billable.
                                        </div>
                                    @endif
                                @endif

                                {{-- inter. --}}
                                <div class="mt-2">
                                    <?php $spoken = $careMonth->has_mcp_interacted_with_client_about_rm; ?>
                                    <span class="font-weight-bold text-secondary">MCP spoke to patient:</span>
                                    <b class="{{$spoken ? 'text-success' : 'text-warning-mellow'}}">
                                        {{$spoken ? 'Yes' : 'No'}}
                                        @if(!$spoken)
                                            <i class="fa fa-exclamation-triangle"></i>
                                        @else
                                            <i class="fa fa-check"></i>
                                        @endif
                                    </b>
                                </div>
                            </div>

                            <div class="border mr-3 px-3 pb-2 bg-light">
                                <!-- mins billes -->
                                <div class="mt-2">
                                    <?php
                                    $minsBilled = 0;
                                    if($careMonth->mcp && $pro->id === $careMonth->mcp->id) {
                                        $minsBilled = $careMonth->rm_total_time_in_seconds_by_mcp;
                                    }
                                    elseif($careMonth->rmm && $pro->id === $careMonth->rmm->id) {
                                        $minsBilled = $careMonth->rm_total_time_in_seconds_by_rmm_pro;
                                    }
                                    elseif($careMonth->rme && $pro->id === $careMonth->rme->id) {
                                        $minsBilled = $careMonth->rm_total_time_in_seconds_by_rme_pro;
                                    }elseif($pro->pro_type == 'ADMIN') {
                                        $minsBilled = $careMonth->rm_total_time_in_seconds;
                                    }

                                    $minsBilled = floor($minsBilled / 60);
                                    ?>

                                    @if($pro->pro_type == 'ADMIN')
                                        <span class="font-weight-bold text-secondary">Mins. billed:</span>
                                    @else
                                        <span class="font-weight-bold text-secondary">Mins. I have billed:</span>
                                    @endif

                                    <b class="{{$minsBilled >= 20 ? 'text-success' : 'text-warning-mellow'}}">
                                        {{$minsBilled}}
                                        @if($minsBilled < 20)
                                            <i class="fa fa-exclamation-triangle"></i>
                                        @else
                                            <i class="fa fa-check"></i>
                                        @endif
                                        <span class="ml-1 text-secondary text-sm font-weight-normal">(20 needed)</span>
                                    </b>
                                    <span class="mx-2 text-secondary">|</span>
                                    @include('app.practice-management.care_month_add_entry_form', ['right' => true])
                                </div>

                                {{-- mcp billing --}}
                                @if($performer->pro->pro_type == 'ADMIN' || $careMonth->mcp && $pro->id === $careMonth->mcp->id)
                                    <div class="mt-2 d-flex align-items-baseline">
                                        @if($performer->pro->pro_type == 'ADMIN')
                                            <span class="font-weight-bold text-secondary mr-1">Billing (MCP):</span>
                                        @else
                                            <span class="font-weight-bold text-secondary mr-1">Billing:</span>
                                        @endif
                                        <div>
                                            @if($careMonth->mcpRmGenericBill == null )
                                                @php
                                                    $rpmBillability = $careMonth->calculateBillabilityForMcp();
                                                @endphp
                                                @if(!$rpmBillability['billable'])
                                                    <div class="alert alert-info">{{$rpmBillability['reason']}}</div>
                                                @else
                                                    <div moe relative class="d-inline-block">
                                                        <a class="font-weight-bold" href="" show start>Bill ${{$rpmBillability['amount']}}</a>
                                                        <form url="/api/careMonth/generateRmGenericBillForMcpAndAutoSign">
                                                            <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                                            <p>Bill ${{$rpmBillability['amount']}} for this care month?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-success btn-sm" submit>Bill &amp; Sign</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                @endif
                                            @else
                                                <div class="font-weight-bold text-success d-inline-flex align-items-baseline">
                                                    <i class="fa fa-check mr-1"></i>
                                                    <span>Billed: ${{$careMonth->mcpRmGenericBill->generic_pro_expected_payment_amount}}</span>
                                                    @if($careMonth->mcpRmGenericBill->is_signed_by_generic_pro)
                                                        <span class="text-success ml-1 text-sm">(Signed)</span>
                                                    @else
                                                        <div moe relative class="d-inline-block text-sm ml-2">
                                                            <a class="font-weight-bold" href="" show start>Sign</a>
                                                            <form url="/api/bill/signAsGenericPro" right>
                                                                <input type="hidden" name="uid" value="{{$careMonth->mcpRmGenericBill->uid}}">
                                                                <p>Sign this bill?</p>
                                                                <div class="mb-0">
                                                                    <button class="btn btn-success btn-sm" submit>Sign</button>
                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    @endif
                                                    <div moe relative class="d-inline-block text-sm ml-2">
                                                        <a class="font-weight-normal text-danger" href="" show start>Cancel</a>
                                                        <form url="/api/bill/markCancelled" right>
                                                            <input type="hidden" name="uid" value="{{$careMonth->mcpRmGenericBill->uid}}">
                                                            <p class="text-dark font-weight-normal">Cancel this bill?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-primary btn-sm" submit>Cancel</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                @endif

                                {{-- rmm billing --}}
                                @if($performer->pro->pro_type == 'ADMIN' || $careMonth->rmmPro && $pro->id === $careMonth->rmmPro->id)
                                    <div class="mt-2 d-flex align-items-baseline">
                                        @if($performer->pro->pro_type == 'ADMIN')
                                            <span class="font-weight-bold text-secondary mr-1">Billing (RMM):</span>
                                        @else
                                            <span class="font-weight-bold text-secondary mr-1">Billing:</span>
                                        @endif
                                        <div>
                                            @if($careMonth->rmmRmGenericBill == null )
                                                @php
                                                    $rpmBillability = $careMonth->calculateBillabilityForRmm();
                                                @endphp
                                                @if(!$rpmBillability['billable'])
                                                    <div class="font-weight-bold">{{$rpmBillability['reason']}}</div>
                                                @else
                                                    <div moe relative class="d-inline-block">
                                                        <a class="font-weight-bold" href="" show start>Bill ${{$rpmBillability['amount']}}</a>
                                                        <form url="/api/careMonth/generateRmGenericBillForRmmAndAutoSign">
                                                            <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                                            <p>Bill ${{$rpmBillability['amount']}} for this care month?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-success btn-sm" submit>Bill &amp; Sign</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                @endif
                                            @else
                                                <div class="font-weight-bold text-success d-inline-flex align-items-baseline">
                                                    <i class="fa fa-check mr-1"></i>
                                                    <span>Billed: ${{$careMonth->rmmRmGenericBill->generic_pro_expected_payment_amount}}</span>
                                                    @if($careMonth->rmmRmGenericBill->is_signed_by_generic_pro)
                                                        <span class="text-success ml-1 text-sm">(Signed)</span>
                                                    @else
                                                        <div moe relative class="d-inline-block text-sm ml-2">
                                                            <a class="font-weight-bold" href="" show start>Sign</a>
                                                            <form url="/api/bill/signAsGenericPro" right>
                                                                <input type="hidden" name="uid" value="{{$careMonth->rmmRmGenericBill->uid}}">
                                                                <p>Sign this bill?</p>
                                                                <div class="mb-0">
                                                                    <button class="btn btn-success btn-sm" submit>Sign</button>
                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    @endif
                                                    <div moe relative class="d-inline-block text-sm ml-2">
                                                        <a class="font-weight-normal text-danger" href="" show start>Cancel</a>
                                                        <form url="/api/bill/markCancelled" right>
                                                            <input type="hidden" name="uid" value="{{$careMonth->rmmRmGenericBill->uid}}">
                                                            <p class="text-dark font-weight-normal">Cancel this bill?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-primary btn-sm" submit>Yes</button>
                                                                <button class="btn btn-default border btn-sm" cancel>No</button>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endif
                                        </div>
                                    </div>
                                @endif
                            </div>

                            <div class="border mr-3 px-3 pb-2 bg-light">

                                {{-- rm reasons --}}
                                <div class="mt-2">
                                    <div class="mb-2">
                                        @include('app/patient/care-month/rm-reasons')
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr class="m-neg-4 my-3">

                    <div class="mb-2">
                        <h6 class="mb-3 font-weight-bold text-dark">Measurements</h6>
                        <div class="row">
                            <div class="col-7">
                                <div class="d-flex align-items-baseline mb-3" tab-links>
                                    <a class="tab-link-active" href="#" tab-link="measurements-graph">Graph</a>
                                    <a class="" href="#" tab-link="measurements-calendar">Calendar</a>
                                    @if($performer->pro->pro_type == 'ADMIN')
                                        <a class="" href="#" tab-link="measurements-admin">Admin</a>
                                    @endif
                                </div>

                                <div class="cm-tab border pr-4" tab-key="measurements-graph">
                                    @include('app.patient.care-month._vitals_graph_unified')
                                </div>

                                <div class="cm-tab" tab-key="measurements-calendar">
                                    <div id="caremonth-measurements-calendar-{{$calendarID}}" class="caremonth-measurements-calendar">

                                    </div>
                                </div>

                                @if($performer->pro->pro_type == 'ADMIN')
                                    <div class="cm-tab border p-3 d-none" tab-key="measurements-admin">
                                        <div>
                                            <div class="my-1 font-weight-bold text-secondary">Has Anyone Interacted With Client About RM: {{$careMonth->has_anyone_interacted_with_client_about_rm? 'Yes': 'No'}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Has Mcp Interacted With Client About RM: {{$careMonth->has_mcp_interacted_with_client_about_rm? 'Yes': 'No'}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Has Admin Interacted With Client About RM: {{$careMonth->has_admin_interacted_with_client_about_rm? 'Yes': 'No'}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Has Rmm Interacted With Client About RM: {{$careMonth->has_rmm_interacted_with_client_about_rm? 'Yes': 'No'}}</div>

                                            <div class="my-1 font-weight-bold text-secondary">Most Recent Mcp Note Date: {{$careMonth->most_recent_mcp_note_date}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Days Between Most Recent Mcp Note Date And End Of Care Month: {{$careMonth->days_between_most_recent_mcp_note_date_and_end_of_care_month}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Rm Total Time In Seconds: {{$careMonth->rm_total_time_in_seconds}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Rm Total Time In Seconds By Mcp: {{$careMonth->rm_total_time_in_seconds_by_mcp}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Rm Total Time In Seconds By Rmm Pro: {{$careMonth->rm_total_time_in_seconds_by_rmm_pro}}</div>
                                            <div class="my-1 font-weight-bold text-secondary">Rm Total Time In Seconds By Rme Pro: {{$careMonth->rm_total_time_in_seconds_by_rme_pro}}</div>
                                        </div>

                                        @include('app.patient.care-month._rtm_stats')
                                    </div>
                                @endif

                            </div>
                            <div class="col-5">
                                @include('app.patient.care-month._matrix-v2')
                            </div>
                        </div>
                        <div class="mt-3">
                            @include('app.patient.care-month._matrix', ['onlyMatrix' => true])
                        </div>
                    </div>



                    <table class="table table-striped table-sm table-bordered mt-2 mb-0 d-none">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Effective Date</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                            <th class="px-2 text-secondary">Stamp</th>
                        </tr>
                        </thead>
                        <tbody>
                        @php
                            $measurementsInCareMonth = $patient->measurementsInCareMonth($careMonth);
                            $plottableMeasurements = [];
                        @endphp
                        @foreach($measurementsInCareMonth as $measurement)
                            @if(!empty($measurement->label) && !in_array($measurement->label, ["SBP", "DBP"]) && !$measurement->is_cellular_zero)
                                <tr>
                                    <td class="px-2">
                                        @if($measurement->ts)
                                            <?php $timestampInSec = floor($measurement->ts/1000); ?>
                                            {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }}
                                        @else
                                            {{ friendly_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN') }}
                                        @endif
                                        EST
                                    </td>
                                    <td class="px-2">{{ $measurement->label }}</td>
                                    <td class="px-2">
                                        @if($measurement->is_cellular_zero)
                                            <i class="font-size-11 fa fa-rss"></i>
                                        @elseif($measurement->label === 'BP')
                                            {{ $measurement->sbp_mm_hg }}/{{ $measurement->dbp_mm_hg }} mmHg
                                        @elseif($measurement->label === 'Wt. (lbs.)')
                                            {{ round(floatval($measurement->numeric_value), 2) }} lbs
                                        @else
                                            {{ $measurement->value }}
                                        @endif
                                    </td>
                                    <td colspan="px-2">
                                        <?php
                                        $stampEndPoint = '';
                                        if ($measurement->client->mcp_pro_id === $pro->id) {
                                            $stampEndPoint = '/api/measurement/stampAsMcp';
                                        } elseif ($measurement->client->default_na_pro_id === $pro->id || $measurement->client->rmm_pro_id === $pro->id || $measurement->client->rme_pro_id === $pro->id) {
                                            $stampEndPoint = '/api/measurement/stampAsNonHcp';
                                        }
                                        ?>
                                        @if(!empty($stampEndPoint))
                                            <div moe relative>
                                                <a href="#" start show>Stamp</a>
                                                <form url="{{$stampEndPoint}}" right class="width-300px">
                                            <input type="hidden" name="uid" value="{{$measurement->uid}}">
                                            <p class="mb-1">Stamp this measurement?</p>
                                            <div class="mt-2 bg-light border p-2">
                                                <div class="mb-1 text-secondary">{{ $measurement->label }}</div>
                                                <div class="font-weight-bold mb-1">
                                                    @if($measurement->label === 'BP')
                                                        {{ round($measurement->sbp_mm_hg, 2) }}/{{ round($measurement->dbp_mm_hg, 2) }} mmHg
                                                        <span class="font-weight-normal d-inline-block pl-2">Pulse:</span>
                                                        {{ $measurement->value_pulse }} {{ $measurement->value_irregular === 0?'Irregular':'' }} {{ $measurement->value_irregular === 1?'Regular':'' }}
                                                    @elseif($measurement->label === 'Wt. (lbs.)')
                                                        {{ round($measurement->numeric_value, 2) }} lbs
                                                    @else
                                                        {{ $measurement->value }}
                                                    @endif
                                                </div>
                                                <div class="text-sm">
                                                    <?php $timestampInSec = floor($measurement->ts / 1000); ?>
                                                    {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }} EST
                                                </div>
                                            </div>
                                            <div class="mb-2 border border-info p-2 mt-2 bg-light">
                                                <span>I have had interactive communication with {{$measurement->name_first}} {{$measurement->name_last}}.</span>
                                                <div class="d-flex border-top mt-2">
                                                    <label class="mt-2 mb-0 d-inline-flex align-items-center mr-3">
                                                        <input type="radio" class="mr-2" name="communicatedToPatient" value="true">
                                                        <span>Yes</span>
                                                    </label>
                                                    <label class="mt-2 mb-0 d-inline-flex align-items-center">
                                                        <input type="radio" class="mr-2" name="communicatedToPatient" value="false" checked>
                                                        <span>No</span>
                                                    </label>
                                                </div>
                                            </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 class="form-group m-0">
                                                <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
                                                <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
                                            </div>
                                        </form>
                                            </div>
                                        @endif
                                    </td>
                                </tr>

                                <?php
                                if ($measurement->ts) {
                                    $timestampInSec = floor($measurement->ts / 1000);
                                    $measurement->start = postgres_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN');
                                } else {
                                    $measurement->start = postgres_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN');
                                }
                                $measurement->title = '';
                                if ($measurement->label === 'BP') {
                                    $measurement->title .= 'BP ' . $measurement->sbp_mm_hg . '/' . $measurement->dbp_mm_hg . '';
                                } elseif ($measurement->label === 'Wt. (lbs.)') {
                                    $measurement->title .= 'Wt ' . round(floatval($measurement->numeric_value), 2) . '';
                                } else {
                                    $measurement->title .= $measurement->value;
                                }
                                $plottableMeasurements[] = $measurement;
                                ?>

                            @endif
                        @endforeach
                        @if(!$patient->measurements || !count($patient->measurements) === 0)
                            <tr>
                                <td class="text-secondary p-0 border-0">
                                    No items to show
                                </td>
                            </tr>
                        @endif
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        {{-- BDT Measurements --}}
        {{-- <hr class="m-negator mt-4 mb-3">

        <div class="row">
            <div class="col-12">
                <div class="d-flex align-items-center">
                    <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">Cellular Measurements</h6>
                </div>
                <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                    @if($patient->measurements && count($patient->measurements))
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Created</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                            <th class="px-2 text-secondary">Status</th>
                            <th class="px-2 text-secondary">Memo</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($patient->deviceMeasurements as $measurement)
                            <tr>
                                <td class="px-2">{{ friendly_date_time($measurement->created_at) }}</td>
                                <td class="px-2">{{ $measurement->measurement->device_category }}</td>
                                <td class="px-2">
                                    @if($measurement->measurement->device_category === 'WEIGHT')
                                        <b>{{ round($measurement->measurement->value_weight / 1000, 1) }} Kg</b>
                                    @elseif($measurement->measurement->device_category === 'BP')
                                        <b>{{ $measurement->measurement->systolic_bp_in_mm_hg }}/{{ $measurement->measurement->diastolic_bp_in_mm_hg }} mmHg</b>
                                    @endif
                                </td>
                                <td class="px-2">
                                    <span>
                                        <span>{{ $measurement->status }}</span>
                                        <span moe class="ml-2" relative>
                                            <a href="#" start show><i class="fa fa-edit text-primary"></i></a>
                                            <form url="/api/clientBdtMeasurement/updateStatus" right>
                                                <input type="hidden" name="uid" value="{{ $measurement->uid }}">
                                                <div class="mb-2">
                                                    <select name="status" class="form-control form-control-sm" required>
                                                        <option value="">-- select --</option>
                                                        <option {{$measurement->status === 'NEW' ? 'selected' : ''  }} value="NEW">NEW</option>
                                                        <option {{$measurement->status === 'ACCEPTED' ? 'selected' : ''  }} value="ACCEPTED">ACCEPTED</option>
                                                        <option {{$measurement->status === 'REJECTED' ? 'selected' : ''  }} value="REJECTED">REJECTED</option>
                                                    </select>
                                                </div>
                                                <div class="mb-2">
                                                    <input type="text" name="statusMemo" placeholder="Status memo" class="form-control form-control-sm">
                                                </div>
                                                <div class="d-flex align-items-center">
                                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                </div>
                                            </form>
                                        </span>
                                    </span>
                                </td>
                                <td class="px-2">
                                    {{ $measurement->status_memo }}
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    @else
                        <tbody>
                        <tr>
                            <td class="text-secondary p-3">No device measurements for this patient</td>
                        </tr>
                        </tbody>
                    @endif
                </table>
            </div>
        </div> --}}

        @include('app.patient.rm-setup-form')

        {{-- rtm msk --}}
        @if($careMonth->is_enrolled_in_rtm_msk)
            <hr class="m-negator my-3">

            <p class="font-weight-bold text-secondary mb-2 font-size-14">RTM Musculoskeletal</p>

            <div class="pl-3">
                <div class="screen-only">
                    <div class="d-flex align-items-center mb-2">
                        <p class="font-weight-bold text-secondary m-0">Transmissions</p>
                    </div>
                    <?php $transmissions = $careMonth->rtmMskTransmissions; ?>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="text-secondary border-bottom-0">Effective Date</th>
                            <th class="text-secondary border-bottom-0 w-35">Instructions</th>
                            <th class="text-secondary border-bottom-0 w-35">Response</th>
                            <th class="text-secondary border-bottom-0">Stamp</th>
                        </tr>
                        </thead>
                        <tbody>
                        @if(!$transmissions || !count($transmissions))
                            <tr>
                                <td class="text-secondary p-0 border-0" colspan="4">
                                    No items to show
                                </td>
                            </tr>
                        @else
                            @foreach($transmissions as $transmission)
                                <tr>
                                    <td>{{friendly_date($transmission->effective_date)}}</td>
                                    <td>
                                        @include('app.patient.rtm.protocol-summary', ['json' => $transmission->protocol_detail_json])
                                    </td>
                                    <td>
                                        @include('app.patient.rtm.feedback-summary', ['json' => $transmission->feedback_detail_json])
                                    </td>
                                    <td>
                                        @php $clientRtmTransmission = $transmission @endphp
                                        @include('app.patient.care-month._stamp_client_rtm_transmission')
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                        </tbody>
                    </table>
                </div>

                <div class="screen-only mt-3">
                    <div class="d-flex align-items-center">
                        <h6 class="font-weight-bold text-secondary m-0">Time Entries</h6>
                        <span class="mx-2 text-secondary">|</span>
                        @include('app.practice-management.care_month_add_rtm_entry_form', ['right' => false, 'type' => 'MSK', 'label' => 'Add for MSK'])
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0 table-hover">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                            <th class="px-2 text-secondary border-bottom-0">Time</th>
                            <th class="px-2 text-secondary border-bottom-0">Created</th>
                            <th class="px-2 text-secondary border-bottom-0 w-50">Comments</th>
                            <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($careMonth->rtmEntries as $entry)
                            @if(!$entry->is_removed && $entry->cm_or_rm_or_rtm_msk_or_rtm_lung == 'RTM_MSK')
                                <tr>
                                    <td class="px-2">
                                        <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                    </td>
                                    <td class="px-2">
                                        {{time_in_hrminsec($entry->time_in_seconds)}}
                                    </td>
                                    <td class="px-2">
                                        {{friendly_date_time($entry->created_at)}}
                                    </td>
                                    <td class="px-2">
                                        <div class="text-secondary in-table-markup">{!! $entry->content_text !!}</div>
                                    </td>
                                    <td class="px-2">
                                        @include('app.practice-management.care_month_add_rtm_entry_form', ['right' => true, 'type' => ($entry->cm_or_rm_or_rtm_msk_or_rtm_lung === 'RTM_MSK' ? 'MSK' : 'LUNG'), 'entry' => $entry])
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                        @php $entry = null; @endphp
                        </tbody>
                    </table>
                </div>
            </div>

        @endif

        {{-- rtm lung --}}
        @if($careMonth->is_enrolled_in_rtm_lung)
            <hr class="m-negator my-3">

            <p class="font-weight-bold text-secondary mb-2 font-size-14">RTM Pulmonary</p>

            <div class="pl-3">
                <div class="screen-only">
                    <div class="d-flex align-items-center mb-2">
                        <p class="font-weight-bold text-secondary m-0">Transmissions</p>
                    </div>
                    <?php $transmissions = $careMonth->rtmLungTransmissions; ?>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="text-secondary border-bottom-0">Effective Date</th>
                            <th class="text-secondary border-bottom-0 w-35">Instructions</th>
                            <th class="text-secondary border-bottom-0 w-35">Response</th>
                            <th class="text-secondary border-bottom-0">Stamp</th>
                        </tr>
                        </thead>
                        <tbody>
                        @if(!$transmissions || !count($transmissions))
                            <tr>
                                <td class="text-secondary p-0 border-0" colspan="4">
                                    No items to show
                                </td>
                            </tr>
                        @else
                            @foreach($transmissions as $transmission)
                                <tr>
                                    <td>{{friendly_date($transmission->effective_date)}}</td>
                                    <td>
                                        @include('app.patient.rtm.protocol-summary', ['json' => $transmission->protocol_detail_json])
                                    </td>
                                    <td>
                                        @include('app.patient.rtm.feedback-summary', ['json' => $transmission->feedback_detail_json])
                                    </td>
                                    <td>
                                        @php $clientRtmTransmission = $transmission @endphp
                                        @include('app.patient.care-month._stamp_client_rtm_transmission')
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                        </tbody>
                    </table>
                </div>

                <div class="screen-only mt-3">
                    <div class="d-flex align-items-center">
                        <h6 class="font-weight-bold text-secondary m-0">Time Entries</h6>
                        <span class="mx-2 text-secondary">|</span>
                        @include('app.practice-management.care_month_add_rtm_entry_form', ['right' => false, 'type' => 'LUNG', 'label' => 'Add for Lung'])
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0 table-hover">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                            <th class="px-2 text-secondary border-bottom-0">Time</th>
                            <th class="px-2 text-secondary border-bottom-0">Created</th>
                            <th class="px-2 text-secondary border-bottom-0 w-50">Comments</th>
                            <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($careMonth->rtmEntries as $entry )
                            @if(!$entry->is_removed && $entry->cm_or_rm_or_rtm_msk_or_rtm_lung == 'RTM_LUNG' )
                                <tr>
                                    <td class="px-2">
                                        <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                    </td>
                                    <td class="px-2">
                                        {{time_in_hrminsec($entry->time_in_seconds)}}
                                    </td>
                                    <td class="px-2">
                                        {{friendly_date_time($entry->created_at)}}
                                    </td>
                                    <td class="px-2">
                                        <div class="text-secondary in-table-markup">{!! $entry->content_text !!}</div>
                                    </td>
                                    <td class="px-2">
                                        @include('app.practice-management.care_month_add_rtm_entry_form', ['right' => true, 'type' => ($entry->cm_or_rm_or_rtm_msk_or_rtm_lung === 'RTM_MSK' ? 'MSK' : 'LUNG'), 'entry' => $entry])
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>

        @endif

        @if($pro->pro_type === 'ADMIN')

            <hr class="m-negator my-3">
            <div class="pb-3 screen-only">
                <div class="">
                    @if($careMonth->mcp)
                        <div class="d-flex align-items-baseline">
                            <div class="text-secondary font-weight-normal mb-1">Company Pro:&nbsp;</div>
                            <b>{{$careMonth->companyPro && $careMonth->companyPro->company ? $careMonth->companyPro->pro->displayName() . ' / ' . $careMonth->companyPro->company->name : '-'}}</b>
                            @if($careMonth->companyPro && $careMonth->companyPro->company)
                                <div moe class="ml-1">
                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                    <form url="/api/careMonth/wipeCompanyPro">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <p>Wipe company pro from this care month?</p>
                                        <div class="mb-0">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @else

                                <div moe class="ml-1">
                                    <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                    <form url="/api/careMonth/putCompanyPro">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <div class="mb-2">
                                            <select name="companyProUid" class="form-control form-control-sm">
                                                <option value="">-- select --</option>
                                                @foreach($careMonth->mcp->companyPros as $companyPro)
                                                    <option value="{{$companyPro->uid}}">{{$companyPro->pro->displayName() . ' / ' . $companyPro->company->name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="mb-0">
                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>

                            @endif
                        </div>
                    @else
                        <div class="alert alert-info">MCP has not been set on the care month.</div>
                    @endif
                    @if($careMonth->companyPro && $careMonth->companyPro->company)
                        <div class="d-flex align-items-baseline">
                            <div class="text-secondary font-weight-normal mb-1">Payer 1°:&nbsp;</div>
                            <b>
                                {{$careMonth->companyProPayer && $careMonth->companyProPayer->payer ? $careMonth->companyProPayer->payer->name : '-'}}
                            </b>
                            @if($careMonth->companyProPayer && $careMonth->companyProPayer->payer)
                                <div moe class="ml-1">
                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                    <form url="/api/careMonth/wipeCompanyProPayer">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <p>Wipe payer from this note?</p>
                                        <div class="mb-0">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @else
                                <div moe class="ml-1">
                                    <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                    <form url="/api/careMonth/putCompanyProPayer">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <div class="mb-2">
                                            <select name="companyProPayerUid" class="form-control form-control-sm">
                                                <option value="">-- select --</option>
                                                @foreach($careMonth->companyPro->companyProPayers as $companyProPayer)
                                                    <option value="{{$companyProPayer->uid}}">{{$companyProPayer->payer->name}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="mb-0">
                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        </div>

                        <div class="d-flex align-items-baseline">
                            <div class="text-secondary font-weight-normal mb-1">Payer 2°: </div>
                        </div>

                        <div class="d-flex align-items-baseline">
                            <div class="text-secondary font-weight-normal mb-1">Location:&nbsp;</div><b>{{$careMonth->companyLocation ? $careMonth->companyLocation->line1 . ', ' . $careMonth->companyLocation->city : '-'}}</b>
                            @if($careMonth->companyLocation)
                                <div moe class="ml-1">
                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                    <form url="/api/careMonth/wipeCompanyLocation">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <p>Wipe location from this note?</p>
                                        <div class="mb-0">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @else
                                <div moe class="ml-1">
                                    <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                    <form url="/api/careMonth/putCompanyLocation">
                                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                        <div class="mb-2">
                                            <select name="companyLocationUid" class="form-control form-control-sm">
                                                <option value="">-- select --</option>
                                                @if($careMonth->company && $careMonth->company->locations)
                                                    @foreach($careMonth->company->locations as $location)
                                                        <option value="{{$location->uid}}">{{$location->line1 . ', ' . $location->city}}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="mb-0">
                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        </div>

                        <div class="d-flex align-items-baseline">
                            <div class="text-secondary font-weight-normal">Primary Coverage:&nbsp;</div>
                            <b class="d-inline-flex">@include('app.patient.coverage_column_renderer', ['patient'=>$patient, 'truncateName' => true])</b>
                        </div>
                    @endif
                </div>
            </div>
        @endif

        @if($careMonth->number_of_days_with_remote_measurements >= 16)

            {{-- bills --}} {{-- only admins --}}
            @if($pro->pro_type === 'ADMIN')

                <hr class="m-negator my-0">

                <div class="screen-only m-neg-4 mb-3">
                    @include('app.generic-bills.inline-for-cm', ['patient' => $patient, 'careMonth' => $careMonth, 'class' => 'p-3 border-bottom', 'label' => 'MCP'])
                </div>

            @endif

            {{-- claims --}} {{-- only admins --}}
            @if($pro->pro_type === 'ADMIN')
                @if($careMonth->claims->count())
                    <div class="">
                        <div class="d-flex align-items-center mb-2">
                            <p class="font-weight-bold m-0">Claims</p>
                            @include('app.patient.care-month.refresh-suggestions-json')
                            @include('app/patient/care-month/_create-claim')
                            <div class="ml-auto">
                                <select class="form-control form-control-sm"
                                        onchange="fastLoad('{{route('patients.view.care-months.view.dashboard', ['patient' => $patient, 'careMonth' => $careMonth])}}?claims-filter=' + this.value)">
                                    <option value="active" {{!request('claims-filter') || request('claims-filter') === 'active' ? 'selected' : ''}}>Active Claims</option>
                                    <option value="all" {{request('claims-filter') === 'all' ? 'selected' : ''}}>All Claims</option>
                                </select>
                            </div>
                        </div>

                        <table class="table table-sm tabe-striped mb-3 border-left border-right border-bottom">
                            <thead class="bg-light">
                            <tr>
                                <th class="border-bottom-0 pl-2">IID</th>
                                <th class="border-bottom-0">Details</th>
                                <th class="border-bottom-0">Current Version</th>
                                <th class="border-bottom-0">Status</th>
                                <th class="border-bottom-0">Submissions</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($careMonth->claims as $claim)
                                @if($claim->status !== 'CANCELLED' || request('claims-filter') === 'all')
                                    <tr class="bg-secondary on-hover-opaque">
                                        <td colspan="5" class="pt-0 pb-1"></td>
                                    </tr>
                                    <tr class="{{ $claim->status === 'CANCELLED' ? 'text-secondary bg-light on-hover-opaque' : '' }}">
                                        <td class="pl-2">
                                            <div>{{ $claim->iid }}</div>
                                            @if($claim->status === 'CANCELLED')
                                                <div class="text-secondary font-weight-bold text-sm mt-1">[CANCELLED]</div>
                                            @else
                                                <div moe class="text-left mt-1" title="Cancel Claim">
                                                    <a class="" href="" show start>Cancel</a>
                                                    <form url="/api/claim/updateStatus">
                                                        <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                        <input type="hidden" name="status" value="CANCELLED">
                                                        <p>Cancel this claim?</p>
                                                        <div class="mb-2">
                                                            <label for="" class="control-label">Cancellation Memo</label>
                                                            <textarea name="memo" class="form-control"></textarea>
                                                        </div>
                                                        <div class="mb-0">
                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif
                                        </td>
                                        <td class="p-0 border-left border-right">
                                            @if($claim->lines->count())
                                                <table class="table table-sm table-condensed border-0 mb-0">
                                                    <thead>
                                                    <tr class="bg-light">
                                                        <th class="border-0">CPT</th>
                                                        <th class="border-0">DOS</th>
                                                        <th class="border-0">ICDs</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody class="pb-3">
                                                    @foreach($claim->lines as $line)
                                                        <tr class="claim-line">
                                                            <td>{{$line->cpt}}</td>
                                                            <td class="text-nowrap">{{friendlier_date($line->date_of_service)}}</td>
                                                            <td>
                                                                @if(count($line->claimLineIcds))
                                                                    @foreach($line->claimLineIcds as $icd)
                                                                        <div>
                                                                            <b class="c-pointer border-secondary border-bottom" title="{{$icd->description}}">{{$icd->code}}</b>
                                                                        </div>
                                                                    @endforeach
                                                                @else
                                                                    <p>No ICDs set</p>
                                                                @endif
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            @else
                                                <p>No lines for this claim</p>
                                            @endif
                                        </td>
                                        <td class="border-right">
                                            {{$claim->currentVersion ? friendlier_date_time($claim->currentVersion->created_at) : '-'}}
                                        </td>
                                        <td class="border-right p-0">

                                            <!-- status -->
                                            <div class="p-1 border-bottom">
                                                <div>
                                                    {{$claim->status ? $claim->status : '(not set)'}}
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="d-inline-block text-left ml-1" title="Update Status">
                                                                <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/updateStatus">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <label for="" class="control-label">Status</label>
                                                                        <select name="status" class="form-control form-control-sm" required>
                                                                            <option value="">-- select --</option>
                                                                            <option value="NEW" {{$claim->status === 'NEW' ? 'selected' : ''}}>New</option>
                                                                            <option value="PROCESSING" {{$claim->status === 'PROCESSING' ? 'selected' : ''}}>Processing</option>
                                                                            <option value="SUBMITTED" {{$claim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-2">
                                                                        <label for="" class="control-label">Status Memo</label>
                                                                        <textarea name="memo" class="form-control"></textarea>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                    @endif
                                                </div>
                                                @if($claim->status_memo)
                                                    <div class="text-secondary font-italic text-sm">{{$claim->status_memo}}</div>
                                                @endif
                                            </div>

                                            <!-- payer, company, location -->
                                            {{--
                                            <div class="p-1">
                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Payer (1°): </span>
                                                    <b>{{$claim->primaryPayer ? $claim->primaryPayer->name : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putPrimaryPayer">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="primaryPayerUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @foreach($note->hcpPro->companyProPayers as $companyProPayer)
                                                                                <option value="{{$companyProPayer->payer->uid}}"
                                                                                        {{$claim->primaryPayer && $claim->primaryPayer->uid === $companyProPayer->payer->uid ? 'selected' : ''}}>{{$companyProPayer->payer->name}}</option>
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->primaryPayer)
                                                            <span moe class="ml-1">
                                                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                <form url="/api/claim/wipePrimaryPayer">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <p>Wipe payer from this claim?</p>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @endif
                                                    @endif
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Payer (2°): </span>
                                                    <b>-</b>
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Company: </span>
                                                    <b>{{$claim->companyPro && $claim->companyPro->company ? $claim->companyPro->company->name : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putCompanyPro">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="companyProUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @foreach($note->hcpPro->companyProPayers as $companyProPayer)
                                                                                <option value="{{$companyProPayer->companyPro->uid}}"
                                                                                        {{$claim->companyPro && $claim->companyPro->uid === $companyProPayer->companyPro->uid ? 'selected' : ''}}>{{$companyProPayer->company->name}}</option>
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->companyPro && $claim->companyPro->company)
                                                            <span moe class="ml-1">
                                                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                    <form url="/api/claim/wipeCompanyPro">
                                                                        <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                        <p>Wipe company from this claim?</p>
                                                                        <div class="mb-0">
                                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                        </div>
                                                                    </form>
                                                                </span>
                                                        @endif
                                                    @endif
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Location: </span>
                                                    <b>{{$claim->companyLocation ? $claim->companyLocation->line1 . ', ' . $claim->companyLocation->city : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putCompanyLocation">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="companyLocationUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @if($claim->company && $claim->company->locations)
                                                                                @foreach($claim->company->locations as $location)
                                                                                    <option value="{{$location->uid}}"
                                                                                            {{$claim->companyLocation && $claim->companyLocation->uid === $location->uid ? 'selected' : ''}}>
                                                                                        {{$location->line1 . ', ' . $location->city}}
                                                                                    </option>
                                                                                @endforeach
                                                                            @endif
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->companyLocation)
                                                            <span moe class="ml-1">
                                                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                <form url="/api/claim/wipeCompanyLocation">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <p>Wipe location from this claim?</p>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @endif
                                                    @endif
                                                </div>
                                            </div>
                                            --}}
                                        </td>
                                        <td class="p-0 border-left border-right">
                                            <table class="table table-sm table-condensed border-0 mb-0">
                                                @if($claim->status !== 'CANCELLED')
                                                    <thead>
                                                    <tr class="">
                                                        <th colspan="3" class="border-top-0 border-bottom">
                                                            <div>
                                                                    <span moe class="d-block" title="Submit Claim">
                                                                        <a class="" href="" show start>Generate Submission to Payer (1°)</a>
                                                                        <form url="/api/mbClaim/createFromClaimForPrimaryPayer">
                                                                            <input type="hidden" name="claimUid" value="{{$claim->uid}}">
                                                                            <p>Generate Submission?</p>
                                                                            <div class="mb-0">
                                                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                            </div>
                                                                        </form>
                                                                    </span>
                                                            </div>
                                                        </th>
                                                    </tr>
                                                    </thead>
                                                @endif
                                                @if(count($claim->mbClaims))
                                                    <thead>
                                                    <tr class="bg-light">
                                                        <th class="border-0">Created</th>
                                                        <th class="border-0">Status</th>
                                                        <th class="border-0">&nbsp;</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody class="pb-3">
                                                    @foreach($claim->mbClaims as $mbClaim)
                                                        <tr>
                                                            <td>
                                                                @if($mbClaim->claim_version_id !== $claim->current_version_id)
                                                                    <i class="fa fa-exclamation-triangle text-warning-mellow text-sm" title="This submission was generated using an older version of the claim"></i>
                                                                @else
                                                                    <i class="fa fa-asterisk text-secondary text-sm" title="This submission is up to date"></i>
                                                                @endif
                                                                <a native target="_blank"
                                                                   open-in-stag-popup
                                                                   title="Submission Details"
                                                                   href="{{route('mb-claim', ['patient' => $patient, 'mbClaim' => $mbClaim])}}">
                                                                    {{ friendlier_date_time($mbClaim->created_at) }}
                                                                </a>
                                                            </td>
                                                            <td>
                                                                {{$mbClaim->status}}
                                                                @if($mbClaim->status_memo)
                                                                    <div class="font-italic text-secondary text-sm">{{$mbClaim->status_memo}}</div>
                                                                @endif
                                                            </td>
                                                            <td class="text-right pr-2">
                                                                     <span moe relative title="Submit Claim">
                                                                        <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                                                        <form url="/api/mbClaim/updateStatus" right>
                                                                            <input type="hidden" name="uid" value="{{$mbClaim->uid}}">
                                                                            <div class="form-group">
                                                                                <label for="" class="control-label">Status</label>
                                                                                <select name="status" class="form-control form-control-sm" required>
                                                                                    <option value="">-- select --</option>
                                                                                    <option value="NEW" {{$mbClaim->status === 'NEW' ? 'selected' : ''}}>New</option>
                                                                                    <option value="PROCESSING" {{$mbClaim->status === 'PROCESSING' ? 'selected' : ''}}>Processing</option>
                                                                                    <option value="SUBMITTED" {{$mbClaim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
                                                                                </select>
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <label for="" class="control-label">Status Memo</label>
                                                                                <textarea name="memo" class="form-control"></textarea>
                                                                            </div>
                                                                            <div class="mb-0">
                                                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                            </div>
                                                                        </form>
                                                                    </span>
                                                                <a class="ml-1" target="_blank" native href="/api/mbClaim/downloadEDI/{{$mbClaim->uid}}" show start><i class="fa fa-file-download"></i></a>
                                                                <a class="ml-1 text-success" href="" show start><i class="fa fa-arrow-right"></i></a>
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                @else
                                                    <tbody>
                                                    <tr>
                                                        <td colspan="3">
                                                            <p class="p-1 text-secondary m-0">No submissions in this claim</p>
                                                        </td>
                                                    </tr>
                                                    </tbody>
                                                @endif
                                            </table>
                                        </td>
                                    </tr>
                                @endif
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="d-flex">
                        <p class="font-weight-bold mb-0">No claims in this care month</p>
                        @include('app.patient.care-month.refresh-suggestions-json')
                        @include('app/patient/care-month/_create-claim')
                    </div>
                @endif
            @endif

        @endif

        {{-- invoices --}}
        @if($pro->pro_type === 'ADMIN')
            <hr class="m-negator mt-4 mb-3">
            @include('app.generic-invoices.index', ['patient' => $patient, 'parentType' => 'Care Month', 'parentID' => $careMonth->id, 'parentUid' => $careMonth->uid])
        @endif

        @if($pro->pro_type === 'ADMIN')
        <hr class="m-negator mt-4 mb-3">
        <div>
            Is RM interaction waived: <b>{{$careMonth->is_rm_interaction_waived? 'Yes': 'No'}}</b>
            <div moe class="text-left ml-2 mb-2">
                <a class="" href="" show start>Toggle</a>
                @if($careMonth->is_rm_interaction_waived)
                    <form url="/api/careMonth/setIsRmInteractionWaivedToFalse">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <p>Set is RM interaction waived to false?</p>
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                @else
                    <form url="/api/careMonth/setIsRmInteractionWaivedToTrue">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <p>Set is RM interaction waived to true?</p>
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                @endif
            </div>
        </div>
        <div>
            Is RM time waived: <b>{{$careMonth->is_rm_time_waived? 'Yes': 'No'}}</b>
            <div moe class="text-left ml-2">
                <a class="" href="" show start>Toggle</a>
                @if($careMonth->is_rm_time_waived)
                    <form url="/api/careMonth/setIsRmTimeWaivedToFalse">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <p>Set is RM Time waived to false?</p>
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                @else
                    <form url="/api/careMonth/setIsRmTimeWaivedToTrue">
                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                        <p>Set is RM time waived to true?</p>
                        <div class="mb-0">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                @endif
            </div>
        </div>
        @endif

        {{-- generic bills --}}{{--
        <div class="row">
            @include('app.generic-bills.inline', ['patient' => $patient, 'class' => 'col-12', 'entityType' => 'CareMonth', 'entityUid' => $careMonth->id])
        </div>--}}

    </div>

    <link href='/fullcalendar-5.3.2/lib/main.css' rel='stylesheet' />
    <script src='/fullcalendar-5.3.2/lib/main.js'></script>
    <script>
        (function() {
            function init() {
                $('#care-month-container-{{$patient->uid}} [cm-rte]').each(function() {

                    $(this).wrap(
                        $('<div class="border-left border-right rte-holder"/>')
                            .attr('data-shortcuts', '')
                    );

                    // give a unique id to this editor instance
                    var editorID = Math.ceil(Math.random() * 99999), fieldName = $(this).attr('data-name');

                    var el = this;
                    var existingContent = $(el).attr('data-content') ? $(el).attr('data-content') : $(el).html();
                    var quill = new Quill(el, {
                        theme: 'snow',
                        modules: stagQuillConfig
                    });

                    var toolbar = $(quill.container).prev('.ql-toolbar');

                    // add button for new shortcut
                    var newSCButton = $('<button class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
                        'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
                    toolbar.append(newSCButton);

                    quill.root.innerHTML = existingContent;

                    $('<input type="hidden" name="' + fieldName + '">').val(existingContent).insertAfter(el);

                    quill.on('text-change', function(delta, oldDelta, source) {
                        $(el).next('[name="' + fieldName + '"]').val(quill.root.innerHTML);
                    });

                    $(quill.container)
                        .find('.ql-editor[contenteditable]')
                        .attr('data-field', fieldName)
                        .attr('data-editor-id', editorID)
                        .attr('with-shortcuts', 1);

                });

                // init calendar view
                // $('#caremonth-measurements-calendar-{{$calendarID}}').closest('.d-none').removeClass('d-none');
                let measurementsCalendar = new FullCalendar.Calendar($('#caremonth-measurements-calendar-{{$calendarID}}')[0], {
                    allDaySlot: false,
                    headerToolbar: false,
                    initialView: 'dayGridMonth',
                    initialDate: '{{ date('Y-m-d', strtotime($careMonth->created_at)) }}',
                    navLinks: false,
                    dayMaxEvents: false,
                    slotMinTime: '00:00',
                    slotMaxTime: '23:59',
                    scrollTime: '06:00:00',
                    slotDuration: '00:15:00',
                    events: function(info, successCallback, failureCallback) {
                        successCallback({!! json_encode($plottableMeasurements) !!});
                    },
                    eventClassNames: function(arg) {
                        let classes = [];
                        if (arg.event.extendedProps.label === 'Wt. (lbs.)') {
                            classes.push('m-weight');
                        }
                        if (arg.event.extendedProps.label === 'BP') {
                            classes.push('m-bp');
                        }
                        return classes;
                    },
                    eventClick: function(info) {
                        // self.selectedEvent = info.event;
                        // self.showEditAppointmentModal();
                    }
                });
                measurementsCalendar.render();

                window.setTimeout(() => {
                    // window.dispatchEvent(new Event('resize'));
                    measurementsCalendar.updateSize();
                    $('#caremonth-measurements-calendar-{{$calendarID}}').parent().addClass('d-none');
                }, 10);

                $('[tab-link=measurements-calendar]').click(function(){
                    if(typeof measurementsCalendar !== 'undefined'){
                        window.setTimeout(()=>{
                            measurementsCalendar.updateSize();
                        },10);
                    }
                });

                // if in popup, invoke vitals graph initer
                if($('#care-month-container-{{$patient->uid}}').closest('.stag-popup').length) {
                    runMCInitializer('vitalsGraphUnified_{{$careMonth->id}}');
                }

            }

            addMCInitializer('care-month-dashboard-{{$patient->uid}}', init, '#care-month-container-{{$patient->uid}}');

        }).call(window);
    </script>

    @endif

    </div>
@endsection
