Pro.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. use App\Helpers\TimeLine;
  5. use DateTime;
  6. use Exception;
  7. use Illuminate\Support\Facades\DB;
  8. class Pro extends Model
  9. {
  10. protected $table = 'pro';
  11. public function displayName() {
  12. $name = [];
  13. if(!empty($this->name_display)) return $this->name_display;
  14. if(!empty($this->name_last)) $name[] = $this->name_last;
  15. if(!empty($this->name_first)) $name[] = $this->name_first;
  16. if(!count($name)) {
  17. $name = $this->name_display;
  18. }
  19. else {
  20. $name = implode(", ", $name);
  21. }
  22. return $name;
  23. }
  24. public function initials() {
  25. $characters = [];
  26. if(!empty($this->name_first)) $characters[] = $this->name_first[0];
  27. if(!empty($this->name_last)) $characters[] = $this->name_last[0];
  28. return strtolower(implode("", $characters));
  29. }
  30. public function debitBills()
  31. {
  32. return $this->hasMany(Bill::class, 'debit_pro_id');
  33. }
  34. public function cmBills()
  35. {
  36. return $this->hasMany(Bill::class, 'cm_pro_id');
  37. }
  38. public function hcpBills()
  39. {
  40. return $this->hasMany(Bill::class, 'hcp_pro_id');
  41. }
  42. public function teamsWhereAssistant()
  43. {
  44. return $this->hasMany(ProTeam::class, 'assistant_pro_id', 'id');
  45. }
  46. public function isDefaultNA()
  47. {
  48. // TODO are we using this?
  49. return true; // $this->is_considered_for_dna;
  50. }
  51. public function lastPayment() {
  52. return ProTransaction
  53. ::where('pro_id', $this->id)
  54. ->where('plus_or_minus', 'PLUS')
  55. ->orderBy('created_at', 'desc')
  56. ->first();
  57. }
  58. public function hasRates() {
  59. $numRates = ProRate::where('is_active', true)->where('pro_id', $this->id)->count();
  60. return $numRates > 0;
  61. }
  62. public function cmRates() {
  63. return ProRate::distinct('code')
  64. ->where('is_active', true)
  65. ->where('pro_id', $this->id)
  66. ->where('code', 'LIKE', 'CM%')
  67. ->get();
  68. }
  69. public function rmRates() {
  70. return ProRate::distinct('code')
  71. ->where('is_active', true)
  72. ->where('pro_id', $this->id)
  73. ->where('code', 'LIKE', 'RM%')
  74. ->get();
  75. }
  76. public function noteRates() {
  77. return ProRate::distinct('code')
  78. ->where('is_active', true)
  79. ->where('pro_id', $this->id)
  80. ->where('code', 'NOT LIKE', 'CM%')
  81. ->where('code', 'NOT LIKE', 'RM%')
  82. ->where('responsibility', '<>', 'GENERIC')
  83. ->get();
  84. }
  85. public function genericRates() {
  86. return ProRate::distinct('code')
  87. ->where('is_active', true)
  88. ->where('pro_id', $this->id)
  89. ->where('responsibility', 'GENERIC')
  90. ->get();
  91. }
  92. public function recentDebits() {
  93. return ProTransaction
  94. ::where('pro_id', $this->id)
  95. ->where('plus_or_minus', 'PLUS')
  96. ->orderBy('created_at', 'desc')
  97. ->skip(0)->take(4)->get();
  98. }
  99. public function shortcuts() {
  100. return $this->hasMany(ProTextShortcut::class, 'pro_id')->where('is_removed', false);
  101. }
  102. public function allShortcuts() {
  103. $myId = $this->id;
  104. $shortcuts = ProTextShortcut::where('is_removed', false)
  105. ->where(function ($query2) use ($myId) {
  106. $query2
  107. ->where('pro_id', $myId)
  108. ->orWhereNull('pro_id');
  109. })
  110. ->orderBy('shortcut')
  111. ->get();
  112. return $shortcuts;
  113. }
  114. public function noteTemplates() {
  115. return $this->hasMany(NoteTemplatePro::class, 'pro_id')
  116. ->where('is_removed', false)
  117. ->orderBy('position_index', 'asc');
  118. }
  119. public function visitTemplates() {
  120. //TODO: use visit access
  121. return VisitTemplate::all();
  122. }
  123. public function currentWork() {
  124. return ProClientWork::where('pro_id', $this->id)->where('is_active', true)->first();
  125. }
  126. public function isWorkingOnClient($_client) {
  127. $count = ProClientWork::where('pro_id', $this->id)->where('client_id', $_client->id)->where('is_active', true)->count();
  128. return $count > 0;
  129. }
  130. public function canvasCustomItems($_key) {
  131. return ClientCanvasDataCustomItem::where('key', $_key)
  132. ->where('pro_id', $this->id)
  133. ->orderBy('label')
  134. ->get();
  135. }
  136. /**
  137. * @param $_start - YYYY-MM-DD
  138. * @param $_end - YYYY-MM-DD
  139. * @param string $_timezone - defaults to EASTERN
  140. * @param string $_availableBG - defaults to #00a
  141. * @param string $_unavailableBG - defaults to #a00
  142. * @return array
  143. * @throws Exception
  144. */
  145. public function getAvailabilityEvents($_start, $_end, $_timezone = 'EASTERN', $_availableBG = '#00a', $_unavailableBG = '#a00') {
  146. $_start .= ' 00:00:00';
  147. $_end .= ' 23:59:59';
  148. // get availability data
  149. $proGenAvail = ProGeneralAvailability
  150. ::where('is_cancelled', false)
  151. ->where('pro_id', $this->id)
  152. ->get();
  153. $proSpecAvail = ProSpecificAvailability
  154. ::where('is_cancelled', false)
  155. ->where('pro_id', $this->id)
  156. ->where(function ($query) use ($_start, $_end) {
  157. $query
  158. ->where(function ($query2) use ($_start, $_end) {
  159. $query2
  160. ->where('start_time', '>=', $_start)
  161. ->where('start_time', '<=', $_end);
  162. })
  163. ->orWhere(function ($query2) use ($_start, $_end) {
  164. $query2
  165. ->where('end_time', '>=', $_start)
  166. ->where('end_time', '<=', $_end);
  167. });
  168. })
  169. ->get();
  170. $proSpecUnavail = ProSpecificUnavailability
  171. ::where('is_cancelled', false)
  172. ->where('pro_id', $this->id)
  173. ->where(function ($query) use ($_start, $_end) {
  174. $query
  175. ->where(function ($query2) use ($_start, $_end) {
  176. $query2
  177. ->where('start_time', '>=', $_start)
  178. ->where('start_time', '<=', $_end);
  179. })
  180. ->orWhere(function ($query2) use ($_start, $_end) {
  181. $query2
  182. ->where('end_time', '>=', $_start)
  183. ->where('end_time', '<=', $_end);
  184. });
  185. })
  186. ->get();
  187. // default GA
  188. // if no gen avail, assume mon to fri, 9 to 7
  189. /*if (count($proGenAvail) === 0) {
  190. $dayNames = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'];
  191. foreach ($dayNames as $dayName) {
  192. $item = new \stdClass();
  193. $item->day_of_week = $dayName;
  194. $item->timezone = $_timezone;
  195. $item->start_time = '09:00:00';
  196. $item->end_time = '18:00:00';
  197. $proGenAvail->push($item);
  198. }
  199. }*/
  200. // create timeline
  201. $phpTZ = appTZtoPHPTZ($_timezone);
  202. $phpTZObject = new \DateTimeZone($phpTZ);
  203. $startDate = new \DateTime($_start, $phpTZObject);
  204. $endDate = new \DateTime($_end, $phpTZObject);
  205. $proTimeLine = new TimeLine($startDate, $endDate);
  206. // General availability
  207. $period = new \DatePeriod($startDate, \DateInterval::createFromDateString('1 day'), $endDate);
  208. $days = [];
  209. foreach ($period as $day) {
  210. $days[] = [
  211. "day" => strtoupper($day->format("l")), // SUNDAY, etc.
  212. "date" => $day->format("Y-m-d"), // 2020-10-04, etc.
  213. ];
  214. }
  215. foreach ($days as $day) {
  216. $proGenAvailForTheDay = $proGenAvail->filter(function ($record) use ($day) {
  217. return $record->day_of_week === $day["day"];
  218. });
  219. foreach ($proGenAvailForTheDay as $ga) {
  220. $gaStart = new \DateTime($day["date"], new \DateTimeZone(appTZtoPHPTZ($ga->timezone)));
  221. $parts = explode(":", $ga->start_time);
  222. $gaStart->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
  223. $gaStart->setTimezone($phpTZObject);
  224. $gaEnd = new \DateTime($day["date"], new \DateTimeZone(appTZtoPHPTZ($ga->timezone)));
  225. $parts = explode(":", $ga->end_time);
  226. $gaEnd->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
  227. $gaEnd->setTimezone($phpTZObject);
  228. $proTimeLine->addAvailability($gaStart, $gaEnd);
  229. }
  230. }
  231. // specific availability
  232. foreach ($proSpecAvail as $sa) {
  233. $saStart = new \DateTime($sa->start_time, new \DateTimeZone(appTZtoPHPTZ($sa->timezone)));
  234. $saStart->setTimezone($phpTZObject);
  235. $saEnd = new \DateTime($sa->end_time, new \DateTimeZone(appTZtoPHPTZ($sa->timezone)));
  236. $saEnd->setTimezone($phpTZObject);
  237. $proTimeLine->addAvailability($saStart, $saEnd);
  238. }
  239. // specific unavailability
  240. foreach ($proSpecUnavail as $sua) {
  241. $suaStart = new \DateTime($sua->start_time, new \DateTimeZone(appTZtoPHPTZ($sua->timezone)));
  242. $suaStart->setTimezone($phpTZObject);
  243. $suaEnd = new \DateTime($sua->end_time, new \DateTimeZone(appTZtoPHPTZ($sua->timezone)));
  244. $suaEnd->setTimezone($phpTZObject);
  245. $proTimeLine->removeAvailability($suaStart, $suaEnd);
  246. }
  247. $events = [];
  248. // availability
  249. foreach ($proTimeLine->getAvailable() as $item) {
  250. $eStart = new \DateTime('@' . $item->start);
  251. $eStart->setTimezone($phpTZObject);
  252. $eEnd = new \DateTime('@' . $item->end);
  253. $eEnd->setTimezone($phpTZObject);
  254. $events[] = [
  255. "type" => "availability",
  256. "start" => $eStart->format('Y-m-d H:i:s'),
  257. "end" => $eEnd->format('Y-m-d H:i:s'),
  258. "editable" => false,
  259. "backgroundColor" => $_availableBG
  260. ];
  261. }
  262. // unavailability
  263. foreach ($proTimeLine->getUnavailable() as $item) {
  264. $eStart = new \DateTime('@' . $item->start);
  265. $eStart->setTimezone($phpTZObject);
  266. $eEnd = new \DateTime('@' . $item->end);
  267. $eEnd->setTimezone($phpTZObject);
  268. $events[] = [
  269. "type" => "unavailability",
  270. "start" => $eStart->format('Y-m-d H:i:s'),
  271. "end" => $eEnd->format('Y-m-d H:i:s'),
  272. "editable" => false,
  273. "backgroundColor" => $_unavailableBG
  274. ];
  275. }
  276. return $events;
  277. }
  278. public function getMyClientIds($_search = false) {
  279. $clients = $this->getAccessibleClientsQuery($_search)->get();
  280. $clientIds = [];
  281. foreach($clients as $client){
  282. $clientIds[] = $client->id;
  283. }
  284. return $clientIds;
  285. }
  286. public function favoritesByCategory($_category) {
  287. return ProFavorite::where('pro_id', $this->id)
  288. ->where('is_removed', false)
  289. ->where('category', $_category)
  290. ->orderBy('category', 'asc')
  291. ->orderBy('position_index', 'asc')
  292. ->get();
  293. }
  294. function get_patients_count_as_mcp() {
  295. $query = Client::whereNull('shadow_pro_id');
  296. return $query->where('mcp_pro_id', $this->id)->count();
  297. }
  298. function get_new_patients_awaiting_visit_count_as_mcp() {
  299. $query = Client::whereNull('shadow_pro_id');
  300. return $query->where('mcp_pro_id', $this->id)
  301. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  302. ->count();
  303. }
  304. function get_notes_pending_signature_count_as_mcp() {
  305. return Note::where('hcp_pro_id', $this->id)
  306. ->where('is_cancelled', '<>', true)
  307. ->where('is_core_note', '<>', true)
  308. ->where('is_signed_by_hcp', '<>', true)
  309. ->count();
  310. }
  311. function get_notes_pending_billing_count_as_mcp() {
  312. return Note::where('hcp_pro_id', $this->id)
  313. ->where('is_cancelled', '<>', true)
  314. ->where('is_signed_by_hcp', true)
  315. ->where('is_billing_marked_done', '<>', true)
  316. ->count();
  317. }
  318. function get_measurements_awaiting_review_count_as_mcp() {
  319. $result = DB::select(DB::raw("
  320. SELECT SUM(rm_num_measurements_not_stamped_by_mcp) AS count
  321. FROM care_month
  322. WHERE mcp_pro_id = :pro_id
  323. AND rm_num_measurements_not_stamped_by_mcp IS NOT NULL
  324. AND rm_num_measurements_not_stamped_by_mcp > 0;
  325. "), ["pro_id" => $this->id]);
  326. if($result) return $result[0]->count;
  327. }
  328. function get_bills_pending_signature_count_as_mcp(){
  329. $pendingBillsToSign = Bill::where('bill_service_type', '<>', 'CARE_MONTH')->where(function ($query) {
  330. $query->where('hcp_pro_id', $this->id)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  331. })
  332. ->orWhere(function ($query) {
  333. $query->where('cm_pro_id', $this->id)->where('is_signed_by_cm', false)->where('is_cancelled', false);
  334. })->orWhere(function ($query) {
  335. $query->where('rme_pro_id', $this->id)->where('is_signed_by_rme', false)->where('is_cancelled', false);
  336. })->orWhere(function ($query) {
  337. $query->where('rmm_pro_id', $this->id)->where('is_signed_by_rmm', false)->where('is_cancelled', false);
  338. })->orWhere(function ($query) {
  339. $query->where('generic_pro_id', $this->id)->where('is_signed_by_generic_pro', false)->where('is_cancelled', false);
  340. })->count();
  341. return $pendingBillsToSign;
  342. }
  343. function get_incoming_reports_pending_signature_count_as_mcp() {
  344. return IncomingReport::where('hcp_pro_id', $this->id)
  345. ->where('has_hcp_pro_signed', '<>', true)
  346. ->where('is_entry_error', '<>', true)
  347. ->count();
  348. }
  349. function get_patients_without_appointment_query() {
  350. return Client::where('mcp_pro_id', $this->id)
  351. ->whereNull('today_mcp_appointment_date')
  352. ->where(function($q){
  353. $q->whereNull('next_mcp_appointment_id')
  354. ->orWhere('next_mcp_appointment_date', '<=', DB::raw('NOW()::DATE'));
  355. });
  356. }
  357. function get_patients_without_appointment_for_dna_query() {
  358. return Client::where('default_na_pro_id', $this->id)
  359. ->whereNull('today_mcp_appointment_date')
  360. ->where(function($q){
  361. $q->whereNull('next_mcp_appointment_id')
  362. ->orWhere('next_mcp_appointment_date', '<=', DB::raw('NOW()::DATE'));
  363. });
  364. }
  365. function get_patients_without_appointment_count_as_mcp() {
  366. return $this->get_patients_without_appointment_query()->count();
  367. }
  368. function get_patients_overdue_for_visit_query() {
  369. return Client::where('mcp_pro_id', $this->id)
  370. ->where(function($q){
  371. $q->whereNull('most_recent_completed_mcp_note_id')
  372. ->orWhere('most_recent_completed_mcp_note_date', '<', DB::raw("NOW()::DATE - INTERVAL '45 DAY'"));
  373. });
  374. }
  375. function get_patients_overdue_for_visit_for_dna_query() {
  376. return Client::where('default_na_pro_id', $this->id)
  377. ->where(function($q){
  378. $q->whereNull('most_recent_completed_mcp_note_id')
  379. ->orWhere('most_recent_completed_mcp_note_date', '<', DB::raw("NOW()::DATE - INTERVAL '45 DAY'"));
  380. });
  381. }
  382. function get_patients_overdue_count_as_mcp() {
  383. return $this->get_patients_overdue_for_visit_query()->count();
  384. }
  385. function get_patients_without_remote_measurement_in_48_hours_count_as_mcp() {
  386. return DB::select("SELECT COUNT(*) as count FROM client WHERE ((most_recent_cellular_measurement_at+ interval '48 hour')::timestamp < NOW() OR most_recent_cellular_measurement_id IS NULL) AND client.mcp_pro_id = :mcp_pro_id AND is_active IS TRUE", ['mcp_pro_id'=>$this->id])[0]->count;
  387. }
  388. function get_cancelled_appointments_pending_acknowledgement_count_as_mcp_query() {
  389. // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  390. return Appointment::where('pro_id', $this->id)
  391. ->where('latest_confirmation_decision_enum', 'REJECTED')
  392. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true);
  393. }
  394. function get_cancelled_appointments_pending_acknowledgement_count_as_mcp() {
  395. // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  396. return $this->get_cancelled_appointments_pending_acknowledgement_count_as_mcp_query()->count();
  397. }
  398. function get_cancelled_bills_awaiting_review_count_as_mcp() {
  399. // SELECT * FROM bill WHERE bill_service_type = 'NOTE' AND is_cancelled IS TRUE AND isCancellationAcknowledged IS FALSE;
  400. return Bill::where('hcp_pro_id', $this->id)
  401. ->where('bill_service_type', 'NOTE')
  402. ->where('is_cancelled', true)
  403. ->where('is_cancellation_acknowledged', '<>', true)
  404. ->count();
  405. }
  406. function get_cancelled_supply_orders_awaiting_review_count_as_mcp() {
  407. // SELECT * FROM supply_order WHERE signed_by_pro_id = :me.id AND is_cancelled IS TRUE AND isCancellationAcknowledged IS NOT TRUE;
  408. return SupplyOrder::where('signed_by_pro_id', $this->id)
  409. ->where('is_cancelled', true)
  410. ->where('is_cancellation_acknowledged', '<>', true)
  411. ->count();
  412. }
  413. function get_erx_and_orders_awaiting_signature_count_as_mcp() {
  414. // SELECT * FROM erx WHERE hcp_pro_id = :me.id AND pro_declared_status <> 'CANCELLED' AND hasHcpProSigned IS NOT TRUE;
  415. return Erx::where('hcp_pro_id', $this->id)
  416. ->where('pro_declared_status', '<>', 'CANCELLED')
  417. ->where('has_hcp_pro_signed', '<>', true)
  418. ->count();
  419. }
  420. function get_supply_orders_awaiting_signature_count_as_mcp() {
  421. // SELECT supply_order.id FROM supply_order WHERE signed_by_pro_id IS NOT TRUE AND is_cancelled IS NOT TRUE AND created_by_pro_id = :me.id;
  422. return SupplyOrder::where('created_by_pro_id', $this->id)
  423. ->whereNull('signed_by_pro_id')
  424. ->where('is_cancelled', '<>', true)
  425. ->count();
  426. }
  427. function get_supply_orders_awaiting_shipment_count_as_mcp() {
  428. return SupplyOrder::where('created_by_pro_id', $this->id)
  429. ->where('is_signed_by_pro', true)
  430. ->where('is_cleared_for_shipment', true)
  431. ->whereNull('shipment_id')
  432. ->count();
  433. }
  434. function get_birthdays_today_as_mcp(){
  435. return;
  436. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  437. $keyNumbers['patientsHavingBirthdayToday'] = $queryClients
  438. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  439. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')])
  440. ->count();
  441. $reimbursement = [];
  442. $reimbursement["currentBalance"] = $performer->pro->balance;
  443. $reimbursement["nextPaymentDate"] = '--';
  444. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  445. if ($lastPayment) {
  446. $reimbursement["lastPayment"] = $lastPayment->amount;
  447. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  448. } else {
  449. $reimbursement["lastPayment"] = '--';
  450. $reimbursement["lastPaymentDate"] = '--';
  451. }
  452. }
  453. public function getAppointmentsPendingStatusChangeAck() {
  454. return Appointment::where('pro_id', $this->id)
  455. ->where('is_status_acknowledgement_from_appointment_pro_pending', true)
  456. ->where('raw_date', '>=', DB::raw('NOW()'))
  457. ->orderBy('raw_date', 'asc')
  458. ->get();
  459. }
  460. public function getAppointmentsPendingDecisionAck() {
  461. return Appointment::where('pro_id', $this->id)
  462. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true)
  463. ->where('raw_date', '>=', DB::raw('NOW()'))
  464. ->orderBy('raw_date', 'asc')
  465. ->get();
  466. }
  467. public function getAppointmentsPendingTimeChangeAck() {
  468. return Appointment::where('pro_id', $this->id)
  469. ->where('is_time_change_acknowledgement_from_appointment_pro_pending', true)
  470. ->where('raw_date', '>=', DB::raw('NOW()'))
  471. ->orderBy('raw_date', 'asc')
  472. ->get();
  473. }
  474. public function getAccessibleClientsQuery($_search = false) {
  475. $proID = $this->id;
  476. $query = Client::whereNull('shadow_pro_id');
  477. if ($this->pro_type === 'ADMIN' && ($_search ? $this->can_see_any_client_via_search : $this->can_see_all_clients_in_list)) {
  478. $query = $query->where('id', '>', 0);
  479. } else {
  480. $query = $query->where(function ($q) use ($proID) {
  481. $q->where('mcp_pro_id', $proID)
  482. ->orWhere('cm_pro_id', $proID)
  483. ->orWhere('rmm_pro_id', $proID)
  484. ->orWhere('rme_pro_id', $proID)
  485. ->orWhere('physician_pro_id', $proID)
  486. ->orWhere('default_na_pro_id', $proID)
  487. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
  488. ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE status NOT IN (\'CANCELLED\') AND pro_id = ?)', [$proID])
  489. ->orWhereRaw('id IN (SELECT mcp_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  490. ->orWhereRaw('id IN (SELECT manager_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  491. ->orWhereRaw('id IN (SELECT client_id FROM note WHERE ally_pro_id = ? AND is_cancelled = FALSE)', [$proID]);;
  492. });
  493. }
  494. return $query;
  495. }
  496. public function canAccess($_patientUid) {
  497. $proID = $this->id;
  498. if ($this->pro_type === 'ADMIN') {
  499. return true;
  500. }
  501. $canAccess = Client::select('uid')
  502. ->where('uid', $_patientUid)
  503. ->where(function ($q) use ($proID) {
  504. $q->where('mcp_pro_id', $proID)
  505. ->orWhere('cm_pro_id', $proID)
  506. ->orWhere('rmm_pro_id', $proID)
  507. ->orWhere('rme_pro_id', $proID)
  508. ->orWhere('physician_pro_id', $proID)
  509. ->orWhere('default_na_pro_id', $proID)
  510. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
  511. ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE status NOT IN (\'CANCELLED\') AND pro_id = ?)', [$proID])
  512. ->orWhereRaw('id IN (SELECT mcp_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  513. ->orWhereRaw('id IN (SELECT manager_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  514. ->orWhereRaw('id IN (SELECT client_id FROM note WHERE ally_pro_id = ? AND is_cancelled = FALSE)', [$proID]);
  515. })->count();
  516. return !!$canAccess;
  517. }
  518. public function canAddCPMEntryForMeasurement(Measurement $measurement, Pro $pro)
  519. {
  520. // check if client has any programs where this measurement type is allowed
  521. $allowed = false;
  522. $client = $measurement->client;
  523. $clientPrograms = $client->clientPrograms;
  524. if($pro->pro_type !== 'ADMIN') {
  525. $clientPrograms = $clientPrograms->filter(function($_clientProgram) use ($pro) {
  526. return $_clientProgram->manager_pro_id === $pro->id;
  527. });
  528. }
  529. if(count($clientPrograms)) {
  530. foreach ($clientPrograms as $clientProgram) {
  531. if(strpos(strtolower($clientProgram->measurement_labels), '|' . strtolower($measurement->label) . '|') !== FALSE) {
  532. $allowed = true;
  533. break;
  534. }
  535. }
  536. }
  537. return $allowed ? $clientPrograms : FALSE;
  538. }
  539. public function getUnstampedMeasurementsFromCurrentMonth($_countOnly, $skip, $limit)
  540. {
  541. date_default_timezone_set('US/Eastern');
  542. $start = strtotime(date('Y-m-01'));
  543. $end = date_add(date_create(date('Y-m-01')), date_interval_create_from_date_string("1 month"))->getTimestamp();
  544. $start *= 1000;
  545. $end *= 1000;
  546. $measurementsQuery = Measurement::where('is_active', true)
  547. ->join('client', 'client.id', '=', 'measurement.client_id')
  548. ->whereNotNull('measurement.client_bdt_measurement_id')
  549. ->whereNotNull('measurement.ts')
  550. ->where('measurement.is_cellular_zero', false)
  551. ->where('measurement.ts', '>=', $start)
  552. ->where('measurement.ts', '<', $end)
  553. ->whereIn('measurement.client_id', $this->getMyClientIds())
  554. ->where(function ($q) {
  555. $q
  556. ->where(function ($q2) {
  557. $q2
  558. ->where('client.mcp_pro_id', $this->id)
  559. ->where('measurement.has_been_stamped_by_mcp', false);
  560. })
  561. ->orWhere(function ($q2) {
  562. $q2
  563. ->where('client.default_na_pro_id', $this->id)
  564. ->where('measurement.has_been_stamped_by_non_hcp', false);
  565. })
  566. ->orWhere(function ($q2) {
  567. $q2
  568. ->where('client.rmm_pro_id', $this->id)
  569. ->where('measurement.has_been_stamped_by_rmm', false);
  570. })
  571. ->orWhere(function ($q2) {
  572. $q2
  573. ->where('client.rme_pro_id', $this->id)
  574. ->where('measurement.has_been_stamped_by_rme', false);
  575. });
  576. });
  577. if($_countOnly) {
  578. return $measurementsQuery->count();
  579. }
  580. $x = [];
  581. $measurements = $measurementsQuery
  582. ->orderBy('ts', 'desc')
  583. ->skip($skip)
  584. ->take($limit)
  585. ->get();
  586. // eager load stuff needed in JS
  587. foreach ($measurements as $measurement) {
  588. // if ($measurement->client_bdt_measurement_id) {
  589. // $measurement->bdtMeasurement = $measurement->clientBDTMeasurement->measurement;
  590. // }
  591. unset($measurement->clientBDTMeasurement); // we do not need this travelling to the frontend
  592. $client = [
  593. "uid" => $measurement->client->uid,
  594. "name" => $measurement->client->displayName(),
  595. ];
  596. $measurement->patient = $client;
  597. $measurement->careMonth = $measurement->client->currentCareMonth();
  598. $measurement->timestamp = friendlier_date_time($measurement->created_at);
  599. unset($measurement->client); // we do not need this travelling to the frontend
  600. if(@$measurement->detail_json) unset($measurement->detail_json);
  601. if(@$measurement->canvas_data) unset($measurement->canvas_data);
  602. if(@$measurement->latest_measurements) unset($measurement->latest_measurements);
  603. if(@$measurement->info_lines) unset($measurement->info_lines);
  604. if(@$measurement->canvas_data_backup) unset($measurement->canvas_data_backup);
  605. if(@$measurement->migrated_canvas_data_backup) unset($measurement->migrated_canvas_data_backup);
  606. // if($measurement->label == 'SBP' || $measurement->label = 'DBP'){
  607. // continue;
  608. // }
  609. $x[] = $measurement;
  610. }
  611. // dd($measurements);
  612. return $measurements;
  613. }
  614. public function getMeasurements($_onlyUnstamped = true)
  615. {
  616. $measurementsQuery = Measurement::where('is_removed', false);
  617. if ($this->pro_type != 'ADMIN') {
  618. $measurementsQuery
  619. ->whereIn('client_id', $this->getMyClientIds());
  620. }
  621. if ($_onlyUnstamped) {
  622. $measurementsQuery
  623. ->whereNotNull('client_bdt_measurement_id')
  624. ->whereNotNull('ts')
  625. ->where('is_cellular_zero', false)
  626. ->where(function ($q) {
  627. $q->whereNull('status')
  628. ->orWhere(function ($q2) {
  629. $q2->where('status', '<>', 'ACK')
  630. ->where('status', '<>', 'INVALID_ACK');
  631. });
  632. });
  633. }
  634. $x = [];
  635. $measurements = $measurementsQuery->orderBy('ts', 'desc')->paginate(50);
  636. // eager load stuff needed in JS
  637. foreach ($measurements as $measurement) {
  638. // if ($measurement->client_bdt_measurement_id) {
  639. // $measurement->bdtMeasurement = $measurement->clientBDTMeasurement->measurement;
  640. // }
  641. unset($measurement->clientBDTMeasurement); // we do not need this travelling to the frontend
  642. $client = [
  643. "uid" => $measurement->client->uid,
  644. "name" => $measurement->client->displayName(),
  645. ];
  646. $measurement->patient = $client;
  647. $measurement->careMonth = $measurement->client->currentCareMonth();
  648. $measurement->timestamp = friendly_date_time($measurement->created_at);
  649. unset($measurement->client); // we do not need this travelling to the frontend
  650. // if($measurement->label == 'SBP' || $measurement->label = 'DBP'){
  651. // continue;
  652. // }
  653. $x[] = $measurement;
  654. }
  655. return $measurements;
  656. }
  657. public function companyPros()
  658. {
  659. return $this->hasMany(CompanyPro::class, 'pro_id', 'id')
  660. ->where('is_active', true);
  661. }
  662. public function companyProPayers()
  663. {
  664. return $this->hasMany(CompanyProPayer::class, 'pro_id', 'id');
  665. }
  666. public function isAssociatedWithMCPayer() {
  667. $companyProPayers = $this->companyProPayers;
  668. $foundMC = false;
  669. if($companyProPayers) {
  670. foreach ($companyProPayers as $companyProPayer) {
  671. if($companyProPayer->payer && $companyProPayer->payer->is_medicare) {
  672. $foundMC = true;
  673. break;
  674. }
  675. }
  676. }
  677. return $foundMC;
  678. }
  679. public function isAssociatedWithNonMCPayer($_payerID) {
  680. $companyProPayers = $this->companyProPayers;
  681. $foundNonMC = false;
  682. if($companyProPayers) {
  683. foreach ($companyProPayers as $companyProPayer) {
  684. if($companyProPayer->payer && !$companyProPayer->payer->is_medicare && $companyProPayer->payer->id === $_payerID) {
  685. $foundNonMC = true;
  686. break;
  687. }
  688. }
  689. }
  690. return $foundNonMC;
  691. }
  692. public function companyLocations() {
  693. $companyProPayers = $this->companyProPayers;
  694. $companyIDs = [];
  695. foreach ($companyProPayers as $companyProPayer) {
  696. $companyIDs[] = $companyProPayer->company_id;
  697. }
  698. $locations = [];
  699. if(count($companyIDs)) {
  700. $locations = CompanyLocation::whereIn('id', $companyIDs)->get();
  701. }
  702. return $locations;
  703. }
  704. public function shadowClient() {
  705. return $this->hasOne(Client::class, 'id', 'shadow_client_id');
  706. }
  707. public function defaultCompanyPro() {
  708. return $this->hasOne(CompanyPro::class, 'id', 'default_company_pro_id');
  709. }
  710. public function currentNotePickupForProcessing() {
  711. return $this->hasOne(NotePickupForProcessing::class, 'id', 'current_note_pickup_for_processing_id');
  712. }
  713. public function get_patients_not_seen_in_45_days_count_as_mcp(){
  714. return 0;
  715. }
  716. //DNA_DASHBOARD
  717. //queries
  718. private function patientsQueryAsDna(){
  719. // WHERE na_pro_id = :me.id
  720. return Client::where('default_na_pro_id', $this->id);
  721. }
  722. private function patientsAwaitingMcpVisitQueryAsDna(){
  723. // WHERE has_mcp_done_onboarding_visit <> 'YES'
  724. return Client::where('default_na_pro_id', $this->id)->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  725. }
  726. private function patientsWithoutAppointmentQueryAsDna(){
  727. // WHERE today_mcp_appointment_date IS NULL AND next_mcp_appointment_date IS NULL
  728. return Client::where('default_na_pro_id', $this->id)
  729. ->whereNull('today_mcp_appointment_date')
  730. ->whereNull('next_mcp_appointment_date');
  731. }
  732. private function encountersPendingMyReviewQueryAsDna(){
  733. // WHERE ally_pro_id = me.id AND is_cancelled IS NOT TRUE AND is_signed_by_hcp IS TRUE AND is_signed_by_ally IS NOT TRUE;
  734. return Note::where('ally_pro_id', $this->id)
  735. ->where('is_cancelled', '<>', true)
  736. ->where('is_signed_by_hcp', true)
  737. ->where('is_signed_by_ally','<>', true);
  738. }
  739. private function encountersInProgressQueryAsDna(){
  740. // SELECT * FROM note WHERE ally_pro_id = me.id AND is_cancelled IS NOT TRUE AND is_signed_by_hcp IS NOT TRUE ORDER BY effective_dateest DESC, created_at DESC;
  741. return Note::where('ally_pro_id', $this->id)
  742. ->where('is_cancelled', '<>', true)
  743. ->where('is_signed_by_hcp', '<>', true);
  744. }
  745. private function appointmentsPendingConfirmationQueryAsDna(){
  746. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND status = 'PENDING'
  747. $myId = $this->id;
  748. return Appointment::whereHas('client', function($clientQuery) use ($myId) {
  749. return $clientQuery->where('default_na_pro_id', $myId);
  750. })->where('status', 'PENDING');
  751. }
  752. private function cancelledAppointmentsPendingAckQueryAsDna(){
  753. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND status = 'CANCELLED' AND is_status_acknowledgement_from_default_na_pending IS TRUE;
  754. $myId = $this->id;
  755. return Appointment::whereHas('client', function($clientQuery) use ($myId) {
  756. return $clientQuery->where('default_na_pro_id', $myId);
  757. })->where('status', 'CANCELLED')
  758. ->where('is_status_acknowledgement_from_default_na_pending', true);
  759. }
  760. private function reportsPendingAckQueryAsDna(){
  761. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND has_na_pro_signed IS FALSE AND is_entry_error
  762. $myId = $this->id;
  763. return IncomingReport::whereHas('client',function($clientQuery) use ($myId) {
  764. return $clientQuery->where('default_na_pro_id', $myId);
  765. })->where('has_na_pro_signed', '<>', true)
  766. ->where('is_entry_error','<>', true);
  767. }
  768. private function supplyOrdersPendingMyAckQueryAsDna(){
  769. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND has_na_pro_signed IS FALSE AND is_signed_by_pro IS TRUE AND is_cancelled IS NOT TRUE;
  770. $myId = $this->id;
  771. return SupplyOrder::whereHas('client',function($clientQuery) use ($myId) {
  772. return $clientQuery->where('default_na_pro_id', $myId);
  773. })->where('has_na_pro_signed', '<>', true)
  774. ->where('is_signed_by_pro', true)
  775. ->where('is_cancelled', '<>', true);
  776. }
  777. private function supplyOrdersPendingHcpApprovalQueryAsDna(){
  778. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND has_na_pro_signed IS TRUE AND is_signed_by_pro IS NOT TRUE AND is_cancelled IS NOT TRUE;
  779. $myId = $this->id;
  780. return SupplyOrder::whereHas('client',function($clientQuery) use ($myId) {
  781. return $clientQuery->where('default_na_pro_id', $myId);
  782. })->where('has_na_pro_signed', true)
  783. ->where('is_signed_by_pro','<>', true)
  784. ->where('is_cancelled', '<>', true);
  785. }
  786. //counts
  787. public function patientsCountAsDna(){
  788. return $this->patientsQueryAsDna()->count();
  789. }
  790. public function patientsAwaitingMcpVisitCountAsDna(){
  791. return $this->patientsAwaitingMcpVisitQueryAsDna()->count();
  792. }
  793. public function patientsWithoutAppointmentCountAsDna(){
  794. return $this->patientsWithoutAppointmentQueryAsDna()->count();
  795. }
  796. public function encountersPendingMyReviewCountAsDna(){
  797. return $this->encountersPendingMyReviewQueryAsDna()->count();
  798. }
  799. public function encountersInProgressCountAsDna(){
  800. return $this->encountersInProgressQueryAsDna()->count();
  801. }
  802. public function appointmentsPendingConfirmationCountAsDna(){
  803. return $this->appointmentsPendingConfirmationQueryAsDna()->count();
  804. }
  805. public function cancelledAppointmentsPendingAckCountAsDna(){
  806. return $this->cancelledAppointmentsPendingAckQueryAsDna()->count();
  807. }
  808. public function reportsPendingAckCountAsDna(){
  809. return $this->reportsPendingAckQueryAsDna()->count();
  810. }
  811. public function supplyOrdersPendingMyAckCountAsDna(){
  812. return $this->supplyOrdersPendingMyAckQueryAsDna()->count();
  813. }
  814. public function supplyOrdersPendingHcpApprovalCountAsDna(){
  815. return $this->supplyOrdersPendingHcpApprovalQueryAsDna()->count();
  816. }
  817. //records
  818. private $DNA_RESULTS_PAGE_SIZE = 50;
  819. public function patientsRecordsAsDna(){
  820. return $this->patientsQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  821. }
  822. public function patientsAwaitingMcpVisitRecordsAsDna(){
  823. return $this->patientsAwaitingMcpVisitQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  824. }
  825. public function patientsWithoutAppointmentRecordsAsDna(){
  826. return $this->patientsWithoutAppointmentQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  827. }
  828. public function encountersPendingMyReviewRecordsAsDna(){
  829. return $this->encountersPendingMyReviewQueryAsDna()
  830. ->orderBy('effective_dateest', 'desc')
  831. ->orderBy('created_at', 'desc')
  832. ->paginate($this->DNA_RESULTS_PAGE_SIZE);
  833. }
  834. public function encountersInProgressRecordsAsDna(){
  835. return $this->encountersInProgressQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  836. }
  837. public function appointmentsPendingConfirmationRecordsAsDna(){
  838. return $this->appointmentsPendingConfirmationQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  839. }
  840. public function cancelledAppointmentsPendingAckRecordsAsDna(){
  841. return $this->cancelledAppointmentsPendingAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  842. }
  843. public function reportsPendingAckRecordsAsDna(){
  844. return $this->reportsPendingAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  845. }
  846. public function supplyOrdersPendingMyAckRecordsAsDna(){
  847. return $this->supplyOrdersPendingMyAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  848. }
  849. public function supplyOrdersPendingHcpApprovalRecordsAsDna(){
  850. return $this->supplyOrdersPendingHcpApprovalQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  851. }
  852. public function measurementsPendingReviewAsDna(){
  853. //Measurements Pending Review
  854. // SELECT * FROM measurement WHERE client_id IN (SELECT id FROM client WHERE rmm_pro_id = :me.id)
  855. // AND has_been_stamped_by_rmm IS FALSE AND is_cellular IS TRUE AND is_cellular_zero IS NOT TRUE AND is_active IS TRUE ORDER BY ts DESC;
  856. $myId = $this->id;
  857. return Measurement::whereHas('client',function($clientQuery) use ($myId) {
  858. return $clientQuery->where('rmm_pro_id', $myId);
  859. })
  860. ->where('has_been_stamped_by_rmm', '<>', true)
  861. ->where('is_cellular', true)
  862. ->where('is_cellular_zero', '<>', true)
  863. ->where('is_active', true)
  864. ->orderBy('ts', 'DESC')
  865. ->paginate(15);
  866. }
  867. public function getProcessingAmountAsDna(){
  868. $expectedForCm = DB::select(DB::raw("SELECT coalesce(SUM(cm_expected_payment_amount),0) as expected_pay FROM bill WHERE cm_pro_id = :performerProID AND has_cm_been_paid = false AND is_signed_by_cm IS TRUE AND is_cancelled = false"), ['performerProID' => $this->id])[0]->expected_pay;
  869. $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay FROM bill WHERE rme_pro_id = :performerProID AND has_rme_been_paid = false AND is_signed_by_rme IS TRUE AND is_cancelled = false"), ['performerProID' => $this->id])[0]->expected_pay;
  870. $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay FROM bill WHERE rmm_pro_id = :performerProID AND has_rmm_been_paid = false AND is_signed_by_rmm IS TRUE AND is_cancelled = false"), ['performerProID' => $this->id])[0]->expected_pay;
  871. $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(generic_pro_expected_payment_amount),0) as expected_pay FROM bill WHERE generic_pro_id = :performerProID AND has_generic_pro_been_paid = false AND is_signed_by_generic_pro IS TRUE AND is_cancelled = false"), ['performerProID' => $this->id])[0]->expected_pay;
  872. $totalExpectedAmount = $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  873. return $totalExpectedAmount;
  874. }
  875. public function getNextPaymentDateAsDna(){
  876. $nextPaymentDate = '--';
  877. //if today is < 15th, next payment is 15th, else nextPayment is
  878. $today = strtotime(date('Y-m-d'));
  879. $todayDate = date('j', $today);
  880. $todayMonth = date('m', $today);
  881. $todayYear = date('Y', $today);
  882. if ($todayDate < 15) {
  883. $nextPaymentDate = new DateTime();
  884. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  885. $nextPaymentDate = $nextPaymentDate->format('m/d/Y');
  886. } else {
  887. $nextPaymentDate = new \DateTime();
  888. $lastDayOfMonth = date('t', $today);
  889. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  890. $nextPaymentDate = $nextPaymentDate->format('m/d/Y');
  891. }
  892. return $nextPaymentDate;
  893. }
  894. public function clientSmsesAsDna(){
  895. $myId = $this->id;
  896. return ClientSMS::whereHas('client', function($clientQuery) use ($myId){
  897. return $clientQuery->where('default_na_pro_id', $myId);
  898. })
  899. ->orderBy('created_at', 'DESC')
  900. ->paginate(15);
  901. }
  902. public function clientMemosAsDna(){
  903. $naClientMemos = DB::select(
  904. DB::raw("
  905. SELECT c.uid as client_uid, c.name_first, c.name_last,
  906. cm.uid, cm.content, cm.created_at
  907. FROM client c join client_memo cm on c.id = cm.client_id
  908. WHERE
  909. c.default_na_pro_id = {$this->id}
  910. ORDER BY cm.created_at DESC
  911. ")
  912. );
  913. return $naClientMemos;
  914. }
  915. public function getAppointmentsPendingStatusChangeAckAsDna() {
  916. $myId = $this->id;
  917. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  918. return $clientQuery->where('default_na_pro_id', $myId);
  919. })
  920. ->where('is_status_acknowledgement_from_appointment_pro_pending', true)
  921. ->where('raw_date', '>=', DB::raw('NOW()'))
  922. ->orderBy('raw_date', 'asc')
  923. ->get();
  924. }
  925. public function getAppointmentsPendingDecisionAckAsDna() {
  926. $myId = $this->id;
  927. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  928. return $clientQuery->where('default_na_pro_id', $myId);
  929. })
  930. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true)
  931. ->where('raw_date', '>=', DB::raw('NOW()'))
  932. ->orderBy('raw_date', 'asc')
  933. ->get();
  934. }
  935. public function getAppointmentsPendingTimeChangeAckAsDna() {
  936. $myId = $this->id;
  937. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  938. return $clientQuery->where('default_na_pro_id', $myId);
  939. })
  940. ->where('is_time_change_acknowledgement_from_appointment_pro_pending', true)
  941. ->where('raw_date', '>=', DB::raw('NOW()'))
  942. ->orderBy('raw_date', 'asc')
  943. ->get();
  944. }
  945. }