PracticeManagementController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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)
  134. {
  135. $performer = $this->performer();
  136. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  137. ->where('is_removed', false)
  138. ->orderBy('category', 'asc')
  139. ->orderBy('position_index', 'asc')
  140. ->get();
  141. return view('app.practice-management.my-favorites', compact('myFavorites'));
  142. }
  143. public function proAvailability(Request $request, $proUid = null)
  144. {
  145. $performer = $this->performer();
  146. $pro = $performer->pro;
  147. if($proUid){
  148. $pro = Pro::where('uid', $proUid)->first();
  149. }
  150. if($request->get('pro_uid')){
  151. $proUid = $request->get('pro_uid');
  152. $pro = Pro::where('uid', $proUid)->first();
  153. }
  154. $selectedProUid = $pro->uid;
  155. $pros =$this->pros;
  156. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  157. $generalAvailabilities = [
  158. 'MONDAY'=>[],
  159. 'TUESDAY'=>[],
  160. 'WEDNESDAY'=>[],
  161. 'THURSDAY'=>[],
  162. 'FRIDAY'=>[],
  163. 'SATURDAY'=>[],
  164. 'SUNDAY'=>[],
  165. ];
  166. foreach($generalAvailabilitiesList as $ga){
  167. if($ga->day_of_week == 'MONDAY'){
  168. $generalAvailabilities['MONDAY'][] = $ga;
  169. }
  170. if($ga->day_of_week == 'TUESDAY'){
  171. $generalAvailabilities['TUESDAY'][] = $ga;
  172. }
  173. if($ga->day_of_week == 'WEDNESDAY'){
  174. $generalAvailabilities['WEDNESDAY'][] = $ga;
  175. }
  176. if($ga->day_of_week == 'THURSDAY'){
  177. $generalAvailabilities['THURSDAY'][] = $ga;
  178. }
  179. if($ga->day_of_week == 'FRIDAY'){
  180. $generalAvailabilities['FRIDAY'][] = $ga;
  181. }
  182. if($ga->day_of_week == 'SATURDAY'){
  183. $generalAvailabilities['SATURDAY'][] = $ga;
  184. }
  185. if($ga->day_of_week == 'SUNDAY'){
  186. $generalAvailabilities['SUNDAY'][] = $ga;
  187. }
  188. }
  189. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  190. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  191. //events for the calendar
  192. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  193. $endDateTime = new DateTime($startDate);
  194. $endDateTime->modify('+6 day');
  195. $endDate = $endDateTime->format("Y-m-d");
  196. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  197. $events = json_encode($eventsData);
  198. return view('app.practice-management.pro-availability',
  199. compact('pros','generalAvailabilities', 'specificAvailabilities',
  200. 'specificUnavailabilities', 'events', 'selectedProUid'));
  201. }
  202. public function loadAvailability(Request $request, $proUid){
  203. $performer = $this->performer();
  204. $pro = $performer->pro;
  205. $startDate = $request->get('start');
  206. $endDate = $request->get('end');
  207. $selectedPro = Pro::where('uid', $proUid)->first();
  208. return $selectedPro->getAvailabilityEvents($startDate, $endDate);
  209. }
  210. public function proAvailabilityFilter(Request $request){
  211. $proUid = $request->get('proUid');
  212. return ['success'=>true, 'data'=>$proUid];
  213. }
  214. // video call page (RHS)
  215. // generic call handle (no uid)
  216. // specific call handle (uid of client)
  217. public function meet(Request $request, $uid = false) {
  218. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  219. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  220. return view('app.video.call', compact('session', 'client'));
  221. }
  222. // ajax ep used by the video page
  223. // this is needed bcoz meet() is used not
  224. // just for the client passed to the view
  225. public function getOpentokSessionKey(Request $request, $uid) {
  226. $client = Client::where('uid', $uid)->first();
  227. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  228. }
  229. // poll to check if there are patients with active mcp requests
  230. public function getPatientsInQueue(Request $request) {
  231. $requests = McpRequest::where('is_active', true)->limit(3)->get();
  232. $results = [];
  233. if($requests && count($requests)) {
  234. foreach ($requests as $mcpRequest) {
  235. $client = $mcpRequest->client;
  236. $results[] = [
  237. "clientUid" => $client->uid,
  238. "name" => $client->displayName(),
  239. "initials" => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  240. ];
  241. }
  242. // $results = $requests;
  243. }
  244. return json_encode($results);
  245. }
  246. public function currentWork(Request $request) {
  247. return view('app/current-work');
  248. }
  249. public function calendar(Request $request, $proUid = null) {
  250. return view('app.practice-management.calendar');
  251. }
  252. }