helpers.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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('get_current_date')) {
  115. function get_current_date($timezone = null){
  116. if(!$timezone){
  117. $timezone = 'US\Eastern';
  118. }
  119. $date = new DateTime("now", new DateTimeZone('US/Eastern') );
  120. return $date->format('Y-m-d');
  121. }
  122. }
  123. if(!function_exists('friendly_date_time')) {
  124. function friendly_date_time($value, $includeTime = true, $default = '-', $long_year=false) {
  125. if(!$value || empty($value)) return $default;
  126. try {
  127. if($includeTime) {
  128. $realTimezone = 'US/Eastern';
  129. $date = new DateTime($value);
  130. $date->setTimezone(new DateTimeZone($realTimezone));
  131. return $date->format("m/d/y" . ($includeTime ? ", h:ia" : "")) . ($includeTime ? ' EST' : '');
  132. }
  133. else {
  134. $result = strtotime($value);
  135. if($long_year){
  136. $result = date("m/d/Y" . ($includeTime ? ", h:ia" : ""), $result);
  137. }else{
  138. $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
  139. }
  140. return $result;
  141. }
  142. }
  143. catch (Exception $e) {
  144. return $value;
  145. }
  146. }
  147. }
  148. if(!function_exists('friendlier_date_time')) {
  149. function friendlier_date_time($value, $includeTime = true, $default = '-') {
  150. return friendly_date_time($value, $includeTime, $default);
  151. }
  152. }
  153. if(!function_exists('friendly_date_time_short')) {
  154. function friendly_date_time_short($value, $includeTime = true, $default = '-') {
  155. if(!$value || empty($value)) return $default;
  156. try {
  157. $result = strtotime($value);
  158. $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
  159. return $result;
  160. }
  161. catch (Exception $e) {
  162. return $value;
  163. }
  164. }
  165. }
  166. if(!function_exists('friendly_date_time_short_with_tz')) {
  167. function friendly_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
  168. if(!$value || empty($value)) return $default;
  169. try {
  170. $realTimezone = resolve_timezone($tz);
  171. $date = new DateTime($value);
  172. $date->setTimezone(new DateTimeZone($realTimezone));
  173. return $date->format("m/d/y" . ($includeTime ? ", h:iA" : ""));
  174. }
  175. catch (Exception $e) {
  176. return $e->getMessage();
  177. }
  178. }
  179. }
  180. if(!function_exists('friendly_date_time_short_with_tz_from_timestamp')) {
  181. function friendly_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
  182. if(!$value || empty($value)) return $default;
  183. try {
  184. $realTimezone = resolve_timezone($tz);
  185. $date = new DateTime("@$value");
  186. $date->setTimezone(new DateTimeZone($realTimezone));
  187. return $date->format("m/d/y, h:iA");
  188. }
  189. catch (Exception $e) {
  190. return $e->getMessage();
  191. }
  192. }
  193. }
  194. if(!function_exists('postgres_date_time_short_with_tz')) {
  195. function postgres_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
  196. if(!$value || empty($value)) return $default;
  197. try {
  198. $realTimezone = resolve_timezone($tz);
  199. $date = new DateTime($value);
  200. $date->setTimezone(new DateTimeZone($realTimezone));
  201. return $date->format("Y-m-d" . ($includeTime ? " h:i:s" : ""));
  202. }
  203. catch (Exception $e) {
  204. return $e->getMessage();
  205. }
  206. }
  207. }
  208. if(!function_exists('postgres_date_time_short_with_tz_from_timestamp')) {
  209. function postgres_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
  210. if(!$value || empty($value)) return $default;
  211. try {
  212. $realTimezone = resolve_timezone($tz);
  213. $date = new DateTime("@$value");
  214. $date->setTimezone(new DateTimeZone($realTimezone));
  215. return $date->format("Y-m-d h:i:s");
  216. }
  217. catch (Exception $e) {
  218. return $e->getMessage();
  219. }
  220. }
  221. }
  222. if(!function_exists('friendly_date_time_short_with_tz_from_timestamp_divide1000')) {
  223. function friendly_date_time_short_with_tz_from_timestamp_divide1000($value, $tz='UTC', $default = '-') {
  224. if(!$value || empty($value)) return $default;
  225. try {
  226. $value = (floor($value / 1000));
  227. $realTimezone = resolve_timezone($tz);
  228. $date = new DateTime("@$value");
  229. $date->setTimezone(new DateTimeZone($realTimezone));
  230. return $date->format("m/d/y, h:iA");
  231. }
  232. catch (Exception $e) {
  233. return $e->getMessage();
  234. }
  235. }
  236. }
  237. if(!function_exists('friendly_date_short_with_tz_from_timestamp_divide1000')) {
  238. function friendly_date_short_with_tz_from_timestamp_divide1000($value, $tz='EASTERN', $default = '-') {
  239. if(!$value || empty($value)) return $default;
  240. try {
  241. $value = (floor($value / 1000));
  242. $realTimezone = resolve_timezone($tz);
  243. $date = new DateTime("@$value");
  244. $date->setTimezone(new DateTimeZone($realTimezone));
  245. return $date->format("m/d/y");
  246. }
  247. catch (Exception $e) {
  248. return $e->getMessage();
  249. }
  250. }
  251. }
  252. if(!function_exists('friendly_date')) {
  253. function friendly_date($value) {
  254. if(!$value || empty($value)) return '';
  255. try {
  256. $result = strtotime($value);
  257. $result = date("m/d/Y", $result);
  258. return $result;
  259. }
  260. catch (Exception $e) {
  261. return $value;
  262. }
  263. }
  264. }
  265. if(!function_exists('friendly_date_month_year')) {
  266. function friendly_date_month_year($value) {
  267. if(!$value || empty($value)) return '';
  268. try {
  269. $result = strtotime($value);
  270. $result = date("M Y", $result);
  271. return $result;
  272. }
  273. catch (Exception $e) {
  274. return $value;
  275. }
  276. }
  277. }
  278. if(!function_exists('friendlier_date')) {
  279. function friendlier_date($value) {
  280. if(!$value || empty($value)) return '';
  281. try {
  282. $result = strtotime($value);
  283. $result = date("m/d/Y", $result);
  284. return $result;
  285. }
  286. catch (Exception $e) {
  287. return $value;
  288. }
  289. }
  290. }
  291. if(!function_exists('relative_friendly_date')) {
  292. function relative_friendly_date($value) {
  293. if(!$value || empty($value)) return '';
  294. try {
  295. $result = date_diff(date_create($value), date_create('now'))->days;
  296. if ($result > 30) $result = date('F Y', strtotime($value));
  297. else if ($result > 1) $result .= ' days ago';
  298. else if ($result === 1) $result = 'Yesterday';
  299. else if ($result === 0) $result = 'Today';
  300. return $result;
  301. }
  302. catch (Exception $e) {
  303. return $value;
  304. }
  305. }
  306. }
  307. if(!function_exists('unfriendly_date')) {
  308. function unfriendly_date($value) {
  309. if(!$value || empty($value)) return '';
  310. try {
  311. $result = strtotime($value);
  312. $result = date("Y-m-d", $result);
  313. return $result;
  314. }
  315. catch (Exception $e) {
  316. return $value;
  317. }
  318. }
  319. }
  320. if(!function_exists('friendly_time')) {
  321. function friendly_time($value, $default = '-') {
  322. if(!$value || empty($value)) return $default;
  323. try {
  324. $result = strtotime($value);
  325. $result = date("h:i a", $result);
  326. return $result;
  327. }
  328. catch (Exception $e) {
  329. return $value;
  330. }
  331. }
  332. }
  333. if(!function_exists('military_time')) {
  334. function military_time($value, $tz='UTC', $default = '-') {
  335. if(!$value || empty($value)) return $default;
  336. try {
  337. $realTimezone = resolve_timezone($tz);
  338. $date = new DateTime($value);
  339. $date->setTimezone(new DateTimeZone($realTimezone));
  340. return $date->format("H:i");
  341. }
  342. catch (Exception $e) {
  343. return $value;
  344. }
  345. }
  346. }
  347. if(!function_exists('resolve_timezone')) {
  348. function resolve_timezone($value) {
  349. try {
  350. switch ($value) {
  351. case 'ALASKA': {
  352. return 'US/Alaska';
  353. }
  354. case 'CENTRAL': {
  355. return 'US/Central';
  356. }
  357. case 'EASTERN': {
  358. return 'US/Eastern';
  359. }
  360. case 'HAWAII': {
  361. return 'US/Hawaii';
  362. }
  363. case 'MOUNTAIN': {
  364. return 'US/Mountain';
  365. }
  366. case 'PACIFIC': {
  367. return 'US/Pacific';
  368. }
  369. case 'PUERTO_RICO': {
  370. return 'America/Puerto_Rico';
  371. }
  372. case 'UTC': {
  373. return 'UTC';
  374. }
  375. }
  376. }
  377. catch (Exception $e) {
  378. return $value;
  379. }
  380. }
  381. }
  382. // $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
  383. // echo $date->format('Y-m-d H:i:sP') . "\n";
  384. if(!function_exists('friendly_month')) {
  385. function friendly_month($value) {
  386. if(!$value || empty($value)) return "-";
  387. try {
  388. $result = strtotime($value);
  389. $result = date("F o", $result);
  390. return $result;
  391. }
  392. catch (Exception $e) {
  393. return $value;
  394. }
  395. }
  396. }
  397. if(!function_exists('day_part_from_date')) {
  398. function day_part_from_date($value) {
  399. if(!$value || empty($value)) return "-";
  400. try {
  401. $result = strtotime($value);
  402. $result = date("d", $result);
  403. return $result;
  404. }
  405. catch (Exception $e) {
  406. return $value;
  407. }
  408. }
  409. }
  410. if(!function_exists('month_part_from_date')) {
  411. function month_part_from_date($value) {
  412. if(!$value || empty($value)) return "-";
  413. try {
  414. $result = strtotime($value);
  415. $result = date("m", $result);
  416. return $result;
  417. }
  418. catch (Exception $e) {
  419. return $value;
  420. }
  421. }
  422. }
  423. if(!function_exists('year_part_from_date')) {
  424. function year_part_from_date($value) {
  425. if(!$value || empty($value)) return "-";
  426. try {
  427. $result = strtotime($value);
  428. $result = date("Y", $result);
  429. return $result;
  430. }
  431. catch (Exception $e) {
  432. return $value;
  433. }
  434. }
  435. }
  436. if(!function_exists('friendly_money')){
  437. function friendly_money($value){
  438. return number_format((float)$value, 2, '.', '');
  439. }
  440. }
  441. if(!function_exists('time_in_hrminsec')) {
  442. function time_in_hrminsec($value, $default = '-') {
  443. if(!$value || empty($value)) return $default;
  444. $value = intval($value);
  445. $minutes = intval($value / 60);
  446. $seconds = $value % 60;
  447. $hours = 0;
  448. if($minutes >= 60) {
  449. $hours = intval($minutes / 60);
  450. $minutes = $minutes % 60;
  451. }
  452. $output = [];
  453. if($hours > 0) {
  454. $output[] = "{$hours}h";
  455. }
  456. if($minutes > 0) {
  457. $output[] = "{$minutes}m";
  458. }
  459. if($seconds > 0) {
  460. $output[] = "{$seconds}s";
  461. }
  462. return implode(" ", $output);
  463. }
  464. }
  465. if(!function_exists('sanitize_field_name')) {
  466. function sanitize_field_name($name) {
  467. $result = strtolower($name);
  468. return preg_replace("/[^0-9a-z]/i", "_", $result);
  469. }
  470. }
  471. if(!function_exists('sanitize_state_name')) {
  472. function sanitize_state_name($name) {
  473. $result = strtolower($name);
  474. return ucwords(preg_replace("/_/i", " ", $result));
  475. }
  476. }
  477. if(!function_exists('renderNoteTemplate')) {
  478. function renderNoteTemplate($template, $topLevel)
  479. {
  480. echo
  481. '<div class="note-template-item" ' .
  482. 'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
  483. 'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
  484. '>' .
  485. '<div class="note-template-text d-flex align-items-center">' .
  486. '<span class="label">' .
  487. '<input type="checkbox" />' .
  488. '<span>' . $template->text . '</span>' .
  489. '</span>';
  490. if (isset($template->type) && $template->type === 'plus-minus') {
  491. echo '<div class="ml-auto mr-2 text-nowrap">';
  492. echo '<a href="#" class="plus-trigger"><i class="fa fa-plus-circle"></i></a>';
  493. echo '<a href="#" class="minus-trigger ml-1"><i class="fa fa-minus-circle"></i></a>';
  494. echo '</div>';
  495. }
  496. echo '</div>';
  497. if (isset($template->children) && count($template->children)) {
  498. echo '<i class="fa fa-chevron-right has-children"></i>';
  499. echo '<div class="note-template-children">';
  500. foreach ($template->children as $t) {
  501. renderNoteTemplate($t, false);
  502. }
  503. echo '</div>';
  504. } else if (isset($template->type) && $template->type !== 'plus-minus') {
  505. echo '<i class="fa fa-chevron-right has-children"></i>';
  506. echo '<div class="note-template-children">';
  507. if ($template->type === 'alpha') {
  508. echo '<textarea class="form-control form-control-sm"></textarea>';
  509. } else {
  510. echo '<input type="' . $template->type . '" class="form-control form-control-sm">';
  511. }
  512. echo '</div>';
  513. }
  514. echo '</div>';
  515. }
  516. }
  517. if(!function_exists('renderNoteTemplates')) {
  518. function renderNoteTemplates($path)
  519. {
  520. $templates = json_decode(file_get_contents($path));
  521. foreach ($templates->templates as $template) {
  522. renderNoteTemplate($template, true);
  523. }
  524. }
  525. }
  526. if(!function_exists('renderNoteExamTemplates')) {
  527. function renderNoteExamTemplates($parentPath, $childPath)
  528. {
  529. $templates = json_decode(file_get_contents($parentPath));
  530. $templates = $templates->templates;
  531. // override as needed with what is in template set
  532. if(file_exists($childPath)) {
  533. $orTemplates = json_decode(file_get_contents($parentPath));
  534. $orTemplates = $orTemplates->templates;
  535. for ($i = 0; $i < count($templates); $i++) {
  536. for ($j = 0; $j < count($orTemplates); $j++) {
  537. if($templates[$i]->text === $orTemplates[$j]->text) {
  538. $templates[$i] = $orTemplates[$j];
  539. }
  540. }
  541. }
  542. }
  543. foreach ($templates as $template) {
  544. renderNoteTemplate($template, true);
  545. }
  546. }
  547. }
  548. if(!function_exists('getVal')) {
  549. function getVal($object, $prop)
  550. {
  551. if (isset($object->$prop)) {
  552. return $object->$prop;
  553. } else {
  554. return '';
  555. }
  556. }
  557. }
  558. if(!function_exists('appTZtoPHPTZ')) {
  559. function appTZtoPHPTZ($_timezone)
  560. {
  561. switch ($_timezone) {
  562. case 'ALASKA':
  563. $timezone = "US/Alaska";
  564. break;
  565. case 'CENTRAL':
  566. $timezone = "US/Central";
  567. break;
  568. case 'HAWAII':
  569. $timezone = "US/Hawaii";
  570. break;
  571. case 'MOUNTAIN':
  572. $timezone = "US/Mountain";
  573. break;
  574. case 'PACIFIC':
  575. $timezone = "US/Pacific";
  576. break;
  577. case 'PUERTO_RICO':
  578. $timezone = "America/Puerto_Rico";
  579. break;
  580. default:
  581. $timezone = "US/Eastern";
  582. break;
  583. }
  584. return $timezone;
  585. }
  586. }
  587. if(!function_exists('convertToTimezone')) {
  588. function convertToTimezone($_dateTime, $_targetTimezone, $_sourceTimezone = 'UTC', $_returnRaw = false)
  589. {
  590. if (!$_dateTime) return $_dateTime;
  591. $date = new \DateTime($_dateTime, new \DateTimeZone($_sourceTimezone));
  592. $date->setTimezone(new \DateTimeZone(appTZtoPHPTZ($_targetTimezone)));
  593. return $_returnRaw ? $date : $date->format('Y-m-d H:i:s');
  594. }
  595. }
  596. if(!function_exists('minutes_to_hhmm')) {
  597. function minutes_to_hhmm($_minutes)
  598. {
  599. $h = intval(floor($_minutes / 60));
  600. $m = $_minutes;
  601. if($h > 0) {
  602. $m = $_minutes - $h * 60;
  603. }
  604. $h = ($h < 10 ? '0' : '') . $h;
  605. $m = ($m < 10 ? '0' : '') . $m;
  606. return $h . ':' . $m;
  607. }
  608. }
  609. if(!function_exists('vsValue')) {
  610. function vsValue($_v, $patient = null, $_direct = false)
  611. {
  612. if ($_direct) {
  613. return $_v ? $_v : '<span class="font-weight-normal text-info font-italic">empty</span>';
  614. }
  615. return @($patient->{$_v}) ? $patient->{$_v} : '<span class="font-weight-normal text-info font-italic">empty</span>';
  616. }
  617. }
  618. if(!function_exists('vsElement')) {
  619. function vsElement($_v, $type, $name, $patient, $class = '')
  620. {
  621. return '<input type="' . $type . '" class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  622. 'name="' . $name . '" ' .
  623. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  624. }
  625. }
  626. if(!function_exists('vsRoElement')) {
  627. function vsRoElement($_v, $type, $name, $patient, $class = '')
  628. {
  629. return '<input type="' . $type . '" readonly class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  630. 'name="' . $name . '" ' .
  631. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  632. }
  633. }
  634. if(!function_exists('str_compact')) {
  635. function str_compact($_str)
  636. {
  637. return preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($_str));
  638. }
  639. }
  640. if(!function_exists('noteMethodDisplay')) {
  641. function noteMethodDisplay($method)
  642. {
  643. if($method === 'IN_CLINIC') return 'In-Clinic';
  644. $method = str_replace('_', ' ', $method);
  645. return ucwords(strtolower($method));
  646. }
  647. }
  648. if(!function_exists('friendly_timezone')) {
  649. function friendly_timezone($tz) {
  650. $map = [
  651. 'EASTERN' => 'EST',
  652. 'CENTRAL' => 'CST',
  653. 'MOUNTAIN' => 'MST',
  654. 'PACIFIC' => 'PST',
  655. 'ALASKA' => 'AST',
  656. 'HAWAII' => 'HST',
  657. 'PUERTO_RICO' => 'PR'
  658. ];
  659. return $map[$tz] ?? str_replace("_", " ", $tz);
  660. }
  661. }
  662. if(!function_exists('segment_template_summary_value_display')) {
  663. function segment_template_summary_value_display($value, $default='________', $class = '') {
  664. if($value && strlen($value)) return '<span class="segment-template-summary-value '.$class.'">' . $value . '</span>';
  665. return $default;
  666. }
  667. }