PracticeManagementController.php 88 KB

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