Pro.php 44 KB

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