helpers.php 23 KB

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