PracticeManagementController.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  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\Handout;
  8. use App\Models\MBClaim;
  9. use App\Models\Measurement;
  10. use App\Models\Bill;
  11. use App\Models\Claim;
  12. use App\Models\Client;
  13. use App\Models\McpRequest;
  14. use App\Models\Note;
  15. use App\Models\Pack;
  16. use App\Models\Pro;
  17. use App\Models\Product;
  18. use App\Models\ProFavorite;
  19. use App\Models\ProGeneralAvailability;
  20. use App\Models\ProProAccess;
  21. use App\Models\ProRate;
  22. use App\Models\ProSpecificAvailability;
  23. use App\Models\ProSpecificUnavailability;
  24. use App\Models\ProTextShortcut;
  25. use App\Models\ProTransaction;
  26. use App\Models\Shipment;
  27. use App\Models\SupplyOrder;
  28. use App\Models\Ticket;
  29. use App\Models\ClientMeasurementDaysPerMonth;
  30. use Illuminate\Support\Facades\DB;
  31. use Illuminate\Support\Facades\Http;
  32. use PDF;
  33. use DateTime;
  34. use DateTimeZone;
  35. use Illuminate\Http\Request;
  36. class PracticeManagementController extends Controller
  37. {
  38. public function remoteMonitoringReport(Request $request)
  39. {
  40. $rows = null;
  41. $proID = $this->performer()->pro->id;
  42. $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
  43. $rows = $isAdmin ? ClientMeasurementDaysPerMonth::all() : ClientMeasurementDaysPerMonth::where('mcp_pro_id', $proID)->orderBy('year_month', 'asc')->orderBy('num_of_days_with_measurement', 'asc')->get();
  44. return view ('app.practice-management.remote-monitoring-report', compact('rows'));
  45. }
  46. public function billingReport(Request $request)
  47. {
  48. $rows = BillingReport::paginate(50);
  49. return view('app.practice-management.billing-report', compact('rows'));
  50. }
  51. public function dashboard(Request $request)
  52. {
  53. return view('app.practice-management.dashboard');
  54. }
  55. public function rates(Request $request, $selectedProUid = 'all')
  56. {
  57. $proUid = $selectedProUid ? $selectedProUid : 'all';
  58. $rates = ProRate::where('is_active', true);
  59. if ($proUid !== 'all') {
  60. $selectedPro = Pro::where('uid', $proUid)->first();
  61. $rates = $rates->where('pro_id', $selectedPro->id);
  62. }
  63. $rates = $rates->orderBy('pro_id', 'asc')->get();
  64. $pros = $this->pros;
  65. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  66. }
  67. public function previousBills(Request $request)
  68. {
  69. return view('app.practice-management.previous-bills');
  70. }
  71. public function financialTransactions(Request $request)
  72. {
  73. $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
  74. return view('app.practice-management.financial-transactions', compact('transactions'));
  75. }
  76. public function pendingBillsToSign(Request $request)
  77. {
  78. return view('app.practice-management.pending-bills-to-sign');
  79. }
  80. public function HR(Request $request)
  81. {
  82. return view('app.practice-management.hr');
  83. }
  84. public function directDepositSettings(Request $request)
  85. {
  86. return view('app.practice-management.direct-deposit-settings');
  87. }
  88. public function w9(Request $request)
  89. {
  90. return view('app.practice-management.w9');
  91. }
  92. public function contract(Request $request)
  93. {
  94. return view('app.practice-management.contract');
  95. }
  96. public function notes(Request $request, $filter = '')
  97. {
  98. $proID = $this->performer()->pro->id;
  99. $query = Note::where('hcp_pro_id', $proID);
  100. switch ($filter) {
  101. case 'not-yet-signed':
  102. $query = $query->where('is_signed_by_hcp', false);
  103. break;
  104. case 'not-yet-signed-but-ally-signed':
  105. $query = $query->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true);
  106. break;
  107. case 'without-bills':
  108. $query = $query->where('is_signed_by_hcp', true)->where('is_cancelled', false)->whereDoesntHave('bills');
  109. break;
  110. // more cases can be added as needed
  111. default:
  112. break;
  113. }
  114. $notes = $query->orderBy('created_at', 'desc')->get();
  115. return view('app.practice-management.notes', compact('notes', 'filter'));
  116. }
  117. public function naBillableSignedNotes(Request $request)
  118. {
  119. $notes = Note
  120. ::where('is_signed_by_hcp', TRUE)
  121. ->where('ally_pro_id', $this->performer()->pro->id)
  122. ->where('is_cancelled', FALSE)
  123. ->whereRaw("
  124. (
  125. SELECT count(bill.id)
  126. FROM bill WHERE
  127. bill.is_cancelled = FALSE AND
  128. bill.generic_pro_id = {$this->performer()->pro->id} AND
  129. bill.note_id = note.id
  130. ) = 0
  131. ");
  132. $notes = $notes->orderBy('created_at', 'desc')->get();
  133. return view('app.practice-management.na-billable-signed-notes', compact('notes'));
  134. }
  135. public function bills(Request $request, $filter = '')
  136. {
  137. $proID = $this->performer()->pro->id;
  138. $query = Bill::where('is_cancelled', false)->where('bill_service_type', '<>', 'CARE_MONTH');
  139. switch ($filter) {
  140. case 'not-yet-signed':
  141. $query = $query
  142. ->where(function ($q) use ($proID) {
  143. $q->where(function ($q2) use ($proID) {
  144. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  145. })
  146. ->orWhere(function ($q2) use ($proID) {
  147. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  148. })
  149. ->orWhere(function ($q2) use ($proID) {
  150. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  151. })
  152. ->orWhere(function ($q2) use ($proID) {
  153. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  154. });
  155. });
  156. break;
  157. case 'previous':
  158. $query = $query
  159. ->where(function ($q) use ($proID) {
  160. $q->where(function ($q2) use ($proID) {
  161. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  162. })
  163. ->orWhere(function ($q2) use ($proID) {
  164. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  165. })
  166. ->orWhere(function ($q2) use ($proID) {
  167. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  168. })
  169. ->orWhere(function ($q2) use ($proID) {
  170. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  171. });
  172. });
  173. break;
  174. // more cases can be added as needed
  175. default:
  176. break;
  177. }
  178. $bills = $query->orderBy('created_at', 'desc')->get();
  179. return view('app.practice-management.bills', compact('bills', 'filter'));
  180. }
  181. public function rmBillsToSign(Request $request)
  182. {
  183. $performerProID = $this->performer()->pro->id;
  184. $bills = Bill::where('is_cancelled', false)->where('cm_or_rm', 'RM')
  185. ->where(function ($q) use ($performerProID) {
  186. $q
  187. ->where(function ($q2) use ($performerProID) {
  188. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  189. })
  190. ->orWhere(function ($q2) use ($performerProID) {
  191. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  192. })
  193. ->orWhere(function ($q2) use ($performerProID) {
  194. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  195. })
  196. ->orWhere(function ($q2) use ($performerProID) {
  197. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  198. });
  199. })
  200. ->orderBy('effective_date', 'desc')
  201. ->get();
  202. return view('app.practice-management.rm-bills-to-sign', compact('bills'));
  203. }
  204. public function unacknowledgedCancelledBills(Request $request)
  205. {
  206. $bills = Bill::where('hcp_pro_id', $this->performer()->pro->id)
  207. ->where('is_cancelled', true)
  208. ->where('is_cancellation_acknowledged', false)
  209. ->orderBy('created_at', 'desc')
  210. ->get();
  211. return view('app.practice-management.unacknowledged-cancelled-bills', compact('bills'));
  212. }
  213. public function myTickets(Request $request, $filter = 'open')
  214. {
  215. $performer = $this->performer();
  216. $myTickets = Ticket::where(function ($q) use ($performer) {
  217. $q->where('assigned_pro_id', $performer->pro_id)
  218. ->orWhere('manager_pro_id', $performer->pro_id)
  219. ->orWhere('ordering_pro_id', $performer->pro_id)
  220. ->orWhere('initiating_pro_id', $performer->pro_id);
  221. });
  222. if ($filter === 'open') {
  223. $myTickets = $myTickets->where('is_open', true);
  224. } else if ($filter === 'closed') {
  225. $myTickets = $myTickets->where('is_open', false);
  226. }
  227. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  228. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  229. }
  230. public function myTextShortcuts(Request $request)
  231. {
  232. $myTextShortcuts = DB::table('pro_text_shortcut')
  233. ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
  234. ->select(
  235. 'pro_text_shortcut.uid',
  236. 'pro_text_shortcut.shortcut',
  237. 'pro_text_shortcut.text',
  238. 'pro.name_first',
  239. 'pro.name_last'
  240. )
  241. ->where('pro_text_shortcut.is_removed', false);
  242. if($this->performer()->pro->pro_type !== 'ADMIN') {
  243. $myTextShortcuts = $myTextShortcuts->where('pro_id', $this->performer()->pro_id);
  244. }
  245. $myTextShortcuts = $myTextShortcuts
  246. ->orderBy('pro.name_last')
  247. ->orderBy('pro.name_first')
  248. ->get();
  249. return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
  250. }
  251. public function myFavorites(Request $request, $filter = 'all')
  252. {
  253. $performer = $this->performer();
  254. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  255. ->where('is_removed', false);
  256. if ($filter !== 'all') {
  257. $myFavorites = $myFavorites->where('category', $filter);
  258. }
  259. $myFavorites = $myFavorites
  260. ->orderBy('category', 'asc')
  261. ->orderBy('position_index', 'asc')
  262. ->get();
  263. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  264. }
  265. public function proAvailability(Request $request, $proUid = null)
  266. {
  267. $performer = $this->performer();
  268. $pro = $performer->pro;
  269. if ($proUid) {
  270. $pro = Pro::where('uid', $proUid)->first();
  271. }
  272. if ($request->get('pro_uid')) {
  273. $proUid = $request->get('pro_uid');
  274. $pro = Pro::where('uid', $proUid)->first();
  275. }
  276. $selectedProUid = $pro->uid;
  277. $pros = $this->pros;
  278. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  279. $generalAvailabilities = [
  280. 'MONDAY' => [],
  281. 'TUESDAY' => [],
  282. 'WEDNESDAY' => [],
  283. 'THURSDAY' => [],
  284. 'FRIDAY' => [],
  285. 'SATURDAY' => [],
  286. 'SUNDAY' => [],
  287. ];
  288. foreach ($generalAvailabilitiesList as $ga) {
  289. if ($ga->day_of_week == 'MONDAY') {
  290. $generalAvailabilities['MONDAY'][] = $ga;
  291. }
  292. if ($ga->day_of_week == 'TUESDAY') {
  293. $generalAvailabilities['TUESDAY'][] = $ga;
  294. }
  295. if ($ga->day_of_week == 'WEDNESDAY') {
  296. $generalAvailabilities['WEDNESDAY'][] = $ga;
  297. }
  298. if ($ga->day_of_week == 'THURSDAY') {
  299. $generalAvailabilities['THURSDAY'][] = $ga;
  300. }
  301. if ($ga->day_of_week == 'FRIDAY') {
  302. $generalAvailabilities['FRIDAY'][] = $ga;
  303. }
  304. if ($ga->day_of_week == 'SATURDAY') {
  305. $generalAvailabilities['SATURDAY'][] = $ga;
  306. }
  307. if ($ga->day_of_week == 'SUNDAY') {
  308. $generalAvailabilities['SUNDAY'][] = $ga;
  309. }
  310. }
  311. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  312. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  313. //events for the calendar
  314. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  315. $endDateTime = new DateTime($startDate);
  316. $endDateTime->modify('+6 day');
  317. $endDate = $endDateTime->format("Y-m-d");
  318. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  319. $events = json_encode($eventsData);
  320. return view(
  321. 'app.practice-management.pro-availability',
  322. compact(
  323. 'pros',
  324. 'generalAvailabilities',
  325. 'specificAvailabilities',
  326. 'specificUnavailabilities',
  327. 'events',
  328. 'selectedProUid'
  329. )
  330. );
  331. }
  332. public function loadAvailability(Request $request, $proUid)
  333. {
  334. $performer = $this->performer();
  335. $pro = $performer->pro;
  336. $startDate = $request->get('start');
  337. $endDate = $request->get('end');
  338. $selectedPro = Pro::where('uid', $proUid)->first();
  339. return $selectedPro->getAvailabilityEvents($startDate, $endDate);
  340. }
  341. public function proAvailabilityFilter(Request $request)
  342. {
  343. $proUid = $request->get('proUid');
  344. return ['success' => true, 'data' => $proUid];
  345. }
  346. // video call page (RHS)
  347. // generic call handle (no uid)
  348. // specific call handle (uid of client)
  349. public function meet(Request $request, $uid = false)
  350. {
  351. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  352. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  353. if (!empty($client)) {
  354. return view('app.video.call-minimal', compact('session', 'client'));
  355. }
  356. return view('app.video.call-agora-v2', compact('session', 'client'));
  357. }
  358. // check video page
  359. public function checkVideo(Request $request, $uid)
  360. {
  361. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  362. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  363. $publish = false;
  364. return view('app.video.check-video-minimal', compact('session', 'client'));
  365. }
  366. public function getParticipantInfo(Request $request)
  367. {
  368. $sid = intval($request->get('uid')) - 1000000;
  369. $session = AppSession::where('id', $sid)->first();
  370. $result = [
  371. "type" => '',
  372. "name" => ''
  373. ];
  374. if ($session) {
  375. $result["type"] = $session->session_type;
  376. switch ($session->session_type) {
  377. case 'PRO':
  378. $pro = Pro::where('id', $session->pro_id)->first();
  379. $result["name"] = $pro->displayName();
  380. break;
  381. case 'CLIENT':
  382. $client = Client::where('id', $session->client_id)->first();
  383. $result["name"] = $client->displayName();
  384. break;
  385. }
  386. }
  387. return json_encode($result);
  388. }
  389. // ajax ep used by the video page
  390. // this is needed bcoz meet() is used not
  391. // just for the client passed to the view
  392. public function getOpentokSessionKey(Request $request, $uid)
  393. {
  394. $client = Client::where('uid', $uid)->first();
  395. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  396. }
  397. // poll to check if there are patients with active mcp requests
  398. public function getPatientsInQueue(Request $request)
  399. {
  400. $myInitiatives = $this->performer->pro->initiatives;
  401. if ($myInitiatives) {
  402. $myInitiatives = strtoupper($myInitiatives);
  403. }
  404. $myInitiativesList = explode('|', $myInitiatives);
  405. $myForeignLanguages = $this->performer->pro->foreign_languages;
  406. if ($myForeignLanguages) {
  407. $myForeignLanguages = strtoupper($myForeignLanguages);
  408. }
  409. $myForeignLanguagesList = explode('|', $myForeignLanguages);
  410. $clients = Client::whereNotNull('active_mcp_request_id')->where(function ($query) use ($myInitiativesList) {
  411. $query->whereNull('initiative')->orWhereIn('initiative', $myInitiativesList);
  412. })
  413. ->where(function ($query) use ($myForeignLanguagesList) {
  414. $query->whereNull('preferred_foreign_language')->orWhereIn('preferred_foreign_language', $myForeignLanguagesList);
  415. })->limit(3)->get();
  416. $results = [];
  417. foreach ($clients as $client) {
  418. $results[] = [
  419. 'clientUid' => $client->uid,
  420. 'name' => $client->displayName(),
  421. 'initials' => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  422. ];
  423. }
  424. return json_encode($results);
  425. }
  426. public function currentWork(Request $request)
  427. {
  428. return view('app/current-work');
  429. }
  430. public function calendar(Request $request, $proUid = null)
  431. {
  432. $pros = Pro::all();
  433. if ($this->pro && $this->pro->pro_type != 'ADMIN') {
  434. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
  435. $accessibleProIds = [];
  436. foreach ($accessiblePros as $accessiblePro) {
  437. $accessibleProIds[] = $accessiblePro->id;
  438. }
  439. $accessibleProIds[] = $this->pro->id;
  440. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  441. }
  442. return view('app.practice-management.calendar', compact('pros'));
  443. }
  444. public function cellularDeviceManager(Request $request, $proUid = null)
  445. {
  446. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  447. $performerPro = $this->performer->pro;
  448. $targetPro = null;
  449. $allPros = [];
  450. $expectedForHcp = null;
  451. if ($performerPro->pro_type == 'ADMIN') {
  452. $allPros = Pro::all();
  453. $targetPro = Pro::where('uid', $proUid)->first();
  454. } else {
  455. $targetPro = $performerPro;
  456. }
  457. $clients = [];
  458. if ($targetPro) {
  459. $clients = Client::where('mcp_pro_id', $targetPro->id)->orderBy('created_at', 'desc')->paginate(100);
  460. } else {
  461. $clients = Client::orderBy('created_at', 'desc')->paginate(100);
  462. }
  463. return view('app.practice-management.cellular-device-manager', compact('clients', 'allPros', 'targetPro', 'proUid'));
  464. }
  465. public function treatmentServiceUtil(Request $request)
  466. {
  467. $view_treatment_service_utilization_org = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_org ORDER BY effective_date DESC"));
  468. $view_treatment_service_utilization = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization ORDER BY effective_date DESC, total_hrs DESC"));
  469. $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"));
  470. return view('app.practice-management.treatment-services-util', compact(
  471. 'view_treatment_service_utilization_org',
  472. 'view_treatment_service_utilization',
  473. 'view_treatment_service_utilization_by_patient'));
  474. }
  475. public function processingBillMatrix(Request $request, $proUid = null)
  476. {
  477. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  478. $performerPro = $this->performer->pro;
  479. $targetPro = null;
  480. if ($performerPro->pro_type == 'ADMIN') {
  481. $targetPro = Pro::where('uid', $proUid)->first();
  482. } else {
  483. $targetPro = $performerPro;
  484. }
  485. $bills = Bill::where('is_cancelled', false);
  486. if(!$request->input('t') || $request->input('t') === 'hcp') {
  487. $bills = $bills
  488. ->where('has_hcp_been_paid', false)
  489. ->where('is_signed_by_hcp', true);
  490. if ($targetPro) {
  491. $bills = $bills->where('hcp_pro_id', $targetPro->id);
  492. }
  493. }
  494. else if($request->input('t') === 'na') {
  495. $bills = $bills
  496. ->where('has_generic_pro_been_paid', false)
  497. ->where('is_signed_by_generic_pro', true);
  498. if ($targetPro) {
  499. $bills = $bills->where('generic_pro_id', $targetPro->id);
  500. }
  501. }
  502. $filter = $request->input('f');
  503. switch ($filter) {
  504. case 'verified':
  505. $bills = $bills->where('is_verified', true);
  506. break;
  507. case 'not-verified':
  508. $bills = $bills->where('is_verified', false);
  509. break;
  510. }
  511. $filter = $request->input('bs');
  512. if ($filter) {
  513. $bills = $bills->where('balance_post_date', '>=', $filter);
  514. }
  515. $filter = $request->input('be');
  516. if ($filter) {
  517. $bills = $bills->where('balance_post_date', '<=', $filter);
  518. }
  519. $bills = $bills->orderBy('effective_date', 'desc')->paginate();
  520. $viewData = [
  521. 'bills' => $bills,
  522. 'targetPro' => $targetPro,
  523. 'performerPro' => $performerPro,
  524. 'proUid' => $proUid
  525. ];
  526. return view('app.practice-management.processing-bill-matrix', $viewData);
  527. }
  528. public function proFinancials(Request $request, $proUid = null)
  529. {
  530. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  531. $performerPro = $this->performer->pro;
  532. $targetPro = null;
  533. if ($performerPro->pro_type == 'ADMIN') {
  534. $targetPro = Pro::where('uid', $proUid)->first();
  535. } else {
  536. $targetPro = $performerPro;
  537. }
  538. $fPros = Pro::whereNotNull('balance');
  539. if($targetPro) {
  540. $fPros = $fPros->where('uid', $targetPro->uid);
  541. }
  542. $fPros = $fPros
  543. ->where('balance', '>', 0)
  544. ->orderBy('name_last')
  545. ->orderBy('name_first')
  546. ->paginate();
  547. return view('app.practice-management.pro-financials', compact('fPros', 'targetPro'));
  548. }
  549. public function hcpBillMatrix(Request $request, $proUid = null)
  550. {
  551. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  552. $performerPro = $this->performer->pro;
  553. $targetPro = null;
  554. $allPros = [];
  555. $expectedForHcp = null;
  556. if ($performerPro->pro_type == 'ADMIN') {
  557. $allPros = Pro::all();
  558. $targetPro = Pro::where('uid', $proUid)->first();
  559. } else {
  560. $targetPro = $performerPro;
  561. }
  562. $rows = [];
  563. if ($targetPro) {
  564. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report WHERE hcp_pro_id = :targetProID"), ['targetProID' => $targetPro->id]);
  565. } else {
  566. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report"));
  567. }
  568. return view('app.practice-management.hcp-bill-matrix', compact('rows', 'allPros', 'expectedForHcp', 'targetPro', 'proUid'));
  569. }
  570. public function billingManager(Request $request, $proUid = null)
  571. {
  572. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  573. $performerPro = $this->performer->pro;
  574. $targetPro = null;
  575. $allPros = [];
  576. $expectedForHcp = null;
  577. if ($performerPro->pro_type == 'ADMIN') {
  578. $allPros = Pro::all();
  579. $targetPro = Pro::where('uid', $proUid)->first();
  580. } else {
  581. $targetPro = $performerPro;
  582. }
  583. $notes = [];
  584. if ($targetPro) {
  585. $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;
  586. $notes = Note::where('hcp_pro_id', $targetPro->id);
  587. } else {
  588. $notes = Note::where('id', '>', 0);
  589. }
  590. if($request->input('date')) {
  591. $notes = $notes->where('effective_dateest', $request->input('date'));
  592. }
  593. $filters = [];
  594. $filters['bills_created'] = $request->input('bills_created');
  595. $filters['is_billing_marked_done'] = $request->input('is_billing_marked_done');
  596. $filters['bills_resolved'] = $request->input('bills_resolved');
  597. $filters['bills_closed'] = $request->input('bills_closed');
  598. $filters['claims_created'] = $request->input('claims_created');
  599. $filters['claims_closed'] = $request->input('claims_closed');
  600. if ($filters['bills_created']) {
  601. $notes->where(
  602. 'bill_total_expected',
  603. ($filters['bills_created'] === 'yes' ? '>' : '<='),
  604. 0);
  605. }
  606. if ($filters['is_billing_marked_done']) {
  607. $notes->where(
  608. 'is_billing_marked_done',
  609. ($filters['is_billing_marked_done'] === 'yes' ? '=' : '!='),
  610. true);
  611. }
  612. if ($filters['bills_resolved']) {
  613. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id) > 0'); // have bills
  614. if ($filters['bills_resolved'] === 'yes') {
  615. $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');
  616. } elseif ($filters['bills_resolved'] === 'no') {
  617. $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');
  618. }
  619. }
  620. if ($filters['bills_closed']) {
  621. $notes->where(
  622. 'is_bill_closed',
  623. ($filters['bills_closed'] === 'yes' ? '=' : '!='),
  624. true);
  625. }
  626. if ($filters['claims_created']) {
  627. $notes->where(
  628. 'claim_total_expected',
  629. ($filters['claims_created'] === 'yes' ? '>' : '<='),
  630. 0);
  631. }
  632. if ($filters['claims_closed']) {
  633. $notes->where(
  634. 'is_claim_closed',
  635. ($filters['claims_closed'] === 'yes' ? '=' : '!='),
  636. true);
  637. }
  638. $notes = $notes->orderBy('effective_dateest', 'desc')->paginate(10);
  639. return view('app.practice-management.billing-manager', compact('notes', 'allPros', 'expectedForHcp', 'targetPro', 'proUid', 'filters'));
  640. }
  641. public function remoteMonitoring(Request $request) {
  642. $performer = $this->performer();
  643. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  644. $careMonthStart = date($ym . '-01');
  645. // filters
  646. $filters = '';
  647. $fmd = $request->input('fmd');
  648. if($fmd && $fmd !== 'all') {
  649. switch($fmd) {
  650. case 'lt16':
  651. $filters .= ' AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL) ';
  652. break;
  653. case 'gte16':
  654. $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
  655. break;
  656. }
  657. }
  658. $fcomm = $request->input('fcomm');
  659. if($fcomm && $fcomm !== 'all') {
  660. switch($fcomm) {
  661. case 'not-done':
  662. $filters .= ' AND (care_month.has_non_hcp_communicated_to_patient_about_rm = FALSE OR care_month.has_non_hcp_communicated_to_patient_about_rm IS NULL) ';
  663. break;
  664. case 'done':
  665. $filters .= ' AND (care_month.has_non_hcp_communicated_to_patient_about_rm = TRUE AND care_month.has_non_hcp_communicated_to_patient_about_rm IS NOT NULL) ';
  666. break;
  667. }
  668. }
  669. $c = $request->input('c');
  670. if($c) {
  671. $filters .= ' AND client.uid = \'' . $request->input('c') . '\' ';
  672. }
  673. $patients = DB::select(
  674. DB::raw(
  675. "
  676. SELECT client.name_first, client.name_last, client.uid as client_uid,
  677. care_month.uid as care_month_uid,
  678. care_month.id as care_month_id,
  679. care_month.start_date,
  680. care_month.number_of_days_with_remote_measurements,
  681. care_month.has_non_hcp_communicated_to_patient_about_rm,
  682. care_month.rm_num_measurements_not_stamped_by_mcp,
  683. care_month.rm_num_measurements_not_stamped_by_non_hcp,
  684. care_month.rm_num_measurements_not_stamped_by_rmm,
  685. care_month.rm_num_measurements_not_stamped_by_rme,
  686. client.mcp_pro_id,
  687. client.default_na_pro_id,
  688. client.rmm_pro_id,
  689. client.rme_pro_id,
  690. client.cell_number
  691. FROM care_month join client on care_month.client_id = client.id
  692. WHERE (
  693. (client.mcp_pro_id = {$performer->pro->id})
  694. OR (client.rmm_pro_id = {$performer->pro->id})
  695. OR (client.rme_pro_id = {$performer->pro->id})
  696. OR (client.default_na_pro_id = {$performer->pro->id})
  697. )
  698. AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  699. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  700. {$filters}
  701. ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first ASC, client.name_last ASC
  702. "
  703. )
  704. );
  705. $timestamp = strtotime(date('Y-m-d'));
  706. $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
  707. return view('app.practice-management.remote-monitoring', compact('patients', 'daysRemaining', 'careMonthStart'));
  708. }
  709. public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
  710. $performer = $this->performer();
  711. $measurements = DB::select(
  712. DB::raw(
  713. "
  714. SELECT measurement.label,
  715. measurement.ts,
  716. measurement.effective_date,
  717. measurement.sbp_mm_hg,
  718. measurement.dbp_mm_hg,
  719. measurement.value_pulse,
  720. measurement.value_irregular,
  721. measurement.numeric_value,
  722. measurement.value,
  723. measurement.uid,
  724. client.name_first,
  725. client.name_last,
  726. client.mcp_pro_id,
  727. client.default_na_pro_id,
  728. client.rmm_pro_id,
  729. client.rme_pro_id
  730. FROM measurement RIGHT JOIN client on measurement.client_id = client.id
  731. WHERE
  732. client.id = {$careMonth->client_id}
  733. AND measurement.label IS NOT NULL
  734. AND measurement.label NOT IN ('SBP', 'DBP')
  735. AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
  736. AND measurement.is_removed IS FALSE
  737. AND measurement.client_bdt_measurement_id IS NOT NULL
  738. AND measurement.care_month_id = {$careMonth->id}
  739. AND (
  740. (client.mcp_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_mcp IS FALSE)
  741. OR (client.rmm_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rmm IS FALSE)
  742. OR (client.rme_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rme IS FALSE)
  743. OR (client.default_na_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_non_hcp IS FALSE)
  744. )
  745. ORDER BY ts DESC
  746. "
  747. )
  748. );
  749. return view('app.practice-management.remote-monitoring-measurements', compact('careMonth', 'measurements'));
  750. }
  751. public function billMatrix(Request $request)
  752. {
  753. $bClients = [];
  754. $bHCPPros = [];
  755. $bNAPros = [];
  756. $filters = [];
  757. $filters['client'] = $request->input('client');
  758. $filters['service'] = $request->input('service');
  759. $filters['hcp'] = $request->input('hcp');
  760. $filters['hcp_paid'] = $request->input('hcp_paid');
  761. $filters['expected_op'] = $request->input('expected_op');
  762. $filters['expected_value'] = $request->input('expected_value');
  763. $filters['paid_op'] = $request->input('paid_op');
  764. $filters['paid_value'] = $request->input('paid_value');
  765. $filters['bal_post_date_op'] = $request->input('bal_post_date_op');
  766. $filters['bal_post_date_value'] = $request->input('bal_post_date_value');
  767. $filters['hcp_sign'] = $request->input('hcp_sign');
  768. $filters['verified'] = $request->input('verified');
  769. $filters['cancelled'] = $request->input('cancelled');
  770. $bills = Bill::orderBy('effective_date')->paginate();
  771. return view('app.practice-management.bill-matrix', compact('bills', 'bClients', 'bHCPPros', 'filters'));
  772. }
  773. public function medicarePartBClaims(Request $request)
  774. {
  775. $medicarePartBOnly = $request->get("medicare_part_b");
  776. $allClaims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->get();
  777. //Only medicare claims
  778. $claims = [];
  779. foreach ($allClaims as $claim) {
  780. if ($claim->client != null && $claim->client->is_part_b_primary == 'YES' && !$claim->edi) {
  781. $claims[] = $claim;
  782. }
  783. }
  784. $claimEDIs = ClaimEDI::all();
  785. return view('app.practice-management.medicare-partb-claims', compact('claims', 'claimEDIs'));
  786. }
  787. // Generate PDF
  788. public function downloadClaims()
  789. {
  790. $claims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->limit(100)->get();
  791. view()->share('claims', $claims);
  792. $pdf = PDF::loadView('app.practice-management.claims-pdf', $claims);
  793. return $pdf->download('pdf_file.pdf');
  794. }
  795. public function tickets(Request $request, $proUid = null)
  796. {
  797. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  798. return view('app.practice-management.tickets', compact('tickets'));
  799. }
  800. public function supplyOrders(Request $request)
  801. {
  802. // counts
  803. $counts = $this->getSupplyOrderCounts();
  804. // so clients
  805. $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
  806. $soClientIDs = array_map(function ($_x) {
  807. return $_x->client_id;
  808. }, $soClientIDs);
  809. $soClients = Client::whereIn('id', $soClientIDs)->get();
  810. // so products
  811. $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
  812. $soProductIDs = array_map(function ($_x) {
  813. return $_x->product_id;
  814. }, $soProductIDs);
  815. $soProducts = Product::whereIn('id', $soProductIDs)->get();
  816. $filters = [];
  817. $filters['client'] = $request->input('client');
  818. $filters['product'] = $request->input('product');
  819. $filters['reason'] = $request->input('reason');
  820. $filters['cu_memo'] = $request->input('cu_memo');
  821. $filters['pro_sign'] = $request->input('pro_sign');
  822. $filters['client_sign'] = $request->input('client_sign');
  823. $filters['shipment'] = $request->input('shipment');
  824. $filters['lot_number'] = $request->input('lot_number');
  825. $filters['imei'] = $request->input('imei');
  826. $filters['cancelled'] = $request->input('cancelled');
  827. $supplyOrders = SupplyOrder::where('id', '>', 0);
  828. // apply filters
  829. if ($filters['client']) $supplyOrders->where('client_id', $filters['client']);
  830. if ($filters['product']) $supplyOrders->where('product_id', $filters['product']);
  831. if ($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
  832. if ($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
  833. if ($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
  834. if ($filters['client_sign']) {
  835. if ($filters['client_sign'] === 'signed')
  836. $supplyOrders->where('is_signed_by_client', true);
  837. elseif ($filters['client_sign'] === 'waived')
  838. $supplyOrders->where('is_client_signature_waived', true);
  839. else
  840. $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
  841. }
  842. if ($filters['shipment']) {
  843. if ($filters['shipment'] === 'not_cleared_for_shipment')
  844. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', false);
  845. elseif ($filters['shipment'] === 'cleared_for_shipment')
  846. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', true);
  847. else
  848. $supplyOrders
  849. ->whereNotNull('shipment_id')
  850. ->whereRaw('(SELECT status FROM shipment WHERE id = shipment_id LIMIT 1) = ?', [$filters['shipment']]);
  851. }
  852. if ($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
  853. if ($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
  854. if ($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  855. $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
  856. return view('app.practice-management.supply-orders',
  857. compact('supplyOrders', 'filters',
  858. 'soClients', 'soProducts', 'counts'
  859. )
  860. );
  861. }
  862. public function shipments(Request $request, $filter = null)
  863. {
  864. // counts
  865. $counts = $this->getShipmentCounts();
  866. // so clients
  867. $shClientIDs = DB::table('shipment')->select('client_id')->distinct()->get()->toArray();
  868. $shClientIDs = array_map(function ($_x) {
  869. return $_x->client_id;
  870. }, $shClientIDs);
  871. $shClients = Client::whereIn('id', $shClientIDs)->get();
  872. $shipments = Shipment::where('id', '>', 0);
  873. $filters = [];
  874. $filters['client'] = $request->input('client');
  875. $filters['courier'] = $request->input('courier');
  876. $filters['tracking_num'] = $request->input('tracking_num');
  877. $filters['label'] = $request->input('label');
  878. $filters['status'] = $request->input('status');
  879. $filters['cancelled'] = $request->input('cancelled');
  880. if ($filters['client']) $shipments->where('client_id', $filters['client']);
  881. if ($filters['courier']) $shipments->where('courier', 'ILIKE', '%' . $filters['courier'] . '%');
  882. if ($filters['tracking_num']) $shipments->where('tracking_number', 'ILIKE', '%' . $filters['tracking_num'] . '%');
  883. if ($filters['label']) {
  884. if ($filters['label'] === 'yes')
  885. $shipments->whereNotNull('label_system_file_id');
  886. else
  887. $shipments->whereNull('label_system_file_id');
  888. }
  889. if ($filters['status']) $shipments->where('status', $filters['status']);
  890. if ($filters['cancelled']) $shipments->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  891. $shipments = $shipments->orderBy('created_at', 'desc')->paginate();
  892. return view('app.practice-management.shipments', compact('shipments', 'filters', 'shClients', 'counts'));
  893. }
  894. public function cellularMeasurements(Request $request)
  895. {
  896. $measurements = Measurement::orderBy('ts', 'desc')->whereNotNull('ts')->paginate();
  897. return view('app.practice-management.cellular-measurements', compact('measurements'));
  898. }
  899. // v2 supply-orders & shipments management (wh)
  900. public function supplyOrdersReadyToShip(Request $request)
  901. {
  902. $counts = $this->getSupplyOrderCounts();
  903. $supplyOrders = SupplyOrder
  904. ::where('is_cleared_for_shipment', true)
  905. ->where('is_cancelled', false)
  906. ->whereNull('shipment_id')
  907. ->join('client', 'client.id', '=', 'supply_order.client_id')
  908. ->orderBy('client.name_last', 'ASC')
  909. ->orderBy('client.name_first', 'ASC')
  910. ->orderBy('supply_order.client_id', 'ASC')
  911. ->orderBy('supply_order.mailing_address_full', 'ASC')
  912. ->orderBy('supply_order.created_at', 'ASC')
  913. ->select('supply_order.*')
  914. ->paginate();
  915. return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
  916. }
  917. public function supplyOrdersShipmentUnderway(Request $request)
  918. {
  919. $counts = $this->getSupplyOrderCounts();
  920. $supplyOrders = SupplyOrder
  921. ::where('is_cancelled', false)
  922. ->whereNotNull('shipment_id')
  923. ->orderBy('client_id', 'ASC')
  924. ->orderBy('mailing_address_full', 'ASC')
  925. ->orderBy('created_at', 'ASC')
  926. ->paginate();
  927. return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
  928. }
  929. public function supplyOrdersHanging(Request $request)
  930. {
  931. $counts = $this->getSupplyOrderCounts();
  932. $supplyOrders = SupplyOrder
  933. ::select('supply_order.*')
  934. ->leftJoin('shipment', function($join) {
  935. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  936. })
  937. ->where('shipment.status', 'CANCELLED')
  938. ->where('supply_order.is_cancelled', false)
  939. ->orderBy('supply_order.client_id', 'ASC')
  940. ->orderBy('supply_order.mailing_address_full', 'ASC')
  941. ->orderBy('supply_order.created_at', 'ASC')
  942. ->paginate();
  943. return view('app.practice-management.supply-orders-hanging', compact('supplyOrders', 'counts'));
  944. }
  945. public function supplyOrdersCancelledButUnacknowledged(Request $request)
  946. {
  947. $supplyOrders = SupplyOrder::where('signed_by_pro_id', $this->performer()->pro->id)
  948. ->where('is_cancelled', true)
  949. ->where('is_cancellation_acknowledged', false)
  950. ->orderBy('created_at', 'desc')
  951. ->paginate();
  952. return view('app.practice-management.supply-orders-cancelled-but-unacknowledged', compact('supplyOrders'));
  953. }
  954. public function supplyOrdersUnsigned(Request $request)
  955. {
  956. $supplyOrders = SupplyOrder
  957. ::where('is_cancelled', false)
  958. ->where('is_signed_by_pro', false)
  959. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$this->performer()->pro->id])
  960. ->orderBy('created_at', 'desc')
  961. ->paginate();
  962. return view('app.practice-management.supply-orders-unsigned', compact('supplyOrders'));
  963. }
  964. private function getSupplyOrderCounts()
  965. {
  966. return [
  967. "supplyOrders" => SupplyOrder::count(),
  968. "supplyOrdersReadyToShip" => SupplyOrder
  969. ::where('is_cleared_for_shipment', true)
  970. ->where('is_cancelled', false)
  971. ->whereNull('shipment_id')->count(),
  972. "supplyOrdersShipmentUnderway" => SupplyOrder
  973. ::where('is_cancelled', false)
  974. ->whereNotNull('shipment_id')->count(),
  975. "supplyOrdersHanging" => SupplyOrder
  976. ::leftJoin('shipment', function($join) {
  977. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  978. })
  979. ->where('shipment.status', 'CANCELLED')
  980. ->where('supply_order.is_cancelled', false)
  981. ->count(),
  982. ];
  983. }
  984. public function shipmentsReadyToPrint(Request $request)
  985. {
  986. $counts = $this->getShipmentCounts();
  987. $shipments = Shipment
  988. ::where('is_cancelled', false)
  989. ->where('status', 'CREATED')
  990. ->orderBy('created_at', 'ASC')
  991. ->paginate();
  992. return view('app.practice-management.shipments-ready-to-print', compact('shipments', 'counts'));
  993. }
  994. public function shipmentsShipmentUnderway(Request $request)
  995. {
  996. $counts = $this->getShipmentCounts();
  997. $shipments = Shipment
  998. ::where('is_cancelled', false)
  999. ->where('status', 'PRINTED')
  1000. ->orderBy('created_at', 'ASC')
  1001. ->paginate();
  1002. return view('app.practice-management.shipments-waiting-for-picker', compact('shipments', 'counts'));
  1003. }
  1004. private function getShipmentCounts()
  1005. {
  1006. return [
  1007. "shipments" => Shipment::count(),
  1008. "shipmentsReadyToPrint" => Shipment
  1009. ::where('is_cancelled', false)
  1010. ->where('status', 'CREATED')
  1011. ->count(),
  1012. "shipmentsWaitingForPicker" => Shipment
  1013. ::where('is_cancelled', false)
  1014. ->where('status', 'PRINTED')
  1015. ->count()
  1016. ];
  1017. }
  1018. public function shipment(Request $request, Shipment $shipment)
  1019. {
  1020. return view('app.practice-management.shipment', compact('shipment'));
  1021. }
  1022. public function shipmentsMultiPrint(Request $request, $ids)
  1023. {
  1024. $ids = array_map(function ($_x) {
  1025. return intval($_x);
  1026. }, explode("|", $ids));
  1027. $shipments = Shipment::whereIn('id', $ids)->get();
  1028. return view('app.practice-management.shipments-multi-print', compact('shipments'));
  1029. }
  1030. public function patientClaimSummary(Request $request, $proUid = null)
  1031. {
  1032. $notesTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE"))[0]->count;
  1033. $notesTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS TRUE"))[0]->count;
  1034. $notesTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS TRUE"))[0]->count;
  1035. $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;
  1036. $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;
  1037. $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;
  1038. $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;
  1039. $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;
  1040. $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;
  1041. $performerPro = $this->performer->pro;
  1042. $allPros = [];
  1043. if ($performerPro->pro_type == 'ADMIN') {
  1044. $allPros = Pro::all();
  1045. } else {
  1046. $allPros = [$performerPro];
  1047. }
  1048. //Patient | MCP | # Notes Total | # Notes without Billing Closed | # Notes without Claiming Closed
  1049. $patientsQuery = Client::where('is_dummy', '=', false)
  1050. ->whereNull('shadow_pro_id')
  1051. ->select('id', 'uid', 'name_first', 'name_last', 'mcp_pro_id', 'is_part_b_primary', 'medicare_advantage_plan',
  1052. DB::raw("(SELECT name_first||' '||name_last FROM pro where pro.id = client.mcp_pro_id) as mcp"),
  1053. DB::raw("(SELECT uid FROM pro where pro.id = mcp_pro_id) as mcp_pro_uid"),
  1054. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id) as notes_total"),
  1055. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_bill_closed IS NOT true) as notes_without_billing_closed"),
  1056. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_claim_closed IS NOT true) as notes_without_claiming_closed")
  1057. )->orderBy('is_part_b_primary', 'asc')->orderBy('notes_without_claiming_closed', 'desc');
  1058. if ($proUid) {
  1059. $mcpPro = Pro::where('uid', $proUid)->first();
  1060. if ($mcpPro) {
  1061. $patientsQuery->where('client.mcp_pro_id', '=', $mcpPro->id);
  1062. }
  1063. }
  1064. $patientsQuery->whereRaw('(SELECT COUNT(*) FROM note where note.client_id = client.id) > 0');
  1065. $patientsQuery->orderBy('notes_total', 'DESC');
  1066. $patients = $patientsQuery->paginate(50);
  1067. $data = [
  1068. 'patients' => $patients,
  1069. 'proUid' => $proUid,
  1070. 'allPros' => $allPros,
  1071. 'notesTotal' => $notesTotal,
  1072. 'notesTotalWithBillingClosed' => $notesTotalWithBillingClosed,
  1073. 'notesTotalWithClaimingClosed' => $notesTotalWithClaimingClosed,
  1074. 'notes3rdPartyTotal' => $notes3rdPartyTotal,
  1075. 'notes3rdPartyTotalWithBillingClosed' => $notes3rdPartyTotalWithBillingClosed,
  1076. 'notes3rdPartyTotalWithClaimingClosed' => $notes3rdPartyTotalWithClaimingClosed,
  1077. 'patientsTotal' => $patientsTotal,
  1078. 'patientsTotalWithBillingClosed' => $patientsTotalWithBillingClosed,
  1079. 'patientsTotalWithClaimingClosed' => $patientsTotalWithClaimingClosed
  1080. ];
  1081. return view('app.practice-management.patient-claim-summary', $data);
  1082. }
  1083. public function claims(Request $request){
  1084. $status = $request->get('status');
  1085. $claims = [];
  1086. if(!$status){
  1087. $claims = Claim::orderBy('created_at', 'DESC')->paginate();
  1088. }else{
  1089. $claims = Claim::where('status', $status)->orderBy('created_at', 'DESC')->paginate();
  1090. }
  1091. return view('app.practice-management.claims', compact('claims', 'status'));
  1092. }
  1093. public function processClaims(Request $request) {
  1094. $status = '';
  1095. $q = $request->input('q') ? $request->input('q') : '';
  1096. $from = $request->input('from') ? $request->input('from') : '1900-01-01';
  1097. $to = $request->input('to') ? $request->input('to') : '2100-01-01';
  1098. $params = [
  1099. 'q' => '%' . $q . '%',
  1100. 'from' => $from,
  1101. 'to' => $to
  1102. ];
  1103. $hcpPro = $request->input('hcp') ? Pro::where('uid', $request->input('hcp'))->first() : null;
  1104. if($hcpPro) {
  1105. $params['hcp'] = $hcpPro->id;
  1106. }
  1107. $claims = DB::select(DB::raw("
  1108. SELECT claim.uid AS uid,
  1109. DATE(claim.created_at) AS created,
  1110. claim.status,
  1111. client.uid AS client_uid,
  1112. client.cell_number AS client_phone,
  1113. (client.name_last || ' ' || client.name_first) AS client ,
  1114. client.chart_number AS client_chart_number,
  1115. cp.id AS claim_pro_id,
  1116. (cp.name_last || ' ' || cp.name_first) AS claim_pro,
  1117. sp.id AS status_pro_id,
  1118. (sp.name_last || ' ' || sp.name_first) AS status_pro,
  1119. note.uid AS note_uid,
  1120. note.method,
  1121. note.new_or_fu_or_na,
  1122. -- claim.status_updated_at,
  1123. (DATE(claim.status_updated_at) || ' ' ||
  1124. LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
  1125. LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) AS status_updated_at,
  1126. (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) AS cpts,
  1127. (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,
  1128. ROUND(claim.expected_total, 3) as expected_total
  1129. FROM claim
  1130. join client on claim.client_id = client.id
  1131. join pro cp on claim.pro_id = cp.id
  1132. left join note on claim.note_id = note.id
  1133. left join app_session on claim.status_updated_by_session_id = app_session.id
  1134. left join pro sp on app_session.pro_id = sp.id
  1135. --WHERE claim.status IS NULL OR claim.status = 'NEW'
  1136. WHERE (claim.status is NULL OR claim.status NOT IN ('CANCELLED', 'ABANDONED'))
  1137. -- AND claim.current_version_id IS NOT NULL
  1138. AND (client.name_first ILIKE :q OR
  1139. client.name_last ILIKE :q OR
  1140. client.chart_number ILIKE :q OR
  1141. client.mcn ILIKE :q)
  1142. AND (claim.created_at >= :from AND claim.created_at <= :to)
  1143. " . ($hcpPro ? "AND claim.pro_id = :hcp" : '') . "
  1144. AND claim.id IN (SELECT mb_claim.claim_id FROM mb_claim)
  1145. ORDER BY claim.created_at ASC
  1146. --OFFSET 0 LIMIT 15
  1147. "), $params);
  1148. if($request->input('json')) {
  1149. return json_encode($claims);
  1150. }
  1151. return view('app.practice-management.process-claims', compact('claims', 'status'));
  1152. }
  1153. public function processNotes(Request $request) {
  1154. $mode = $request->input('mode') ? $request->input('mode') : '1';
  1155. if(($mode < 1 || $mode > 5) && $mode != 8) $mode = 1;
  1156. $counts = [
  1157. "picked" => Note::where('is_cancelled', false)
  1158. ->whereNotNull('current_note_pickup_for_processing_id')
  1159. ->count(),
  1160. "bad" => Note::where('is_cancelled', false)
  1161. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1162. ->count(),
  1163. // not yet signed
  1164. "mode-1" => Note::where('is_cancelled', false)
  1165. ->where('is_signed_by_hcp', false)
  1166. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1167. // ->whereNull('current_note_pickup_for_processing_id')
  1168. ->count(),
  1169. // billing not marked done
  1170. "mode-2" => Note::where('is_cancelled', false)
  1171. ->where('is_signed_by_hcp', true)
  1172. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1173. // ->whereNull('current_note_pickup_for_processing_id')
  1174. ->where('is_billing_marked_done', false)
  1175. ->count(),
  1176. // billing not closed
  1177. "mode-3" => Note::where('is_cancelled', false)
  1178. ->where('is_signed_by_hcp', true)
  1179. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1180. // ->whereNull('current_note_pickup_for_processing_id')
  1181. ->where('is_billing_marked_done', true)
  1182. ->where('is_bill_closed', false)
  1183. ->count(),
  1184. // claiming not closed
  1185. "mode-4" => Note::where('is_cancelled', false)
  1186. ->where('is_signed_by_hcp', true)
  1187. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1188. // ->whereNull('current_note_pickup_for_processing_id')
  1189. ->where('is_billing_marked_done', true)
  1190. ->where('is_bill_closed', true)
  1191. ->where('is_claim_closed', false)
  1192. ->count(),
  1193. // has unsubmitted claims
  1194. "mode-5" => Note::where('is_cancelled', false)
  1195. ->where('is_signed_by_hcp', true)
  1196. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1197. // ->whereNull('current_note_pickup_for_processing_id')
  1198. ->where('is_billing_marked_done', true)
  1199. ->where('is_bill_closed', true)
  1200. ->where('is_claim_closed', true)
  1201. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1202. ->count(),
  1203. // has unsubmitted claims MARKED GOOD!
  1204. "mode-8" => Note::where('is_cancelled', false)
  1205. ->where('is_signed_by_hcp', true)
  1206. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1207. // ->whereNull('current_note_pickup_for_processing_id')
  1208. ->where('is_billing_marked_done', true)
  1209. ->where('is_bill_closed', true)
  1210. // ->where('is_claim_closed', true)
  1211. // ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1212. ->count(),
  1213. // all good
  1214. "mode-6" => Note::where('is_cancelled', false)
  1215. ->where('is_signed_by_hcp', true)
  1216. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1217. // ->whereNull('current_note_pickup_for_processing_id')
  1218. ->where('is_billing_marked_done', true)
  1219. ->where('is_bill_closed', true)
  1220. ->where('is_claim_closed', true)
  1221. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id) > 0")
  1222. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0")
  1223. ->count(),
  1224. "mode-7" => Note::where('is_cancelled', false)
  1225. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1226. ->count(),
  1227. ];
  1228. return view('app.practice-management.process-notes', compact('mode', 'counts'));
  1229. }
  1230. public function getNextNote(Request $request, $mode)
  1231. {
  1232. $note = null;
  1233. switch (+$mode) {
  1234. case 1:
  1235. $note = Note::where('is_cancelled', false)
  1236. ->where('is_signed_by_hcp', false)
  1237. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1238. ->whereNull('current_note_pickup_for_processing_id')
  1239. ->orderBy('effective_dateest', 'DESC')
  1240. ->first();
  1241. break;
  1242. case 2:
  1243. $note = Note::where('is_cancelled', false)
  1244. ->where('is_signed_by_hcp', true)
  1245. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1246. ->whereNull('current_note_pickup_for_processing_id')
  1247. ->where('is_billing_marked_done', false)
  1248. ->orderBy('effective_dateest', 'DESC')
  1249. ->first();
  1250. break;
  1251. case 3:
  1252. $note = Note::where('is_cancelled', false)
  1253. ->where('is_signed_by_hcp', true)
  1254. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1255. ->whereNull('current_note_pickup_for_processing_id')
  1256. ->where('is_billing_marked_done', true)
  1257. ->where('is_bill_closed', false)
  1258. ->orderBy('effective_dateest', 'DESC')
  1259. ->first();
  1260. break;
  1261. case 4:
  1262. $note = Note::where('is_cancelled', false)
  1263. ->where('is_signed_by_hcp', true)
  1264. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1265. ->whereNull('current_note_pickup_for_processing_id')
  1266. ->where('is_billing_marked_done', true)
  1267. ->where('is_bill_closed', true)
  1268. ->where('is_claim_closed', false)
  1269. ->orderBy('effective_dateest', 'DESC')
  1270. ->first();
  1271. break;
  1272. case 5:
  1273. $note = Note::where('is_cancelled', false)
  1274. ->where('is_signed_by_hcp', true)
  1275. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1276. ->whereNull('current_note_pickup_for_processing_id')
  1277. ->where('is_billing_marked_done', true)
  1278. ->where('is_bill_closed', true)
  1279. ->where('is_claim_closed', true)
  1280. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1281. ->orderBy('effective_dateest', 'DESC')
  1282. ->first();
  1283. break;
  1284. case 8:
  1285. $note = Note::where('is_cancelled', false)
  1286. ->where('is_signed_by_hcp', true)
  1287. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1288. // ->whereNull('current_note_pickup_for_processing_id')
  1289. ->where('is_billing_marked_done', true)
  1290. ->where('is_bill_closed', true)
  1291. // ->where('is_claim_closed', true)
  1292. // ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1293. ->orderBy('effective_dateest', 'DESC')
  1294. ->first();
  1295. break;
  1296. }
  1297. if($note) {
  1298. $note->client_uid = $note->client->uid;
  1299. }
  1300. return json_encode($note);
  1301. }
  1302. public function pickedNotes(Request $request) {
  1303. $counts = [
  1304. "unpicked" => Note::where('is_cancelled', false)
  1305. ->whereNull('current_note_pickup_for_processing_id')
  1306. ->count(),
  1307. ];
  1308. $notes = Note::where('is_cancelled', false)
  1309. ->whereNotNull('current_note_pickup_for_processing_id')
  1310. ->orderBy('effective_dateest', 'ASC')
  1311. ->paginate();
  1312. return view('app.practice-management.picked-notes', compact('counts', 'notes'));
  1313. }
  1314. public function badNotes(Request $request) {
  1315. $counts = [
  1316. "unpicked" => Note::where('is_cancelled', false)
  1317. ->whereNull('current_note_pickup_for_processing_id')
  1318. ->count(),
  1319. ];
  1320. $notes = Note::where('is_cancelled', false)
  1321. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1322. ->orderBy('effective_dateest', 'ASC')
  1323. ->paginate();
  1324. return view('app.practice-management.bad-notes', compact('counts', 'notes'));
  1325. }
  1326. public function doneNotes(Request $request) {
  1327. $counts = [
  1328. "unpicked" => Note::where('is_cancelled', false)
  1329. ->whereNull('current_note_pickup_for_processing_id')
  1330. ->count(),
  1331. ];
  1332. $notes = Note::where('is_cancelled', false)
  1333. ->where('is_signed_by_hcp', true)
  1334. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1335. ->whereNull('current_note_pickup_for_processing_id')
  1336. ->where('is_billing_marked_done', true)
  1337. ->where('is_bill_closed', true)
  1338. ->where('is_claim_closed', true)
  1339. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id) > 0")
  1340. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0")
  1341. ->orderBy('effective_dateest', 'ASC')
  1342. ->paginate();
  1343. return view('app.practice-management.done-notes', compact('counts', 'notes'));
  1344. }
  1345. public function currentMbClaim(Request $request, $claimUid) {
  1346. $claim = Claim::where('uid', $claimUid)->first();
  1347. return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->first());
  1348. }
  1349. public function currentClaimLines(Request $request, $claimUid) {
  1350. $claim = Claim::where('uid', $claimUid)->first();
  1351. if($request->input('json')) {
  1352. foreach ($claim->lines as $line) {
  1353. $line->expected_total = round($line->expected_total, 3);
  1354. $x = $line->claimLineIcds;
  1355. }
  1356. return json_encode($claim->lines);
  1357. }
  1358. return view('app.practice-management._claim-lines', compact('claim'));
  1359. }
  1360. public function packsMultiPrint(Request $request) {
  1361. $packs = Pack
  1362. ::select('pack.*')
  1363. ->leftJoin('shipment', function($join) {
  1364. $join->on('pack.shipment_id', '=', 'shipment.id');
  1365. })
  1366. ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
  1367. ->where(function ($query) {
  1368. $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
  1369. })
  1370. ->whereNotNull('pack.label_system_file_id')
  1371. ->orderBy('pack.created_at', 'ASC')
  1372. ->get();
  1373. return view('app.practice-management.packs-multi-print', compact('packs'));
  1374. }
  1375. public function packsMultiPDF(Request $request, $ids) {
  1376. $ids = array_map(function ($_x) {
  1377. return intval($_x);
  1378. }, explode("|", $ids));
  1379. $packs = Pack::whereIn('id', $ids)->get();
  1380. }
  1381. public function handouts(Request $request) {
  1382. $handouts = Handout::orderBy('display_name')->get();
  1383. return view('app.practice-management.handouts', compact('handouts'));
  1384. }
  1385. private function callJava($request, $endPoint, $data)
  1386. {
  1387. $url = config('stag.backendUrl') . $endPoint;
  1388. $response = Http::asForm()
  1389. ->withHeaders([
  1390. 'sessionKey' => $request->cookie('sessionKey')
  1391. ])
  1392. ->post($url, $data)
  1393. ->body();
  1394. dd($response);
  1395. return $response;
  1396. }
  1397. public function genericBills(Request $request)
  1398. {
  1399. return view('app.practice-management.generic-bills');
  1400. }
  1401. }