AdminController.php 32 KB

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