PracticeManagementController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\BillingReport;
  5. use App\Models\ClaimEDI;
  6. use App\Models\Handout;
  7. use App\Models\MBClaim;
  8. use App\Models\Measurement;
  9. use App\Models\Bill;
  10. use App\Models\Claim;
  11. use App\Models\Client;
  12. use App\Models\McpRequest;
  13. use App\Models\Note;
  14. use App\Models\Pack;
  15. use App\Models\Pro;
  16. use App\Models\Product;
  17. use App\Models\ProFavorite;
  18. use App\Models\ProGeneralAvailability;
  19. use App\Models\ProProAccess;
  20. use App\Models\ProRate;
  21. use App\Models\ProSpecificAvailability;
  22. use App\Models\ProSpecificUnavailability;
  23. use App\Models\ProTextShortcut;
  24. use App\Models\ProTransaction;
  25. use App\Models\Shipment;
  26. use App\Models\SupplyOrder;
  27. use App\Models\Ticket;
  28. use App\Models\ClientMeasurementDaysPerMonth;
  29. use Illuminate\Support\Facades\DB;
  30. use Illuminate\Support\Facades\Http;
  31. use PDF;
  32. use DateTime;
  33. use DateTimeZone;
  34. use Illuminate\Http\Request;
  35. class PracticeManagementController extends Controller
  36. {
  37. public function remoteMonitoringReport(Request $request)
  38. {
  39. $rows = null;
  40. $proID = $this->performer()->pro->id;
  41. $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
  42. $rows = $isAdmin ? ClientMeasurementDaysPerMonth::all() : ClientMeasurementDaysPerMonth::where('mcp_pro_id', $proID)->orderBy('year_month', 'asc')->orderBy('num_of_days_with_measurement', 'asc')->get();
  43. return view ('app.practice-management.remote-monitoring-report', compact('rows'));
  44. }
  45. public function billingReport(Request $request)
  46. {
  47. $rows = BillingReport::paginate(50);
  48. return view('app.practice-management.billing-report', compact('rows'));
  49. }
  50. public function dashboard(Request $request)
  51. {
  52. return view('app.practice-management.dashboard');
  53. }
  54. public function rates(Request $request, $selectedProUid = 'all')
  55. {
  56. $proUid = $selectedProUid ? $selectedProUid : 'all';
  57. $rates = ProRate::where('is_active', true);
  58. if ($proUid !== 'all') {
  59. $selectedPro = Pro::where('uid', $proUid)->first();
  60. $rates = $rates->where('pro_id', $selectedPro->id);
  61. }
  62. $rates = $rates->orderBy('pro_id', 'asc')->get();
  63. $pros = $this->pros;
  64. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  65. }
  66. public function previousBills(Request $request)
  67. {
  68. return view('app.practice-management.previous-bills');
  69. }
  70. public function financialTransactions(Request $request)
  71. {
  72. $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
  73. return view('app.practice-management.financial-transactions', compact('transactions'));
  74. }
  75. public function pendingBillsToSign(Request $request)
  76. {
  77. return view('app.practice-management.pending-bills-to-sign');
  78. }
  79. public function HR(Request $request)
  80. {
  81. return view('app.practice-management.hr');
  82. }
  83. public function directDepositSettings(Request $request)
  84. {
  85. return view('app.practice-management.direct-deposit-settings');
  86. }
  87. public function w9(Request $request)
  88. {
  89. return view('app.practice-management.w9');
  90. }
  91. public function contract(Request $request)
  92. {
  93. return view('app.practice-management.contract');
  94. }
  95. public function notes(Request $request, $filter = '')
  96. {
  97. $proID = $this->performer()->pro->id;
  98. $query = Note::where('hcp_pro_id', $proID);
  99. switch ($filter) {
  100. case 'not-yet-signed':
  101. $query = $query->where('is_signed_by_hcp', false);
  102. break;
  103. // more cases can be added as needed
  104. default:
  105. break;
  106. }
  107. $notes = $query->orderBy('created_at', 'desc')->get();
  108. return view('app.practice-management.notes', compact('notes', 'filter'));
  109. }
  110. public function bills(Request $request, $filter = '')
  111. {
  112. $proID = $this->performer()->pro->id;
  113. $query = Bill::where('is_cancelled', false);
  114. switch ($filter) {
  115. case 'not-yet-signed':
  116. $query = $query
  117. ->where(function ($q) use ($proID) {
  118. $q->where(function ($q2) use ($proID) {
  119. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  120. })
  121. ->orWhere(function ($q2) use ($proID) {
  122. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  123. })
  124. ->orWhere(function ($q2) use ($proID) {
  125. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  126. })
  127. ->orWhere(function ($q2) use ($proID) {
  128. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  129. });
  130. });
  131. break;
  132. case 'previous':
  133. $query = $query
  134. ->where(function ($q) use ($proID) {
  135. $q->where(function ($q2) use ($proID) {
  136. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  137. })
  138. ->orWhere(function ($q2) use ($proID) {
  139. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  140. })
  141. ->orWhere(function ($q2) use ($proID) {
  142. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  143. })
  144. ->orWhere(function ($q2) use ($proID) {
  145. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  146. });
  147. });
  148. break;
  149. // more cases can be added as needed
  150. default:
  151. break;
  152. }
  153. $bills = $query->orderBy('created_at', 'desc')->get();
  154. return view('app.practice-management.bills', compact('bills', 'filter'));
  155. }
  156. public function unacknowledgedCancelledBills(Request $request)
  157. {
  158. $bills = Bill::where('hcp_pro_id', $this->performer()->pro->id)
  159. ->where('is_cancelled', true)
  160. ->where('is_cancellation_acknowledged', false)
  161. ->orderBy('created_at', 'desc')
  162. ->get();
  163. return view('app.practice-management.unacknowledged-cancelled-bills', compact('bills'));
  164. }
  165. public function myTickets(Request $request, $filter = 'open')
  166. {
  167. $performer = $this->performer();
  168. $myTickets = Ticket::where(function ($q) use ($performer) {
  169. $q->where('assigned_pro_id', $performer->pro_id)
  170. ->orWhere('manager_pro_id', $performer->pro_id)
  171. ->orWhere('ordering_pro_id', $performer->pro_id)
  172. ->orWhere('initiating_pro_id', $performer->pro_id);
  173. });
  174. if ($filter === 'open') {
  175. $myTickets = $myTickets->where('is_open', true);
  176. } else if ($filter === 'closed') {
  177. $myTickets = $myTickets->where('is_open', false);
  178. }
  179. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  180. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  181. }
  182. public function myTextShortcuts(Request $request)
  183. {
  184. $myTextShortcuts = DB::table('pro_text_shortcut')
  185. ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
  186. ->select(
  187. 'pro_text_shortcut.uid',
  188. 'pro_text_shortcut.shortcut',
  189. 'pro_text_shortcut.text',
  190. 'pro.name_first',
  191. 'pro.name_last'
  192. )
  193. ->where('pro_text_shortcut.is_removed', false);
  194. if($this->performer()->pro->pro_type !== 'ADMIN') {
  195. $myTextShortcuts = $myTextShortcuts->where('pro_id', $this->performer()->pro_id);
  196. }
  197. $myTextShortcuts = $myTextShortcuts
  198. ->orderBy('pro.name_last')
  199. ->orderBy('pro.name_first')
  200. ->get();
  201. return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
  202. }
  203. public function myFavorites(Request $request, $filter = 'all')
  204. {
  205. $performer = $this->performer();
  206. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  207. ->where('is_removed', false);
  208. if ($filter !== 'all') {
  209. $myFavorites = $myFavorites->where('category', $filter);
  210. }
  211. $myFavorites = $myFavorites
  212. ->orderBy('category', 'asc')
  213. ->orderBy('position_index', 'asc')
  214. ->get();
  215. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  216. }
  217. public function proAvailability(Request $request, $proUid = null)
  218. {
  219. $performer = $this->performer();
  220. $pro = $performer->pro;
  221. if ($proUid) {
  222. $pro = Pro::where('uid', $proUid)->first();
  223. }
  224. if ($request->get('pro_uid')) {
  225. $proUid = $request->get('pro_uid');
  226. $pro = Pro::where('uid', $proUid)->first();
  227. }
  228. $selectedProUid = $pro->uid;
  229. $pros = $this->pros;
  230. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  231. $generalAvailabilities = [
  232. 'MONDAY' => [],
  233. 'TUESDAY' => [],
  234. 'WEDNESDAY' => [],
  235. 'THURSDAY' => [],
  236. 'FRIDAY' => [],
  237. 'SATURDAY' => [],
  238. 'SUNDAY' => [],
  239. ];
  240. foreach ($generalAvailabilitiesList as $ga) {
  241. if ($ga->day_of_week == 'MONDAY') {
  242. $generalAvailabilities['MONDAY'][] = $ga;
  243. }
  244. if ($ga->day_of_week == 'TUESDAY') {
  245. $generalAvailabilities['TUESDAY'][] = $ga;
  246. }
  247. if ($ga->day_of_week == 'WEDNESDAY') {
  248. $generalAvailabilities['WEDNESDAY'][] = $ga;
  249. }
  250. if ($ga->day_of_week == 'THURSDAY') {
  251. $generalAvailabilities['THURSDAY'][] = $ga;
  252. }
  253. if ($ga->day_of_week == 'FRIDAY') {
  254. $generalAvailabilities['FRIDAY'][] = $ga;
  255. }
  256. if ($ga->day_of_week == 'SATURDAY') {
  257. $generalAvailabilities['SATURDAY'][] = $ga;
  258. }
  259. if ($ga->day_of_week == 'SUNDAY') {
  260. $generalAvailabilities['SUNDAY'][] = $ga;
  261. }
  262. }
  263. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  264. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  265. //events for the calendar
  266. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  267. $endDateTime = new DateTime($startDate);
  268. $endDateTime->modify('+6 day');
  269. $endDate = $endDateTime->format("Y-m-d");
  270. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  271. $events = json_encode($eventsData);
  272. return view(
  273. 'app.practice-management.pro-availability',
  274. compact(
  275. 'pros',
  276. 'generalAvailabilities',
  277. 'specificAvailabilities',
  278. 'specificUnavailabilities',
  279. 'events',
  280. 'selectedProUid'
  281. )
  282. );
  283. }
  284. public function loadAvailability(Request $request, $proUid)
  285. {
  286. $performer = $this->performer();
  287. $pro = $performer->pro;
  288. $startDate = $request->get('start');
  289. $endDate = $request->get('end');
  290. $selectedPro = Pro::where('uid', $proUid)->first();
  291. return $selectedPro->getAvailabilityEvents($startDate, $endDate);
  292. }
  293. public function proAvailabilityFilter(Request $request)
  294. {
  295. $proUid = $request->get('proUid');
  296. return ['success' => true, 'data' => $proUid];
  297. }
  298. // video call page (RHS)
  299. // generic call handle (no uid)
  300. // specific call handle (uid of client)
  301. public function meet(Request $request, $uid = false)
  302. {
  303. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  304. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  305. if (!empty($client)) {
  306. return view('app.video.call-minimal', compact('session', 'client'));
  307. }
  308. return view('app.video.call-agora-v2', compact('session', 'client'));
  309. }
  310. // check video page
  311. public function checkVideo(Request $request, $uid)
  312. {
  313. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  314. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  315. $publish = false;
  316. return view('app.video.check-video-minimal', compact('session', 'client'));
  317. }
  318. public function getParticipantInfo(Request $request)
  319. {
  320. $sid = intval($request->get('uid')) - 1000000;
  321. $session = AppSession::where('id', $sid)->first();
  322. $result = [
  323. "type" => '',
  324. "name" => ''
  325. ];
  326. if ($session) {
  327. $result["type"] = $session->session_type;
  328. switch ($session->session_type) {
  329. case 'PRO':
  330. $pro = Pro::where('id', $session->pro_id)->first();
  331. $result["name"] = $pro->displayName();
  332. break;
  333. case 'CLIENT':
  334. $client = Client::where('id', $session->client_id)->first();
  335. $result["name"] = $client->displayName();
  336. break;
  337. }
  338. }
  339. return json_encode($result);
  340. }
  341. // ajax ep used by the video page
  342. // this is needed bcoz meet() is used not
  343. // just for the client passed to the view
  344. public function getOpentokSessionKey(Request $request, $uid)
  345. {
  346. $client = Client::where('uid', $uid)->first();
  347. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  348. }
  349. // poll to check if there are patients with active mcp requests
  350. public function getPatientsInQueue(Request $request)
  351. {
  352. $myInitiatives = $this->performer->pro->initiatives;
  353. if ($myInitiatives) {
  354. $myInitiatives = strtoupper($myInitiatives);
  355. }
  356. $myInitiativesList = explode('|', $myInitiatives);
  357. $myForeignLanguages = $this->performer->pro->foreign_languages;
  358. if ($myForeignLanguages) {
  359. $myForeignLanguages = strtoupper($myForeignLanguages);
  360. }
  361. $myForeignLanguagesList = explode('|', $myForeignLanguages);
  362. $clients = Client::whereNotNull('active_mcp_request_id')->where(function ($query) use ($myInitiativesList) {
  363. $query->whereNull('initiative')->orWhereIn('initiative', $myInitiativesList);
  364. })
  365. ->where(function ($query) use ($myForeignLanguagesList) {
  366. $query->whereNull('preferred_foreign_language')->orWhereIn('preferred_foreign_language', $myForeignLanguagesList);
  367. })->limit(3)->get();
  368. $results = [];
  369. foreach ($clients as $client) {
  370. $results[] = [
  371. 'clientUid' => $client->uid,
  372. 'name' => $client->displayName(),
  373. 'initials' => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  374. ];
  375. }
  376. return json_encode($results);
  377. }
  378. public function currentWork(Request $request)
  379. {
  380. return view('app/current-work');
  381. }
  382. public function calendar(Request $request, $proUid = null)
  383. {
  384. $pros = Pro::all();
  385. if ($this->pro && $this->pro->pro_type != 'ADMIN') {
  386. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
  387. $accessibleProIds = [];
  388. foreach ($accessiblePros as $accessiblePro) {
  389. $accessibleProIds[] = $accessiblePro->id;
  390. }
  391. $accessibleProIds[] = $this->pro->id;
  392. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  393. }
  394. return view('app.practice-management.calendar', compact('pros'));
  395. }
  396. public function cellularDeviceManager(Request $request, $proUid = null)
  397. {
  398. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  399. $performerPro = $this->performer->pro;
  400. $targetPro = null;
  401. $allPros = [];
  402. $expectedForHcp = null;
  403. if ($performerPro->pro_type == 'ADMIN') {
  404. $allPros = Pro::all();
  405. $targetPro = Pro::where('uid', $proUid)->first();
  406. } else {
  407. $targetPro = $performerPro;
  408. }
  409. $clients = [];
  410. if ($targetPro) {
  411. $clients = Client::where('mcp_pro_id', $targetPro->id)->orderBy('created_at', 'desc')->paginate(100);
  412. } else {
  413. $clients = Client::orderBy('created_at', 'desc')->paginate(100);
  414. }
  415. return view('app.practice-management.cellular-device-manager', compact('clients', 'allPros', 'targetPro', 'proUid'));
  416. }
  417. public function treatmentServiceUtil(Request $request)
  418. {
  419. $view_treatment_service_utilization_org = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_org ORDER BY effective_date DESC"));
  420. $view_treatment_service_utilization = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization ORDER BY effective_date DESC, total_hrs DESC"));
  421. $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"));
  422. return view('app.practice-management.treatment-services-util', compact(
  423. 'view_treatment_service_utilization_org',
  424. 'view_treatment_service_utilization',
  425. 'view_treatment_service_utilization_by_patient'));
  426. }
  427. public function processingBillMatrix(Request $request, $proUid = null)
  428. {
  429. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  430. $performerPro = $this->performer->pro;
  431. $targetPro = null;
  432. $allPros = [];
  433. if ($performerPro->pro_type == 'ADMIN') {
  434. $allPros = Pro::all();
  435. $targetPro = Pro::where('uid', $proUid)->first();
  436. } else {
  437. $targetPro = $performerPro;
  438. }
  439. $bills = [];
  440. if ($targetPro) {
  441. $bills = Bill::where('hcp_pro_id', $targetPro->id)->
  442. where('has_hcp_been_paid', false)->
  443. where('is_cancelled', false)->
  444. where('is_signed_by_hcp', true)->
  445. orderBy('effective_date', 'desc')->paginate();
  446. } else {
  447. $bills = Bill::where('has_hcp_been_paid', false)->
  448. where('is_cancelled', false)->
  449. where('is_signed_by_hcp', true)->
  450. orderBy('effective_date', 'desc')->
  451. paginate();
  452. }
  453. $viewData = [
  454. 'bills' => $bills,
  455. 'allPros' => $allPros,
  456. 'targetPro' => $targetPro,
  457. 'performerPro' => $performerPro,
  458. 'proUid' => $proUid
  459. ];
  460. return view('app.practice-management.processing-bill-matrix', $viewData);
  461. }
  462. public function hcpBillMatrix(Request $request, $proUid = null)
  463. {
  464. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  465. $performerPro = $this->performer->pro;
  466. $targetPro = null;
  467. $allPros = [];
  468. $expectedForHcp = null;
  469. if ($performerPro->pro_type == 'ADMIN') {
  470. $allPros = Pro::all();
  471. $targetPro = Pro::where('uid', $proUid)->first();
  472. } else {
  473. $targetPro = $performerPro;
  474. }
  475. $rows = [];
  476. if ($targetPro) {
  477. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report WHERE hcp_pro_id = :targetProID"), ['targetProID' => $targetPro->id]);
  478. } else {
  479. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report"));
  480. }
  481. return view('app.practice-management.hcp-bill-matrix', compact('rows', 'allPros', 'expectedForHcp', 'targetPro', 'proUid'));
  482. }
  483. public function billingManager(Request $request, $proUid = null)
  484. {
  485. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  486. $performerPro = $this->performer->pro;
  487. $targetPro = null;
  488. $allPros = [];
  489. $expectedForHcp = null;
  490. if ($performerPro->pro_type == 'ADMIN') {
  491. $allPros = Pro::all();
  492. $targetPro = Pro::where('uid', $proUid)->first();
  493. } else {
  494. $targetPro = $performerPro;
  495. }
  496. $notes = [];
  497. if ($targetPro) {
  498. $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;
  499. $notes = Note::where('hcp_pro_id', $targetPro->id);
  500. } else {
  501. $notes = Note::where('id', '>', 0);
  502. }
  503. if($request->input('date')) {
  504. $notes = $notes->where('effective_dateest', $request->input('date'));
  505. }
  506. $filters = [];
  507. $filters['bills_created'] = $request->input('bills_created');
  508. $filters['is_billing_marked_done'] = $request->input('is_billing_marked_done');
  509. $filters['bills_resolved'] = $request->input('bills_resolved');
  510. $filters['bills_closed'] = $request->input('bills_closed');
  511. $filters['claims_created'] = $request->input('claims_created');
  512. $filters['claims_closed'] = $request->input('claims_closed');
  513. if ($filters['bills_created']) {
  514. $notes->where(
  515. 'bill_total_expected',
  516. ($filters['bills_created'] === 'yes' ? '>' : '<='),
  517. 0);
  518. }
  519. if ($filters['is_billing_marked_done']) {
  520. $notes->where(
  521. 'is_billing_marked_done',
  522. ($filters['is_billing_marked_done'] === 'yes' ? '=' : '!='),
  523. true);
  524. }
  525. if ($filters['bills_resolved']) {
  526. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id) > 0'); // have bills
  527. if ($filters['bills_resolved'] === 'yes') {
  528. $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');
  529. } elseif ($filters['bills_resolved'] === 'no') {
  530. $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');
  531. }
  532. }
  533. if ($filters['bills_closed']) {
  534. $notes->where(
  535. 'is_bill_closed',
  536. ($filters['bills_closed'] === 'yes' ? '=' : '!='),
  537. true);
  538. }
  539. if ($filters['claims_created']) {
  540. $notes->where(
  541. 'claim_total_expected',
  542. ($filters['claims_created'] === 'yes' ? '>' : '<='),
  543. 0);
  544. }
  545. if ($filters['claims_closed']) {
  546. $notes->where(
  547. 'is_claim_closed',
  548. ($filters['claims_closed'] === 'yes' ? '=' : '!='),
  549. true);
  550. }
  551. $notes = $notes->orderBy('effective_dateest', 'desc')->paginate(10);
  552. return view('app.practice-management.billing-manager', compact('notes', 'allPros', 'expectedForHcp', 'targetPro', 'proUid', 'filters'));
  553. }
  554. public function billMatrix(Request $request)
  555. {
  556. $bClients = [];
  557. $bHCPPros = [];
  558. $bNAPros = [];
  559. $filters = [];
  560. $filters['client'] = $request->input('client');
  561. $filters['service'] = $request->input('service');
  562. $filters['hcp'] = $request->input('hcp');
  563. $filters['hcp_paid'] = $request->input('hcp_paid');
  564. $filters['expected_op'] = $request->input('expected_op');
  565. $filters['expected_value'] = $request->input('expected_value');
  566. $filters['paid_op'] = $request->input('paid_op');
  567. $filters['paid_value'] = $request->input('paid_value');
  568. $filters['bal_post_date_op'] = $request->input('bal_post_date_op');
  569. $filters['bal_post_date_value'] = $request->input('bal_post_date_value');
  570. $filters['hcp_sign'] = $request->input('hcp_sign');
  571. $filters['verified'] = $request->input('verified');
  572. $filters['cancelled'] = $request->input('cancelled');
  573. $bills = Bill::orderBy('effective_date')->paginate();
  574. return view('app.practice-management.bill-matrix', compact('bills', 'bClients', 'bHCPPros', 'filters'));
  575. }
  576. public function medicarePartBClaims(Request $request)
  577. {
  578. $medicarePartBOnly = $request->get("medicare_part_b");
  579. $allClaims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->get();
  580. //Only medicare claims
  581. $claims = [];
  582. foreach ($allClaims as $claim) {
  583. if ($claim->client != null && $claim->client->is_part_b_primary == 'YES' && !$claim->edi) {
  584. $claims[] = $claim;
  585. }
  586. }
  587. $claimEDIs = ClaimEDI::all();
  588. return view('app.practice-management.medicare-partb-claims', compact('claims', 'claimEDIs'));
  589. }
  590. // Generate PDF
  591. public function downloadClaims()
  592. {
  593. $claims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->limit(100)->get();
  594. view()->share('claims', $claims);
  595. $pdf = PDF::loadView('app.practice-management.claims-pdf', $claims);
  596. return $pdf->download('pdf_file.pdf');
  597. }
  598. public function tickets(Request $request, $proUid = null)
  599. {
  600. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  601. return view('app.practice-management.tickets', compact('tickets'));
  602. }
  603. public function supplyOrders(Request $request)
  604. {
  605. // counts
  606. $counts = $this->getSupplyOrderCounts();
  607. // so clients
  608. $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
  609. $soClientIDs = array_map(function ($_x) {
  610. return $_x->client_id;
  611. }, $soClientIDs);
  612. $soClients = Client::whereIn('id', $soClientIDs)->get();
  613. // so products
  614. $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
  615. $soProductIDs = array_map(function ($_x) {
  616. return $_x->product_id;
  617. }, $soProductIDs);
  618. $soProducts = Product::whereIn('id', $soProductIDs)->get();
  619. $filters = [];
  620. $filters['client'] = $request->input('client');
  621. $filters['product'] = $request->input('product');
  622. $filters['reason'] = $request->input('reason');
  623. $filters['cu_memo'] = $request->input('cu_memo');
  624. $filters['pro_sign'] = $request->input('pro_sign');
  625. $filters['client_sign'] = $request->input('client_sign');
  626. $filters['shipment'] = $request->input('shipment');
  627. $filters['lot_number'] = $request->input('lot_number');
  628. $filters['imei'] = $request->input('imei');
  629. $filters['cancelled'] = $request->input('cancelled');
  630. $supplyOrders = SupplyOrder::where('id', '>', 0);
  631. // apply filters
  632. if ($filters['client']) $supplyOrders->where('client_id', $filters['client']);
  633. if ($filters['product']) $supplyOrders->where('product_id', $filters['product']);
  634. if ($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
  635. if ($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
  636. if ($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
  637. if ($filters['client_sign']) {
  638. if ($filters['client_sign'] === 'signed')
  639. $supplyOrders->where('is_signed_by_client', true);
  640. elseif ($filters['client_sign'] === 'waived')
  641. $supplyOrders->where('is_client_signature_waived', true);
  642. else
  643. $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
  644. }
  645. if ($filters['shipment']) {
  646. if ($filters['shipment'] === 'not_cleared_for_shipment')
  647. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', false);
  648. elseif ($filters['shipment'] === 'cleared_for_shipment')
  649. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', true);
  650. else
  651. $supplyOrders
  652. ->whereNotNull('shipment_id')
  653. ->whereRaw('(SELECT status FROM shipment WHERE id = shipment_id LIMIT 1) = ?', [$filters['shipment']]);
  654. }
  655. if ($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
  656. if ($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
  657. if ($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  658. $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
  659. return view('app.practice-management.supply-orders',
  660. compact('supplyOrders', 'filters',
  661. 'soClients', 'soProducts', 'counts'
  662. )
  663. );
  664. }
  665. public function shipments(Request $request, $filter = null)
  666. {
  667. // counts
  668. $counts = $this->getShipmentCounts();
  669. // so clients
  670. $shClientIDs = DB::table('shipment')->select('client_id')->distinct()->get()->toArray();
  671. $shClientIDs = array_map(function ($_x) {
  672. return $_x->client_id;
  673. }, $shClientIDs);
  674. $shClients = Client::whereIn('id', $shClientIDs)->get();
  675. $shipments = Shipment::where('id', '>', 0);
  676. $filters = [];
  677. $filters['client'] = $request->input('client');
  678. $filters['courier'] = $request->input('courier');
  679. $filters['tracking_num'] = $request->input('tracking_num');
  680. $filters['label'] = $request->input('label');
  681. $filters['status'] = $request->input('status');
  682. $filters['cancelled'] = $request->input('cancelled');
  683. if ($filters['client']) $shipments->where('client_id', $filters['client']);
  684. if ($filters['courier']) $shipments->where('courier', 'ILIKE', '%' . $filters['courier'] . '%');
  685. if ($filters['tracking_num']) $shipments->where('tracking_number', 'ILIKE', '%' . $filters['tracking_num'] . '%');
  686. if ($filters['label']) {
  687. if ($filters['label'] === 'yes')
  688. $shipments->whereNotNull('label_system_file_id');
  689. else
  690. $shipments->whereNull('label_system_file_id');
  691. }
  692. if ($filters['status']) $shipments->where('status', $filters['status']);
  693. if ($filters['cancelled']) $shipments->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  694. $shipments = $shipments->orderBy('created_at', 'desc')->paginate();
  695. return view('app.practice-management.shipments', compact('shipments', 'filters', 'shClients', 'counts'));
  696. }
  697. public function cellularMeasurements(Request $request)
  698. {
  699. $measurements = Measurement::orderBy('ts', 'desc')->whereNotNull('ts')->paginate();
  700. return view('app.practice-management.cellular-measurements', compact('measurements'));
  701. }
  702. // v2 supply-orders & shipments management (wh)
  703. public function supplyOrdersReadyToShip(Request $request)
  704. {
  705. $counts = $this->getSupplyOrderCounts();
  706. $supplyOrders = SupplyOrder
  707. ::where('is_cleared_for_shipment', true)
  708. ->where('is_cancelled', false)
  709. ->whereNull('shipment_id')
  710. ->join('client', 'client.id', '=', 'supply_order.client_id')
  711. ->orderBy('client.name_last', 'ASC')
  712. ->orderBy('client.name_first', 'ASC')
  713. ->orderBy('supply_order.client_id', 'ASC')
  714. ->orderBy('supply_order.mailing_address_full', 'ASC')
  715. ->orderBy('supply_order.created_at', 'ASC')
  716. ->select('supply_order.*')
  717. ->paginate();
  718. return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
  719. }
  720. public function supplyOrdersShipmentUnderway(Request $request)
  721. {
  722. $counts = $this->getSupplyOrderCounts();
  723. $supplyOrders = SupplyOrder
  724. ::where('is_cancelled', false)
  725. ->whereNotNull('shipment_id')
  726. ->orderBy('client_id', 'ASC')
  727. ->orderBy('mailing_address_full', 'ASC')
  728. ->orderBy('created_at', 'ASC')
  729. ->paginate();
  730. return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
  731. }
  732. public function supplyOrdersHanging(Request $request)
  733. {
  734. $counts = $this->getSupplyOrderCounts();
  735. $supplyOrders = SupplyOrder
  736. ::select('supply_order.*')
  737. ->leftJoin('shipment', function($join) {
  738. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  739. })
  740. ->where('shipment.status', 'CANCELLED')
  741. ->where('supply_order.is_cancelled', false)
  742. ->orderBy('supply_order.client_id', 'ASC')
  743. ->orderBy('supply_order.mailing_address_full', 'ASC')
  744. ->orderBy('supply_order.created_at', 'ASC')
  745. ->paginate();
  746. return view('app.practice-management.supply-orders-hanging', compact('supplyOrders', 'counts'));
  747. }
  748. public function supplyOrdersCancelledButUnacknowledged(Request $request)
  749. {
  750. $supplyOrders = SupplyOrder::where('signed_by_pro_id', $this->performer()->pro->id)
  751. ->where('is_cancelled', true)
  752. ->where('is_cancellation_acknowledged', false)
  753. ->orderBy('created_at', 'desc')
  754. ->paginate();
  755. return view('app.practice-management.supply-orders-cancelled-but-unacknowledged', compact('supplyOrders'));
  756. }
  757. public function supplyOrdersUnsigned(Request $request)
  758. {
  759. $supplyOrders = SupplyOrder
  760. ::where('is_cancelled', false)
  761. ->where('is_signed_by_pro', false)
  762. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$this->performer()->pro->id])
  763. ->orderBy('created_at', 'desc')
  764. ->paginate();
  765. return view('app.practice-management.supply-orders-unsigned', compact('supplyOrders'));
  766. }
  767. private function getSupplyOrderCounts()
  768. {
  769. return [
  770. "supplyOrders" => SupplyOrder::count(),
  771. "supplyOrdersReadyToShip" => SupplyOrder
  772. ::where('is_cleared_for_shipment', true)
  773. ->where('is_cancelled', false)
  774. ->whereNull('shipment_id')->count(),
  775. "supplyOrdersShipmentUnderway" => SupplyOrder
  776. ::where('is_cancelled', false)
  777. ->whereNotNull('shipment_id')->count(),
  778. "supplyOrdersHanging" => SupplyOrder
  779. ::leftJoin('shipment', function($join) {
  780. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  781. })
  782. ->where('shipment.status', 'CANCELLED')
  783. ->where('supply_order.is_cancelled', false)
  784. ->count(),
  785. ];
  786. }
  787. public function shipmentsReadyToPrint(Request $request)
  788. {
  789. $counts = $this->getShipmentCounts();
  790. $shipments = Shipment
  791. ::where('is_cancelled', false)
  792. ->where('status', 'CREATED')
  793. ->orderBy('created_at', 'ASC')
  794. ->paginate();
  795. return view('app.practice-management.shipments-ready-to-print', compact('shipments', 'counts'));
  796. }
  797. public function shipmentsShipmentUnderway(Request $request)
  798. {
  799. $counts = $this->getShipmentCounts();
  800. $shipments = Shipment
  801. ::where('is_cancelled', false)
  802. ->where('status', 'PRINTED')
  803. ->orderBy('created_at', 'ASC')
  804. ->paginate();
  805. return view('app.practice-management.shipments-waiting-for-picker', compact('shipments', 'counts'));
  806. }
  807. private function getShipmentCounts()
  808. {
  809. return [
  810. "shipments" => Shipment::count(),
  811. "shipmentsReadyToPrint" => Shipment
  812. ::where('is_cancelled', false)
  813. ->where('status', 'CREATED')
  814. ->count(),
  815. "shipmentsWaitingForPicker" => Shipment
  816. ::where('is_cancelled', false)
  817. ->where('status', 'PRINTED')
  818. ->count()
  819. ];
  820. }
  821. public function shipment(Request $request, Shipment $shipment)
  822. {
  823. return view('app.practice-management.shipment', compact('shipment'));
  824. }
  825. public function shipmentsMultiPrint(Request $request, $ids)
  826. {
  827. $ids = array_map(function ($_x) {
  828. return intval($_x);
  829. }, explode("|", $ids));
  830. $shipments = Shipment::whereIn('id', $ids)->get();
  831. return view('app.practice-management.shipments-multi-print', compact('shipments'));
  832. }
  833. public function patientClaimSummary(Request $request, $proUid = null)
  834. {
  835. $notesTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE"))[0]->count;
  836. $notesTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS TRUE"))[0]->count;
  837. $notesTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS TRUE"))[0]->count;
  838. $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;
  839. $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;
  840. $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;
  841. $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;
  842. $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;
  843. $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;
  844. $performerPro = $this->performer->pro;
  845. $allPros = [];
  846. if ($performerPro->pro_type == 'ADMIN') {
  847. $allPros = Pro::all();
  848. } else {
  849. $allPros = [$performerPro];
  850. }
  851. //Patient | MCP | # Notes Total | # Notes without Billing Closed | # Notes without Claiming Closed
  852. $patientsQuery = Client::where('is_dummy', '=', false)
  853. ->whereNull('shadow_pro_id')
  854. ->select('id', 'uid', 'name_first', 'name_last', 'mcp_pro_id', 'is_part_b_primary', 'medicare_advantage_plan',
  855. DB::raw("(SELECT name_first||' '||name_last FROM pro where pro.id = client.mcp_pro_id) as mcp"),
  856. DB::raw("(SELECT uid FROM pro where pro.id = mcp_pro_id) as mcp_pro_uid"),
  857. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id) as notes_total"),
  858. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_bill_closed IS NOT true) as notes_without_billing_closed"),
  859. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_claim_closed IS NOT true) as notes_without_claiming_closed")
  860. )->orderBy('is_part_b_primary', 'asc')->orderBy('notes_without_claiming_closed', 'desc');
  861. if ($proUid) {
  862. $mcpPro = Pro::where('uid', $proUid)->first();
  863. if ($mcpPro) {
  864. $patientsQuery->where('client.mcp_pro_id', '=', $mcpPro->id);
  865. }
  866. }
  867. $patientsQuery->whereRaw('(SELECT COUNT(*) FROM note where note.client_id = client.id) > 0');
  868. $patientsQuery->orderBy('notes_without_claiming_closed', 'DESC');
  869. $patients = $patientsQuery->paginate(50);
  870. $data = [
  871. 'patients' => $patients,
  872. 'proUid' => $proUid,
  873. 'allPros' => $allPros,
  874. 'notesTotal' => $notesTotal,
  875. 'notesTotalWithBillingClosed' => $notesTotalWithBillingClosed,
  876. 'notesTotalWithClaimingClosed' => $notesTotalWithClaimingClosed,
  877. 'notes3rdPartyTotal' => $notes3rdPartyTotal,
  878. 'notes3rdPartyTotalWithBillingClosed' => $notes3rdPartyTotalWithBillingClosed,
  879. 'notes3rdPartyTotalWithClaimingClosed' => $notes3rdPartyTotalWithClaimingClosed,
  880. 'patientsTotal' => $patientsTotal,
  881. 'patientsTotalWithBillingClosed' => $patientsTotalWithBillingClosed,
  882. 'patientsTotalWithClaimingClosed' => $patientsTotalWithClaimingClosed
  883. ];
  884. return view('app.practice-management.patient-claim-summary', $data);
  885. }
  886. public function claims(Request $request){
  887. $status = $request->get('status');
  888. $claims = [];
  889. if(!$status){
  890. $claims = Claim::orderBy('created_at', 'DESC')->paginate();
  891. }else{
  892. $claims = Claim::where('status', $status)->orderBy('created_at', 'DESC')->paginate();
  893. }
  894. return view('app.practice-management.claims', compact('claims', 'status'));
  895. }
  896. public function processClaims(Request $request) {
  897. $status = '';
  898. $claims = DB::select(DB::raw("
  899. SELECT claim.uid as uid,
  900. DATE(claim.created_at) as created,
  901. claim.status,
  902. client.uid as client_uid,
  903. (client.name_last || ' ' || client.name_first) as client ,
  904. client.chart_number as client_chart_number,
  905. cp.id as claim_pro_id,
  906. (cp.name_last || ' ' || cp.name_first) as claim_pro,
  907. sp.id as status_pro_id,
  908. (sp.name_last || ' ' || sp.name_first) as status_pro,
  909. -- claim.status_updated_at,
  910. (DATE(claim.status_updated_at) || ' ' ||
  911. LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
  912. LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) as status_updated_at,
  913. (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) as cpts,
  914. (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,
  915. ROUND(claim.expected_total, 2) as expected_total
  916. FROM claim
  917. join client on claim.client_id = client.id
  918. join pro cp on claim.pro_id = cp.id
  919. left join app_session on claim.status_updated_by_session_id = app_session.id
  920. left join pro sp on app_session.pro_id = sp.id
  921. --WHERE claim.status IS NULL OR claim.status = 'NEW'
  922. WHERE claim.status is NULL OR claim.status NOt IN ('CANCELLED', 'ABANDONED')
  923. ORDER BY claim.created_at ASC
  924. --OFFSET 0 LIMIT 15
  925. "));
  926. return view('app.practice-management.process-claims', compact('claims', 'status'));
  927. }
  928. public function currentMbClaim(Request $request, $claimUid) {
  929. $claim = Claim::where('uid', $claimUid)->first();
  930. return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->first());
  931. }
  932. public function currentClaimLines(Request $request, $claimUid) {
  933. $claim = Claim::where('uid', $claimUid)->first();
  934. return view('app.practice-management._claim-lines', compact('claim'));
  935. }
  936. public function packsMultiPrint(Request $request) {
  937. $packs = Pack
  938. ::select('pack.*')
  939. ->leftJoin('shipment', function($join) {
  940. $join->on('pack.shipment_id', '=', 'shipment.id');
  941. })
  942. ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
  943. ->where(function ($query) {
  944. $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
  945. })
  946. ->whereNotNull('pack.label_system_file_id')
  947. ->orderBy('pack.created_at', 'ASC')
  948. ->get();
  949. return view('app.practice-management.packs-multi-print', compact('packs'));
  950. }
  951. public function packsMultiPDF(Request $request, $ids) {
  952. $ids = array_map(function ($_x) {
  953. return intval($_x);
  954. }, explode("|", $ids));
  955. $packs = Pack::whereIn('id', $ids)->get();
  956. }
  957. public function handouts(Request $request) {
  958. $handouts = Handout::orderBy('display_name')->get();
  959. return view('app.practice-management.handouts', compact('handouts'));
  960. }
  961. private function callJava($request, $endPoint, $data)
  962. {
  963. $url = config('stag.backendUrl') . $endPoint;
  964. $response = Http::asForm()
  965. ->withHeaders([
  966. 'sessionKey' => $request->cookie('sessionKey')
  967. ])
  968. ->post($url, $data)
  969. ->body();
  970. dd($response);
  971. return $response;
  972. }
  973. }