PracticeManagementController.php 12 KB

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