McpController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 Illuminate\Support\Facades\Http;
  30. use PDF;
  31. class McpController extends Controller
  32. {
  33. public function patients(Request $request)
  34. {
  35. $filters = $request->all();
  36. $patients = Client::whereNull('shadow_pro_id')->where('mcp_pro_id', $this->performer->pro->id);
  37. // filters
  38. /*
  39. array:18 [▼
  40. "age_category" => "LESS_THAN"
  41. "age_value_1" => "34"
  42. "age_value_2" => null
  43. "sex" => "M"
  44. "bmi_category" => "BETWEEN"
  45. "bmi_value_1" => "20"
  46. "bmi_value_2" => "25"
  47. "last_visit_category" => "LESS_THAN"
  48. "last_visit_value_1" => "2021-10-14"
  49. "last_visit_value_2" => null
  50. "next_appointment_category" => "LESS_THAN"
  51. "next_appointment_value_1" => "2021-10-15"
  52. "status" => "ACTIVE"
  53. "last_weighed_in_category" => "EXACTLY"
  54. "last_weighed_in_value_1" => "2021-10-07"
  55. "last_bp_category" => "BETWEEN"
  56. "last_bp_value_1" => "2021-10-01"
  57. "last_bp_value_2" => "2021-10-31"
  58. ]
  59. */
  60. if ($request->input('name')) {
  61. $name = trim($request->input('name'));
  62. if ($name) {
  63. $patients = $patients->where(function ($q) use ($name) {
  64. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  65. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  66. });
  67. }
  68. }
  69. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  70. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  71. $this->filterMultiQuery($request, $patients, 'usual_bmi', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  72. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  73. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  74. switch($request->input('status')) {
  75. case 'ACTIVE':
  76. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  77. break;
  78. case 'AWAITING_VISIT':
  79. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  80. break;
  81. case 'INACTIVE':
  82. $patients->where('is_active', '<>', true);
  83. break;
  84. }
  85. $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
  86. return view('app.mcp.patients', compact('patients', 'filters'));
  87. }
  88. private function filterSimpleQuery(Request $request, $query, $columnName, $valueName) {
  89. if($request->input($valueName)) {
  90. $query->where($columnName, $request->input($valueName));
  91. }
  92. }
  93. private function filterMultiQuery(Request $request, $query, $columnName, $keyName, $valueName1, $valueName2) {
  94. switch($request->input($keyName)) {
  95. case 'EXACTLY':
  96. if($request->input($valueName1)) {
  97. $query->where($columnName, $request->input($valueName1));
  98. }
  99. break;
  100. case 'LESS_THAN':
  101. if($request->input($valueName1)) {
  102. $query->where($columnName, '<', $request->input($valueName1));
  103. }
  104. break;
  105. case 'GREATER_THAN':
  106. if($request->input($valueName1)) {
  107. $query->where($columnName, '>', $request->input($valueName1));
  108. }
  109. break;
  110. case 'BETWEEN':
  111. if($request->input($valueName1) && $request->input($valueName2)) {
  112. $query
  113. ->where($columnName, '>=', $request->input($valueName1))
  114. ->where($columnName, '<=', $request->input($valueName2));
  115. }
  116. break;
  117. case 'NOT_BETWEEN':
  118. if($request->input($valueName1) && $request->input($valueName2)) {
  119. $query
  120. ->where(function ($q) use ($request, $columnName, $valueName1, $valueName2) {
  121. $q->where($columnName, '<', $request->input($valueName1))
  122. ->orWhere($columnName, '>', $request->input($valueName2));
  123. });
  124. }
  125. break;
  126. }
  127. }
  128. public function notes(Request $request)
  129. {
  130. $notes = Note::paginate(5);
  131. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  132. return view('app.mcp.notes', compact('notes'));
  133. }
  134. public function appointments(Request $request)
  135. {
  136. $appointments = Appointment::paginate(5);
  137. return view('app.mcp.appointments', compact('appointments'));
  138. }
  139. public function bills(Request $request)
  140. {
  141. $bills = Bill::paginate(5);
  142. return view('app.mcp.bills', compact('bills'));
  143. }
  144. public function erx_and_orders(Request $request)
  145. {
  146. $erxAndOrders = Erx::paginate(5);
  147. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  148. }
  149. public function reports(Request $request)
  150. {
  151. $data = [];
  152. return view('app.mcp.reports', $data);
  153. }
  154. public function supply_orders(Request $request)
  155. {
  156. $supplyOrders = SupplyOrder::paginate(5);
  157. return view('app.mcp.supply_orders', compact('supplyOrders'));
  158. }
  159. public function client_messages(Request $request)
  160. {
  161. $filters = $request->all();
  162. $clientMessages = ClientSMS::select('client_sms.*')
  163. ->join('client', 'client.id', '=', 'client_sms.client_id')
  164. ->where('client.mcp_pro_id', $this->performer->pro->id);
  165. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  166. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  167. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  168. $clientMessages = $clientMessages->paginate(20);
  169. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  170. }
  171. public function new_patients_awaiting_visit(Request $request){
  172. $data = [
  173. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  174. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  175. ->orderBy('created_at')
  176. ->get()
  177. ];
  178. return view('app.mcp.new_patients_awaiting_visit', $data);
  179. }
  180. public function notes_pending_signature(Request $request){
  181. $data = [
  182. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  183. ->where('is_cancelled', '<>', true)
  184. ->where('is_signed_by_hcp', '<>', true)
  185. ->where('is_core_note', false)
  186. ->orderBy('created_at')
  187. ->get()
  188. ];
  189. return view('app.mcp.notes_pending_signature', $data);
  190. }
  191. public function notes_pending_billing(Request $request){
  192. $data = [
  193. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  194. ->where('is_cancelled', '<>', true)
  195. ->where('is_signed_by_hcp', true)
  196. ->where('is_billing_marked_done', '<>', true)
  197. ->orderBy('created_at')
  198. ->get()
  199. ];
  200. return view('app.mcp.notes_pending_billing', $data);
  201. }
  202. public function reports_pending_signature(Request $request){
  203. $data = [
  204. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  205. ->where('has_hcp_pro_signed', '<>', true)
  206. ->where('is_entry_error', '<>', true)
  207. ->orderBy('created_at')
  208. ->get()
  209. ];
  210. return view('app.mcp.reports_pending_signature', $data);
  211. }
  212. public function patients_without_appointments(Request $request){
  213. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  214. return view('app.mcp.patients_without_appointments', compact('patients'));
  215. }
  216. public function patients_overdue_for_visit(Request $request){
  217. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  218. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  219. }
  220. public function cancelled_appointments_pending_review(Request $request){
  221. $data = [];
  222. return view('app.mcp.cancelled_appointments_pending_review', $data);
  223. }
  224. public function cancelled_bills_pending_review(Request $request){
  225. $data = [
  226. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  227. ->where('bill_service_type', 'NOTE')
  228. ->where('is_cancelled', true)
  229. ->where('is_cancellation_acknowledged', '<>', true)
  230. ->orderBy('created_at')
  231. ->get()
  232. ];
  233. return view('app.mcp.cancelled_bills_pending_review', $data);
  234. }
  235. public function cancelled_supply_orders_pending_review(Request $request){
  236. $data = [
  237. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  238. ->where('is_cancelled', true)
  239. ->where('is_cancellation_acknowledged', '<>', true)
  240. ->orderBy('created_at')
  241. ->get()
  242. ];
  243. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  244. }
  245. public function erx_and_orders_pending_signature(Request $request){
  246. $data = [
  247. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  248. ->where('pro_declared_status', '<>', 'CANCELLED')
  249. ->where('has_hcp_pro_signed', '<>', true)
  250. ->orderBy('created_at')
  251. ->get()
  252. ];
  253. return view('app.mcp.erx_and_orders_pending_signature', $data);
  254. }
  255. public function supply_orders_pending_signature(Request $request){
  256. $data = [
  257. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  258. ->whereNull('signed_by_pro_id')
  259. ->where('is_cancelled', '<>', true)
  260. ->orderBy('created_at')
  261. ->get()
  262. ];
  263. return view('app.mcp.supply_orders_pending_signature', $data);
  264. }
  265. public function measurements_pending_stamping(Request $request){
  266. $data = [
  267. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  268. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  269. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  270. ->orderBy('created_at', 'DESC')
  271. ->paginate(15)
  272. ];
  273. return view('app.mcp.measurements_pending_stamping', $data);
  274. }
  275. }