PracticeManagementController.php 65 KB

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