HomeController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Client;
  4. use App\Models\Bill;
  5. use App\Models\Note;
  6. use App\Models\ProTransaction;
  7. use Illuminate\Http\Request;
  8. class HomeController extends Controller
  9. {
  10. public function dashboard(Request $request)
  11. {
  12. //patients where performer is the mcp
  13. $performer = $this->performer();
  14. $performerProID = $performer->pro->id;
  15. $keyNumbers = [];
  16. $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
  17. $keyNumbers['totalPatients'] = $totalPatients;
  18. $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
  19. ->where(function ($query) {
  20. $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
  21. ->orWhere('has_mcp_done_onboarding_visit', 'NO');
  22. })->count();
  23. $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
  24. $pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
  25. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  26. })
  27. ->orWhere(function ($query) use ($performerProID) {
  28. $query->where('cm_pro_id', $performerProID)->where('is_signed_by_cm', false)->where('is_cancelled', false);;
  29. })->orWhere(function ($query) use ($performerProID) {
  30. $query->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false)->where('is_cancelled', false);;
  31. })->orWhere(function ($query) use ($performerProID) {
  32. $query->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false)->where('is_cancelled', false);;
  33. })->count();
  34. $keyNumbers['pendingBillsToSign'] = $pendingBillsToSign;
  35. $pendingNotesToSign = Note::where(function ($query) use ($performerProID) {
  36. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);;
  37. })
  38. ->orWhere(function ($query) use ($performerProID) {
  39. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false);;
  40. })->count();
  41. $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
  42. $reimbursement = [];
  43. $reimbursement["currentBalance"] = $performer->pro->balance;
  44. $reimbursement["nextPaymentDate"] = '--';
  45. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  46. if ($lastPayment) {
  47. $reimbursement["lastPayment"] = $lastPayment->amount;
  48. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  49. } else {
  50. $reimbursement["lastPayment"] = '--';
  51. $reimbursement["lastPaymentDate"] = '--';
  52. }
  53. $clientsWithAppointments = Client::where("mcp_pro_id", $performerProID)
  54. ->whereNotNull('next_mcp_appointment')->get();
  55. $appointments = [];
  56. foreach ($clientsWithAppointments as $client) {
  57. $appointment = [
  58. 'client_uid' => $client->uid,
  59. 'title' => $client->name_first . ' ' . $client->name_last,
  60. 'start' => $client->next_mcp_appointment
  61. ];
  62. $appointments[] = $appointment;
  63. }
  64. return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'appointments'));
  65. }
  66. public function patients(Request $request)
  67. {
  68. $proID = $this->performer()->pro->id;
  69. $patients = Client::where(function ($q) use($proID) {
  70. $q->where('mcp_pro_id', $proID)
  71. ->orWhere('cm_pro_id', $proID)
  72. ->orWhere('rmm_pro_id', $proID)
  73. ->orWhere('rme_pro_id', $proID)
  74. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID]);
  75. })
  76. ->orderBy('name_last', 'asc')
  77. ->orderBy('name_first', 'asc')
  78. ->get();
  79. return view('app/patients', ['patients' => $patients]);
  80. }
  81. public function newPatient(Request $request)
  82. {
  83. return view('app/new-patient');
  84. }
  85. public function mc(Request $request, $fragment = "")
  86. {
  87. $page = "/";
  88. if ($fragment) {
  89. $page = '/' . $fragment;
  90. }
  91. return view('app/mc', compact('page'));
  92. }
  93. }