PracticeManagementController.php 89 KB

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