PracticeManagementController.php 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\BillingReport;
  5. use App\Models\CareMonth;
  6. use App\Models\ClaimEDI;
  7. use App\Models\Company;
  8. use App\Models\Handout;
  9. use App\Models\MBClaim;
  10. use App\Models\Measurement;
  11. use App\Models\Bill;
  12. use App\Models\Claim;
  13. use App\Models\Client;
  14. use App\Models\McpRequest;
  15. use App\Models\McCodeCheck;
  16. use App\Models\Note;
  17. use App\Models\Pack;
  18. use App\Models\Pro;
  19. use App\Models\Product;
  20. use App\Models\ProFavorite;
  21. use App\Models\ProGeneralAvailability;
  22. use App\Models\ProProAccess;
  23. use App\Models\ProRate;
  24. use App\Models\ProSpecificAvailability;
  25. use App\Models\ProSpecificUnavailability;
  26. use App\Models\ProTeam;
  27. use App\Models\ProTextShortcut;
  28. use App\Models\ProTransaction;
  29. use App\Models\Shipment;
  30. use App\Models\SupplyOrder;
  31. use App\Models\Team;
  32. use App\Models\Ticket;
  33. use App\Models\AccountInvite;
  34. use App\Models\ClientMeasurementDaysPerMonth;
  35. use Illuminate\Support\Facades\DB;
  36. use Illuminate\Support\Facades\Http;
  37. use PDF;
  38. use DateTime;
  39. use DateTimeZone;
  40. use Illuminate\Http\Request;
  41. class PracticeManagementController extends Controller
  42. {
  43. public function mcCodeChecks(Request $request)
  44. {
  45. $checks = McCodeCheck::orderBy('next_eligible_date_professional', 'asc')->get();
  46. return view ('app.practice-management.mc-code-checks', compact('checks'));
  47. }
  48. public function remoteMonitoringReport(Request $request)
  49. {
  50. $rows = null;
  51. $proID = $this->performer()->pro->id;
  52. $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
  53. //$rows = $isAdmin ? ClientMeasurementDaysPerMonth::all() : ClientMeasurementDaysPerMonth::where('mcp_pro_id', $proID)->orderBy('year_month', 'asc')->orderBy('num_of_days_with_measurement', 'asc')->get();
  54. $rows = CareMonth::whereNotNull('mcp_pro_id')
  55. ->where('number_of_days_with_remote_measurements', '>=', 16)
  56. ->orderByRaw(DB::raw('start_date DESC'))->paginate(50) ;
  57. return view ('app.practice-management.remote-monitoring-report', compact('rows'));
  58. }
  59. public function billingReport(Request $request)
  60. {
  61. $rows = BillingReport::paginate(50);
  62. return view('app.practice-management.billing-report', compact('rows'));
  63. }
  64. public function dashboard(Request $request)
  65. {
  66. return view('app.practice-management.dashboard');
  67. }
  68. public function rates(Request $request, $selectedProUid = 'all')
  69. {
  70. $proUid = $selectedProUid ? $selectedProUid : 'all';
  71. $rates = ProRate::where('is_active', true);
  72. if ($proUid !== 'all') {
  73. $selectedPro = Pro::where('uid', $proUid)->first();
  74. $rates = $rates->where('pro_id', $selectedPro->id);
  75. }
  76. $rates = $rates->orderBy('pro_id', 'asc')->get();
  77. $pros = $this->pros;
  78. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  79. }
  80. public function previousBills(Request $request)
  81. {
  82. return view('app.practice-management.previous-bills');
  83. }
  84. public function financialTransactions(Request $request)
  85. {
  86. $pro = $this->performer()->pro;
  87. $transactions = null;
  88. if($pro->pro_type === 'ADMIN') {
  89. $transactions = ProTransaction::whereNotNull('id');
  90. }
  91. else {
  92. $transactions = ProTransaction::where('pro_id', $pro->id);
  93. }
  94. $filter = $request->input('p');
  95. if ($filter) {
  96. $filterPro = Pro::where('uid', $filter)->first();
  97. if($filterPro) {
  98. $transactions = $transactions->where('pro_id', '=', $filterPro->id);
  99. }
  100. }
  101. $filter = $request->input('t');
  102. if ($filter) {
  103. $transactions = $transactions->where('plus_or_minus', '=', $filter);
  104. }
  105. $filter = $request->input('c');
  106. if ($filter) {
  107. $transactions = $transactions->where('company_id', '=', $filter);
  108. }
  109. $filter = $request->input('bs');
  110. if ($filter) {
  111. $transactions = $transactions->where('created_at', '>=', $filter);
  112. }
  113. $filter = $request->input('be');
  114. if ($filter) {
  115. $transactions = $transactions->where('created_at', '<=', $filter);
  116. }
  117. $transactions = $transactions->orderBy('created_at', 'desc')->paginate();
  118. $companies = Company::where('is_active', true)->orderBy('name')->get();
  119. return view('app.practice-management.financial-transactions', compact('transactions', 'companies'));
  120. }
  121. public function pendingBillsToSign(Request $request)
  122. {
  123. return view('app.practice-management.pending-bills-to-sign');
  124. }
  125. public function HR(Request $request)
  126. {
  127. return view('app.practice-management.hr');
  128. }
  129. public function directDepositSettings(Request $request)
  130. {
  131. return view('app.practice-management.direct-deposit-settings');
  132. }
  133. public function w9(Request $request)
  134. {
  135. return view('app.practice-management.w9');
  136. }
  137. public function contract(Request $request)
  138. {
  139. return view('app.practice-management.contract');
  140. }
  141. public function notes(Request $request, $filter = '')
  142. {
  143. $proID = $this->performer()->pro->id;
  144. $query = Note::where('hcp_pro_id', $proID);
  145. switch ($filter) {
  146. case 'not-yet-signed':
  147. $query = $query->where('is_signed_by_hcp', false);
  148. break;
  149. case 'not-yet-signed-but-ally-signed':
  150. $query = $query->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true);
  151. break;
  152. case 'without-bills':
  153. $query = $query->where('is_signed_by_hcp', true)->where('is_cancelled', false)->whereDoesntHave('bills');
  154. break;
  155. // more cases can be added as needed
  156. default:
  157. break;
  158. }
  159. $notes = $query->orderBy('created_at', 'desc')->get();
  160. return view('app.practice-management.notes', compact('notes', 'filter'));
  161. }
  162. public function dnaNotesPendingMcpSign(Request $request)
  163. {
  164. $proID = $this->performer()->pro->id;
  165. $notes = Note::where('ally_pro_id', $proID)
  166. ->where('is_signed_by_hcp', false)
  167. ->where('is_cancelled', false)
  168. ->orderBy('created_at', 'desc')
  169. ->get();
  170. return view('app.practice-management.dna-notes-pending-mcp-sign', compact('notes'));
  171. }
  172. public function naBillableSignedNotes(Request $request)
  173. {
  174. $notes = Note
  175. ::where('is_signed_by_hcp', TRUE)
  176. ->where('ally_pro_id', $this->performer()->pro->id)
  177. ->where('is_cancelled', FALSE)
  178. ->whereRaw("
  179. (
  180. SELECT count(bill.id)
  181. FROM bill WHERE
  182. bill.is_cancelled = FALSE AND
  183. bill.generic_pro_id = {$this->performer()->pro->id} AND
  184. bill.note_id = note.id
  185. ) = 0
  186. ");
  187. $notes = $notes->orderBy('created_at', 'desc')->get();
  188. return view('app.practice-management.na-billable-signed-notes', compact('notes'));
  189. }
  190. public function bills(Request $request, $filter = '')
  191. {
  192. $proID = $this->performer()->pro->id;
  193. $query = Bill::where('is_cancelled', false)->where('bill_service_type', '<>', 'CARE_MONTH');
  194. switch ($filter) {
  195. case 'not-yet-signed':
  196. $query = $query
  197. ->where(function ($q) use ($proID) {
  198. $q->where(function ($q2) use ($proID) {
  199. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  200. })
  201. ->orWhere(function ($q2) use ($proID) {
  202. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  203. })
  204. ->orWhere(function ($q2) use ($proID) {
  205. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  206. })
  207. ->orWhere(function ($q2) use ($proID) {
  208. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  209. });
  210. });
  211. break;
  212. case 'previous':
  213. $query = $query
  214. ->where(function ($q) use ($proID) {
  215. $q->where(function ($q2) use ($proID) {
  216. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  217. })
  218. ->orWhere(function ($q2) use ($proID) {
  219. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  220. })
  221. ->orWhere(function ($q2) use ($proID) {
  222. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  223. })
  224. ->orWhere(function ($q2) use ($proID) {
  225. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  226. });
  227. });
  228. break;
  229. // more cases can be added as needed
  230. default:
  231. $query = $query
  232. ->where(function ($q) use ($proID) {
  233. $q->where(function ($q2) use ($proID) {
  234. $q2->where('hcp_pro_id', $proID);
  235. })
  236. ->orWhere(function ($q2) use ($proID) {
  237. $q2->where('cm_pro_id', $proID);
  238. })
  239. ->orWhere(function ($q2) use ($proID) {
  240. $q2->where('rme_pro_id', $proID);
  241. })
  242. ->orWhere(function ($q2) use ($proID) {
  243. $q2->where('rmm_pro_id', $proID);
  244. });
  245. });
  246. break;
  247. }
  248. $bills = $query->orderBy('created_at', 'desc')->get();
  249. return view('app.practice-management.bills', compact('bills', 'filter'));
  250. }
  251. public function rmBillsToSign(Request $request)
  252. {
  253. $performerProID = $this->performer()->pro->id;
  254. $bills = Bill::where('is_cancelled', false)->where('cm_or_rm', 'RM')
  255. ->where(function ($q) use ($performerProID) {
  256. $q
  257. ->where(function ($q2) use ($performerProID) {
  258. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  259. })
  260. ->orWhere(function ($q2) use ($performerProID) {
  261. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  262. })
  263. ->orWhere(function ($q2) use ($performerProID) {
  264. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  265. })
  266. ->orWhere(function ($q2) use ($performerProID) {
  267. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  268. });
  269. })
  270. ->orderBy('effective_date', 'desc')
  271. ->get();
  272. return view('app.practice-management.rm-bills-to-sign', compact('bills'));
  273. }
  274. public function unacknowledgedCancelledBills(Request $request)
  275. {
  276. $bills = Bill::where('hcp_pro_id', $this->performer()->pro->id)
  277. ->where('is_cancelled', true)
  278. ->where('is_cancellation_acknowledged', false)
  279. ->orderBy('created_at', 'desc')
  280. ->get();
  281. return view('app.practice-management.unacknowledged-cancelled-bills', compact('bills'));
  282. }
  283. public function myTickets(Request $request, $filter = 'open')
  284. {
  285. $performer = $this->performer();
  286. $myTickets = Ticket::where(function ($q) use ($performer) {
  287. $q->where('assigned_pro_id', $performer->pro_id)
  288. ->orWhere('manager_pro_id', $performer->pro_id)
  289. ->orWhere('ordering_pro_id', $performer->pro_id)
  290. ->orWhere('initiating_pro_id', $performer->pro_id);
  291. });
  292. if ($filter === 'open') {
  293. $myTickets = $myTickets->where('is_open', true);
  294. } else if ($filter === 'closed') {
  295. $myTickets = $myTickets->where('is_open', false);
  296. }
  297. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  298. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  299. }
  300. public function myTextShortcuts(Request $request)
  301. {
  302. $personalShortcuts = DB::table('pro_text_shortcut')
  303. ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
  304. ->select(
  305. 'pro_text_shortcut.uid',
  306. 'pro_text_shortcut.shortcut',
  307. 'pro_text_shortcut.text',
  308. 'pro.name_first',
  309. 'pro.name_last'
  310. )
  311. ->where('pro_text_shortcut.is_removed', false);
  312. if($this->performer()->pro->pro_type !== 'ADMIN') {
  313. $personalShortcuts = $personalShortcuts->where('pro_id', $this->performer()->pro_id);
  314. }
  315. $personalShortcuts = $personalShortcuts
  316. ->orderBy('pro.name_last')
  317. ->orderBy('pro.name_first')
  318. ->orderBy('pro_text_shortcut.shortcut')
  319. ->get();
  320. $globalTextShortcuts = DB::table('pro_text_shortcut')
  321. ->select(
  322. 'pro_text_shortcut.uid',
  323. 'pro_text_shortcut.shortcut',
  324. 'pro_text_shortcut.text'
  325. )
  326. ->whereNull('pro_id')
  327. ->where('pro_text_shortcut.is_removed', false)
  328. ->orderBy('pro_text_shortcut.shortcut')
  329. ->get();
  330. return view('app.practice-management.my-text-shortcuts', compact('personalShortcuts', 'globalTextShortcuts'));
  331. }
  332. public function myFavorites(Request $request, $filter = 'all')
  333. {
  334. $performer = $this->performer();
  335. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  336. ->where('is_removed', false);
  337. if ($filter !== 'all') {
  338. $myFavorites = $myFavorites->where('category', $filter);
  339. }
  340. $myFavorites = $myFavorites
  341. ->orderBy('category', 'asc')
  342. ->orderBy('position_index', 'asc')
  343. ->get();
  344. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  345. }
  346. public function patientsWithoutCoverage(Request $request, $filter = 'all')
  347. {
  348. $performer = $this->performer();
  349. $sql = "SELECT cl.uid, cl.name_first, cl.name_last FROM client cl ";
  350. $joinClause = 'LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id ';
  351. $withoutCondition = "cl.latest_client_primary_coverage_id IS NULL";
  352. $pendingCondition = "
  353. (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
  354. AND (
  355. (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
  356. OR
  357. (cpc.plan_type != 'MEDICARE' AND
  358. (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
  359. ))";
  360. switch ($filter) {
  361. case 'without-coverage-information':
  362. $sql .= 'WHERE cl.shadow_pro_id IS NULL AND ';
  363. $sql .= $withoutCondition;
  364. break;
  365. case 'pending-coverage-verification':
  366. $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
  367. $sql .= $pendingCondition;
  368. break;
  369. default:
  370. $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
  371. $sql .= '(' . $withoutCondition . ' OR ' . $pendingCondition . ')';
  372. break;
  373. }
  374. $sql .= ' ORDER BY cl.name_first ASC';
  375. $pendingCoverage = DB::select(DB::raw($sql));
  376. return view('app.practice-management.patients-without-coverage', compact('pendingCoverage', 'filter'));
  377. }
  378. public function proAvailability(Request $request, $proUid = null)
  379. {
  380. $performer = $this->performer();
  381. $pro = $performer->pro;
  382. if ($proUid) {
  383. $pro = Pro::where('uid', $proUid)->first();
  384. }
  385. if ($request->get('pro_uid')) {
  386. $proUid = $request->get('pro_uid');
  387. $pro = Pro::where('uid', $proUid)->first();
  388. }
  389. $selectedProUid = $pro->uid;
  390. $pros = $this->pros;
  391. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  392. $generalAvailabilities = [
  393. 'MONDAY' => [],
  394. 'TUESDAY' => [],
  395. 'WEDNESDAY' => [],
  396. 'THURSDAY' => [],
  397. 'FRIDAY' => [],
  398. 'SATURDAY' => [],
  399. 'SUNDAY' => [],
  400. ];
  401. foreach ($generalAvailabilitiesList as $ga) {
  402. if ($ga->day_of_week == 'MONDAY') {
  403. $generalAvailabilities['MONDAY'][] = $ga;
  404. }
  405. if ($ga->day_of_week == 'TUESDAY') {
  406. $generalAvailabilities['TUESDAY'][] = $ga;
  407. }
  408. if ($ga->day_of_week == 'WEDNESDAY') {
  409. $generalAvailabilities['WEDNESDAY'][] = $ga;
  410. }
  411. if ($ga->day_of_week == 'THURSDAY') {
  412. $generalAvailabilities['THURSDAY'][] = $ga;
  413. }
  414. if ($ga->day_of_week == 'FRIDAY') {
  415. $generalAvailabilities['FRIDAY'][] = $ga;
  416. }
  417. if ($ga->day_of_week == 'SATURDAY') {
  418. $generalAvailabilities['SATURDAY'][] = $ga;
  419. }
  420. if ($ga->day_of_week == 'SUNDAY') {
  421. $generalAvailabilities['SUNDAY'][] = $ga;
  422. }
  423. }
  424. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  425. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  426. //events for the calendar
  427. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  428. $endDateTime = new DateTime($startDate);
  429. $endDateTime->modify('+6 day');
  430. $endDate = $endDateTime->format("Y-m-d");
  431. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  432. $events = json_encode($eventsData);
  433. return view(
  434. 'app.practice-management.pro-availability',
  435. compact(
  436. 'pros',
  437. 'generalAvailabilities',
  438. 'specificAvailabilities',
  439. 'specificUnavailabilities',
  440. 'events',
  441. 'selectedProUid'
  442. )
  443. );
  444. }
  445. public function loadAvailability(Request $request, $proUid)
  446. {
  447. $performer = $this->performer();
  448. $pro = $performer->pro;
  449. $startDate = $request->get('start');
  450. $endDate = $request->get('end');
  451. $selectedPro = Pro::where('uid', $proUid)->first();
  452. return $selectedPro->getAvailabilityEvents($startDate, $endDate, $request->input('tz') ? $request->input('tz') : 'EASTERN');
  453. }
  454. public function proAvailabilityFilter(Request $request)
  455. {
  456. $proUid = $request->get('proUid');
  457. return ['success' => true, 'data' => $proUid];
  458. }
  459. // video call page (RHS)
  460. // generic call handle (no uid)
  461. // specific call handle (uid of client)
  462. public function meet(Request $request, $uid = false)
  463. {
  464. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  465. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  466. if (!empty($client)) {
  467. return view('app.video.call-minimal', compact('session', 'client'));
  468. }
  469. return view('app.video.call-agora-v2', compact('session', 'client'));
  470. }
  471. // check video page
  472. public function checkVideo(Request $request, $uid)
  473. {
  474. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  475. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  476. $publish = false;
  477. return view('app.video.check-video-minimal', compact('session', 'client'));
  478. }
  479. public function getParticipantInfo(Request $request)
  480. {
  481. $sid = intval($request->get('uid')) - 1000000;
  482. $session = AppSession::where('id', $sid)->first();
  483. $result = [
  484. "type" => '',
  485. "name" => ''
  486. ];
  487. if ($session) {
  488. $result["type"] = $session->session_type;
  489. switch ($session->session_type) {
  490. case 'PRO':
  491. $pro = Pro::where('id', $session->pro_id)->first();
  492. $result["name"] = $pro->displayName();
  493. break;
  494. case 'CLIENT':
  495. $client = Client::where('id', $session->client_id)->first();
  496. $result["name"] = $client->displayName();
  497. break;
  498. }
  499. }
  500. return json_encode($result);
  501. }
  502. // ajax ep used by the video page
  503. // this is needed bcoz meet() is used not
  504. // just for the client passed to the view
  505. public function getOpentokSessionKey(Request $request, $uid)
  506. {
  507. $client = Client::where('uid', $uid)->first();
  508. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  509. }
  510. // poll to check if there are patients with active mcp requests
  511. public function getPatientsInQueue(Request $request)
  512. {
  513. $myInitiatives = $this->performer->pro->initiatives;
  514. if ($myInitiatives) {
  515. $myInitiatives = strtoupper($myInitiatives);
  516. }
  517. $myInitiativesList = explode('|', $myInitiatives);
  518. $myForeignLanguages = $this->performer->pro->foreign_languages;
  519. if ($myForeignLanguages) {
  520. $myForeignLanguages = strtoupper($myForeignLanguages);
  521. }
  522. $myForeignLanguagesList = explode('|', $myForeignLanguages);
  523. $clients = Client::whereNotNull('active_mcp_request_id')->where(function ($query) use ($myInitiativesList) {
  524. $query->whereNull('initiative')->orWhereIn('initiative', $myInitiativesList);
  525. })
  526. ->where(function ($query) use ($myForeignLanguagesList) {
  527. $query->whereNull('preferred_foreign_language')->orWhereIn('preferred_foreign_language', $myForeignLanguagesList);
  528. })->limit(3)->get();
  529. $results = [];
  530. foreach ($clients as $client) {
  531. $results[] = [
  532. 'clientUid' => $client->uid,
  533. 'name' => $client->displayName(),
  534. 'initials' => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  535. ];
  536. }
  537. return json_encode($results);
  538. }
  539. public function currentWork(Request $request)
  540. {
  541. return view('app/current-work');
  542. }
  543. public function calendar(Request $request, $proUid = null)
  544. {
  545. $pros = Pro::all();
  546. if ($this->pro && $this->pro->pro_type != 'ADMIN') {
  547. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
  548. $accessibleProIds = [];
  549. foreach ($accessiblePros as $accessiblePro) {
  550. $accessibleProIds[] = $accessiblePro->id;
  551. }
  552. $accessibleProIds[] = $this->pro->id;
  553. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  554. }
  555. return view('app.practice-management.calendar', compact('pros'));
  556. }
  557. public function cellularDeviceManager(Request $request, $proUid = null)
  558. {
  559. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  560. $performerPro = $this->performer->pro;
  561. $targetPro = null;
  562. $expectedForHcp = null;
  563. if ($performerPro->pro_type == 'ADMIN') {
  564. $targetPro = Pro::where('uid', $proUid)->first();
  565. } else {
  566. $targetPro = $performerPro;
  567. }
  568. $clients = [];
  569. if ($targetPro) {
  570. $clients = Client::where('mcp_pro_id', $targetPro->id)->orderBy('created_at', 'desc')->paginate(20);
  571. } else {
  572. $clients = Client::orderBy('created_at', 'desc')->paginate(20);
  573. }
  574. return view('app.practice-management.cellular-device-manager', compact('clients', 'targetPro', 'proUid'));
  575. }
  576. public function treatmentServiceUtil(Request $request)
  577. {
  578. $view_treatment_service_utilization_org = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_org ORDER BY effective_date DESC"));
  579. $view_treatment_service_utilization = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization ORDER BY effective_date DESC, total_hrs DESC"));
  580. $view_treatment_service_utilization_by_patient = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_by_patient ORDER BY pro_lname ASC, pro_fname ASC, hcp_pro_id ASC, total_hrs DESC"));
  581. return view('app.practice-management.treatment-services-util', compact(
  582. 'view_treatment_service_utilization_org',
  583. 'view_treatment_service_utilization',
  584. 'view_treatment_service_utilization_by_patient'));
  585. }
  586. public function processingBillMatrix(Request $request, $proUid = null)
  587. {
  588. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  589. $performerPro = $this->performer->pro;
  590. $targetPro = null;
  591. if ($performerPro->pro_type == 'ADMIN') {
  592. $targetPro = Pro::where('uid', $proUid)->first();
  593. } else {
  594. $targetPro = $performerPro;
  595. }
  596. $bills = Bill::where('is_cancelled', false);
  597. if(!$request->input('t') || $request->input('t') === 'hcp') {
  598. $bills = $bills
  599. ->where('has_hcp_been_paid', false)
  600. ->where('is_signed_by_hcp', true);
  601. if ($targetPro) {
  602. $bills = $bills->where('hcp_pro_id', $targetPro->id);
  603. }
  604. if($request->input('c')) {
  605. $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = hcp_company_pro_id) = ' . $request->input('c'));
  606. }
  607. }
  608. else if($request->input('t') === 'na') {
  609. $bills = $bills
  610. ->where('has_generic_pro_been_paid', false)
  611. ->where('is_signed_by_generic_pro', true);
  612. if ($targetPro) {
  613. $bills = $bills->where('generic_pro_id', $targetPro->id);
  614. }
  615. if($request->input('c')) {
  616. $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = generic_company_pro_id) = ' . $request->input('c'));
  617. }
  618. }
  619. $filter = $request->input('f');
  620. switch ($filter) {
  621. case 'verified':
  622. $bills = $bills->where('is_verified', true);
  623. break;
  624. case 'not-verified':
  625. $bills = $bills->where('is_verified', false);
  626. break;
  627. }
  628. $filter = $request->input('bs');
  629. if ($filter) {
  630. $bills = $bills->where('balance_post_date', '>=', $filter);
  631. }
  632. $filter = $request->input('be');
  633. if ($filter) {
  634. $bills = $bills->where('balance_post_date', '<=', $filter);
  635. }
  636. $filter = $request->input('s');
  637. if ($filter) {
  638. $bills = $bills->where('code', '=', $filter);
  639. }
  640. $bills = $bills->orderBy('effective_date', 'desc')->paginate();
  641. $companies = Company::where('is_active', true)->orderBy('name')->get();
  642. $codes = DB::select(DB::raw("SELECT code, count(*) as count FROM bill WHERE is_cancelled IS FALSE GROUP BY code ORDER BY code"));
  643. $viewData = [
  644. 'bills' => $bills,
  645. 'targetPro' => $targetPro,
  646. 'performerPro' => $performerPro,
  647. 'proUid' => $proUid,
  648. 'companies' => $companies,
  649. 'codes' => $codes
  650. ];
  651. return view('app.practice-management.processing-bill-matrix', $viewData);
  652. }
  653. public function proFinancials(Request $request, $proUid = null)
  654. {
  655. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  656. $performerPro = $this->performer->pro;
  657. $targetPro = null;
  658. if ($performerPro->pro_type == 'ADMIN') {
  659. $targetPro = Pro::where('uid', $proUid)->first();
  660. } else {
  661. $targetPro = $performerPro;
  662. }
  663. $fPros = Pro::whereNotNull('balance');
  664. if($targetPro) {
  665. $fPros = $fPros->where('uid', $targetPro->uid);
  666. }
  667. $fPros = $fPros
  668. ->where('balance', '>', 0)
  669. ->orderBy('name_last')
  670. ->orderBy('name_first')
  671. ->paginate();
  672. return view('app.practice-management.pro-financials', compact('fPros', 'targetPro'));
  673. }
  674. public function hcpBillMatrix(Request $request, $proUid = null)
  675. {
  676. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  677. $performerPro = $this->performer->pro;
  678. $targetPro = null;
  679. $allPros = [];
  680. $expectedForHcp = null;
  681. if ($performerPro->pro_type == 'ADMIN') {
  682. $allPros = Pro::all();
  683. $targetPro = Pro::where('uid', $proUid)->first();
  684. } else {
  685. $targetPro = $performerPro;
  686. }
  687. $rows = [];
  688. if ($targetPro) {
  689. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report WHERE hcp_pro_id = :targetProID"), ['targetProID' => $targetPro->id]);
  690. } else {
  691. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report"));
  692. }
  693. return view('app.practice-management.hcp-bill-matrix', compact('rows', 'allPros', 'expectedForHcp', 'targetPro', 'proUid'));
  694. }
  695. public function billingManager(Request $request, $proUid = null)
  696. {
  697. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  698. $performerPro = $this->performer->pro;
  699. $targetPro = null;
  700. $allPros = [];
  701. $expectedForHcp = null;
  702. if ($performerPro->pro_type == 'ADMIN') {
  703. $allPros = Pro::all();
  704. $targetPro = Pro::where('uid', $proUid)->first();
  705. } else {
  706. $targetPro = $performerPro;
  707. }
  708. $notes = [];
  709. if ($targetPro) {
  710. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :targetProID AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['targetProID' => $targetPro->id])[0]->expected_pay;
  711. $notes = Note::where('hcp_pro_id', $targetPro->id);
  712. } else {
  713. $notes = Note::where('id', '>', 0);
  714. }
  715. if($request->input('date')) {
  716. $notes = $notes->where('effective_dateest', $request->input('date'));
  717. }
  718. $filters = [];
  719. $filters['bills_created'] = $request->input('bills_created');
  720. $filters['is_billing_marked_done'] = $request->input('is_billing_marked_done');
  721. $filters['bills_resolved'] = $request->input('bills_resolved');
  722. $filters['bills_closed'] = $request->input('bills_closed');
  723. $filters['claims_created'] = $request->input('claims_created');
  724. $filters['claims_closed'] = $request->input('claims_closed');
  725. if ($filters['bills_created']) {
  726. $notes->where(
  727. 'bill_total_expected',
  728. ($filters['bills_created'] === 'yes' ? '>' : '<='),
  729. 0);
  730. }
  731. if ($filters['is_billing_marked_done']) {
  732. $notes->where(
  733. 'is_billing_marked_done',
  734. ($filters['is_billing_marked_done'] === 'yes' ? '=' : '!='),
  735. true);
  736. }
  737. if ($filters['bills_resolved']) {
  738. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id) > 0'); // have bills
  739. if ($filters['bills_resolved'] === 'yes') {
  740. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = false AND is_verified = false) OR (is_cancelled = TRUE AND is_cancellation_acknowledged = FALSE)) > 0');
  741. } elseif ($filters['bills_resolved'] === 'no') {
  742. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND ((is_cancelled = true AND is_cancellation_acknowledged = true) OR is_verified = true)) = 0');
  743. }
  744. }
  745. if ($filters['bills_closed']) {
  746. $notes->where(
  747. 'is_bill_closed',
  748. ($filters['bills_closed'] === 'yes' ? '=' : '!='),
  749. true);
  750. }
  751. if ($filters['claims_created']) {
  752. $notes->where(
  753. 'claim_total_expected',
  754. ($filters['claims_created'] === 'yes' ? '>' : '<='),
  755. 0);
  756. }
  757. if ($filters['claims_closed']) {
  758. $notes->where(
  759. 'is_claim_closed',
  760. ($filters['claims_closed'] === 'yes' ? '=' : '!='),
  761. true);
  762. }
  763. $notes = $notes->orderBy('effective_dateest', 'desc')->paginate(20);
  764. return view('app.practice-management.billing-manager', compact('notes', 'allPros', 'expectedForHcp', 'targetPro', 'proUid', 'filters'));
  765. }
  766. public function remoteMonitoring(Request $request) {
  767. $performer = $this->performer();
  768. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  769. $careMonthStart = date($ym . '-01');
  770. // filters
  771. $filters = '';
  772. $fmd = $request->input('fmd');
  773. if($fmd && $fmd !== 'all') {
  774. switch($fmd) {
  775. case 'lt16':
  776. $filters .= ' AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL) ';
  777. break;
  778. case 'gte16':
  779. $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
  780. break;
  781. }
  782. }
  783. $fcomm = $request->input('fcomm');
  784. if($fcomm && $fcomm !== 'all') {
  785. switch($fcomm) {
  786. case 'not-done':
  787. $filters .= ' 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) ';
  788. break;
  789. case 'done':
  790. $filters .= ' 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) ';
  791. break;
  792. }
  793. }
  794. $c = $request->input('c');
  795. if($c) {
  796. $filters .= ' AND client.uid = \'' . $request->input('c') . '\' ';
  797. }
  798. $patients = DB::select(
  799. DB::raw(
  800. "
  801. SELECT client.name_first, client.name_last, client.uid as client_uid,
  802. care_month.uid as care_month_uid,
  803. care_month.id as care_month_id,
  804. care_month.start_date,
  805. care_month.number_of_days_with_remote_measurements,
  806. care_month.has_anyone_interacted_with_client_about_rm_outside_note,
  807. care_month.rm_num_measurements_not_stamped_by_mcp,
  808. care_month.rm_num_measurements_not_stamped_by_non_hcp,
  809. care_month.rm_num_measurements_not_stamped_by_rmm,
  810. care_month.rm_num_measurements_not_stamped_by_rme,
  811. client.mcp_pro_id,
  812. client.default_na_pro_id,
  813. client.rmm_pro_id,
  814. client.rme_pro_id,
  815. client.cell_number
  816. FROM care_month join client on care_month.client_id = client.id
  817. WHERE
  818. EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  819. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  820. {$filters}
  821. ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first ASC, client.name_last ASC
  822. "
  823. )
  824. );
  825. $timestamp = strtotime(date('Y-m-d'));
  826. $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
  827. return view('app.practice-management.remote-monitoring', compact('patients', 'daysRemaining', 'careMonthStart'));
  828. }
  829. public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
  830. $performer = $this->performer();
  831. $measurements = DB::select(
  832. DB::raw(
  833. "
  834. SELECT measurement.label,
  835. measurement.ts,
  836. measurement.effective_date,
  837. measurement.sbp_mm_hg,
  838. measurement.dbp_mm_hg,
  839. measurement.value_pulse,
  840. measurement.value_irregular,
  841. measurement.numeric_value,
  842. measurement.value,
  843. measurement.uid,
  844. client.name_first,
  845. client.name_last,
  846. client.mcp_pro_id,
  847. client.default_na_pro_id,
  848. client.rmm_pro_id,
  849. client.rme_pro_id
  850. FROM measurement RIGHT JOIN client on measurement.client_id = client.id
  851. WHERE
  852. client.id = {$careMonth->client_id}
  853. AND measurement.label IS NOT NULL
  854. AND measurement.label NOT IN ('SBP', 'DBP')
  855. AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
  856. AND measurement.is_removed IS FALSE
  857. AND measurement.client_bdt_measurement_id IS NOT NULL
  858. AND measurement.care_month_id = {$careMonth->id}
  859. AND (
  860. (client.mcp_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_mcp IS FALSE)
  861. OR (client.rmm_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rmm IS FALSE)
  862. OR (client.rme_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rme IS FALSE)
  863. OR (client.default_na_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_non_hcp IS FALSE)
  864. )
  865. ORDER BY ts DESC
  866. "
  867. )
  868. );
  869. return view('app.practice-management.remote-monitoring-measurements', compact('careMonth', 'measurements'));
  870. }
  871. public function billMatrix(Request $request)
  872. {
  873. $bClients = [];
  874. $bHCPPros = [];
  875. $bNAPros = [];
  876. $filters = [];
  877. $filters['client'] = $request->input('client');
  878. $filters['service'] = $request->input('service');
  879. $filters['hcp'] = $request->input('hcp');
  880. $filters['hcp_paid'] = $request->input('hcp_paid');
  881. $filters['expected_op'] = $request->input('expected_op');
  882. $filters['expected_value'] = $request->input('expected_value');
  883. $filters['paid_op'] = $request->input('paid_op');
  884. $filters['paid_value'] = $request->input('paid_value');
  885. $filters['bal_post_date_op'] = $request->input('bal_post_date_op');
  886. $filters['bal_post_date_value'] = $request->input('bal_post_date_value');
  887. $filters['hcp_sign'] = $request->input('hcp_sign');
  888. $filters['verified'] = $request->input('verified');
  889. $filters['cancelled'] = $request->input('cancelled');
  890. $bills = Bill::orderBy('effective_date')->paginate();
  891. return view('app.practice-management.bill-matrix', compact('bills', 'bClients', 'bHCPPros', 'filters'));
  892. }
  893. public function medicarePartBClaims(Request $request)
  894. {
  895. $medicarePartBOnly = $request->get("medicare_part_b");
  896. $allClaims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->get();
  897. //Only medicare claims
  898. $claims = [];
  899. foreach ($allClaims as $claim) {
  900. if ($claim->client != null && $claim->client->getPrimaryCoverageStatus() == 'YES' && !$claim->edi) {
  901. $claims[] = $claim;
  902. }
  903. }
  904. $claimEDIs = ClaimEDI::all();
  905. return view('app.practice-management.medicare-partb-claims', compact('claims', 'claimEDIs'));
  906. }
  907. // Generate PDF
  908. public function downloadClaims()
  909. {
  910. $claims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->limit(100)->get();
  911. view()->share('claims', $claims);
  912. $pdf = PDF::loadView('app.practice-management.claims-pdf', $claims);
  913. return $pdf->download('pdf_file.pdf');
  914. }
  915. public function tickets(Request $request, $proUid = null)
  916. {
  917. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  918. return view('app.practice-management.tickets', compact('tickets'));
  919. }
  920. public function supplyOrders(Request $request)
  921. {
  922. // counts
  923. $counts = $this->getSupplyOrderCounts();
  924. // so clients
  925. $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
  926. $soClientIDs = array_map(function ($_x) {
  927. return $_x->client_id;
  928. }, $soClientIDs);
  929. $soClients = Client::whereIn('id', $soClientIDs)->get();
  930. // so products
  931. $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
  932. $soProductIDs = array_map(function ($_x) {
  933. return $_x->product_id;
  934. }, $soProductIDs);
  935. $soProducts = Product::whereIn('id', $soProductIDs)->get();
  936. $filters = [];
  937. $filters['client'] = $request->input('client');
  938. $filters['product'] = $request->input('product');
  939. $filters['reason'] = $request->input('reason');
  940. $filters['cu_memo'] = $request->input('cu_memo');
  941. $filters['pro_sign'] = $request->input('pro_sign');
  942. $filters['client_sign'] = $request->input('client_sign');
  943. $filters['shipment'] = $request->input('shipment');
  944. $filters['lot_number'] = $request->input('lot_number');
  945. $filters['imei'] = $request->input('imei');
  946. $filters['cancelled'] = $request->input('cancelled');
  947. $supplyOrders = SupplyOrder::where('id', '>', 0);
  948. // apply filters
  949. if ($filters['client']) $supplyOrders->where('client_id', $filters['client']);
  950. if ($filters['product']) $supplyOrders->where('product_id', $filters['product']);
  951. if ($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
  952. if ($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
  953. if ($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
  954. if ($filters['client_sign']) {
  955. if ($filters['client_sign'] === 'signed')
  956. $supplyOrders->where('is_signed_by_client', true);
  957. elseif ($filters['client_sign'] === 'waived')
  958. $supplyOrders->where('is_client_signature_waived', true);
  959. else
  960. $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
  961. }
  962. if ($filters['shipment']) {
  963. if ($filters['shipment'] === 'not_cleared_for_shipment')
  964. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', false);
  965. elseif ($filters['shipment'] === 'cleared_for_shipment')
  966. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', true);
  967. else
  968. $supplyOrders
  969. ->whereNotNull('shipment_id')
  970. ->whereRaw('(SELECT status FROM shipment WHERE id = shipment_id LIMIT 1) = ?', [$filters['shipment']]);
  971. }
  972. if ($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
  973. if ($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
  974. if ($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  975. $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
  976. return view('app.practice-management.supply-orders',
  977. compact('supplyOrders', 'filters',
  978. 'soClients', 'soProducts', 'counts'
  979. )
  980. );
  981. }
  982. public function shipments(Request $request, $filter = null)
  983. {
  984. // counts
  985. $counts = $this->getShipmentCounts();
  986. // so clients
  987. $shClientIDs = DB::table('shipment')->select('client_id')->distinct()->get()->toArray();
  988. $shClientIDs = array_map(function ($_x) {
  989. return $_x->client_id;
  990. }, $shClientIDs);
  991. $shClients = Client::whereIn('id', $shClientIDs)->get();
  992. $shipments = Shipment::where('id', '>', 0);
  993. $filters = [];
  994. $filters['client'] = $request->input('client');
  995. $filters['courier'] = $request->input('courier');
  996. $filters['tracking_num'] = $request->input('tracking_num');
  997. $filters['label'] = $request->input('label');
  998. $filters['status'] = $request->input('status');
  999. $filters['cancelled'] = $request->input('cancelled');
  1000. if ($filters['client']) $shipments->where('client_id', $filters['client']);
  1001. if ($filters['courier']) $shipments->where('courier', 'ILIKE', '%' . $filters['courier'] . '%');
  1002. if ($filters['tracking_num']) $shipments->where('tracking_number', 'ILIKE', '%' . $filters['tracking_num'] . '%');
  1003. if ($filters['label']) {
  1004. if ($filters['label'] === 'yes')
  1005. $shipments->whereNotNull('label_system_file_id');
  1006. else
  1007. $shipments->whereNull('label_system_file_id');
  1008. }
  1009. if ($filters['status']) $shipments->where('status', $filters['status']);
  1010. if ($filters['cancelled']) $shipments->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  1011. $shipments = $shipments->orderBy('created_at', 'desc')->paginate();
  1012. return view('app.practice-management.shipments', compact('shipments', 'filters', 'shClients', 'counts'));
  1013. }
  1014. public function cellularMeasurements(Request $request)
  1015. {
  1016. $measurements = Measurement::orderBy('ts', 'desc')->whereNotNull('ts')->paginate();
  1017. return view('app.practice-management.cellular-measurements', compact('measurements'));
  1018. }
  1019. // v2 supply-orders & shipments management (wh)
  1020. public function supplyOrdersReadyToShip(Request $request)
  1021. {
  1022. $counts = $this->getSupplyOrderCounts();
  1023. $supplyOrders = SupplyOrder
  1024. ::where('is_cleared_for_shipment', true)
  1025. ->where('is_cancelled', false)
  1026. ->whereNull('shipment_id')
  1027. ->join('client', 'client.id', '=', 'supply_order.client_id')
  1028. ->orderBy('client.name_last', 'ASC')
  1029. ->orderBy('client.name_first', 'ASC')
  1030. ->orderBy('supply_order.client_id', 'ASC')
  1031. ->orderBy('supply_order.mailing_address_full', 'ASC')
  1032. ->orderBy('supply_order.created_at', 'ASC')
  1033. ->select('supply_order.*')
  1034. ->paginate();
  1035. return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
  1036. }
  1037. public function supplyOrdersShipmentUnderway(Request $request)
  1038. {
  1039. $counts = $this->getSupplyOrderCounts();
  1040. $supplyOrders = SupplyOrder
  1041. ::where('is_cancelled', false)
  1042. ->whereNotNull('shipment_id')
  1043. ->orderBy('client_id', 'ASC')
  1044. ->orderBy('mailing_address_full', 'ASC')
  1045. ->orderBy('created_at', 'ASC')
  1046. ->paginate();
  1047. return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
  1048. }
  1049. public function supplyOrdersHanging(Request $request)
  1050. {
  1051. $counts = $this->getSupplyOrderCounts();
  1052. $supplyOrders = SupplyOrder
  1053. ::select('supply_order.*')
  1054. ->leftJoin('shipment', function($join) {
  1055. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  1056. })
  1057. ->where('shipment.status', 'CANCELLED')
  1058. ->where('supply_order.is_cancelled', false)
  1059. ->orderBy('supply_order.client_id', 'ASC')
  1060. ->orderBy('supply_order.mailing_address_full', 'ASC')
  1061. ->orderBy('supply_order.created_at', 'ASC')
  1062. ->paginate();
  1063. return view('app.practice-management.supply-orders-hanging', compact('supplyOrders', 'counts'));
  1064. }
  1065. public function supplyOrdersCancelledButUnacknowledged(Request $request)
  1066. {
  1067. $supplyOrders = SupplyOrder::where('signed_by_pro_id', $this->performer()->pro->id)
  1068. ->where('is_cancelled', true)
  1069. ->where('is_cancellation_acknowledged', false)
  1070. ->orderBy('created_at', 'desc')
  1071. ->paginate();
  1072. return view('app.practice-management.supply-orders-cancelled-but-unacknowledged', compact('supplyOrders'));
  1073. }
  1074. public function supplyOrdersUnsigned(Request $request)
  1075. {
  1076. $supplyOrders = SupplyOrder
  1077. ::where('is_cancelled', false)
  1078. ->where('is_signed_by_pro', false)
  1079. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$this->performer()->pro->id])
  1080. ->orderBy('created_at', 'desc')
  1081. ->paginate();
  1082. return view('app.practice-management.supply-orders-unsigned', compact('supplyOrders'));
  1083. }
  1084. private function getSupplyOrderCounts()
  1085. {
  1086. return [
  1087. "supplyOrders" => SupplyOrder::count(),
  1088. "supplyOrdersReadyToShip" => SupplyOrder
  1089. ::where('is_cleared_for_shipment', true)
  1090. ->where('is_cancelled', false)
  1091. ->whereNull('shipment_id')->count(),
  1092. "supplyOrdersShipmentUnderway" => SupplyOrder
  1093. ::where('is_cancelled', false)
  1094. ->whereNotNull('shipment_id')->count(),
  1095. "supplyOrdersHanging" => SupplyOrder
  1096. ::leftJoin('shipment', function($join) {
  1097. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  1098. })
  1099. ->where('shipment.status', 'CANCELLED')
  1100. ->where('supply_order.is_cancelled', false)
  1101. ->count(),
  1102. ];
  1103. }
  1104. public function shipmentsReadyToPrint(Request $request)
  1105. {
  1106. $counts = $this->getShipmentCounts();
  1107. $shipments = Shipment
  1108. ::where('is_cancelled', false)
  1109. ->where('status', 'CREATED')
  1110. ->orderBy('created_at', 'ASC')
  1111. ->paginate();
  1112. return view('app.practice-management.shipments-ready-to-print', compact('shipments', 'counts'));
  1113. }
  1114. public function shipmentsShipmentUnderway(Request $request)
  1115. {
  1116. $counts = $this->getShipmentCounts();
  1117. $shipments = Shipment
  1118. ::where('is_cancelled', false)
  1119. ->where('status', 'PRINTED')
  1120. ->orderBy('created_at', 'ASC')
  1121. ->paginate();
  1122. return view('app.practice-management.shipments-waiting-for-picker', compact('shipments', 'counts'));
  1123. }
  1124. private function getShipmentCounts()
  1125. {
  1126. return [
  1127. "shipments" => Shipment::count(),
  1128. "shipmentsReadyToPrint" => Shipment
  1129. ::where('is_cancelled', false)
  1130. ->where('status', 'CREATED')
  1131. ->count(),
  1132. "shipmentsWaitingForPicker" => Shipment
  1133. ::where('is_cancelled', false)
  1134. ->where('status', 'PRINTED')
  1135. ->count()
  1136. ];
  1137. }
  1138. public function shipment(Request $request, Shipment $shipment)
  1139. {
  1140. return view('app.practice-management.shipment', compact('shipment'));
  1141. }
  1142. public function shipmentsMultiPrint(Request $request, $ids)
  1143. {
  1144. $ids = array_map(function ($_x) {
  1145. return intval($_x);
  1146. }, explode("|", $ids));
  1147. $shipments = Shipment::whereIn('id', $ids)->get();
  1148. return view('app.practice-management.shipments-multi-print', compact('shipments'));
  1149. }
  1150. public function patientClaimSummary(Request $request, $proUid = null)
  1151. {
  1152. $notesTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE"))[0]->count;
  1153. $notesTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS TRUE"))[0]->count;
  1154. $notesTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS TRUE"))[0]->count;
  1155. $notes3rdPartyTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1156. $notes3rdPartyTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND n.is_bill_closed IS TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1157. $notes3rdPartyTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND n.is_claim_closed IS TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1158. $patientsTotal = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1159. $patientsTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) y) AND 0 IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1160. $patientsTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) y) AND 0 IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1161. $performerPro = $this->performer->pro;
  1162. $allPros = [];
  1163. if ($performerPro->pro_type == 'ADMIN') {
  1164. $allPros = Pro::all();
  1165. } else {
  1166. $allPros = [$performerPro];
  1167. }
  1168. //Patient | MCP | # Notes Total | # Notes without Billing Closed | # Notes without Claiming Closed
  1169. $patientsQuery = Client::where('is_dummy', '=', false)
  1170. ->whereNull('shadow_pro_id')
  1171. ->select('id', 'uid', 'name_first', 'name_last', 'mcp_pro_id', 'is_part_b_primary', 'medicare_advantage_plan',
  1172. DB::raw("(SELECT name_first||' '||name_last FROM pro where pro.id = client.mcp_pro_id) as mcp"),
  1173. DB::raw("(SELECT uid FROM pro where pro.id = mcp_pro_id) as mcp_pro_uid"),
  1174. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id) as notes_total"),
  1175. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_bill_closed IS NOT true) as notes_without_billing_closed"),
  1176. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_claim_closed IS NOT true) as notes_without_claiming_closed")
  1177. )->orderBy('is_part_b_primary', 'asc')->orderBy('notes_without_claiming_closed', 'desc');
  1178. if ($proUid) {
  1179. $mcpPro = Pro::where('uid', $proUid)->first();
  1180. if ($mcpPro) {
  1181. $patientsQuery->where('client.mcp_pro_id', '=', $mcpPro->id);
  1182. }
  1183. }
  1184. $patientsQuery->whereRaw('(SELECT COUNT(*) FROM note where note.client_id = client.id) > 0');
  1185. $patientsQuery->orderBy('notes_total', 'DESC');
  1186. $patients = $patientsQuery->paginate(50);
  1187. $data = [
  1188. 'patients' => $patients,
  1189. 'proUid' => $proUid,
  1190. 'allPros' => $allPros,
  1191. 'notesTotal' => $notesTotal,
  1192. 'notesTotalWithBillingClosed' => $notesTotalWithBillingClosed,
  1193. 'notesTotalWithClaimingClosed' => $notesTotalWithClaimingClosed,
  1194. 'notes3rdPartyTotal' => $notes3rdPartyTotal,
  1195. 'notes3rdPartyTotalWithBillingClosed' => $notes3rdPartyTotalWithBillingClosed,
  1196. 'notes3rdPartyTotalWithClaimingClosed' => $notes3rdPartyTotalWithClaimingClosed,
  1197. 'patientsTotal' => $patientsTotal,
  1198. 'patientsTotalWithBillingClosed' => $patientsTotalWithBillingClosed,
  1199. 'patientsTotalWithClaimingClosed' => $patientsTotalWithClaimingClosed
  1200. ];
  1201. return view('app.practice-management.patient-claim-summary', $data);
  1202. }
  1203. public function claims(Request $request){
  1204. $status = $request->get('status');
  1205. $claims = [];
  1206. if(!$status){
  1207. $claims = Claim::orderBy('created_at', 'DESC')->paginate();
  1208. }else{
  1209. $claims = Claim::where('status', $status)->orderBy('created_at', 'DESC')->paginate();
  1210. }
  1211. return view('app.practice-management.claims', compact('claims', 'status'));
  1212. }
  1213. public function processClaims(Request $request) {
  1214. $status = '';
  1215. $q = $request->input('q') ? $request->input('q') : '';
  1216. $from = $request->input('from') ? $request->input('from') : '1900-01-01';
  1217. $to = $request->input('to') ? $request->input('to') : '2100-01-01';
  1218. $params = [
  1219. 'q' => '%' . $q . '%',
  1220. 'from' => $from,
  1221. 'to' => $to
  1222. ];
  1223. $hcpPro = $request->input('hcp') ? Pro::where('uid', $request->input('hcp'))->first() : null;
  1224. if($hcpPro) {
  1225. $params['hcp'] = $hcpPro->id;
  1226. }
  1227. $claims = DB::select(DB::raw("
  1228. SELECT claim.uid AS uid,
  1229. DATE(claim.created_at) AS created,
  1230. claim.status,
  1231. client.uid AS client_uid,
  1232. client.cell_number AS client_phone,
  1233. (client.name_last || ' ' || client.name_first) AS client ,
  1234. client.chart_number AS client_chart_number,
  1235. cp.id AS claim_pro_id,
  1236. (cp.name_last || ' ' || cp.name_first) AS claim_pro,
  1237. sp.id AS status_pro_id,
  1238. (sp.name_last || ' ' || sp.name_first) AS status_pro,
  1239. note.uid AS note_uid,
  1240. note.method,
  1241. note.new_or_fu_or_na,
  1242. care_month.uid AS care_month_uid,
  1243. -- claim.status_updated_at,
  1244. (DATE(claim.status_updated_at) || ' ' ||
  1245. LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
  1246. LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) AS status_updated_at,
  1247. (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) AS cpts,
  1248. (SELECT COUNT(claim_line_icd.id) FROM claim_line_icd WHERE claim_line_id IN (SELECT id FROM claim_line WHERE claim_id = claim.id)) AS icds,
  1249. ROUND(claim.expected_total, 3) as expected_total
  1250. FROM claim
  1251. join client on claim.client_id = client.id
  1252. join pro cp on claim.pro_id = cp.id
  1253. left join note on claim.note_id = note.id
  1254. left join care_month on claim.care_month_id = care_month.id
  1255. left join app_session on claim.status_updated_by_session_id = app_session.id
  1256. left join pro sp on app_session.pro_id = sp.id
  1257. --WHERE claim.status IS NULL OR claim.status = 'NEW'
  1258. WHERE (claim.status is NULL OR claim.status NOT IN ('CANCELLED', 'ABANDONED'" . ($request->input('show-submitted') ? "" : ", 'SUBMITTED'") . "))
  1259. -- AND claim.current_version_id IS NOT NULL
  1260. AND (client.name_first ILIKE :q OR
  1261. client.name_last ILIKE :q OR
  1262. client.chart_number ILIKE :q OR
  1263. client.mcn ILIKE :q)
  1264. AND (claim.created_at >= :from AND claim.created_at <= :to)
  1265. " . ($hcpPro ? "AND claim.pro_id = :hcp" : '') . "
  1266. AND claim.id IN (SELECT mb_claim.claim_id FROM mb_claim)
  1267. ORDER BY claim.created_at DESC
  1268. --OFFSET 0 LIMIT 15
  1269. "), $params);
  1270. if($request->input('json')) {
  1271. return json_encode($claims);
  1272. }
  1273. return view('app.practice-management.process-claims', compact('claims', 'status'));
  1274. }
  1275. public function rmLaunchAndClean(Request $request) {
  1276. $keyNumbers = [];
  1277. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40'] = CareMonth::where('is_bill_closed', false)
  1278. ->whereNotNull('company_pro_id')
  1279. ->whereNotNull('company_pro_payer_id')
  1280. ->whereNotNull('company_location_id')
  1281. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1282. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1283. ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
  1284. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1285. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1286. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE )')
  1287. ->count();
  1288. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
  1289. ->whereNotNull('company_pro_id')
  1290. ->whereNotNull('company_pro_payer_id')
  1291. ->whereNotNull('company_location_id')
  1292. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1293. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1294. ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
  1295. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1296. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1297. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS NOT TRUE AND has_mcp_rm_interacted_by_note IS NOT TRUE AND is_rm_interaction_waived IS NOT TRUE )')
  1298. ->count();
  1299. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20'] = CareMonth::where('is_bill_closed', false)
  1300. ->whereNotNull('company_pro_id')
  1301. ->whereNotNull('company_pro_payer_id')
  1302. ->whereNotNull('company_location_id')
  1303. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1304. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1305. ->where('rm_total_time_in_seconds', '<', 4200)
  1306. ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
  1307. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1308. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1309. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE)')
  1310. ->count();
  1311. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
  1312. ->whereNotNull('company_pro_id')
  1313. ->whereNotNull('company_pro_payer_id')
  1314. ->whereNotNull('company_location_id')
  1315. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1316. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1317. ->where('rm_total_time_in_seconds', '<', 4200)
  1318. ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
  1319. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1320. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1321. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS NOT TRUE AND has_mcp_rm_interacted_by_note IS NOT TRUE AND is_rm_interaction_waived IS NOT TRUE )')
  1322. ->count();
  1323. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP'] = CareMonth::where('is_bill_closed', false)
  1324. ->whereNotNull('company_pro_id')
  1325. ->whereNotNull('company_pro_payer_id')
  1326. ->whereNotNull('company_location_id')
  1327. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1328. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1329. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1330. ->whereRaw('(rm_total_time_in_seconds < 3000 OR (rm_total_time_in_seconds >= 3000 AND is_rm_interaction_waived IS TRUE))')
  1331. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1332. ->count();
  1333. $keyNumbers['careMonthsEligibleForBillGeneration_RMB'] = CareMonth::where('is_bill_closed', false)
  1334. ->whereNotNull('company_pro_id')
  1335. ->whereNotNull('company_pro_payer_id')
  1336. ->whereNotNull('company_location_id')
  1337. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1338. ->whereRaw('is_rm_time_waived IS TRUE')
  1339. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1340. ->count();
  1341. $keyNumbers['careMonthsWith16OrMoreMeasurementDays'] = CareMonth::where('is_bill_closed', false)
  1342. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1343. ->count();
  1344. $careMonthsWith16PlusMeasurements = CareMonth::where('is_bill_closed', false)
  1345. ->where('number_of_days_with_remote_measurements', '>=', 16 )->get();
  1346. return view('app.practice-management.rm-launch-and-clean', compact('keyNumbers', 'careMonthsWith16PlusMeasurements'));
  1347. }
  1348. public function processNotes(Request $request) {
  1349. $mode = $request->input('mode') ? $request->input('mode') : '1';
  1350. if(($mode < 1 || $mode > 5) && $mode != 8) $mode = 1;
  1351. DB::enableQueryLog(); // Enable query log
  1352. $test = Note::where('is_cancelled', false)
  1353. ->where('is_signed_by_hcp', true)
  1354. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1355. ->whereNull('current_note_pickup_for_processing_id')
  1356. ->where('is_billing_marked_done', true)
  1357. ->where('is_bill_closed', true)
  1358. ->where('is_claim_closed', true)
  1359. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1360. ->count();
  1361. // var_dump($test);
  1362. // dd(DB::getQueryLog()); // Show results of log
  1363. // exit;
  1364. $counts = [
  1365. "picked" => Note::where('is_cancelled', false)
  1366. ->whereNotNull('current_note_pickup_for_processing_id')
  1367. ->count(),
  1368. "bad" => Note::where('is_cancelled', false)
  1369. ->whereRaw("((detail_json)::json->>'isBad' = 'true')")
  1370. ->count(),
  1371. // not yet signed
  1372. "mode-1" => Note::where('is_cancelled', false)
  1373. ->where('is_signed_by_hcp', false)
  1374. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1375. // ->whereNull('current_note_pickup_for_processing_id')
  1376. ->count(),
  1377. // billing not marked done
  1378. "mode-2" => Note::where('is_cancelled', false)
  1379. ->where('is_signed_by_hcp', true)
  1380. //->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1381. // ->whereNull('current_note_pickup_for_processing_id')
  1382. ->where('is_billing_marked_done', false)
  1383. ->count(),
  1384. // billing not closed
  1385. "mode-3" => Note::where('is_cancelled', false)
  1386. ->where('is_signed_by_hcp', true)
  1387. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1388. // ->whereNull('current_note_pickup_for_processing_id')
  1389. ->where('is_billing_marked_done', true)
  1390. ->where('is_bill_closed', false)
  1391. ->count(),
  1392. // claiming not closed
  1393. "mode-4" => Note::where('is_cancelled', false)
  1394. ->where('is_signed_by_hcp', true)
  1395. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1396. // ->whereNull('current_note_pickup_for_processing_id')
  1397. ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
  1398. ->where('is_billing_marked_done', true)
  1399. ->where('is_bill_closed', true)
  1400. ->where('is_claim_closed', false)
  1401. ->count(),
  1402. // has unsubmitted claims
  1403. "mode-5" => Note::where('is_cancelled', false)
  1404. /*->where('is_signed_by_hcp', true)
  1405. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1406. ->whereNull('current_note_pickup_for_processing_id')
  1407. ->where('is_billing_marked_done', true)
  1408. ->where('is_bill_closed', true)
  1409. ->where('is_claim_closed', true)
  1410. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1411. */
  1412. ->where('is_signed_by_hcp', true)
  1413. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1414. // ->whereNull('current_note_pickup_for_processing_id')
  1415. ->where('is_billing_marked_done', true)
  1416. ->where('is_bill_closed', true)
  1417. // ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true')")
  1418. ->where('is_claim_closed', true)
  1419. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0)")
  1420. ->count(),
  1421. // has unsubmitted claims MARKED GOOD!
  1422. "mode-8" => Note::where('is_cancelled', false)
  1423. ->where('is_signed_by_hcp', true)
  1424. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1425. ->whereNull('current_note_pickup_for_processing_id')
  1426. ->where('is_billing_marked_done', true)
  1427. ->where('is_bill_closed', true)
  1428. ->where('is_claim_closed', false)
  1429. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1430. ->count(),
  1431. // all good
  1432. "mode-6" => Note::where('is_cancelled', false)
  1433. ->where('is_signed_by_hcp', true)
  1434. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1435. // ->whereNull('current_note_pickup_for_processing_id')
  1436. ->where('is_billing_marked_done', true)
  1437. ->where('is_bill_closed', true)
  1438. ->where('is_claim_closed', true)
  1439. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id) > 0)")
  1440. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1441. ->count(),
  1442. "mode-7" => Note::where('is_cancelled', false)
  1443. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1444. ->count(),
  1445. ];
  1446. return view('app.practice-management.process-notes', compact('mode', 'counts'));
  1447. }
  1448. public function notesProcessingCenter(Request $request) {
  1449. $notes = Note::where('is_cancelled', false);
  1450. // filters
  1451. $proUid = $request->input('proUid');
  1452. if($proUid) {
  1453. $fPro = Pro::where('uid', $proUid)->first();
  1454. if($fPro) {
  1455. $notes = $notes->where('hcp_pro_id', $fPro->id);
  1456. }
  1457. }
  1458. $proSigned = $request->input('proSigned');
  1459. switch($proSigned) {
  1460. case 'yes': $notes = $notes->where('is_signed_by_hcp', true); break;
  1461. case 'no': $notes = $notes->where('is_signed_by_hcp', '!=', true); break;
  1462. }
  1463. $billingMarkedDone = $request->input('billingMarkedDone');
  1464. switch($billingMarkedDone) {
  1465. case 'yes': $notes = $notes->where('is_billing_marked_done', true); break;
  1466. case 'no': $notes = $notes->where('is_billing_marked_done', '!=', true); break;
  1467. }
  1468. $billingClosed = $request->input('billingClosed');
  1469. switch($billingClosed) {
  1470. case 'yes': $notes = $notes->where('is_bill_closed', true); break;
  1471. case 'no': $notes = $notes->where('is_bill_closed', '!=', true); break;
  1472. }
  1473. $claimingClosed = $request->input('claimingClosed');
  1474. switch($claimingClosed) {
  1475. case 'yes': $notes = $notes->where('is_claim_closed', true); break;
  1476. case 'no': $notes = $notes->where('is_claim_closed', '!=', true); break;
  1477. }
  1478. $allClaimsSubmitted = $request->input('allClaimsSubmitted');
  1479. if($allClaimsSubmitted) {
  1480. // TODO
  1481. }
  1482. $goodBad = $request->input('goodBad');
  1483. switch($goodBad) {
  1484. case 'good': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'false'"); break;
  1485. case 'bad': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'true'"); break;
  1486. case 'unclassified': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' is null"); break;
  1487. }
  1488. $startDate = $request->input('startDate');
  1489. if($startDate) {
  1490. $notes = $notes->where('effective_dateest', '>=', $startDate);
  1491. }
  1492. $endDate = $request->input('endDate');
  1493. if($endDate) {
  1494. $notes = $notes->where('effective_dateest', '<=', $endDate);
  1495. }
  1496. $mcPartB = $request->input('mcPartB');
  1497. if($mcPartB) {
  1498. // TODO
  1499. }
  1500. $notes = $notes->orderBy('effective_dateest')->paginate(10);
  1501. return view('app.practice-management.notes-processing-center', compact('notes'));
  1502. }
  1503. public function getNextNote(Request $request, $mode)
  1504. {
  1505. $note = null;
  1506. switch (+$mode) {
  1507. case 1:
  1508. $note = Note::where('is_cancelled', false)
  1509. ->where('is_signed_by_hcp', false)
  1510. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1511. ->whereNull('current_note_pickup_for_processing_id')
  1512. ->orderBy('effective_dateest', 'DESC')
  1513. ->first();
  1514. break;
  1515. case 2:
  1516. $note = Note::where('is_cancelled', false)
  1517. ->where('is_signed_by_hcp', true)
  1518. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1519. ->whereNull('current_note_pickup_for_processing_id')
  1520. ->where('is_billing_marked_done', false)
  1521. ->orderBy('effective_dateest', 'DESC')
  1522. ->first();
  1523. break;
  1524. case 3:
  1525. $note = Note::where('is_cancelled', false)
  1526. ->where('is_signed_by_hcp', true)
  1527. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1528. ->whereNull('current_note_pickup_for_processing_id')
  1529. ->where('is_billing_marked_done', true)
  1530. ->where('is_bill_closed', false)
  1531. ->orderBy('effective_dateest', 'DESC')
  1532. ->first();
  1533. break;
  1534. case 4: // claiming not closed
  1535. DB::enableQueryLog(); // Enable query log
  1536. $note = Note::where('is_cancelled', false)
  1537. ->where('is_signed_by_hcp', true)
  1538. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1539. ->whereNull('current_note_pickup_for_processing_id')
  1540. ->where('is_billing_marked_done', true)
  1541. ->where('is_bill_closed', true)
  1542. ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
  1543. ->where('is_claim_closed', false)
  1544. ->orderBy('effective_dateest', 'DESC')
  1545. ->first();
  1546. // DB::enableQueryLog(); // Enable query log
  1547. // Your Eloquent query executed by using get()
  1548. // dd(DB::getQueryLog()); // Show results of log
  1549. break;
  1550. case 5:
  1551. $note = Note::where('is_cancelled', false)
  1552. ->where('is_signed_by_hcp', true)
  1553. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1554. ->whereNull('current_note_pickup_for_processing_id')
  1555. ->where('is_billing_marked_done', true)
  1556. ->where('is_bill_closed', true)
  1557. ->where('is_claim_closed', true)
  1558. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1559. ->orderBy('effective_dateest', 'DESC')
  1560. ->first();
  1561. break;
  1562. case 8:
  1563. $note = Note::where('is_cancelled', false)
  1564. ->where('is_signed_by_hcp', true)
  1565. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1566. ->whereNull('current_note_pickup_for_processing_id')
  1567. ->where('is_billing_marked_done', true)
  1568. ->where('is_bill_closed', true)
  1569. ->where('is_claim_closed', false)
  1570. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1571. ->orderBy('effective_dateest', 'DESC')
  1572. ->first();
  1573. break;
  1574. }
  1575. if($note) {
  1576. $note->client_uid = $note->client->uid;
  1577. }
  1578. return json_encode($note);
  1579. }
  1580. public function pickedNotes(Request $request) {
  1581. $counts = [
  1582. "unpicked" => Note::where('is_cancelled', false)
  1583. ->whereNull('current_note_pickup_for_processing_id')
  1584. ->count(),
  1585. ];
  1586. $notes = Note::where('is_cancelled', false)
  1587. ->whereNotNull('current_note_pickup_for_processing_id')
  1588. ->orderBy('effective_dateest', 'ASC')
  1589. ->paginate();
  1590. return view('app.practice-management.picked-notes', compact('counts', 'notes'));
  1591. }
  1592. public function badNotes(Request $request) {
  1593. $counts = [
  1594. "unpicked" => Note::where('is_cancelled', false)
  1595. ->whereNull('current_note_pickup_for_processing_id')
  1596. ->count(),
  1597. ];
  1598. $notes = Note::where('is_cancelled', false)
  1599. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1600. ->orderBy('effective_dateest', 'ASC')
  1601. ->paginate();
  1602. return view('app.practice-management.bad-notes', compact('counts', 'notes'));
  1603. }
  1604. public function doneNotes(Request $request) {
  1605. $counts = [
  1606. "unpicked" => Note::where('is_cancelled', false)
  1607. ->whereNull('current_note_pickup_for_processing_id')
  1608. ->count(),
  1609. ];
  1610. $notes = Note::where('is_cancelled', false)
  1611. ->where('is_signed_by_hcp', true)
  1612. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1613. ->whereNull('current_note_pickup_for_processing_id')
  1614. ->where('is_billing_marked_done', true)
  1615. ->where('is_bill_closed', true)
  1616. ->where('is_claim_closed', true)
  1617. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id) > 0")
  1618. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0")
  1619. ->orderBy('effective_dateest', 'ASC')
  1620. ->paginate();
  1621. return view('app.practice-management.done-notes', compact('counts', 'notes'));
  1622. }
  1623. public function currentMbClaim(Request $request, $claimUid) {
  1624. $claim = Claim::where('uid', $claimUid)->first();
  1625. return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->first());
  1626. }
  1627. public function currentClaimLines(Request $request, $claimUid) {
  1628. $claim = Claim::where('uid', $claimUid)->first();
  1629. if($request->input('json')) {
  1630. foreach ($claim->lines as $line) {
  1631. $line->expected_total = round($line->expected_total, 3);
  1632. $x = $line->claimLineIcds;
  1633. }
  1634. return json_encode($claim->lines);
  1635. }
  1636. return view('app.practice-management._claim-lines', compact('claim'));
  1637. }
  1638. public function packsMultiPrint(Request $request) {
  1639. $packs = Pack
  1640. ::select('pack.*')
  1641. ->leftJoin('shipment', function($join) {
  1642. $join->on('pack.shipment_id', '=', 'shipment.id');
  1643. })
  1644. ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
  1645. ->where(function ($query) {
  1646. $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
  1647. })
  1648. ->whereNotNull('pack.label_system_file_id')
  1649. ->orderBy('pack.created_at', 'ASC')
  1650. ->get();
  1651. return view('app.practice-management.packs-multi-print', compact('packs'));
  1652. }
  1653. public function packsMultiPDF(Request $request, $ids) {
  1654. $ids = array_map(function ($_x) {
  1655. return intval($_x);
  1656. }, explode("|", $ids));
  1657. $packs = Pack::whereIn('id', $ids)->get();
  1658. }
  1659. public function handouts(Request $request) {
  1660. $handouts = Handout::orderBy('display_name')->get();
  1661. return view('app.practice-management.handouts', compact('handouts'));
  1662. }
  1663. private function callJava($request, $endPoint, $data)
  1664. {
  1665. $url = config('stag.backendUrl') . $endPoint;
  1666. $response = Http::asForm()
  1667. ->withHeaders([
  1668. 'sessionKey' => $request->cookie('sessionKey')
  1669. ])
  1670. ->post($url, $data)
  1671. ->body();
  1672. dd($response);
  1673. return $response;
  1674. }
  1675. public function genericBills(Request $request)
  1676. {
  1677. return view('app.practice-management.generic-bills');
  1678. }
  1679. public function billsUnderProcessing(Request $request)
  1680. {
  1681. $bills = Bill::where('is_cancelled', false)
  1682. ->where(function ($query) { // mcp of any client program and program OB pending
  1683. $query
  1684. ->where(function ($_query) {
  1685. $_query->where('hcp_pro_id', $this->pro->id)
  1686. ->where('hcp_expected_payment_amount', '>', 0)
  1687. ->where('has_hcp_been_paid', false)
  1688. ->where('is_signed_by_hcp', true);
  1689. })
  1690. ->orWhere(function ($_query) {
  1691. $_query->where('cm_pro_id', $this->pro->id)
  1692. ->where('cm_expected_payment_amount', '>', 0)
  1693. ->where('has_cm_been_paid', false)
  1694. ->where('is_signed_by_cm', true);
  1695. })
  1696. ->orWhere(function ($_query) {
  1697. $_query->where('rme_pro_id', $this->pro->id)
  1698. ->where('rme_expected_payment_amount', '>', 0)
  1699. ->where('has_rme_been_paid', false)
  1700. ->where('is_signed_by_rme', true);
  1701. })
  1702. ->orWhere(function ($_query) {
  1703. $_query->where('rmm_pro_id', $this->pro->id)
  1704. ->where('rmm_expected_payment_amount', '>', 0)
  1705. ->where('has_rmm_been_paid', false)
  1706. ->where('is_signed_by_rmm', true);
  1707. })
  1708. ->orWhere(function ($_query) {
  1709. $_query->where('generic_pro_id', $this->pro->id)
  1710. ->where('generic_pro_expected_payment_amount', '>', 0)
  1711. ->where('has_generic_pro_been_paid', false)
  1712. ->where('is_signed_by_generic_pro', true);
  1713. });
  1714. })
  1715. ->orderBy('created_at', 'DESC')
  1716. ->paginate();
  1717. return view('app.practice-management.bills-under-processing', compact('bills'));
  1718. }
  1719. public function careMonthReport(Request $request) {
  1720. $m = $request->input('m');
  1721. $y = $request->input('y');
  1722. if(!$m || !$y) {
  1723. $date = date('Y-m-01');
  1724. }
  1725. else {
  1726. $date = date('Y-m-d', strtotime("$m/1/$y"));
  1727. }
  1728. $pro = $this->pro;
  1729. $records = DB::select("
  1730. SELECT cm.id as care_month_id,
  1731. cm.uid as care_month_uid,
  1732. c.id as client_id,
  1733. c.uid as client_uid,
  1734. cm.number_of_days_with_remote_measurements,
  1735. cm.rm_total_time_in_seconds_by_mcp,
  1736. cm.rm_total_time_in_seconds_by_rme_pro,
  1737. cm.rm_total_time_in_seconds_by_rmm_pro,
  1738. cm.mcp_pro_id,
  1739. cm.rme_pro_id,
  1740. cm.rmm_pro_id,
  1741. (c.name_first || ' ' || c.name_last) as client_name
  1742. FROM care_month cm
  1743. JOIN client c on cm.client_id = c.id
  1744. WHERE cm.start_date = :startDate
  1745. AND (cm.mcp_pro_id = :proID OR
  1746. cm.rme_pro_id = :proID OR
  1747. cm.rmm_pro_id = :proID)
  1748. ORDER BY c.name_last, c.name_first
  1749. ",
  1750. ['startDate' => $date, 'proID' => $pro->id]
  1751. );
  1752. return view('app.practice-management.care-month-report', compact('records', 'date'));
  1753. }
  1754. public function myTeams(Request $request) {
  1755. $pro = $this->pro;
  1756. // get all teams where the authed-pro is the assistant pro
  1757. $teams = ProTeam::where('assistant_pro_id', $pro->id)
  1758. ->where('is_active', true)
  1759. ->orderBy('slug')
  1760. ->get();
  1761. return view('app.practice-management.my-teams', compact('teams'));
  1762. }
  1763. public function patientsAccountsInvites(Request $request){
  1764. $filters = $request->all();
  1765. $accountInvites = AccountInvite::select('account_invite.*')
  1766. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  1767. if($this->performer->pro->pro_type !== 'ADMIN'){
  1768. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  1769. }
  1770. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  1771. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  1772. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  1773. return view('app.practice-management.patients-accounts-invites', compact('accountInvites','filters'));
  1774. }
  1775. }