@extends ('layouts/template')

@section('content')
<style>
	#rm-action-report-filters label {
		font-weight: bold;
	}

	#rm-action-report-filters .mw-100px {
		min-width: 100px;
	}
	.filter-container{
		display: flex;
		align-items: flex-start;
		flex-wrap: wrap;
	}
	.filter-container >div {
		width: 165px;
	}
	.filter-container >div:not(:last-child) {
		margin-right: 15px;
	}
	.sm-section {
		width: 150px !important;
	}
    thead.border-bottom-0 tr th {
        border-bottom: none;
    }
</style>
<div id="rm-action-report" class="p-3 mcp-theme-1">
    <div class="card">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-user"></i>
                RM Action Report
            </strong>
        </div>
        <div class="card-body p-0 border-0 table-responsive">
            <div class="m-2">
                <form id="rm-action-report-filters" method="GET" action="{{ route('practice-management.rmActionReport') }}" class="filter-container">
                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Month/Year</label>
                            <input name="care_month_year" type="month" class="form-control input-sm" value="{{request()->input('care_month_year')}}">
                        </div>
                    </div>
                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Claiming Closed:</label>
                            <select name="claiming_closed" class="form-control input-sm">
                                <option {{request()->input('claiming_closed') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('claiming_closed') === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                                <option {{request()->input('claiming_closed') === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Measurement Days:</label>
                            <select name="num_of_measurements" class="form-control input-sm">
                                <option {{request()->input('num_of_measurements') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('num_of_measurements') === '16_or_more' ? 'selected' : ''}} value="16_or_more">16 or more</option>
                                <option {{request()->input('num_of_measurements') === 'min_or_more' ? 'selected' : ''}} value="min_or_more">{{$minRequiredMeasurements}} or more</option>
                                <option {{request()->input('num_of_measurements') === 'less_than_min' ? 'selected' : ''}} value="less_than_min">Less than {{$minRequiredMeasurements}}</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Visit in 90 days:</label>
                            <select name="has_recent_visit" class="form-control input-sm">
                                <option {{request()->input('has_recent_visit') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('has_recent_visit') === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                                <option {{request()->input('has_recent_visit') === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Comm. this month:</label>
                            <select name="has_been_spoken_to" class="form-control input-sm">
                                <option {{request()->input('has_been_spoken_to') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('has_been_spoken_to') === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                                <option {{request()->input('has_been_spoken_to') === 'NO' ? 'selected' : ''}} value="NO">No</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">MCP:</label>
                            <select name="mcp_uid" class="form-control input-sm" provider-search provider-type="hcp" data-pro-uid="{{request()->input('mcp_uid')}}"></select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Status:</label>
                            <select name="status" class="form-control input-sm">
                                <option value="ACTIVE">Active</option>
                                <option {{request()->input('status') === 'INACTIVE' ? 'selected' : ''}} value="INACTIVE">Inactive</option>
                                <option {{request()->input('status') === 'ENTRY_ERROR' ? 'selected' : ''}} value="ENTRY_ERROR">Entry Error</option>
                                <option {{request()->input('status') === 'DUMMY' ? 'selected' : ''}} value="DUMMY">Test Chart</option>
                                <option {{request()->input('status') === 'DECEASED' ? 'selected' : ''}} value="DECEASED">Deceased</option>
                                <option {{request()->input('status') === 'DUPLICATE' ? 'selected' : ''}} value="DUPLICATE">Duplicate</option>
                                <option {{request()->input('status') === 'NO_LONGER_INTERESTED' ? 'selected' : ''}} value="NO_LONGER_INTERESTED">No Longer Interested</option>
                                <option {{request()->input('status') === 'BAD_RECORD' ? 'selected' : ''}} value="BAD_RECORD">Bad Record</option>
                                <option {{request()->input('status') === 'NO_LONGER_ELIGIBLE' ? 'selected' : ''}} value="NO_LONGER_ELIGIBLE">No Longer Eligible</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Eligible for RM:</label>
                            <select name="rm_eligible" class="form-control input-sm">
                                <option {{request()->input('rm_eligible') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('rm_eligible') === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                                <option {{request()->input('rm_eligible') === 'NO' ? 'selected' : ''}} value="NO">No</option>
                                <option {{request()->input('rm_eligible') === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">Eligible for RM:</label>
                            <select name="rm_enrolled" class="form-control input-sm">
                                <option {{request()->input('rm_enrolled') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('rm_enrolled') === 'YES' ? 'selected' : ''}} value="YES">Yes</option>
                                <option {{request()->input('rm_enrolled') === 'NO' ? 'selected' : ''}} value="NO">No</option>
                                <option {{request()->input('rm_enrolled') === 'UNKNOWN' ? 'selected' : ''}} value="UNKNOWN">Unknown</option>
                            </select>
                        </div>
                    </div>

                    <div class="sm-section">
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">RM Setup:</label>
                            <select name="rm_setup" class="form-control input-sm">
                                <option {{request()->input('rm_setup') === '' ? 'selected' : ''}} value="">All</option>
                                <option {{request()->input('rm_setup') === 'YES' ? 'selected' : ''}} value="YES">Performed</option>
                                <option {{request()->input('rm_setup') === 'NO' ? 'selected' : ''}} value="NO">Not Performed</option>
                            </select>
                        </div>
                    </div>

                    <div>
                        <div class="form-group m-0">
                            <label class="font-weight-normal mb-1">&nbsp;</label>
                            <div class=" d-flex">
                                <button type="button" onclick="return fastLoad('{{  route('practice-management.rmActionReport') }}?' + $('#rm-action-report-filters').serialize())" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
                                <a href="#" onclick="return fastLoad('{{  route('practice-management.rmActionReport') }}')" class="btn btn-link btn-sm text-danger">Clear Filters</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div> 
            <table class="table table-sm table-striped table-bordered border-0 p-0 m-0 text-nowrap">
                <thead class="bg-light border-bottom-0">
                    <tr>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Month', 'key' => 'start_date'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Patient', 'key' => 'client_name'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RM<br>Elig.', 'key' => 'is_eligible_for_rm'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RM<br>Enrol', 'key' => 'is_client_enrolled_in_rm'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RM<br>Setup', 'key' => 'has_rm_setup_been_performed'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'MCP', 'key' => 'mcp_name'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RMM', 'key' => 'rmm_name'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Meas.<br>Days', 'key' => 'number_of_days_with_remote_measurements'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'DSLM', 'key' => 'dslm'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Last<br>Visit', 'key' => 'mr_note_date'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'DSLV', 'key' => 'days_between_most_recent_mcp_note_date_and_end_of_care_month'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'MCP<br>Mins.', 'key' => 'rm_total_time_in_seconds_by_mcp'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RMM<br>Mins.', 'key' => 'rm_total_time_in_seconds_by_rmm_pro'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Total<br>Mins.', 'key' => 'rm_total_time_in_seconds'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Admin<br>Comm.', 'key' => 'has_admin_interacted_with_client_about_rm'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'MCP<br>Comm.', 'key' => 'has_mcp_interacted_with_client_about_rm'])</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'MCP<br>Payable', 'key' => 'mcp_payable'])</th>
                        <th class="text-secondary">MCP Bill</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'RMM<br>Payable', 'key' => 'rmm_payable'])</th>
                        <th class="text-secondary">RMM Bill</th>
                        <th class="text-secondary">Guidance</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Claiming<br>Closed?', 'key' => 'is_claim_closed'])</th>
                        <th class="text-secondary">Claim</th>
                        <th>@include('app.practice-management._sort_header_multi', ['route' => route("practice-management.rmActionReport"), 'label' => 'Claim<br>Status', 'key' => 'claim_status'])</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($rows as $row)
                    <tr class="{{false ? 'bg-light' : ''}}">
                        <td class="text-nowrap border-left-0">
                            <a href="/patients/view/{{$row->client_uid}}/care-months/view/{{$row->care_month_uid}}">
                                {{friendly_date_month_year($row->start_date)}}
                            </a>
                        </td>
                        <td class="">
                            <a href="/patients/view/{{$row->client_uid}}">
                                {{$row->client_name}}
                            </a>
                        </td>
                        <td>{{ucwords(strtolower($row->is_eligible_for_rm))}}</td>
                        <td>{{ucwords(strtolower($row->is_client_enrolled_in_rm))}}</td>
                        <td>{{$row->has_rm_setup_been_performed ? 'Yes' : 'No'}}</td>
                        <td>
                            {{$row->mcp_name}}
                        </td>
                        <td>
                            {{$row->rmm_name}}
                        </td>
                        <td>
                            {{$row->number_of_days_with_remote_measurements}}
                        </td>
                        <td>
                            {{$row->dslm}}
                        </td>
                        <td>
                            <!-- Most Recent Visit -->
                            @if($row->mr_note_uid)
                                <a href="/patients/view/{{ $row->client_uid }}/notes/view/{{ $row->mr_note_uid }}">{{ friendly_date($row->mr_note_date) }}</a>
                            @else
                                -
                            @endif
                        </td>
                        <td>
                            <!-- Most Recent Visit Days Before EOM -->
                            {{ $row->days_between_most_recent_mcp_note_date_and_end_of_care_month ?? '-' }}
                        </td>
                        <td>
                            <!-- # Minutes Billed by MCP -->
                            {{ round($row->rm_total_time_in_seconds_by_mcp / 60, 2) }}
                        </td>
                        <td>
                            <!-- # Minutes Billed by RMM -->
                            {{ round($row->rm_total_time_in_seconds_by_rmm_pro / 60, 2) }}
                        </td>
                        <td>
                            <!-- # Minutes Billed Total -->
                            {{ round($row->rm_total_time_in_seconds / 60, 2) }}
                        </td>
                        <td>
                            <!-- Has Admin interacted? -->
                            {{ $row->has_admin_interacted_with_client_about_rm ? 'Yes' : 'No' }}
                        </td>
                        <td>
                            <!-- Has MCP interacted? -->
                            {{ $row->has_mcp_interacted_with_client_about_rm ? 'Yes' : 'No' }}
                        </td>
                        <td>
                            <!-- Is Payable to MCP? -->
                            {{ $row->mcp_payable ? 'Yes' : 'No' }}
                        </td>
                        <td>
                            <!-- MCP Bill -->
                            {{ $row->mcp_rm_bill_code }}
                        </td>
                        <td>
                            <!-- Is Payable to RMM? -->
                            {{ $row->rmm_payable ? 'Yes' : 'No' }}
                        </td>
                        <td> 
                            <!-- RMM Bill -->
                            {{ $row->rmm_rm_bill_code }}
                        </td>
                        <td>
                            <?php
                                $careMonthClaimSuggestion = json_decode($row->claim_suggestion_json);
                            ?>
                            @if($careMonthClaimSuggestion)
                            <div class="d-flex flex-column">
                                @foreach($careMonthClaimSuggestion->lines as $line)
                                <span><i class="fas fa-circle" style="color: #00bcd4;"></i> {{ $line->cpt }}</span>
                                @endforeach
                            </div>
                            @endif
                        </td>
                        <td>
                            {{ $row->is_claim_closed ? 'YES':'NO' }}
                        </td>
                        <td>
                            <div>{{@$row->cpts}}</div>
                            @include('app.patient.care-month._create-claim-table-action', ['careMonth' => $row])
                        </td>
                        <td>
                            {{$row->claim_status}}
                            @include('app.patient.care-month.update-claim-status', ['uid' => $row->claim_uid, 'status' => $row->claim_status])
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>

        </div>
    </div>
    <div class="d-flex align-items-baseline mt-3">
        {!! $paginator->withQueryString()->links() !!}
        <div class="mb-3">
            <div class="ml-4 mb-3">Showing <b>{{$paginator->firstItem()}}</b> to <b>{{$paginator->lastItem()}}</b> (page {{$paginator->currentPage()}}) of <b>{{$paginator->total()}}</b> care months</div>
        </div>
    </div>

</div>

@endsection