Pro.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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. $pendingBillsToSign = Bill::where('bill_service_type', '<>', 'CARE_MONTH')->where(function ($query) {
  329. $query->where('hcp_pro_id', $this->id)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  330. })
  331. ->orWhere(function ($query) {
  332. $query->where('cm_pro_id', $this->id)->where('is_signed_by_cm', false)->where('is_cancelled', false);
  333. })->orWhere(function ($query) {
  334. $query->where('rme_pro_id', $this->id)->where('is_signed_by_rme', false)->where('is_cancelled', false);
  335. })->orWhere(function ($query) {
  336. $query->where('rmm_pro_id', $this->id)->where('is_signed_by_rmm', false)->where('is_cancelled', false);
  337. })->orWhere(function ($query) {
  338. $query->where('generic_pro_id', $this->id)->where('is_signed_by_generic_pro', false)->where('is_cancelled', false);
  339. })->count();
  340. return $pendingBillsToSign;
  341. }
  342. function get_incoming_reports_pending_signature_count_as_mcp() {
  343. return IncomingReport::where('hcp_pro_id', $this->id)
  344. ->where('has_hcp_pro_signed', '<>', true)
  345. ->where('is_entry_error', '<>', true)
  346. ->count();
  347. }
  348. function get_patients_without_appointment_query() {
  349. return Client::where('mcp_pro_id', $this->id)
  350. ->whereNull('today_mcp_appointment_date')
  351. ->where(function($q){
  352. $q->whereNull('next_mcp_appointment_id')
  353. ->orWhere('next_mcp_appointment_date', '<=', DB::raw('NOW()::DATE'));
  354. });
  355. }
  356. function get_patients_without_appointment_for_dna_query() {
  357. return Client::where('default_na_pro_id', $this->id)
  358. ->whereNull('today_mcp_appointment_date')
  359. ->where(function($q){
  360. $q->whereNull('next_mcp_appointment_id')
  361. ->orWhere('next_mcp_appointment_date', '<=', DB::raw('NOW()::DATE'));
  362. });
  363. }
  364. function get_patients_without_appointment_count_as_mcp() {
  365. return $this->get_patients_without_appointment_query()->count();
  366. }
  367. function get_patients_overdue_for_visit_query() {
  368. return Client::where('mcp_pro_id', $this->id)
  369. ->where(function($q){
  370. $q->whereNull('most_recent_completed_mcp_note_id')
  371. ->orWhere('most_recent_completed_mcp_note_date', '<', DB::raw("NOW()::DATE - INTERVAL '45 DAY'"));
  372. });
  373. }
  374. function get_patients_overdue_for_visit_for_dna_query() {
  375. return Client::where('default_na_pro_id', $this->id)
  376. ->where(function($q){
  377. $q->whereNull('most_recent_completed_mcp_note_id')
  378. ->orWhere('most_recent_completed_mcp_note_date', '<', DB::raw("NOW()::DATE - INTERVAL '45 DAY'"));
  379. });
  380. }
  381. function get_patients_overdue_count_as_mcp() {
  382. return $this->get_patients_overdue_for_visit_query()->count();
  383. }
  384. function get_patients_without_remote_measurement_in_48_hours_count_as_mcp() {
  385. 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;
  386. }
  387. function get_cancelled_appointments_pending_acknowledgement_count_as_mcp_query() {
  388. // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  389. return Appointment::where('pro_id', $this->id)
  390. ->where('latest_confirmation_decision_enum', 'REJECTED')
  391. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true);
  392. }
  393. function get_cancelled_appointments_pending_acknowledgement_count_as_mcp() {
  394. // SELECT * FROM appointment WHERE hcp_pro_id = :me.id AND status = 'REJECTED' AND wasAcknowledgedByAppointmentPro IS NOT TRUE;
  395. return $this->get_cancelled_appointments_pending_acknowledgement_count_as_mcp_query()->count();
  396. }
  397. function get_cancelled_bills_awaiting_review_count_as_mcp() {
  398. // SELECT * FROM bill WHERE bill_service_type = 'NOTE' AND is_cancelled IS TRUE AND isCancellationAcknowledged IS FALSE;
  399. return Bill::where('hcp_pro_id', $this->id)
  400. ->where('bill_service_type', 'NOTE')
  401. ->where('is_cancelled', true)
  402. ->where('is_cancellation_acknowledged', '<>', true)
  403. ->count();
  404. }
  405. function get_cancelled_supply_orders_awaiting_review_count_as_mcp() {
  406. // SELECT * FROM supply_order WHERE signed_by_pro_id = :me.id AND is_cancelled IS TRUE AND isCancellationAcknowledged IS NOT TRUE;
  407. return SupplyOrder::where('signed_by_pro_id', $this->id)
  408. ->where('is_cancelled', true)
  409. ->where('is_cancellation_acknowledged', '<>', true)
  410. ->count();
  411. }
  412. function get_erx_and_orders_awaiting_signature_count_as_mcp() {
  413. // SELECT * FROM erx WHERE hcp_pro_id = :me.id AND pro_declared_status <> 'CANCELLED' AND hasHcpProSigned IS NOT TRUE;
  414. return Erx::where('hcp_pro_id', $this->id)
  415. ->where('pro_declared_status', '<>', 'CANCELLED')
  416. ->where('has_hcp_pro_signed', '<>', true)
  417. ->count();
  418. }
  419. function get_supply_orders_awaiting_signature_count_as_mcp() {
  420. // 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;
  421. return SupplyOrder::where('created_by_pro_id', $this->id)
  422. ->whereNull('signed_by_pro_id')
  423. ->where('is_cancelled', '<>', true)
  424. ->count();
  425. }
  426. function get_supply_orders_awaiting_shipment_count_as_mcp() {
  427. return SupplyOrder::where('created_by_pro_id', $this->id)
  428. ->where('is_signed_by_pro', true)
  429. ->where('is_cleared_for_shipment', true)
  430. ->whereNull('shipment_id')
  431. ->count();
  432. }
  433. function get_birthdays_today_as_mcp(){
  434. return;
  435. $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
  436. $keyNumbers['patientsHavingBirthdayToday'] = $queryClients
  437. ->whereRaw('EXTRACT(DAY from dob) = ?', [date('d')])
  438. ->whereRaw('EXTRACT(MONTH from dob) = ?', [date('m')])
  439. ->count();
  440. $reimbursement = [];
  441. $reimbursement["currentBalance"] = $performer->pro->balance;
  442. $reimbursement["nextPaymentDate"] = '--';
  443. $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
  444. if ($lastPayment) {
  445. $reimbursement["lastPayment"] = $lastPayment->amount;
  446. $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
  447. } else {
  448. $reimbursement["lastPayment"] = '--';
  449. $reimbursement["lastPaymentDate"] = '--';
  450. }
  451. }
  452. public function getAppointmentsPendingStatusChangeAck() {
  453. return Appointment::where('pro_id', $this->id)
  454. ->where('is_status_acknowledgement_from_appointment_pro_pending', true)
  455. ->where('raw_date', '>=', DB::raw('NOW()'))
  456. ->orderBy('raw_date', 'asc')
  457. ->get();
  458. }
  459. public function getAppointmentsPendingDecisionAck() {
  460. return Appointment::where('pro_id', $this->id)
  461. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true)
  462. ->where('raw_date', '>=', DB::raw('NOW()'))
  463. ->orderBy('raw_date', 'asc')
  464. ->get();
  465. }
  466. public function getAppointmentsPendingTimeChangeAck() {
  467. return Appointment::where('pro_id', $this->id)
  468. ->where('is_time_change_acknowledgement_from_appointment_pro_pending', true)
  469. ->where('raw_date', '>=', DB::raw('NOW()'))
  470. ->orderBy('raw_date', 'asc')
  471. ->get();
  472. }
  473. public function getAccessibleClientsQuery($_search = false) {
  474. $proID = $this->id;
  475. $query = Client::whereNull('shadow_pro_id');
  476. if ($this->pro_type === 'ADMIN' && ($_search ? $this->can_see_any_client_via_search : $this->can_see_all_clients_in_list)) {
  477. $query = $query->where('id', '>', 0);
  478. } else {
  479. $query = $query->where(function ($q) use ($proID) {
  480. $q->where('mcp_pro_id', $proID)
  481. ->orWhere('cm_pro_id', $proID)
  482. ->orWhere('rmm_pro_id', $proID)
  483. ->orWhere('rme_pro_id', $proID)
  484. ->orWhere('physician_pro_id', $proID)
  485. ->orWhere('default_na_pro_id', $proID)
  486. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
  487. ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE status NOT IN (\'CANCELLED\') AND pro_id = ?)', [$proID])
  488. ->orWhereRaw('id IN (SELECT mcp_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  489. ->orWhereRaw('id IN (SELECT manager_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  490. ->orWhereRaw('id IN (SELECT client_id FROM note WHERE ally_pro_id = ? AND is_cancelled = FALSE)', [$proID]);;
  491. });
  492. }
  493. return $query;
  494. }
  495. public function canAccess($_patientUid) {
  496. $proID = $this->id;
  497. if ($this->pro_type === 'ADMIN') {
  498. return true;
  499. }
  500. $canAccess = Client::select('uid')
  501. ->where('uid', $_patientUid)
  502. ->where(function ($q) use ($proID) {
  503. $q->where('mcp_pro_id', $proID)
  504. ->orWhere('cm_pro_id', $proID)
  505. ->orWhere('rmm_pro_id', $proID)
  506. ->orWhere('rme_pro_id', $proID)
  507. ->orWhere('physician_pro_id', $proID)
  508. ->orWhere('default_na_pro_id', $proID)
  509. ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
  510. ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE status NOT IN (\'CANCELLED\') AND pro_id = ?)', [$proID])
  511. ->orWhereRaw('id IN (SELECT mcp_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  512. ->orWhereRaw('id IN (SELECT manager_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
  513. ->orWhereRaw('id IN (SELECT client_id FROM note WHERE ally_pro_id = ? AND is_cancelled = FALSE)', [$proID]);
  514. })->count();
  515. return !!$canAccess;
  516. }
  517. public function canAddCPMEntryForMeasurement(Measurement $measurement, Pro $pro)
  518. {
  519. // check if client has any programs where this measurement type is allowed
  520. $allowed = false;
  521. $client = $measurement->client;
  522. $clientPrograms = $client->clientPrograms;
  523. if($pro->pro_type !== 'ADMIN') {
  524. $clientPrograms = $clientPrograms->filter(function($_clientProgram) use ($pro) {
  525. return $_clientProgram->manager_pro_id === $pro->id;
  526. });
  527. }
  528. if(count($clientPrograms)) {
  529. foreach ($clientPrograms as $clientProgram) {
  530. if(strpos(strtolower($clientProgram->measurement_labels), '|' . strtolower($measurement->label) . '|') !== FALSE) {
  531. $allowed = true;
  532. break;
  533. }
  534. }
  535. }
  536. return $allowed ? $clientPrograms : FALSE;
  537. }
  538. public function getUnstampedMeasurementsFromCurrentMonth($_countOnly, $skip, $limit)
  539. {
  540. date_default_timezone_set('US/Eastern');
  541. $start = strtotime(date('Y-m-01'));
  542. $end = date_add(date_create(date('Y-m-01')), date_interval_create_from_date_string("1 month"))->getTimestamp();
  543. $start *= 1000;
  544. $end *= 1000;
  545. $measurementsQuery = Measurement::where('is_removed', false)
  546. ->join('client', 'client.id', '=', 'measurement.client_id')
  547. ->whereNotNull('measurement.client_bdt_measurement_id')
  548. ->whereNotNull('measurement.ts')
  549. ->where('measurement.is_cellular_zero', false)
  550. ->where('measurement.ts', '>=', $start)
  551. ->where('measurement.ts', '<', $end)
  552. ->whereIn('measurement.client_id', $this->getMyClientIds())
  553. ->where(function ($q) {
  554. $q
  555. ->where(function ($q2) {
  556. $q2
  557. ->where('client.mcp_pro_id', $this->id)
  558. ->where('measurement.has_been_stamped_by_mcp', false);
  559. })
  560. ->orWhere(function ($q2) {
  561. $q2
  562. ->where('client.default_na_pro_id', $this->id)
  563. ->where('measurement.has_been_stamped_by_non_hcp', false);
  564. })
  565. ->orWhere(function ($q2) {
  566. $q2
  567. ->where('client.rmm_pro_id', $this->id)
  568. ->where('measurement.has_been_stamped_by_rmm', false);
  569. })
  570. ->orWhere(function ($q2) {
  571. $q2
  572. ->where('client.rme_pro_id', $this->id)
  573. ->where('measurement.has_been_stamped_by_rme', false);
  574. });
  575. });
  576. if($_countOnly) {
  577. return $measurementsQuery->count();
  578. }
  579. $x = [];
  580. $measurements = $measurementsQuery
  581. ->orderBy('ts', 'desc')
  582. ->skip($skip)
  583. ->take($limit)
  584. ->get();
  585. // eager load stuff needed in JS
  586. foreach ($measurements as $measurement) {
  587. // if ($measurement->client_bdt_measurement_id) {
  588. // $measurement->bdtMeasurement = $measurement->clientBDTMeasurement->measurement;
  589. // }
  590. unset($measurement->clientBDTMeasurement); // we do not need this travelling to the frontend
  591. $client = [
  592. "uid" => $measurement->client->uid,
  593. "name" => $measurement->client->displayName(),
  594. ];
  595. $measurement->patient = $client;
  596. $measurement->careMonth = $measurement->client->currentCareMonth();
  597. $measurement->timestamp = friendlier_date_time($measurement->created_at);
  598. unset($measurement->client); // we do not need this travelling to the frontend
  599. if(@$measurement->detail_json) unset($measurement->detail_json);
  600. if(@$measurement->canvas_data) unset($measurement->canvas_data);
  601. if(@$measurement->latest_measurements) unset($measurement->latest_measurements);
  602. if(@$measurement->info_lines) unset($measurement->info_lines);
  603. if(@$measurement->canvas_data_backup) unset($measurement->canvas_data_backup);
  604. if(@$measurement->migrated_canvas_data_backup) unset($measurement->migrated_canvas_data_backup);
  605. // if($measurement->label == 'SBP' || $measurement->label = 'DBP'){
  606. // continue;
  607. // }
  608. $x[] = $measurement;
  609. }
  610. // dd($measurements);
  611. return $measurements;
  612. }
  613. public function getMeasurements($_onlyUnstamped = true)
  614. {
  615. $measurementsQuery = Measurement::where('is_removed', false);
  616. if ($this->pro_type != 'ADMIN') {
  617. $measurementsQuery
  618. ->whereIn('client_id', $this->getMyClientIds());
  619. }
  620. if ($_onlyUnstamped) {
  621. $measurementsQuery
  622. ->whereNotNull('client_bdt_measurement_id')
  623. ->whereNotNull('ts')
  624. ->where('is_cellular_zero', false)
  625. ->where(function ($q) {
  626. $q->whereNull('status')
  627. ->orWhere(function ($q2) {
  628. $q2->where('status', '<>', 'ACK')
  629. ->where('status', '<>', 'INVALID_ACK');
  630. });
  631. });
  632. }
  633. $x = [];
  634. $measurements = $measurementsQuery->orderBy('ts', 'desc')->paginate(50);
  635. // eager load stuff needed in JS
  636. foreach ($measurements as $measurement) {
  637. // if ($measurement->client_bdt_measurement_id) {
  638. // $measurement->bdtMeasurement = $measurement->clientBDTMeasurement->measurement;
  639. // }
  640. unset($measurement->clientBDTMeasurement); // we do not need this travelling to the frontend
  641. $client = [
  642. "uid" => $measurement->client->uid,
  643. "name" => $measurement->client->displayName(),
  644. ];
  645. $measurement->patient = $client;
  646. $measurement->careMonth = $measurement->client->currentCareMonth();
  647. $measurement->timestamp = friendly_date_time($measurement->created_at);
  648. unset($measurement->client); // we do not need this travelling to the frontend
  649. // if($measurement->label == 'SBP' || $measurement->label = 'DBP'){
  650. // continue;
  651. // }
  652. $x[] = $measurement;
  653. }
  654. return $measurements;
  655. }
  656. public function companyPros()
  657. {
  658. return $this->hasMany(CompanyPro::class, 'pro_id', 'id')
  659. ->where('is_active', true);
  660. }
  661. public function companyProPayers()
  662. {
  663. return $this->hasMany(CompanyProPayer::class, 'pro_id', 'id');
  664. }
  665. public function isAssociatedWithMCPayer() {
  666. $companyProPayers = $this->companyProPayers;
  667. $foundMC = false;
  668. if($companyProPayers) {
  669. foreach ($companyProPayers as $companyProPayer) {
  670. if($companyProPayer->payer && $companyProPayer->payer->is_medicare) {
  671. $foundMC = true;
  672. break;
  673. }
  674. }
  675. }
  676. return $foundMC;
  677. }
  678. public function isAssociatedWithNonMCPayer($_payerID) {
  679. $companyProPayers = $this->companyProPayers;
  680. $foundNonMC = false;
  681. if($companyProPayers) {
  682. foreach ($companyProPayers as $companyProPayer) {
  683. if($companyProPayer->payer && !$companyProPayer->payer->is_medicare && $companyProPayer->payer->id === $_payerID) {
  684. $foundNonMC = true;
  685. break;
  686. }
  687. }
  688. }
  689. return $foundNonMC;
  690. }
  691. public function companyLocations() {
  692. $companyProPayers = $this->companyProPayers;
  693. $companyIDs = [];
  694. foreach ($companyProPayers as $companyProPayer) {
  695. $companyIDs[] = $companyProPayer->company_id;
  696. }
  697. $locations = [];
  698. if(count($companyIDs)) {
  699. $locations = CompanyLocation::whereIn('id', $companyIDs)->get();
  700. }
  701. return $locations;
  702. }
  703. public function shadowClient() {
  704. return $this->hasOne(Client::class, 'id', 'shadow_client_id');
  705. }
  706. public function defaultCompanyPro() {
  707. return $this->hasOne(CompanyPro::class, 'id', 'default_company_pro_id');
  708. }
  709. public function currentNotePickupForProcessing() {
  710. return $this->hasOne(NotePickupForProcessing::class, 'id', 'current_note_pickup_for_processing_id');
  711. }
  712. public function get_patients_not_seen_in_45_days_count_as_mcp(){
  713. return 0;
  714. }
  715. //DNA_DASHBOARD
  716. //queries
  717. private function patientsQueryAsDna(){
  718. // WHERE na_pro_id = :me.id
  719. return Client::where('default_na_pro_id', $this->id);
  720. }
  721. private function patientsAwaitingMcpVisitQueryAsDna(){
  722. // WHERE has_mcp_done_onboarding_visit <> 'YES'
  723. return Client::where('default_na_pro_id', $this->id)->where('has_mcp_done_onboarding_visit', '<>', 'YES');
  724. }
  725. private function patientsWithoutAppointmentQueryAsDna(){
  726. // WHERE today_mcp_appointment_date IS NULL AND next_mcp_appointment_date IS NULL
  727. return Client::where('default_na_pro_id', $this->id)
  728. ->whereNull('today_mcp_appointment_date')
  729. ->whereNull('next_mcp_appointment_date');
  730. }
  731. private function encountersPendingMyReviewQueryAsDna(){
  732. // 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;
  733. return Note::where('ally_pro_id', $this->id)
  734. ->where('is_cancelled', '<>', true)
  735. ->where('is_signed_by_hcp', true)
  736. ->where('is_signed_by_ally','<>', true);
  737. }
  738. private function encountersInProgressQueryAsDna(){
  739. // 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;
  740. return Note::where('ally_pro_id', $this->id)
  741. ->where('is_cancelled', '<>', true)
  742. ->where('is_signed_by_hcp', '<>', true);
  743. }
  744. private function appointmentsPendingConfirmationQueryAsDna(){
  745. // WHERE client_id IN (SELECT id FROM client WHERE default_na_pro_id = :me.id) AND status = 'PENDING'
  746. $myId = $this->id;
  747. return Appointment::whereHas('client', function($clientQuery) use ($myId) {
  748. return $clientQuery->where('default_na_pro_id', $myId);
  749. })->where('status', 'PENDING');
  750. }
  751. private function cancelledAppointmentsPendingAckQueryAsDna(){
  752. // 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;
  753. $myId = $this->id;
  754. return Appointment::whereHas('client', function($clientQuery) use ($myId) {
  755. return $clientQuery->where('default_na_pro_id', $myId);
  756. })->where('status', 'CANCELLED')
  757. ->where('is_status_acknowledgement_from_default_na_pending', true);
  758. }
  759. private function reportsPendingAckQueryAsDna(){
  760. // 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
  761. $myId = $this->id;
  762. return IncomingReport::whereHas('client',function($clientQuery) use ($myId) {
  763. return $clientQuery->where('default_na_pro_id', $myId);
  764. })->where('has_na_pro_signed', '<>', true)
  765. ->where('is_entry_error','<>', true);
  766. }
  767. private function supplyOrdersPendingMyAckQueryAsDna(){
  768. // 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;
  769. $myId = $this->id;
  770. return SupplyOrder::whereHas('client',function($clientQuery) use ($myId) {
  771. return $clientQuery->where('default_na_pro_id', $myId);
  772. })->where('has_na_pro_signed', '<>', true)
  773. ->where('is_signed_by_pro', true)
  774. ->where('is_cancelled', '<>', true);
  775. }
  776. private function supplyOrdersPendingHcpApprovalQueryAsDna(){
  777. // 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;
  778. $myId = $this->id;
  779. return SupplyOrder::whereHas('client',function($clientQuery) use ($myId) {
  780. return $clientQuery->where('default_na_pro_id', $myId);
  781. })->where('has_na_pro_signed', true)
  782. ->where('is_signed_by_pro','<>', true)
  783. ->where('is_cancelled', '<>', true);
  784. }
  785. //counts
  786. public function patientsCountAsDna(){
  787. return $this->patientsQueryAsDna()->count();
  788. }
  789. public function patientsAwaitingMcpVisitCountAsDna(){
  790. return $this->patientsAwaitingMcpVisitQueryAsDna()->count();
  791. }
  792. public function patientsWithoutAppointmentCountAsDna(){
  793. return $this->patientsWithoutAppointmentQueryAsDna()->count();
  794. }
  795. public function encountersPendingMyReviewCountAsDna(){
  796. return $this->encountersPendingMyReviewQueryAsDna()->count();
  797. }
  798. public function encountersInProgressCountAsDna(){
  799. return $this->encountersInProgressQueryAsDna()->count();
  800. }
  801. public function appointmentsPendingConfirmationCountAsDna(){
  802. return $this->appointmentsPendingConfirmationQueryAsDna()->count();
  803. }
  804. public function cancelledAppointmentsPendingAckCountAsDna(){
  805. return $this->cancelledAppointmentsPendingAckQueryAsDna()->count();
  806. }
  807. public function reportsPendingAckCountAsDna(){
  808. return $this->reportsPendingAckQueryAsDna()->count();
  809. }
  810. public function supplyOrdersPendingMyAckCountAsDna(){
  811. return $this->supplyOrdersPendingMyAckQueryAsDna()->count();
  812. }
  813. public function supplyOrdersPendingHcpApprovalCountAsDna(){
  814. return $this->supplyOrdersPendingHcpApprovalQueryAsDna()->count();
  815. }
  816. //records
  817. private $DNA_RESULTS_PAGE_SIZE = 50;
  818. public function patientsRecordsAsDna(){
  819. return $this->patientsQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  820. }
  821. public function patientsAwaitingMcpVisitRecordsAsDna(){
  822. return $this->patientsAwaitingMcpVisitQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  823. }
  824. public function patientsWithoutAppointmentRecordsAsDna(){
  825. return $this->patientsWithoutAppointmentQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  826. }
  827. public function encountersPendingMyReviewRecordsAsDna(){
  828. return $this->encountersPendingMyReviewQueryAsDna()
  829. ->orderBy('effective_dateest', 'desc')
  830. ->orderBy('created_at', 'desc')
  831. ->paginate($this->DNA_RESULTS_PAGE_SIZE);
  832. }
  833. public function encountersInProgressRecordsAsDna(){
  834. return $this->encountersInProgressQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  835. }
  836. public function appointmentsPendingConfirmationRecordsAsDna(){
  837. return $this->appointmentsPendingConfirmationQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  838. }
  839. public function cancelledAppointmentsPendingAckRecordsAsDna(){
  840. return $this->cancelledAppointmentsPendingAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  841. }
  842. public function reportsPendingAckRecordsAsDna(){
  843. return $this->reportsPendingAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  844. }
  845. public function supplyOrdersPendingMyAckRecordsAsDna(){
  846. return $this->supplyOrdersPendingMyAckQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  847. }
  848. public function supplyOrdersPendingHcpApprovalRecordsAsDna(){
  849. return $this->supplyOrdersPendingHcpApprovalQueryAsDna()->paginate($this->DNA_RESULTS_PAGE_SIZE);
  850. }
  851. public function measurementsPendingReviewAsDna(){
  852. //Measurements Pending Review
  853. // SELECT * FROM measurement WHERE client_id IN (SELECT id FROM client WHERE rmm_pro_id = :me.id)
  854. // 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;
  855. $myId = $this->id;
  856. return Measurement::whereHas('client',function($clientQuery) use ($myId) {
  857. return $clientQuery->where('rmm_pro_id', $myId);
  858. })
  859. ->where('has_been_stamped_by_rmm', '<>', true)
  860. ->where('is_cellular', true)
  861. ->where('is_cellular_zero', '<>', true)
  862. ->where('is_active', true)
  863. ->orderBy('ts', 'DESC')
  864. ->paginate(15);
  865. }
  866. public function getProcessingAmountAsDna(){
  867. $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;
  868. $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;
  869. $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;
  870. $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;
  871. $totalExpectedAmount = $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
  872. return $totalExpectedAmount;
  873. }
  874. public function getNextPaymentDateAsDna(){
  875. $nextPaymentDate = '--';
  876. //if today is < 15th, next payment is 15th, else nextPayment is
  877. $today = strtotime(date('Y-m-d'));
  878. $todayDate = date('j', $today);
  879. $todayMonth = date('m', $today);
  880. $todayYear = date('Y', $today);
  881. if ($todayDate < 15) {
  882. $nextPaymentDate = new DateTime();
  883. $nextPaymentDate->setDate($todayYear, $todayMonth, 15);
  884. $nextPaymentDate = $nextPaymentDate->format('m/d/Y');
  885. } else {
  886. $nextPaymentDate = new \DateTime();
  887. $lastDayOfMonth = date('t', $today);
  888. $nextPaymentDate->setDate($todayYear, $todayMonth, $lastDayOfMonth);
  889. $nextPaymentDate = $nextPaymentDate->format('m/d/Y');
  890. }
  891. return $nextPaymentDate;
  892. }
  893. public function clientSmsesAsDna(){
  894. $myId = $this->id;
  895. return ClientSMS::whereHas('client', function($clientQuery) use ($myId){
  896. return $clientQuery->where('default_na_pro_id', $myId);
  897. })
  898. ->orderBy('created_at', 'DESC')
  899. ->paginate(15);
  900. }
  901. public function clientMemosAsDna(){
  902. $naClientMemos = DB::select(
  903. DB::raw("
  904. SELECT c.uid as client_uid, c.name_first, c.name_last,
  905. cm.uid, cm.content, cm.created_at
  906. FROM client c join client_memo cm on c.id = cm.client_id
  907. WHERE
  908. c.default_na_pro_id = {$this->id}
  909. ORDER BY cm.created_at DESC
  910. ")
  911. );
  912. return $naClientMemos;
  913. }
  914. public function getAppointmentsPendingStatusChangeAckAsDna() {
  915. $myId = $this->id;
  916. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  917. return $clientQuery->where('default_na_pro_id', $myId);
  918. })
  919. ->where('is_status_acknowledgement_from_appointment_pro_pending', true)
  920. ->where('raw_date', '>=', DB::raw('NOW()'))
  921. ->orderBy('raw_date', 'asc')
  922. ->get();
  923. }
  924. public function getAppointmentsPendingDecisionAckAsDna() {
  925. $myId = $this->id;
  926. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  927. return $clientQuery->where('default_na_pro_id', $myId);
  928. })
  929. ->where('is_decision_acknowledgement_from_appointment_pro_pending', true)
  930. ->where('raw_date', '>=', DB::raw('NOW()'))
  931. ->orderBy('raw_date', 'asc')
  932. ->get();
  933. }
  934. public function getAppointmentsPendingTimeChangeAckAsDna() {
  935. $myId = $this->id;
  936. return Appointment::whereHas('client', function($clientQuery) use ($myId){
  937. return $clientQuery->where('default_na_pro_id', $myId);
  938. })
  939. ->where('is_time_change_acknowledgement_from_appointment_pro_pending', true)
  940. ->where('raw_date', '>=', DB::raw('NOW()'))
  941. ->orderBy('raw_date', 'asc')
  942. ->get();
  943. }
  944. }