PracticeManagementController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\Bill;
  5. use App\Models\Client;
  6. use App\Models\McpRequest;
  7. use App\Models\Note;
  8. use App\Models\Pro;
  9. use App\Models\ProFavorite;
  10. use App\Models\ProGeneralAvailability;
  11. use App\Models\ProRate;
  12. use App\Models\ProSpecificAvailability;
  13. use App\Models\ProSpecificUnavailability;
  14. use App\Models\ProTextShortcut;
  15. use App\Models\ProTransaction;
  16. use App\Models\Ticket;
  17. use DateTime;
  18. use DateTimeZone;
  19. use Illuminate\Http\Request;
  20. class PracticeManagementController extends Controller
  21. {
  22. public function dashboard(Request $request)
  23. {
  24. return view('app.practice-management.dashboard');
  25. }
  26. public function rates(Request $request, $selectedProUid = 'all')
  27. {
  28. $proUid = $selectedProUid ? $selectedProUid : 'all';
  29. $rates = ProRate::where('is_active', true);
  30. if ($proUid !== 'all') {
  31. $selectedPro = Pro::where('uid', $proUid)->first();
  32. $rates = $rates->where('pro_id', $selectedPro->id);
  33. }
  34. $rates = $rates->orderBy('pro_id', 'asc')->get();
  35. $pros = $this->pros;
  36. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  37. }
  38. public function previousBills(Request $request)
  39. {
  40. return view('app.practice-management.previous-bills');
  41. }
  42. public function financialTransactions(Request $request)
  43. {
  44. $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
  45. return view('app.practice-management.financial-transactions', compact('transactions'));
  46. }
  47. public function pendingBillsToSign(Request $request)
  48. {
  49. return view('app.practice-management.pending-bills-to-sign');
  50. }
  51. public function HR(Request $request)
  52. {
  53. return view('app.practice-management.hr');
  54. }
  55. public function directDepositSettings(Request $request)
  56. {
  57. return view('app.practice-management.direct-deposit-settings');
  58. }
  59. public function w9(Request $request)
  60. {
  61. return view('app.practice-management.w9');
  62. }
  63. public function contract(Request $request)
  64. {
  65. return view('app.practice-management.contract');
  66. }
  67. public function notes(Request $request, $filter = '')
  68. {
  69. $proID = $this->performer()->pro->id;
  70. $query = Note::where('hcp_pro_id', $proID);
  71. switch ($filter) {
  72. case 'not-yet-signed':
  73. $query = $query->where('is_signed_by_hcp', false);
  74. break;
  75. // more cases can be added as needed
  76. default:
  77. break;
  78. }
  79. $notes = $query->orderBy('created_at', 'desc')->get();
  80. return view('app.practice-management.notes', compact('notes', 'filter'));
  81. }
  82. public function bills(Request $request, $filter = '')
  83. {
  84. $proID = $this->performer()->pro->id;
  85. $query = Bill::where('is_cancelled', false);
  86. switch ($filter) {
  87. case 'not-yet-signed':
  88. $query = $query
  89. ->where(function ($q) use ($proID) {
  90. $q->where(function ($q2) use ($proID) {
  91. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  92. })
  93. ->orWhere(function ($q2) use ($proID) {
  94. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  95. })
  96. ->orWhere(function ($q2) use ($proID) {
  97. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  98. })
  99. ->orWhere(function ($q2) use ($proID) {
  100. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  101. });
  102. });
  103. break;
  104. case 'previous':
  105. $query = $query
  106. ->where(function ($q) use ($proID) {
  107. $q->where(function ($q2) use ($proID) {
  108. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  109. })
  110. ->orWhere(function ($q2) use ($proID) {
  111. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  112. })
  113. ->orWhere(function ($q2) use ($proID) {
  114. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  115. })
  116. ->orWhere(function ($q2) use ($proID) {
  117. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  118. });
  119. });
  120. break;
  121. // more cases can be added as needed
  122. default:
  123. break;
  124. }
  125. $bills = $query->orderBy('created_at', 'desc')->get();
  126. return view('app.practice-management.bills', compact('bills', 'filter'));
  127. }
  128. public function myTickets(Request $request, $filter = 'open')
  129. {
  130. $performer = $this->performer();
  131. $myTickets = Ticket::where(function ($q) use ($performer) {
  132. $q->where('assigned_pro_id', $performer->pro_id)
  133. ->orWhere('manager_pro_id', $performer->pro_id)
  134. ->orWhere('ordering_pro_id', $performer->pro_id)
  135. ->orWhere('initiating_pro_id', $performer->pro_id);
  136. });
  137. if ($filter === 'open') {
  138. $myTickets = $myTickets->where('is_open', true);
  139. } else if ($filter === 'closed') {
  140. $myTickets = $myTickets->where('is_open', false);
  141. }
  142. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  143. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  144. }
  145. public function myTextShortcuts(Request $request)
  146. {
  147. $performer = $this->performer();
  148. $myTextShortcuts = ProTextShortcut::where('pro_id', $performer->pro_id)->where('is_removed', false)->get();
  149. return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
  150. }
  151. public function myFavorites(Request $request, $filter = 'all')
  152. {
  153. $performer = $this->performer();
  154. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  155. ->where('is_removed', false);
  156. if ($filter !== 'all') {
  157. $myFavorites = $myFavorites->where('category', $filter);
  158. }
  159. $myFavorites = $myFavorites
  160. ->orderBy('category', 'asc')
  161. ->orderBy('position_index', 'asc')
  162. ->get();
  163. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  164. }
  165. public function proAvailability(Request $request, $proUid = null)
  166. {
  167. $performer = $this->performer();
  168. $pro = $performer->pro;
  169. if ($proUid) {
  170. $pro = Pro::where('uid', $proUid)->first();
  171. }
  172. if ($request->get('pro_uid')) {
  173. $proUid = $request->get('pro_uid');
  174. $pro = Pro::where('uid', $proUid)->first();
  175. }
  176. $selectedProUid = $pro->uid;
  177. $pros = $this->pros;
  178. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  179. $generalAvailabilities = [
  180. 'MONDAY' => [],
  181. 'TUESDAY' => [],
  182. 'WEDNESDAY' => [],
  183. 'THURSDAY' => [],
  184. 'FRIDAY' => [],
  185. 'SATURDAY' => [],
  186. 'SUNDAY' => [],
  187. ];
  188. foreach ($generalAvailabilitiesList as $ga) {
  189. if ($ga->day_of_week == 'MONDAY') {
  190. $generalAvailabilities['MONDAY'][] = $ga;
  191. }
  192. if ($ga->day_of_week == 'TUESDAY') {
  193. $generalAvailabilities['TUESDAY'][] = $ga;
  194. }
  195. if ($ga->day_of_week == 'WEDNESDAY') {
  196. $generalAvailabilities['WEDNESDAY'][] = $ga;
  197. }
  198. if ($ga->day_of_week == 'THURSDAY') {
  199. $generalAvailabilities['THURSDAY'][] = $ga;
  200. }
  201. if ($ga->day_of_week == 'FRIDAY') {
  202. $generalAvailabilities['FRIDAY'][] = $ga;
  203. }
  204. if ($ga->day_of_week == 'SATURDAY') {
  205. $generalAvailabilities['SATURDAY'][] = $ga;
  206. }
  207. if ($ga->day_of_week == 'SUNDAY') {
  208. $generalAvailabilities['SUNDAY'][] = $ga;
  209. }
  210. }
  211. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  212. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  213. //events for the calendar
  214. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  215. $endDateTime = new DateTime($startDate);
  216. $endDateTime->modify('+6 day');
  217. $endDate = $endDateTime->format("Y-m-d");
  218. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  219. $events = json_encode($eventsData);
  220. return view(
  221. 'app.practice-management.pro-availability',
  222. compact(
  223. 'pros',
  224. 'generalAvailabilities',
  225. 'specificAvailabilities',
  226. 'specificUnavailabilities',
  227. 'events',
  228. 'selectedProUid'
  229. )
  230. );
  231. }
  232. public function loadAvailability(Request $request, $proUid)
  233. {
  234. $performer = $this->performer();
  235. $pro = $performer->pro;
  236. $startDate = $request->get('start');
  237. $endDate = $request->get('end');
  238. $selectedPro = Pro::where('uid', $proUid)->first();
  239. return $selectedPro->getAvailabilityEvents($startDate, $endDate);
  240. }
  241. public function proAvailabilityFilter(Request $request)
  242. {
  243. $proUid = $request->get('proUid');
  244. return ['success' => true, 'data' => $proUid];
  245. }
  246. // video call page (RHS)
  247. // generic call handle (no uid)
  248. // specific call handle (uid of client)
  249. public function meet(Request $request, $uid = false)
  250. {
  251. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  252. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  253. if (!empty($client)) {
  254. return view('app.video.call-minimal', compact('session', 'client'));
  255. }
  256. return view('app.video.call-agora-v2', compact('session', 'client'));
  257. }
  258. // check video page
  259. public function checkVideo(Request $request, $uid) {
  260. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  261. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  262. $publish = false;
  263. return view('app.video.check-video-minimal', compact('session', 'client'));
  264. }
  265. public function getParticipantInfo(Request $request) {
  266. $sid = intval($request->get('uid')) - 1000000;
  267. $session = AppSession::where('id', $sid)->first();
  268. $result = [
  269. "type" => '',
  270. "name" => ''
  271. ];
  272. if ($session) {
  273. $result["type"] = $session->session_type;
  274. switch ($session->session_type) {
  275. case 'PRO':
  276. $pro = Pro::where('id', $session->pro_id)->first();
  277. $result["name"] = $pro->displayName();
  278. break;
  279. case 'CLIENT':
  280. $client = Client::where('id', $session->client_id)->first();
  281. $result["name"] = $client->displayName();
  282. break;
  283. }
  284. }
  285. return json_encode($result);
  286. }
  287. // ajax ep used by the video page
  288. // this is needed bcoz meet() is used not
  289. // just for the client passed to the view
  290. public function getOpentokSessionKey(Request $request, $uid)
  291. {
  292. $client = Client::where('uid', $uid)->first();
  293. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  294. }
  295. // poll to check if there are patients with active mcp requests
  296. public function getPatientsInQueue(Request $request)
  297. {
  298. $requests = McpRequest::where('is_active', true)->limit(3)->get();
  299. $results = [];
  300. if ($requests && count($requests)) {
  301. foreach ($requests as $mcpRequest) {
  302. $client = $mcpRequest->client;
  303. if ($client->initiative) {
  304. if (strpos($this->performer->pro->initiative, $client->initiative) !== false) {
  305. $results[] = [
  306. "clientUid" => $client->uid,
  307. "name" => $client->displayName(),
  308. "initials" => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  309. ];
  310. }
  311. } else {
  312. $results[] = [
  313. "clientUid" => $client->uid,
  314. "name" => $client->displayName(),
  315. "initials" => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  316. ];
  317. }
  318. }
  319. }
  320. return json_encode($results);
  321. }
  322. public function currentWork(Request $request)
  323. {
  324. return view('app/current-work');
  325. }
  326. public function calendar(Request $request, $proUid = null)
  327. {
  328. return view('app.practice-management.calendar');
  329. }
  330. public function billingManager(Request $request, $proUid = null)
  331. {
  332. $notes = Note::orderBy('created_at', 'desc')->paginate();
  333. return view('app.practice-management.billing-manager', compact('notes'));
  334. }
  335. public function tickets(Request $request, $proUid = null)
  336. {
  337. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  338. return view('app.practice-management.tickets', compact('tickets'));
  339. }
  340. }