Client.php 21 KB

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