HomeController.php 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Lib\Backend;
  4. use App\Models\Appointment;
  5. use App\Models\AppointmentConfirmationDecision;
  6. use App\Models\AppSession;
  7. use App\Models\ClientMemo;
  8. use App\Models\ClientProChange;
  9. use App\Models\ClientSMS;
  10. use App\Models\Facility;
  11. use App\Models\IncomingReport;
  12. use App\Models\MBPayer;
  13. use App\Models\ProProAccess;
  14. use App\Models\SupplyOrder;
  15. use App\Models\Ticket;
  16. use DateTime;
  17. use App\Models\Client;
  18. use App\Models\Bill;
  19. use App\Models\Measurement;
  20. use App\Models\Note;
  21. use App\Models\Pro;
  22. use App\Models\ProTransaction;
  23. use GuzzleHttp\Cookie\CookieJar;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\Cookie;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Support\Facades\Http;
  28. class HomeController extends Controller
  29. {
  30. public function confirmSmsAuthToken(Request $request)
  31. {
  32. return view('app/confirm_sms_auth_token');
  33. }
  34. public function setPassword(Request $request)
  35. {
  36. return view('app/set_password');
  37. }
  38. public function setSecurityQuestions(Request $request)
  39. {
  40. return view('app/set_security_questions');
  41. }
  42. public function postConfirmSmsAuthToken(Request $request)
  43. {
  44. try {
  45. $url = config('stag.backendUrl') . '/session/confirmSmsAuthToken';
  46. $data = [
  47. 'cellNumber' => $request->input('cellNumber'),
  48. 'token' => $request->input('token'),
  49. ];
  50. $response = Http::asForm()
  51. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  52. ->post($url, $data)
  53. ->json();
  54. if (!isset($response['success']) || !$response['success']) {
  55. $message = 'API error';
  56. if (isset($response['error'])) {
  57. $message = $response['error'];
  58. if (isset($response['path'])) $message .= ': ' . $response['path'];
  59. } else if (isset($response['message'])) $message = $response['message'];
  60. return redirect('/confirm_sms_auth_token')
  61. ->withInput()
  62. ->with('message', $message);
  63. }
  64. return redirect('/');
  65. } catch (\Exception $e) {
  66. return redirect()->back()
  67. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  68. ->withInput($request->input());
  69. }
  70. }
  71. public function resendSmsAuthToken(Request $request)
  72. {
  73. try {
  74. $url = config('stag.backendUrl') . '/session/resendSmsAuthToken';
  75. $data = [];
  76. $response = Http::asForm()
  77. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  78. ->post($url, $data)
  79. ->json();
  80. if (!isset($response['success']) || !$response['success']) {
  81. $message = 'API error';
  82. if (isset($response['error'])) {
  83. $message = $response['error'];
  84. if (isset($response['path'])) $message .= ': ' . $response['path'];
  85. } else if (isset($response['message'])) $message = $response['message'];
  86. return redirect('/confirm_sms_auth_token')
  87. ->withInput()
  88. ->with('message', $message);
  89. }
  90. return redirect()->back()->withInput()->with('message', "SMS Auth Token sent.");
  91. } catch (\Exception $e) {
  92. return redirect()->back()
  93. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  94. ->withInput($request->input());
  95. }
  96. }
  97. public function postSetPassword(Request $request)
  98. {
  99. try {
  100. $url = config('stag.backendUrl') . '/pro/selfPutPassword';
  101. $data = [
  102. 'newPassword' => $request->input('newPassword'),
  103. 'newPasswordConfirmation' => $request->input('newPasswordConfirmation'),
  104. ];
  105. $response = Http::asForm()
  106. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  107. ->post($url, $data)
  108. ->json();
  109. if (!isset($response['success']) || !$response['success']) {
  110. $message = 'API error';
  111. if (isset($response['error'])) {
  112. $message = $response['error'];
  113. if (isset($response['path'])) $message .= ': ' . $response['path'];
  114. } else if (isset($response['message'])) $message = $response['message'];
  115. return redirect('/set_password')
  116. ->withInput()
  117. ->with('message', $message);
  118. }
  119. return redirect('/');
  120. } catch (\Exception $e) {
  121. return redirect()->back()
  122. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  123. ->withInput($request->input());
  124. }
  125. }
  126. public function postSetSecurityQuestions(Request $request)
  127. {
  128. try {
  129. $url = env('BACKEND_URL', 'http://localhost:8080/api') . '/pro/selfPutSecurityQuestions';
  130. $data = [
  131. 'securityQuestion1' => $request->input('securityQuestion1'),
  132. 'securityAnswer1' => $request->input('securityAnswer1'),
  133. 'securityQuestion2' => $request->input('securityQuestion2'),
  134. 'securityAnswer2' => $request->input('securityAnswer2'),
  135. ];
  136. $response = Http::asForm()
  137. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  138. ->post($url, $data)
  139. ->json();
  140. if (!isset($response['success']) || !$response['success']) {
  141. $message = 'API error';
  142. if (isset($response['error'])) {
  143. $message = $response['error'];
  144. if (isset($response['path'])) $message .= ': ' . $response['path'];
  145. } else if (isset($response['message'])) $message = $response['message'];
  146. return redirect('/set_password')
  147. ->withInput()
  148. ->with('message', $message);
  149. }
  150. return redirect('/');
  151. } catch (\Exception $e) {
  152. return redirect()->back()
  153. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  154. ->withInput($request->input());
  155. }
  156. }
  157. private function dashboard_MCP(Request $request){
  158. $keyNumbers = [];
  159. // Patients // SELECT * FROM client WHERE mcp_pro_id = :me.id;
  160. // New Patients Awaiting Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND hasMcpDoneOnboardingVisit != 'YES';
  161. // Notes Pending Signature // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS NOT TRUE;
  162. // Notes Pending Billing // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS TRUE AND is_billing_marked_done IS FALSE;
  163. // Reports Pending Signature // SELECT * FROM incoming_report WHERE hcp_pro_id = :me.id AND isEntryError IS NOT TRUE AND hasHcpProSigned IS NOT TRUE;
  164. // Patients w/o Appointments // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_mcp_appointment_date < today();
  165. // Patients Overdue for Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_expected_mcp_visit_date < today();
  166. // Cancelled Appts. Pending Review // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  167. // Cancelled Bills Pending Review // SELECT * FROM bill WHERE bill_service_type = 'NOTE' AND is_cancelled IS TRUE AND isCancellationAcknowledged IS FALSE;
  168. // Cancelled Supply Orders Pending Review // SELECT * FROM supply_order WHERE signed_by_pro_id = :me.id AND is_cancelled IS TRUE AND isCancellationAcknowledged IS NOT TRUE;
  169. // ERx & Orders Pending Signature // SELECT * FROM erx WHERE hcp_pro_id = :me.id AND pro_declared_status <> 'CANCELLED' AND hasHcpProSigned IS NOT TRUE;
  170. // Supply Orders Pending Signature // SELECT supply_order.id FROM supply_order WHERE signed_by_pro_id IS NOT TRUE AND is_cancelled IS NOT TRUE AND created_by_pro_id = :me.id;
  171. $performer = $this->performer();
  172. $pro = $performer->pro;
  173. $performerProID = $performer->pro->id;
  174. $keyNumbers = [];
  175. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  176. $pendingNotesToSign = Note
  177. ::where(function ($query) use ($performerProID) {
  178. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  179. })
  180. ->orWhere(function ($query) use ($performerProID) {
  181. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false);
  182. })
  183. ->count();
  184. $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
  185. // notes pending mcp sign (applicable to dnas only)
  186. $pendingNotesToSignMCP = Note
  187. ::where(function ($query) use ($performerProID) {
  188. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  189. })
  190. ->count();
  191. $keyNumbers['$pendingNotesToSignMCP'] = $pendingNotesToSignMCP;
  192. $pendingNotesToSignAllySigned = Note::where(function ($query) use ($performerProID) {
  193. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true)->where('is_cancelled', false);;
  194. })->count();
  195. $keyNumbers['pendingNotesToSignAllySigned'] = $pendingNotesToSignAllySigned;
  196. $signedNotesWithoutBills = Note::where(function ($query) use ($performerProID) {
  197. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', true)->where('is_cancelled', false);
  198. })->whereDoesntHave('bills')->count();
  199. $keyNumbers['signedNotesWithoutBills'] = $signedNotesWithoutBills;
  200. // open tickets
  201. $keyNumbers['numOpenTickets'] = Ticket::where('is_open', true)
  202. ->where(function ($q) use ($performerProID) {
  203. $q->where('assigned_pro_id', $performerProID)
  204. ->orWhere('manager_pro_id', $performerProID)
  205. ->orWhere('ordering_pro_id', $performerProID)
  206. ->orWhere('initiating_pro_id', $performerProID);
  207. })
  208. ->count();
  209. // unacknowledged cancelled bills for authed pro
  210. $keyNumbers['unacknowledgedCancelledBills'] = Bill::where('hcp_pro_id', $performerProID)
  211. ->where('is_cancelled', true)
  212. ->where('is_cancellation_acknowledged', false)
  213. ->count();
  214. // unacknowledged cancelled supply orders for authed pro
  215. $keyNumbers['unacknowledgedCancelledSupplyOrders'] = SupplyOrder::where('signed_by_pro_id', $performerProID)
  216. ->where('is_cancelled', true)
  217. ->where('is_cancellation_acknowledged', false)
  218. ->count();
  219. // unsigned supply orders created by authed pro
  220. $keyNumbers['unsignedSupplyOrders'] = SupplyOrder
  221. ::where('is_cancelled', false)
  222. ->where('is_signed_by_pro', false)
  223. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$performerProID])
  224. ->count();
  225. // patientsHavingBirthdayToday
  226. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  227. $keyNumbers['patientsHavingBirthdayToday'] = $queryClients
  228. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  229. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')])
  230. ->count();
  231. $reimbursement = [];
  232. $reimbursement["currentBalance"] = $performer->pro->balance;
  233. $reimbursement["nextPaymentDate"] = '--';
  234. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  235. if ($lastPayment) {
  236. $reimbursement["lastPayment"] = $lastPayment->amount;
  237. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  238. } else {
  239. $reimbursement["lastPayment"] = '--';
  240. $reimbursement["lastPaymentDate"] = '--';
  241. }
  242. //if today is < 15th, next payment is 15th, else nextPayment is
  243. $today = strtotime(date('Y-m-d'));
  244. $todayDate = date('j', $today);
  245. $todayMonth = date('m', $today);
  246. $todayYear = date('Y', $today);
  247. if ($todayDate < 15) {
  248. $nextPaymentDate = new DateTime();
  249. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  250. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  251. } else {
  252. $nextPaymentDate = new \DateTime();
  253. $lastDayOfMonth = date('t', $today);
  254. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  255. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  256. }
  257. //expectedPay
  258. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :performerProID AND has_hcp_been_paid = false AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  259. $expectedForCm = DB::select(DB::raw("SELECT coalesce(SUM(cm_expected_payment_amount),0) as expected_pay FROM bill WHERE cm_pro_id = :performerProID AND has_cm_been_paid = false AND is_signed_by_cm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  260. $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay FROM bill WHERE rme_pro_id = :performerProID AND has_rme_been_paid = false AND is_signed_by_rme IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  261. $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay FROM bill WHERE rmm_pro_id = :performerProID AND has_rmm_been_paid = false AND is_signed_by_rmm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  262. $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(generic_pro_expected_payment_amount),0) as expected_pay FROM bill WHERE generic_pro_id = :performerProID AND has_generic_pro_been_paid = false AND is_signed_by_generic_pro IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  263. $totalExpectedAmount = $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  264. $reimbursement['nextPaymentAmount'] = $totalExpectedAmount;
  265. $milliseconds = strtotime(date('Y-m-d')) . '000';
  266. // bills & claims
  267. $businessNumbers = [];
  268. // Notes with bills to resolve
  269. $businessNumbers['notesWithBillsToResolve'] = Note::where('is_cancelled', '!=', true)
  270. ->where('is_bill_closed', '!=', true)
  271. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND is_cancelled = false AND is_verified = false) > 0')
  272. ->count();
  273. // Notes pending bill closure
  274. $businessNumbers['notesPendingBillingClosure'] = Note::where('is_cancelled', '!=', true)
  275. ->where('is_bill_closed', '!=', true)
  276. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = true OR is_verified = true)) = 0')
  277. ->count();
  278. // incoming reports not signed
  279. $incomingReports = IncomingReport::where('hcp_pro_id', $performerProID)
  280. ->where('has_hcp_pro_signed', false)
  281. ->where('is_entry_error', false)
  282. ->orderBy('created_at', 'ASC')
  283. ->get();
  284. // erx, labs & imaging that are not closed
  285. $tickets = Ticket::where('ordering_pro_id', $performerProID)
  286. ->where('is_entry_error', false)
  287. ->where('is_open', true)
  288. ->orderBy('created_at', 'ASC')
  289. ->get();
  290. $supplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  291. ->where('is_cancelled', false)
  292. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  293. ->orderBy('created_at', 'ASC')
  294. ->get();
  295. $numERx = Ticket::where('ordering_pro_id', $performerProID)
  296. ->where('category', 'erx')
  297. ->where('is_entry_error', false)
  298. ->where('is_open', true)
  299. ->count();
  300. $numLabs = Ticket::where('ordering_pro_id', $performerProID)
  301. ->where('category', 'lab')
  302. ->where('is_entry_error', false)
  303. ->where('is_open', true)
  304. ->count();
  305. $numImaging = Ticket::where('ordering_pro_id', $performerProID)
  306. ->where('category', 'imaging')
  307. ->where('is_entry_error', false)
  308. ->where('is_open', true)
  309. ->count();
  310. $numSupplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  311. ->where('is_cancelled', false)
  312. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  313. ->count();
  314. $newMCPAssociations = ClientProChange
  315. ::where('new_pro_id', $performerProID)
  316. ->where('responsibility_type', 'MCP')
  317. ->whereNull('current_client_pro_change_decision_id')
  318. ->get();
  319. $newNAAssociations = ClientProChange
  320. ::where('new_pro_id', $performerProID)
  321. ->where('responsibility_type', 'DEFAULT_NA')
  322. ->whereNull('current_client_pro_change_decision_id')
  323. ->get();
  324. // unstamped client memos
  325. // for mcp
  326. $mcpClientMemos = DB::select(
  327. DB::raw("
  328. SELECT c.uid as client_uid, c.name_first, c.name_last,
  329. cm.uid, cm.content, cm.created_at
  330. FROM client c join client_memo cm on c.id = cm.client_id
  331. WHERE
  332. c.mcp_pro_id = {$performerProID} AND
  333. cm.mcp_stamp_id IS NULL
  334. AND (is_admin_only IS FALSE OR is_admin_only IS NULL)
  335. ORDER BY cm.created_at DESC
  336. ")
  337. );
  338. // for na
  339. $naClientMemos = DB::select(
  340. DB::raw("
  341. SELECT c.uid as client_uid, c.name_first, c.name_last,
  342. cm.uid, cm.content, cm.created_at
  343. FROM client c join client_memo cm on c.id = cm.client_id
  344. WHERE
  345. c.default_na_pro_id = {$performerProID} AND
  346. cm.default_na_stamp_id IS NULL
  347. ORDER BY cm.created_at DESC
  348. ")
  349. );
  350. $keyNumbers['rmBillsToSign'] = Bill
  351. ::where('is_cancelled', false)
  352. ->where('cm_or_rm', 'RM')
  353. ->where(function ($q) use ($performerProID) {
  354. $q
  355. ->where(function ($q2) use ($performerProID) {
  356. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  357. })
  358. ->orWhere(function ($q2) use ($performerProID) {
  359. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  360. })
  361. ->orWhere(function ($q2) use ($performerProID) {
  362. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  363. })
  364. ->orWhere(function ($q2) use ($performerProID) {
  365. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  366. });
  367. })
  368. ->count();
  369. $count = DB::select(
  370. DB::raw(
  371. "
  372. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  373. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  374. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  375. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  376. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  377. AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL)
  378. "
  379. )
  380. );
  381. $keyNumbers['rmPatientsWithLT16MD'] = $count[0]->cnt;
  382. $count = DB::select(
  383. DB::raw(
  384. "
  385. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  386. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  387. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  388. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  389. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  390. AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL)
  391. "
  392. )
  393. );
  394. $keyNumbers['rmPatientsWithGTE16MD'] = $count[0]->cnt;
  395. $count = DB::select(
  396. DB::raw(
  397. "
  398. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  399. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  400. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  401. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  402. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  403. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL)
  404. "
  405. )
  406. );
  407. $keyNumbers['rmPatientsWithWhomCommDone'] = $count[0]->cnt;
  408. $count = DB::select(
  409. DB::raw(
  410. "
  411. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  412. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  413. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  414. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  415. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  416. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL)
  417. "
  418. )
  419. );
  420. $keyNumbers['rmPatientsWithWhomCommNotDone'] = $count[0]->cnt;
  421. // num measurements that need stamping
  422. $keyNumbers['measurementsToBeStamped'] = $this->performer()->pro->getUnstampedMeasurementsFromCurrentMonth(true, null, null);
  423. if($performer->pro->pro_type === 'ADMIN') {
  424. // patients without coverage information
  425. $keyNumbers['patientsWithoutCoverageInformation'] = DB::select(DB::raw("
  426. SELECT count(DISTINCT (cl.id)) as cnt
  427. FROM client cl
  428. WHERE cl.shadow_pro_id IS NULL AND cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
  429. ))[0]->cnt;
  430. // patients pending coverage verification
  431. $keyNumbers['patientsPendingCoverageVerification'] = DB::select(DB::raw("
  432. SELECT count(DISTINCT (cl.id)) as cnt
  433. FROM client cl
  434. LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id
  435. WHERE cl.shadow_pro_id IS NULL
  436. AND (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
  437. AND (
  438. (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
  439. OR
  440. (cpc.plan_type != 'MEDICARE' AND
  441. (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
  442. ))"
  443. ))[0]->cnt;
  444. }
  445. return view('app/dashboard-mcp', compact('keyNumbers', 'reimbursement', 'milliseconds',
  446. 'businessNumbers',
  447. 'incomingReports', 'tickets', 'supplyOrders',
  448. 'numERx', 'numLabs', 'numImaging', 'numSupplyOrders',
  449. 'newMCPAssociations', 'newNAAssociations',
  450. 'mcpClientMemos', 'naClientMemos'));
  451. }
  452. private function dashboard_DNA(Request $request){
  453. $performer = $this->performer();
  454. $pro = $performer->pro;
  455. $keyNumbers = [];
  456. // Patients // SELECT * FROM client WHERE mcp_pro_id = :me.id;
  457. // New Patients Awaiting Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND hasMcpDoneOnboardingVisit != 'YES';
  458. // Notes Pending Signature // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS NOT TRUE;
  459. // Notes Pending Billing // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS TRUE AND is_billing_marked_done IS FALSE;
  460. // Reports Pending Signature // SELECT * FROM incoming_report WHERE hcp_pro_id = :me.id AND isEntryError IS NOT TRUE AND hasHcpProSigned IS NOT TRUE;
  461. // Patients w/o Appointments // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_mcp_appointment_date < today();
  462. // Patients Overdue for Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_expected_mcp_visit_date < today();
  463. // Cancelled Appts. Pending Review // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  464. // Cancelled Bills Pending Review // SELECT * FROM bill WHERE bill_service_type = 'NOTE' AND is_cancelled IS TRUE AND isCancellationAcknowledged IS FALSE;
  465. // Cancelled Supply Orders Pending Review // SELECT * FROM supply_order WHERE signed_by_pro_id = :me.id AND is_cancelled IS TRUE AND isCancellationAcknowledged IS NOT TRUE;
  466. // ERx & Orders Pending Signature // SELECT * FROM erx WHERE hcp_pro_id = :me.id AND pro_declared_status <> 'CANCELLED' AND hasHcpProSigned IS NOT TRUE;
  467. // Supply Orders Pending Signature // SELECT supply_order.id FROM supply_order WHERE signed_by_pro_id IS NOT TRUE AND is_cancelled IS NOT TRUE AND created_by_pro_id = :me.id;
  468. $performer = $this->performer();
  469. $pro = $performer->pro;
  470. $performerProID = $performer->pro->id;
  471. $keyNumbers = [];
  472. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  473. $pendingNotesToSign = Note::where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false)->count();
  474. $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
  475. // notes pending mcp sign (applicable to dnas only)
  476. $pendingNotesToSignMCP = Note::where('ally_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false)->count();
  477. $keyNumbers['$pendingNotesToSignMCP'] = $pendingNotesToSignMCP;
  478. $pendingNotesToSignAllySigned = Note::where(function ($query) use ($performerProID) {
  479. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true)->where('is_cancelled', false);;
  480. })->count();
  481. $keyNumbers['pendingNotesToSignAllySigned'] = $pendingNotesToSignAllySigned;
  482. $signedNotesWithoutBills = Note::where(function ($query) use ($performerProID) {
  483. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', true)->where('is_cancelled', false);
  484. })->whereDoesntHave('bills')->count();
  485. $keyNumbers['signedNotesWithoutBills'] = $signedNotesWithoutBills;
  486. // open tickets
  487. $keyNumbers['numOpenTickets'] = Ticket::where('is_open', true)
  488. ->where(function ($q) use ($performerProID) {
  489. $q->where('assigned_pro_id', $performerProID)
  490. ->orWhere('manager_pro_id', $performerProID)
  491. ->orWhere('ordering_pro_id', $performerProID)
  492. ->orWhere('initiating_pro_id', $performerProID);
  493. })
  494. ->count();
  495. // unacknowledged cancelled bills for authed pro
  496. $keyNumbers['unacknowledgedCancelledBills'] = Bill::where('hcp_pro_id', $performerProID)
  497. ->where('is_cancelled', true)
  498. ->where('is_cancellation_acknowledged', false)
  499. ->count();
  500. // unacknowledged cancelled supply orders for authed pro
  501. $keyNumbers['unacknowledgedCancelledSupplyOrders'] = SupplyOrder::where('signed_by_pro_id', $performerProID)
  502. ->where('is_cancelled', true)
  503. ->where('is_cancellation_acknowledged', false)
  504. ->count();
  505. // unsigned supply orders created by authed pro
  506. $keyNumbers['unsignedSupplyOrders'] = SupplyOrder
  507. ::where('is_cancelled', false)
  508. ->where('is_signed_by_pro', false)
  509. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$performerProID])
  510. ->count();
  511. // patientsHavingBirthdayToday
  512. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  513. $keyNumbers['patientsHavingBirthdayToday'] = $queryClients
  514. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  515. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')])
  516. ->count();
  517. $reimbursement = [];
  518. $reimbursement["currentBalance"] = $performer->pro->balance;
  519. $reimbursement["nextPaymentDate"] = '--';
  520. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  521. if ($lastPayment) {
  522. $reimbursement["lastPayment"] = $lastPayment->amount;
  523. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  524. } else {
  525. $reimbursement["lastPayment"] = '--';
  526. $reimbursement["lastPaymentDate"] = '--';
  527. }
  528. //if today is < 15th, next payment is 15th, else nextPayment is
  529. $today = strtotime(date('Y-m-d'));
  530. $todayDate = date('j', $today);
  531. $todayMonth = date('m', $today);
  532. $todayYear = date('Y', $today);
  533. if ($todayDate < 15) {
  534. $nextPaymentDate = new DateTime();
  535. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  536. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  537. } else {
  538. $nextPaymentDate = new \DateTime();
  539. $lastDayOfMonth = date('t', $today);
  540. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  541. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  542. }
  543. //expectedPay
  544. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :performerProID AND has_hcp_been_paid = false AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  545. $expectedForCm = DB::select(DB::raw("SELECT coalesce(SUM(cm_expected_payment_amount),0) as expected_pay FROM bill WHERE cm_pro_id = :performerProID AND has_cm_been_paid = false AND is_signed_by_cm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  546. $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay FROM bill WHERE rme_pro_id = :performerProID AND has_rme_been_paid = false AND is_signed_by_rme IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  547. $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay FROM bill WHERE rmm_pro_id = :performerProID AND has_rmm_been_paid = false AND is_signed_by_rmm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  548. $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(generic_pro_expected_payment_amount),0) as expected_pay FROM bill WHERE generic_pro_id = :performerProID AND has_generic_pro_been_paid = false AND is_signed_by_generic_pro IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  549. $totalExpectedAmount = $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  550. $reimbursement['nextPaymentAmount'] = $totalExpectedAmount;
  551. $milliseconds = strtotime(date('Y-m-d')) . '000';
  552. // bills & claims
  553. $businessNumbers = [];
  554. // Notes with bills to resolve
  555. $businessNumbers['notesWithBillsToResolve'] = Note::where('is_cancelled', '!=', true)
  556. ->where('is_bill_closed', '!=', true)
  557. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND is_cancelled = false AND is_verified = false) > 0')
  558. ->count();
  559. // Notes pending bill closure
  560. $businessNumbers['notesPendingBillingClosure'] = Note::where('is_cancelled', '!=', true)
  561. ->where('is_bill_closed', '!=', true)
  562. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = true OR is_verified = true)) = 0')
  563. ->count();
  564. // incoming reports not signed
  565. $incomingReports = IncomingReport::where('hcp_pro_id', $performerProID)
  566. ->where('has_hcp_pro_signed', false)
  567. ->where('is_entry_error', false)
  568. ->orderBy('created_at', 'ASC')
  569. ->get();
  570. // erx, labs & imaging that are not closed
  571. $tickets = Ticket::where('ordering_pro_id', $performerProID)
  572. ->where('is_entry_error', false)
  573. ->where('is_open', true)
  574. ->orderBy('created_at', 'ASC')
  575. ->get();
  576. $supplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  577. ->where('is_cancelled', false)
  578. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  579. ->orderBy('created_at', 'ASC')
  580. ->get();
  581. $numERx = Ticket::where('ordering_pro_id', $performerProID)
  582. ->where('category', 'erx')
  583. ->where('is_entry_error', false)
  584. ->where('is_open', true)
  585. ->count();
  586. $numLabs = Ticket::where('ordering_pro_id', $performerProID)
  587. ->where('category', 'lab')
  588. ->where('is_entry_error', false)
  589. ->where('is_open', true)
  590. ->count();
  591. $numImaging = Ticket::where('ordering_pro_id', $performerProID)
  592. ->where('category', 'imaging')
  593. ->where('is_entry_error', false)
  594. ->where('is_open', true)
  595. ->count();
  596. $numSupplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  597. ->where('is_cancelled', false)
  598. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  599. ->count();
  600. $newMCPAssociations = ClientProChange
  601. ::where('new_pro_id', $performerProID)
  602. ->where('responsibility_type', 'MCP')
  603. ->whereNull('current_client_pro_change_decision_id')
  604. ->get();
  605. $newNAAssociations = ClientProChange
  606. ::where('new_pro_id', $performerProID)
  607. ->where('responsibility_type', 'DEFAULT_NA')
  608. ->whereNull('current_client_pro_change_decision_id')
  609. ->get();
  610. // unstamped client memos
  611. // for mcp
  612. $mcpClientMemos = DB::select(
  613. DB::raw("
  614. SELECT c.uid as client_uid, c.name_first, c.name_last,
  615. cm.uid, cm.content, cm.created_at
  616. FROM client c join client_memo cm on c.id = cm.client_id
  617. WHERE
  618. c.mcp_pro_id = {$performerProID} AND
  619. cm.mcp_stamp_id IS NULL
  620. ORDER BY cm.created_at DESC
  621. ")
  622. );
  623. // for na
  624. $naClientMemos = DB::select(
  625. DB::raw("
  626. SELECT c.uid as client_uid, c.name_first, c.name_last,
  627. cm.uid, cm.content, cm.created_at
  628. FROM client c join client_memo cm on c.id = cm.client_id
  629. WHERE
  630. c.default_na_pro_id = {$performerProID} AND
  631. cm.default_na_stamp_id IS NULL
  632. ORDER BY cm.created_at DESC
  633. ")
  634. );
  635. $keyNumbers['rmBillsToSign'] = Bill
  636. ::where('is_cancelled', false)
  637. ->where('cm_or_rm', 'RM')
  638. ->where(function ($q) use ($performerProID) {
  639. $q
  640. ->where(function ($q2) use ($performerProID) {
  641. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  642. })
  643. ->orWhere(function ($q2) use ($performerProID) {
  644. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  645. })
  646. ->orWhere(function ($q2) use ($performerProID) {
  647. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  648. })
  649. ->orWhere(function ($q2) use ($performerProID) {
  650. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  651. });
  652. })
  653. ->count();
  654. $count = DB::select(
  655. DB::raw(
  656. "
  657. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  658. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  659. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  660. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  661. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  662. AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL)
  663. "
  664. )
  665. );
  666. $keyNumbers['rmPatientsWithLT16MD'] = $count[0]->cnt;
  667. $count = DB::select(
  668. DB::raw(
  669. "
  670. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  671. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  672. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  673. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  674. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  675. AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL)
  676. "
  677. )
  678. );
  679. $keyNumbers['rmPatientsWithGTE16MD'] = $count[0]->cnt;
  680. $count = DB::select(
  681. DB::raw(
  682. "
  683. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  684. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  685. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  686. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  687. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  688. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL)
  689. "
  690. )
  691. );
  692. $keyNumbers['rmPatientsWithWhomCommDone'] = $count[0]->cnt;
  693. $count = DB::select(
  694. DB::raw(
  695. "
  696. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  697. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  698. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  699. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  700. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  701. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL)
  702. "
  703. )
  704. );
  705. $keyNumbers['rmPatientsWithWhomCommNotDone'] = $count[0]->cnt;
  706. // num measurements that need stamping
  707. $keyNumbers['measurementsToBeStamped'] = $this->performer()->pro->getUnstampedMeasurementsFromCurrentMonth(true, null, null);
  708. if($performer->pro->pro_type === 'ADMIN') {
  709. // patients without coverage information
  710. $keyNumbers['patientsWithoutCoverageInformation'] = DB::select(DB::raw("
  711. SELECT count(DISTINCT (cl.id)) as cnt
  712. FROM client cl
  713. WHERE cl.shadow_pro_id IS NULL AND cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
  714. ))[0]->cnt;
  715. // patients pending coverage verification
  716. $keyNumbers['patientsPendingCoverageVerification'] = DB::select(DB::raw("
  717. SELECT count(DISTINCT (cl.id)) as cnt
  718. FROM client cl
  719. LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id
  720. WHERE cl.shadow_pro_id IS NULL
  721. AND (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
  722. AND (
  723. (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
  724. OR
  725. (cpc.plan_type != 'MEDICARE' AND
  726. (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
  727. ))"
  728. ))[0]->cnt;
  729. }
  730. return view('app/dashboard-dna', compact('keyNumbers', 'reimbursement', 'milliseconds',
  731. 'businessNumbers',
  732. 'incomingReports', 'tickets', 'supplyOrders',
  733. 'numERx', 'numLabs', 'numImaging', 'numSupplyOrders',
  734. 'newMCPAssociations', 'newNAAssociations',
  735. 'mcpClientMemos', 'naClientMemos'));
  736. }
  737. private function dashboard_ADMIN(Request $request){
  738. $keyNumbers = [];
  739. // Patients // SELECT * FROM client WHERE mcp_pro_id = :me.id;
  740. // New Patients Awaiting Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND hasMcpDoneOnboardingVisit != 'YES';
  741. // Notes Pending Signature // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS NOT TRUE;
  742. // Notes Pending Billing // SELECT * FROM note WHERE hcp_pro_id = :me.id AND is_cancelled IS NOT TRUE AND has_hcp_signed IS TRUE AND is_billing_marked_done IS FALSE;
  743. // Reports Pending Signature // SELECT * FROM incoming_report WHERE hcp_pro_id = :me.id AND isEntryError IS NOT TRUE AND hasHcpProSigned IS NOT TRUE;
  744. // Patients w/o Appointments // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_mcp_appointment_date < today();
  745. // Patients Overdue for Visit // SELECT * FROM client WHERE mcp_pro_id = :me.id AND client.next_expected_mcp_visit_date < today();
  746. // Cancelled Appts. Pending Review // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  747. // Cancelled Bills Pending Review // SELECT * FROM bill WHERE bill_service_type = 'NOTE' AND is_cancelled IS TRUE AND isCancellationAcknowledged IS FALSE;
  748. // Cancelled Supply Orders Pending Review // SELECT * FROM supply_order WHERE signed_by_pro_id = :me.id AND is_cancelled IS TRUE AND isCancellationAcknowledged IS NOT TRUE;
  749. // ERx & Orders Pending Signature // SELECT * FROM erx WHERE hcp_pro_id = :me.id AND pro_declared_status <> 'CANCELLED' AND hasHcpProSigned IS NOT TRUE;
  750. // Supply Orders Pending Signature // SELECT supply_order.id FROM supply_order WHERE signed_by_pro_id IS NOT TRUE AND is_cancelled IS NOT TRUE AND created_by_pro_id = :me.id;
  751. $performer = $this->performer();
  752. $pro = $performer->pro;
  753. $performerProID = $performer->pro->id;
  754. $keyNumbers = [];
  755. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  756. $pendingNotesToSign = Note
  757. ::where(function ($query) use ($performerProID) {
  758. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  759. })
  760. ->orWhere(function ($query) use ($performerProID) {
  761. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false);
  762. })
  763. ->count();
  764. $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
  765. // notes pending mcp sign (applicable to dnas only)
  766. $pendingNotesToSignMCP = Note
  767. ::where(function ($query) use ($performerProID) {
  768. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  769. })
  770. ->count();
  771. $keyNumbers['$pendingNotesToSignMCP'] = $pendingNotesToSignMCP;
  772. $pendingNotesToSignAllySigned = Note::where(function ($query) use ($performerProID) {
  773. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true)->where('is_cancelled', false);;
  774. })->count();
  775. $keyNumbers['pendingNotesToSignAllySigned'] = $pendingNotesToSignAllySigned;
  776. $signedNotesWithoutBills = Note::where(function ($query) use ($performerProID) {
  777. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', true)->where('is_cancelled', false);
  778. })->whereDoesntHave('bills')->count();
  779. $keyNumbers['signedNotesWithoutBills'] = $signedNotesWithoutBills;
  780. // open tickets
  781. $keyNumbers['numOpenTickets'] = Ticket::where('is_open', true)
  782. ->where(function ($q) use ($performerProID) {
  783. $q->where('assigned_pro_id', $performerProID)
  784. ->orWhere('manager_pro_id', $performerProID)
  785. ->orWhere('ordering_pro_id', $performerProID)
  786. ->orWhere('initiating_pro_id', $performerProID);
  787. })
  788. ->count();
  789. // unacknowledged cancelled bills for authed pro
  790. $keyNumbers['unacknowledgedCancelledBills'] = Bill::where('hcp_pro_id', $performerProID)
  791. ->where('is_cancelled', true)
  792. ->where('is_cancellation_acknowledged', false)
  793. ->count();
  794. // unacknowledged cancelled supply orders for authed pro
  795. $keyNumbers['unacknowledgedCancelledSupplyOrders'] = SupplyOrder::where('signed_by_pro_id', $performerProID)
  796. ->where('is_cancelled', true)
  797. ->where('is_cancellation_acknowledged', false)
  798. ->count();
  799. // unsigned supply orders created by authed pro
  800. $keyNumbers['unsignedSupplyOrders'] = SupplyOrder
  801. ::where('is_cancelled', false)
  802. ->where('is_signed_by_pro', false)
  803. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$performerProID])
  804. ->count();
  805. // patientsHavingBirthdayToday
  806. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  807. $keyNumbers['patientsHavingBirthdayToday'] = $queryClients
  808. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  809. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')])
  810. ->count();
  811. $reimbursement = [];
  812. $reimbursement["currentBalance"] = $performer->pro->balance;
  813. $reimbursement["nextPaymentDate"] = '--';
  814. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  815. if ($lastPayment) {
  816. $reimbursement["lastPayment"] = $lastPayment->amount;
  817. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  818. } else {
  819. $reimbursement["lastPayment"] = '--';
  820. $reimbursement["lastPaymentDate"] = '--';
  821. }
  822. //if today is < 15th, next payment is 15th, else nextPayment is
  823. $today = strtotime(date('Y-m-d'));
  824. $todayDate = date('j', $today);
  825. $todayMonth = date('m', $today);
  826. $todayYear = date('Y', $today);
  827. if ($todayDate < 15) {
  828. $nextPaymentDate = new DateTime();
  829. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  830. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  831. } else {
  832. $nextPaymentDate = new \DateTime();
  833. $lastDayOfMonth = date('t', $today);
  834. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  835. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  836. }
  837. //expectedPay
  838. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :performerProID AND has_hcp_been_paid = false AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  839. $expectedForCm = DB::select(DB::raw("SELECT coalesce(SUM(cm_expected_payment_amount),0) as expected_pay FROM bill WHERE cm_pro_id = :performerProID AND has_cm_been_paid = false AND is_signed_by_cm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  840. $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay FROM bill WHERE rme_pro_id = :performerProID AND has_rme_been_paid = false AND is_signed_by_rme IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  841. $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay FROM bill WHERE rmm_pro_id = :performerProID AND has_rmm_been_paid = false AND is_signed_by_rmm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  842. $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(generic_pro_expected_payment_amount),0) as expected_pay FROM bill WHERE generic_pro_id = :performerProID AND has_generic_pro_been_paid = false AND is_signed_by_generic_pro IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  843. $totalExpectedAmount = $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  844. $reimbursement['nextPaymentAmount'] = $totalExpectedAmount;
  845. $milliseconds = strtotime(date('Y-m-d')) . '000';
  846. // bills & claims
  847. $businessNumbers = [];
  848. // Notes with bills to resolve
  849. $businessNumbers['notesWithBillsToResolve'] = Note::where('is_cancelled', '!=', true)
  850. ->where('is_bill_closed', '!=', true)
  851. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND is_cancelled = false AND is_verified = false) > 0')
  852. ->count();
  853. // Notes pending bill closure
  854. $businessNumbers['notesPendingBillingClosure'] = Note::where('is_cancelled', '!=', true)
  855. ->where('is_bill_closed', '!=', true)
  856. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = true OR is_verified = true)) = 0')
  857. ->count();
  858. // incoming reports not signed
  859. $incomingReports = IncomingReport::where('hcp_pro_id', $performerProID)
  860. ->where('has_hcp_pro_signed', false)
  861. ->where('is_entry_error', false)
  862. ->orderBy('created_at', 'ASC')
  863. ->get();
  864. // erx, labs & imaging that are not closed
  865. $tickets = Ticket::where('ordering_pro_id', $performerProID)
  866. ->where('is_entry_error', false)
  867. ->where('is_open', true)
  868. ->orderBy('created_at', 'ASC')
  869. ->get();
  870. $supplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  871. ->where('is_cancelled', false)
  872. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  873. ->orderBy('created_at', 'ASC')
  874. ->get();
  875. $numERx = Ticket::where('ordering_pro_id', $performerProID)
  876. ->where('category', 'erx')
  877. ->where('is_entry_error', false)
  878. ->where('is_open', true)
  879. ->count();
  880. $numLabs = Ticket::where('ordering_pro_id', $performerProID)
  881. ->where('category', 'lab')
  882. ->where('is_entry_error', false)
  883. ->where('is_open', true)
  884. ->count();
  885. $numImaging = Ticket::where('ordering_pro_id', $performerProID)
  886. ->where('category', 'imaging')
  887. ->where('is_entry_error', false)
  888. ->where('is_open', true)
  889. ->count();
  890. $numSupplyOrders = SupplyOrder::where('is_cleared_for_shipment', false)
  891. ->where('is_cancelled', false)
  892. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session where pro_id = ?)', [$performer->pro->id])
  893. ->count();
  894. $newMCPAssociations = ClientProChange
  895. ::where('new_pro_id', $performerProID)
  896. ->where('responsibility_type', 'MCP')
  897. ->whereNull('current_client_pro_change_decision_id')
  898. ->get();
  899. $newNAAssociations = ClientProChange
  900. ::where('new_pro_id', $performerProID)
  901. ->where('responsibility_type', 'DEFAULT_NA')
  902. ->whereNull('current_client_pro_change_decision_id')
  903. ->get();
  904. $proApptUpdates = AppointmentConfirmationDecision
  905. ::select('appointment_confirmation_decision.uid', 'client.name_first', 'client.name_last', 'appointment.start_time')
  906. ->rightJoin('appointment', 'appointment.id', '=', 'appointment_confirmation_decision.appointment_id')
  907. ->rightJoin('client', 'client.id', '=', 'appointment.client_id')
  908. ->where('appointment_confirmation_decision.was_acknowledged_by_appointment_pro', false)
  909. ->where('appointment.status', '!=', 'CREATED')
  910. ->where('appointment.status', '!=', 'COMPLETED')
  911. ->where('appointment.status', '!=', 'ABANDONED')
  912. ->where('appointment.pro_id', $performerProID)
  913. ->where('client.mcp_pro_id', $performerProID)
  914. ->orderBy('appointment.start_time', 'DESC')
  915. ->get();
  916. $naApptUpdates = AppointmentConfirmationDecision
  917. ::select('appointment_confirmation_decision.uid', 'client.name_first', 'client.name_last', 'pro.name_first as pro_name_first', 'pro.name_last as pro_name_last', 'appointment.start_time')
  918. ->rightJoin('appointment', 'appointment.id', '=', 'appointment_confirmation_decision.appointment_id')
  919. ->rightJoin('client', 'client.id', '=', 'appointment.client_id')
  920. ->rightJoin('pro', 'pro.id', '=', 'appointment.pro_id')
  921. ->where('appointment_confirmation_decision.was_acknowledged_by_client_default_na', false)
  922. ->where('appointment.status', '!=', 'CREATED')
  923. ->where('appointment.status', '!=', 'COMPLETED')
  924. ->where('appointment.status', '!=', 'ABANDONED')
  925. ->where('client.default_na_pro_id', $performerProID)
  926. ->orderBy('appointment.start_time', 'DESC')
  927. ->get();
  928. // $naApptUpdates = AppointmentConfirmationDecision
  929. // ::join('appointment', 'appointment.id', '=', 'appointment_confirmation_decision.appointment_id')
  930. // ->join('client', 'client.id', '=', 'appointment.client_id')
  931. // ->where('client.default_na_pro_id', $performerProID)
  932. // ->where('appointment_confirmation_decision.was_acknowledged_by_client_default_na', false)
  933. // ->orderBy('appointment.start_time DESC')
  934. // ->get();
  935. // unstamped client memos
  936. // for mcp
  937. $mcpClientMemos = DB::select(
  938. DB::raw("
  939. SELECT c.uid as client_uid, c.name_first, c.name_last,
  940. cm.uid, cm.content, cm.created_at
  941. FROM client c join client_memo cm on c.id = cm.client_id
  942. WHERE
  943. c.mcp_pro_id = {$performerProID} AND
  944. cm.mcp_stamp_id IS NULL
  945. ORDER BY cm.created_at DESC
  946. ")
  947. );
  948. // for na
  949. $naClientMemos = DB::select(
  950. DB::raw("
  951. SELECT c.uid as client_uid, c.name_first, c.name_last,
  952. cm.uid, cm.content, cm.created_at
  953. FROM client c join client_memo cm on c.id = cm.client_id
  954. WHERE
  955. c.default_na_pro_id = {$performerProID} AND
  956. cm.default_na_stamp_id IS NULL
  957. ORDER BY cm.created_at DESC
  958. ")
  959. );
  960. $keyNumbers['rmBillsToSign'] = Bill
  961. ::where('is_cancelled', false)
  962. ->where('cm_or_rm', 'RM')
  963. ->where(function ($q) use ($performerProID) {
  964. $q
  965. ->where(function ($q2) use ($performerProID) {
  966. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  967. })
  968. ->orWhere(function ($q2) use ($performerProID) {
  969. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  970. })
  971. ->orWhere(function ($q2) use ($performerProID) {
  972. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  973. })
  974. ->orWhere(function ($q2) use ($performerProID) {
  975. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  976. });
  977. })
  978. ->count();
  979. $count = DB::select(
  980. DB::raw(
  981. "
  982. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  983. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  984. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  985. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  986. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  987. AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL)
  988. "
  989. )
  990. );
  991. $keyNumbers['rmPatientsWithLT16MD'] = $count[0]->cnt;
  992. $count = DB::select(
  993. DB::raw(
  994. "
  995. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  996. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  997. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  998. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  999. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  1000. AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL)
  1001. "
  1002. )
  1003. );
  1004. $keyNumbers['rmPatientsWithGTE16MD'] = $count[0]->cnt;
  1005. $count = DB::select(
  1006. DB::raw(
  1007. "
  1008. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  1009. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  1010. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  1011. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  1012. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  1013. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL)
  1014. "
  1015. )
  1016. );
  1017. $keyNumbers['rmPatientsWithWhomCommDone'] = $count[0]->cnt;
  1018. $count = DB::select(
  1019. DB::raw(
  1020. "
  1021. SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
  1022. WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
  1023. OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_pro_id = {$performer->pro->id}))
  1024. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
  1025. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
  1026. AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL)
  1027. "
  1028. )
  1029. );
  1030. $keyNumbers['rmPatientsWithWhomCommNotDone'] = $count[0]->cnt;
  1031. // num measurements that need stamping
  1032. $keyNumbers['measurementsToBeStamped'] = $this->performer()->pro->getUnstampedMeasurementsFromCurrentMonth(true, null, null);
  1033. if($performer->pro->pro_type === 'ADMIN') {
  1034. // patients without coverage information
  1035. $keyNumbers['patientsWithoutCoverageInformation'] = DB::select(DB::raw("
  1036. SELECT count(DISTINCT (cl.id)) as cnt
  1037. FROM client cl
  1038. WHERE cl.shadow_pro_id IS NULL AND cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
  1039. ))[0]->cnt;
  1040. // patients pending coverage verification
  1041. $keyNumbers['patientsPendingCoverageVerification'] = DB::select(DB::raw("
  1042. SELECT count(DISTINCT (cl.id)) as cnt
  1043. FROM client cl
  1044. LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id
  1045. WHERE cl.shadow_pro_id IS NULL
  1046. AND (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
  1047. AND (
  1048. (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
  1049. OR
  1050. (cpc.plan_type != 'MEDICARE' AND
  1051. (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
  1052. ))"
  1053. ))[0]->cnt;
  1054. }
  1055. return view('app/dashboard-admin', compact('keyNumbers', 'reimbursement', 'milliseconds',
  1056. 'businessNumbers',
  1057. 'incomingReports', 'tickets', 'supplyOrders',
  1058. 'numERx', 'numLabs', 'numImaging', 'numSupplyOrders',
  1059. 'newMCPAssociations', 'newNAAssociations',
  1060. 'mcpClientMemos', 'naClientMemos',
  1061. 'proApptUpdates', 'naApptUpdates'));
  1062. }
  1063. public function dashboard(Request $request)
  1064. {
  1065. $performer = $this->performer();
  1066. $pro = $performer->pro;
  1067. if($pro->is_enrolled_as_mcp){
  1068. return $this->dashboard_MCP($request);
  1069. }elseif($pro->pro_type === 'ADMIN'){
  1070. return $this->dashboard_ADMIN($request);
  1071. }else{
  1072. return $this->dashboard_DNA($request);
  1073. }
  1074. }
  1075. public function dashboardMeasurementsTab(Request $request, $page = 1) {
  1076. $performer = $this->performer();
  1077. $myClientIDs = [];
  1078. if ($performer->pro->pro_type != 'ADMIN') {
  1079. $myClientIDs = $this->getMyClientIds();
  1080. $myClientIDs = implode(", ", $myClientIDs);
  1081. }
  1082. $ifNotAdmin = " AND (
  1083. client.mcp_pro_id = {$performer->pro->id}
  1084. OR client.rmm_pro_id = {$performer->pro->id}
  1085. OR client.rme_pro_id = {$performer->pro->id}
  1086. OR client.physician_pro_id = {$performer->pro->id}
  1087. OR client.id in (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = {$performer->pro->id})
  1088. OR client.id in (SELECT client_id FROM appointment WHERE status NOT IN ('CANCELLED') AND pro_id = {$performer->pro->id})
  1089. )";
  1090. $numMeasurements = DB::select(
  1091. DB::raw(
  1092. "
  1093. SELECT count(measurement.id) as cnt
  1094. FROM measurement
  1095. join client on measurement.client_id = client.id
  1096. WHERE measurement.label NOT IN ('SBP', 'DBP')
  1097. AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
  1098. AND measurement.is_removed IS FALSE
  1099. AND measurement.has_been_stamped_by_mcp IS FALSE
  1100. AND measurement.ts IS NOT NULL
  1101. AND measurement.client_bdt_measurement_id IS NOT NULL
  1102. AND (measurement.status IS NULL OR (measurement.status <> 'ACK' AND measurement.status <> 'INVALID_ACK'))
  1103. AND EXTRACT(MONTH from measurement.created_at) = EXTRACT(MONTH from NOW())
  1104. AND EXTRACT(YEAR from measurement.created_at) = EXTRACT(YEAR from NOW())
  1105. " .
  1106. (
  1107. $performer->pro->pro_type != 'ADMIN' ? $ifNotAdmin : ''
  1108. )
  1109. )
  1110. );
  1111. $numMeasurements = $numMeasurements[0]->cnt;
  1112. $measurements = DB::select(
  1113. DB::raw(
  1114. "
  1115. SELECT measurement.uid as uid,
  1116. care_month.uid as care_month_uid,
  1117. care_month.start_date as care_month_start_date,
  1118. measurement.label,
  1119. measurement.value,
  1120. measurement.sbp_mm_hg,
  1121. measurement.dbp_mm_hg,
  1122. measurement.numeric_value,
  1123. measurement.value_pulse,
  1124. measurement.value_irregular,
  1125. measurement.ts,
  1126. client.id as client_id,
  1127. client.mcp_pro_id,
  1128. client.default_na_pro_id,
  1129. client.rmm_pro_id,
  1130. client.rme_pro_id,
  1131. client.uid as client_uid,
  1132. client.name_last,
  1133. client.name_first,
  1134. care_month.rm_total_time_in_seconds
  1135. FROM measurement
  1136. join client on measurement.client_id = client.id
  1137. join care_month on client.id = care_month.client_id
  1138. WHERE measurement.label NOT IN ('SBP', 'DBP')
  1139. AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
  1140. AND measurement.is_removed IS FALSE
  1141. AND measurement.has_been_stamped_by_mcp IS FALSE
  1142. AND measurement.ts IS NOT NULL
  1143. AND measurement.client_bdt_measurement_id IS NOT NULL
  1144. AND (measurement.status IS NULL OR (measurement.status <> 'ACK' AND measurement.status <> 'INVALID_ACK'))
  1145. AND EXTRACT(MONTH from measurement.created_at) = EXTRACT(MONTH from NOW())
  1146. AND EXTRACT(YEAR from measurement.created_at) = EXTRACT(YEAR from NOW())
  1147. AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from NOW())
  1148. AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from NOW())
  1149. " .
  1150. (
  1151. $performer->pro->pro_type != 'ADMIN' ? $ifNotAdmin : ''
  1152. )
  1153. ) .
  1154. " ORDER BY measurement.ts DESC LIMIT 20 OFFSET " . (($page - 1) * 20)
  1155. );
  1156. return view('app.dashboard.measurements', compact('numMeasurements', 'measurements', 'page'));
  1157. }
  1158. public function dashboardAppointmentDates(Request $request, $from, $to) {
  1159. $performer = $this->performer();
  1160. $performerProID = $performer->pro->id;
  1161. $isAdmin = ($performer->pro->pro_type === 'ADMIN');
  1162. $results = DB::table('appointment')->select('raw_date')->distinct()->where("start_time", '>=', $from)->where("start_time", '<=', $to.' 23:59:00+00');
  1163. if(!$isAdmin) {
  1164. $results = $results->where("pro_id", $performerProID);
  1165. }
  1166. $results = $results->get();
  1167. $dates = [];
  1168. foreach ($results as $result) {
  1169. // $dates[] = strtotime($result->raw_date) . '000';
  1170. $dates[] = $result->raw_date;
  1171. }
  1172. // foreach ($results as $result) {
  1173. // $results->dateYMD = date('Y-m-d', strtotime($result->raw_date));
  1174. // }
  1175. return json_encode($dates);
  1176. }
  1177. public function dashboardAppointments(Request $request, $from, $to) {
  1178. $performer = $this->performer();
  1179. $performerProID = $performer->pro->id;
  1180. $isAdmin = ($performer->pro->pro_type === 'ADMIN');
  1181. // $appointments = Appointment::where("start_time", '>=', $from)->where("start_time", '<=', $to.' 23:59:00+00');
  1182. $appointments = Appointment::where("raw_date", '=', $from);
  1183. if(!$isAdmin) {
  1184. $appointments = $appointments->where("pro_id", $performerProID);
  1185. }
  1186. $appointments = $appointments
  1187. ->whereRaw('status NOT IN (\'CANCELLED\', \'COMPLETED\')')
  1188. ->orderBy('start_time', 'asc')
  1189. ->get();
  1190. foreach ($appointments as $appointment) {
  1191. $date = explode(" ", $appointment->start_time)[0];
  1192. $appointment->milliseconds = strtotime($date) . '000';
  1193. $appointment->newStatus = $appointment->status;
  1194. $appointment->dateYMD = date('Y-m-d', strtotime($appointment->raw_date));
  1195. $appointment->clientName = $appointment->client->displayName();
  1196. $appointment->clientInitials = substr($appointment->client->name_first, 0, 1) . substr($appointment->client->name_last, 0, 1);
  1197. $appointment->isClientShadowOfPro = $appointment->client->shadow_pro_id ? true : false;
  1198. $appointment->proInitials = substr($appointment->pro->name_first, 0, 1) . substr($appointment->pro->name_last, 0, 1);
  1199. $appointment->friendlyStartTime = friendly_time($appointment->raw_start_time);
  1200. $appointment->friendlyEndTime = friendly_time($appointment->raw_end_time);
  1201. $appointment->clientSummary = friendly_date_time($appointment->client->dob, false) . ' (' .
  1202. $appointment->client->age_in_years . ' y.o' .
  1203. ($appointment->client->sex ? ' ' . $appointment->client->sex : '') .
  1204. ')';
  1205. $appointment->clientAge = $appointment->client->age_in_years;
  1206. $appointment->clientSex = $appointment->client->sex;
  1207. $appointment->started = false;
  1208. $appointment->inHowManyHours = date_diff(date_create('now'), date_create($appointment->start_time), false)
  1209. ->format('%R%h h, %i m');
  1210. if ($appointment->inHowManyHours[0] === '-') {
  1211. $appointment->inHowManyHours = substr($appointment->inHowManyHours, 1) . ' ago';
  1212. $appointment->started = true;
  1213. } else {
  1214. $appointment->inHowManyHours = 'Appt. in ' . substr($appointment->inHowManyHours, 1);
  1215. }
  1216. $appointment->clientUid = $appointment->client->uid;
  1217. $appointment->proUid = $appointment->pro->uid;
  1218. $appointment->proName = $appointment->pro->displayName();
  1219. // insurance information
  1220. $appointment->coverage = $appointment->client->getPrimaryCoverageStatus();
  1221. unset($appointment->client);
  1222. unset($appointment->pro);
  1223. unset($appointment->detail_json);
  1224. }
  1225. return json_encode($appointments);
  1226. }
  1227. public function dashboardMeasurements(Request $request, $filter) {
  1228. $measurements = $this->performer()->pro->getMeasurements($filter === 'NEED_ACK');
  1229. return json_encode($measurements);
  1230. }
  1231. public function patients(Request $request, $filter = '')
  1232. {
  1233. $performer = $this->performer();
  1234. $query = $performer->pro->getAccessibleClientsQuery();
  1235. $q = trim($request->input('q'));
  1236. if(!empty($q)) {
  1237. $query = $query->where(function ($query) use ($q) {
  1238. $query->where('name_first', 'ILIKE', "%$q%")
  1239. ->orWhere('name_last', 'ILIKE', "%$q%")
  1240. ->orWhere('email_address', 'ILIKE', "%$q%")
  1241. ->orWhere('tags', 'ILIKE', "%$q%");
  1242. });
  1243. }
  1244. switch ($filter) {
  1245. case 'not-yet-seen':
  1246. $query = $query
  1247. ->where(function ($query) use ($performer) {
  1248. $query
  1249. ->where(function ($query) use ($performer) { // own patient and primary OB visit pending
  1250. $query->where('mcp_pro_id', $performer->pro->id)
  1251. ->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  1252. })
  1253. ->orWhere(function ($query) use ($performer) { // mcp of any client program and program OB pending
  1254. $query->select(DB::raw('COUNT(id)'))
  1255. ->from('client_program')
  1256. ->whereColumn('client_id', 'client.id')
  1257. ->where('mcp_pro_id', $performer->pro->id)
  1258. ->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  1259. }, '>=', 1);
  1260. });
  1261. break;
  1262. case 'having-birthday-today':
  1263. $query = $query
  1264. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  1265. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')]);
  1266. break;
  1267. // more cases can be added as needed
  1268. default:
  1269. break;
  1270. }
  1271. $patients = $query->orderBy('id', 'desc')->paginate(50);
  1272. // patient acquisition chart (admin only)
  1273. $patientAcquisitionData = null;
  1274. if($performer->pro->pro_type === 'ADMIN') {
  1275. $startDate = date_sub(date_create(), date_interval_create_from_date_string("1 month"));
  1276. $startDate = date_format($startDate, "Y-m-d");
  1277. $patientAcquisitionData = DB::select(DB::raw(
  1278. "SELECT count(id) as count, DATE(created_at at time zone 'utc' at time zone 'est') as date " .
  1279. "FROM client " .
  1280. "WHERE shadow_pro_id IS NULL " .
  1281. "GROUP BY DATE(created_at at time zone 'utc' at time zone 'est') " .
  1282. "ORDER BY DATE(created_at at time zone 'utc' at time zone 'est') DESC " .
  1283. "LIMIT 30"));
  1284. }
  1285. return view('app/patients', compact('patients', 'filter', 'patientAcquisitionData'));
  1286. }
  1287. public function patientsSuggest(Request $request)
  1288. {
  1289. $pro = $this->pro;
  1290. $term = $request->input('term') ? trim($request->input('term')) : '';
  1291. $originalTerm = $term;
  1292. if (empty($term)) return '';
  1293. // if multiple words in query, check for all (max 2)
  1294. $term2 = '';
  1295. if(strpos($term, ' ') !== FALSE) {
  1296. $terms = explode(' ', $term);
  1297. $term = trim($terms[0]);
  1298. $term2 = trim($terms[1]);
  1299. }
  1300. $phoneNumberTerm = preg_replace("/[^0-9]/", "", $originalTerm );
  1301. if($phoneNumberTerm == ""){ //to avoid search with blank string
  1302. $phoneNumberTerm = $term;
  1303. }
  1304. $clientQuery= Client::whereNull('shadow_pro_id')
  1305. ->where(function ($q) use ($term, $phoneNumberTerm) {
  1306. $q->where('name_first', 'ILIKE', '%' . $term . '%')
  1307. ->orWhere('name_last', 'ILIKE', '%' . $term . '%')
  1308. ->orWhere('cell_number', 'ILIKE', '%' . $phoneNumberTerm . '%')
  1309. ->orWhere('phone_home', 'ILIKE', '%' . $phoneNumberTerm . '%');
  1310. });
  1311. if(!empty($term2)) {
  1312. $clientQuery = $clientQuery->where(function ($q) use ($term2, $phoneNumberTerm) {
  1313. $q->where('name_first', 'ILIKE', '%' . $term2 . '%')
  1314. ->orWhere('name_last', 'ILIKE', '%' . $term2 . '%')
  1315. ->orWhere('cell_number', 'ILIKE', '%' . $phoneNumberTerm . '%')
  1316. ->orWhere('phone_home', 'ILIKE', '%' . $phoneNumberTerm . '%');
  1317. });
  1318. }
  1319. if(!($pro->pro_type === 'ADMIN' && $pro->can_see_any_client_via_search)) {
  1320. $clientQuery->where(function ($q) use ($pro) {
  1321. if($pro->pro_type === 'ADMIN') {
  1322. $q->whereIn('id', $pro->getMyClientIds(true))->orWhereNull('mcp_pro_id');
  1323. }
  1324. else {
  1325. $q->whereIn('id', $pro->getMyClientIds(true));
  1326. }
  1327. });
  1328. }
  1329. $clients = $clientQuery->get();
  1330. return view('app/patient-suggest', compact('clients'));
  1331. }
  1332. public function pharmacySuggest(Request $request)
  1333. {
  1334. $term = $request->input('term') ? trim($request->input('term')) : '';
  1335. if (empty($term)) return '';
  1336. $term = strtolower($term);
  1337. $pharmacies = Facility::where('facility_type', 'Pharmacy')
  1338. ->where(function ($q) use ($term) {
  1339. $q->orWhereRaw('LOWER(name::text) LIKE ?', ['%' . $term . '%'])
  1340. ->orWhereRaw('LOWER(address_line1::text) LIKE ?', ['%' . $term . '%'])
  1341. ->orWhereRaw('LOWER(address_line2::text) LIKE ?', ['%' . $term . '%'])
  1342. ->orWhereRaw('LOWER(address_city::text) LIKE ?', ['%' . $term . '%'])
  1343. ->orWhereRaw('LOWER(address_state::text) LIKE ?', ['%' . $term . '%'])
  1344. ->orWhereRaw('LOWER(phone::text) LIKE ?', ['%' . $term . '%'])
  1345. ->orWhereRaw('LOWER(address_zip::text) LIKE ?', ['%' . $term . '%']);
  1346. });
  1347. if($request->input('city')) {
  1348. $pharmacies = $pharmacies->whereRaw('LOWER(address_city::text) LIKE ?', ['%' . strtolower($request->input('city')) . '%']);
  1349. }
  1350. if($request->input('state')) {
  1351. $pharmacies = $pharmacies->whereRaw('LOWER(address_state::text) LIKE ?', ['%' . strtolower($request->input('state')) . '%']);
  1352. }
  1353. if($request->input('zip')) {
  1354. $pharmacies = $pharmacies->whereRaw('LOWER(address_zip::text) LIKE ?', ['%' . strtolower($request->input('zip')) . '%']);
  1355. }
  1356. $pharmacies = $pharmacies
  1357. ->orderBy('name', 'asc')
  1358. ->orderBy('address_line1', 'asc')
  1359. ->orderBy('address_city', 'asc')
  1360. ->orderBy('address_state', 'asc')
  1361. ->get();
  1362. return view('app/pharmacy-suggest', compact('pharmacies'));
  1363. }
  1364. public function proSuggest(Request $request) {
  1365. $term = $request->input('term') ? trim($request->input('term')) : '';
  1366. if (empty($term)) return '';
  1367. $term = strtolower($term);
  1368. $pros = Pro::where(function ($q) use ($term) {
  1369. $q->orWhereRaw('LOWER(name_first::text) LIKE ?', ['%' . $term . '%'])
  1370. ->orWhereRaw('LOWER(name_last::text) LIKE ?', ['%' . $term . '%'])
  1371. ->orWhereRaw('cell_number LIKE ?', ['%' . $term . '%']);
  1372. });
  1373. $type = $request->input('type') ? trim($request->input('type')) : '';
  1374. if(!!$type) {
  1375. switch(strtolower($type)) {
  1376. case 'hcp':
  1377. $pros->where('is_hcp', true);
  1378. break;
  1379. case 'default-na': // TODO: fix condition for NA
  1380. $pros->where('is_hcp', false)->where('pro_type', '!=', 'ADMIN');
  1381. break;
  1382. case 'admin':
  1383. $pros->where('pro_type', 'ADMIN');
  1384. break;
  1385. case 'non-admin':
  1386. $pros->where('pro_type', '!=', 'ADMIN');
  1387. break;
  1388. }
  1389. }
  1390. if($this->performer->pro && $this->performer->pro->pro_type != 'ADMIN'){
  1391. $accessiblePros = ProProAccess::where('owner_pro_id', $this->performer->pro->id);
  1392. $accessibleProIds = [];
  1393. foreach($accessiblePros as $accessiblePro){
  1394. $accessibleProIds[] = $accessiblePro->id;
  1395. }
  1396. $accessibleProIds[] = $this->performer->pro->id;
  1397. // for dna, add pros accessible via pro teams
  1398. if($this->performer->pro->isDefaultNA()) {
  1399. $teams = $this->performer->pro->teamsWhereAssistant;
  1400. foreach ($teams as $team) {
  1401. if(!in_array($team->mcp_pro_id, $accessibleProIds)) {
  1402. $accessibleProIds[] = $team->mcp_pro_id;
  1403. }
  1404. }
  1405. }
  1406. $pros->whereIn('id', $accessibleProIds);
  1407. }
  1408. $suggestedPros = $pros->orderBy('name_last')->orderBy('name_first')->get();
  1409. // for calendar select2
  1410. if($request->input('json')) {
  1411. $jsonPros = $suggestedPros->map(function($_pro) {
  1412. return [
  1413. "uid" => $_pro->uid,
  1414. "id" => $_pro->id,
  1415. "text" => $_pro->displayName(),
  1416. "initials" => $_pro->initials(),
  1417. ];
  1418. });
  1419. return json_encode([
  1420. "results" => $jsonPros
  1421. ]);
  1422. }
  1423. return view('app/pro-suggest', compact('suggestedPros'));
  1424. }
  1425. public function canAccessPatient(Request $request, $uid) {
  1426. return json_encode([
  1427. "success" => true,
  1428. "data" => $this->performer->pro->canAccess($uid)
  1429. ]);
  1430. }
  1431. public function proDisplayName(Request $request, Pro $pro) {
  1432. return $pro ? $pro->displayName() : '';
  1433. }
  1434. public function unmappedSMS(Request $request, $filter = '')
  1435. {
  1436. $proID = $this->performer()->pro->id;
  1437. if ($this->performer()->pro->pro_type === 'ADMIN') {
  1438. $query = Client::where('id', '>', 0);
  1439. } else {
  1440. $query = Client::where(function ($q) use ($proID) {
  1441. $q->where('mcp_pro_id', $proID)
  1442. ->orWhere('cm_pro_id', $proID)
  1443. ->orWhere('rmm_pro_id', $proID)
  1444. ->orWhere('rme_pro_id', $proID)
  1445. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID]);
  1446. });
  1447. }
  1448. $patients = $query->orderBy('name_last', 'asc')->orderBy('name_first', 'asc')->get();
  1449. $unmappedSMS = ClientSMS::where('client_id', null)->where('incoming_or_outgoing', 'INCOMING')->paginate(20);
  1450. return view('app/unmapped-sms', compact('unmappedSMS', 'patients'));
  1451. }
  1452. public function newPatient(Request $request)
  1453. {
  1454. $mbPayers = MBPayer::all();
  1455. return view('app/new-patient', compact('mbPayers'));
  1456. }
  1457. public function newNonMcnPatient(Request $request)
  1458. {
  1459. $mbPayers = MBPayer::all();
  1460. return view('app/new-non-mcn-patient', compact('mbPayers'));
  1461. }
  1462. public function mc(Request $request, $fragment = "")
  1463. {
  1464. $page = "/";
  1465. if ($fragment) {
  1466. $page = '/' . $fragment;
  1467. }
  1468. return view('app/mc', compact('page'));
  1469. }
  1470. public function blank(Request $request)
  1471. {
  1472. return view('app/blank');
  1473. }
  1474. public function noteTemplateSet(Request $request, $section, $template)
  1475. {
  1476. return view('app/patient/note/_template', [
  1477. "sectionInternalName" => $section,
  1478. "templateName" => $template
  1479. ]);
  1480. }
  1481. public function noteExamTemplateSet(Request $request, $exam, $template)
  1482. {
  1483. return view('app/patient/note/_template-exam', [
  1484. "exam" => $exam,
  1485. "sectionInternalName" => 'exam-' . $exam . '-detail',
  1486. "templateName" => $template
  1487. ]);
  1488. }
  1489. public function logInAs(Request $request)
  1490. {
  1491. if($this->pro->pro_type != 'ADMIN'){
  1492. return redirect()->to(route('dashboard'));
  1493. }
  1494. // dummy condition to get the chain-ability going
  1495. $pros = Pro::where('id', '>', 0);
  1496. if($request->input('q')) {
  1497. $nameQuery = '%' . $request->input('q') . '%';
  1498. $pros = $pros->where(function ($query) use ($nameQuery) {
  1499. $query->where('name_first', 'ILIKE', $nameQuery)
  1500. ->orWhere('name_last', 'ILIKE', $nameQuery)
  1501. ->orWhere('email_address', 'ILIKE', $nameQuery)
  1502. ->orWhere('cell_number', 'ILIKE', $nameQuery);
  1503. });
  1504. }
  1505. if($request->input('sort') && $request->input('dir')) {
  1506. $pros = $pros->orderBy($request->input('sort'), $request->input('dir'));
  1507. }
  1508. else {
  1509. $pros = $pros->orderBy('name_last', 'asc');
  1510. }
  1511. $pros = $pros->paginate(20);
  1512. return view('app/log-in-as', ['logInAsPros' => $pros]);
  1513. }
  1514. public function processLogInAs(Request $request)
  1515. {
  1516. $api = new Backend();
  1517. try {
  1518. $apiResponse = $api->post('session/proLogInAs', [
  1519. 'proUid' => $request->post('proUid')
  1520. ],
  1521. [
  1522. 'sessionKey'=>$this->performer()->session_key
  1523. ]);
  1524. $data = json_decode($apiResponse->getContents());
  1525. if (!property_exists($data, 'success') || !$data->success) {
  1526. return redirect()->to(route('log-in-as'))->with('message', $data->message)
  1527. ->withInput($request->input());
  1528. }
  1529. Cookie::queue('sessionKey', $data->data->sessionKey);
  1530. return redirect('/mc');
  1531. } catch (\Exception $e) {
  1532. return redirect()->to(route('log-in-as'))
  1533. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  1534. ->withInput($request->input());
  1535. }
  1536. }
  1537. public function backToAdminPro(Request $request){
  1538. $adminPerformerId = $this->performer->logged_in_as_pro_from_admin_pro_app_session_id;
  1539. $adminPerformer = AppSession::where('id', $adminPerformerId)->first();
  1540. $url = "/session/pro_log_in_with_session_key/".$adminPerformer->session_key;
  1541. $api = new Backend();
  1542. try {
  1543. $apiResponse = $api->post($url, []);
  1544. $data = json_decode($apiResponse->getContents());
  1545. if (!property_exists($data, 'success') || !$data->success) {
  1546. return redirect()->to(route('logout'));
  1547. }
  1548. Cookie::queue('sessionKey', $data->data->sessionKey);
  1549. return redirect(route('dashboard'));
  1550. } catch (\Exception $e) {
  1551. return redirect(route('dashboard'));
  1552. }
  1553. }
  1554. public function getTicket(Request $request, Ticket $ticket) {
  1555. $ticket->data = json_decode($ticket->data);
  1556. // $ticket->created_at = friendly_date_time($ticket->created_at);
  1557. $ticket->assignedPro;
  1558. $ticket->managerPro;
  1559. $ticket->orderingPro;
  1560. $ticket->initiatingPro;
  1561. return json_encode($ticket);
  1562. }
  1563. public function genericBill(Request $request, $entityType, $entityUid) {
  1564. $patient = null;
  1565. if ($entityType && $entityUid) {
  1566. try {
  1567. $entityClass = "\\App\\Models\\" . $entityType;
  1568. $entity = $entityClass::where('uid', $entityUid)->first();
  1569. if ($entity->client) {
  1570. $patient = $entity->client;
  1571. }
  1572. } catch (\Exception $e) {
  1573. }
  1574. }
  1575. return view('app.generic-bills.inline', ['class' => 'p-3 border-top mt-3', 'entityType' => $entityType, 'entityUid' => $entityUid, 'patient' => $patient]);
  1576. }
  1577. }