helpers.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tatu
  5. * Date: 6/23/20
  6. * Time: 12:10 AM
  7. */
  8. use App\Models\AppSession;
  9. use App\Models\Client;
  10. use App\Models\Pro;
  11. use App\Models\Bill;
  12. //require_once './class.Diff.php';
  13. use Soundasleep\Html2Text as Html2Text;
  14. if(!function_exists('toFeetAndInches')) {
  15. function toFeetAndInches($value, $ftLabel = ' ft.', $inLabel = ' in.') {
  16. if(!$value) return '-';
  17. $value = round($value);
  18. $ft = round(floor($value / 12));
  19. $in = $value % 12;
  20. return "$ft$ftLabel $in$inLabel";
  21. }
  22. }
  23. if(!function_exists('feetFromInches')) {
  24. function feetFromInches($value) {
  25. if(!$value) return 0;
  26. $value = round($value);
  27. return round(floor($value / 12));
  28. }
  29. }
  30. if(!function_exists('inchesAfterFeetFromInches')) {
  31. function inchesAfterFeetFromInches($value) {
  32. if(!$value) return 0;
  33. $value = round($value);
  34. return round($value % 12);
  35. }
  36. }
  37. if(!function_exists('genericBills')) {
  38. function genericBills(Pro $performerPro, $patient, $entityType, $entityUid) {
  39. $genericBills = Bill::where('bill_service_type', 'GENERIC');
  40. if($performerPro->pro_type !== 'ADMIN') {
  41. $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
  42. }
  43. if($patient) {
  44. $genericBills = $genericBills->where('client_id', $patient->id);
  45. }
  46. if($entityType && $entityUid) {
  47. $genericBills = $genericBills
  48. ->where('generic_target_entity_type', $entityType)
  49. ->where('generic_target_entity_uid', $entityUid);
  50. }
  51. return $genericBills->orderBy('created_at', 'DESC')->get();
  52. }
  53. }
  54. if(!function_exists('hasActiveGenericBill')) {
  55. function hasActiveGenericBill(Pro $performerPro, $patient, $entityType, $entityUid) {
  56. $genericBills = Bill::where('bill_service_type', 'GENERIC')->where('is_cancelled', false);
  57. if($performerPro->pro_type !== 'ADMIN') {
  58. $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
  59. }
  60. if($patient) {
  61. $genericBills = $genericBills->where('client_id', $patient->id);
  62. }
  63. if($entityType && $entityUid) {
  64. $genericBills = $genericBills
  65. ->where('generic_target_entity_type', $entityType)
  66. ->where('generic_target_entity_uid', $entityUid);
  67. }
  68. return $genericBills->count() > 0;
  69. }
  70. }
  71. if(!function_exists('queryLineExcept')) {
  72. function queryLineExcept($except = []) {
  73. $params = request()->all();
  74. $final = [];
  75. foreach ($params as $k => $v) {
  76. if(in_array($k, $except) === FALSE) {
  77. if(is_array($v)) $v = implode(',', $v);
  78. $final[] = "$k=" . urlencode($v);
  79. }
  80. }
  81. return implode('&', $final);
  82. }
  83. }
  84. if(!function_exists('sortColumnHead')) {
  85. function sortColumnHead($url, $label, $sortKey, $defaultDirection = 'ASC') {
  86. $currentSortKey = request()->input('sort');
  87. $currentDir = request()->input('dir');
  88. $targetDir = $currentDir ? ($currentDir === 'ASC' ? 'DESC' : 'ASC') : $defaultDirection;
  89. echo '<a href="' . $url . '?sort=' . $sortKey . '&dir=' . $targetDir . '&' . queryLineExcept(['sort', 'dir']) . '">' . $label . '</a>';
  90. if($currentSortKey === $sortKey) {
  91. if($currentDir === 'ASC') {
  92. echo "&nbsp;&nbsp;↑";
  93. }
  94. elseif($currentDir === 'DESC') {
  95. echo "&nbsp;&nbsp;↓";
  96. }
  97. }
  98. }
  99. }
  100. if(!function_exists('html2Text')) {
  101. function html2Text($old, $new){
  102. }
  103. }
  104. if(!function_exists('diff')) {
  105. function diff($old, $new){
  106. // return Diff::toHTML(Diff::compare($old, $new));
  107. }
  108. }
  109. if(!function_exists('get_current_session')) {
  110. function get_current_session(){
  111. return AppSession::where('session_key', request()->cookie('sessionKey'))->first();
  112. }
  113. }
  114. if(!function_exists('friendly_date_time')) {
  115. function friendly_date_time($value, $includeTime = true, $default = '-', $long_year=false) {
  116. if(!$value || empty($value)) return $default;
  117. try {
  118. $realTimezone = 'US/Eastern';
  119. $date = new DateTime($value);
  120. $date->setTimezone(new DateTimeZone($realTimezone));
  121. return $date->format("m/d/y" . ($includeTime ? ", h:ia" : "")) . ($includeTime ? ' EST' : '');
  122. /*$result = strtotime($value);
  123. if($long_year){
  124. $result = date("m/d/Y" . ($includeTime ? ", h:ia" : ""), $result);
  125. }else{
  126. $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
  127. }
  128. return $result;*/
  129. }
  130. catch (Exception $e) {
  131. return $value;
  132. }
  133. }
  134. }
  135. if(!function_exists('friendlier_date_time')) {
  136. function friendlier_date_time($value, $includeTime = true, $default = '-') {
  137. if(!$value || empty($value)) return $default;
  138. try {
  139. $realTimezone = 'US/Eastern';
  140. $date = new DateTime($value);
  141. $date->setTimezone(new DateTimeZone($realTimezone));
  142. return $date->format("m/d/y" . ($includeTime ? ", h:ia" : "")) . ($includeTime ? ' EST' : '');
  143. /*$result = strtotime($value);
  144. $result = date("m/d/Y" . ($includeTime ? ", h:i a" : ""), $result);
  145. return $result;*/
  146. }
  147. catch (Exception $e) {
  148. return $value;
  149. }
  150. }
  151. }
  152. if(!function_exists('friendly_date_time_short')) {
  153. function friendly_date_time_short($value, $includeTime = true, $default = '-') {
  154. if(!$value || empty($value)) return $default;
  155. try {
  156. $result = strtotime($value);
  157. $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
  158. return $result;
  159. }
  160. catch (Exception $e) {
  161. return $value;
  162. }
  163. }
  164. }
  165. if(!function_exists('friendly_date_time_short_with_tz')) {
  166. function friendly_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
  167. if(!$value || empty($value)) return $default;
  168. try {
  169. $realTimezone = resolve_timezone($tz);
  170. $date = new DateTime($value);
  171. $date->setTimezone(new DateTimeZone($realTimezone));
  172. return $date->format("m/d/y" . ($includeTime ? ", h:iA" : ""));
  173. }
  174. catch (Exception $e) {
  175. return $e->getMessage();
  176. }
  177. }
  178. }
  179. if(!function_exists('friendly_date_time_short_with_tz_from_timestamp')) {
  180. function friendly_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
  181. if(!$value || empty($value)) return $default;
  182. try {
  183. $realTimezone = resolve_timezone($tz);
  184. $date = new DateTime("@$value");
  185. $date->setTimezone(new DateTimeZone($realTimezone));
  186. return $date->format("m/d/y, h:iA");
  187. }
  188. catch (Exception $e) {
  189. return $e->getMessage();
  190. }
  191. }
  192. }
  193. if(!function_exists('postgres_date_time_short_with_tz')) {
  194. function postgres_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
  195. if(!$value || empty($value)) return $default;
  196. try {
  197. $realTimezone = resolve_timezone($tz);
  198. $date = new DateTime($value);
  199. $date->setTimezone(new DateTimeZone($realTimezone));
  200. return $date->format("Y-m-d" . ($includeTime ? " h:i:s" : ""));
  201. }
  202. catch (Exception $e) {
  203. return $e->getMessage();
  204. }
  205. }
  206. }
  207. if(!function_exists('postgres_date_time_short_with_tz_from_timestamp')) {
  208. function postgres_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
  209. if(!$value || empty($value)) return $default;
  210. try {
  211. $realTimezone = resolve_timezone($tz);
  212. $date = new DateTime("@$value");
  213. $date->setTimezone(new DateTimeZone($realTimezone));
  214. return $date->format("Y-m-d h:i:s");
  215. }
  216. catch (Exception $e) {
  217. return $e->getMessage();
  218. }
  219. }
  220. }
  221. if(!function_exists('friendly_date_time_short_with_tz_from_timestamp_divide1000')) {
  222. function friendly_date_time_short_with_tz_from_timestamp_divide1000($value, $tz='UTC', $default = '-') {
  223. if(!$value || empty($value)) return $default;
  224. try {
  225. $value = (floor($value / 1000));
  226. $realTimezone = resolve_timezone($tz);
  227. $date = new DateTime("@$value");
  228. $date->setTimezone(new DateTimeZone($realTimezone));
  229. return $date->format("m/d/y, h:iA");
  230. }
  231. catch (Exception $e) {
  232. return $e->getMessage();
  233. }
  234. }
  235. }
  236. if(!function_exists('friendly_date_short_with_tz_from_timestamp_divide1000')) {
  237. function friendly_date_short_with_tz_from_timestamp_divide1000($value, $tz='EASTERN', $default = '-') {
  238. if(!$value || empty($value)) return $default;
  239. try {
  240. $value = (floor($value / 1000));
  241. $realTimezone = resolve_timezone($tz);
  242. $date = new DateTime("@$value");
  243. $date->setTimezone(new DateTimeZone($realTimezone));
  244. return $date->format("m/d/y");
  245. }
  246. catch (Exception $e) {
  247. return $e->getMessage();
  248. }
  249. }
  250. }
  251. if(!function_exists('friendly_date')) {
  252. function friendly_date($value) {
  253. if(!$value || empty($value)) return '';
  254. try {
  255. $result = strtotime($value);
  256. $result = date("m/d/Y", $result);
  257. return $result;
  258. }
  259. catch (Exception $e) {
  260. return $value;
  261. }
  262. }
  263. }
  264. if(!function_exists('friendly_date_month_year')) {
  265. function friendly_date_month_year($value) {
  266. if(!$value || empty($value)) return '';
  267. try {
  268. $result = strtotime($value);
  269. $result = date("M Y", $result);
  270. return $result;
  271. }
  272. catch (Exception $e) {
  273. return $value;
  274. }
  275. }
  276. }
  277. if(!function_exists('friendlier_date')) {
  278. function friendlier_date($value) {
  279. if(!$value || empty($value)) return '';
  280. try {
  281. $result = strtotime($value);
  282. $result = date("m/d/Y", $result);
  283. return $result;
  284. }
  285. catch (Exception $e) {
  286. return $value;
  287. }
  288. }
  289. }
  290. if(!function_exists('relative_friendly_date')) {
  291. function relative_friendly_date($value) {
  292. if(!$value || empty($value)) return '';
  293. try {
  294. $result = date_diff(date_create($value), date_create('now'))->days;
  295. if ($result > 30) $result = date('F Y', strtotime($value));
  296. else if ($result > 1) $result .= ' days ago';
  297. else if ($result === 1) $result = 'Yesterday';
  298. else if ($result === 0) $result = 'Today';
  299. return $result;
  300. }
  301. catch (Exception $e) {
  302. return $value;
  303. }
  304. }
  305. }
  306. if(!function_exists('unfriendly_date')) {
  307. function unfriendly_date($value) {
  308. if(!$value || empty($value)) return '';
  309. try {
  310. $result = strtotime($value);
  311. $result = date("Y-m-d", $result);
  312. return $result;
  313. }
  314. catch (Exception $e) {
  315. return $value;
  316. }
  317. }
  318. }
  319. if(!function_exists('friendly_time')) {
  320. function friendly_time($value, $default = '-') {
  321. if(!$value || empty($value)) return $default;
  322. try {
  323. $result = strtotime($value);
  324. $result = date("h:i a", $result);
  325. return $result;
  326. }
  327. catch (Exception $e) {
  328. return $value;
  329. }
  330. }
  331. }
  332. if(!function_exists('military_time')) {
  333. function military_time($value, $tz='UTC', $default = '-') {
  334. if(!$value || empty($value)) return $default;
  335. try {
  336. $realTimezone = resolve_timezone($tz);
  337. $date = new DateTime($value);
  338. $date->setTimezone(new DateTimeZone($realTimezone));
  339. return $date->format("H:i");
  340. }
  341. catch (Exception $e) {
  342. return $value;
  343. }
  344. }
  345. }
  346. if(!function_exists('resolve_timezone')) {
  347. function resolve_timezone($value) {
  348. try {
  349. switch ($value) {
  350. case 'ALASKA': {
  351. return 'US/Alaska';
  352. }
  353. case 'CENTRAL': {
  354. return 'US/Central';
  355. }
  356. case 'EASTERN': {
  357. return 'US/Eastern';
  358. }
  359. case 'HAWAII': {
  360. return 'US/Hawaii';
  361. }
  362. case 'MOUNTAIN': {
  363. return 'US/Mountain';
  364. }
  365. case 'PACIFIC': {
  366. return 'US/Pacific';
  367. }
  368. case 'PUERTO_RICO': {
  369. return 'America/Puerto_Rico';
  370. }
  371. case 'UTC': {
  372. return 'UTC';
  373. }
  374. }
  375. }
  376. catch (Exception $e) {
  377. return $value;
  378. }
  379. }
  380. }
  381. // $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
  382. // echo $date->format('Y-m-d H:i:sP') . "\n";
  383. if(!function_exists('friendly_month')) {
  384. function friendly_month($value) {
  385. if(!$value || empty($value)) return "-";
  386. try {
  387. $result = strtotime($value);
  388. $result = date("F o", $result);
  389. return $result;
  390. }
  391. catch (Exception $e) {
  392. return $value;
  393. }
  394. }
  395. }
  396. if(!function_exists('day_part_from_date')) {
  397. function day_part_from_date($value) {
  398. if(!$value || empty($value)) return "-";
  399. try {
  400. $result = strtotime($value);
  401. $result = date("d", $result);
  402. return $result;
  403. }
  404. catch (Exception $e) {
  405. return $value;
  406. }
  407. }
  408. }
  409. if(!function_exists('month_part_from_date')) {
  410. function month_part_from_date($value) {
  411. if(!$value || empty($value)) return "-";
  412. try {
  413. $result = strtotime($value);
  414. $result = date("m", $result);
  415. return $result;
  416. }
  417. catch (Exception $e) {
  418. return $value;
  419. }
  420. }
  421. }
  422. if(!function_exists('year_part_from_date')) {
  423. function year_part_from_date($value) {
  424. if(!$value || empty($value)) return "-";
  425. try {
  426. $result = strtotime($value);
  427. $result = date("Y", $result);
  428. return $result;
  429. }
  430. catch (Exception $e) {
  431. return $value;
  432. }
  433. }
  434. }
  435. if(!function_exists('friendly_money')){
  436. function friendly_money($value){
  437. return number_format((float)$value, 2, '.', '');
  438. }
  439. }
  440. if(!function_exists('time_in_hrminsec')) {
  441. function time_in_hrminsec($value, $default = '-') {
  442. if(!$value || empty($value)) return $default;
  443. $value = intval($value);
  444. $minutes = intval($value / 60);
  445. $seconds = $value % 60;
  446. $hours = 0;
  447. if($minutes >= 60) {
  448. $hours = intval($minutes / 60);
  449. $minutes = $minutes % 60;
  450. }
  451. $output = [];
  452. if($hours > 0) {
  453. $output[] = "{$hours}h";
  454. }
  455. if($minutes > 0) {
  456. $output[] = "{$minutes}m";
  457. }
  458. if($seconds > 0) {
  459. $output[] = "{$seconds}s";
  460. }
  461. return implode(" ", $output);
  462. }
  463. }
  464. if(!function_exists('sanitize_field_name')) {
  465. function sanitize_field_name($name) {
  466. $result = strtolower($name);
  467. return preg_replace("/[^0-9a-z]/i", "_", $result);
  468. }
  469. }
  470. if(!function_exists('sanitize_state_name')) {
  471. function sanitize_state_name($name) {
  472. $result = strtolower($name);
  473. return ucwords(preg_replace("/_/i", " ", $result));
  474. }
  475. }
  476. if(!function_exists('renderNoteTemplate')) {
  477. function renderNoteTemplate($template, $topLevel)
  478. {
  479. echo
  480. '<div class="note-template-item" ' .
  481. 'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
  482. 'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
  483. '>' .
  484. '<div class="note-template-text d-flex align-items-center">' .
  485. '<span class="label">' .
  486. '<input type="checkbox" />' .
  487. '<span>' . $template->text . '</span>' .
  488. '</span>';
  489. if (isset($template->type) && $template->type === 'plus-minus') {
  490. echo '<div class="ml-auto mr-2 text-nowrap">';
  491. echo '<a href="#" class="plus-trigger"><i class="fa fa-plus-circle"></i></a>';
  492. echo '<a href="#" class="minus-trigger ml-1"><i class="fa fa-minus-circle"></i></a>';
  493. echo '</div>';
  494. }
  495. echo '</div>';
  496. if (isset($template->children) && count($template->children)) {
  497. echo '<i class="fa fa-chevron-right has-children"></i>';
  498. echo '<div class="note-template-children">';
  499. foreach ($template->children as $t) {
  500. renderNoteTemplate($t, false);
  501. }
  502. echo '</div>';
  503. } else if (isset($template->type) && $template->type !== 'plus-minus') {
  504. echo '<i class="fa fa-chevron-right has-children"></i>';
  505. echo '<div class="note-template-children">';
  506. if ($template->type === 'alpha') {
  507. echo '<textarea class="form-control form-control-sm"></textarea>';
  508. } else {
  509. echo '<input type="' . $template->type . '" class="form-control form-control-sm">';
  510. }
  511. echo '</div>';
  512. }
  513. echo '</div>';
  514. }
  515. }
  516. if(!function_exists('renderNoteTemplates')) {
  517. function renderNoteTemplates($path)
  518. {
  519. $templates = json_decode(file_get_contents($path));
  520. foreach ($templates->templates as $template) {
  521. renderNoteTemplate($template, true);
  522. }
  523. }
  524. }
  525. if(!function_exists('renderNoteExamTemplates')) {
  526. function renderNoteExamTemplates($parentPath, $childPath)
  527. {
  528. $templates = json_decode(file_get_contents($parentPath));
  529. $templates = $templates->templates;
  530. // override as needed with what is in template set
  531. if(file_exists($childPath)) {
  532. $orTemplates = json_decode(file_get_contents($parentPath));
  533. $orTemplates = $orTemplates->templates;
  534. for ($i = 0; $i < count($templates); $i++) {
  535. for ($j = 0; $j < count($orTemplates); $j++) {
  536. if($templates[$i]->text === $orTemplates[$j]->text) {
  537. $templates[$i] = $orTemplates[$j];
  538. }
  539. }
  540. }
  541. }
  542. foreach ($templates as $template) {
  543. renderNoteTemplate($template, true);
  544. }
  545. }
  546. }
  547. if(!function_exists('getVal')) {
  548. function getVal($object, $prop)
  549. {
  550. if (isset($object->$prop)) {
  551. return $object->$prop;
  552. } else {
  553. return '';
  554. }
  555. }
  556. }
  557. if(!function_exists('appTZtoPHPTZ')) {
  558. function appTZtoPHPTZ($_timezone)
  559. {
  560. switch ($_timezone) {
  561. case 'ALASKA':
  562. $timezone = "US/Alaska";
  563. break;
  564. case 'CENTRAL':
  565. $timezone = "US/Central";
  566. break;
  567. case 'HAWAII':
  568. $timezone = "US/Hawaii";
  569. break;
  570. case 'MOUNTAIN':
  571. $timezone = "US/Mountain";
  572. break;
  573. case 'PACIFIC':
  574. $timezone = "US/Pacific";
  575. break;
  576. case 'PUERTO_RICO':
  577. $timezone = "America/Puerto_Rico";
  578. break;
  579. default:
  580. $timezone = "US/Eastern";
  581. break;
  582. }
  583. return $timezone;
  584. }
  585. }
  586. if(!function_exists('convertToTimezone')) {
  587. function convertToTimezone($_dateTime, $_targetTimezone, $_sourceTimezone = 'UTC', $_returnRaw = false)
  588. {
  589. if (!$_dateTime) return $_dateTime;
  590. $date = new \DateTime($_dateTime, new \DateTimeZone($_sourceTimezone));
  591. $date->setTimezone(new \DateTimeZone(appTZtoPHPTZ($_targetTimezone)));
  592. return $_returnRaw ? $date : $date->format('Y-m-d H:i:s');
  593. }
  594. }
  595. if(!function_exists('minutes_to_hhmm')) {
  596. function minutes_to_hhmm($_minutes)
  597. {
  598. $h = intval(floor($_minutes / 60));
  599. $m = $_minutes;
  600. if($h > 0) {
  601. $m = $_minutes - $h * 60;
  602. }
  603. $h = ($h < 10 ? '0' : '') . $h;
  604. $m = ($m < 10 ? '0' : '') . $m;
  605. return $h . ':' . $m;
  606. }
  607. }
  608. if(!function_exists('vsValue')) {
  609. function vsValue($_v, $patient = null, $_direct = false)
  610. {
  611. if ($_direct) {
  612. return $_v ? $_v : '<span class="font-weight-normal text-info font-italic">empty</span>';
  613. }
  614. return @($patient->{$_v}) ? $patient->{$_v} : '<span class="font-weight-normal text-info font-italic">empty</span>';
  615. }
  616. }
  617. if(!function_exists('vsElement')) {
  618. function vsElement($_v, $type, $name, $patient, $class = '')
  619. {
  620. return '<input type="' . $type . '" class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  621. 'name="' . $name . '" ' .
  622. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  623. }
  624. }
  625. if(!function_exists('vsRoElement')) {
  626. function vsRoElement($_v, $type, $name, $patient, $class = '')
  627. {
  628. return '<input type="' . $type . '" readonly class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  629. 'name="' . $name . '" ' .
  630. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  631. }
  632. }
  633. if(!function_exists('str_compact')) {
  634. function str_compact($_str)
  635. {
  636. return preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($_str));
  637. }
  638. }
  639. if(!function_exists('noteMethodDisplay')) {
  640. function noteMethodDisplay($method)
  641. {
  642. if($method === 'IN_CLINIC') return 'In-Clinic';
  643. $method = str_replace('_', ' ', $method);
  644. return ucwords(strtolower($method));
  645. }
  646. }
  647. if(!function_exists('friendly_timezone')) {
  648. function friendly_timezone($tz) {
  649. $map = [
  650. 'EASTERN' => 'EST',
  651. 'CENTRAL' => 'CST',
  652. 'MOUNTAIN' => 'MST',
  653. 'PACIFIC' => 'PST',
  654. 'ALASKA' => 'AST',
  655. 'HAWAII' => 'HST',
  656. 'PUERTO_RICO' => 'PR'
  657. ];
  658. return $map[$tz] ?? str_replace("_", " ", $tz);
  659. }
  660. }