PracticeManagementController.php 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\BillingReport;
  5. use App\Models\CareMonth;
  6. use App\Models\ClaimEDI;
  7. use App\Models\ClientProChange;
  8. use App\Models\Company;
  9. use App\Models\Handout;
  10. use App\Models\MBClaim;
  11. use App\Models\Measurement;
  12. use App\Models\Bill;
  13. use App\Models\Claim;
  14. use App\Models\Client;
  15. use App\Models\McpRequest;
  16. use App\Models\McCodeCheck;
  17. use App\Models\Note;
  18. use App\Models\Pack;
  19. use App\Models\Pro;
  20. use App\Models\Product;
  21. use App\Models\ProFavorite;
  22. use App\Models\ProGeneralAvailability;
  23. use App\Models\ProProAccess;
  24. use App\Models\ProRate;
  25. use App\Models\ProSpecificAvailability;
  26. use App\Models\ProSpecificUnavailability;
  27. use App\Models\ProTeam;
  28. use App\Models\ProTextShortcut;
  29. use App\Models\ProTransaction;
  30. use App\Models\Shipment;
  31. use App\Models\SupplyOrder;
  32. use App\Models\Team;
  33. use App\Models\Ticket;
  34. use App\Models\AccountInvite;
  35. use App\Models\ClientMeasurementDaysPerMonth;
  36. use App\Models\ClientBDTDevice;
  37. use App\Models\ClientMemo;
  38. use Carbon\Carbon;
  39. use Illuminate\Support\Facades\DB;
  40. use Illuminate\Support\Facades\Http;
  41. use PDF;
  42. use DateTime;
  43. use DateTimeZone;
  44. use Illuminate\Http\Request;
  45. use App\Models\SegmentTemplate;
  46. use App\Models\VisitTemplate;
  47. use App\Models\VisitTemplateSegmentTemplate;
  48. use App\Models\VisitTemplateAccess;
  49. class PracticeManagementController extends Controller
  50. {
  51. public function rpmMatrix(Request $request)
  52. {
  53. $proID = $this->performer()->pro->id;
  54. $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
  55. $query = Client::whereNull('shadow_pro_id');
  56. if(!$isAdmin) $query->where('mcp_pro_id', '=', $proID);
  57. $clients = $query->orderByRaw('most_recent_cellular_measurement_at desc nulls last')
  58. ->paginate(50);
  59. return view ('app.practice-management.rpm-matrix', compact('clients'));
  60. }
  61. public function mcCodeChecks(Request $request)
  62. {
  63. $checks = McCodeCheck::orderBy('next_eligible_date_professional', 'asc')->get();
  64. return view ('app.practice-management.mc-code-checks', compact('checks'));
  65. }
  66. public function remoteMonitoringReport(Request $request)
  67. {
  68. $rows = null;
  69. $proID = $this->performer()->pro->id;
  70. $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
  71. //$rows = $isAdmin ? ClientMeasurementDaysPerMonth::all() : ClientMeasurementDaysPerMonth::where('mcp_pro_id', $proID)->orderBy('year_month', 'asc')->orderBy('num_of_days_with_measurement', 'asc')->get();
  72. $query = CareMonth::whereNotNull('mcp_pro_id')
  73. ->where('number_of_days_with_remote_measurements', '>=', 16)
  74. ->where('days_between_most_recent_mcp_note_date_and_end_of_care_month', '<=', 90);
  75. if(!$isAdmin) $query->where('mcp_pro_id', '=', $proID);
  76. if($request->get('show_billing_not_closed_only')){
  77. $query->where(function($q){
  78. return $q->where('is_bill_closed', false)->orWhereNull('is_bill_closed');
  79. });
  80. }
  81. $rows = $query->orderByRaw(DB::raw('start_date DESC'))->paginate(100) ;
  82. return view ('app.practice-management.remote-monitoring-report', compact('rows', 'isAdmin'));
  83. }
  84. public function dailyTreatmentServices(Request $request) {
  85. $type = $request->input('t');
  86. $fPro = null;
  87. if($type === 'pro') {
  88. $fPro = Pro::where('uid', $request->input('p'))->first();
  89. $rows = DB::select(DB::raw("
  90. SELECT effective_date, hcp_pro_id, p.name_first, p.name_last, count(*), sum(number_of_units) as units
  91. FROM bill JOIN pro p on p.id = bill.hcp_pro_id
  92. WHERE code = 'Treatment Services'
  93. GROUP BY effective_date, hcp_pro_id, p.name_first, p.name_last
  94. ORDER BY effective_date DESC, p.name_first ASC, p.name_last ASC
  95. "));
  96. }
  97. else {
  98. $rows = DB::select(DB::raw("
  99. SELECT effective_date, count(*), sum(number_of_units) as units FROM bill WHERE code = 'Treatment Services' GROUP BY effective_date ORDER BY effective_date DESC
  100. "));
  101. }
  102. return view ('app.practice-management.daily-treatment-services', compact('rows'));
  103. }
  104. public function clientProChanges(Request $request)
  105. {
  106. $rows = ClientProChange::orderByRaw('created_at::date DESC')->orderBy('client_id', 'desc')->paginate(20);
  107. return view ('app.practice-management.client-pro-changes', compact('rows'));
  108. }
  109. public function billingReport(Request $request)
  110. {
  111. $filters = $request->all();
  112. $claimStatus = $request->get('status');
  113. $rows = BillingReport::whereHas('client', function($clientQuery){
  114. return $clientQuery->where('client_engagement_status_category','<>' ,'DUMMY');
  115. })->orderBy('note_date', 'desc');
  116. $no_claims = $request->get('no_claims');
  117. $zero_deductible = $request->get('zero_deductible');
  118. $claim_status = $request->get('claim_status');
  119. $verified = $request->get('verified');
  120. if($no_claims){
  121. $rows = $rows->whereHas('note', function($noteQuery){
  122. return $noteQuery->has('claims', '=', 0);
  123. });
  124. }
  125. if($zero_deductible){
  126. $rows = $rows->whereHas('client', function($clientQuery){
  127. return $clientQuery->where('client_engagement_status_category','<>' ,'DUMMY')
  128. ->whereHas('latestClientPrimaryCoverage', function($lcpcQuery){
  129. return $lcpcQuery->where('auto_medicare_mpb_deductible', 0);
  130. });
  131. });
  132. }
  133. if($claim_status){
  134. $rows = $rows->whereHas('note', function($noteQuery) use ($claim_status){
  135. return $noteQuery->whereHas('claims', function($claimQuery) use ($claim_status) {
  136. return $claimQuery->where('status', $claim_status);
  137. });
  138. });
  139. }
  140. if($verified){
  141. if($verified == 'VERIFIED'){
  142. $rows = $rows->whereHas('note', function($noteQuery){
  143. return $noteQuery->whereHas('bills', function($billQuery) {
  144. return $billQuery->where('is_verified', true)->where('is_cancelled', false);
  145. });
  146. });
  147. }
  148. if($verified == 'UNVERIFIED'){
  149. $rows = $rows->whereHas('note', function($noteQuery){
  150. return $noteQuery->whereHas('bills', function($billQuery) {
  151. return $billQuery->where('is_verified', false)->where('is_cancelled', false);
  152. });
  153. });
  154. }
  155. }
  156. $rows = $rows->paginate(50);
  157. $claimStatuses = DB::select('SELECT distinct status FROM claim ORDER BY status DESC');
  158. return view('app.practice-management.billing-report', compact('rows', 'claimStatuses', 'filters'));
  159. }
  160. public function dashboard(Request $request)
  161. {
  162. return view('app.practice-management.dashboard');
  163. }
  164. public function rates(Request $request, $selectedProUid = 'all')
  165. {
  166. $proUid = $selectedProUid ? $selectedProUid : 'all';
  167. $rates = ProRate::where('is_active', true);
  168. if ($proUid !== 'all') {
  169. $selectedPro = Pro::where('uid', $proUid)->first();
  170. $rates = $rates->where('pro_id', $selectedPro->id);
  171. }
  172. $rates = $rates->orderBy('pro_id', 'asc')->get();
  173. $pros = $this->pros;
  174. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  175. }
  176. public function previousBills(Request $request)
  177. {
  178. return view('app.practice-management.previous-bills');
  179. }
  180. public function financialTransactions(Request $request)
  181. {
  182. $pro = $this->performer()->pro;
  183. $transactions = null;
  184. if($pro->pro_type === 'ADMIN') {
  185. $transactions = ProTransaction::whereNotNull('id');
  186. }
  187. else {
  188. $transactions = ProTransaction::where('pro_id', $pro->id);
  189. }
  190. $filter = $request->input('p');
  191. if ($filter) {
  192. $filterPro = Pro::where('uid', $filter)->first();
  193. if($filterPro) {
  194. $transactions = $transactions->where('pro_id', '=', $filterPro->id);
  195. }
  196. }
  197. $filter = $request->input('t');
  198. if ($filter) {
  199. $transactions = $transactions->where('plus_or_minus', '=', $filter);
  200. }
  201. $filter = $request->input('c');
  202. if ($filter) {
  203. $transactions = $transactions->where('company_id', '=', $filter);
  204. }
  205. $filter = $request->input('bs');
  206. if ($filter) {
  207. $transactions = $transactions->where('created_at', '>=', $filter);
  208. }
  209. $filter = $request->input('be');
  210. if ($filter) {
  211. $transactions = $transactions->where('created_at', '<=', $filter);
  212. }
  213. $transactions = $transactions->orderBy('created_at', 'desc')->paginate();
  214. $companies = Company::where('is_active', true)->orderBy('name')->get();
  215. return view('app.practice-management.financial-transactions', compact('transactions', 'companies'));
  216. }
  217. public function pendingBillsToSign(Request $request)
  218. {
  219. return view('app.practice-management.pending-bills-to-sign');
  220. }
  221. public function HR(Request $request)
  222. {
  223. return view('app.practice-management.hr');
  224. }
  225. public function directDepositSettings(Request $request)
  226. {
  227. return view('app.practice-management.direct-deposit-settings');
  228. }
  229. public function w9(Request $request)
  230. {
  231. return view('app.practice-management.w9');
  232. }
  233. public function contract(Request $request)
  234. {
  235. return view('app.practice-management.contract');
  236. }
  237. public function notes(Request $request, $filter = '')
  238. {
  239. $proID = $this->performer()->pro->id;
  240. $query = Note::where('hcp_pro_id', $proID);
  241. switch ($filter) {
  242. case 'not-yet-signed':
  243. $query = $query->where('is_signed_by_hcp', false);
  244. break;
  245. case 'not-yet-signed-but-ally-signed':
  246. $query = $query->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true);
  247. break;
  248. case 'without-bills':
  249. $query = $query->where('is_signed_by_hcp', true)->where('is_cancelled', false)->whereDoesntHave('bills');
  250. break;
  251. // more cases can be added as needed
  252. default:
  253. break;
  254. }
  255. $notes = $query->orderBy('created_at', 'desc')->get();
  256. return view('app.practice-management.notes', compact('notes', 'filter'));
  257. }
  258. public function dnaNotesPendingMcpSign(Request $request)
  259. {
  260. $proID = $this->performer()->pro->id;
  261. $notes = Note::where('ally_pro_id', $proID)
  262. ->where('is_signed_by_hcp', false)
  263. ->where('is_cancelled', false)
  264. ->orderBy('created_at', 'desc')
  265. ->get();
  266. return view('app.practice-management.dna-notes-pending-mcp-sign', compact('notes'));
  267. }
  268. public function naBillableSignedNotes(Request $request)
  269. {
  270. $notes = Note
  271. ::where('is_signed_by_hcp', TRUE)
  272. ->where('ally_pro_id', $this->performer()->pro->id)
  273. ->where('is_cancelled', FALSE)
  274. ->whereRaw("
  275. (
  276. SELECT count(bill.id)
  277. FROM bill WHERE
  278. bill.is_cancelled = FALSE AND
  279. bill.generic_pro_id = {$this->performer()->pro->id} AND
  280. bill.note_id = note.id
  281. ) = 0
  282. ");
  283. $notes = $notes->orderBy('created_at', 'desc')->get();
  284. return view('app.practice-management.na-billable-signed-notes', compact('notes'));
  285. }
  286. public function bills(Request $request, $filter = '')
  287. {
  288. $proID = $this->performer()->pro->id;
  289. $query = Bill::where('is_cancelled', false)->where('bill_service_type', '<>', 'CARE_MONTH');
  290. switch ($filter) {
  291. case 'not-yet-signed':
  292. $query = $query
  293. ->where(function ($q) use ($proID) {
  294. $q->where(function ($q2) use ($proID) {
  295. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  296. })
  297. ->orWhere(function ($q2) use ($proID) {
  298. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  299. })
  300. ->orWhere(function ($q2) use ($proID) {
  301. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  302. })
  303. ->orWhere(function ($q2) use ($proID) {
  304. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  305. })
  306. ->orWhere(function ($q2) use ($proID) {
  307. $q2->where('generic_pro_id', $proID)->where('is_signed_by_generic_pro', false);
  308. });
  309. });
  310. break;
  311. case 'previous':
  312. $query = $query
  313. ->where(function ($q) use ($proID) {
  314. $q->where(function ($q2) use ($proID) {
  315. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  316. })
  317. ->orWhere(function ($q2) use ($proID) {
  318. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  319. })
  320. ->orWhere(function ($q2) use ($proID) {
  321. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  322. })
  323. ->orWhere(function ($q2) use ($proID) {
  324. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  325. });
  326. });
  327. break;
  328. // more cases can be added as needed
  329. default:
  330. $query = $query
  331. ->where(function ($q) use ($proID) {
  332. $q->where(function ($q2) use ($proID) {
  333. $q2->where('hcp_pro_id', $proID);
  334. })
  335. ->orWhere(function ($q2) use ($proID) {
  336. $q2->where('cm_pro_id', $proID);
  337. })
  338. ->orWhere(function ($q2) use ($proID) {
  339. $q2->where('rme_pro_id', $proID);
  340. })
  341. ->orWhere(function ($q2) use ($proID) {
  342. $q2->where('rmm_pro_id', $proID);
  343. });
  344. });
  345. break;
  346. }
  347. $bills = $query->orderBy('created_at', 'desc')->get();
  348. return view('app.practice-management.bills', compact('bills', 'filter'));
  349. }
  350. public function rmBillsToSign(Request $request)
  351. {
  352. $performerProID = $this->performer()->pro->id;
  353. $bills = Bill::where('is_cancelled', false)->where('cm_or_rm', 'RM')
  354. ->where(function ($q) use ($performerProID) {
  355. $q
  356. ->where(function ($q2) use ($performerProID) {
  357. $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
  358. })
  359. ->orWhere(function ($q2) use ($performerProID) {
  360. $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
  361. })
  362. ->orWhere(function ($q2) use ($performerProID) {
  363. $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
  364. })
  365. ->orWhere(function ($q2) use ($performerProID) {
  366. $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
  367. });
  368. })
  369. ->orderBy('effective_date', 'desc')
  370. ->get();
  371. return view('app.practice-management.rm-bills-to-sign', compact('bills'));
  372. }
  373. public function unacknowledgedCancelledBills(Request $request)
  374. {
  375. $bills = Bill::where('hcp_pro_id', $this->performer()->pro->id)
  376. ->where('is_cancelled', true)
  377. ->where('is_cancellation_acknowledged', false)
  378. ->orderBy('created_at', 'desc')
  379. ->get();
  380. return view('app.practice-management.unacknowledged-cancelled-bills', compact('bills'));
  381. }
  382. public function myTickets(Request $request, $filter = 'open')
  383. {
  384. $performer = $this->performer();
  385. $myTickets = Ticket::where(function ($q) use ($performer) {
  386. $q->where('assigned_pro_id', $performer->pro_id)
  387. ->orWhere('manager_pro_id', $performer->pro_id)
  388. ->orWhere('ordering_pro_id', $performer->pro_id)
  389. ->orWhere('initiating_pro_id', $performer->pro_id);
  390. });
  391. if ($filter === 'open') {
  392. $myTickets = $myTickets->where('is_open', true);
  393. } else if ($filter === 'closed') {
  394. $myTickets = $myTickets->where('is_open', false);
  395. }
  396. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  397. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  398. }
  399. public function myTextShortcuts(Request $request)
  400. {
  401. $personalShortcuts = DB::table('pro_text_shortcut')
  402. ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
  403. ->select(
  404. 'pro_text_shortcut.uid',
  405. 'pro_text_shortcut.shortcut',
  406. 'pro_text_shortcut.text',
  407. 'pro.name_first',
  408. 'pro.name_last'
  409. )
  410. ->where('pro_text_shortcut.is_removed', false);
  411. if($this->performer()->pro->pro_type !== 'ADMIN') {
  412. $personalShortcuts = $personalShortcuts->where('pro_id', $this->performer()->pro_id);
  413. }
  414. $personalShortcuts = $personalShortcuts
  415. ->orderBy('pro.name_last')
  416. ->orderBy('pro.name_first')
  417. ->orderBy('pro_text_shortcut.shortcut')
  418. ->get();
  419. $globalTextShortcuts = DB::table('pro_text_shortcut')
  420. ->select(
  421. 'pro_text_shortcut.uid',
  422. 'pro_text_shortcut.shortcut',
  423. 'pro_text_shortcut.text'
  424. )
  425. ->whereNull('pro_id')
  426. ->where('pro_text_shortcut.is_removed', false)
  427. ->orderBy('pro_text_shortcut.shortcut')
  428. ->get();
  429. return view('app.practice-management.my-text-shortcuts', compact('personalShortcuts', 'globalTextShortcuts'));
  430. }
  431. public function myFavorites(Request $request, $filter = 'all')
  432. {
  433. $performer = $this->performer();
  434. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)->where('is_removed', false);
  435. if ($filter !== 'all') {
  436. $myFavorites = $myFavorites->where('category', $filter);
  437. }
  438. $myFavorites = $myFavorites
  439. ->whereIn('category', ['allergy', 'medication', 'problem'])
  440. ->orderBy('category', 'asc')
  441. ->orderBy('position_index', 'asc')
  442. ->get();
  443. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  444. }
  445. public function patientsWithoutCoverage(Request $request, $filter = 'all')
  446. {
  447. $performer = $this->performer();
  448. $sql = "SELECT cl.uid, cl.name_first, cl.name_last FROM client cl ";
  449. $joinClause = 'LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id ';
  450. $withoutCondition = "cl.latest_client_primary_coverage_id IS NULL";
  451. $pendingCondition = "
  452. (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
  453. AND (
  454. (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
  455. OR
  456. (cpc.plan_type != 'MEDICARE' AND
  457. (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
  458. ))";
  459. switch ($filter) {
  460. case 'without-coverage-information':
  461. $sql .= 'WHERE cl.shadow_pro_id IS NULL AND ';
  462. $sql .= $withoutCondition;
  463. break;
  464. case 'pending-coverage-verification':
  465. $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
  466. $sql .= $pendingCondition;
  467. break;
  468. default:
  469. $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
  470. $sql .= '(' . $withoutCondition . ' OR ' . $pendingCondition . ')';
  471. break;
  472. }
  473. $sql .= ' ORDER BY cl.name_first ASC';
  474. $pendingCoverage = DB::select(DB::raw($sql));
  475. return view('app.practice-management.patients-without-coverage', compact('pendingCoverage', 'filter'));
  476. }
  477. public function proAvailability(Request $request, $proUid = null)
  478. {
  479. $performer = $this->performer();
  480. $pro = $performer->pro;
  481. if ($proUid) {
  482. $pro = Pro::where('uid', $proUid)->first();
  483. }
  484. if ($request->get('pro_uid')) {
  485. $proUid = $request->get('pro_uid');
  486. $pro = Pro::where('uid', $proUid)->first();
  487. }
  488. $selectedProUid = $pro->uid;
  489. $pros = $this->pros;
  490. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  491. $generalAvailabilities = [
  492. 'MONDAY' => [],
  493. 'TUESDAY' => [],
  494. 'WEDNESDAY' => [],
  495. 'THURSDAY' => [],
  496. 'FRIDAY' => [],
  497. 'SATURDAY' => [],
  498. 'SUNDAY' => [],
  499. ];
  500. foreach ($generalAvailabilitiesList as $ga) {
  501. if ($ga->day_of_week == 'MONDAY') {
  502. $generalAvailabilities['MONDAY'][] = $ga;
  503. }
  504. if ($ga->day_of_week == 'TUESDAY') {
  505. $generalAvailabilities['TUESDAY'][] = $ga;
  506. }
  507. if ($ga->day_of_week == 'WEDNESDAY') {
  508. $generalAvailabilities['WEDNESDAY'][] = $ga;
  509. }
  510. if ($ga->day_of_week == 'THURSDAY') {
  511. $generalAvailabilities['THURSDAY'][] = $ga;
  512. }
  513. if ($ga->day_of_week == 'FRIDAY') {
  514. $generalAvailabilities['FRIDAY'][] = $ga;
  515. }
  516. if ($ga->day_of_week == 'SATURDAY') {
  517. $generalAvailabilities['SATURDAY'][] = $ga;
  518. }
  519. if ($ga->day_of_week == 'SUNDAY') {
  520. $generalAvailabilities['SUNDAY'][] = $ga;
  521. }
  522. }
  523. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  524. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  525. //events for the calendar
  526. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  527. $endDateTime = new DateTime($startDate);
  528. $endDateTime->modify('+6 day');
  529. $endDate = $endDateTime->format("Y-m-d");
  530. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  531. $events = json_encode($eventsData);
  532. return view(
  533. 'app.practice-management.pro-availability',
  534. compact(
  535. 'pros',
  536. 'generalAvailabilities',
  537. 'specificAvailabilities',
  538. 'specificUnavailabilities',
  539. 'events',
  540. 'selectedProUid'
  541. )
  542. );
  543. }
  544. public function loadAvailability(Request $request, $proUid)
  545. {
  546. $performer = $this->performer();
  547. $pro = $performer->pro;
  548. $startDate = $request->get('start');
  549. $endDate = $request->get('end');
  550. $selectedPro = Pro::where('uid', $proUid)->first();
  551. return $selectedPro->getAvailabilityEvents($startDate, $endDate, $request->input('tz') ? $request->input('tz') : 'EASTERN');
  552. }
  553. public function proAvailabilityFilter(Request $request)
  554. {
  555. $proUid = $request->get('proUid');
  556. return ['success' => true, 'data' => $proUid];
  557. }
  558. // video call page (RHS)
  559. // generic call handle (no uid)
  560. // specific call handle (uid of client)
  561. public function meet(Request $request, $uid = false)
  562. {
  563. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  564. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  565. if (!empty($client)) {
  566. return view('app.video.call-minimal', compact('session', 'client'));
  567. }
  568. return view('app.video.call-agora-v2', compact('session', 'client'));
  569. }
  570. // check video page
  571. public function checkVideo(Request $request, $uid)
  572. {
  573. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  574. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  575. $publish = false;
  576. return view('app.video.check-video-minimal', compact('session', 'client'));
  577. }
  578. public function getParticipantInfo(Request $request)
  579. {
  580. $sid = intval($request->get('uid')) - 1000000;
  581. $session = AppSession::where('id', $sid)->first();
  582. $result = [
  583. "type" => '',
  584. "name" => ''
  585. ];
  586. if ($session) {
  587. $result["type"] = $session->session_type;
  588. switch ($session->session_type) {
  589. case 'PRO':
  590. $pro = Pro::where('id', $session->pro_id)->first();
  591. $result["name"] = $pro->displayName();
  592. break;
  593. case 'CLIENT':
  594. $client = Client::where('id', $session->client_id)->first();
  595. $result["name"] = $client->displayName();
  596. break;
  597. }
  598. }
  599. return json_encode($result);
  600. }
  601. // ajax ep used by the video page
  602. // this is needed bcoz meet() is used not
  603. // just for the client passed to the view
  604. public function getOpentokSessionKey(Request $request, $uid)
  605. {
  606. $client = Client::where('uid', $uid)->first();
  607. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  608. }
  609. // poll to check if there are patients with active mcp requests
  610. public function getPatientsInQueue(Request $request)
  611. {
  612. $myInitiatives = $this->performer->pro->initiatives;
  613. if ($myInitiatives) {
  614. $myInitiatives = strtoupper($myInitiatives);
  615. }
  616. $myInitiativesList = explode('|', $myInitiatives);
  617. $myForeignLanguages = $this->performer->pro->foreign_languages;
  618. if ($myForeignLanguages) {
  619. $myForeignLanguages = strtoupper($myForeignLanguages);
  620. }
  621. $myForeignLanguagesList = explode('|', $myForeignLanguages);
  622. $clients = Client::whereNotNull('active_mcp_request_id')->where(function ($query) use ($myInitiativesList) {
  623. $query->whereNull('initiative')->orWhereIn('initiative', $myInitiativesList);
  624. })
  625. ->where(function ($query) use ($myForeignLanguagesList) {
  626. $query->whereNull('preferred_foreign_language')->orWhereIn('preferred_foreign_language', $myForeignLanguagesList);
  627. })->limit(3)->get();
  628. $results = [];
  629. foreach ($clients as $client) {
  630. $results[] = [
  631. 'clientUid' => $client->uid,
  632. 'name' => $client->displayName(),
  633. 'initials' => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  634. ];
  635. }
  636. return json_encode($results);
  637. }
  638. public function currentWork(Request $request)
  639. {
  640. return view('app/current-work');
  641. }
  642. public function calendar(Request $request, $proUid = null)
  643. {
  644. $pros = Pro::all();
  645. if ($this->pro && $this->pro->pro_type != 'ADMIN') {
  646. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
  647. $accessibleProIds = [];
  648. foreach ($accessiblePros as $accessiblePro) {
  649. $accessibleProIds[] = $accessiblePro->id;
  650. }
  651. $accessibleProIds[] = $this->pro->id;
  652. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  653. }
  654. return view('app.practice-management.calendar', compact('pros'));
  655. }
  656. public function cellularDeviceManager(Request $request, $proUid = null)
  657. {
  658. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  659. $performerPro = $this->performer->pro;
  660. $targetPro = null;
  661. $expectedForHcp = null;
  662. if ($performerPro->pro_type == 'ADMIN') {
  663. $targetPro = Pro::where('uid', $proUid)->first();
  664. } else {
  665. $targetPro = $performerPro;
  666. }
  667. $clients = [];
  668. if ($targetPro) {
  669. $clients = Client::where('mcp_pro_id', $targetPro->id)->orderBy('created_at', 'desc')->paginate(20);
  670. } else {
  671. $clients = Client::orderBy('created_at', 'desc')->paginate(20);
  672. }
  673. return view('app.practice-management.cellular-device-manager', compact('clients', 'targetPro', 'proUid'));
  674. }
  675. public function treatmentServiceUtil(Request $request)
  676. {
  677. $view_treatment_service_utilization_org = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_org ORDER BY effective_date DESC"));
  678. $view_treatment_service_utilization = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization ORDER BY effective_date DESC, total_hrs DESC"));
  679. $view_treatment_service_utilization_by_patient = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_by_patient ORDER BY pro_lname ASC, pro_fname ASC, hcp_pro_id ASC, total_hrs DESC"));
  680. return view('app.practice-management.treatment-services-util', compact(
  681. 'view_treatment_service_utilization_org',
  682. 'view_treatment_service_utilization',
  683. 'view_treatment_service_utilization_by_patient'));
  684. }
  685. public function processingBillMatrix(Request $request, $proUid = null)
  686. {
  687. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  688. $performerPro = $this->performer->pro;
  689. $targetPro = null;
  690. if ($performerPro->pro_type == 'ADMIN') {
  691. $targetPro = Pro::where('uid', $proUid)->first();
  692. } else {
  693. $targetPro = $performerPro;
  694. }
  695. $bills = Bill::where('is_cancelled', false);
  696. if(!$request->input('t') || $request->input('t') === 'hcp') {
  697. $bills = $bills
  698. ->where('has_hcp_been_paid', false)
  699. ->where('hcp_expected_payment_amount', '>', 0)
  700. ->where('is_signed_by_hcp', true);
  701. if ($targetPro) {
  702. $bills = $bills->where('hcp_pro_id', $targetPro->id);
  703. }
  704. if($request->input('c')) {
  705. $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = hcp_company_pro_id) = ' . $request->input('c'));
  706. }
  707. }
  708. else if($request->input('t') === 'na') {
  709. $bills = $bills
  710. ->where('has_generic_pro_been_paid', false)
  711. ->where('generic_pro_expected_payment_amount', '>', 0)
  712. ->where('is_signed_by_generic_pro', true);
  713. if ($targetPro) {
  714. $bills = $bills->where('generic_pro_id', $targetPro->id);
  715. }
  716. if($request->input('c')) {
  717. $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = generic_company_pro_id) = ' . $request->input('c'));
  718. }
  719. }
  720. $filter = $request->input('f');
  721. switch ($filter) {
  722. case 'verified':
  723. $bills = $bills->where('is_verified', true);
  724. break;
  725. case 'not-verified':
  726. $bills = $bills->where('is_verified', false);
  727. break;
  728. }
  729. $filter = $request->input('bs');
  730. if ($filter) {
  731. $bills = $bills->where('balance_post_date', '>=', $filter);
  732. }
  733. $filter = $request->input('be');
  734. if ($filter) {
  735. $bills = $bills->where('balance_post_date', '<=', $filter);
  736. }
  737. $filter = $request->input('s');
  738. if ($filter) {
  739. $bills = $bills->where('code', '=', $filter);
  740. }
  741. $bills = $bills->orderBy('effective_date', 'desc')->paginate();
  742. $companies = Company::where('is_active', true)->orderBy('name')->get();
  743. $codes = DB::select(DB::raw("SELECT code, count(*) as count FROM bill WHERE is_cancelled IS FALSE GROUP BY code ORDER BY code"));
  744. $viewData = [
  745. 'bills' => $bills,
  746. 'targetPro' => $targetPro,
  747. 'performerPro' => $performerPro,
  748. 'proUid' => $proUid,
  749. 'companies' => $companies,
  750. 'codes' => $codes
  751. ];
  752. return view('app.practice-management.processing-bill-matrix', $viewData);
  753. }
  754. public function hcpNoteActivity(Request $request)
  755. {
  756. $filters = $request->all();
  757. $from_date = $request->get('from_date');
  758. // if(!$from_date) {
  759. // $from_date = '2010-01-01';
  760. // }
  761. $to_date = $request->get('to_date');
  762. // if(!$to_date){
  763. // $to_date = '2900-12-31';
  764. // }
  765. //TODO sanitize inputs
  766. $proUid = $request->get('pro-uid');
  767. $now = Carbon::now();
  768. $startOfCurrentMonth = $now->startOfMonth('Y-m-d');
  769. $startOfCurrentMonth = $startOfCurrentMonth->toDateString();
  770. $endOfCurrentMonth = $now->endOfMonth()->format('Y-m-d');
  771. $rows = DB::table('pro')
  772. ->selectRaw(" *,
  773. (SELECT id FROM note WHERE note.hcp_pro_id = pro.id AND is_cancelled = false ORDER BY created_at DESC LIMIT 1) as last_note_id,
  774. (SELECT note.created_at FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false ORDER BY note.created_at DESC LIMIT 1) as last_note_created_at,
  775. (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${startOfCurrentMonth}'::DATE AND created_at::DATE <= '${endOfCurrentMonth}'::DATE ) AS notes_this_month,
  776. (SELECT COUNT(*) FROM client WHERE client.mcp_pro_id = pro.id AND client.client_engagement_status_category <> 'DUMMY' AND client.client_engagement_status_category <> 'DUPLICATE') as total_client_count,
  777. (SELECT COUNT(*) FROM client WHERE client.mcp_pro_id = pro.id AND client.client_engagement_status_category <> 'DUMMY' AND client.client_engagement_status_category <> 'DUPLICATE' AND client.most_recent_completed_mcp_note_date >= (NOW() - interval '60 days')::DATE) as active_client_count
  778. " . (!!$from_date && !!$to_date ? ",(SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${from_date}'::DATE AND created_at::DATE <= '${to_date}'::DATE ) AS notes_this_period" : ""));
  779. $prosIDs = $request->get('pros_ids');
  780. if($prosIDs){
  781. $pros =
  782. $rows = $rows->whereIn('pro.id', $prosIDs);
  783. }
  784. $sortBy = $request->input('sort_by') ?: 'name_first';
  785. $sortDir = $request->input('sort_dir') ?: 'ASC';
  786. $rows = $rows->orderByRaw("$sortBy $sortDir NULLS LAST");
  787. $rows = $rows->paginate(50);
  788. return view('app.practice-management.hcp-note-activity', compact('rows', 'filters'));
  789. }
  790. public function proFinancials(Request $request, $proUid = null)
  791. {
  792. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  793. $performerPro = $this->performer->pro;
  794. $targetPro = null;
  795. if ($performerPro->pro_type == 'ADMIN') {
  796. $targetPro = Pro::where('uid', $proUid)->first();
  797. } else {
  798. $targetPro = $performerPro;
  799. }
  800. $fPros = Pro::whereNotNull('balance');
  801. if($targetPro) {
  802. $fPros = $fPros->where('uid', $targetPro->uid);
  803. }
  804. $fPros = $fPros
  805. ->where('balance', '>', 0)
  806. ->orderBy('name_first')
  807. ->orderBy('name_last')
  808. ->paginate();
  809. return view('app.practice-management.pro-financials', compact('fPros', 'targetPro'));
  810. }
  811. public function hcpBillMatrix(Request $request, $proUid = null)
  812. {
  813. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  814. $performerPro = $this->performer->pro;
  815. $targetPro = null;
  816. $allPros = [];
  817. $expectedForHcp = null;
  818. if ($performerPro->pro_type == 'ADMIN') {
  819. $allPros = Pro::all();
  820. $targetPro = Pro::where('uid', $proUid)->first();
  821. } else {
  822. $targetPro = $performerPro;
  823. }
  824. $rows = [];
  825. if ($targetPro) {
  826. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report WHERE hcp_pro_id = :targetProID"), ['targetProID' => $targetPro->id]);
  827. } else {
  828. $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report"));
  829. }
  830. return view('app.practice-management.hcp-bill-matrix', compact('rows', 'allPros', 'expectedForHcp', 'targetPro', 'proUid'));
  831. }
  832. public function billingManager(Request $request, $proUid = null)
  833. {
  834. $proUid = $proUid ? $proUid : $request->get('pro-uid');
  835. $performerPro = $this->performer->pro;
  836. $targetPro = null;
  837. $allPros = [];
  838. $expectedForHcp = null;
  839. if ($performerPro->pro_type == 'ADMIN') {
  840. $allPros = Pro::query()->orderBy('name_first', 'asc')->get();
  841. $targetPro = Pro::where('uid', $proUid)->first();
  842. } else {
  843. $targetPro = $performerPro;
  844. }
  845. $notes = [];
  846. if ($targetPro) {
  847. $expectedForHcp = DB::select(DB::raw("SELECT coalesce(SUM(hcp_expected_payment_amount),0) as expected_pay FROM bill WHERE hcp_pro_id = :targetProID AND is_signed_by_hcp IS TRUE AND is_cancelled = false"), ['targetProID' => $targetPro->id])[0]->expected_pay;
  848. $notes = Note::where('hcp_pro_id', $targetPro->id);
  849. } else {
  850. $notes = Note::where('id', '>', 0);
  851. }
  852. if($request->input('date')) {
  853. $notes = $notes->where('effective_dateest', $request->input('date'));
  854. }
  855. $filters = [];
  856. $filters['bills_created'] = $request->input('bills_created');
  857. $filters['is_billing_marked_done'] = $request->input('is_billing_marked_done');
  858. $filters['bills_resolved'] = $request->input('bills_resolved');
  859. $filters['bills_closed'] = $request->input('bills_closed');
  860. $filters['claims_created'] = $request->input('claims_created');
  861. $filters['claims_closed'] = $request->input('claims_closed');
  862. if ($filters['bills_created']) {
  863. $notes->where(
  864. 'bill_total_expected',
  865. ($filters['bills_created'] === 'yes' ? '>' : '<='),
  866. 0);
  867. }
  868. if ($filters['is_billing_marked_done']) {
  869. $notes->where(
  870. 'is_billing_marked_done',
  871. ($filters['is_billing_marked_done'] === 'yes' ? '=' : '!='),
  872. true);
  873. }
  874. if ($filters['bills_resolved']) {
  875. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id) > 0'); // have bills
  876. if ($filters['bills_resolved'] === 'yes') {
  877. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND (is_cancelled = false AND is_verified = false) OR (is_cancelled = TRUE AND is_cancellation_acknowledged = FALSE)) > 0');
  878. } elseif ($filters['bills_resolved'] === 'no') {
  879. $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id AND ((is_cancelled = true AND is_cancellation_acknowledged = true) OR is_verified = true)) = 0');
  880. }
  881. }
  882. if ($filters['bills_closed']) {
  883. $notes->where(
  884. 'is_bill_closed',
  885. ($filters['bills_closed'] === 'yes' ? '=' : '!='),
  886. true);
  887. }
  888. if ($filters['claims_created']) {
  889. $notes->where(
  890. 'claim_total_expected',
  891. ($filters['claims_created'] === 'yes' ? '>' : '<='),
  892. 0);
  893. }
  894. if ($filters['claims_closed']) {
  895. $notes->where(
  896. 'is_claim_closed',
  897. ($filters['claims_closed'] === 'yes' ? '=' : '!='),
  898. true);
  899. }
  900. $notes = $notes->orderBy('effective_dateest', 'desc')->paginate(20);
  901. return view('app.practice-management.billing-manager', compact('notes', 'allPros', 'expectedForHcp', 'targetPro', 'proUid', 'filters'));
  902. }
  903. public function remoteMonitoring(Request $request) {
  904. $performer = $this->performer();
  905. // abort_if($performer->pro->pro_type !== 'ADMIN' && !$performer->pro->can_view_rm_matrix, 403);
  906. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  907. $careMonthStart = date($ym . '-01');
  908. $rc = $request->input('rc') ?: 1;
  909. $rc2 = $request->input('rc2') ?: 2;
  910. $conditions = [];// $this->rpmConditions($performer, $rc, $rc2);
  911. $sortBy = $request->input('sort_by') ?: 'name_first';
  912. $sortDir = $request->input('sort_dir') ?: 'ASC';
  913. $orderBy = "ORDER BY $sortBy $sortDir NULLS LAST";
  914. $query = "
  915. SELECT client.name_first, client.name_last,
  916. (client.name_first || ' ' || client.name_last) as client_name,
  917. client.uid as client_uid,
  918. client.dob,
  919. client.is_enrolled_in_rm,
  920. client.most_recent_completed_mcp_note_date,
  921. client.most_recent_completed_mcp_note_id,
  922. mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
  923. mrmnote.id as most_recent_completed_mcp_note_id_cm,
  924. mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
  925. client.cell_number,
  926. client.is_assigned_cellular_bp_device,
  927. client.is_assigned_cellular_weight_scale_device,
  928. care_month.uid as care_month_uid,
  929. care_month.id as care_month_id,
  930. care_month.start_date,
  931. care_month.rm_total_time_in_seconds_by_mcp,
  932. care_month.rm_total_time_in_seconds_by_rmm_pro,
  933. care_month.number_of_days_with_remote_measurements,
  934. care_month.has_mcp_interacted_with_client_about_rm,
  935. care_month.rm_num_measurements_not_stamped_by_mcp,
  936. care_month.rm_num_measurements_not_stamped_by_non_hcp,
  937. care_month.rm_num_measurements_not_stamped_by_rmm,
  938. care_month.rm_num_measurements_not_stamped_by_rme,
  939. care_month.mcp_pro_id as care_month_mcp_pro_id,
  940. care_month.rmm_pro_id as care_month_rmm_pro_id,
  941. client.mcp_pro_id,
  942. client.default_na_pro_id,
  943. client.rmm_pro_id,
  944. client.rme_pro_id,
  945. client.cell_number,
  946. client.most_recent_cellular_bp_dbp_mm_hg,
  947. client.most_recent_cellular_bp_sbp_mm_hg,
  948. client.most_recent_cellular_bp_measurement_at,
  949. client.most_recent_cellular_weight_value,
  950. client.most_recent_cellular_weight_measurement_at
  951. FROM care_month join client on care_month.client_id = client.id join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
  952. left join note mrmnote on mrmnote.id = (
  953. select max(n.id) from note n
  954. where
  955. n.client_id = client.id AND
  956. n.is_cancelled = FALSE AND
  957. (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
  958. n.effective_dateest::date >= care_month.start_date::date AND
  959. n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
  960. )
  961. WHERE
  962. (care_month.mcp_pro_id = {$performer->pro->id} OR care_month.rmm_pro_id = {$performer->pro->id})
  963. AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  964. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  965. " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
  966. $orderBy
  967. ";
  968. $patients = DB::select($query);
  969. $timestamp = strtotime(date('Y-m-d'));
  970. $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
  971. return view('app.practice-management.remote-monitoring', compact('patients', 'daysRemaining', 'careMonthStart'));
  972. }
  973. public function remoteMonitoring_Row(Request $request) {
  974. $clientUid = $request->input('clientUid');
  975. $careMonthUid = $request->input('careMonthUid');
  976. $query = "
  977. SELECT client.name_first, client.name_last,
  978. (client.name_first || ' ' || client.name_last) as client_name,
  979. client.uid as client_uid,
  980. client.dob,
  981. client.is_enrolled_in_rm,
  982. client.most_recent_completed_mcp_note_date,
  983. client.most_recent_completed_mcp_note_id,
  984. mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
  985. mrmnote.id as most_recent_completed_mcp_note_id_cm,
  986. mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
  987. client.cell_number,
  988. client.is_assigned_cellular_bp_device,
  989. client.is_assigned_cellular_weight_scale_device,
  990. care_month.uid as care_month_uid,
  991. care_month.id as care_month_id,
  992. care_month.start_date,
  993. care_month.rm_total_time_in_seconds_by_mcp,
  994. care_month.rm_total_time_in_seconds_by_rmm_pro,
  995. care_month.number_of_days_with_remote_measurements,
  996. care_month.has_mcp_interacted_with_client_about_rm,
  997. care_month.rm_num_measurements_not_stamped_by_mcp,
  998. care_month.rm_num_measurements_not_stamped_by_non_hcp,
  999. care_month.rm_num_measurements_not_stamped_by_rmm,
  1000. care_month.rm_num_measurements_not_stamped_by_rme,
  1001. care_month.mcp_pro_id as care_month_mcp_pro_id,
  1002. care_month.rmm_pro_id as care_month_rmm_pro_id,
  1003. client.mcp_pro_id,
  1004. client.default_na_pro_id,
  1005. client.rmm_pro_id,
  1006. client.rme_pro_id,
  1007. client.cell_number,
  1008. client.most_recent_cellular_bp_dbp_mm_hg,
  1009. client.most_recent_cellular_bp_sbp_mm_hg,
  1010. client.most_recent_cellular_bp_measurement_at,
  1011. client.most_recent_cellular_weight_value,
  1012. client.most_recent_cellular_weight_measurement_at
  1013. FROM care_month join client on care_month.client_id = client.id join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
  1014. left join note mrmnote on mrmnote.id = (
  1015. select max(n.id) from note n
  1016. where
  1017. n.client_id = client.id AND
  1018. n.is_cancelled = FALSE AND
  1019. (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
  1020. n.effective_dateest::date >= care_month.start_date::date AND
  1021. n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
  1022. )
  1023. WHERE care_month.uid = '{$careMonthUid}' AND client.uid = '{$clientUid}'
  1024. ";
  1025. $patients = DB::select($query);
  1026. return view('app.practice-management.remote-monitoring-row', ['iPatient' => $patients[0], 'trIndex' => $request->input('trIndex')]);
  1027. }
  1028. public function rpm_work_matrix(Request $request) {
  1029. // get the patient having most recent unstamped measurement
  1030. $performer = $this->performer();
  1031. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  1032. $careMonthStart = date($ym . '-01');
  1033. $patient = null;
  1034. $careMonth = null;
  1035. if($request->input('patientUid') && $request->input('careMonthUid')) {
  1036. $patient = Client::where('uid', $request->input('patientUid'))->first();
  1037. $careMonth = CareMonth::where('uid', $request->input('careMonthUid'))->first();
  1038. }
  1039. if(!$patient && !$careMonth) {
  1040. $query = "
  1041. SELECT client.name_first, client.name_last,
  1042. (client.name_first || ' ' || client.name_last) as client_name,
  1043. client.uid as client_uid,
  1044. client.dob,
  1045. client.is_enrolled_in_rm,
  1046. client.most_recent_completed_mcp_note_date,
  1047. care_month.uid as care_month_uid,
  1048. care_month.id as care_month_id,
  1049. care_month.start_date,
  1050. care_month.rm_total_time_in_seconds_by_mcp,
  1051. care_month.number_of_days_with_remote_measurements,
  1052. care_month.rm_num_measurements_not_stamped_by_mcp,
  1053. care_month.rm_num_measurements_not_stamped_by_rmm,
  1054. client.mcp_pro_id,
  1055. client.default_na_pro_id,
  1056. client.rmm_pro_id,
  1057. client.rme_pro_id,
  1058. client.cell_number,
  1059. client.most_recent_cellular_bp_dbp_mm_hg,
  1060. client.most_recent_cellular_bp_sbp_mm_hg,
  1061. client.most_recent_cellular_bp_measurement_at,
  1062. client.most_recent_cellular_weight_value,
  1063. client.most_recent_cellular_weight_measurement_at,
  1064. GREATEST(client.most_recent_cellular_bp_measurement_at, client.most_recent_cellular_weight_measurement_at) as latest_measurement_at
  1065. FROM care_month join client on care_month.client_id = client.id
  1066. WHERE
  1067. (
  1068. (care_month.mcp_pro_id = {$performer->pro->id} AND care_month.rm_num_measurements_not_stamped_by_mcp > 0) OR
  1069. (care_month.rmm_pro_id = {$performer->pro->id} AND care_month.rm_num_measurements_not_stamped_by_rmm > 0)
  1070. )
  1071. AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  1072. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  1073. ORDER BY latest_measurement_at DESC
  1074. LIMIT 1
  1075. ";
  1076. $patients = DB::select($query);
  1077. if (count($patients)) {
  1078. $patient = Client::where('uid', $patients[0]->client_uid)->first();
  1079. $careMonth = CareMonth::where('uid', $patients[0]->care_month_uid)->first();
  1080. }
  1081. }
  1082. return view('app.practice-management.rpm_work_matrix', compact('patient', 'careMonth'));
  1083. }
  1084. public function remoteMonitoringCount(Request $request) {
  1085. $performer = $this->performer();
  1086. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  1087. $careMonthStart = date($ym . '-01');
  1088. $rc = $request->input('rc') ?: 1;
  1089. $rc2 = $request->input('rc2') ?: 2;
  1090. $conditions = $this->rpmConditions($performer, $rc, $rc2);
  1091. $count = DB::select(
  1092. DB::raw(
  1093. "
  1094. SELECT count(*)
  1095. FROM care_month join client on care_month.client_id = client.id
  1096. WHERE
  1097. client.mcp_pro_id = {$performer->pro->id}
  1098. AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  1099. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  1100. " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
  1101. )
  1102. );
  1103. return $count[0]->count;
  1104. }
  1105. public function remoteMonitoringAdmin(Request $request) {
  1106. $performer = $this->performer();
  1107. // abort_if($performer->pro->pro_type !== 'ADMIN' && !$performer->pro->can_view_rm_matrix, 403);
  1108. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  1109. $careMonthStart = date($ym . '-01');
  1110. $rc = $request->input('rc') ?: 1;
  1111. $rc2 = $request->input('rc2') ?: 2;
  1112. $conditions = [];// $this->rpmConditions($performer, $rc, $rc2);
  1113. $sortBy = $request->input('sort_by') ?: 'name_first';
  1114. $sortDir = $request->input('sort_dir') ?: 'ASC';
  1115. $orderBy = "ORDER BY $sortBy $sortDir NULLS LAST";
  1116. $query = "
  1117. SELECT client.name_first, client.name_last,
  1118. (client.name_first || ' ' || client.name_last) as client_name,
  1119. (mcp_pro.name_first || ' ' || mcp_pro.name_last) as mcp_pro_name,
  1120. (rmm_pro.name_first || ' ' || rmm_pro.name_last) as rmm_pro_name,
  1121. client.uid as client_uid,
  1122. client.dob,
  1123. client.is_enrolled_in_rm,
  1124. client.most_recent_completed_mcp_note_date,
  1125. client.most_recent_completed_mcp_note_id,
  1126. mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
  1127. mrmnote.id as most_recent_completed_mcp_note_id_cm,
  1128. mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
  1129. client.cell_number,
  1130. client.is_assigned_cellular_bp_device,
  1131. client.is_assigned_cellular_weight_scale_device,
  1132. care_month.uid as care_month_uid,
  1133. care_month.id as care_month_id,
  1134. care_month.start_date,
  1135. care_month.rm_total_time_in_seconds_by_mcp,
  1136. care_month.rm_total_time_in_seconds_by_rmm_pro,
  1137. care_month.number_of_days_with_remote_measurements,
  1138. care_month.has_anyone_interacted_with_client_about_rm,
  1139. care_month.has_mcp_interacted_with_client_about_rm,
  1140. care_month.rm_num_measurements_not_stamped_by_mcp,
  1141. care_month.rm_num_measurements_not_stamped_by_non_hcp,
  1142. care_month.rm_num_measurements_not_stamped_by_rmm,
  1143. care_month.rm_num_measurements_not_stamped_by_rme,
  1144. care_month.mcp_pro_id as care_month_mcp_pro_id,
  1145. care_month.rmm_pro_id as care_month_rmm_pro_id,
  1146. client.mcp_pro_id,
  1147. client.default_na_pro_id,
  1148. client.rmm_pro_id,
  1149. client.rme_pro_id,
  1150. client.cell_number,
  1151. client.most_recent_cellular_bp_dbp_mm_hg,
  1152. client.most_recent_cellular_bp_sbp_mm_hg,
  1153. client.most_recent_cellular_bp_measurement_at,
  1154. client.most_recent_cellular_weight_value,
  1155. client.most_recent_cellular_weight_measurement_at
  1156. FROM care_month join client on care_month.client_id = client.id join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
  1157. left join note mrmnote on mrmnote.id = (
  1158. select max(n.id) from note n
  1159. where
  1160. n.client_id = client.id AND
  1161. n.is_cancelled = FALSE AND
  1162. (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
  1163. n.effective_dateest::date >= care_month.start_date::date AND
  1164. n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
  1165. )
  1166. left join pro mcp_pro on care_month.mcp_pro_id = mcp_pro.id
  1167. left join pro rmm_pro on care_month.rmm_pro_id = rmm_pro.id
  1168. WHERE
  1169. EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  1170. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  1171. " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
  1172. $orderBy
  1173. ";
  1174. $patients = DB::select($query);
  1175. $timestamp = strtotime(date('Y-m-d'));
  1176. $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
  1177. return view('app.practice-management.remote-monitoring-admin', compact('patients', 'daysRemaining', 'careMonthStart'));
  1178. }
  1179. public function remoteMonitoringAdminCount(Request $request) {
  1180. $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
  1181. $careMonthStart = date($ym . '-01');
  1182. $rc = $request->input('rc') ?: 1;
  1183. $rc2 = $request->input('rc2') ?: 2;
  1184. $conditions = $this->rpmConditionsAdmin($this->performer(), $rc, $rc2);
  1185. $count = DB::select(
  1186. DB::raw(
  1187. "
  1188. SELECT count(*)
  1189. FROM care_month join client on care_month.client_id = client.id
  1190. WHERE
  1191. client.shadow_pro_id is null AND client.is_enrolled_in_rm = 'YES'
  1192. AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
  1193. AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
  1194. " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
  1195. )
  1196. );
  1197. return $count[0]->count;
  1198. }
  1199. private function rpmConditions($performer, $rc, $rc2) {
  1200. $conditions = [];
  1201. $c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
  1202. $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
  1203. $c_hasDevice = "(SELECT COUNT(client_bdt_device.id) FROM client_bdt_device JOIN bdt_device bd on client_bdt_device.device_id = bd.id WHERE client_bdt_device.client_id = client.id) > 0";
  1204. $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
  1205. $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
  1206. $c_notSpokenToThisMonth = "(care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL OR care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE)";
  1207. $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
  1208. $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
  1209. $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
  1210. $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
  1211. $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
  1212. $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
  1213. $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
  1214. $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
  1215. $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
  1216. switch ($rc) {
  1217. case 1:
  1218. $conditions = [$c_isMCP];
  1219. break;
  1220. case 2:
  1221. $conditions = [$c_isMCP, $c_enrolledInRPM];
  1222. break;
  1223. case 3:
  1224. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice];
  1225. break;
  1226. case 4:
  1227. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
  1228. break;
  1229. case 5:
  1230. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
  1231. break;
  1232. case 6:
  1233. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
  1234. break;
  1235. case 7:
  1236. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
  1237. break;
  1238. case 10:
  1239. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
  1240. break;
  1241. case 8:
  1242. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
  1243. break;
  1244. case 9:
  1245. $conditions = [$c_isMCP, $c_enrolledInRPM, $c_deviceUsed];
  1246. break;
  1247. }
  1248. return $conditions;
  1249. }
  1250. private function rpmConditionsAdmin($performer, $rc, $rc2) {
  1251. $conditions = [];
  1252. $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
  1253. $c_hasDevice = "(SELECT COUNT(client_bdt_device.id) FROM client_bdt_device JOIN bdt_device bd on client_bdt_device.device_id = bd.id WHERE client_bdt_device.client_id = client.id) > 0";
  1254. $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
  1255. $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
  1256. $c_notSpokenToThisMonth = "(care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL OR care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE)";
  1257. $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
  1258. $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
  1259. $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
  1260. $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
  1261. $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
  1262. $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
  1263. $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
  1264. $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
  1265. $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
  1266. switch ($rc) {
  1267. case 2:
  1268. $conditions = [$c_enrolledInRPM];
  1269. break;
  1270. case 3:
  1271. $conditions = [$c_enrolledInRPM, $c_hasDevice];
  1272. break;
  1273. case 4:
  1274. $conditions = [$c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
  1275. break;
  1276. case 5:
  1277. $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
  1278. break;
  1279. case 6:
  1280. $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
  1281. break;
  1282. case 7:
  1283. $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
  1284. break;
  1285. case 10:
  1286. $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
  1287. break;
  1288. case 8:
  1289. $conditions = [$c_enrolledInRPM, $c_subscribedToSMS];
  1290. break;
  1291. case 9:
  1292. $conditions = [$c_enrolledInRPM, $c_deviceUsed];
  1293. break;
  1294. }
  1295. return $conditions;
  1296. }
  1297. public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
  1298. $performer = $this->performer();
  1299. $measurements = DB::select(
  1300. DB::raw(
  1301. "
  1302. SELECT measurement.label,
  1303. measurement.ts,
  1304. measurement.effective_date,
  1305. measurement.sbp_mm_hg,
  1306. measurement.dbp_mm_hg,
  1307. measurement.value_pulse,
  1308. measurement.value_irregular,
  1309. measurement.numeric_value,
  1310. measurement.value,
  1311. measurement.uid,
  1312. client.name_first,
  1313. client.name_last,
  1314. client.mcp_pro_id,
  1315. client.default_na_pro_id,
  1316. client.rmm_pro_id,
  1317. client.rme_pro_id
  1318. FROM measurement RIGHT JOIN client on measurement.client_id = client.id
  1319. WHERE
  1320. client.id = {$careMonth->client_id}
  1321. AND measurement.label IS NOT NULL
  1322. AND measurement.label NOT IN ('SBP', 'DBP')
  1323. AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
  1324. AND measurement.is_removed IS FALSE
  1325. AND measurement.client_bdt_measurement_id IS NOT NULL
  1326. AND measurement.care_month_id = {$careMonth->id}
  1327. AND (
  1328. (client.mcp_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_mcp IS FALSE)
  1329. OR (client.rmm_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rmm IS FALSE)
  1330. OR (client.rme_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rme IS FALSE)
  1331. OR (client.default_na_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_non_hcp IS FALSE)
  1332. )
  1333. ORDER BY ts DESC
  1334. "
  1335. )
  1336. );
  1337. return view('app.practice-management.remote-monitoring-measurements', compact('careMonth', 'measurements'));
  1338. }
  1339. public function billMatrix(Request $request)
  1340. {
  1341. $bClients = [];
  1342. $bHCPPros = [];
  1343. $bNAPros = [];
  1344. $filters = [];
  1345. $filters['client'] = $request->input('client');
  1346. $filters['service'] = $request->input('service');
  1347. $filters['hcp'] = $request->input('hcp');
  1348. $filters['hcp_paid'] = $request->input('hcp_paid');
  1349. $filters['expected_op'] = $request->input('expected_op');
  1350. $filters['expected_value'] = $request->input('expected_value');
  1351. $filters['paid_op'] = $request->input('paid_op');
  1352. $filters['paid_value'] = $request->input('paid_value');
  1353. $filters['bal_post_date_op'] = $request->input('bal_post_date_op');
  1354. $filters['bal_post_date_value'] = $request->input('bal_post_date_value');
  1355. $filters['hcp_sign'] = $request->input('hcp_sign');
  1356. $filters['verified'] = $request->input('verified');
  1357. $filters['cancelled'] = $request->input('cancelled');
  1358. $bills = Bill::orderBy('effective_date')->paginate();
  1359. return view('app.practice-management.bill-matrix', compact('bills', 'bClients', 'bHCPPros', 'filters'));
  1360. }
  1361. public function medicarePartBClaims(Request $request)
  1362. {
  1363. $medicarePartBOnly = $request->get("medicare_part_b");
  1364. $allClaims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->get();
  1365. //Only medicare claims
  1366. $claims = [];
  1367. foreach ($allClaims as $claim) {
  1368. if ($claim->client != null && $claim->client->getPrimaryCoverageStatus() == 'YES' && !$claim->edi) {
  1369. $claims[] = $claim;
  1370. }
  1371. }
  1372. $claimEDIs = ClaimEDI::all();
  1373. return view('app.practice-management.medicare-partb-claims', compact('claims', 'claimEDIs'));
  1374. }
  1375. // Generate PDF
  1376. public function downloadClaims()
  1377. {
  1378. $claims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->limit(100)->get();
  1379. view()->share('claims', $claims);
  1380. $pdf = PDF::loadView('app.practice-management.claims-pdf', $claims);
  1381. return $pdf->download('pdf_file.pdf');
  1382. }
  1383. public function tickets(Request $request, $proUid = null)
  1384. {
  1385. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  1386. return view('app.practice-management.tickets', compact('tickets'));
  1387. }
  1388. public function supplyOrders(Request $request)
  1389. {
  1390. // counts
  1391. $counts = $this->getSupplyOrderCounts();
  1392. // so clients
  1393. $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
  1394. $soClientIDs = array_map(function ($_x) {
  1395. return $_x->client_id;
  1396. }, $soClientIDs);
  1397. $soClients = Client::whereIn('id', $soClientIDs)->get();
  1398. // so products
  1399. $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
  1400. $soProductIDs = array_map(function ($_x) {
  1401. return $_x->product_id;
  1402. }, $soProductIDs);
  1403. $soProducts = Product::whereIn('id', $soProductIDs)->get();
  1404. $filters = [];
  1405. $filters['client'] = $request->input('client');
  1406. $filters['product'] = $request->input('product');
  1407. $filters['reason'] = $request->input('reason');
  1408. $filters['cu_memo'] = $request->input('cu_memo');
  1409. $filters['pro_sign'] = $request->input('pro_sign');
  1410. $filters['client_sign'] = $request->input('client_sign');
  1411. $filters['shipment'] = $request->input('shipment');
  1412. $filters['lot_number'] = $request->input('lot_number');
  1413. $filters['imei'] = $request->input('imei');
  1414. $filters['cancelled'] = $request->input('cancelled');
  1415. $supplyOrders = SupplyOrder::where('id', '>', 0);
  1416. // apply filters
  1417. if ($filters['client']) $supplyOrders->where('client_id', $filters['client']);
  1418. if ($filters['product']) $supplyOrders->where('product_id', $filters['product']);
  1419. if ($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
  1420. if ($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
  1421. if ($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
  1422. if ($filters['client_sign']) {
  1423. if ($filters['client_sign'] === 'signed')
  1424. $supplyOrders->where('is_signed_by_client', true);
  1425. elseif ($filters['client_sign'] === 'waived')
  1426. $supplyOrders->where('is_client_signature_waived', true);
  1427. else
  1428. $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
  1429. }
  1430. if ($filters['shipment']) {
  1431. if ($filters['shipment'] === 'not_cleared_for_shipment')
  1432. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', false);
  1433. elseif ($filters['shipment'] === 'cleared_for_shipment')
  1434. $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', true);
  1435. else
  1436. $supplyOrders
  1437. ->whereNotNull('shipment_id')
  1438. ->whereRaw('(SELECT status FROM shipment WHERE id = shipment_id LIMIT 1) = ?', [$filters['shipment']]);
  1439. }
  1440. if ($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
  1441. if ($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
  1442. if ($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  1443. $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
  1444. return view('app.practice-management.supply-orders',
  1445. compact('supplyOrders', 'filters',
  1446. 'soClients', 'soProducts', 'counts'
  1447. )
  1448. );
  1449. }
  1450. public function shipments(Request $request, $filter = null)
  1451. {
  1452. // counts
  1453. $counts = $this->getShipmentCounts();
  1454. // so clients
  1455. $shClientIDs = DB::table('shipment')->select('client_id')->distinct()->get()->toArray();
  1456. $shClientIDs = array_map(function ($_x) {
  1457. return $_x->client_id;
  1458. }, $shClientIDs);
  1459. $shClients = Client::whereIn('id', $shClientIDs)->get();
  1460. $shipments = Shipment::where('id', '>', 0);
  1461. $filters = [];
  1462. $filters['client'] = $request->input('client');
  1463. $filters['courier'] = $request->input('courier');
  1464. $filters['tracking_num'] = $request->input('tracking_num');
  1465. $filters['label'] = $request->input('label');
  1466. $filters['status'] = $request->input('status');
  1467. $filters['cancelled'] = $request->input('cancelled');
  1468. if ($filters['client']) $shipments->where('client_id', $filters['client']);
  1469. if ($filters['courier']) $shipments->where('courier', 'ILIKE', '%' . $filters['courier'] . '%');
  1470. if ($filters['tracking_num']) $shipments->where('tracking_number', 'ILIKE', '%' . $filters['tracking_num'] . '%');
  1471. if ($filters['label']) {
  1472. if ($filters['label'] === 'yes')
  1473. $shipments->whereNotNull('label_system_file_id');
  1474. else
  1475. $shipments->whereNull('label_system_file_id');
  1476. }
  1477. if ($filters['status']) $shipments->where('status', $filters['status']);
  1478. if ($filters['cancelled']) $shipments->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
  1479. $shipments = $shipments->orderBy('created_at', 'desc')->paginate();
  1480. return view('app.practice-management.shipments', compact('shipments', 'filters', 'shClients', 'counts'));
  1481. }
  1482. public function cellularMeasurements(Request $request)
  1483. {
  1484. $measurements = Measurement::orderBy('ts', 'desc')->whereNotNull('ts')->paginate();
  1485. return view('app.practice-management.cellular-measurements', compact('measurements'));
  1486. }
  1487. // v2 supply-orders & shipments management (wh)
  1488. public function supplyOrdersReadyToShip(Request $request)
  1489. {
  1490. $counts = $this->getSupplyOrderCounts();
  1491. $supplyOrders = SupplyOrder
  1492. ::where('is_cleared_for_shipment', true)
  1493. ->where('is_cancelled', false)
  1494. ->whereNull('shipment_id')
  1495. ->join('client', 'client.id', '=', 'supply_order.client_id')
  1496. ->orderBy('client.name_last', 'ASC')
  1497. ->orderBy('client.name_first', 'ASC')
  1498. ->orderBy('supply_order.client_id', 'ASC')
  1499. ->orderBy('supply_order.mailing_address_full', 'ASC')
  1500. ->orderBy('supply_order.created_at', 'ASC')
  1501. ->select('supply_order.*')
  1502. ->paginate();
  1503. return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
  1504. }
  1505. public function supplyOrdersShipmentUnderway(Request $request)
  1506. {
  1507. $counts = $this->getSupplyOrderCounts();
  1508. $supplyOrders = SupplyOrder
  1509. ::where('is_cancelled', false)
  1510. ->whereNotNull('shipment_id')
  1511. ->orderBy('client_id', 'ASC')
  1512. ->orderBy('mailing_address_full', 'ASC')
  1513. ->orderBy('created_at', 'ASC')
  1514. ->paginate();
  1515. return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
  1516. }
  1517. public function supplyOrdersHanging(Request $request)
  1518. {
  1519. $counts = $this->getSupplyOrderCounts();
  1520. $supplyOrders = SupplyOrder
  1521. ::select('supply_order.*')
  1522. ->leftJoin('shipment', function($join) {
  1523. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  1524. })
  1525. ->where('shipment.status', 'CANCELLED')
  1526. ->where('supply_order.is_cancelled', false)
  1527. ->orderBy('supply_order.client_id', 'ASC')
  1528. ->orderBy('supply_order.mailing_address_full', 'ASC')
  1529. ->orderBy('supply_order.created_at', 'ASC')
  1530. ->paginate();
  1531. return view('app.practice-management.supply-orders-hanging', compact('supplyOrders', 'counts'));
  1532. }
  1533. public function supplyOrdersCancelledButUnacknowledged(Request $request)
  1534. {
  1535. $supplyOrders = SupplyOrder::where('signed_by_pro_id', $this->performer()->pro->id)
  1536. ->where('is_cancelled', true)
  1537. ->where('is_cancellation_acknowledged', false)
  1538. ->orderBy('created_at', 'desc')
  1539. ->paginate();
  1540. return view('app.practice-management.supply-orders-cancelled-but-unacknowledged', compact('supplyOrders'));
  1541. }
  1542. public function supplyOrdersUnsigned(Request $request)
  1543. {
  1544. $supplyOrders = SupplyOrder
  1545. ::where('is_cancelled', false)
  1546. ->where('is_signed_by_pro', false)
  1547. ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$this->performer()->pro->id])
  1548. ->orderBy('created_at', 'desc')
  1549. ->paginate();
  1550. return view('app.practice-management.supply-orders-unsigned', compact('supplyOrders'));
  1551. }
  1552. private function getSupplyOrderCounts()
  1553. {
  1554. return [
  1555. "supplyOrders" => SupplyOrder::count(),
  1556. "supplyOrdersReadyToShip" => SupplyOrder
  1557. ::where('is_cleared_for_shipment', true)
  1558. ->where('is_cancelled', false)
  1559. ->whereNull('shipment_id')->count(),
  1560. "supplyOrdersShipmentUnderway" => SupplyOrder
  1561. ::where('is_cancelled', false)
  1562. ->whereNotNull('shipment_id')->count(),
  1563. "supplyOrdersHanging" => SupplyOrder
  1564. ::leftJoin('shipment', function($join) {
  1565. $join->on('supply_order.shipment_id', '=', 'shipment.id');
  1566. })
  1567. ->where('shipment.status', 'CANCELLED')
  1568. ->where('supply_order.is_cancelled', false)
  1569. ->count(),
  1570. ];
  1571. }
  1572. public function shipmentsReadyToPrint(Request $request)
  1573. {
  1574. $counts = $this->getShipmentCounts();
  1575. $shipments = Shipment
  1576. ::where('is_cancelled', false)
  1577. ->where('status', 'CREATED')
  1578. ->orderBy('created_at', 'ASC')
  1579. ->paginate();
  1580. return view('app.practice-management.shipments-ready-to-print', compact('shipments', 'counts'));
  1581. }
  1582. public function shipmentsShipmentUnderway(Request $request)
  1583. {
  1584. $counts = $this->getShipmentCounts();
  1585. $shipments = Shipment
  1586. ::where('is_cancelled', false)
  1587. ->where('status', 'PRINTED')
  1588. ->orderBy('created_at', 'ASC')
  1589. ->paginate();
  1590. return view('app.practice-management.shipments-waiting-for-picker', compact('shipments', 'counts'));
  1591. }
  1592. private function getShipmentCounts()
  1593. {
  1594. return [
  1595. "shipments" => Shipment::count(),
  1596. "shipmentsReadyToPrint" => Shipment
  1597. ::where('is_cancelled', false)
  1598. ->where('status', 'CREATED')
  1599. ->count(),
  1600. "shipmentsWaitingForPicker" => Shipment
  1601. ::where('is_cancelled', false)
  1602. ->where('status', 'PRINTED')
  1603. ->count()
  1604. ];
  1605. }
  1606. public function shipment(Request $request, Shipment $shipment)
  1607. {
  1608. return view('app.practice-management.shipment', compact('shipment'));
  1609. }
  1610. public function shipmentsMultiPrint(Request $request, $ids)
  1611. {
  1612. $ids = array_map(function ($_x) {
  1613. return intval($_x);
  1614. }, explode("|", $ids));
  1615. $shipments = Shipment::whereIn('id', $ids)->get();
  1616. return view('app.practice-management.shipments-multi-print', compact('shipments'));
  1617. }
  1618. public function patientClaimSummary(Request $request, $proUid = null)
  1619. {
  1620. $notesTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE"))[0]->count;
  1621. $notesTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS TRUE"))[0]->count;
  1622. $notesTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS TRUE"))[0]->count;
  1623. $notes3rdPartyTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1624. $notes3rdPartyTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND n.is_bill_closed IS TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1625. $notes3rdPartyTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note n LEFT JOIN client c ON n.client_id = c.id WHERE n.is_cancelled IS NOT TRUE AND n.is_claim_closed IS TRUE AND c.is_part_b_primary <> 'YES'"))[0]->count;
  1626. $patientsTotal = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1627. $patientsTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) y) AND 0 IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1628. $patientsTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM client WHERE is_active IS TRUE AND 0 NOT IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND note.client_id = client.id) y) AND 0 IN (SELECT c FROM (SELECT COUNT(*) c FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS NOT TRUE AND note.client_id = client.id) x)"))[0]->count;
  1629. $performerPro = $this->performer->pro;
  1630. $allPros = [];
  1631. if ($performerPro->pro_type == 'ADMIN') {
  1632. $allPros = Pro::all();
  1633. } else {
  1634. $allPros = [$performerPro];
  1635. }
  1636. //Patient | MCP | # Notes Total | # Notes without Billing Closed | # Notes without Claiming Closed
  1637. $patientsQuery = Client::where('is_dummy', '=', false)
  1638. ->whereNull('shadow_pro_id')
  1639. ->select('id', 'uid', 'name_first', 'name_last', 'mcp_pro_id', 'is_part_b_primary', 'medicare_advantage_plan',
  1640. DB::raw("(SELECT name_first||' '||name_last FROM pro where pro.id = client.mcp_pro_id) as mcp"),
  1641. DB::raw("(SELECT uid FROM pro where pro.id = mcp_pro_id) as mcp_pro_uid"),
  1642. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id) as notes_total"),
  1643. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_bill_closed IS NOT true) as notes_without_billing_closed"),
  1644. DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_claim_closed IS NOT true) as notes_without_claiming_closed")
  1645. )->orderBy('is_part_b_primary', 'asc')->orderBy('notes_without_claiming_closed', 'desc');
  1646. if ($proUid) {
  1647. $mcpPro = Pro::where('uid', $proUid)->first();
  1648. if ($mcpPro) {
  1649. $patientsQuery->where('client.mcp_pro_id', '=', $mcpPro->id);
  1650. }
  1651. }
  1652. $patientsQuery->whereRaw('(SELECT COUNT(*) FROM note where note.client_id = client.id) > 0');
  1653. $patientsQuery->orderBy('notes_total', 'DESC');
  1654. $patients = $patientsQuery->paginate(50);
  1655. $data = [
  1656. 'patients' => $patients,
  1657. 'proUid' => $proUid,
  1658. 'allPros' => $allPros,
  1659. 'notesTotal' => $notesTotal,
  1660. 'notesTotalWithBillingClosed' => $notesTotalWithBillingClosed,
  1661. 'notesTotalWithClaimingClosed' => $notesTotalWithClaimingClosed,
  1662. 'notes3rdPartyTotal' => $notes3rdPartyTotal,
  1663. 'notes3rdPartyTotalWithBillingClosed' => $notes3rdPartyTotalWithBillingClosed,
  1664. 'notes3rdPartyTotalWithClaimingClosed' => $notes3rdPartyTotalWithClaimingClosed,
  1665. 'patientsTotal' => $patientsTotal,
  1666. 'patientsTotalWithBillingClosed' => $patientsTotalWithBillingClosed,
  1667. 'patientsTotalWithClaimingClosed' => $patientsTotalWithClaimingClosed
  1668. ];
  1669. return view('app.practice-management.patient-claim-summary', $data);
  1670. }
  1671. public function claims(Request $request){
  1672. $status = $request->get('status');
  1673. $claims = [];
  1674. if(!$status){
  1675. $claims = Claim::orderBy('created_at', 'DESC')->paginate();
  1676. }else{
  1677. $claims = Claim::where('status', $status)->orderBy('created_at', 'DESC')->paginate();
  1678. }
  1679. return view('app.practice-management.claims', compact('claims', 'status'));
  1680. }
  1681. public function processClaims(Request $request) {
  1682. $status = '';
  1683. $q = $request->input('q') ? $request->input('q') : '';
  1684. $from = $request->input('from') ? $request->input('from') : '1900-01-01';
  1685. $to = $request->input('to') ? $request->input('to') : '2100-01-01';
  1686. $params = [
  1687. 'q' => '%' . $q . '%',
  1688. 'from' => $from,
  1689. 'to' => $to
  1690. ];
  1691. $hcpPro = $request->input('hcp') ? Pro::where('uid', $request->input('hcp'))->first() : null;
  1692. if($hcpPro) {
  1693. $params['hcp'] = $hcpPro->id;
  1694. }
  1695. $claims = DB::select(DB::raw("
  1696. SELECT claim.uid AS uid,
  1697. DATE(claim.created_at) AS created,
  1698. claim.status,
  1699. client.uid AS client_uid,
  1700. client.cell_number AS client_phone,
  1701. client.phone_home AS client_phone_home,
  1702. (client.name_last || ' ' || client.name_first) AS client ,
  1703. client.chart_number AS client_chart_number,
  1704. cp.id AS claim_pro_id,
  1705. (cp.name_last || ' ' || cp.name_first) AS claim_pro,
  1706. sp.id AS status_pro_id,
  1707. (sp.name_last || ' ' || sp.name_first) AS status_pro,
  1708. note.uid AS note_uid,
  1709. note.method,
  1710. note.new_or_fu_or_na,
  1711. care_month.uid AS care_month_uid,
  1712. -- claim.status_updated_at,
  1713. (DATE(claim.status_updated_at) || ' ' ||
  1714. LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
  1715. LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) AS status_updated_at,
  1716. (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) AS cpts,
  1717. (SELECT COUNT(claim_line_icd.id) FROM claim_line_icd WHERE claim_line_id IN (SELECT id FROM claim_line WHERE claim_id = claim.id)) AS icds,
  1718. ROUND(claim.expected_total, 3) as expected_total
  1719. FROM claim
  1720. join client on claim.client_id = client.id
  1721. join pro cp on claim.pro_id = cp.id
  1722. left join note on claim.note_id = note.id
  1723. left join care_month on claim.care_month_id = care_month.id
  1724. left join app_session on claim.status_updated_by_session_id = app_session.id
  1725. left join pro sp on app_session.pro_id = sp.id
  1726. --WHERE claim.status IS NULL OR claim.status = 'NEW'
  1727. WHERE (claim.status is NULL OR claim.status NOT IN ('CANCELLED', 'ABANDONED'" . ($request->input('show-submitted') ? "" : ", 'SUBMITTED'") . "))
  1728. -- AND claim.current_version_id IS NOT NULL
  1729. AND (client.name_first ILIKE :q OR
  1730. client.name_last ILIKE :q OR
  1731. client.chart_number ILIKE :q OR
  1732. client.mcn ILIKE :q)
  1733. AND (claim.created_at >= :from AND claim.created_at <= :to)
  1734. " . ($hcpPro ? "AND claim.pro_id = :hcp" : '') . "
  1735. AND claim.id IN (SELECT mb_claim.claim_id FROM mb_claim)
  1736. ORDER BY claim.created_at DESC
  1737. --OFFSET 0 LIMIT 15
  1738. "), $params);
  1739. if($request->input('json')) {
  1740. return json_encode($claims);
  1741. }
  1742. return view('app.practice-management.process-claims', compact('claims', 'status'));
  1743. }
  1744. public function rmLaunchAndClean(Request $request) {
  1745. $keyNumbers = [];
  1746. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40'] = CareMonth::where('is_bill_closed', false)
  1747. ->whereNotNull('company_pro_id')
  1748. ->whereNotNull('company_pro_payer_id')
  1749. ->whereNotNull('company_location_id')
  1750. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1751. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1752. ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
  1753. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1754. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1755. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE )')
  1756. ->count();
  1757. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
  1758. ->whereNotNull('company_pro_id')
  1759. ->whereNotNull('company_pro_payer_id')
  1760. ->whereNotNull('company_location_id')
  1761. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1762. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1763. ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
  1764. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1765. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1766. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS NOT TRUE AND has_mcp_rm_interacted_by_note IS NOT TRUE AND is_rm_interaction_waived IS NOT TRUE )')
  1767. ->count();
  1768. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20'] = CareMonth::where('is_bill_closed', false)
  1769. ->whereNotNull('company_pro_id')
  1770. ->whereNotNull('company_pro_payer_id')
  1771. ->whereNotNull('company_location_id')
  1772. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1773. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1774. ->where('rm_total_time_in_seconds', '<', 4200)
  1775. ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
  1776. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1777. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1778. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE)')
  1779. ->count();
  1780. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
  1781. ->whereNotNull('company_pro_id')
  1782. ->whereNotNull('company_pro_payer_id')
  1783. ->whereNotNull('company_location_id')
  1784. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1785. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1786. ->where('rm_total_time_in_seconds', '<', 4200)
  1787. ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
  1788. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1789. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1790. ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS NOT TRUE AND has_mcp_rm_interacted_by_note IS NOT TRUE AND is_rm_interaction_waived IS NOT TRUE )')
  1791. ->count();
  1792. $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP'] = CareMonth::where('is_bill_closed', false)
  1793. ->whereNotNull('company_pro_id')
  1794. ->whereNotNull('company_pro_payer_id')
  1795. ->whereNotNull('company_location_id')
  1796. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1797. ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
  1798. ->whereRaw('is_rm_time_waived IS NOT TRUE')
  1799. ->whereRaw('(rm_total_time_in_seconds < 3000 OR (rm_total_time_in_seconds >= 3000 AND is_rm_interaction_waived IS TRUE))')
  1800. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1801. ->count();
  1802. $keyNumbers['careMonthsEligibleForBillGeneration_RMB'] = CareMonth::where('is_bill_closed', false)
  1803. ->whereNotNull('company_pro_id')
  1804. ->whereNotNull('company_pro_payer_id')
  1805. ->whereNotNull('company_location_id')
  1806. ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
  1807. ->whereRaw('is_rm_time_waived IS TRUE')
  1808. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1809. ->count();
  1810. $keyNumbers['careMonthsWith16OrMoreMeasurementDays'] = CareMonth::where('is_bill_closed', false)
  1811. ->where('number_of_days_with_remote_measurements', '>=', 16 )
  1812. ->count();
  1813. $careMonthsWith16PlusMeasurements = CareMonth::where('is_bill_closed', false)
  1814. ->where('number_of_days_with_remote_measurements', '>=', 16 )->get();
  1815. return view('app.practice-management.rm-launch-and-clean', compact('keyNumbers', 'careMonthsWith16PlusMeasurements'));
  1816. }
  1817. public function processNotes(Request $request) {
  1818. $mode = $request->input('mode') ? $request->input('mode') : '1';
  1819. if(($mode < 1 || $mode > 5) && $mode != 8) $mode = 1;
  1820. DB::enableQueryLog(); // Enable query log
  1821. $test = Note::where('is_cancelled', false)
  1822. ->where('is_signed_by_hcp', true)
  1823. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1824. ->whereNull('current_note_pickup_for_processing_id')
  1825. ->where('is_billing_marked_done', true)
  1826. ->where('is_bill_closed', true)
  1827. ->where('is_claim_closed', true)
  1828. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1829. ->count();
  1830. // var_dump($test);
  1831. // dd(DB::getQueryLog()); // Show results of log
  1832. // exit;
  1833. $counts = [
  1834. "picked" => Note::where('is_cancelled', false)
  1835. ->whereNotNull('current_note_pickup_for_processing_id')
  1836. ->count(),
  1837. "bad" => Note::where('is_cancelled', false)
  1838. ->whereRaw("((detail_json)::json->>'isBad' = 'true')")
  1839. ->count(),
  1840. // not yet signed
  1841. "mode-1" => Note::where('is_cancelled', false)
  1842. ->where('is_signed_by_hcp', false)
  1843. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1844. // ->whereNull('current_note_pickup_for_processing_id')
  1845. ->count(),
  1846. // billing not marked done
  1847. "mode-2" => Note::where('is_cancelled', false)
  1848. ->where('is_signed_by_hcp', true)
  1849. //->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1850. // ->whereNull('current_note_pickup_for_processing_id')
  1851. ->where('is_billing_marked_done', false)
  1852. ->count(),
  1853. // billing not closed
  1854. "mode-3" => Note::where('is_cancelled', false)
  1855. ->where('is_signed_by_hcp', true)
  1856. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1857. // ->whereNull('current_note_pickup_for_processing_id')
  1858. ->where('is_billing_marked_done', true)
  1859. ->where('is_bill_closed', false)
  1860. ->count(),
  1861. // claiming not closed
  1862. "mode-4" => Note::where('is_cancelled', false)
  1863. ->where('is_signed_by_hcp', true)
  1864. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1865. // ->whereNull('current_note_pickup_for_processing_id')
  1866. ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
  1867. ->where('is_billing_marked_done', true)
  1868. ->where('is_bill_closed', true)
  1869. ->where('is_claim_closed', false)
  1870. ->count(),
  1871. // has unsubmitted claims
  1872. "mode-5" => Note::where('is_cancelled', false)
  1873. /*->where('is_signed_by_hcp', true)
  1874. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1875. ->whereNull('current_note_pickup_for_processing_id')
  1876. ->where('is_billing_marked_done', true)
  1877. ->where('is_bill_closed', true)
  1878. ->where('is_claim_closed', true)
  1879. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  1880. */
  1881. ->where('is_signed_by_hcp', true)
  1882. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1883. // ->whereNull('current_note_pickup_for_processing_id')
  1884. ->where('is_billing_marked_done', true)
  1885. ->where('is_bill_closed', true)
  1886. // ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true')")
  1887. ->where('is_claim_closed', true)
  1888. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0)")
  1889. ->count(),
  1890. // has unsubmitted claims MARKED GOOD!
  1891. "mode-8" => Note::where('is_cancelled', false)
  1892. ->where('is_signed_by_hcp', true)
  1893. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  1894. ->whereNull('current_note_pickup_for_processing_id')
  1895. ->where('is_billing_marked_done', true)
  1896. ->where('is_bill_closed', true)
  1897. ->where('is_claim_closed', false)
  1898. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1899. ->count(),
  1900. // all good
  1901. "mode-6" => Note::where('is_cancelled', false)
  1902. ->where('is_signed_by_hcp', true)
  1903. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1904. // ->whereNull('current_note_pickup_for_processing_id')
  1905. ->where('is_billing_marked_done', true)
  1906. ->where('is_bill_closed', true)
  1907. ->where('is_claim_closed', true)
  1908. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id) > 0)")
  1909. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  1910. ->count(),
  1911. "mode-7" => Note::where('is_cancelled', false)
  1912. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  1913. ->count(),
  1914. ];
  1915. return view('app.practice-management.process-notes', compact('mode', 'counts'));
  1916. }
  1917. public function notesProcessingCenter(Request $request) {
  1918. $notes = Note::where('is_cancelled', false);
  1919. // filters
  1920. $proUid = $request->input('proUid');
  1921. if($proUid) {
  1922. $fPro = Pro::where('uid', $proUid)->first();
  1923. if($fPro) {
  1924. $notes = $notes->where('hcp_pro_id', $fPro->id);
  1925. }
  1926. }
  1927. $proSigned = $request->input('proSigned');
  1928. switch($proSigned) {
  1929. case 'yes': $notes = $notes->where('is_signed_by_hcp', true); break;
  1930. case 'no': $notes = $notes->where('is_signed_by_hcp', '!=', true); break;
  1931. }
  1932. $billingMarkedDone = $request->input('billingMarkedDone');
  1933. switch($billingMarkedDone) {
  1934. case 'yes': $notes = $notes->where('is_billing_marked_done', true); break;
  1935. case 'no': $notes = $notes->where('is_billing_marked_done', '!=', true); break;
  1936. }
  1937. $billingClosed = $request->input('billingClosed');
  1938. switch($billingClosed) {
  1939. case 'yes': $notes = $notes->where('is_bill_closed', true); break;
  1940. case 'no': $notes = $notes->where('is_bill_closed', '!=', true); break;
  1941. }
  1942. $claimingClosed = $request->input('claimingClosed');
  1943. switch($claimingClosed) {
  1944. case 'yes': $notes = $notes->where('is_claim_closed', true); break;
  1945. case 'no': $notes = $notes->where('is_claim_closed', '!=', true); break;
  1946. }
  1947. $allClaimsSubmitted = $request->input('allClaimsSubmitted');
  1948. if($allClaimsSubmitted) {
  1949. // TODO
  1950. }
  1951. $goodBad = $request->input('goodBad');
  1952. switch($goodBad) {
  1953. case 'good': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'false'"); break;
  1954. case 'bad': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'true'"); break;
  1955. case 'unclassified': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' is null"); break;
  1956. }
  1957. $startDate = $request->input('startDate');
  1958. if($startDate) {
  1959. $notes = $notes->where('effective_dateest', '>=', $startDate);
  1960. }
  1961. $endDate = $request->input('endDate');
  1962. if($endDate) {
  1963. $notes = $notes->where('effective_dateest', '<=', $endDate);
  1964. }
  1965. $mcPartB = $request->input('mcPartB');
  1966. if($mcPartB) {
  1967. // TODO
  1968. }
  1969. $notes = $notes->orderBy('effective_dateest')->paginate(10);
  1970. return view('app.practice-management.notes-processing-center', compact('notes'));
  1971. }
  1972. public function getNextNote(Request $request, $mode)
  1973. {
  1974. $note = null;
  1975. switch (+$mode) {
  1976. case 1:
  1977. $note = Note::where('is_cancelled', false)
  1978. ->where('is_signed_by_hcp', false)
  1979. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1980. ->whereNull('current_note_pickup_for_processing_id')
  1981. ->orderBy('effective_dateest', 'DESC')
  1982. ->first();
  1983. break;
  1984. case 2:
  1985. $note = Note::where('is_cancelled', false)
  1986. ->where('is_signed_by_hcp', true)
  1987. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1988. ->whereNull('current_note_pickup_for_processing_id')
  1989. ->where('is_billing_marked_done', false)
  1990. ->orderBy('effective_dateest', 'DESC')
  1991. ->first();
  1992. break;
  1993. case 3:
  1994. $note = Note::where('is_cancelled', false)
  1995. ->where('is_signed_by_hcp', true)
  1996. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  1997. ->whereNull('current_note_pickup_for_processing_id')
  1998. ->where('is_billing_marked_done', true)
  1999. ->where('is_bill_closed', false)
  2000. ->orderBy('effective_dateest', 'DESC')
  2001. ->first();
  2002. break;
  2003. case 4: // claiming not closed
  2004. DB::enableQueryLog(); // Enable query log
  2005. $note = Note::where('is_cancelled', false)
  2006. ->where('is_signed_by_hcp', true)
  2007. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  2008. ->whereNull('current_note_pickup_for_processing_id')
  2009. ->where('is_billing_marked_done', true)
  2010. ->where('is_bill_closed', true)
  2011. ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
  2012. ->where('is_claim_closed', false)
  2013. ->orderBy('effective_dateest', 'DESC')
  2014. ->first();
  2015. // DB::enableQueryLog(); // Enable query log
  2016. // Your Eloquent query executed by using get()
  2017. // dd(DB::getQueryLog()); // Show results of log
  2018. break;
  2019. case 5:
  2020. $note = Note::where('is_cancelled', false)
  2021. ->where('is_signed_by_hcp', true)
  2022. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  2023. ->whereNull('current_note_pickup_for_processing_id')
  2024. ->where('is_billing_marked_done', true)
  2025. ->where('is_bill_closed', true)
  2026. ->where('is_claim_closed', true)
  2027. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
  2028. ->orderBy('effective_dateest', 'DESC')
  2029. ->first();
  2030. break;
  2031. case 8:
  2032. $note = Note::where('is_cancelled', false)
  2033. ->where('is_signed_by_hcp', true)
  2034. ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
  2035. ->whereNull('current_note_pickup_for_processing_id')
  2036. ->where('is_billing_marked_done', true)
  2037. ->where('is_bill_closed', true)
  2038. ->where('is_claim_closed', false)
  2039. ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
  2040. ->orderBy('effective_dateest', 'DESC')
  2041. ->first();
  2042. break;
  2043. }
  2044. if($note) {
  2045. $note->client_uid = $note->client->uid;
  2046. }
  2047. return json_encode($note);
  2048. }
  2049. public function pickedNotes(Request $request) {
  2050. $counts = [
  2051. "unpicked" => Note::where('is_cancelled', false)
  2052. ->whereNull('current_note_pickup_for_processing_id')
  2053. ->count(),
  2054. ];
  2055. $notes = Note::where('is_cancelled', false)
  2056. ->whereNotNull('current_note_pickup_for_processing_id')
  2057. ->orderBy('effective_dateest', 'ASC')
  2058. ->paginate();
  2059. return view('app.practice-management.picked-notes', compact('counts', 'notes'));
  2060. }
  2061. public function badNotes(Request $request) {
  2062. $counts = [
  2063. "unpicked" => Note::where('is_cancelled', false)
  2064. ->whereNull('current_note_pickup_for_processing_id')
  2065. ->count(),
  2066. ];
  2067. $notes = Note::where('is_cancelled', false)
  2068. ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
  2069. ->orderBy('effective_dateest', 'ASC')
  2070. ->paginate();
  2071. return view('app.practice-management.bad-notes', compact('counts', 'notes'));
  2072. }
  2073. public function doneNotes(Request $request) {
  2074. $counts = [
  2075. "unpicked" => Note::where('is_cancelled', false)
  2076. ->whereNull('current_note_pickup_for_processing_id')
  2077. ->count(),
  2078. ];
  2079. $notes = Note::where('is_cancelled', false)
  2080. ->where('is_signed_by_hcp', true)
  2081. ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
  2082. ->whereNull('current_note_pickup_for_processing_id')
  2083. ->where('is_billing_marked_done', true)
  2084. ->where('is_bill_closed', true)
  2085. ->where('is_claim_closed', true)
  2086. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id) > 0")
  2087. ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0")
  2088. ->orderBy('effective_dateest', 'ASC')
  2089. ->paginate();
  2090. return view('app.practice-management.done-notes', compact('counts', 'notes'));
  2091. }
  2092. public function currentMbClaim(Request $request, $claimUid) {
  2093. $claim = Claim::where('uid', $claimUid)->first();
  2094. return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->where('status', '!=', 'CANCELLED')->first());
  2095. }
  2096. public function currentClaimLines(Request $request, $claimUid) {
  2097. $claim = Claim::where('uid', $claimUid)->first();
  2098. if($request->input('json')) {
  2099. foreach ($claim->lines as $line) {
  2100. $line->expected_total = round($line->expected_total, 3);
  2101. $x = $line->claimLineIcds;
  2102. }
  2103. return json_encode($claim->lines);
  2104. }
  2105. return view('app.practice-management._claim-lines', compact('claim'));
  2106. }
  2107. public function packsMultiPrint(Request $request) {
  2108. $packs = Pack
  2109. ::select('pack.*')
  2110. ->leftJoin('shipment', function($join) {
  2111. $join->on('pack.shipment_id', '=', 'shipment.id');
  2112. })
  2113. ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
  2114. ->where(function ($query) {
  2115. $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
  2116. })
  2117. ->whereNotNull('pack.label_system_file_id')
  2118. ->orderBy('pack.created_at', 'ASC')
  2119. ->get();
  2120. return view('app.practice-management.packs-multi-print', compact('packs'));
  2121. }
  2122. public function packsMultiPDF(Request $request, $ids) {
  2123. $ids = array_map(function ($_x) {
  2124. return intval($_x);
  2125. }, explode("|", $ids));
  2126. $packs = Pack::whereIn('id', $ids)->get();
  2127. }
  2128. public function handouts(Request $request) {
  2129. $handouts = Handout::orderBy('display_name')->get();
  2130. return view('app.practice-management.handouts', compact('handouts'));
  2131. }
  2132. private function callJava($request, $endPoint, $data)
  2133. {
  2134. $url = config('stag.backendUrl') . $endPoint;
  2135. $response = Http::asForm()
  2136. ->withHeaders([
  2137. 'sessionKey' => $request->cookie('sessionKey')
  2138. ])
  2139. ->post($url, $data)
  2140. ->body();
  2141. dd($response);
  2142. return $response;
  2143. }
  2144. public function genericBills(Request $request)
  2145. {
  2146. return view('app.practice-management.generic-bills');
  2147. }
  2148. public function billsUnderProcessing(Request $request)
  2149. {
  2150. $bills = Bill::where('is_cancelled', false)
  2151. ->where(function ($query) { // mcp of any client program and program OB pending
  2152. $query
  2153. ->where(function ($_query) {
  2154. $_query->where('hcp_pro_id', $this->pro->id)
  2155. ->where('hcp_expected_payment_amount', '>', 0)
  2156. ->where('has_hcp_been_paid', false)
  2157. ->where('is_signed_by_hcp', true);
  2158. })
  2159. ->orWhere(function ($_query) {
  2160. $_query->where('cm_pro_id', $this->pro->id)
  2161. ->where('cm_expected_payment_amount', '>', 0)
  2162. ->where('has_cm_been_paid', false)
  2163. ->where('is_signed_by_cm', true);
  2164. })
  2165. ->orWhere(function ($_query) {
  2166. $_query->where('rme_pro_id', $this->pro->id)
  2167. ->where('rme_expected_payment_amount', '>', 0)
  2168. ->where('has_rme_been_paid', false)
  2169. ->where('is_signed_by_rme', true);
  2170. })
  2171. ->orWhere(function ($_query) {
  2172. $_query->where('rmm_pro_id', $this->pro->id)
  2173. ->where('rmm_expected_payment_amount', '>', 0)
  2174. ->where('has_rmm_been_paid', false)
  2175. ->where('is_signed_by_rmm', true);
  2176. })
  2177. ->orWhere(function ($_query) {
  2178. $_query->where('generic_pro_id', $this->pro->id)
  2179. ->where('generic_pro_expected_payment_amount', '>', 0)
  2180. ->where('has_generic_pro_been_paid', false)
  2181. ->where('is_signed_by_generic_pro', true);
  2182. });
  2183. })
  2184. ->orderBy('created_at', 'DESC')
  2185. ->paginate();
  2186. return view('app.practice-management.bills-under-processing', compact('bills'));
  2187. }
  2188. public function careMonthReport(Request $request) {
  2189. $m = $request->input('m');
  2190. $y = $request->input('y');
  2191. if(!$m || !$y) {
  2192. $date = date('Y-m-01');
  2193. }
  2194. else {
  2195. $date = date('Y-m-d', strtotime("$m/1/$y"));
  2196. }
  2197. $pro = $this->pro;
  2198. $records = DB::select("
  2199. SELECT cm.id as care_month_id,
  2200. cm.uid as care_month_uid,
  2201. c.id as client_id,
  2202. c.uid as client_uid,
  2203. cm.number_of_days_with_remote_measurements,
  2204. cm.rm_total_time_in_seconds_by_mcp,
  2205. cm.rm_total_time_in_seconds_by_rme_pro,
  2206. cm.rm_total_time_in_seconds_by_rmm_pro,
  2207. cm.mcp_pro_id,
  2208. cm.rme_pro_id,
  2209. cm.rmm_pro_id,
  2210. (c.name_first || ' ' || c.name_last) as client_name
  2211. FROM care_month cm
  2212. JOIN client c on cm.client_id = c.id
  2213. WHERE cm.start_date = :startDate
  2214. AND (cm.mcp_pro_id = :proID OR
  2215. cm.rme_pro_id = :proID OR
  2216. cm.rmm_pro_id = :proID)
  2217. ORDER BY c.name_last, c.name_first
  2218. ",
  2219. ['startDate' => $date, 'proID' => $pro->id]
  2220. );
  2221. return view('app.practice-management.care-month-report', compact('records', 'date'));
  2222. }
  2223. public function myTeams(Request $request) {
  2224. $pro = $this->pro;
  2225. // get all teams where the authed-pro is the assistant pro
  2226. $teams = ProTeam::where('assistant_pro_id', $pro->id)
  2227. ->where('is_active', true)
  2228. ->orderBy('slug')
  2229. ->get();
  2230. return view('app.practice-management.my-teams', compact('teams'));
  2231. }
  2232. public function patientsAccountsInvites(Request $request){
  2233. $filters = $request->all();
  2234. $accountInvites = AccountInvite::select('account_invite.*')
  2235. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  2236. if($this->performer->pro->pro_type !== 'ADMIN'){
  2237. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  2238. }
  2239. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  2240. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  2241. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  2242. return view('app.practice-management.patients-accounts-invites', compact('accountInvites','filters'));
  2243. }
  2244. public function clientsBdtDevices(Request $request){
  2245. $filters = $request->all();
  2246. $devices = ClientBDTDevice::select(
  2247. 'client_bdt_device.*',
  2248. DB::raw('(SELECT COUNT(*) FROM bdt_measurement WHERE bdt_measurement.bdt_device_id = client_bdt_device.device_id AND is_cellular_zero IS FALSE) as num_of_measurements'))
  2249. // DB::raw('(SELECT ts_date_time FROM bdt_measurement WHERE bdt_measurement.bdt_device_id = client_bdt_device.device_id AND is_cellular_zero IS FALSE ORDER BY ts_date_time DESC LIMIT 1) as most_recent_none_zero_measurement_at'))
  2250. ->join('client', 'client.id', '=', 'client_bdt_device.client_id');
  2251. if($this->performer->pro->pro_type !== 'ADMIN'){
  2252. $devices = $devices->where('client.mcp_pro_id', $this->performer->pro->id);
  2253. }
  2254. $this->filterMultiQuery($request, $devices, 'client_bdt_device.most_recent_measurement_at', 'date_category', 'date_value_1', 'date_value_2');
  2255. // $dateKeyName = $request->get('date_category');
  2256. // $date1 = $request->get('date_value_1');
  2257. // $date2 = $request->get('date_value_2');
  2258. // $dateColumnName = "(SELECT (MAX(ts_date_time))::DATE FROM bdt_measurement WHERE bdt_measurement.bdt_device_id = client_bdt_device.device_id AND is_cellular_zero IS FALSE)";
  2259. // switch($dateKeyName) {
  2260. // case 'EXACTLY':
  2261. // if($date1) {
  2262. // $devices->whereRaw($dateColumnName." = '$date1'::DATE");
  2263. // }
  2264. // break;
  2265. // case 'LESS_THAN':
  2266. // if($date1) {
  2267. // $devices->whereRaw($dateColumnName. "< '$date1'::DATE" );
  2268. // }
  2269. // break;
  2270. // case 'GREATER_THAN':
  2271. // if($date1) {
  2272. // $devices->whereRaw($dateColumnName. "> '$date1'::DATE");
  2273. // }
  2274. // break;
  2275. // case 'BETWEEN':
  2276. // if($date1 && $date2) {
  2277. // $devices
  2278. // ->whereRaw($dateColumnName. ">= '$date1'::DATE")
  2279. // ->whereRaw($dateColumnName. "<= '$date2'::DATE");
  2280. // }
  2281. // break;
  2282. // case 'NOT_BETWEEN':
  2283. // if($date2 && $date1) {
  2284. // $devices
  2285. // ->where(function ($q) use ($request, $dateColumnName, $date1, $date2) {
  2286. // $q->whereRaw($dateColumnName. "< '$date1'::DATE")
  2287. // ->orWhereRaw($dateColumnName. "> '$date2'::DATE");
  2288. // });
  2289. // }
  2290. // break;
  2291. // }
  2292. $keyName = $request->get('measurement_count_category');
  2293. $value1 = $request->get('measurement_count_value_1');
  2294. $value2 = $request->get('measurement_count_value_2');
  2295. $columnName = "(SELECT COUNT(*) FROM bdt_measurement WHERE bdt_measurement.bdt_device_id = client_bdt_device.device_id AND is_cellular_zero IS FALSE)";
  2296. switch($keyName) {
  2297. case 'EXACTLY':
  2298. if($value1) {
  2299. $devices->whereRaw($columnName.'='.$value1);
  2300. }
  2301. break;
  2302. case 'LESS_THAN':
  2303. if($value1) {
  2304. $devices->whereRaw($columnName. '<' .$value1);
  2305. }
  2306. break;
  2307. case 'GREATER_THAN':
  2308. if($value1) {
  2309. $devices->whereRaw($columnName. '>'. $value1);
  2310. }
  2311. break;
  2312. case 'BETWEEN':
  2313. if($value1 && $value2) {
  2314. $devices
  2315. ->whereRaw($columnName. '>=' . $value1)
  2316. ->whereRaw($columnName. '<=' . $value1);
  2317. }
  2318. break;
  2319. case 'NOT_BETWEEN':
  2320. if($value1 && $value2) {
  2321. $devices
  2322. ->where(function ($q) use ($request, $columnName, $value1, $value2) {
  2323. $q->whereRaw($columnName. '<'. $value1)
  2324. ->orWhereRaw($columnName. '>'.$value2);
  2325. });
  2326. }
  2327. break;
  2328. }
  2329. $status = $request->get('status');
  2330. if($status){
  2331. if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
  2332. if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
  2333. }
  2334. $devices = $devices->orderBy('num_of_measurements', 'DESC')->paginate(20);
  2335. return view('app.practice-management.clients_bdt_devices', compact('devices','filters'));
  2336. }
  2337. public function memos(Request $request){
  2338. $filters = $request->all();
  2339. $memos = ClientMemo::select('client_memo.*')
  2340. ->join('client', 'client.id', '=', 'client_memo.client_id');
  2341. if($this->performer->pro->pro_type !== 'ADMIN'){
  2342. $memos = $memos->where('client.mcp_pro_id', $this->performer->pro->id);
  2343. }
  2344. $this->filterMultiQuery($request, $memos, 'client_memo.created_at', 'date_category', 'date_value_1', 'date_value_2');
  2345. $this->filterSimpleQuery($request, $memos, 'category', 'category');
  2346. $memos = $memos->orderBy('created_at', 'DESC')->paginate(20);
  2347. return view('app.practice-management.memos', compact('memos', 'filters'));
  2348. }
  2349. public function segmentTemplates(Request $request){
  2350. $segmentTemplates = SegmentTemplate::query();
  2351. $segmentTemplates = $segmentTemplates->orderBy('created_at', 'DESC');
  2352. $responseType = $request->get('response_type');
  2353. if($responseType && $responseType == 'json'){
  2354. $segmentTemplates = $segmentTemplates->where('is_active', true)->get();
  2355. return $this->pass($segmentTemplates);
  2356. }
  2357. $segmentTemplates = $segmentTemplates->paginate(30);
  2358. return view('app.practice-management.segment-templates.index', compact('segmentTemplates'));
  2359. }
  2360. public function visitTemplates(Request $request){
  2361. $visitTemplates = VisitTemplate::query();
  2362. $visitTemplates = $visitTemplates->orderBy('created_at', 'DESC');
  2363. $responseType = $request->get('response_type');
  2364. if($responseType && $responseType == 'json'){
  2365. $visitTemplates = $visitTemplates->where('is_active', true)->get();
  2366. return $this->pass($visitTemplates);
  2367. }
  2368. $visitTemplates = $visitTemplates->paginate(30);
  2369. return view('app.practice-management.visit-templates.index', compact('visitTemplates'));
  2370. }
  2371. public function visitTemplate(Request $request, VisitTemplate $visitTemplate){
  2372. $visitTemplateSegmentTemplates = VisitTemplateSegmentTemplate::query();
  2373. $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->where('visit_template_id', $visitTemplate->id);
  2374. $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->orderBy('position_index', 'ASC');
  2375. $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->paginate(50);
  2376. return view('app.practice-management.visit-templates.visit-template-segment-templates.index', compact('visitTemplate','visitTemplateSegmentTemplates'));
  2377. }
  2378. public function visitTemplateAccess(Request $request, VisitTemplate $visitTemplate){
  2379. $visitTemplateAccesses = VisitTemplateAccess::where('visit_template_id', $visitTemplate->id)->paginate(50);
  2380. return view('app.practice-management.visit-templates.visit-template-accesses.index', compact('visitTemplate','visitTemplateAccesses'));
  2381. }
  2382. public function clientCcmRmStatus(Request $request){
  2383. $filters = $request->all();
  2384. $patients = Client::whereNull('shadow_pro_id');
  2385. $pro = $this->performer()->pro;
  2386. if($pro->pro_type !== 'ADMIN') {
  2387. $patients = $patients->where('mcp_pro_id', $this->performer()->pro->id);
  2388. }
  2389. // filters
  2390. /*
  2391. array:18 [▼
  2392. "age_category" => "LESS_THAN"
  2393. "age_value_1" => "34"
  2394. "age_value_2" => null
  2395. "sex" => "M"
  2396. "bmi_category" => "BETWEEN"
  2397. "bmi_value_1" => "20"
  2398. "bmi_value_2" => "25"
  2399. "last_visit_category" => "LESS_THAN"
  2400. "last_visit_value_1" => "2021-10-14"
  2401. "last_visit_value_2" => null
  2402. "next_appointment_category" => "LESS_THAN"
  2403. "next_appointment_value_1" => "2021-10-15"
  2404. "status" => "ACTIVE"
  2405. "last_weighed_in_category" => "EXACTLY"
  2406. "last_weighed_in_value_1" => "2021-10-07"
  2407. "last_bp_category" => "BETWEEN"
  2408. "last_bp_value_1" => "2021-10-01"
  2409. "last_bp_value_2" => "2021-10-31"
  2410. ]
  2411. */
  2412. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  2413. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  2414. $this->filterMultiQuery($request, $patients, 'usual_bmi', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  2415. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  2416. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  2417. switch($request->input('status')) {
  2418. case 'ACTIVE':
  2419. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  2420. break;
  2421. case 'AWAITING_VISIT':
  2422. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  2423. break;
  2424. case 'INACTIVE':
  2425. $patients->where('is_active', '<>', true);
  2426. break;
  2427. }
  2428. if($request->input('is_eligible_for_cm')){
  2429. $patients->where('is_eligible_for_cm', '=', $request->input('is_eligible_for_cm'));
  2430. }
  2431. if($request->input('is_enrolled_in_cm')){
  2432. $patients->where('is_enrolled_in_cm', '=', $request->input('is_enrolled_in_cm'));
  2433. }
  2434. if($request->input('has_cm_setup_been_performed')){
  2435. $patients->where('has_cm_setup_been_performed', '=', $request->input('has_cm_setup_been_performed')=='YES'? true : false);
  2436. }
  2437. if($request->input('is_eligible_for_rm')){
  2438. $patients->where('is_eligible_for_rm', '=', $request->input('is_eligible_for_rm'));
  2439. }
  2440. if($request->input('is_enrolled_in_rm')){
  2441. $patients->where('is_enrolled_in_rm', '=', $request->input('is_enrolled_in_rm'));
  2442. }
  2443. if($request->input('has_rm_setup_been_performed')){
  2444. $patients->where('has_rm_setup_been_performed', '=', $request->input('has_rm_setup_been_performed') =='YES'? true : false);
  2445. }
  2446. $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
  2447. return view('app.admin.client-ccm-rm-status', compact('patients', 'filters'));
  2448. }
  2449. public function rmActionReport(Request $request){
  2450. $filters = $request->all();
  2451. $careMonthStartDate = $request->get('care_month_start_date');
  2452. $careMonthYear = $request->get('care_month_year');
  2453. if(!$careMonthStartDate){
  2454. $careMonthStartDate = '2022-01-01';
  2455. }
  2456. if($careMonthYear){
  2457. $careMonthStartDate = $careMonthYear . "-01";
  2458. }
  2459. $lastDateOfMonth = new DateTime(date("Y-m-t", strtotime(get_current_date())));
  2460. $today = new DateTime(get_current_date());
  2461. $diff = $lastDateOfMonth->diff($today);
  2462. $daysBetweenNowAndEndmonth = $diff->days;
  2463. $minRequiredMeasurements = 16 - $daysBetweenNowAndEndmonth -1;
  2464. $numOfMeasurements = $request->get('num_of_measurements'); //16_or_more, 12_or_more
  2465. $hasRecentVisit = $request->get('has_recent_visit'); //yes no
  2466. $hasBeenSpokenToThisMonth = $request->get('has_been_spoken_to'); //yes no
  2467. $cmQuery = CareMonth::where('start_date', $careMonthStartDate);
  2468. //remove dummies
  2469. $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
  2470. return $clientQuery->where('client_engagement_status_category','<>', 'DUMMY')
  2471. ->orWhere('client_engagement_status_category', '=', null);
  2472. });
  2473. if($numOfMeasurements){
  2474. if($numOfMeasurements == '16_or_more'){
  2475. $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '>=', 16);
  2476. }
  2477. if($numOfMeasurements == 'min_or_more'){
  2478. $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '>=', $minRequiredMeasurements)
  2479. ->where('number_of_days_with_remote_measurements', '<', 16);
  2480. }
  2481. if($numOfMeasurements == 'less_than_min'){
  2482. $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '<', $minRequiredMeasurements);
  2483. }
  2484. }
  2485. if($hasRecentVisit){
  2486. if($hasRecentVisit == 'YES'){
  2487. $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
  2488. return $clientQuery->whereRaw("most_recent_completed_mcp_note_date::DATE >= ((NOW() - interval '90 days')::DATE)");
  2489. });
  2490. }else{
  2491. $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
  2492. return $clientQuery->whereRaw("most_recent_completed_mcp_note_date::DATE < ((NOW() - interval '90 days')::DATE)");
  2493. });
  2494. }
  2495. }
  2496. if($hasBeenSpokenToThisMonth){
  2497. if($hasBeenSpokenToThisMonth == 'YES'){
  2498. $cmQuery = $cmQuery->where('has_anyone_interacted_with_client_about_rm_outside_note', '=', true);
  2499. }else{
  2500. $cmQuery = $cmQuery->where('has_anyone_interacted_with_client_about_rm_outside_note', '=', false);
  2501. }
  2502. }
  2503. $claimingClosed = $request->get('claiming_closed');
  2504. if($claimingClosed){
  2505. if($claimingClosed === 'YES') $cmQuery = $cmQuery->where('is_claim_closed', true);
  2506. if($claimingClosed === 'NO') $cmQuery = $cmQuery->where('is_claim_closed', false);
  2507. }
  2508. $rows = $cmQuery->paginate(15);
  2509. return view('app.practice-management.rm-action-report', compact('rows', 'filters', 'minRequiredMeasurements'));
  2510. }
  2511. public function myFlyers(Request $request){
  2512. $pro = $this->performer->pro;
  2513. $slug = $pro->slug ?? $pro->uid;
  2514. $url = config('app.stagfe6_url') . '/flyers/json-list?slug=' . $slug;
  2515. $arrContextOptions=array(
  2516. "ssl"=>array(
  2517. "verify_peer"=>false,
  2518. "verify_peer_name"=>false,
  2519. ),
  2520. );
  2521. $response = @file_get_contents($url, false, stream_context_create($arrContextOptions));
  2522. $response = @json_decode($response);
  2523. $flyerTemplates = [];
  2524. if(isset($response->data)){
  2525. $flyerTemplates = $response->data;
  2526. }
  2527. return view('app.my-flyers', compact('pro','flyerTemplates'));
  2528. }
  2529. }