HomeController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Lib\Backend;
  4. use App\Models\Appointment;
  5. use App\Models\AppSession;
  6. use App\Models\ClientSMS;
  7. use App\Models\Facility;
  8. use App\Models\IncomingReport;
  9. use App\Models\MBPayer;
  10. use App\Models\ProProAccess;
  11. use App\Models\Ticket;
  12. use DateTime;
  13. use App\Models\Client;
  14. use App\Models\Bill;
  15. use App\Models\Measurement;
  16. use App\Models\Note;
  17. use App\Models\Pro;
  18. use App\Models\ProTransaction;
  19. use GuzzleHttp\Cookie\CookieJar;
  20. use Illuminate\Http\Request;
  21. use Illuminate\Support\Facades\Cookie;
  22. use Illuminate\Support\Facades\DB;
  23. use Illuminate\Support\Facades\Http;
  24. class HomeController extends Controller
  25. {
  26. public function confirmSmsAuthToken(Request $request)
  27. {
  28. return view('app/confirm_sms_auth_token');
  29. }
  30. public function setPassword(Request $request)
  31. {
  32. return view('app/set_password');
  33. }
  34. public function setSecurityQuestions(Request $request)
  35. {
  36. return view('app/set_security_questions');
  37. }
  38. public function postConfirmSmsAuthToken(Request $request)
  39. {
  40. try {
  41. $url = config('stag.backendUrl') . '/session/confirmSmsAuthToken';
  42. $data = [
  43. 'cellNumber' => $request->input('cellNumber'),
  44. 'token' => $request->input('token'),
  45. ];
  46. $response = Http::asForm()
  47. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  48. ->post($url, $data)
  49. ->json();
  50. if (!isset($response['success']) || !$response['success']) {
  51. $message = 'API error';
  52. if (isset($response['error'])) {
  53. $message = $response['error'];
  54. if (isset($response['path'])) $message .= ': ' . $response['path'];
  55. } else if (isset($response['message'])) $message = $response['message'];
  56. return redirect('/confirm_sms_auth_token')
  57. ->withInput()
  58. ->with('message', $message);
  59. }
  60. return redirect('/');
  61. } catch (\Exception $e) {
  62. return redirect()->back()
  63. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  64. ->withInput($request->input());
  65. }
  66. }
  67. public function resendSmsAuthToken(Request $request)
  68. {
  69. try {
  70. $url = config('stag.backendUrl') . '/session/resendSmsAuthToken';
  71. $data = [];
  72. $response = Http::asForm()
  73. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  74. ->post($url, $data)
  75. ->json();
  76. if (!isset($response['success']) || !$response['success']) {
  77. $message = 'API error';
  78. if (isset($response['error'])) {
  79. $message = $response['error'];
  80. if (isset($response['path'])) $message .= ': ' . $response['path'];
  81. } else if (isset($response['message'])) $message = $response['message'];
  82. return redirect('/confirm_sms_auth_token')
  83. ->withInput()
  84. ->with('message', $message);
  85. }
  86. return redirect()->back()->withInput()->with('message', "SMS Auth Token sent.");
  87. } catch (\Exception $e) {
  88. return redirect()->back()
  89. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  90. ->withInput($request->input());
  91. }
  92. }
  93. public function postSetPassword(Request $request)
  94. {
  95. try {
  96. $url = config('stag.backendUrl') . '/pro/selfPutPassword';
  97. $data = [
  98. 'newPassword' => $request->input('newPassword'),
  99. 'newPasswordConfirmation' => $request->input('newPasswordConfirmation'),
  100. ];
  101. $response = Http::asForm()
  102. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  103. ->post($url, $data)
  104. ->json();
  105. if (!isset($response['success']) || !$response['success']) {
  106. $message = 'API error';
  107. if (isset($response['error'])) {
  108. $message = $response['error'];
  109. if (isset($response['path'])) $message .= ': ' . $response['path'];
  110. } else if (isset($response['message'])) $message = $response['message'];
  111. return redirect('/set_password')
  112. ->withInput()
  113. ->with('message', $message);
  114. }
  115. return redirect('/');
  116. } catch (\Exception $e) {
  117. return redirect()->back()
  118. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  119. ->withInput($request->input());
  120. }
  121. }
  122. public function postSetSecurityQuestions(Request $request)
  123. {
  124. try {
  125. $url = env('BACKEND_URL', 'http://localhost:8080/api') . '/pro/selfPutSecurityQuestions';
  126. $data = [
  127. 'securityQuestion1' => $request->input('securityQuestion1'),
  128. 'securityAnswer1' => $request->input('securityAnswer1'),
  129. 'securityQuestion2' => $request->input('securityQuestion2'),
  130. 'securityAnswer2' => $request->input('securityAnswer2'),
  131. ];
  132. $response = Http::asForm()
  133. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  134. ->post($url, $data)
  135. ->json();
  136. if (!isset($response['success']) || !$response['success']) {
  137. $message = 'API error';
  138. if (isset($response['error'])) {
  139. $message = $response['error'];
  140. if (isset($response['path'])) $message .= ': ' . $response['path'];
  141. } else if (isset($response['message'])) $message = $response['message'];
  142. return redirect('/set_password')
  143. ->withInput()
  144. ->with('message', $message);
  145. }
  146. return redirect('/');
  147. } catch (\Exception $e) {
  148. return redirect()->back()
  149. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  150. ->withInput($request->input());
  151. }
  152. }
  153. public function dashboard(Request $request)
  154. {
  155. //patients where performer is the mcp
  156. $performer = $this->performer();
  157. $performerProID = $performer->pro->id;
  158. $isAdmin = ($performer->pro->pro_type === 'ADMIN');
  159. $keyNumbers = [];
  160. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  161. $keyNumbers['totalPatients'] = $queryClients->count();
  162. // patientNotSeenYet
  163. $patientNotSeenYet = $queryClients
  164. ->where(function ($query) use ($performer) { // own patient and primary OB visit pending
  165. $query->where('mcp_pro_id', $performer->pro->id)
  166. ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
  167. })
  168. ->orWhere(function ($query) { // mcp of any client program and program OB pending
  169. $query->where(function ($_query) {
  170. $_query->select(DB::raw('COUNT(id)'))
  171. ->from('client_program')
  172. ->whereColumn('client_id', 'client.id')
  173. ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
  174. }, '>=', 1);
  175. })->count();
  176. $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
  177. $pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
  178. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  179. })
  180. ->orWhere(function ($query) use ($performerProID) {
  181. $query->where('cm_pro_id', $performerProID)->where('is_signed_by_cm', false)->where('is_cancelled', false);;
  182. })->orWhere(function ($query) use ($performerProID) {
  183. $query->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false)->where('is_cancelled', false);;
  184. })->orWhere(function ($query) use ($performerProID) {
  185. $query->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false)->where('is_cancelled', false);;
  186. })->count();
  187. $keyNumbers['pendingBillsToSign'] = $pendingBillsToSign;
  188. $pendingNotesToSign = Note::where(function ($query) use ($performerProID) {
  189. $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);;
  190. })
  191. ->orWhere(function ($query) use ($performerProID) {
  192. $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false)->where('is_cancelled', false);;
  193. })->count();
  194. $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
  195. // open tickets
  196. $keyNumbers['numOpenTickets'] = Ticket::where('is_open', true)
  197. ->where(function ($q) use ($performerProID) {
  198. $q->where('assigned_pro_id', $performerProID)
  199. ->orWhere('manager_pro_id', $performerProID)
  200. ->orWhere('ordering_pro_id', $performerProID)
  201. ->orWhere('initiating_pro_id', $performerProID);
  202. })
  203. ->count();
  204. // num measurements that need stamping
  205. $keyNumbers['measurementsToBeStamped'] = ($this->performer()->pro->pro_type === 'ADMIN' ? '-' : count($this->performer()->pro->getMeasurements(true)));
  206. $reimbursement = [];
  207. $reimbursement["currentBalance"] = $performer->pro->balance;
  208. $reimbursement["nextPaymentDate"] = '--';
  209. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  210. if ($lastPayment) {
  211. $reimbursement["lastPayment"] = $lastPayment->amount;
  212. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  213. } else {
  214. $reimbursement["lastPayment"] = '--';
  215. $reimbursement["lastPaymentDate"] = '--';
  216. }
  217. //if today is < 15th, next payment is 15th, else nextPayment is
  218. $today = strtotime(date('Y-m-d'));
  219. $todayDate = date('j', $today);
  220. $todayMonth = date('m', $today);
  221. $todayYear = date('Y', $today);
  222. if ($todayDate < 15) {
  223. $nextPaymentDate = new DateTime();
  224. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  225. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  226. } else {
  227. $nextPaymentDate = new \DateTime();
  228. $lastDayOfMonth = date('t', $today);
  229. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  230. $reimbursement['nextPaymentDate'] = $nextPaymentDate->format('m/d/Y');
  231. }
  232. //expectedPay
  233. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :performerProID AND has_hcp_been_paid = false AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  234. $expectedForCm = DB::select(DB::raw("SELECT coalesce(SUM(cm_expected_payment_amount),0) as expected_pay FROM bill WHERE cm_pro_id = :performerProID AND has_cm_been_paid = false AND is_signed_by_cm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  235. $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay FROM bill WHERE rme_pro_id = :performerProID AND has_rme_been_paid = false AND is_signed_by_rme IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  236. $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay FROM bill WHERE rmm_pro_id = :performerProID AND has_rmm_been_paid = false AND is_signed_by_rmm IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  237. $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(na_expected_payment_amount),0) as expected_pay FROM bill WHERE na_pro_id = :performerProID AND has_na_been_paid = false AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['performerProID' => $performerProID])[0]->expected_pay;
  238. $totalExpectedAmount = $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  239. $reimbursement['nextPaymentAmount'] = $totalExpectedAmount;
  240. $milliseconds = strtotime(date('Y-m-d')) . '000';
  241. $measurements = $performer->pro->getMeasurements();
  242. // bills & claims
  243. $businessNumbers = [];
  244. // Notes with bills to resolve
  245. $businessNumbers['notesWithBillsToResolve'] = Note::where('is_cancelled', '!=', true)
  246. ->where('is_bill_closed', '!=', true)
  247. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND is_cancelled = false AND is_verified = false) > 0')
  248. ->count();
  249. // Notes pending bill closure
  250. $businessNumbers['notesPendingBillingClosure'] = Note::where('is_cancelled', '!=', true)
  251. ->where('is_bill_closed', '!=', true)
  252. ->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = true OR is_verified = true)) = 0')
  253. ->count();
  254. // incoming reports not signed
  255. $incomingReports = IncomingReport::where('hcp_pro_id', $performerProID)
  256. ->where('has_hcp_pro_signed', false)
  257. ->where('is_entry_error', false)
  258. ->orderBy('created_at', 'ASC')
  259. ->get();
  260. // erx, labs & imaging that are not closed
  261. $tickets = Ticket::where('ordering_pro_id', $performerProID)
  262. ->where('is_entry_error', false)
  263. ->where('is_open', true)
  264. ->orderBy('created_at', 'ASC')
  265. ->get();
  266. $numERx = Ticket::where('ordering_pro_id', $performerProID)
  267. ->where('category', 'erx')
  268. ->where('is_entry_error', false)
  269. ->where('is_open', true)
  270. ->count();
  271. $numLabs = Ticket::where('ordering_pro_id', $performerProID)
  272. ->where('category', 'lab')
  273. ->where('is_entry_error', false)
  274. ->where('is_open', true)
  275. ->count();
  276. $numImaging = Ticket::where('ordering_pro_id', $performerProID)
  277. ->where('category', 'imaging')
  278. ->where('is_entry_error', false)
  279. ->where('is_open', true)
  280. ->count();
  281. return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'milliseconds', 'measurements', 'businessNumbers',
  282. 'incomingReports', 'tickets', 'numERx', 'numLabs', 'numImaging'));
  283. }
  284. public function dashboardAppointments(Request $request, $from, $to) {
  285. $performer = $this->performer();
  286. $performerProID = $performer->pro->id;
  287. $isAdmin = ($performer->pro->pro_type === 'ADMIN');
  288. $appointments = Appointment::where("start_time", '>=', $from)->where("start_time", '<=', $to.' 23:59:00+00');
  289. if(!$isAdmin) {
  290. $appointments = $appointments->where("pro_id", $performerProID);
  291. }
  292. $appointments = $appointments
  293. ->orderBy('start_time', 'asc')
  294. ->get();
  295. foreach ($appointments as $appointment) {
  296. $date = explode(" ", $appointment->start_time)[0];
  297. $appointment->milliseconds = strtotime($date) . '000';
  298. $appointment->newStatus = $appointment->status;
  299. $appointment->dateYMD = date('Y-m-d', strtotime($appointment->raw_date));
  300. $appointment->clientName = $appointment->client->displayName();
  301. $appointment->clientInitials = substr($appointment->client->name_first, 0, 1) . substr($appointment->client->name_last, 0, 1);
  302. $appointment->proInitials = substr($appointment->pro->name_first, 0, 1) . substr($appointment->pro->name_last, 0, 1);
  303. $appointment->friendlyStartTime = friendly_time($appointment->raw_start_time);
  304. $appointment->friendlyEndTime = friendly_time($appointment->raw_end_time);
  305. $appointment->clientSummary = friendly_date_time($appointment->client->dob, false) . ' (' .
  306. $appointment->client->age_in_years . ' y.o' .
  307. ($appointment->client->sex ? ' ' . $appointment->client->sex : '') .
  308. ')';
  309. $appointment->started = false;
  310. $appointment->inHowManyHours = date_diff(date_create('now'), date_create($appointment->start_time), false)
  311. ->format('%R%h h, %i m');
  312. if ($appointment->inHowManyHours[0] === '-') {
  313. $appointment->inHowManyHours = substr($appointment->inHowManyHours, 1) . ' ago';
  314. $appointment->started = true;
  315. } else {
  316. $appointment->inHowManyHours = 'Appt. in ' . substr($appointment->inHowManyHours, 1);
  317. }
  318. $appointment->clientUid = $appointment->client->uid;
  319. $appointment->proUid = $appointment->pro->uid;
  320. $appointment->proName = $appointment->pro->displayName();
  321. }
  322. return json_encode($appointments);
  323. }
  324. public function dashboardMeasurements(Request $request, $filter) {
  325. $measurements = $this->performer()->pro->getMeasurements($filter === 'NEED_ACK');
  326. return json_encode($measurements);
  327. }
  328. public function patients(Request $request, $filter = '')
  329. {
  330. $performer = $this->performer();
  331. $query = $performer->pro->getAccessibleClientsQuery();
  332. switch ($filter) {
  333. case 'not-yet-seen':
  334. $query = $query
  335. ->where(function ($query) use ($performer) {
  336. $query
  337. ->where(function ($query) use ($performer) { // own patient and primary OB visit pending
  338. $query->where('mcp_pro_id', $performer->pro->id)
  339. ->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  340. })
  341. ->orWhere(function ($query) use ($performer) { // mcp of any client program and program OB pending
  342. $query->select(DB::raw('COUNT(id)'))
  343. ->from('client_program')
  344. ->whereColumn('client_id', 'client.id')
  345. ->where('mcp_pro_id', $performer->pro->id)
  346. ->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  347. }, '>=', 1);
  348. });
  349. break;
  350. // more cases can be added as needed
  351. default:
  352. break;
  353. }
  354. $patients = $query->orderBy('id', 'desc')->paginate(500);
  355. return view('app/patients', compact('patients', 'filter'));
  356. }
  357. public function patientsSuggest(Request $request)
  358. {
  359. $pro = $this->pro;
  360. $term = $request->input('term') ? trim($request->input('term')) : '';
  361. if (empty($term)) return '';
  362. $clientQuery= Client::where(function ($q) use ($term) {
  363. $q->where('name_first', 'ILIKE', '%' . $term . '%')
  364. ->orWhere('name_last', 'ILIKE', '%' . $term . '%')
  365. ->orWhere('cell_number', 'ILIKE', '%' . $term . '%');
  366. });
  367. if($pro->pro_type != 'ADMIN') {
  368. $clientQuery->where(function ($q) use ($pro) {
  369. $q->whereIn('id', $pro->getMyClientIds())
  370. ->orWhereNull('mcp_pro_id');
  371. });
  372. }
  373. $clients = $clientQuery->get();
  374. return view('app/patient-suggest', compact('clients'));
  375. }
  376. public function pharmacySuggest(Request $request)
  377. {
  378. $term = $request->input('term') ? trim($request->input('term')) : '';
  379. if (empty($term)) return '';
  380. $term = strtolower($term);
  381. $pharmacies = Facility::where('facility_type', 'Pharmacy')
  382. ->where(function ($q) use ($term) {
  383. $q->orWhereRaw('LOWER(name::text) LIKE ?', ['%' . $term . '%'])
  384. ->orWhereRaw('LOWER(address_line1::text) LIKE ?', ['%' . $term . '%'])
  385. ->orWhereRaw('LOWER(address_line2::text) LIKE ?', ['%' . $term . '%'])
  386. ->orWhereRaw('LOWER(address_city::text) LIKE ?', ['%' . $term . '%'])
  387. ->orWhereRaw('LOWER(address_state::text) LIKE ?', ['%' . $term . '%'])
  388. ->orWhereRaw('LOWER(phone::text) LIKE ?', ['%' . $term . '%'])
  389. ->orWhereRaw('LOWER(address_zip::text) LIKE ?', ['%' . $term . '%']);
  390. })
  391. ->orderBy('name', 'asc')
  392. ->orderBy('address_line1', 'asc')
  393. ->orderBy('address_city', 'asc')
  394. ->orderBy('address_state', 'asc')
  395. ->get();
  396. return view('app/pharmacy-suggest', compact('pharmacies'));
  397. }
  398. public function proSuggest(Request $request) {
  399. $term = $request->input('term') ? trim($request->input('term')) : '';
  400. if (empty($term)) return '';
  401. $term = strtolower($term);
  402. $pros = Pro::where(function ($q) use ($term) {
  403. $q->orWhereRaw('LOWER(name_first::text) LIKE ?', ['%' . $term . '%'])
  404. ->orWhereRaw('LOWER(name_last::text) LIKE ?', ['%' . $term . '%'])
  405. ->orWhereRaw('cell_number LIKE ?', ['%' . $term . '%']);
  406. });
  407. if($this->performer->pro && $this->performer->pro->pro_type != 'ADMIN'){
  408. $accessiblePros = ProProAccess::where('owner_pro_id', $this->performer->pro->id);
  409. $accessibleProIds = [];
  410. foreach($accessiblePros as $accessiblePro){
  411. $accessibleProIds[] = $accessiblePro->id;
  412. }
  413. $accessibleProIds[] = $this->performer->pro->id;
  414. $pros->whereIn('id', $accessibleProIds);
  415. }
  416. $suggestedPros = $pros->orderBy('name_last')->orderBy('name_first')->get();
  417. return view('app/pro-suggest', compact('suggestedPros'));
  418. }
  419. public function proDisplayName(Request $request, Pro $pro) {
  420. return $pro ? $pro->displayName() : '';
  421. }
  422. public function unmappedSMS(Request $request, $filter = '')
  423. {
  424. $proID = $this->performer()->pro->id;
  425. if ($this->performer()->pro->pro_type === 'ADMIN') {
  426. $query = Client::where('id', '>', 0);
  427. } else {
  428. $query = Client::where(function ($q) use ($proID) {
  429. $q->where('mcp_pro_id', $proID)
  430. ->orWhere('cm_pro_id', $proID)
  431. ->orWhere('rmm_pro_id', $proID)
  432. ->orWhere('rme_pro_id', $proID)
  433. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID]);
  434. });
  435. }
  436. $patients = $query->orderBy('name_last', 'asc')->orderBy('name_first', 'asc')->get();
  437. $unmappedSMS = ClientSMS::where('client_id', null)->where('incoming_or_outgoing', 'INCOMING')->get();
  438. return view('app/unmapped-sms', compact('unmappedSMS', 'patients'));
  439. }
  440. public function newPatient(Request $request)
  441. {
  442. $mbPayers = MBPayer::all();
  443. return view('app/new-patient', compact('mbPayers'));
  444. }
  445. public function newNonMcnPatient(Request $request)
  446. {
  447. $mbPayers = MBPayer::all();
  448. return view('app/new-non-mcn-patient', compact('mbPayers'));
  449. }
  450. public function mc(Request $request, $fragment = "")
  451. {
  452. $page = "/";
  453. if ($fragment) {
  454. $page = '/' . $fragment;
  455. }
  456. return view('app/mc', compact('page'));
  457. }
  458. public function blank(Request $request)
  459. {
  460. return view('app/blank');
  461. }
  462. public function noteTemplateSet(Request $request, $section, $template)
  463. {
  464. return view('app/patient/note/_template', [
  465. "sectionInternalName" => $section,
  466. "templateName" => $template
  467. ]);
  468. }
  469. public function noteExamTemplateSet(Request $request, $exam, $template)
  470. {
  471. return view('app/patient/note/_template-exam', [
  472. "exam" => $exam,
  473. "sectionInternalName" => 'exam-' . $exam . '-detail',
  474. "templateName" => $template
  475. ]);
  476. }
  477. public function logInAs(Request $request)
  478. {
  479. if($this->pro->pro_type != 'ADMIN'){
  480. return redirect()->to(route('dashboard'));
  481. }
  482. $pros = Pro
  483. ::where('pro_type', '!=', 'ADMIN')
  484. ->orWhereNull('pro_type')
  485. ->orderBy('name_last', 'asc')
  486. ->orderBy('name_first', 'asc')
  487. ->get();
  488. return view('app/log-in-as', compact('pros'));
  489. }
  490. public function processLogInAs(Request $request)
  491. {
  492. $api = new Backend();
  493. try {
  494. $apiResponse = $api->post('session/proLogInAs', [
  495. 'proUid' => $request->post('proUid')
  496. ],
  497. [
  498. 'sessionKey'=>$this->performer()->session_key
  499. ]);
  500. $data = json_decode($apiResponse->getContents());
  501. if (!property_exists($data, 'success') || !$data->success) {
  502. return redirect()->to(route('log-in-as'))->with('message', $data->message)
  503. ->withInput($request->input());
  504. }
  505. Cookie::queue('sessionKey', $data->data->sessionKey);
  506. return redirect('/mc');
  507. } catch (\Exception $e) {
  508. return redirect()->to(route('log-in-as'))
  509. ->with('message', 'Unable to process your request at the moment. Please try again later.')
  510. ->withInput($request->input());
  511. }
  512. }
  513. public function backToAdminPro(Request $request){
  514. $adminPerformerId = $this->performer->logged_in_as_pro_from_admin_pro_app_session_id;
  515. $adminPerformer = AppSession::where('id', $adminPerformerId)->first();
  516. $url = "/session/pro_log_in_with_session_key/".$adminPerformer->session_key;
  517. $api = new Backend();
  518. try {
  519. $apiResponse = $api->post($url, []);
  520. $data = json_decode($apiResponse->getContents());
  521. if (!property_exists($data, 'success') || !$data->success) {
  522. return redirect()->to(route('logout'));
  523. }
  524. Cookie::queue('sessionKey', $data->data->sessionKey);
  525. return redirect(route('dashboard'));
  526. } catch (\Exception $e) {
  527. return redirect(route('dashboard'));
  528. }
  529. }
  530. }