McpController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\BDTDevice;
  5. use App\Models\CareMonth;
  6. use App\Models\Client;
  7. use App\Models\ClientBDTDevice;
  8. use App\Models\ClientInfoLine;
  9. use App\Models\Erx;
  10. use App\Models\Facility;
  11. use App\Models\Handout;
  12. use App\Models\IncomingReport;
  13. use App\Models\MBClaim;
  14. use App\Models\MBPayer;
  15. use App\Models\Note;
  16. use App\Models\NoteTemplate;
  17. use App\Models\Pro;
  18. use App\Models\Product;
  19. use App\Models\ProProAccess;
  20. use App\Models\SectionTemplate;
  21. use App\Models\Shipment;
  22. use App\Models\SupplyOrder;
  23. use App\Models\Ticket;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\DB;
  26. use Illuminate\Support\Facades\File;
  27. use App\Models\Bill;
  28. use App\Models\ClientSMS;
  29. use App\Models\AccountInvite;
  30. use App\Models\ClientMemo;
  31. use Illuminate\Support\Facades\Http;
  32. use PDF;
  33. class McpController extends Controller
  34. {
  35. public function patients(Request $request)
  36. {
  37. $filters = $request->all();
  38. $patients = Client::whereNull('shadow_pro_id')->where('mcp_pro_id', $this->performer->pro->id);
  39. // filters
  40. /*
  41. array:18 [▼
  42. "age_category" => "LESS_THAN"
  43. "age_value_1" => "34"
  44. "age_value_2" => null
  45. "sex" => "M"
  46. "bmi_category" => "BETWEEN"
  47. "bmi_value_1" => "20"
  48. "bmi_value_2" => "25"
  49. "last_visit_category" => "LESS_THAN"
  50. "last_visit_value_1" => "2021-10-14"
  51. "last_visit_value_2" => null
  52. "next_appointment_category" => "LESS_THAN"
  53. "next_appointment_value_1" => "2021-10-15"
  54. "status" => "ACTIVE"
  55. "last_weighed_in_category" => "EXACTLY"
  56. "last_weighed_in_value_1" => "2021-10-07"
  57. "last_bp_category" => "BETWEEN"
  58. "last_bp_value_1" => "2021-10-01"
  59. "last_bp_value_2" => "2021-10-31"
  60. ]
  61. */
  62. if ($request->input('name')) {
  63. $name = trim($request->input('name'));
  64. if ($name) {
  65. $patients = $patients->where(function ($q) use ($name) {
  66. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  67. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  68. });
  69. }
  70. }
  71. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  72. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  73. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  74. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  75. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  76. switch($request->input('status')) {
  77. case 'ACTIVE':
  78. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  79. break;
  80. case 'AWAITING_VISIT':
  81. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  82. break;
  83. case 'INACTIVE':
  84. $patients->where('is_active', '<>', true);
  85. break;
  86. }
  87. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  88. return view('app.mcp.patients', compact('patients', 'filters'));
  89. }
  90. public function notes(Request $request)
  91. {
  92. $filters = $request->all();
  93. $notes = Note::query();
  94. $notes = $notes->where('hcp_pro_id', $this->performer->pro->id);
  95. $this->filterMultiQuery($request, $notes, 'effective_time', 'date_category', 'date_value_1', 'date_value_2');
  96. $this->filterSimpleQuery($request, $notes, 'new_or_fu_or_na', 'new_or_fu_or_na');
  97. $notes = $notes->orderBy('created_at', 'DESC')->paginate(20);
  98. return view('app.mcp.notes', compact('notes','filters'));
  99. }
  100. public function appointments(Request $request)
  101. {
  102. $filters = $request->all();
  103. $appointments = Appointment::where('pro_id', $this->performer->pro->id);
  104. $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  105. $this->filterSimpleQuery($request, $appointments, 'status', 'status');
  106. $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
  107. return view('app.mcp.appointments', compact('appointments', 'filters'));
  108. }
  109. public function bills(Request $request)
  110. {
  111. $filters = $request->all();
  112. $bills = Bill::where('hcp_pro_id', $this->performer->pro->id);
  113. $this->filterMultiQuery($request, $bills, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  114. $status = $request->get('status');
  115. if($status){
  116. if($status == 'CANCELLED') $bills = $bills->where('is_cancelled', true);
  117. if($status == 'NOT_CANCELLED') $bills = $bills->where('is_cancelled', false);
  118. }
  119. $bills = $bills->orderBy('created_at', 'DESC')->paginate(20);
  120. return view('app.mcp.bills', compact('bills', 'filters'));
  121. }
  122. public function clients_bdt_devices(Request $request){
  123. $filters = $request->all();
  124. $devices = ClientBDTDevice::select('client_bdt_device.*')
  125. ->join('client', 'client.id', '=', 'client_bdt_device.client_id')
  126. ->where('client.mcp_pro_id', $this->performer->pro->id);
  127. $this->filterMultiQuery($request, $devices, 'client_bdt_device.created_at', 'date_category', 'date_value_1', 'date_value_2');
  128. $status = $request->get('status');
  129. if($status){
  130. if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
  131. if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
  132. }
  133. $devices = $devices->orderBy('created_at', 'DESC')->paginate(20);
  134. return view('app.mcp.clients_bdt_devices', compact('devices', 'filters'));
  135. }
  136. public function memos(Request $request){
  137. $filters = $request->all();
  138. $memos = ClientMemo::select('client_memo.*')
  139. ->join('client', 'client.id', '=', 'client_memo.client_id')
  140. ->where('client.mcp_pro_id', $this->performer->pro->id);
  141. $this->filterMultiQuery($request, $memos, 'client_memo.created_at', 'date_category', 'date_value_1', 'date_value_2');
  142. $this->filterSimpleQuery($request, $memos, 'category', 'category');
  143. $memos = $memos->orderBy('created_at', 'DESC')->paginate(20);
  144. return view('app.mcp.memos', compact('memos', 'filters'));
  145. }
  146. public function erx_and_orders(Request $request)
  147. {
  148. $filters = $request->all();
  149. $erxAndOrders = Erx::query();
  150. $erxAndOrders = $erxAndOrders->where('hcp_pro_id', $this->performer->pro->id);
  151. $this->filterMultiQuery($request, $erxAndOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  152. $this->filterSimpleQuery($request, $erxAndOrders, 'pro_declared_status', 'status');
  153. $erxAndOrders = $erxAndOrders->orderBy('created_at', 'DESC')->paginate(20);
  154. return view('app.mcp.erx_and_orders', compact('erxAndOrders', 'filters'));
  155. }
  156. public function reports(Request $request)
  157. {
  158. $filters = $request->all();
  159. $reports = IncomingReport::where('hcp_pro_id', $this->performer->pro->id);
  160. $this->filterMultiQuery($request, $reports, 'report_date', 'date_category', 'date_value_1', 'date_value_2');
  161. $status = $request->get('status');
  162. if($status){
  163. if($status == 'SIGNED') $reports = $reports->where('has_hcp_pro_signed', true);
  164. if($status == 'NOT_SIGNED') $reports = $reports->where('has_hcp_pro_signed', false);
  165. }
  166. $reports = $reports->orderBy('created_at', 'DESC')->paginate(20);
  167. return view('app.mcp.reports', compact('reports', 'filters'));
  168. }
  169. public function supply_orders(Request $request)
  170. {
  171. $filters = $request->all();
  172. $supplyOrders = SupplyOrder::select('supply_order.*')->where('supply_order.signed_by_pro_id', $this->performer->pro->id);
  173. $this->filterMultiQuery($request, $supplyOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  174. $status = $request->get('status');
  175. if($status){
  176. if($status == 'CLEARED_FOR_SHIPMENT'){
  177. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', true);
  178. }elseif($status == 'NOT_CLEARED_FOR_SHIPMENT'){
  179. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', false);
  180. }elseif($status == 'CANCELLED'){
  181. $supplyOrders = $supplyOrders->where('is_cancelled', true);
  182. }else{
  183. $supplyOrders = $supplyOrders->join('shipment', 'shipment.id', '=', 'supply_order.shipment_id')->where('shipment.status', $status);
  184. }
  185. }
  186. $supplyOrders = $supplyOrders->orderBy('created_at', 'DESC')->paginate(20);
  187. return view('app.mcp.supply_orders', compact('supplyOrders', 'filters'));
  188. }
  189. public function client_messages(Request $request)
  190. {
  191. $filters = $request->all();
  192. $clientMessages = ClientSMS::select('client_sms.*')
  193. ->join('client', 'client.id', '=', 'client_sms.client_id')
  194. ->where('client.mcp_pro_id', $this->performer->pro->id);
  195. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  196. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  197. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  198. $clientMessages = $clientMessages->paginate(20);
  199. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  200. }
  201. public function patients_accounts_invites(Request $request){
  202. $filters = $request->all();
  203. $accountInvites = AccountInvite::select('account_invite.*')
  204. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  205. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  206. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  207. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  208. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  209. return view('app.mcp.patients-accounts-invites', compact('accountInvites', 'filters'));
  210. }
  211. public function new_patients_awaiting_visit(Request $request){
  212. $data = [
  213. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  214. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  215. ->orderBy('created_at')
  216. ->get()
  217. ];
  218. return view('app.mcp.new_patients_awaiting_visit', $data);
  219. }
  220. public function notes_pending_signature(Request $request){
  221. $data = [
  222. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  223. ->where('is_cancelled', '<>', true)
  224. ->where('is_signed_by_hcp', '<>', true)
  225. ->where('is_core_note', false)
  226. ->orderBy('created_at')
  227. ->get()
  228. ];
  229. return view('app.mcp.notes_pending_signature', $data);
  230. }
  231. public function notes_pending_billing(Request $request){
  232. $data = [
  233. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  234. ->where('is_cancelled', '<>', true)
  235. ->where('is_signed_by_hcp', true)
  236. ->where('is_billing_marked_done', '<>', true)
  237. ->orderBy('created_at')
  238. ->get()
  239. ];
  240. return view('app.mcp.notes_pending_billing', $data);
  241. }
  242. public function reports_pending_signature(Request $request){
  243. $data = [
  244. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  245. ->where('has_hcp_pro_signed', '<>', true)
  246. ->where('is_entry_error', '<>', true)
  247. ->orderBy('created_at')
  248. ->get()
  249. ];
  250. return view('app.mcp.reports_pending_signature', $data);
  251. }
  252. public function patients_without_appointments(Request $request){
  253. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  254. return view('app.mcp.patients_without_appointments', compact('patients'));
  255. }
  256. public function patients_overdue_for_visit(Request $request){
  257. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  258. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  259. }
  260. public function cancelled_appointments_pending_review(Request $request){
  261. $data = [];
  262. return view('app.mcp.cancelled_appointments_pending_review', $data);
  263. }
  264. public function cancelled_bills_pending_review(Request $request){
  265. $data = [
  266. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  267. ->where('bill_service_type', 'NOTE')
  268. ->where('is_cancelled', true)
  269. ->where('is_cancellation_acknowledged', '<>', true)
  270. ->orderBy('created_at')
  271. ->get()
  272. ];
  273. return view('app.mcp.cancelled_bills_pending_review', $data);
  274. }
  275. public function cancelled_supply_orders_pending_review(Request $request){
  276. $data = [
  277. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  278. ->where('is_cancelled', true)
  279. ->where('is_cancellation_acknowledged', '<>', true)
  280. ->orderBy('created_at')
  281. ->get()
  282. ];
  283. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  284. }
  285. public function erx_and_orders_pending_signature(Request $request){
  286. $data = [
  287. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  288. ->where('pro_declared_status', '<>', 'CANCELLED')
  289. ->where('has_hcp_pro_signed', '<>', true)
  290. ->orderBy('created_at')
  291. ->get()
  292. ];
  293. return view('app.mcp.erx_and_orders_pending_signature', $data);
  294. }
  295. public function supply_orders_pending_signature(Request $request){
  296. $data = [
  297. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  298. ->whereNull('signed_by_pro_id')
  299. ->where('is_cancelled', '<>', true)
  300. ->orderBy('created_at')
  301. ->get()
  302. ];
  303. return view('app.mcp.supply_orders_pending_signature', $data);
  304. }
  305. public function supply_orders_awaiting_shipment(Request $request){
  306. $data = [
  307. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  308. ->where('is_signed_by_pro', true)
  309. ->where('is_cleared_for_shipment', true)
  310. ->whereNull('shipment_id')
  311. ->orderBy('created_at')
  312. ->get()
  313. ];
  314. return view('app.mcp.supply_orders_awaiting_shipment', $data);
  315. }
  316. public function measurements_pending_stamping(Request $request){
  317. $data = [
  318. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  319. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  320. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  321. ->orderBy('created_at', 'DESC')
  322. ->paginate(15)
  323. ];
  324. return view('app.mcp.measurements_pending_stamping', $data);
  325. }
  326. }