123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\AppSession;
- use App\Models\BillingReport;
- use App\Models\CareMonth;
- use App\Models\ClaimEDI;
- 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 Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Http;
- use PDF;
- use DateTime;
- use DateTimeZone;
- use Illuminate\Http\Request;
- 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);
- if(!$isAdmin) $query->where('mcp_pro_id', '=', $proID);
- $rows = $query->orderByRaw(DB::raw('start_date DESC'))->paginate(50) ;
- return view ('app.practice-management.remote-monitoring-report', compact('rows', 'isAdmin'));
- }
- public function billingReport(Request $request)
- {
- $rows = BillingReport::paginate(50);
- return view('app.practice-management.billing-report', compact('rows'));
- }
- 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')->get();
- return view('app.practice-management.notes', compact('notes', 'filter'));
- }
- 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);
- });
- });
- 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
- ->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('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('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 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_last')
- ->orderBy('name_first')
- ->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::all();
- $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();
- $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
- $careMonthStart = date($ym . '-01');
- // filters
- $filters = '';
- $fmd = $request->input('fmd');
- if($fmd && $fmd !== 'all') {
- switch($fmd) {
- case 'lt16':
- $filters .= ' AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL) ';
- break;
- case 'gte16':
- $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
- break;
- }
- }
- $fcomm = $request->input('fcomm');
- if($fcomm && $fcomm !== 'all') {
- switch($fcomm) {
- case 'not-done':
- $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL) ';
- break;
- case 'done':
- $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL) ';
- break;
- }
- }
- $c = $request->input('c');
- if($c) {
- $filters .= ' AND client.uid = \'' . $request->input('c') . '\' ';
- }
- $patients = DB::select(
- DB::raw(
- "
- SELECT client.name_first, client.name_last, client.uid as client_uid,
- care_month.uid as care_month_uid,
- care_month.id as care_month_id,
- care_month.start_date,
- care_month.number_of_days_with_remote_measurements,
- care_month.has_anyone_interacted_with_client_about_rm_outside_note,
- 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,
- client.mcp_pro_id,
- client.default_na_pro_id,
- client.rmm_pro_id,
- client.rme_pro_id,
- client.cell_number
- FROM care_month join client on care_month.client_id = client.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())') . "
- {$filters}
- ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first ASC, client.name_last ASC
- "
- )
- );
- $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 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.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,
- -- 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)->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.*')
- ->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.created_at', 'date_category', 'date_value_1', 'date_value_2');
- $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('created_at', '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'));
- }
- }
|