AdminController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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\InternalMessage;
  14. use App\Models\MBClaim;
  15. use App\Models\MBPayer;
  16. use App\Models\Note;
  17. use App\Models\NoteTemplate;
  18. use App\Models\Pro;
  19. use App\Models\Product;
  20. use App\Models\ProProAccess;
  21. use App\Models\SectionTemplate;
  22. use App\Models\Shipment;
  23. use App\Models\SupplyOrder;
  24. use App\Models\Ticket;
  25. use Illuminate\Http\Request;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Support\Facades\File;
  28. use App\Models\Bill;
  29. use App\Models\ClientSMS;
  30. use App\Models\Point;
  31. use Illuminate\Support\Facades\Http;
  32. use PDF;
  33. use Illuminate\Support\Facades\Schema;
  34. use App\Models\AdminPatient;
  35. use App\Models\BDTDeviceView;
  36. use App\Models\SupplyOrderView;
  37. class AdminController extends Controller
  38. {
  39. public function patients(Request $request)
  40. {
  41. $filters = $request->all();
  42. $patients = AdminPatient::whereNull('shadow_pro_id');
  43. if ($request->input('name')) {
  44. $name = trim($request->input('name'));
  45. if ($name) {
  46. $patients = $patients->where(function ($q) use ($name) {
  47. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  48. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  49. });
  50. }
  51. }
  52. if ($request->input('mcp')) {
  53. if($request->input('mcp') == 'NO_MCP'){
  54. $patients = $patients->whereNull('mcp_pro_id');
  55. }else{
  56. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  57. if ($mcp) {
  58. $patients = $patients->where('mcp_pro_id', $mcp->id);
  59. }
  60. }
  61. }
  62. if ($request->input('na')) {
  63. if($request->input('na') == 'NO_NA'){
  64. $patients = $patients->whereNull('default_na_pro_id');
  65. }else{
  66. $na = Pro::where('uid', trim($request->input('na')))->first();
  67. if ($na) {
  68. $patients = $patients->where('default_na_pro_id', $na->id);
  69. }
  70. }
  71. }
  72. if ($request->input('ob')) {
  73. if ($request->input('ob') == 'yes') {
  74. $patients = $patients->where('has_mcp_done_onboarding_visit', 'YES');
  75. } else {
  76. $patients = $patients->where('has_mcp_done_onboarding_visit', '!=', 'YES');
  77. }
  78. }
  79. if ($request->input('next_appointment_category')) {
  80. if($request->input('next_appointment_category') == 'NONE'){
  81. $patients = $patients->whereNull('next_mcp_appointment_id');
  82. }else{
  83. $self = $this;
  84. $patients = $patients->whereHas('nextMcpAppointment', function($pQry) use ($request, $self){
  85. return $self->filterMultiQuery($request, $pQry, 'raw_date', 'next_appointment_category', 'next_appointment_value_1', 'next_appointment_value_2');
  86. });
  87. }
  88. }
  89. if ($request->input('chart_number')) {
  90. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  91. }
  92. if ($request->input('home_address_state')) {
  93. if($request->input('home_address_state') == 'NONE'){
  94. $patients = $patients->whereRaw("mailing_address_state IS NULL OR TRIM(BOTH FROM mailing_address_state = ''");
  95. }else if($request->input('home_address_state') == 'NOT_MD'){
  96. $patients = $patients->whereRaw("(TRIM(BOTH FROM mailing_address_state) NOT ILIKE 'MD' AND TRIM(BOTH FROM mailing_address_state) NOT ILIKE 'MARYLAND')");
  97. }else{
  98. $patients = $patients->whereRaw("TRIM(BOTH FROM mailing_address_state) = '" . $request->input('home_address_state') . "'");
  99. }
  100. }
  101. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2', false);
  102. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  103. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2', false);
  104. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  105. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  106. $this->filterMultiQuery($request, $patients, 'created_at', 'created_at', 'created_at_value_1', 'created_at_value_2');
  107. $this->filterMultiQuery($request, $patients, 'most_recent_completed_mcp_note_date', 'last_visit_category', 'last_visit_value_1', 'last_visit_value_2');
  108. $fVal = $request->input('has_email');
  109. if($fVal) {
  110. if($fVal === 'YES') {
  111. $patients = $patients->whereRaw("(email_address IS NOT NULL AND TRIM(email_address) != '')");
  112. }
  113. else {
  114. $patients = $patients->whereRaw("(email_address IS NULL OR TRIM(email_address) = '')");
  115. }
  116. }
  117. $fVal = $request->input('has_account');
  118. if($fVal) {
  119. if($fVal === 'YES') {
  120. $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = admin_patient_list.id) > 0)");
  121. }
  122. else {
  123. $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = admin_patient_list.id) = 0)");
  124. }
  125. }
  126. $fVal = $request->input('has_default_mcp_company_pro');
  127. if($fVal) {
  128. if($fVal === 'YES') {
  129. $patients = $patients->whereRaw("(default_mcp_company_pro_id IS NOT NULL)");
  130. }
  131. else {
  132. $patients = $patients->whereRaw("(default_mcp_company_pro_id IS NULL)");
  133. }
  134. }
  135. $fVal = $request->input('has_default_mcp_company_pro_payer');
  136. if($fVal) {
  137. if($fVal === 'YES') {
  138. $patients = $patients->whereRaw("(default_mcp_company_pro_payer_id IS NOT NULL)");
  139. }
  140. else {
  141. $patients = $patients->whereRaw("(default_mcp_company_pro_payer_id IS NULL)");
  142. }
  143. }
  144. $fVal = $request->input('has_default_mcp_company_location');
  145. if($fVal) {
  146. if($fVal === 'YES') {
  147. $patients = $patients->whereRaw("(default_mcp_company_location_id IS NOT NULL)");
  148. }
  149. else {
  150. $patients = $patients->whereRaw("(default_mcp_company_location_id IS NULL)");
  151. }
  152. }
  153. $fVal = $request->input('has_bp_device');
  154. if($fVal) {
  155. if($fVal === 'YES') {
  156. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  157. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  158. "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
  159. }
  160. else {
  161. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  162. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  163. "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
  164. }
  165. }
  166. $fVal = $request->input('has_weight_scale');
  167. if($fVal) {
  168. if($fVal === 'YES') {
  169. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  170. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  171. "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
  172. }
  173. else {
  174. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  175. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  176. "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
  177. }
  178. }
  179. $fVal = $request->input('has_pulse_ox');
  180. if($fVal) {
  181. if($fVal === 'YES') {
  182. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  183. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  184. "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
  185. }
  186. else {
  187. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  188. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  189. "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
  190. }
  191. }
  192. $fVal = $request->input('has_temp_fun');
  193. if($fVal) {
  194. if($fVal === 'YES') {
  195. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  196. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  197. "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
  198. }
  199. else {
  200. $patients = $patients->whereRaw("((SELECT count(sh.id) " .
  201. "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
  202. "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
  203. }
  204. }
  205. $fVal = $request->input('imei');
  206. if($fVal) {
  207. $patients = $patients->whereRaw("((SELECT count(cbd.id) FROM client_bdt_device cbd
  208. WHERE cbd.client_id = admin_patient_list.id AND cbd.device_id IN (SELECT bd.id FROM bdt_device bd WHERE bd.imei LIKE '%$fVal%' AND bd.is_active IS TRUE)) > 0)");
  209. }
  210. if($request->input('number_of_measurements')){
  211. $keyName = $request->input('number_of_measurements');
  212. $measurementCountQuery = '(SELECT COUNT(*) FROM measurement WHERE measurement.client_id = admin_patient_list.id AND is_active IS TRUE AND is_cellular IS TRUE AND is_cellular_zero IS NOT TRUE)';
  213. switch($keyName) {
  214. case 'EXACTLY':
  215. if($request->input('number_of_measurements_value_1')) {
  216. $patients->whereRaw($measurementCountQuery . '='.$request->input('number_of_measurements_value_1'));
  217. }
  218. break;
  219. case 'LESS_THAN':
  220. if($request->input('number_of_measurements_value_1')) {
  221. $patients->whereRaw($measurementCountQuery . '<='.$request->input('number_of_measurements_value_1'));
  222. }
  223. break;
  224. case 'GREATER_THAN':
  225. if($request->input('number_of_measurements_value_1')) {
  226. $patients->whereRaw($measurementCountQuery . '>='.$request->input('number_of_measurements_value_1'));
  227. }
  228. break;
  229. case 'BETWEEN':
  230. if($request->input('number_of_measurements_value_1') && $request->input('number_of_measurements_value_2')) {
  231. $patients->whereRaw($measurementCountQuery.'>='.$request->input('number_of_measurements_value_1') .' AND '. $measurementCountQuery . '<='.$request->input('number_of_measurements_value_2'));
  232. }
  233. break;
  234. case 'NOT_BETWEEN':
  235. if($request->input('number_of_measurements_value_1') && $request->input('number_of_measurements_value_2')) {
  236. $patients->where(function ($q) use ($request, $measurementCountQuery) {
  237. $q->whereRaw($measurementCountQuery . '<'.$request->input('number_of_measurements_value_1') .' OR '. $measurementCountQuery . '>'.$request->input('number_of_measurements_value_2'));
  238. });
  239. }
  240. break;
  241. }
  242. }
  243. $status = $request->input('status');
  244. if($status){
  245. if($status === 'ACTIVE'){
  246. $patients->where('is_active', true)->where(function($q) use ($status){
  247. return $q->where('client_engagement_status_category', $status)
  248. ->orWhereNull('client_engagement_status_category');
  249. });
  250. }elseif($status === 'NONE'){
  251. $patients->whereNull('client_engagement_status_category');
  252. }else {
  253. $patients->where('client_engagement_status_category', $status);
  254. }
  255. }
  256. $initiative = $request->input('initiative');
  257. if($initiative){
  258. $wildCardedInitiative = '%'.$initiative.'%';
  259. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  260. }
  261. $include_test_records = $request->input('include_test_records');
  262. if(!$include_test_records && $status != 'DUMMY'){
  263. $patients = $patients->where(function ($q) {
  264. $q->whereNull('client_engagement_status_category')
  265. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  266. });
  267. }
  268. $zero_deductible = $request->input('zero_deductible');
  269. if($zero_deductible){
  270. $patients = $patients->where(function ($q) {
  271. $q->where('mpb_remaining', 0);
  272. });
  273. }
  274. $insurance = $request->get('insurance');
  275. if($insurance){
  276. if($insurance === 'MEDICARE'){
  277. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery) {
  278. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  279. });
  280. }else{
  281. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery) use ($insurance){
  282. return $cpcQuery->where('commercial_payer_id', '=', $insurance);
  283. });
  284. }
  285. }
  286. $companyID = $request->get('company');
  287. if($companyID){
  288. if($companyID == 'NONE'){
  289. $patients = $patients->doesntHave('companyClients');
  290. }else{
  291. $patients = $patients->whereHas('companyClients', function($qry)use($companyID){
  292. if($companyID != 'ANY'){
  293. return $qry->where('company_id', $companyID);
  294. }
  295. });
  296. }
  297. }
  298. $sortBy = $request->input('sort_by') ?: 'name_first';
  299. $sortDir = $request->input('sort_dir') ?: 'ASC';
  300. $sortBySQL = "$sortBy $sortDir NULLS LAST";
  301. if($sortBy !== 'client_engagement_status_category' && $request->input('status')) {
  302. $sortBySQL = "client_engagement_status_category DESC NULLS LAST";
  303. }
  304. if(@$filters['mapView'] == 1){
  305. $patients = $patients->orderByRaw($sortBySQL)->paginate(100);
  306. }else{
  307. $patients = $patients->orderByRaw($sortBySQL)->paginate(25);
  308. }
  309. $insurances = DB::select('SELECT DISTINCT commercial_payer_name, commercial_payer_id FROM client_primary_coverage WHERE commercial_payer_name IS NOT NULL ORDER BY commercial_payer_name ASC');
  310. return view('app.admin.patients', compact('patients', 'filters', 'insurances'));
  311. }
  312. public function partBPatients(Request $request){
  313. $filters = $request->all();
  314. $patients = Client::whereNull('shadow_pro_id');
  315. if ($request->input('name')) {
  316. $name = trim($request->input('name'));
  317. if ($name) {
  318. $patients = $patients->where(function ($q) use ($name) {
  319. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  320. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  321. });
  322. }
  323. }
  324. if ($request->input('mcp')) {
  325. if($request->input('mcp') == 'NO_MCP'){
  326. $patients = $patients->whereNull('mcp_pro_id');
  327. }else{
  328. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  329. if ($mcp) {
  330. $patients = $patients->where('mcp_pro_id', $mcp->id);
  331. }
  332. }
  333. }
  334. if ($request->input('na')) {
  335. if($request->input('na') == 'NO_NA'){
  336. $patients = $patients->whereNull('default_na_pro_id');
  337. }else{
  338. $na = Pro::where('uid', trim($request->input('na')))->first();
  339. if ($na) {
  340. $patients = $patients->where('default_na_pro_id', $na->id);
  341. }
  342. }
  343. }
  344. if ($request->input('next_appointment_category')) {
  345. if($request->input('next_appointment_category') == 'NONE'){
  346. $patients = $patients->whereNull('next_mcp_appointment_id');
  347. }
  348. }
  349. if ($request->input('chart_number')) {
  350. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  351. }
  352. if ($request->input('home_address_state')) {
  353. if($request->input('home_address_state') == 'NONE'){
  354. $patients = $patients->whereNull('mailing_address_state');
  355. }else if($request->input('home_address_state') == 'NOT_MD'){
  356. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  357. }else{
  358. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  359. }
  360. }
  361. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2', false);
  362. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  363. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2', false);
  364. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  365. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  366. if($request->input('deductible')){
  367. $keyName = $request->input('deductible');
  368. switch($keyName) {
  369. case 'EXACTLY':
  370. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  371. return $q->where('auto_medicare_mpb_deductible', '=', $request->input('deductible_value_1'));
  372. });
  373. break;
  374. case 'LESS_THAN':
  375. if($request->input('deductible_value_1')) {
  376. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  377. return $q->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_1'));
  378. });
  379. }
  380. break;
  381. case 'GREATER_THAN':
  382. if($request->input('deductible_value_1')) {
  383. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  384. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'));
  385. });
  386. }
  387. break;
  388. case 'BETWEEN':
  389. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  390. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'))
  391. ->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_2'));
  392. });
  393. break;
  394. case 'NOT_BETWEEN':
  395. if($request->input('deductible_value_1') && $request->input('deductible_value_2')) {
  396. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  397. return $q->where(function($qq) use ($request){
  398. return $qq->where('auto_medicare_mpb_deductible', '<', $request->input('deductible_value_1'))
  399. ->orWhere('auto_medicare_mpb_deductible', '>', $request->input('deductible_value_2'));
  400. });
  401. });
  402. }
  403. break;
  404. }
  405. }
  406. switch($request->input('status')) {
  407. case 'ACTIVE':
  408. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  409. break;
  410. case 'AWAITING_VISIT':
  411. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  412. break;
  413. case 'INACTIVE':
  414. $patients->where('is_active', '<>', true);
  415. break;
  416. }
  417. $initiative = $request->input('initiative');
  418. if($initiative){
  419. $wildCardedInitiative = '%'.$initiative.'%';
  420. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  421. }
  422. $include_test_records = $request->input('include_test_records');
  423. if(!$include_test_records){
  424. $patients = $patients->where(function ($q) {
  425. return $q->whereNull('client_engagement_status_category')
  426. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  427. });
  428. }
  429. $with_claim_not_closed = $request->input('with_claim_not_closed');
  430. if($with_claim_not_closed){
  431. $patients = $patients->whereHas('notes', function ($q) {
  432. return $q->where('is_claim_closed', false)
  433. ->where('is_signed_by_hcp', true)
  434. ->where('is_cancelled', false);
  435. });
  436. }
  437. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  438. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  439. });
  440. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  441. return view('app.admin.part_b_patients', compact('patients', 'filters'));
  442. }
  443. public function notes(Request $request)
  444. {
  445. $notes = Note::paginate(5);
  446. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  447. return view('app.mcp.notes', compact('notes'));
  448. }
  449. public function notes_pending_summary_suggestion(Request $request){
  450. $pro = $this->performer->pro;
  451. $data = [
  452. 'records' => $pro->get_notes_pending_summary_suggestion_as_admin()
  453. ];
  454. return view('app.admin.notes_pending_summary_suggestion', $data);
  455. }
  456. public function notes_rejected_summary_suggestion(Request $request){
  457. $pro = $this->performer->pro;
  458. $data = [
  459. 'records' => $pro->get_notes_rejected_summary_suggestion_as_admin()
  460. ];
  461. return view('app.admin.notes_rejected_summary_suggestion', $data);
  462. }
  463. public function appointments(Request $request)
  464. {
  465. $appointments = Appointment::paginate(5);
  466. return view('app.mcp.appointments', compact('appointments'));
  467. }
  468. public function bills(Request $request)
  469. {
  470. $bills = Bill::paginate(5);
  471. return view('app.mcp.bills', compact('bills'));
  472. }
  473. public function erx_and_orders(Request $request)
  474. {
  475. $erxAndOrders = Erx::paginate(5);
  476. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  477. }
  478. public function reports(Request $request)
  479. {
  480. $data = [];
  481. return view('app.mcp.reports', $data);
  482. }
  483. public function supply_orders(Request $request)
  484. {
  485. $supplyOrders = SupplyOrderView::paginate(5);
  486. return view('app.mcp.supply_orders', compact('supplyOrders'));
  487. }
  488. public function getCreateNewPatientScriptTemplate(Request $request){
  489. $template = $request->get('template');
  490. if(!$template) return $this->fail('No script template');
  491. $path = resource_path() . '/views/app/patient/create-patient/scripts/' . $template . '.blade.php';
  492. if(!File::exists($path)) return $this->fail('Invalid script template');
  493. $templateContent = file_get_contents($path);
  494. return $this->pass($templateContent);
  495. }
  496. public function bdtDevices(Request $request)
  497. {
  498. $filters = $request->all();
  499. $bdtDevices = BDTDeviceView::query();
  500. $imei = $request->input('imei');
  501. if($imei){
  502. $bdtDevices = $bdtDevices->where('imei', '=', $imei);
  503. }
  504. $client = $request->input('client');
  505. if($client){
  506. $client = '%'.$client.'%';
  507. $bdtDevices = $bdtDevices->where('client_name_first', 'ilike', $client)
  508. ->orWhere('client_name_last', 'ilike', $client)
  509. ->orWhere('client_cell_number', 'ilike', $client)
  510. ->orWhereRaw("client_name_first||' '||client_name_last ILIKE "."'".$client."'");
  511. }
  512. $is_issued = $request->input('is_issued');
  513. if($is_issued){
  514. if($is_issued == 'YES'){
  515. $bdtDevices = $bdtDevices->whereRaw('client_id IS NOT NULL');
  516. }
  517. if($is_issued == 'NO'){
  518. $bdtDevices = $bdtDevices->whereRaw('client_id IS NULL');
  519. }
  520. }
  521. $mcp = $request->input('mcp');
  522. if($mcp){
  523. $bdtDevices = $bdtDevices->where('client_mcp_pro_uid', $mcp);
  524. }
  525. $bdtDevices = $bdtDevices->paginate(20);
  526. return view('app.admin.bdt_devices', compact('bdtDevices', 'filters'));
  527. }
  528. public function patientsMissingDefasultSettings(Request $request){
  529. $filters = $request->all();
  530. $patients = Client::whereNull('shadow_pro_id');
  531. $patients = $patients->where(function($qry){
  532. return $qry->orWhereNull('mcp_pro_id')->orWhereNull('default_mcp_company_pro_id')->orWhereNull('default_mcp_company_pro_payer_id')->orWhereNull('default_mcp_company_location_id');
  533. });
  534. if ($request->input('name')) {
  535. $name = trim($request->input('name'));
  536. if ($name) {
  537. $patients = $patients->where(function ($q) use ($name) {
  538. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  539. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  540. });
  541. }
  542. }
  543. if ($request->input('mcp')) {
  544. if($request->input('mcp') == 'NO_MCP'){
  545. $patients = $patients->whereNull('mcp_pro_id');
  546. }else{
  547. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  548. if ($mcp) {
  549. $patients = $patients->where('mcp_pro_id', $mcp->id);
  550. }
  551. }
  552. }
  553. if ($request->input('chart_number')) {
  554. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  555. }
  556. $status = $request->input('status');
  557. if($status){
  558. if($status == 'ACTIVE'){
  559. $patients->where('is_active', true)->where(function($q) use ($status){
  560. return $q->where('client_engagement_status_category', $status)
  561. ->orWhereNull('client_engagement_status_category');
  562. });
  563. }else {
  564. $patients->where('client_engagement_status_category', $status);
  565. }
  566. }
  567. $insurance = $request->get('insurance');
  568. if($insurance){
  569. if($insurance === 'MEDICARE'){
  570. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  571. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  572. });
  573. }elseif($insurance === 'MEDICARE_PENDING'){
  574. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  575. return $cpcQuery->where('plan_type', 'MEDICARE')->where('is_covered', '!=', 'YES');
  576. });
  577. }elseif($insurance === 'NOT_COVERED'){
  578. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  579. return $cpcQuery->where('is_covered', '!=', 'YES');
  580. });
  581. }elseif($insurance === 'PENDING'){
  582. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  583. return $cpcQuery->where('is_covered', '=', 'UNKNOWN');
  584. });
  585. }
  586. else{
  587. $patients = $patients->whereDoesntHave('effectiveClientPrimaryCoverage', function($cpcQuery){
  588. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  589. });
  590. }
  591. }
  592. $missing_default_settings = $request->get('missing_default_settings');
  593. if($missing_default_settings){
  594. if($missing_default_settings === 'NO_MCP') $patients = $patients->whereNull('mcp_pro_id');
  595. if($missing_default_settings === 'NO_MCP_COMPANY_PRO') $patients = $patients->whereNull('default_mcp_company_pro_id');
  596. if($missing_default_settings === 'NO_MCP_COMPANY_PRO_PAYER') $patients = $patients->whereNull('default_mcp_company_pro_payer_id');
  597. if($missing_default_settings === 'NO_MCP_COMPANY_LOCATION') $patients = $patients->whereNull('default_mcp_company_location_id');
  598. }
  599. $care_plan = $request->get('care_plan');
  600. if($care_plan){
  601. if($care_plan === 'UNSIGNED_CARE_PLANS'){
  602. $patients = $patients->whereHas('notes', function($noteQuery){
  603. return $noteQuery->where('cm_setup_manager_signature_status', '!=', 'SIGNED');
  604. });
  605. }
  606. if($care_plan === 'UNCLEARED_CARE_PLANS'){
  607. $patients = $patients->where('has_care_plan_flag', true)->where('is_flag_cleared', false);
  608. }
  609. }
  610. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  611. return view('app.admin.patients_missing_default_settings', compact('patients', 'filters'));
  612. }
  613. public function points(Request $request){
  614. $filters = $request->all();
  615. $points = Point::query();
  616. $points = $points->where('is_removed','!=', true);
  617. if ($request->input('name')) {
  618. $name = trim($request->input('name'));
  619. if ($name) {
  620. $points = $points->whereHas('client', function ($q) use ($name) {
  621. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  622. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  623. });
  624. }
  625. }
  626. if ($request->input('mcp')) {
  627. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  628. if ($mcp) {
  629. $points = $points->where('created_by_pro_id', $mcp->id);
  630. }
  631. }
  632. $points = $points->paginate(30);
  633. $_point = new Point;
  634. $tableName = $_point->getTable();
  635. $columns = Schema::getColumnListing($tableName);
  636. return view('app.admin.points.index', compact('points', 'filters', 'columns'));
  637. }
  638. public function messages(Request $request)
  639. {
  640. $messages = InternalMessage::orderBy('created_at', 'desc')->paginate(50);
  641. return view('app.admin.messages', compact('messages'));
  642. }
  643. }