PracticeManagementController.php 106 KB

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