123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Client;
- use App\Models\Bill;
- use App\Models\Note;
- use App\Models\ProTransaction;
- use Illuminate\Http\Request;
- class HomeController extends Controller
- {
- public function dashboard(Request $request)
- {
- //patients where performer is the mcp
- $performer = $this->performer();
- $performerProID = $performer->pro->id;
- $keyNumbers = [];
- $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
- $keyNumbers['totalPatients'] = $totalPatients;
- $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
- ->where(function ($query) {
- $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
- ->orWhere('has_mcp_done_onboarding_visit', 'NO');
- })->count();
- $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
- $pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
- $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
- })
- ->orWhere(function ($query) use ($performerProID) {
- $query->where('cm_pro_id', $performerProID)->where('is_signed_by_cm', false)->where('is_cancelled', false);;
- })->orWhere(function ($query) use ($performerProID) {
- $query->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false)->where('is_cancelled', false);;
- })->orWhere(function ($query) use ($performerProID) {
- $query->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false)->where('is_cancelled', false);;
- })->count();
- $keyNumbers['pendingBillsToSign'] = $pendingBillsToSign;
- $pendingNotesToSign = Note::where(function ($query) use ($performerProID) {
- $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);;
- })
- ->orWhere(function ($query) use ($performerProID) {
- $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false);;
- })->count();
- $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
- $reimbursement = [];
- $reimbursement["currentBalance"] = $performer->pro->balance;
- $reimbursement["nextPaymentDate"] = '--';
- $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
- if ($lastPayment) {
- $reimbursement["lastPayment"] = $lastPayment->amount;
- $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
- } else {
- $reimbursement["lastPayment"] = '--';
- $reimbursement["lastPaymentDate"] = '--';
- }
- $clientsWithAppointments = Client::where("mcp_pro_id", $performerProID)
- ->whereNotNull('next_mcp_appointment')->get();
- $appointments = [];
- foreach ($clientsWithAppointments as $client) {
- $appointment = [
- 'client_uid' => $client->uid,
- 'title' => $client->name_first . ' ' . $client->name_last,
- 'start' => $client->next_mcp_appointment
- ];
- $appointments[] = $appointment;
- }
- return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'appointments'));
- }
- public function patients(Request $request)
- {
- $proID = $this->performer()->pro->id;
- $patients = Client::where(function ($q) use($proID) {
- $q->where('mcp_pro_id', $proID)
- ->orWhere('cm_pro_id', $proID)
- ->orWhere('rmm_pro_id', $proID)
- ->orWhere('rme_pro_id', $proID)
- ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID]);
- })
- ->orderBy('name_last', 'asc')
- ->orderBy('name_first', 'asc')
- ->get();
- return view('app/patients', ['patients' => $patients]);
- }
- public function newPatient(Request $request)
- {
- return view('app/new-patient');
- }
- public function mc(Request $request, $fragment = "")
- {
- $page = "/";
- if ($fragment) {
- $page = '/' . $fragment;
- }
- return view('app/mc', compact('page'));
- }
- }
|