HomeController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $keyNumbers = [];
  15. $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
  16. $keyNumbers['totalPatients'] = $totalPatients;
  17. $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
  18. ->where(function($query){
  19. $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
  20. ->orWhere('has_mcp_done_onboarding_visit', 'NO');
  21. })->count();
  22. $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
  23. $performerProID = $performer->pro->id;
  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. return view('app/dashboard', compact('keyNumbers','reimbursement'));
  54. }
  55. public function patients(Request $request)
  56. {
  57. $proID = $this->performer()->pro->id;
  58. $patients = Client::where(function ($q) use($proID) {
  59. $q->where('mcp_pro_id', $proID)
  60. ->orWhere('cm_pro_id', $proID)
  61. ->orWhere('rmm_pro_id', $proID)
  62. ->orWhere('rme_pro_id', $proID)
  63. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID]);
  64. })
  65. ->orderBy('name_last', 'asc')
  66. ->orderBy('name_first', 'asc')
  67. ->get();
  68. return view('app/patients', ['patients' => $patients]);
  69. }
  70. public function newPatient(Request $request)
  71. {
  72. return view('app/new-patient');
  73. }
  74. public function mc(Request $request, $fragment = "") {
  75. $page = "/";
  76. if($fragment) {
  77. $page = '/' . $fragment;
  78. }
  79. return view('app/mc', compact('page'));
  80. }
  81. }