HomeController.php 4.0 KB

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