PracticeManagementController.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. $q = $request->input('q') ? $request->input('q') : '';
  899. $from = $request->input('from') ? $request->input('from') : '1900-01-01';
  900. $to = $request->input('to') ? $request->input('to') : '2100-01-01';
  901. $params = [
  902. 'q' => '%' . $q . '%',
  903. 'from' => $from,
  904. 'to' => $to
  905. ];
  906. $hcpPro = $request->input('hcp') ? Pro::where('uid', $request->input('hcp'))->first() : null;
  907. if($hcpPro) {
  908. $params['hcp'] = $hcpPro->id;
  909. }
  910. $claims = DB::select(DB::raw("
  911. SELECT claim.uid as uid,
  912. DATE(claim.created_at) as created,
  913. claim.status,
  914. client.uid as client_uid,
  915. (client.name_last || ' ' || client.name_first) as client ,
  916. client.chart_number as client_chart_number,
  917. cp.id as claim_pro_id,
  918. (cp.name_last || ' ' || cp.name_first) as claim_pro,
  919. sp.id as status_pro_id,
  920. (sp.name_last || ' ' || sp.name_first) as status_pro,
  921. note.uid as note_uid,
  922. note.method,
  923. -- claim.status_updated_at,
  924. (DATE(claim.status_updated_at) || ' ' ||
  925. LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
  926. LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) as status_updated_at,
  927. (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) as cpts,
  928. (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,
  929. ROUND(claim.expected_total, 3) as expected_total
  930. FROM claim
  931. join client on claim.client_id = client.id
  932. join pro cp on claim.pro_id = cp.id
  933. left join note on claim.note_id = note.id
  934. left join app_session on claim.status_updated_by_session_id = app_session.id
  935. left join pro sp on app_session.pro_id = sp.id
  936. --WHERE claim.status IS NULL OR claim.status = 'NEW'
  937. WHERE (claim.status is NULL OR claim.status NOT IN ('CANCELLED', 'ABANDONED'))
  938. -- AND claim.current_version_id IS NOT NULL
  939. AND (client.name_first ILIKE :q OR
  940. client.name_last ILIKE :q OR
  941. client.chart_number ILIKE :q OR
  942. client.mcn ILIKE :q)
  943. AND (claim.created_at >= :from AND claim.created_at <= :to)
  944. " . ($hcpPro ? "AND claim.pro_id = :hcp" : '') . "
  945. ORDER BY claim.created_at ASC
  946. --OFFSET 0 LIMIT 15
  947. "), $params);
  948. if($request->input('json')) {
  949. return json_encode($claims);
  950. }
  951. return view('app.practice-management.process-claims', compact('claims', 'status'));
  952. }
  953. public function currentMbClaim(Request $request, $claimUid) {
  954. $claim = Claim::where('uid', $claimUid)->first();
  955. return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->first());
  956. }
  957. public function currentClaimLines(Request $request, $claimUid) {
  958. $claim = Claim::where('uid', $claimUid)->first();
  959. return view('app.practice-management._claim-lines', compact('claim'));
  960. }
  961. public function packsMultiPrint(Request $request) {
  962. $packs = Pack
  963. ::select('pack.*')
  964. ->leftJoin('shipment', function($join) {
  965. $join->on('pack.shipment_id', '=', 'shipment.id');
  966. })
  967. ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
  968. ->where(function ($query) {
  969. $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
  970. })
  971. ->whereNotNull('pack.label_system_file_id')
  972. ->orderBy('pack.created_at', 'ASC')
  973. ->get();
  974. return view('app.practice-management.packs-multi-print', compact('packs'));
  975. }
  976. public function packsMultiPDF(Request $request, $ids) {
  977. $ids = array_map(function ($_x) {
  978. return intval($_x);
  979. }, explode("|", $ids));
  980. $packs = Pack::whereIn('id', $ids)->get();
  981. }
  982. public function handouts(Request $request) {
  983. $handouts = Handout::orderBy('display_name')->get();
  984. return view('app.practice-management.handouts', compact('handouts'));
  985. }
  986. private function callJava($request, $endPoint, $data)
  987. {
  988. $url = config('stag.backendUrl') . $endPoint;
  989. $response = Http::asForm()
  990. ->withHeaders([
  991. 'sessionKey' => $request->cookie('sessionKey')
  992. ])
  993. ->post($url, $data)
  994. ->body();
  995. dd($response);
  996. return $response;
  997. }
  998. }