Client.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Relations\HasOne;
  4. use Illuminate\Support\Collection;
  5. # use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. class Client extends Model
  8. {
  9. protected $table = 'client';
  10. public function primaryCoverages()
  11. {
  12. return $this->hasMany(ClientPrimaryCoverage::class, 'client_id', 'id')
  13. ->orderBy('created_at', 'desc');
  14. }
  15. public function displayName()
  16. {
  17. return $this->name_last . ', ' . $this->name_first;
  18. }
  19. public function mcp()
  20. {
  21. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  22. }
  23. public function pcp()
  24. {
  25. return $this->hasOne(Pro::class, 'id', 'physician_pro_id');
  26. }
  27. public function cm()
  28. {
  29. return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
  30. }
  31. public function rmm()
  32. {
  33. return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
  34. }
  35. public function rme()
  36. {
  37. return $this->hasOne(Pro::class, 'id', 'rme_pro_id');
  38. }
  39. public function rms()
  40. {
  41. return $this->hasOne(Pro::class, 'id', 'rms_pro_id');
  42. }
  43. public function rmg()
  44. {
  45. return $this->hasOne(Pro::class, 'id', 'rmg_pro_id');
  46. }
  47. public function defaultNaPro()
  48. {
  49. return $this->hasOne(Pro::class, 'id', 'default_na_pro_id');
  50. }
  51. public function prosInMeetingWith()
  52. {
  53. return Pro::where('in_meeting_with_client_id', $this->id)->get();
  54. }
  55. public function notes()
  56. {
  57. return $this->hasMany(Note::class, 'client_id', 'id')
  58. ->orderBy('effective_dateest', 'desc');
  59. }
  60. public function prescriptions()
  61. {
  62. return $this->hasMany(Erx::class, 'client_id', 'id')
  63. ->orderBy('created_at', 'desc');
  64. }
  65. public function notesAscending()
  66. {
  67. return $this->hasMany(Note::class, 'client_id', 'id')
  68. ->orderBy('effective_dateest', 'asc');
  69. }
  70. public function mcCodeChecks(){
  71. // $tables = DB::select("SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema'");
  72. // foreach ($tables as $table) {
  73. // dump($table);
  74. // }
  75. // die();
  76. return $this->hasMany(McCodeCheck::class, 'client_id', 'id')->orderBy('created_at', 'asc');
  77. }
  78. public function activeNotes()
  79. {
  80. return $this->hasMany(Note::class, 'client_id', 'id')
  81. ->where('is_cancelled', false)
  82. ->orderBy('effective_dateest', 'desc');
  83. }
  84. public function cancelledNotes()
  85. {
  86. return $this->hasMany(Note::class, 'client_id', 'id')
  87. ->where('is_cancelled', true)
  88. ->orderBy('effective_dateest', 'desc');
  89. }
  90. public function sections()
  91. {
  92. return $this->hasMany(Section::class, 'client_id', 'id')
  93. ->where('is_active', true)
  94. ->orderBy('created_at', 'asc');
  95. }
  96. public function handouts()
  97. {
  98. $mappings = HandoutClient::where('client_id', $this->id)->get();
  99. $handouts = new Collection();
  100. foreach ($mappings as $mapping) {
  101. $handout = Handout::where('id', $mapping->handout_id)->first();
  102. $handout->handout_client_uid = $mapping->uid;
  103. $handouts->add($handout);
  104. }
  105. $handouts = $handouts->sortBy('created_at');
  106. return $handouts;
  107. }
  108. public function duplicateOf()
  109. {
  110. return $this->hasOne(Client::class, 'id', 'duplicate_of_client_id');
  111. }
  112. public function actionItems()
  113. {
  114. return $this->hasMany(ActionItem::class, 'client_id', 'id')
  115. ->orderBy('action_item_category', 'asc')
  116. ->orderBy('created_at', 'desc');
  117. }
  118. public function infoLines()
  119. {
  120. return $this->hasMany(ClientInfoLine::class, 'client_id', 'id')->orderBy('created_at', 'desc');
  121. }
  122. public function measurements()
  123. {
  124. return $this->hasMany(Measurement::class, 'client_id', 'id')
  125. /*->distinct('label')*/
  126. ->where('is_removed', false)
  127. ->orderByRaw('ts DESC NULLS LAST');
  128. }
  129. public function recentMeasurements()
  130. {
  131. return $this->hasMany(Measurement::class, 'client_id', 'id')
  132. ->where('is_removed', false)
  133. ->whereNotNull('label')
  134. ->where('label', '<>', 'SBP')
  135. ->where('label', '<>', 'DBP')
  136. ->where('is_cellular_zero', false)
  137. ->orderByRaw('ts DESC NULLS LAST')
  138. ->offset(0)->limit(20);
  139. }
  140. public function nonZeroMeasurements()
  141. {
  142. return $this->hasMany(Measurement::class, 'client_id', 'id')
  143. /*->distinct('label')*/
  144. ->where('is_removed', false)
  145. ->where('is_cellular_zero', false)
  146. ->orderBy('effective_date', 'desc');
  147. }
  148. public function getNonZeroBpMeasurements(){
  149. return $this->hasMany(Measurement::class, 'client_id', 'id')
  150. /*->distinct('label')*/
  151. ->where('is_removed', false)
  152. ->where('label', '=', 'BP')
  153. ->where('sbp_mm_hg', '>', 0)
  154. ->where('dbp_mm_hg', '>', 0)
  155. ->orderBy('ts', 'desc');
  156. }
  157. public function getNonZeroWeightMeasurements(){
  158. return $this->hasMany(Measurement::class, 'client_id', 'id')
  159. /*->distinct('label')*/
  160. ->where('is_removed', false)
  161. ->where('label', '=', 'Wt. (lbs.)')
  162. ->where('numeric_value', '>', 0)
  163. ->orderBy('ts', 'desc');
  164. }
  165. public function currentCareMonth()
  166. {
  167. $cmStartDate = strtotime(date('Y-m-d'));
  168. $month = date("n", $cmStartDate);
  169. $year = date("Y", $cmStartDate);
  170. return CareMonth
  171. ::where('client_id', $this->id)
  172. ->whereRaw('EXTRACT(MONTH FROM start_date) = ?', [$month])
  173. ->whereRaw('EXTRACT(YEAR FROM start_date) = ?', [$year])
  174. ->first();
  175. }
  176. public function measurementsInCareMonth(CareMonth $careMonth)
  177. {
  178. $cmStartDate = strtotime($careMonth->start_date);
  179. $month = date("n", $cmStartDate);
  180. $year = date("Y", $cmStartDate);
  181. $measurements = Measurement
  182. ::where('client_id', $this->id)
  183. ->whereRaw('EXTRACT(MONTH FROM effective_date) = ?', [$month])
  184. ->whereRaw('EXTRACT(YEAR FROM effective_date) = ?', [$year])
  185. ->where('is_removed', false)
  186. ->orderBy('ts', 'desc')
  187. ->get();
  188. return $measurements;
  189. }
  190. public function allMeasurements()
  191. {
  192. return $this->hasMany(Measurement::class, 'client_id', 'id')
  193. ->where('is_removed', false)
  194. ->whereNull('parent_measurement_id')
  195. ->orderBy('label', 'asc')
  196. ->orderBy('effective_date', 'desc');
  197. }
  198. public function smses()
  199. {
  200. return $this->hasMany(ClientSMS::class, 'client_id', 'id')
  201. ->orderBy('created_at', 'desc');
  202. }
  203. public function documents()
  204. {
  205. return $this->hasMany(ClientDocument::class, 'client_id', 'id')
  206. ->orderBy('created_at', 'desc');
  207. }
  208. public function incomingReports() {
  209. return $this->hasMany(IncomingReport::class, 'client_id', 'id')
  210. ->orderBy('created_at', 'desc');
  211. }
  212. public function smsNumbers() {
  213. return $this->hasMany(ClientSMSNumber::class, 'client_id', 'id')
  214. ->orderBy('created_at', 'desc');
  215. }
  216. public function nextMcpAppointment()
  217. {
  218. if ($this->mcp) {
  219. return Appointment::where('client_id', $this->id)
  220. ->where('pro_id', $this->mcp->id)
  221. ->where('start_time', '>=', date('Y-m-d'))
  222. ->orderBy('start_time', 'asc')
  223. ->first();
  224. }
  225. return false;
  226. }
  227. public function appointments()
  228. {
  229. return $this->hasMany(Appointment::class, 'client_id', 'id')
  230. ->orderBy('start_time', 'desc');
  231. }
  232. public function appointmentsForProByStatus($forPro = 'all', $status = 'all')
  233. {
  234. $appointments = Appointment::where('client_id', $this->id);
  235. if($forPro !== 'all') {
  236. $forPro = Pro::where('uid', $forPro)->first();
  237. $appointments = $appointments->where('pro_id', $forPro->id);
  238. }
  239. if($status !== 'ALL') {
  240. $appointments = $appointments->where('status', $status);
  241. }
  242. $appointments = $appointments->orderBy('start_time', 'desc');
  243. return $appointments->get();
  244. }
  245. public function upcomingAppointments()
  246. {
  247. return $this->hasMany(Appointment::class, 'client_id', 'id')
  248. ->where('raw_date', '>=', date('Y-m-d'))
  249. ->whereIn('status', ['CREATED', 'CONFIRMED'])
  250. ->orderBy('start_time', 'desc')
  251. ->limit(5);
  252. }
  253. public function appointmentsFromLastWeek()
  254. {
  255. $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("7 days"));
  256. $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
  257. return $this->hasMany(Appointment::class, 'client_id', 'id')
  258. ->where('raw_date', '>=', $dateLastWeek)
  259. ->whereIn('status', ['CREATED', 'CONFIRMED'])
  260. ->orderBy('start_time', 'desc');
  261. }
  262. public function memos()
  263. {
  264. return $this->hasMany(ClientMemo::class, 'client_id', 'id')
  265. ->where('is_cancelled', false)
  266. ->orderBy('created_at', 'desc');
  267. }
  268. public function devices()
  269. {
  270. return $this->hasMany(ClientBDTDevice::class, 'client_id', 'id')
  271. ->where('is_active', true)
  272. ->orderBy('created_at', 'desc');
  273. }
  274. public function deactivatedDevices()
  275. {
  276. return $this->hasMany(ClientBDTDevice::class, 'client_id', 'id')
  277. ->where('is_active', false)
  278. ->orderBy('created_at', 'desc');
  279. }
  280. public function hasDevice($_device)
  281. {
  282. $count = ClientBDTDevice::where('client_id', $this->id)
  283. ->where('device_id', $_device->id)
  284. ->where('is_active', true)
  285. ->count();
  286. return !!$count;
  287. }
  288. public function deviceMeasurements()
  289. {
  290. return $this->hasMany(ClientBDTMeasurement::class, 'client_id', 'id')
  291. ->orderBy('created_at', 'desc');
  292. }
  293. public function activeMcpRequest()
  294. {
  295. return $this->hasOne(McpRequest::class, 'id', 'active_mcp_request_id');
  296. }
  297. public function clientPrograms()
  298. {
  299. return $this->hasMany(ClientProgram::class, 'client_id', 'id')
  300. ->where('is_active', true)
  301. ->orderBy('title', 'desc');
  302. }
  303. public function tickets()
  304. {
  305. return $this->hasMany(Ticket::class, 'client_id', 'id')
  306. ->orderBy('is_open', 'desc')
  307. ->orderBy('created_at', 'desc');
  308. }
  309. public function mcpDisplayName()
  310. {
  311. }
  312. public function rmeDisplayName()
  313. {
  314. }
  315. public function supplyOrderForCellularBPDevice() {
  316. return SupplyOrder::where('product_id', 1)
  317. ->where('is_cancelled', false)
  318. ->where('client_id', $this->id)
  319. ->orderBy('id', 'desc')
  320. ->first();
  321. }
  322. public function supplyOrderForCellularWeightScale() {
  323. return SupplyOrder::where('product_id', 2)
  324. ->where('is_cancelled', false)
  325. ->where('client_id', $this->id)
  326. ->orderBy('id', 'desc')
  327. ->first();
  328. }
  329. public function firstCellularBPDevice()
  330. {
  331. $devices = $this->devices;
  332. $x = null;
  333. foreach($devices as $device){
  334. if($device->device->category == 'BP'){
  335. $x = $device;
  336. break;
  337. }
  338. }
  339. return $x;
  340. }
  341. public function getFirstCellularBPMeasurementAt()
  342. {
  343. }
  344. public function getLatestCellularBPMeasurementAt()
  345. {
  346. }
  347. public function getTotalCellularBPMeasurements()
  348. {
  349. }
  350. public function firstCellularWeightDevice()
  351. {
  352. $devices = $this->devices;
  353. $x = null;
  354. foreach($devices as $device){
  355. if($device->device->category == 'WEIGHT'){
  356. $x = $device;
  357. break;
  358. }
  359. }
  360. return $x;
  361. }
  362. public function getFirstCellularWeightMeasurementAt()
  363. {
  364. }
  365. public function getLatestCellularWeightMeasurementAt()
  366. {
  367. }
  368. public function getTotalCellularWeightMeasurements()
  369. {
  370. }
  371. public function prosWithAccess()
  372. {
  373. $pros = [];
  374. // directly associated pros
  375. $pro = $this->mcp;
  376. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'MCP'];
  377. $pro = $this->pcp;
  378. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'PCP (Physician)'];
  379. $pro = $this->cm;
  380. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'CM'];
  381. $pro = $this->rmm;
  382. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'RMM'];
  383. $pro = $this->rme;
  384. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'RME'];
  385. $pro = $this->defaultNaPro;
  386. if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'Nurse'];
  387. // via client pro access
  388. $cpAccesses = ClientProAccess::where('client_id', $this->id)->where('is_active', true)->get();
  389. foreach ($cpAccesses as $cpAccess) {
  390. if (!$cpAccess->pro) continue;
  391. $pros[] = ["pro" => $cpAccess->pro->displayName(), "association" => 'Via Client-Pro Access'];
  392. }
  393. // via appointments
  394. $appointments = Appointment::where('client_id', $this->id)->get();
  395. foreach ($appointments as $appointment) {
  396. if (!$appointment->pro) continue;
  397. $pros[] = ["pro" => $appointment->pro->displayName(), "association" => 'Via Appointment: ' . $appointment->raw_date];
  398. }
  399. // via client program
  400. $clientPrograms = ClientProgram::where('client_id', $this->id)->where('is_active', true)->get();
  401. foreach ($clientPrograms as $clientProgram) {
  402. if ($clientProgram->mcp)
  403. $pros[] = ["pro" => $clientProgram->mcp->displayName(), "association" => 'Program MCP: ' . $clientProgram->title];
  404. if ($clientProgram->manager)
  405. $pros[] = ["pro" => $clientProgram->manager->displayName(), "association" => 'Program Manager: ' . $clientProgram->title];
  406. }
  407. // sort by pro name
  408. $name = array_column($pros, 'pro');
  409. array_multisort($name, SORT_ASC, $pros);
  410. return $pros;
  411. }
  412. public function mcpRequests()
  413. {
  414. return $this->hasMany(McpRequest::class, 'for_client_id', 'id')
  415. ->orderBy('created_at', 'desc');
  416. }
  417. public function eligibleRefreshes()
  418. {
  419. return $this->hasMany(ClientEligibleRefresh::class, 'client_id', 'id')
  420. ->orderBy('created_at', 'desc');
  421. }
  422. public function mbPayerValidationResults()
  423. {
  424. return $this->hasMany(ClientMBPayerValidationResult::class, 'client_id', 'id')
  425. ->orderBy('created_at', 'desc');
  426. }
  427. public function payer()
  428. {
  429. return $this->hasOne(MBPayer::class, 'id', 'mb_payer_id');
  430. }
  431. public function supplyOrders()
  432. {
  433. return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
  434. ->orderBy('created_at', 'desc');
  435. }
  436. public function activeSupplyOrders()
  437. {
  438. return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
  439. ->where('is_cancelled', false)
  440. ->orderBy('created_at', 'desc');
  441. }
  442. public function cancelledSupplyOrders()
  443. {
  444. return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
  445. ->where('is_cancelled', true)
  446. ->orderBy('created_at', 'desc');
  447. }
  448. public function readyToShipSupplyOrders()
  449. {
  450. return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
  451. ->where('is_cancelled', false)
  452. ->where('is_cleared_for_shipment', true)
  453. ->whereNull('shipment_id')
  454. ->orderBy('created_at', 'desc');
  455. }
  456. public function shipments()
  457. {
  458. return $this->hasMany(Shipment::class, 'client_id', 'id')
  459. ->where('is_cancelled', false)
  460. ->orderBy('created_at', 'desc');
  461. }
  462. public function numSignedNotes() {
  463. return Note::where('client_id', $this->id)
  464. ->where('is_cancelled', false)
  465. ->where('is_signed_by_hcp', true)
  466. ->count();
  467. }
  468. public function smsReminders()
  469. {
  470. return $this->hasMany(SimpleSMSReminder::class, 'client_id', 'id')
  471. ->orderBy('created_at', 'asc');
  472. }
  473. public function measurementConfirmationNumbers()
  474. {
  475. return $this->hasMany(MeasurementConfirmationNumber::class, 'client_id', 'id')
  476. ->orderBy('created_at', 'asc');
  477. }
  478. public function shadowOfPro() {
  479. return $this->hasOne(Pro::class, 'id', 'shadow_pro_id');
  480. }
  481. public function clientTags()
  482. {
  483. return $this->hasMany(ClientTag::class, 'client_id', 'id')
  484. ->where('is_cancelled', false)
  485. ->orderBy('tag', 'asc');
  486. }
  487. public function medicalTeam()
  488. {
  489. return $this->hasMany(ClientProAccess::class, 'client_id', 'id')
  490. ->where('is_active', true)
  491. ->whereNotNull('pro_id')
  492. ->orderBy('created_at', 'asc');
  493. }
  494. public function accountInvites()
  495. {
  496. return $this->hasMany(AccountInvite::class, 'for_client_id', 'id')
  497. ->orderBy('created_at', 'desc');
  498. }
  499. public function linkedAccounts()
  500. {
  501. return $this->hasMany(AccountClient::class, 'client_id', 'id')
  502. ->orderBy('created_at', 'desc');
  503. }
  504. public function pages($_type, $_returnShadows, $_note) {
  505. return Page
  506. ::where('client_id', $this->id)
  507. ->where('note_id', $_note->id)
  508. ->where('category', $_type)
  509. ->where('is_shadow', !!$_returnShadows)
  510. ->orderBy('key', 'ASC')
  511. ->get();
  512. }
  513. public function firstPageByCategoryAndKey($_category, $_key) {
  514. return Page
  515. ::where('client_id', $this->id)
  516. ->where('category', $_category)
  517. ->where('key', $_key)
  518. ->first();
  519. }
  520. public function cmReasons()
  521. {
  522. return $this->hasMany(ClientCmRmReason::class, 'client_id', 'id')
  523. ->where('cm_or_rm', 'CM')
  524. ->orderBy('position_index', 'ASC')
  525. ->orderBy('code', 'ASC');
  526. }
  527. public function rmReasons()
  528. {
  529. return $this->hasMany(ClientCmRmReason::class, 'client_id', 'id')
  530. ->where('cm_or_rm', 'RM')
  531. ->orderBy('position_index', 'ASC')
  532. ->orderBy('code', 'ASC');
  533. }
  534. public function defaultMcpCompanyPro()
  535. {
  536. return $this->hasOne(CompanyPro::class, 'id', 'default_mcp_company_pro_id');
  537. }
  538. public function defaultMcpCompanyProPayer()
  539. {
  540. return $this->hasOne(CompanyProPayer::class, 'id', 'default_mcp_company_pro_payer_id');
  541. }
  542. public function defaultMcpCompanyLocation()
  543. {
  544. return $this->hasOne(CompanyLocation::class, 'id', 'default_mcp_company_location_id');
  545. }
  546. public function hasNewNoteForPro($_pro) {
  547. $count = Note::where('client_id', $this->id)->where('hcp_pro_id', $_pro->id)->where('is_cancelled', false)->where('new_or_fu_or_na', 'NEW')->count();
  548. return !!$count;
  549. }
  550. public function recentNotes($_pro = null) {
  551. $notes = Note::where('client_id', $this->id)->where('is_cancelled', false);
  552. if($_pro) {
  553. $notes = $notes->where('hcp_pro_id', $_pro->id);
  554. }
  555. $notes = $notes->orderBy('effective_dateest', 'DESC')->limit(5)->get();
  556. return $notes;
  557. }
  558. public function cmMeasurementsMatrix($_careMonth = null) {
  559. $days = [];
  560. $matches = DB::select(
  561. "
  562. SELECT m.id AS measurement_id,
  563. m.uid AS measurement_uid,
  564. cm.id AS care_month_id,
  565. cm.uid AS care_month_uid,
  566. m.label,
  567. m.value,
  568. m.dbp_mm_hg,
  569. m.sbp_mm_hg,
  570. m.value_pulse,
  571. m.value_irregular,
  572. m.numeric_value,
  573. m.effective_date,
  574. m.ts,
  575. m.has_been_stamped_by_mcp,
  576. m.has_been_stamped_by_non_hcp
  577. FROM measurement m
  578. JOIN care_month cm ON m.care_month_id = cm.id
  579. WHERE m.care_month_id = :careMonthID
  580. AND m.label NOT IN ('SBP', 'DBP')
  581. AND m.bdt_measurement_id IS NOT NULL
  582. AND m.is_removed IS FALSE
  583. AND (m.is_cellular_zero = FALSE or m.is_cellular_zero IS NULL)
  584. AND m.ts IS NOT NULL
  585. AND m.client_bdt_measurement_id IS NOT NULL
  586. ORDER BY m.effective_date
  587. ",
  588. ['careMonthID' => $_careMonth->id]
  589. );
  590. foreach ($matches as $match) {
  591. $time = (floor($match->ts / 1000));
  592. $realTimezone = resolve_timezone('EASTERN');
  593. $date = new \DateTime("@$time");
  594. $date->setTimezone(new \DateTimeZone($realTimezone));
  595. $match->date = $date->format("m/d/Y");
  596. $match->dateYMD = $date->format("Y-m-d");
  597. $match->time = $date->format("h:i A");
  598. // get existing entries for listing
  599. $match->entries = CareMonthEntry::where('care_month_id', $match->care_month_id)
  600. ->where('is_removed', false)
  601. ->where('effective_date', $match->dateYMD)
  602. ->orderBy('created_at')
  603. ->get();
  604. if(!isset($days[$match->date])) {
  605. $days[$match->date] = [];
  606. }
  607. $days[$match->date][] = $match;
  608. }
  609. return $days;
  610. }
  611. }