PracticeManagementController.php 86 KB

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