1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\AppSession;
- use App\Models\BillingReport;
- use App\Models\CareMonth;
- use App\Models\ClaimEDI;
- use App\Models\ClientProChange;
- use App\Models\Company;
- use App\Models\Handout;
- use App\Models\MBClaim;
- use App\Models\Measurement;
- use App\Models\Bill;
- use App\Models\Claim;
- use App\Models\Client;
- use App\Models\McpRequest;
- use App\Models\McCodeCheck;
- use App\Models\Note;
- use App\Models\Pack;
- use App\Models\Pro;
- use App\Models\Product;
- use App\Models\ProFavorite;
- use App\Models\ProGeneralAvailability;
- use App\Models\ProProAccess;
- use App\Models\ProRate;
- use App\Models\ProSpecificAvailability;
- use App\Models\ProSpecificUnavailability;
- use App\Models\ProTeam;
- use App\Models\ProTextShortcut;
- use App\Models\ProTransaction;
- use App\Models\Shipment;
- use App\Models\SupplyOrder;
- use App\Models\Team;
- use App\Models\Ticket;
- use App\Models\AccountInvite;
- use App\Models\ClientMeasurementDaysPerMonth;
- use App\Models\ClientBDTDevice;
- use App\Models\ClientMemo;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Http;
- use PDF;
- use DateTime;
- use DateTimeZone;
- use Illuminate\Http\Request;
- use App\Models\SegmentTemplate;
- use App\Models\VisitTemplate;
- use App\Models\VisitTemplateSegmentTemplate;
- use App\Models\VisitTemplateAccess;
- class PracticeManagementController extends Controller
- {
- public function rpmMatrix(Request $request)
- {
- $proID = $this->performer()->pro->id;
- $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
- $query = Client::whereNull('shadow_pro_id');
- if(!$isAdmin) $query->where('mcp_pro_id', '=', $proID);
- $clients = $query->orderByRaw('most_recent_cellular_measurement_at desc nulls last')
- ->paginate(50);
- return view ('app.practice-management.rpm-matrix', compact('clients'));
- }
- public function mcCodeChecks(Request $request)
- {
- $checks = McCodeCheck::orderBy('next_eligible_date_professional', 'asc')->get();
- return view ('app.practice-management.mc-code-checks', compact('checks'));
- }
- public function remoteMonitoringReport(Request $request)
- {
- $rows = null;
- $proID = $this->performer()->pro->id;
- $isAdmin = $this->performer()->pro->pro_type == 'ADMIN';
- //$rows = $isAdmin ? ClientMeasurementDaysPerMonth::all() : ClientMeasurementDaysPerMonth::where('mcp_pro_id', $proID)->orderBy('year_month', 'asc')->orderBy('num_of_days_with_measurement', 'asc')->get();
- $query = CareMonth::whereNotNull('mcp_pro_id')
- ->where('number_of_days_with_remote_measurements', '>=', 16)
- ->where('days_between_most_recent_mcp_note_date_and_end_of_care_month', '<=', 90);
- if(!$isAdmin) $query->where('mcp_pro_id', '=', $proID);
- if($request->get('show_billing_not_closed_only')){
- $query->where(function($q){
- return $q->where('is_bill_closed', false)->orWhereNull('is_bill_closed');
- });
- }
- $rows = $query->orderByRaw(DB::raw('start_date DESC'))->paginate(100) ;
- return view ('app.practice-management.remote-monitoring-report', compact('rows', 'isAdmin'));
- }
- public function dailyTreatmentServices(Request $request) {
- $type = $request->input('t');
- $fPro = null;
- if($type === 'pro') {
- $fPro = Pro::where('uid', $request->input('p'))->first();
- $rows = DB::select(DB::raw("
- SELECT effective_date, hcp_pro_id, p.name_first, p.name_last, count(*), sum(number_of_units) as units
- FROM bill JOIN pro p on p.id = bill.hcp_pro_id
- WHERE code = 'Treatment Services'
- GROUP BY effective_date, hcp_pro_id, p.name_first, p.name_last
- ORDER BY effective_date DESC, p.name_first ASC, p.name_last ASC
- "));
- }
- else {
- $rows = DB::select(DB::raw("
- 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
- "));
- }
- return view ('app.practice-management.daily-treatment-services', compact('rows'));
- }
- public function clientProChanges(Request $request)
- {
- $filters = $request->all();
- $rows = ClientProChange::query();
- $associationTypes = DB::table('client_pro_change')->select('responsibility_type')->distinct()->pluck('responsibility_type')->toArray();
- $this->filterMultiQuery($request, $rows, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
- $this->filterSimpleQuery($request, $rows, 'responsibility_type', 'responsibility_type');
- $oldProUid = $request->get('old_pro');
- if($oldProUid){
- $oldPro = Pro::where('uid', $oldProUid)->first();
- $rows = $rows->where('previous_pro_id',$oldPro->id);
- }
- $newProUid = $request->get('new_pro');
- if($newProUid){
- $newPro = Pro::where('uid', $newProUid)->first();
- $rows = $rows->where('new_pro_id',$newPro->id);
- }
- $rows = $rows->orderByRaw('created_at::date DESC')->orderBy('client_id', 'desc')->paginate(20);
- return view ('app.practice-management.client-pro-changes', compact('rows', 'filters', 'associationTypes'));
- }
- public function billingReport(Request $request)
- {
- $filters = $request->all();
- $claimStatus = $request->get('status');
-
-
- $rows = BillingReport::whereHas('client', function($clientQuery){
- return $clientQuery->where('client_engagement_status_category','<>' ,'DUMMY');
- })->orderBy('note_date', 'desc');
- $no_claims = $request->get('no_claims');
- $zero_deductible = $request->get('zero_deductible');
- $claim_status = $request->get('claim_status');
- $verified = $request->get('verified');
-
- if($no_claims){
- $rows = $rows->whereHas('note', function($noteQuery){
- return $noteQuery->has('claims', '=', 0);
- });
- }
-
- if($zero_deductible){
- $rows = $rows->whereHas('client', function($clientQuery){
- return $clientQuery->where('client_engagement_status_category','<>' ,'DUMMY')
- ->whereHas('latestClientPrimaryCoverage', function($lcpcQuery){
- return $lcpcQuery->where('auto_medicare_mpb_deductible', 0);
- });
- });
- }
-
- if($claim_status){
- $rows = $rows->whereHas('note', function($noteQuery) use ($claim_status){
- return $noteQuery->whereHas('claims', function($claimQuery) use ($claim_status) {
- return $claimQuery->where('status', $claim_status);
- });
- });
- }
- if($verified){
- if($verified == 'VERIFIED'){
- $rows = $rows->whereHas('note', function($noteQuery){
- return $noteQuery->whereHas('bills', function($billQuery) {
- return $billQuery->where('is_verified', true)->where('is_cancelled', false);
- });
- });
- }
- if($verified == 'UNVERIFIED'){
- $rows = $rows->whereHas('note', function($noteQuery){
- return $noteQuery->whereHas('bills', function($billQuery) {
- return $billQuery->where('is_verified', false)->where('is_cancelled', false);
- });
- });
- }
- }
-
- $rows = $rows->paginate(50);
- $claimStatuses = DB::select('SELECT distinct status FROM claim ORDER BY status DESC');
- return view('app.practice-management.billing-report', compact('rows', 'claimStatuses', 'filters'));
- }
- public function dashboard(Request $request)
- {
- return view('app.practice-management.dashboard');
- }
- public function rates(Request $request, $selectedProUid = 'all')
- {
- $proUid = $selectedProUid ? $selectedProUid : 'all';
- $rates = ProRate::where('is_active', true);
- if ($proUid !== 'all') {
- $selectedPro = Pro::where('uid', $proUid)->first();
- $rates = $rates->where('pro_id', $selectedPro->id);
- }
- $rates = $rates->orderBy('pro_id', 'asc')->get();
- $pros = $this->pros;
- return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
- }
- public function previousBills(Request $request)
- {
- return view('app.practice-management.previous-bills');
- }
- public function financialTransactions(Request $request)
- {
- $pro = $this->performer()->pro;
- $transactions = null;
- if($pro->pro_type === 'ADMIN') {
- $transactions = ProTransaction::whereNotNull('id');
- }
- else {
- $transactions = ProTransaction::where('pro_id', $pro->id);
- }
- $filter = $request->input('p');
- if ($filter) {
- $filterPro = Pro::where('uid', $filter)->first();
- if($filterPro) {
- $transactions = $transactions->where('pro_id', '=', $filterPro->id);
- }
- }
- $filter = $request->input('t');
- if ($filter) {
- $transactions = $transactions->where('plus_or_minus', '=', $filter);
- }
- $filter = $request->input('c');
- if ($filter) {
- $transactions = $transactions->where('company_id', '=', $filter);
- }
- $filter = $request->input('bs');
- if ($filter) {
- $transactions = $transactions->where('created_at', '>=', $filter);
- }
- $filter = $request->input('be');
- if ($filter) {
- $transactions = $transactions->where('created_at', '<=', $filter);
- }
- $transactions = $transactions->orderBy('created_at', 'desc')->paginate();
- $companies = Company::where('is_active', true)->orderBy('name')->get();
- return view('app.practice-management.financial-transactions', compact('transactions', 'companies'));
- }
- public function pendingBillsToSign(Request $request)
- {
- return view('app.practice-management.pending-bills-to-sign');
- }
- public function HR(Request $request)
- {
- return view('app.practice-management.hr');
- }
- public function directDepositSettings(Request $request)
- {
- return view('app.practice-management.direct-deposit-settings');
- }
- public function w9(Request $request)
- {
- return view('app.practice-management.w9');
- }
- public function contract(Request $request)
- {
- return view('app.practice-management.contract');
- }
- public function notes(Request $request, $filter = '')
- {
- $proID = $this->performer()->pro->id;
- $query = Note::where('hcp_pro_id', $proID);
- switch ($filter) {
- case 'not-yet-signed':
- $query = $query->where('is_signed_by_hcp', false);
- break;
- case 'not-yet-signed-but-ally-signed':
- $query = $query->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true);
- break;
- case 'without-bills':
- $query = $query->where('is_signed_by_hcp', true)->where('is_cancelled', false)->whereDoesntHave('bills');
- break;
- // more cases can be added as needed
- default:
- break;
- }
- $notes = $query->orderBy('created_at', 'desc')->paginate(30);
- return view('app.practice-management.notes', compact('notes', 'filter'));
- }
- public function allNotes(Request $request)
- {
- $query = Note::query();
-
- $filters = $request->all();
- $this->filterMultiQuery($request, $query, 'created_at', 'created_at_category', 'created_at_value_1', 'created_at_value_2');
- $this->filterMultiQuery($request, $query, 'effective_dateest', 'effective_date_category', 'effective_date_value_1', 'effective_date_value_2');
-
- $filterByProsIDs = $request->get('pros');
- if($filterByProsIDs && count($filterByProsIDs)){
- $query = $query->whereIn('hcp_pro_id', $filterByProsIDs);
- }
- $filterByPatientsIDs = $request->get('patients');
- if($filterByPatientsIDs && count($filterByPatientsIDs)){
- $query = $query->whereIn('client_id', $filterByPatientsIDs);
- }
-
- $status = $request->get('status');
- if($status){
- if($status == 'CANCELLED') $query = $query->where('is_cancelled', true);
- if($status == 'NOT_YET_SIGNED') $query = $query->where('is_signed_by_hcp', false);
- if($status == 'NOT_YET_SIGNED_BUT_ALLY_SIGNED') $query = $query->where('is_signed_by_hcp', false)->where('is_signed_by_ally', true);
- if($status == 'WITHOUT_BILLS') $query = $query->where('is_signed_by_hcp', true)->where('is_cancelled', false)->whereDoesntHave('bills');
- }
-
- $allProsWithNotesIDs = Note::pluck('hcp_pro_id')->toArray();
- $allProsWithNotes = Pro::whereIn('id', $allProsWithNotesIDs)->get();
- $allPatientsWithNotesIDs = Note::pluck('client_id')->toArray();
- $allPatientsWithNotes = Client::whereIn('id', $allPatientsWithNotesIDs)->get();
- $notes = $query->orderBy('created_at', 'desc')->paginate(30);
- return view('app.practice-management.all-notes', compact('notes', 'filters','allProsWithNotes', 'allPatientsWithNotes'));
- }
- public function dnaNotesPendingMcpSign(Request $request)
- {
- $proID = $this->performer()->pro->id;
- $notes = Note::where('ally_pro_id', $proID)
- ->where('is_signed_by_hcp', false)
- ->where('is_cancelled', false)
- ->orderBy('created_at', 'desc')
- ->get();
- return view('app.practice-management.dna-notes-pending-mcp-sign', compact('notes'));
- }
- public function naBillableSignedNotes(Request $request)
- {
- $notes = Note
- ::where('is_signed_by_hcp', TRUE)
- ->where('ally_pro_id', $this->performer()->pro->id)
- ->where('is_cancelled', FALSE)
- ->whereRaw("
- (
- SELECT count(bill.id)
- FROM bill WHERE
- bill.is_cancelled = FALSE AND
- bill.generic_pro_id = {$this->performer()->pro->id} AND
- bill.note_id = note.id
- ) = 0
- ");
- $notes = $notes->orderBy('created_at', 'desc')->get();
- return view('app.practice-management.na-billable-signed-notes', compact('notes'));
- }
- public function bills(Request $request, $filter = '')
- {
- $proID = $this->performer()->pro->id;
- $query = Bill::where('is_cancelled', false)->where('bill_service_type', '<>', 'CARE_MONTH');
- switch ($filter) {
- case 'not-yet-signed':
- $query = $query
- ->where(function ($q) use ($proID) {
- $q->where(function ($q2) use ($proID) {
- $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('generic_pro_id', $proID)->where('is_signed_by_generic_pro', false);
- });
- });
- break;
- case 'previous':
- $query = $query
- ->where(function ($q) use ($proID) {
- $q->where(function ($q2) use ($proID) {
- $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
- });
- });
- break;
- // more cases can be added as needed
- default:
- $query = $query
- ->where(function ($q) use ($proID) {
- $q->where(function ($q2) use ($proID) {
- $q2->where('hcp_pro_id', $proID);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('cm_pro_id', $proID);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rme_pro_id', $proID);
- })
- ->orWhere(function ($q2) use ($proID) {
- $q2->where('rmm_pro_id', $proID);
- });
- });
- break;
- }
- $bills = $query->orderBy('created_at', 'desc')->get();
- return view('app.practice-management.bills', compact('bills', 'filter'));
- }
- public function rmBillsToSign(Request $request)
- {
- $performerProID = $this->performer()->pro->id;
- $bills = Bill::where('is_cancelled', false)->where('cm_or_rm', 'RM')
- ->where(function ($q) use ($performerProID) {
- $q
- ->where(function ($q2) use ($performerProID) {
- $q2->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
- })
- ->orWhere(function ($q2) use ($performerProID) {
- $q2->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
- })
- ->orWhere(function ($q2) use ($performerProID) {
- $q2->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
- })
- ->orWhere(function ($q2) use ($performerProID) {
- $q2->where('generic_pro_id', $performerProID)->where('is_signed_by_generic_pro', false);
- });
- })
- ->orderBy('effective_date', 'desc')
- ->get();
- return view('app.practice-management.rm-bills-to-sign', compact('bills'));
- }
- public function unacknowledgedCancelledBills(Request $request)
- {
- $bills = Bill::where('hcp_pro_id', $this->performer()->pro->id)
- ->where('is_cancelled', true)
- ->where('is_cancellation_acknowledged', false)
- ->orderBy('created_at', 'desc')
- ->get();
- return view('app.practice-management.unacknowledged-cancelled-bills', compact('bills'));
- }
- public function myTickets(Request $request, $filter = 'open')
- {
- $performer = $this->performer();
- $myTickets = Ticket::where(function ($q) use ($performer) {
- $q->where('assigned_pro_id', $performer->pro_id)
- ->orWhere('manager_pro_id', $performer->pro_id)
- ->orWhere('ordering_pro_id', $performer->pro_id)
- ->orWhere('initiating_pro_id', $performer->pro_id);
- });
- if ($filter === 'open') {
- $myTickets = $myTickets->where('is_open', true);
- } else if ($filter === 'closed') {
- $myTickets = $myTickets->where('is_open', false);
- }
- $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
- return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
- }
- public function myTextShortcuts(Request $request)
- {
- $personalShortcuts = DB::table('pro_text_shortcut')
- ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
- ->select(
- 'pro_text_shortcut.uid',
- 'pro_text_shortcut.shortcut',
- 'pro_text_shortcut.text',
- 'pro.name_first',
- 'pro.name_last'
- )
- ->where('pro_text_shortcut.is_removed', false);
- if($this->performer()->pro->pro_type !== 'ADMIN') {
- $personalShortcuts = $personalShortcuts->where('pro_id', $this->performer()->pro_id);
- }
- $personalShortcuts = $personalShortcuts
- ->orderBy('pro.name_last')
- ->orderBy('pro.name_first')
- ->orderBy('pro_text_shortcut.shortcut')
- ->get();
- $globalTextShortcuts = DB::table('pro_text_shortcut')
- ->select(
- 'pro_text_shortcut.uid',
- 'pro_text_shortcut.shortcut',
- 'pro_text_shortcut.text'
- )
- ->whereNull('pro_id')
- ->where('pro_text_shortcut.is_removed', false)
- ->orderBy('pro_text_shortcut.shortcut')
- ->get();
- return view('app.practice-management.my-text-shortcuts', compact('personalShortcuts', 'globalTextShortcuts'));
- }
- public function myFavorites(Request $request, $filter = 'all')
- {
- $performer = $this->performer();
- $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)->where('is_removed', false);
- if ($filter !== 'all') {
- $myFavorites = $myFavorites->where('category', $filter);
- }
- $myFavorites = $myFavorites
- ->whereIn('category', ['allergy', 'medication', 'problem'])
- ->orderBy('category', 'asc')
- ->orderBy('position_index', 'asc')
- ->get();
- return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
- }
- public function patientsWithoutCoverage(Request $request, $filter = 'all')
- {
- $performer = $this->performer();
- $sql = "SELECT cl.uid, cl.name_first, cl.name_last FROM client cl ";
- $joinClause = 'LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id ';
- $withoutCondition = "cl.latest_client_primary_coverage_id IS NULL";
- $pendingCondition = "
- (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
- AND (
- (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
- OR
- (cpc.plan_type != 'MEDICARE' AND
- (cpc.manual_determination_category = 'UNKNOWN' OR cpc.manual_determination_category IS NULL))
- ))";
- switch ($filter) {
- case 'without-coverage-information':
- $sql .= 'WHERE cl.shadow_pro_id IS NULL AND ';
- $sql .= $withoutCondition;
- break;
- case 'pending-coverage-verification':
- $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
- $sql .= $pendingCondition;
- break;
- default:
- $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
- $sql .= '(' . $withoutCondition . ' OR ' . $pendingCondition . ')';
- break;
- }
- $sql .= ' ORDER BY cl.name_first ASC';
- $pendingCoverage = DB::select(DB::raw($sql));
- return view('app.practice-management.patients-without-coverage', compact('pendingCoverage', 'filter'));
- }
- public function proAvailability(Request $request, $proUid = null)
- {
- $performer = $this->performer();
- $pro = $performer->pro;
- if ($proUid) {
- $pro = Pro::where('uid', $proUid)->first();
- }
- if ($request->get('pro_uid')) {
- $proUid = $request->get('pro_uid');
- $pro = Pro::where('uid', $proUid)->first();
- }
- $selectedProUid = $pro->uid;
- $pros = $this->pros;
- $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
- $generalAvailabilities = [
- 'MONDAY' => [],
- 'TUESDAY' => [],
- 'WEDNESDAY' => [],
- 'THURSDAY' => [],
- 'FRIDAY' => [],
- 'SATURDAY' => [],
- 'SUNDAY' => [],
- ];
- foreach ($generalAvailabilitiesList as $ga) {
- if ($ga->day_of_week == 'MONDAY') {
- $generalAvailabilities['MONDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'TUESDAY') {
- $generalAvailabilities['TUESDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'WEDNESDAY') {
- $generalAvailabilities['WEDNESDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'THURSDAY') {
- $generalAvailabilities['THURSDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'FRIDAY') {
- $generalAvailabilities['FRIDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'SATURDAY') {
- $generalAvailabilities['SATURDAY'][] = $ga;
- }
- if ($ga->day_of_week == 'SUNDAY') {
- $generalAvailabilities['SUNDAY'][] = $ga;
- }
- }
- $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
- $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
- //events for the calendar
- $startDate = date('Y-m-d', strtotime("sunday -1 week"));
- $endDateTime = new DateTime($startDate);
- $endDateTime->modify('+6 day');
- $endDate = $endDateTime->format("Y-m-d");
- $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
- $events = json_encode($eventsData);
- return view(
- 'app.practice-management.pro-availability',
- compact(
- 'pros',
- 'generalAvailabilities',
- 'specificAvailabilities',
- 'specificUnavailabilities',
- 'events',
- 'selectedProUid'
- )
- );
- }
- public function loadAvailability(Request $request, $proUid)
- {
- $performer = $this->performer();
- $pro = $performer->pro;
- $startDate = $request->get('start');
- $endDate = $request->get('end');
- $selectedPro = Pro::where('uid', $proUid)->first();
- return $selectedPro->getAvailabilityEvents($startDate, $endDate, $request->input('tz') ? $request->input('tz') : 'EASTERN');
- }
- public function proAvailabilityFilter(Request $request)
- {
- $proUid = $request->get('proUid');
- return ['success' => true, 'data' => $proUid];
- }
- // video call page (RHS)
- // generic call handle (no uid)
- // specific call handle (uid of client)
- public function meet(Request $request, $uid = false)
- {
- $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
- $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
- if (!empty($client)) {
- return view('app.video.call-minimal', compact('session', 'client'));
- }
- return view('app.video.call-agora-v2', compact('session', 'client'));
- }
- // check video page
- public function checkVideo(Request $request, $uid)
- {
- $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
- $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
- $publish = false;
- return view('app.video.check-video-minimal', compact('session', 'client'));
- }
- public function getParticipantInfo(Request $request)
- {
- $sid = intval($request->get('uid')) - 1000000;
- $session = AppSession::where('id', $sid)->first();
- $result = [
- "type" => '',
- "name" => ''
- ];
- if ($session) {
- $result["type"] = $session->session_type;
- switch ($session->session_type) {
- case 'PRO':
- $pro = Pro::where('id', $session->pro_id)->first();
- $result["name"] = $pro->displayName();
- break;
- case 'CLIENT':
- $client = Client::where('id', $session->client_id)->first();
- $result["name"] = $client->displayName();
- break;
- }
- }
- return json_encode($result);
- }
- // ajax ep used by the video page
- // this is needed bcoz meet() is used not
- // just for the client passed to the view
- public function getOpentokSessionKey(Request $request, $uid)
- {
- $client = Client::where('uid', $uid)->first();
- return json_encode(["data" => $client ? $client->opentok_session_id : '']);
- }
- // poll to check if there are patients with active mcp requests
- public function getPatientsInQueue(Request $request)
- {
- $myInitiatives = $this->performer->pro->initiatives;
- if ($myInitiatives) {
- $myInitiatives = strtoupper($myInitiatives);
- }
- $myInitiativesList = explode('|', $myInitiatives);
- $myForeignLanguages = $this->performer->pro->foreign_languages;
- if ($myForeignLanguages) {
- $myForeignLanguages = strtoupper($myForeignLanguages);
- }
- $myForeignLanguagesList = explode('|', $myForeignLanguages);
- $clients = Client::whereNotNull('active_mcp_request_id')->where(function ($query) use ($myInitiativesList) {
- $query->whereNull('initiative')->orWhereIn('initiative', $myInitiativesList);
- })
- ->where(function ($query) use ($myForeignLanguagesList) {
- $query->whereNull('preferred_foreign_language')->orWhereIn('preferred_foreign_language', $myForeignLanguagesList);
- })->limit(3)->get();
- $results = [];
- foreach ($clients as $client) {
- $results[] = [
- 'clientUid' => $client->uid,
- 'name' => $client->displayName(),
- 'initials' => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
- ];
- }
- return json_encode($results);
- }
- public function currentWork(Request $request)
- {
- return view('app/current-work');
- }
- public function calendar(Request $request, $proUid = null)
- {
- $pros = Pro::all();
- if ($this->pro && $this->pro->pro_type != 'ADMIN') {
- $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id);
- $accessibleProIds = [];
- foreach ($accessiblePros as $accessiblePro) {
- $accessibleProIds[] = $accessiblePro->id;
- }
- $accessibleProIds[] = $this->pro->id;
- $pros = Pro::whereIn('id', $accessibleProIds)->get();
- }
- return view('app.practice-management.calendar', compact('pros'));
- }
- public function cellularDeviceManager(Request $request, $proUid = null)
- {
- $proUid = $proUid ? $proUid : $request->get('pro-uid');
- $performerPro = $this->performer->pro;
- $targetPro = null;
- $expectedForHcp = null;
- if ($performerPro->pro_type == 'ADMIN') {
- $targetPro = Pro::where('uid', $proUid)->first();
- } else {
- $targetPro = $performerPro;
- }
- $clients = [];
- if ($targetPro) {
- $clients = Client::where('mcp_pro_id', $targetPro->id)->orderBy('created_at', 'desc')->paginate(20);
- } else {
- $clients = Client::orderBy('created_at', 'desc')->paginate(20);
- }
- return view('app.practice-management.cellular-device-manager', compact('clients', 'targetPro', 'proUid'));
- }
- public function treatmentServiceUtil(Request $request)
- {
- $view_treatment_service_utilization_org = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization_org ORDER BY effective_date DESC"));
- $view_treatment_service_utilization = DB::select(DB::raw("SELECT * FROM view_treatment_service_utilization ORDER BY effective_date DESC, total_hrs DESC"));
- $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"));
- return view('app.practice-management.treatment-services-util', compact(
- 'view_treatment_service_utilization_org',
- 'view_treatment_service_utilization',
- 'view_treatment_service_utilization_by_patient'));
- }
- public function processingBillMatrix(Request $request, $proUid = null)
- {
- $proUid = $proUid ? $proUid : $request->get('pro-uid');
- $performerPro = $this->performer->pro;
- $targetPro = null;
- if ($performerPro->pro_type == 'ADMIN') {
- $targetPro = Pro::where('uid', $proUid)->first();
- } else {
- $targetPro = $performerPro;
- }
- $bills = Bill::where('is_cancelled', false);
- if(!$request->input('t') || $request->input('t') === 'hcp') {
- $bills = $bills
- ->where('has_hcp_been_paid', false)
- ->where('hcp_expected_payment_amount', '>', 0)
- ->where('is_signed_by_hcp', true);
- if ($targetPro) {
- $bills = $bills->where('hcp_pro_id', $targetPro->id);
- }
- if($request->input('c')) {
- $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = hcp_company_pro_id) = ' . $request->input('c'));
- }
- }
- else if($request->input('t') === 'na') {
- $bills = $bills
- ->where('has_generic_pro_been_paid', false)
- ->where('generic_pro_expected_payment_amount', '>', 0)
- ->where('is_signed_by_generic_pro', true);
- if ($targetPro) {
- $bills = $bills->where('generic_pro_id', $targetPro->id);
- }
- if($request->input('c')) {
- $bills = $bills->whereRaw('(SELECT company_id from company_pro where id = generic_company_pro_id) = ' . $request->input('c'));
- }
- }
- $filter = $request->input('f');
- switch ($filter) {
- case 'verified':
- $bills = $bills->where('is_verified', true);
- break;
- case 'not-verified':
- $bills = $bills->where('is_verified', false);
- break;
- }
- $filter = $request->input('bs');
- if ($filter) {
- $bills = $bills->where('balance_post_date', '>=', $filter);
- }
- $filter = $request->input('be');
- if ($filter) {
- $bills = $bills->where('balance_post_date', '<=', $filter);
- }
- $filter = $request->input('s');
- if ($filter) {
- $bills = $bills->where('code', '=', $filter);
- }
- $bills = $bills->orderBy('effective_date', 'desc')->paginate();
- $companies = Company::where('is_active', true)->orderBy('name')->get();
- $codes = DB::select(DB::raw("SELECT code, count(*) as count FROM bill WHERE is_cancelled IS FALSE GROUP BY code ORDER BY code"));
- $viewData = [
- 'bills' => $bills,
- 'targetPro' => $targetPro,
- 'performerPro' => $performerPro,
- 'proUid' => $proUid,
- 'companies' => $companies,
- 'codes' => $codes
- ];
- return view('app.practice-management.processing-bill-matrix', $viewData);
- }
- public function hcpNoteActivity(Request $request)
- {
- $filters = $request->all();
- $from_date = $request->get('from_date');
- // if(!$from_date) {
- // $from_date = '2010-01-01';
- // }
- $to_date = $request->get('to_date');
- // if(!$to_date){
- // $to_date = '2900-12-31';
- // }
-
- //TODO sanitize inputs
- $proUid = $request->get('pro-uid');
- $now = Carbon::now();
- $startOfCurrentMonth = $now->startOfMonth('Y-m-d');
- $startOfCurrentMonth = $startOfCurrentMonth->toDateString();
- $endOfCurrentMonth = $now->endOfMonth()->format('Y-m-d');
- $rows = DB::table('pro')
- ->selectRaw(" *,
- (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,
- (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,
- (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,
- (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,
- (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
- " . (!!$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" : ""));
- $prosIDs = $request->get('pros_ids');
- if($prosIDs){
- $pros =
- $rows = $rows->whereIn('pro.id', $prosIDs);
- }
- $sortBy = $request->input('sort_by') ?: 'name_first';
- $sortDir = $request->input('sort_dir') ?: 'ASC';
- $rows = $rows->orderByRaw("$sortBy $sortDir NULLS LAST");
- $rows = $rows->paginate(50);
- return view('app.practice-management.hcp-note-activity', compact('rows', 'filters'));
- }
- public function proFinancials(Request $request, $proUid = null)
- {
- $proUid = $proUid ? $proUid : $request->get('pro-uid');
- $performerPro = $this->performer->pro;
- $targetPro = null;
- if ($performerPro->pro_type == 'ADMIN') {
- $targetPro = Pro::where('uid', $proUid)->first();
- } else {
- $targetPro = $performerPro;
- }
- $fPros = Pro::whereNotNull('balance');
- if($targetPro) {
- $fPros = $fPros->where('uid', $targetPro->uid);
- }
- $fPros = $fPros
- ->where('balance', '>', 0)
- ->orderBy('name_first')
- ->orderBy('name_last')
- ->paginate();
- return view('app.practice-management.pro-financials', compact('fPros', 'targetPro'));
- }
- public function hcpBillMatrix(Request $request, $proUid = null)
- {
- $proUid = $proUid ? $proUid : $request->get('pro-uid');
- $performerPro = $this->performer->pro;
- $targetPro = null;
- $allPros = [];
- $expectedForHcp = null;
- if ($performerPro->pro_type == 'ADMIN') {
- $allPros = Pro::all();
- $targetPro = Pro::where('uid', $proUid)->first();
- } else {
- $targetPro = $performerPro;
- }
- $rows = [];
- if ($targetPro) {
- $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report WHERE hcp_pro_id = :targetProID"), ['targetProID' => $targetPro->id]);
- } else {
- $rows = DB::select(DB::raw("SELECT * FROM aemish_bill_report"));
- }
- return view('app.practice-management.hcp-bill-matrix', compact('rows', 'allPros', 'expectedForHcp', 'targetPro', 'proUid'));
- }
- public function billingManager(Request $request, $proUid = null)
- {
- $proUid = $proUid ? $proUid : $request->get('pro-uid');
- $performerPro = $this->performer->pro;
- $targetPro = null;
- $allPros = [];
- $expectedForHcp = null;
- if ($performerPro->pro_type == 'ADMIN') {
- $allPros = Pro::query()->orderBy('name_first', 'asc')->get();
- $targetPro = Pro::where('uid', $proUid)->first();
- } else {
- $targetPro = $performerPro;
- }
- $notes = [];
- if ($targetPro) {
- $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;
- $notes = Note::where('hcp_pro_id', $targetPro->id);
- } else {
- $notes = Note::where('id', '>', 0);
- }
- if($request->input('date')) {
- $notes = $notes->where('effective_dateest', $request->input('date'));
- }
- $filters = [];
- $filters['bills_created'] = $request->input('bills_created');
- $filters['is_billing_marked_done'] = $request->input('is_billing_marked_done');
- $filters['bills_resolved'] = $request->input('bills_resolved');
- $filters['bills_closed'] = $request->input('bills_closed');
- $filters['claims_created'] = $request->input('claims_created');
- $filters['claims_closed'] = $request->input('claims_closed');
- if ($filters['bills_created']) {
- $notes->where(
- 'bill_total_expected',
- ($filters['bills_created'] === 'yes' ? '>' : '<='),
- 0);
- }
- if ($filters['is_billing_marked_done']) {
- $notes->where(
- 'is_billing_marked_done',
- ($filters['is_billing_marked_done'] === 'yes' ? '=' : '!='),
- true);
- }
- if ($filters['bills_resolved']) {
- $notes->whereRaw('(SELECT count(id) FROM bill WHERE note_id = note.id) > 0'); // have bills
- if ($filters['bills_resolved'] === 'yes') {
- $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');
- } elseif ($filters['bills_resolved'] === 'no') {
- $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');
- }
- }
- if ($filters['bills_closed']) {
- $notes->where(
- 'is_bill_closed',
- ($filters['bills_closed'] === 'yes' ? '=' : '!='),
- true);
- }
- if ($filters['claims_created']) {
- $notes->where(
- 'claim_total_expected',
- ($filters['claims_created'] === 'yes' ? '>' : '<='),
- 0);
- }
- if ($filters['claims_closed']) {
- $notes->where(
- 'is_claim_closed',
- ($filters['claims_closed'] === 'yes' ? '=' : '!='),
- true);
- }
- $notes = $notes->orderBy('effective_dateest', 'desc')->paginate(20);
- return view('app.practice-management.billing-manager', compact('notes', 'allPros', 'expectedForHcp', 'targetPro', 'proUid', 'filters'));
- }
- public function remoteMonitoring(Request $request) {
- $performer = $this->performer();
- // abort_if($performer->pro->pro_type !== 'ADMIN' && !$performer->pro->can_view_rm_matrix, 403);
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- $rc = $request->input('rc') ?: 1;
- $rc2 = $request->input('rc2') ?: 2;
- $conditions = [];// $this->rpmConditions($performer, $rc, $rc2);
- $sortBy = $request->input('sort_by') ?: 'name_first';
- $sortDir = $request->input('sort_dir') ?: 'ASC';
- $orderBy = "ORDER BY $sortBy $sortDir NULLS LAST";
- $query = "
- SELECT client.name_first, client.name_last,
- (client.name_first || ' ' || client.name_last) as client_name,
- client.uid as client_uid,
- client.dob,
- client.is_enrolled_in_rm,
- client.most_recent_completed_mcp_note_date,
- client.most_recent_completed_mcp_note_id,
- mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
- mrmnote.id as most_recent_completed_mcp_note_id_cm,
- mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
- client.cell_number,
- client.is_assigned_cellular_bp_device,
- client.is_assigned_cellular_weight_scale_device,
- care_month.uid as care_month_uid,
- care_month.id as care_month_id,
- care_month.start_date,
- care_month.rm_total_time_in_seconds_by_mcp,
- care_month.rm_total_time_in_seconds_by_rmm_pro,
- care_month.number_of_days_with_remote_measurements,
- care_month.has_mcp_interacted_with_client_about_rm,
- care_month.rm_num_measurements_not_stamped_by_mcp,
- care_month.rm_num_measurements_not_stamped_by_non_hcp,
- care_month.rm_num_measurements_not_stamped_by_rmm,
- care_month.rm_num_measurements_not_stamped_by_rme,
- care_month.mcp_pro_id as care_month_mcp_pro_id,
- care_month.rmm_pro_id as care_month_rmm_pro_id,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id,
- client.cell_number,
- client.most_recent_cellular_bp_dbp_mm_hg,
- client.most_recent_cellular_bp_sbp_mm_hg,
- client.most_recent_cellular_bp_measurement_at,
- client.most_recent_cellular_weight_value,
- client.most_recent_cellular_weight_measurement_at
- 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
- left join note mrmnote on mrmnote.id = (
- select max(n.id) from note n
- where
- n.client_id = client.id AND
- n.is_cancelled = FALSE AND
- (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
- n.effective_dateest::date >= care_month.start_date::date AND
- n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
- )
- WHERE
- (care_month.mcp_pro_id = {$performer->pro->id} OR care_month.rmm_pro_id = {$performer->pro->id})
- AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
- $orderBy
- ";
- $patients = DB::select($query);
- $timestamp = strtotime(date('Y-m-d'));
- $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
- return view('app.practice-management.remote-monitoring', compact('patients', 'daysRemaining', 'careMonthStart'));
- }
- public function remoteMonitoring_Row(Request $request) {
- $clientUid = $request->input('clientUid');
- $careMonthUid = $request->input('careMonthUid');
- $query = "
- SELECT client.name_first, client.name_last,
- (client.name_first || ' ' || client.name_last) as client_name,
- client.uid as client_uid,
- client.dob,
- client.is_enrolled_in_rm,
- client.most_recent_completed_mcp_note_date,
- client.most_recent_completed_mcp_note_id,
- mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
- mrmnote.id as most_recent_completed_mcp_note_id_cm,
- mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
- client.cell_number,
- client.is_assigned_cellular_bp_device,
- client.is_assigned_cellular_weight_scale_device,
- care_month.uid as care_month_uid,
- care_month.id as care_month_id,
- care_month.start_date,
- care_month.rm_total_time_in_seconds_by_mcp,
- care_month.rm_total_time_in_seconds_by_rmm_pro,
- care_month.number_of_days_with_remote_measurements,
- care_month.has_mcp_interacted_with_client_about_rm,
- care_month.rm_num_measurements_not_stamped_by_mcp,
- care_month.rm_num_measurements_not_stamped_by_non_hcp,
- care_month.rm_num_measurements_not_stamped_by_rmm,
- care_month.rm_num_measurements_not_stamped_by_rme,
- care_month.mcp_pro_id as care_month_mcp_pro_id,
- care_month.rmm_pro_id as care_month_rmm_pro_id,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id,
- client.cell_number,
- client.most_recent_cellular_bp_dbp_mm_hg,
- client.most_recent_cellular_bp_sbp_mm_hg,
- client.most_recent_cellular_bp_measurement_at,
- client.most_recent_cellular_weight_value,
- client.most_recent_cellular_weight_measurement_at
- 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
- left join note mrmnote on mrmnote.id = (
- select max(n.id) from note n
- where
- n.client_id = client.id AND
- n.is_cancelled = FALSE AND
- (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
- n.effective_dateest::date >= care_month.start_date::date AND
- n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
- )
- WHERE care_month.uid = '{$careMonthUid}' AND client.uid = '{$clientUid}'
- ";
- $patients = DB::select($query);
- return view('app.practice-management.remote-monitoring-row', ['iPatient' => $patients[0], 'trIndex' => $request->input('trIndex')]);
- }
- public function rpm_work_matrix(Request $request) {
- // get the patient having most recent unstamped measurement
- $performer = $this->performer();
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- $patient = null;
- $careMonth = null;
- if($request->input('patientUid') && $request->input('careMonthUid')) {
- $patient = Client::where('uid', $request->input('patientUid'))->first();
- $careMonth = CareMonth::where('uid', $request->input('careMonthUid'))->first();
- }
- if(!$patient && !$careMonth) {
- $query = "
- SELECT client.name_first, client.name_last,
- (client.name_first || ' ' || client.name_last) as client_name,
- client.uid as client_uid,
- client.dob,
- client.is_enrolled_in_rm,
- client.most_recent_completed_mcp_note_date,
- care_month.uid as care_month_uid,
- care_month.id as care_month_id,
- care_month.start_date,
- care_month.rm_total_time_in_seconds_by_mcp,
- care_month.number_of_days_with_remote_measurements,
- care_month.rm_num_measurements_not_stamped_by_mcp,
- care_month.rm_num_measurements_not_stamped_by_rmm,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id,
- client.cell_number,
- client.most_recent_cellular_bp_dbp_mm_hg,
- client.most_recent_cellular_bp_sbp_mm_hg,
- client.most_recent_cellular_bp_measurement_at,
- client.most_recent_cellular_weight_value,
- client.most_recent_cellular_weight_measurement_at,
- GREATEST(client.most_recent_cellular_bp_measurement_at, client.most_recent_cellular_weight_measurement_at) as latest_measurement_at
- FROM care_month join client on care_month.client_id = client.id
- WHERE
- (
- (care_month.mcp_pro_id = {$performer->pro->id} AND care_month.rm_num_measurements_not_stamped_by_mcp > 0) OR
- (care_month.rmm_pro_id = {$performer->pro->id} AND care_month.rm_num_measurements_not_stamped_by_rmm > 0)
- )
- AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
- ORDER BY latest_measurement_at DESC
- LIMIT 1
- ";
- $patients = DB::select($query);
- if (count($patients)) {
- $patient = Client::where('uid', $patients[0]->client_uid)->first();
- $careMonth = CareMonth::where('uid', $patients[0]->care_month_uid)->first();
- }
- }
- return view('app.practice-management.rpm_work_matrix', compact('patient', 'careMonth'));
- }
- public function remoteMonitoringCount(Request $request) {
- $performer = $this->performer();
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- $rc = $request->input('rc') ?: 1;
- $rc2 = $request->input('rc2') ?: 2;
- $conditions = $this->rpmConditions($performer, $rc, $rc2);
- $count = DB::select(
- DB::raw(
- "
- SELECT count(*)
- FROM care_month join client on care_month.client_id = client.id
- WHERE
- client.mcp_pro_id = {$performer->pro->id}
- AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
- )
- );
- return $count[0]->count;
- }
- public function remoteMonitoringAdmin(Request $request) {
- $performer = $this->performer();
- // abort_if($performer->pro->pro_type !== 'ADMIN' && !$performer->pro->can_view_rm_matrix, 403);
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- $rc = $request->input('rc') ?: 1;
- $rc2 = $request->input('rc2') ?: 2;
- $conditions = [];// $this->rpmConditions($performer, $rc, $rc2);
- $sortBy = $request->input('sort_by') ?: 'name_first';
- $sortDir = $request->input('sort_dir') ?: 'ASC';
- $orderBy = "ORDER BY $sortBy $sortDir NULLS LAST";
- $query = "
- SELECT client.name_first, client.name_last,
- (client.name_first || ' ' || client.name_last) as client_name,
- (mcp_pro.name_first || ' ' || mcp_pro.name_last) as mcp_pro_name,
- (rmm_pro.name_first || ' ' || rmm_pro.name_last) as rmm_pro_name,
- client.uid as client_uid,
- client.chart_number,
- client.dob,
- client.is_enrolled_in_rm,
- client.most_recent_completed_mcp_note_date,
- client.most_recent_completed_mcp_note_id,
- mrmnote.effective_dateest::date as most_recent_completed_mcp_note_date_cm,
- mrmnote.id as most_recent_completed_mcp_note_id_cm,
- mrmnote.uid as most_recent_completed_mcp_note_uid_cm,
- client.cell_number,
- client.is_assigned_cellular_bp_device,
- client.is_assigned_cellular_weight_scale_device,
- care_month.uid as care_month_uid,
- care_month.id as care_month_id,
- care_month.start_date,
- care_month.rm_total_time_in_seconds_by_mcp,
- care_month.rm_total_time_in_seconds_by_rmm_pro,
- care_month.number_of_days_with_remote_measurements,
- care_month.has_anyone_interacted_with_client_about_rm,
- care_month.has_mcp_interacted_with_client_about_rm,
- care_month.rm_num_measurements_not_stamped_by_mcp,
- care_month.rm_num_measurements_not_stamped_by_non_hcp,
- care_month.rm_num_measurements_not_stamped_by_rmm,
- care_month.rm_num_measurements_not_stamped_by_rme,
- care_month.mcp_pro_id as care_month_mcp_pro_id,
- care_month.rmm_pro_id as care_month_rmm_pro_id,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id,
- client.cell_number,
- care_month.most_recent_cellular_bp_dbp_mm_hg,
- care_month.most_recent_cellular_bp_sbp_mm_hg,
- care_month.most_recent_cellular_bp_measurement_at,
- care_month.most_recent_cellular_weight_value,
- care_month.most_recent_cellular_weight_measurement_at
- 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
- left join note mrmnote on mrmnote.id = (
- select max(n.id) from note n
- where
- n.client_id = client.id AND
- n.is_cancelled = FALSE AND
- (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
- n.effective_dateest::date >= care_month.start_date::date AND
- n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
- )
- left join pro mcp_pro on care_month.mcp_pro_id = mcp_pro.id
- left join pro rmm_pro on care_month.rmm_pro_id = rmm_pro.id
- WHERE
- EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
- $orderBy
- ";
- $patients = DB::select($query);
- $timestamp = strtotime(date('Y-m-d'));
- $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
- return view('app.practice-management.remote-monitoring-admin', compact('patients', 'daysRemaining', 'careMonthStart'));
- }
- public function remoteMonitoringAdminCount(Request $request) {
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- $rc = $request->input('rc') ?: 1;
- $rc2 = $request->input('rc2') ?: 2;
- $conditions = $this->rpmConditionsAdmin($this->performer(), $rc, $rc2);
- $count = DB::select(
- DB::raw(
- "
- SELECT count(*)
- FROM care_month join client on care_month.client_id = client.id
- WHERE
- client.shadow_pro_id is null AND client.is_enrolled_in_rm = 'YES'
- AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
- )
- );
- return $count[0]->count;
- }
- private function rpmConditions($performer, $rc, $rc2) {
- $conditions = [];
- $c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
- $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
- $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";
- $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
- $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
- $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)";
- $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
- $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
- $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
- $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
- $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
- $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
- $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
- $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
- $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
- switch ($rc) {
- case 1:
- $conditions = [$c_isMCP];
- break;
- case 2:
- $conditions = [$c_isMCP, $c_enrolledInRPM];
- break;
- case 3:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice];
- break;
- case 4:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
- break;
- case 5:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
- break;
- case 6:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
- break;
- case 7:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
- break;
- case 10:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
- break;
- case 8:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
- break;
- case 9:
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_deviceUsed];
- break;
- }
- return $conditions;
- }
- private function rpmConditionsAdmin($performer, $rc, $rc2) {
- $conditions = [];
- $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
- $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";
- $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
- $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
- $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)";
- $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
- $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
- $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
- $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
- $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
- $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
- $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR client.most_recent_cellular_weight_measurement_at IS NOT NULL)";
- $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
- $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
- switch ($rc) {
- case 2:
- $conditions = [$c_enrolledInRPM];
- break;
- case 3:
- $conditions = [$c_enrolledInRPM, $c_hasDevice];
- break;
- case 4:
- $conditions = [$c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
- break;
- case 5:
- $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
- break;
- case 6:
- $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
- break;
- case 7:
- $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
- break;
- case 10:
- $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
- break;
- case 8:
- $conditions = [$c_enrolledInRPM, $c_subscribedToSMS];
- break;
- case 9:
- $conditions = [$c_enrolledInRPM, $c_deviceUsed];
- break;
- }
- return $conditions;
- }
- public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
- $performer = $this->performer();
- $measurements = DB::select(
- DB::raw(
- "
- SELECT measurement.label,
- measurement.ts,
- measurement.effective_date,
- measurement.sbp_mm_hg,
- measurement.dbp_mm_hg,
- measurement.value_pulse,
- measurement.value_irregular,
- measurement.numeric_value,
- measurement.value,
- measurement.uid,
- client.name_first,
- client.name_last,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id
- FROM measurement RIGHT JOIN client on measurement.client_id = client.id
- WHERE
- client.id = {$careMonth->client_id}
- AND measurement.label IS NOT NULL
- AND measurement.label NOT IN ('SBP', 'DBP')
- AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
- AND measurement.is_removed IS FALSE
- AND measurement.client_bdt_measurement_id IS NOT NULL
- AND measurement.care_month_id = {$careMonth->id}
- AND (
- (client.mcp_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_mcp IS FALSE)
- OR (client.rmm_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rmm IS FALSE)
- OR (client.rme_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_rme IS FALSE)
- OR (client.default_na_pro_id = {$performer->pro->id} AND measurement.has_been_stamped_by_non_hcp IS FALSE)
- )
- ORDER BY ts DESC
- "
- )
- );
- return view('app.practice-management.remote-monitoring-measurements', compact('careMonth', 'measurements'));
- }
- public function billMatrix(Request $request)
- {
- $bClients = [];
- $bHCPPros = [];
- $bNAPros = [];
- $filters = [];
- $filters['client'] = $request->input('client');
- $filters['service'] = $request->input('service');
- $filters['hcp'] = $request->input('hcp');
- $filters['hcp_paid'] = $request->input('hcp_paid');
- $filters['expected_op'] = $request->input('expected_op');
- $filters['expected_value'] = $request->input('expected_value');
- $filters['paid_op'] = $request->input('paid_op');
- $filters['paid_value'] = $request->input('paid_value');
- $filters['bal_post_date_op'] = $request->input('bal_post_date_op');
- $filters['bal_post_date_value'] = $request->input('bal_post_date_value');
- $filters['hcp_sign'] = $request->input('hcp_sign');
- $filters['verified'] = $request->input('verified');
- $filters['cancelled'] = $request->input('cancelled');
- $bills = Bill::orderBy('effective_date')->paginate();
- return view('app.practice-management.bill-matrix', compact('bills', 'bClients', 'bHCPPros', 'filters'));
- }
- public function medicarePartBClaims(Request $request)
- {
- $medicarePartBOnly = $request->get("medicare_part_b");
- $allClaims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->get();
- //Only medicare claims
- $claims = [];
- foreach ($allClaims as $claim) {
- if ($claim->client != null && $claim->client->getPrimaryCoverageStatus() == 'YES' && !$claim->edi) {
- $claims[] = $claim;
- }
- }
- $claimEDIs = ClaimEDI::all();
- return view('app.practice-management.medicare-partb-claims', compact('claims', 'claimEDIs'));
- }
- // Generate PDF
- public function downloadClaims()
- {
- $claims = Claim::where('was_submitted', false)->orWhere('was_submitted', null)->orderBy('created_at', 'desc')->limit(100)->get();
- view()->share('claims', $claims);
- $pdf = PDF::loadView('app.practice-management.claims-pdf', $claims);
- return $pdf->download('pdf_file.pdf');
- }
- public function tickets(Request $request, $proUid = null)
- {
- $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
- return view('app.practice-management.tickets', compact('tickets'));
- }
- public function supplyOrders(Request $request)
- {
- // counts
- $counts = $this->getSupplyOrderCounts();
- // so clients
- $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
- $soClientIDs = array_map(function ($_x) {
- return $_x->client_id;
- }, $soClientIDs);
- $soClients = Client::whereIn('id', $soClientIDs)->get();
- // so products
- $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
- $soProductIDs = array_map(function ($_x) {
- return $_x->product_id;
- }, $soProductIDs);
- $soProducts = Product::whereIn('id', $soProductIDs)->get();
- $filters = [];
- $filters['client'] = $request->input('client');
- $filters['product'] = $request->input('product');
- $filters['reason'] = $request->input('reason');
- $filters['cu_memo'] = $request->input('cu_memo');
- $filters['pro_sign'] = $request->input('pro_sign');
- $filters['client_sign'] = $request->input('client_sign');
- $filters['shipment'] = $request->input('shipment');
- $filters['lot_number'] = $request->input('lot_number');
- $filters['imei'] = $request->input('imei');
- $filters['cancelled'] = $request->input('cancelled');
- $supplyOrders = SupplyOrder::where('id', '>', 0);
- // apply filters
- if ($filters['client']) $supplyOrders->where('client_id', $filters['client']);
- if ($filters['product']) $supplyOrders->where('product_id', $filters['product']);
- if ($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
- if ($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
- if ($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
- if ($filters['client_sign']) {
- if ($filters['client_sign'] === 'signed')
- $supplyOrders->where('is_signed_by_client', true);
- elseif ($filters['client_sign'] === 'waived')
- $supplyOrders->where('is_client_signature_waived', true);
- else
- $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
- }
- if ($filters['shipment']) {
- if ($filters['shipment'] === 'not_cleared_for_shipment')
- $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', false);
- elseif ($filters['shipment'] === 'cleared_for_shipment')
- $supplyOrders->whereNull('shipment_id')->where('is_cleared_for_shipment', true);
- else
- $supplyOrders
- ->whereNotNull('shipment_id')
- ->whereRaw('(SELECT status FROM shipment WHERE id = shipment_id LIMIT 1) = ?', [$filters['shipment']]);
- }
- if ($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
- if ($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
- if ($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
- $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
- return view('app.practice-management.supply-orders',
- compact('supplyOrders', 'filters',
- 'soClients', 'soProducts', 'counts'
- )
- );
- }
- public function shipments(Request $request, $filter = null)
- {
- // counts
- $counts = $this->getShipmentCounts();
- // so clients
- $shClientIDs = DB::table('shipment')->select('client_id')->distinct()->get()->toArray();
- $shClientIDs = array_map(function ($_x) {
- return $_x->client_id;
- }, $shClientIDs);
- $shClients = Client::whereIn('id', $shClientIDs)->get();
- $shipments = Shipment::where('id', '>', 0);
- $filters = [];
- $filters['client'] = $request->input('client');
- $filters['courier'] = $request->input('courier');
- $filters['tracking_num'] = $request->input('tracking_num');
- $filters['label'] = $request->input('label');
- $filters['status'] = $request->input('status');
- $filters['cancelled'] = $request->input('cancelled');
- if ($filters['client']) $shipments->where('client_id', $filters['client']);
- if ($filters['courier']) $shipments->where('courier', 'ILIKE', '%' . $filters['courier'] . '%');
- if ($filters['tracking_num']) $shipments->where('tracking_number', 'ILIKE', '%' . $filters['tracking_num'] . '%');
- if ($filters['label']) {
- if ($filters['label'] === 'yes')
- $shipments->whereNotNull('label_system_file_id');
- else
- $shipments->whereNull('label_system_file_id');
- }
- if ($filters['status']) $shipments->where('status', $filters['status']);
- if ($filters['cancelled']) $shipments->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
- $shipments = $shipments->orderBy('created_at', 'desc')->paginate();
- return view('app.practice-management.shipments', compact('shipments', 'filters', 'shClients', 'counts'));
- }
- public function cellularMeasurements(Request $request)
- {
- $measurements = Measurement::orderBy('ts', 'desc')->whereNotNull('ts')->paginate();
- return view('app.practice-management.cellular-measurements', compact('measurements'));
- }
- // v2 supply-orders & shipments management (wh)
- public function supplyOrdersReadyToShip(Request $request)
- {
- $counts = $this->getSupplyOrderCounts();
- $supplyOrders = SupplyOrder
- ::where('is_cleared_for_shipment', true)
- ->where('is_cancelled', false)
- ->whereNull('shipment_id')
- ->join('client', 'client.id', '=', 'supply_order.client_id')
- ->orderBy('client.name_last', 'ASC')
- ->orderBy('client.name_first', 'ASC')
- ->orderBy('supply_order.client_id', 'ASC')
- ->orderBy('supply_order.mailing_address_full', 'ASC')
- ->orderBy('supply_order.created_at', 'ASC')
- ->select('supply_order.*')
- ->paginate();
- return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
- }
- public function supplyOrdersShipmentUnderway(Request $request)
- {
- $counts = $this->getSupplyOrderCounts();
- $supplyOrders = SupplyOrder
- ::where('is_cancelled', false)
- ->whereNotNull('shipment_id')
- ->orderBy('client_id', 'ASC')
- ->orderBy('mailing_address_full', 'ASC')
- ->orderBy('created_at', 'ASC')
- ->paginate();
- return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
- }
- public function supplyOrdersHanging(Request $request)
- {
- $counts = $this->getSupplyOrderCounts();
- $supplyOrders = SupplyOrder
- ::select('supply_order.*')
- ->leftJoin('shipment', function($join) {
- $join->on('supply_order.shipment_id', '=', 'shipment.id');
- })
- ->where('shipment.status', 'CANCELLED')
- ->where('supply_order.is_cancelled', false)
- ->orderBy('supply_order.client_id', 'ASC')
- ->orderBy('supply_order.mailing_address_full', 'ASC')
- ->orderBy('supply_order.created_at', 'ASC')
- ->paginate();
- return view('app.practice-management.supply-orders-hanging', compact('supplyOrders', 'counts'));
- }
- public function supplyOrdersCancelledButUnacknowledged(Request $request)
- {
- $supplyOrders = SupplyOrder::where('signed_by_pro_id', $this->performer()->pro->id)
- ->where('is_cancelled', true)
- ->where('is_cancellation_acknowledged', false)
- ->orderBy('created_at', 'desc')
- ->paginate();
- return view('app.practice-management.supply-orders-cancelled-but-unacknowledged', compact('supplyOrders'));
- }
- public function supplyOrdersUnsigned(Request $request)
- {
- $supplyOrders = SupplyOrder
- ::where('is_cancelled', false)
- ->where('is_signed_by_pro', false)
- ->whereRaw('created_by_session_id IN (SELECT id FROM app_session WHERE pro_id = ?)', [$this->performer()->pro->id])
- ->orderBy('created_at', 'desc')
- ->paginate();
- return view('app.practice-management.supply-orders-unsigned', compact('supplyOrders'));
- }
- private function getSupplyOrderCounts()
- {
- return [
- "supplyOrders" => SupplyOrder::count(),
- "supplyOrdersReadyToShip" => SupplyOrder
- ::where('is_cleared_for_shipment', true)
- ->where('is_cancelled', false)
- ->whereNull('shipment_id')->count(),
- "supplyOrdersShipmentUnderway" => SupplyOrder
- ::where('is_cancelled', false)
- ->whereNotNull('shipment_id')->count(),
- "supplyOrdersHanging" => SupplyOrder
- ::leftJoin('shipment', function($join) {
- $join->on('supply_order.shipment_id', '=', 'shipment.id');
- })
- ->where('shipment.status', 'CANCELLED')
- ->where('supply_order.is_cancelled', false)
- ->count(),
- ];
- }
- public function shipmentsReadyToPrint(Request $request)
- {
- $counts = $this->getShipmentCounts();
- $shipments = Shipment
- ::where('is_cancelled', false)
- ->where('status', 'CREATED')
- ->orderBy('created_at', 'ASC')
- ->paginate();
- return view('app.practice-management.shipments-ready-to-print', compact('shipments', 'counts'));
- }
- public function shipmentsShipmentUnderway(Request $request)
- {
- $counts = $this->getShipmentCounts();
- $shipments = Shipment
- ::where('is_cancelled', false)
- ->where('status', 'PRINTED')
- ->orderBy('created_at', 'ASC')
- ->paginate();
- return view('app.practice-management.shipments-waiting-for-picker', compact('shipments', 'counts'));
- }
- private function getShipmentCounts()
- {
- return [
- "shipments" => Shipment::count(),
- "shipmentsReadyToPrint" => Shipment
- ::where('is_cancelled', false)
- ->where('status', 'CREATED')
- ->count(),
- "shipmentsWaitingForPicker" => Shipment
- ::where('is_cancelled', false)
- ->where('status', 'PRINTED')
- ->count()
- ];
- }
- public function shipment(Request $request, Shipment $shipment)
- {
- return view('app.practice-management.shipment', compact('shipment'));
- }
- public function shipmentsMultiPrint(Request $request, $ids)
- {
- $ids = array_map(function ($_x) {
- return intval($_x);
- }, explode("|", $ids));
- $shipments = Shipment::whereIn('id', $ids)->get();
- return view('app.practice-management.shipments-multi-print', compact('shipments'));
- }
- public function patientClaimSummary(Request $request, $proUid = null)
- {
- $notesTotal = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE"))[0]->count;
- $notesTotalWithBillingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_bill_closed IS TRUE"))[0]->count;
- $notesTotalWithClaimingClosed = DB::select(DB::raw("SELECT COUNT(*) FROM note WHERE is_cancelled IS NOT TRUE AND is_claim_closed IS TRUE"))[0]->count;
- $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;
- $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;
- $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;
- $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;
- $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;
- $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;
- $performerPro = $this->performer->pro;
- $allPros = [];
- if ($performerPro->pro_type == 'ADMIN') {
- $allPros = Pro::all();
- } else {
- $allPros = [$performerPro];
- }
- //Patient | MCP | # Notes Total | # Notes without Billing Closed | # Notes without Claiming Closed
- $patientsQuery = Client::where('is_dummy', '=', false)
- ->whereNull('shadow_pro_id')
- ->select('id', 'uid', 'name_first', 'name_last', 'mcp_pro_id', 'is_part_b_primary', 'medicare_advantage_plan',
- DB::raw("(SELECT name_first||' '||name_last FROM pro where pro.id = client.mcp_pro_id) as mcp"),
- DB::raw("(SELECT uid FROM pro where pro.id = mcp_pro_id) as mcp_pro_uid"),
- DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id) as notes_total"),
- DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_bill_closed IS NOT true) as notes_without_billing_closed"),
- DB::raw("(SELECT COUNT(*) FROM note where note.client_id = client.id AND is_claim_closed IS NOT true) as notes_without_claiming_closed")
- )->orderBy('is_part_b_primary', 'asc')->orderBy('notes_without_claiming_closed', 'desc');
- if ($proUid) {
- $mcpPro = Pro::where('uid', $proUid)->first();
- if ($mcpPro) {
- $patientsQuery->where('client.mcp_pro_id', '=', $mcpPro->id);
- }
- }
- $patientsQuery->whereRaw('(SELECT COUNT(*) FROM note where note.client_id = client.id) > 0');
- $patientsQuery->orderBy('notes_total', 'DESC');
- $patients = $patientsQuery->paginate(50);
- $data = [
- 'patients' => $patients,
- 'proUid' => $proUid,
- 'allPros' => $allPros,
- 'notesTotal' => $notesTotal,
- 'notesTotalWithBillingClosed' => $notesTotalWithBillingClosed,
- 'notesTotalWithClaimingClosed' => $notesTotalWithClaimingClosed,
- 'notes3rdPartyTotal' => $notes3rdPartyTotal,
- 'notes3rdPartyTotalWithBillingClosed' => $notes3rdPartyTotalWithBillingClosed,
- 'notes3rdPartyTotalWithClaimingClosed' => $notes3rdPartyTotalWithClaimingClosed,
- 'patientsTotal' => $patientsTotal,
- 'patientsTotalWithBillingClosed' => $patientsTotalWithBillingClosed,
- 'patientsTotalWithClaimingClosed' => $patientsTotalWithClaimingClosed
- ];
- return view('app.practice-management.patient-claim-summary', $data);
- }
- public function claims(Request $request){
- $status = $request->get('status');
- $claims = [];
- if(!$status){
- $claims = Claim::orderBy('created_at', 'DESC')->paginate();
- }else{
- $claims = Claim::where('status', $status)->orderBy('created_at', 'DESC')->paginate();
- }
- return view('app.practice-management.claims', compact('claims', 'status'));
- }
- public function processClaims(Request $request) {
- $status = '';
- $q = $request->input('q') ? $request->input('q') : '';
- $from = $request->input('from') ? $request->input('from') : '1900-01-01';
- $to = $request->input('to') ? $request->input('to') : '2100-01-01';
- $params = [
- 'q' => '%' . $q . '%',
- 'from' => $from,
- 'to' => $to
- ];
- $hcpPro = $request->input('hcp') ? Pro::where('uid', $request->input('hcp'))->first() : null;
- if($hcpPro) {
- $params['hcp'] = $hcpPro->id;
- }
- $claims = DB::select(DB::raw("
- SELECT claim.uid AS uid,
- DATE(claim.created_at) AS created,
- claim.status,
- client.uid AS client_uid,
- client.cell_number AS client_phone,
- client.phone_home AS client_phone_home,
- (client.name_last || ' ' || client.name_first) AS client ,
- client.chart_number AS client_chart_number,
- cp.id AS claim_pro_id,
- (cp.name_last || ' ' || cp.name_first) AS claim_pro,
- sp.id AS status_pro_id,
- (sp.name_last || ' ' || sp.name_first) AS status_pro,
- note.uid AS note_uid,
- note.method,
- note.new_or_fu_or_na,
- care_month.uid AS care_month_uid,
- care_month.start_date as care_month_start__date,
- -- claim.status_updated_at,
- (DATE(claim.status_updated_at) || ' ' ||
- LPAD(EXTRACT(hour FROM claim.status_updated_at)::text, 2, '0') || ':' ||
- LPAD(EXTRACT(minute FROM claim.status_updated_at)::text, 2, '0')) AS status_updated_at,
- (SELECT string_agg(claim_line.cpt, ', ') FROM claim_line where claim_id = claim.id) AS cpts,
- (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,
- ROUND(claim.expected_total, 3) as expected_total
- FROM claim
- join client on claim.client_id = client.id
- join pro cp on claim.pro_id = cp.id
- left join note on claim.note_id = note.id
- left join care_month on claim.care_month_id = care_month.id
- left join app_session on claim.status_updated_by_session_id = app_session.id
- left join pro sp on app_session.pro_id = sp.id
- --WHERE claim.status IS NULL OR claim.status = 'NEW'
- WHERE (claim.status is NULL OR claim.status NOT IN ('CANCELLED', 'ABANDONED'" . ($request->input('show-submitted') ? "" : ", 'SUBMITTED'") . "))
- -- AND claim.current_version_id IS NOT NULL
- AND (client.name_first ILIKE :q OR
- client.name_last ILIKE :q OR
- client.chart_number ILIKE :q OR
- client.mcn ILIKE :q)
- AND (claim.created_at >= :from AND claim.created_at <= :to)
- " . ($hcpPro ? "AND claim.pro_id = :hcp" : '') . "
- AND claim.id IN (SELECT mb_claim.claim_id FROM mb_claim)
- ORDER BY claim.created_at DESC
- --OFFSET 0 LIMIT 15
- "), $params);
- if($request->input('json')) {
- return json_encode($claims);
- }
- return view('app.practice-management.process-claims', compact('claims', 'status'));
- }
- public function rmLaunchAndClean(Request $request) {
- $keyNumbers = [];
- $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
- ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->whereRaw('is_rm_time_waived IS NOT TRUE')
- ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE )')
- ->count();
- $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_40_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
- ->where('rm_total_time_in_seconds', '>=', 4200) // at 4200 (70 minutes, it becomes eligible for plus40)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->whereRaw('is_rm_time_waived IS NOT TRUE')
- ->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 )')
- ->count();
- $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
- ->where('rm_total_time_in_seconds', '<', 4200)
- ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->whereRaw('is_rm_time_waived IS NOT TRUE')
- ->whereRaw('(has_anyone_interacted_with_client_about_rm_outside_note IS TRUE OR has_mcp_rm_interacted_by_note IS TRUE)')
- ->count();
- $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP_PLUS_20_ifHadInteraction'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
- ->where('rm_total_time_in_seconds', '<', 4200)
- ->where('rm_total_time_in_seconds', '>=', 3000) // at 3000 (50 minutes, it becomes eligible for plus20)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->whereRaw('is_rm_time_waived IS NOT TRUE')
- ->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 )')
- ->count();
- $keyNumbers['careMonthsEligibleForBillGeneration_RM30_HCP'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->where('rm_total_time_in_seconds_by_mcp', '>=', 1800)
- ->whereRaw('is_rm_time_waived IS NOT TRUE')
- ->whereRaw('(rm_total_time_in_seconds < 3000 OR (rm_total_time_in_seconds >= 3000 AND is_rm_interaction_waived IS TRUE))')
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->count();
- $keyNumbers['careMonthsEligibleForBillGeneration_RMB'] = CareMonth::where('is_bill_closed', false)
- ->whereNotNull('company_pro_id')
- ->whereNotNull('company_pro_payer_id')
- ->whereNotNull('company_location_id')
- ->whereRaw('(SELECT count(id) FROM care_month_cm_rm_reason WHERE care_month_id = care_month.id) > 0')
- ->whereRaw('is_rm_time_waived IS TRUE')
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->count();
- $keyNumbers['careMonthsWith16OrMoreMeasurementDays'] = CareMonth::where('is_bill_closed', false)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )
- ->count();
- $careMonthsWith16PlusMeasurements = CareMonth::where('is_bill_closed', false)
- ->where('number_of_days_with_remote_measurements', '>=', 16 )->get();
- return view('app.practice-management.rm-launch-and-clean', compact('keyNumbers', 'careMonthsWith16PlusMeasurements'));
- }
- public function processNotes(Request $request) {
- $mode = $request->input('mode') ? $request->input('mode') : '1';
- if(($mode < 1 || $mode > 5) && $mode != 8) $mode = 1;
- DB::enableQueryLog(); // Enable query log
- $test = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', true)
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
- ->count();
- // var_dump($test);
- // dd(DB::getQueryLog()); // Show results of log
- // exit;
- $counts = [
- "picked" => Note::where('is_cancelled', false)
- ->whereNotNull('current_note_pickup_for_processing_id')
- ->count(),
- "bad" => Note::where('is_cancelled', false)
- ->whereRaw("((detail_json)::json->>'isBad' = 'true')")
- ->count(),
- // not yet signed
- "mode-1" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', false)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->count(),
- // billing not marked done
- "mode-2" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- //->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', false)
- ->count(),
- // billing not closed
- "mode-3" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', false)
- ->count(),
- // claiming not closed
- "mode-4" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', false)
- ->count(),
- // has unsubmitted claims
- "mode-5" => Note::where('is_cancelled', false)
- /*->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', true)
- ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
- */
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- // ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true')")
- ->where('is_claim_closed', true)
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0)")
- ->count(),
- // has unsubmitted claims MARKED GOOD!
- "mode-8" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', false)
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
- ->count(),
- // all good
- "mode-6" => Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- // ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', true)
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id) > 0)")
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
- ->count(),
- "mode-7" => Note::where('is_cancelled', false)
- ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
- ->count(),
- ];
- return view('app.practice-management.process-notes', compact('mode', 'counts'));
- }
- public function notesProcessingCenter(Request $request) {
- $notes = Note::where('is_cancelled', false);
- // filters
- $proUid = $request->input('proUid');
- if($proUid) {
- $fPro = Pro::where('uid', $proUid)->first();
- if($fPro) {
- $notes = $notes->where('hcp_pro_id', $fPro->id);
- }
- }
- $proSigned = $request->input('proSigned');
- switch($proSigned) {
- case 'yes': $notes = $notes->where('is_signed_by_hcp', true); break;
- case 'no': $notes = $notes->where('is_signed_by_hcp', '!=', true); break;
- }
- $billingMarkedDone = $request->input('billingMarkedDone');
- switch($billingMarkedDone) {
- case 'yes': $notes = $notes->where('is_billing_marked_done', true); break;
- case 'no': $notes = $notes->where('is_billing_marked_done', '!=', true); break;
- }
- $billingClosed = $request->input('billingClosed');
- switch($billingClosed) {
- case 'yes': $notes = $notes->where('is_bill_closed', true); break;
- case 'no': $notes = $notes->where('is_bill_closed', '!=', true); break;
- }
- $claimingClosed = $request->input('claimingClosed');
- switch($claimingClosed) {
- case 'yes': $notes = $notes->where('is_claim_closed', true); break;
- case 'no': $notes = $notes->where('is_claim_closed', '!=', true); break;
- }
- $allClaimsSubmitted = $request->input('allClaimsSubmitted');
- if($allClaimsSubmitted) {
- // TODO
- }
- $goodBad = $request->input('goodBad');
- switch($goodBad) {
- case 'good': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'false'"); break;
- case 'bad': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' = 'true'"); break;
- case 'unclassified': $notes = $notes->whereRaw("(detail_json)::json->>'isBad' is null"); break;
- }
- $startDate = $request->input('startDate');
- if($startDate) {
- $notes = $notes->where('effective_dateest', '>=', $startDate);
- }
- $endDate = $request->input('endDate');
- if($endDate) {
- $notes = $notes->where('effective_dateest', '<=', $endDate);
- }
- $mcPartB = $request->input('mcPartB');
- if($mcPartB) {
- // TODO
- }
- $notes = $notes->orderBy('effective_dateest')->paginate(10);
- return view('app.practice-management.notes-processing-center', compact('notes'));
- }
- public function getNextNote(Request $request, $mode)
- {
- $note = null;
- switch (+$mode) {
- case 1:
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', false)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- break;
- case 2:
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', false)
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- break;
- case 3:
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', false)
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- break;
- case 4: // claiming not closed
- DB::enableQueryLog(); // Enable query log
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->whereRaw("(((detail_json)::json->>'isGood')::text <> 'true' OR ((detail_json)::json->>'isGood')::text IS NULL)")
- ->where('is_claim_closed', false)
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- // DB::enableQueryLog(); // Enable query log
- // Your Eloquent query executed by using get()
- // dd(DB::getQueryLog()); // Show results of log
- break;
- case 5:
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', true)
- ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') > 0")
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- break;
- case 8:
- $note = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isGood')::text = 'true'")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', false)
- ->whereRaw("((SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0)")
- ->orderBy('effective_dateest', 'DESC')
- ->first();
- break;
- }
- if($note) {
- $note->client_uid = $note->client->uid;
- }
- return json_encode($note);
- }
- public function pickedNotes(Request $request) {
- $counts = [
- "unpicked" => Note::where('is_cancelled', false)
- ->whereNull('current_note_pickup_for_processing_id')
- ->count(),
- ];
- $notes = Note::where('is_cancelled', false)
- ->whereNotNull('current_note_pickup_for_processing_id')
- ->orderBy('effective_dateest', 'ASC')
- ->paginate();
- return view('app.practice-management.picked-notes', compact('counts', 'notes'));
- }
- public function badNotes(Request $request) {
- $counts = [
- "unpicked" => Note::where('is_cancelled', false)
- ->whereNull('current_note_pickup_for_processing_id')
- ->count(),
- ];
- $notes = Note::where('is_cancelled', false)
- ->whereRaw("(detail_json)::json->>'isBad' = 'true'")
- ->orderBy('effective_dateest', 'ASC')
- ->paginate();
- return view('app.practice-management.bad-notes', compact('counts', 'notes'));
- }
- public function doneNotes(Request $request) {
- $counts = [
- "unpicked" => Note::where('is_cancelled', false)
- ->whereNull('current_note_pickup_for_processing_id')
- ->count(),
- ];
- $notes = Note::where('is_cancelled', false)
- ->where('is_signed_by_hcp', true)
- ->whereRaw("((detail_json)::json->>'isBad' is null OR ((detail_json)::json->>'isBad')::text != 'true')")
- ->whereNull('current_note_pickup_for_processing_id')
- ->where('is_billing_marked_done', true)
- ->where('is_bill_closed', true)
- ->where('is_claim_closed', true)
- ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id) > 0")
- ->whereRaw("(SELECT count(id) FROM claim WHERE note_id = note.id AND is_cancelled IS FALSE AND status != 'CANCELLED' AND status != 'SUBMITTED') = 0")
- ->orderBy('effective_dateest', 'ASC')
- ->paginate();
- return view('app.practice-management.done-notes', compact('counts', 'notes'));
- }
- public function currentMbClaim(Request $request, $claimUid) {
- $claim = Claim::where('uid', $claimUid)->first();
- return json_encode(MBClaim::where('claim_version_id', $claim->currentVersion->id)->where('status', '!=', 'CANCELLED')->first());
- }
- public function currentClaimLines(Request $request, $claimUid) {
- $claim = Claim::where('uid', $claimUid)->first();
- if($request->input('json')) {
- foreach ($claim->lines as $line) {
- $line->expected_total = round($line->expected_total, 3);
- $x = $line->claimLineIcds;
- }
- return json_encode($claim->lines);
- }
- return view('app.practice-management._claim-lines', compact('claim'));
- }
- public function packsMultiPrint(Request $request) {
- $packs = Pack
- ::select('pack.*')
- ->leftJoin('shipment', function($join) {
- $join->on('pack.shipment_id', '=', 'shipment.id');
- })
- ->whereNotIn('shipment.status', ['CANCELLED', 'DISPATCHED'])
- ->where(function ($query) {
- $query->where('pack.status', '<>', 'DELETED')->orWhereNull('pack.status'); // weird, but just the <> isn't working!
- })
- ->whereNotNull('pack.label_system_file_id')
- ->orderBy('pack.created_at', 'ASC')
- ->get();
- return view('app.practice-management.packs-multi-print', compact('packs'));
- }
- public function packsMultiPDF(Request $request, $ids) {
- $ids = array_map(function ($_x) {
- return intval($_x);
- }, explode("|", $ids));
- $packs = Pack::whereIn('id', $ids)->get();
- }
- public function handouts(Request $request) {
- $handouts = Handout::orderBy('display_name')->get();
- return view('app.practice-management.handouts', compact('handouts'));
- }
- private function callJava($request, $endPoint, $data)
- {
- $url = config('stag.backendUrl') . $endPoint;
- $response = Http::asForm()
- ->withHeaders([
- 'sessionKey' => $request->cookie('sessionKey')
- ])
- ->post($url, $data)
- ->body();
- dd($response);
- return $response;
- }
- public function genericBills(Request $request)
- {
- return view('app.practice-management.generic-bills');
- }
- public function billsUnderProcessing(Request $request)
- {
- $bills = Bill::where('is_cancelled', false)
- ->where(function ($query) { // mcp of any client program and program OB pending
- $query
- ->where(function ($_query) {
- $_query->where('hcp_pro_id', $this->pro->id)
- ->where('hcp_expected_payment_amount', '>', 0)
- ->where('has_hcp_been_paid', false)
- ->where('is_signed_by_hcp', true);
- })
- ->orWhere(function ($_query) {
- $_query->where('cm_pro_id', $this->pro->id)
- ->where('cm_expected_payment_amount', '>', 0)
- ->where('has_cm_been_paid', false)
- ->where('is_signed_by_cm', true);
- })
- ->orWhere(function ($_query) {
- $_query->where('rme_pro_id', $this->pro->id)
- ->where('rme_expected_payment_amount', '>', 0)
- ->where('has_rme_been_paid', false)
- ->where('is_signed_by_rme', true);
- })
- ->orWhere(function ($_query) {
- $_query->where('rmm_pro_id', $this->pro->id)
- ->where('rmm_expected_payment_amount', '>', 0)
- ->where('has_rmm_been_paid', false)
- ->where('is_signed_by_rmm', true);
- })
- ->orWhere(function ($_query) {
- $_query->where('generic_pro_id', $this->pro->id)
- ->where('generic_pro_expected_payment_amount', '>', 0)
- ->where('has_generic_pro_been_paid', false)
- ->where('is_signed_by_generic_pro', true);
- });
- })
- ->orderBy('created_at', 'DESC')
- ->paginate();
- return view('app.practice-management.bills-under-processing', compact('bills'));
- }
- public function careMonthReport(Request $request) {
- $m = $request->input('m');
- $y = $request->input('y');
- if(!$m || !$y) {
- $date = date('Y-m-01');
- }
- else {
- $date = date('Y-m-d', strtotime("$m/1/$y"));
- }
- $pro = $this->pro;
- $records = DB::select("
- SELECT cm.id as care_month_id,
- cm.uid as care_month_uid,
- c.id as client_id,
- c.uid as client_uid,
- cm.number_of_days_with_remote_measurements,
- cm.rm_total_time_in_seconds_by_mcp,
- cm.rm_total_time_in_seconds_by_rme_pro,
- cm.rm_total_time_in_seconds_by_rmm_pro,
- cm.mcp_pro_id,
- cm.rme_pro_id,
- cm.rmm_pro_id,
- (c.name_first || ' ' || c.name_last) as client_name
- FROM care_month cm
- JOIN client c on cm.client_id = c.id
- WHERE cm.start_date = :startDate
- AND (cm.mcp_pro_id = :proID OR
- cm.rme_pro_id = :proID OR
- cm.rmm_pro_id = :proID)
- ORDER BY c.name_last, c.name_first
- ",
- ['startDate' => $date, 'proID' => $pro->id]
- );
- return view('app.practice-management.care-month-report', compact('records', 'date'));
- }
- public function myTeams(Request $request) {
- $pro = $this->pro;
- // get all teams where the authed-pro is the assistant pro
- $teams = ProTeam::where('assistant_pro_id', $pro->id)
- ->where('is_active', true)
- ->orderBy('slug')
- ->get();
- return view('app.practice-management.my-teams', compact('teams'));
- }
- public function patientsAccountsInvites(Request $request){
- $filters = $request->all();
- $accountInvites = AccountInvite::select('account_invite.*')
- ->join('client', 'client.id', '=', 'account_invite.for_client_id');
- if($this->performer->pro->pro_type !== 'ADMIN'){
- $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
- }
- $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
- $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
- $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
- return view('app.practice-management.patients-accounts-invites', compact('accountInvites','filters'));
- }
- public function clientsBdtDevices(Request $request){
- $filters = $request->all();
- $devices = ClientBDTDevice::select(
- 'client_bdt_device.*',
- 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'))
- // 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'))
- ->join('client', 'client.id', '=', 'client_bdt_device.client_id');
- if($this->performer->pro->pro_type !== 'ADMIN'){
- $devices = $devices->where('client.mcp_pro_id', $this->performer->pro->id);
- }
- $this->filterMultiQuery($request, $devices, 'client_bdt_device.most_recent_measurement_at', 'date_category', 'date_value_1', 'date_value_2');
-
- // $dateKeyName = $request->get('date_category');
- // $date1 = $request->get('date_value_1');
- // $date2 = $request->get('date_value_2');
- // $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)";
- // switch($dateKeyName) {
- // case 'EXACTLY':
- // if($date1) {
- // $devices->whereRaw($dateColumnName." = '$date1'::DATE");
- // }
- // break;
- // case 'LESS_THAN':
- // if($date1) {
- // $devices->whereRaw($dateColumnName. "< '$date1'::DATE" );
- // }
- // break;
- // case 'GREATER_THAN':
- // if($date1) {
- // $devices->whereRaw($dateColumnName. "> '$date1'::DATE");
- // }
- // break;
- // case 'BETWEEN':
- // if($date1 && $date2) {
- // $devices
- // ->whereRaw($dateColumnName. ">= '$date1'::DATE")
- // ->whereRaw($dateColumnName. "<= '$date2'::DATE");
- // }
- // break;
- // case 'NOT_BETWEEN':
- // if($date2 && $date1) {
- // $devices
- // ->where(function ($q) use ($request, $dateColumnName, $date1, $date2) {
- // $q->whereRaw($dateColumnName. "< '$date1'::DATE")
- // ->orWhereRaw($dateColumnName. "> '$date2'::DATE");
- // });
- // }
- // break;
- // }
- $keyName = $request->get('measurement_count_category');
- $value1 = $request->get('measurement_count_value_1');
- $value2 = $request->get('measurement_count_value_2');
- $columnName = "(SELECT COUNT(*) FROM bdt_measurement WHERE bdt_measurement.bdt_device_id = client_bdt_device.device_id AND is_cellular_zero IS FALSE)";
- switch($keyName) {
- case 'EXACTLY':
- if($value1) {
- $devices->whereRaw($columnName.'='.$value1);
- }
- break;
- case 'LESS_THAN':
- if($value1) {
- $devices->whereRaw($columnName. '<' .$value1);
- }
- break;
- case 'GREATER_THAN':
- if($value1) {
- $devices->whereRaw($columnName. '>'. $value1);
- }
- break;
- case 'BETWEEN':
- if($value1 && $value2) {
- $devices
- ->whereRaw($columnName. '>=' . $value1)
- ->whereRaw($columnName. '<=' . $value1);
- }
- break;
- case 'NOT_BETWEEN':
- if($value1 && $value2) {
- $devices
- ->where(function ($q) use ($request, $columnName, $value1, $value2) {
- $q->whereRaw($columnName. '<'. $value1)
- ->orWhereRaw($columnName. '>'.$value2);
- });
- }
- break;
- }
-
- $status = $request->get('status');
- if($status){
- if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
- if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
- }
- $devices = $devices->orderBy('num_of_measurements', 'DESC')->paginate(20);
- return view('app.practice-management.clients_bdt_devices', compact('devices','filters'));
- }
- public function memos(Request $request){
- $filters = $request->all();
- $memos = ClientMemo::select('client_memo.*')
- ->join('client', 'client.id', '=', 'client_memo.client_id');
- if($this->performer->pro->pro_type !== 'ADMIN'){
- $memos = $memos->where('client.mcp_pro_id', $this->performer->pro->id);
- }
- $this->filterMultiQuery($request, $memos, 'client_memo.created_at', 'date_category', 'date_value_1', 'date_value_2');
- $this->filterSimpleQuery($request, $memos, 'category', 'category');
- $memos = $memos->orderBy('created_at', 'DESC')->paginate(20);
- return view('app.practice-management.memos', compact('memos', 'filters'));
- }
- public function segmentTemplates(Request $request){
- $segmentTemplates = SegmentTemplate::query();
- $segmentTemplates = $segmentTemplates->orderBy('created_at', 'DESC');
-
- $responseType = $request->get('response_type');
- if($responseType && $responseType == 'json'){
- $segmentTemplates = $segmentTemplates->where('is_active', true)->get();
- return $this->pass($segmentTemplates);
- }
- $segmentTemplates = $segmentTemplates->paginate(30);
- return view('app.practice-management.segment-templates.index', compact('segmentTemplates'));
- }
- public function visitTemplates(Request $request){
- $visitTemplates = VisitTemplate::query();
- $visitTemplates = $visitTemplates->orderBy('created_at', 'DESC');
- $responseType = $request->get('response_type');
- if($responseType && $responseType == 'json'){
- $visitTemplates = $visitTemplates->where('is_active', true)->get();
- return $this->pass($visitTemplates);
- }
- $visitTemplates = $visitTemplates->paginate(30);
- return view('app.practice-management.visit-templates.index', compact('visitTemplates'));
- }
- public function visitTemplate(Request $request, VisitTemplate $visitTemplate){
- $visitTemplateSegmentTemplates = VisitTemplateSegmentTemplate::query();
- $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->where('visit_template_id', $visitTemplate->id);
- $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->orderBy('position_index', 'ASC');
- $visitTemplateSegmentTemplates = $visitTemplateSegmentTemplates->paginate(50);
- return view('app.practice-management.visit-templates.visit-template-segment-templates.index', compact('visitTemplate','visitTemplateSegmentTemplates'));
- }
- public function visitTemplateAccess(Request $request, VisitTemplate $visitTemplate){
- $visitTemplateAccesses = VisitTemplateAccess::where('visit_template_id', $visitTemplate->id)->paginate(50);
- return view('app.practice-management.visit-templates.visit-template-accesses.index', compact('visitTemplate','visitTemplateAccesses'));
- }
- public function clientCcmRmStatus(Request $request){
- $filters = $request->all();
- $patients = Client::whereNull('shadow_pro_id');
- $pro = $this->performer()->pro;
- if($pro->pro_type !== 'ADMIN') {
- $patients = $patients->where('mcp_pro_id', $this->performer()->pro->id);
- }
- // filters
- /*
- array:18 [▼
- "age_category" => "LESS_THAN"
- "age_value_1" => "34"
- "age_value_2" => null
- "sex" => "M"
- "bmi_category" => "BETWEEN"
- "bmi_value_1" => "20"
- "bmi_value_2" => "25"
- "last_visit_category" => "LESS_THAN"
- "last_visit_value_1" => "2021-10-14"
- "last_visit_value_2" => null
- "next_appointment_category" => "LESS_THAN"
- "next_appointment_value_1" => "2021-10-15"
- "status" => "ACTIVE"
- "last_weighed_in_category" => "EXACTLY"
- "last_weighed_in_value_1" => "2021-10-07"
- "last_bp_category" => "BETWEEN"
- "last_bp_value_1" => "2021-10-01"
- "last_bp_value_2" => "2021-10-31"
- ]
- */
- $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
- $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
- $this->filterMultiQuery($request, $patients, 'usual_bmi', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
- $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
- $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
- switch($request->input('status')) {
- case 'ACTIVE':
- $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
- break;
- case 'AWAITING_VISIT':
- $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
- break;
- case 'INACTIVE':
- $patients->where('is_active', '<>', true);
- break;
- }
- if($request->input('is_eligible_for_cm')){
- $patients->where('is_eligible_for_cm', '=', $request->input('is_eligible_for_cm'));
- }
- if($request->input('is_enrolled_in_cm')){
- $patients->where('is_enrolled_in_cm', '=', $request->input('is_enrolled_in_cm'));
- }
- if($request->input('has_cm_setup_been_performed')){
- $patients->where('has_cm_setup_been_performed', '=', $request->input('has_cm_setup_been_performed')=='YES'? true : false);
- }
- if($request->input('is_eligible_for_rm')){
- $patients->where('is_eligible_for_rm', '=', $request->input('is_eligible_for_rm'));
- }
- if($request->input('is_enrolled_in_rm')){
- $patients->where('is_enrolled_in_rm', '=', $request->input('is_enrolled_in_rm'));
- }
- if($request->input('has_rm_setup_been_performed')){
- $patients->where('has_rm_setup_been_performed', '=', $request->input('has_rm_setup_been_performed') =='YES'? true : false);
- }
- $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
- return view('app.admin.client-ccm-rm-status', compact('patients', 'filters'));
- }
- public function rmActionReport(Request $request){
- $filters = $request->all();
-
- $careMonthStartDate = $request->get('care_month_start_date');
- $careMonthYear = $request->get('care_month_year');
-
- if(!$careMonthStartDate){
- $careMonthStartDate = '2022-01-01';
- }
- if($careMonthYear){
- $careMonthStartDate = $careMonthYear . "-01";
- }
- $lastDateOfMonth = new DateTime(date("Y-m-t", strtotime(get_current_date())));
- $today = new DateTime(get_current_date());
- $diff = $lastDateOfMonth->diff($today);
- $daysBetweenNowAndEndmonth = $diff->days;
- $minRequiredMeasurements = 16 - $daysBetweenNowAndEndmonth -1;
- $numOfMeasurements = $request->get('num_of_measurements'); //16_or_more, 12_or_more
- $hasRecentVisit = $request->get('has_recent_visit'); //yes no
- $hasBeenSpokenToThisMonth = $request->get('has_been_spoken_to'); //yes no
- $cmQuery = CareMonth::where('start_date', $careMonthStartDate);
- //remove dummies
- $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
- return $clientQuery->where('client_engagement_status_category','<>', 'DUMMY')
- ->orWhere('client_engagement_status_category', '=', null);
- });
- if($numOfMeasurements){
- if($numOfMeasurements == '16_or_more'){
- $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '>=', 16);
- }
- if($numOfMeasurements == 'min_or_more'){
- $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '>=', $minRequiredMeasurements)
- ->where('number_of_days_with_remote_measurements', '<', 16);
- }
- if($numOfMeasurements == 'less_than_min'){
- $cmQuery = $cmQuery->where('number_of_days_with_remote_measurements', '<', $minRequiredMeasurements);
- }
- }
- if($hasRecentVisit){
- if($hasRecentVisit == 'YES'){
- $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
- return $clientQuery->whereRaw("most_recent_completed_mcp_note_date::DATE >= ((NOW() - interval '90 days')::DATE)");
- });
- }else{
- $cmQuery = $cmQuery->whereHas('client', function($clientQuery) {
- return $clientQuery->whereRaw("most_recent_completed_mcp_note_date::DATE < ((NOW() - interval '90 days')::DATE)");
- });
- }
- }
- if($hasBeenSpokenToThisMonth){
- if($hasBeenSpokenToThisMonth == 'YES'){
- $cmQuery = $cmQuery->where('has_anyone_interacted_with_client_about_rm_outside_note', '=', true);
- }else{
- $cmQuery = $cmQuery->where('has_anyone_interacted_with_client_about_rm_outside_note', '=', false);
- }
-
- }
- $claimingClosed = $request->get('claiming_closed');
- if($claimingClosed){
- if($claimingClosed === 'YES') $cmQuery = $cmQuery->where('is_claim_closed', true);
- if($claimingClosed === 'NO') $cmQuery = $cmQuery->where('is_claim_closed', false);
- }
- $cmQuery = $cmQuery->orderBy('start_date', 'DESC')->orderBy('client_id', 'ASC');
- $rows =$cmQuery->paginate(15);
- return view('app.practice-management.rm-action-report', compact('rows', 'filters', 'minRequiredMeasurements'));
- }
- public function myFlyers(Request $request){
- $pro = $this->performer->pro;
- $slug = $pro->slug ?? $pro->uid;
- $url = config('app.stagfe6_url') . '/flyers/json-list?slug=' . $slug;
- $arrContextOptions=array(
- "ssl"=>array(
- "verify_peer"=>false,
- "verify_peer_name"=>false,
- ),
- );
- $response = @file_get_contents($url, false, stream_context_create($arrContextOptions));
- $response = @json_decode($response);
- $flyerTemplates = [];
- if(isset($response->data)){
- $flyerTemplates = $response->data;
- }
- return view('app.my-flyers', compact('pro','flyerTemplates'));
- }
-
- }
|