helpers.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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('date_short_with_tz_from_timestamp_divide1000')) {
  266. function date_short_with_tz_from_timestamp_divide1000($value, $tz='EASTERN', $default = '-') {
  267. if(!$value || empty($value)) return $default;
  268. try {
  269. $value = (floor($value / 1000));
  270. $realTimezone = resolve_timezone($tz);
  271. $date = new DateTime("@$value");
  272. $date->setTimezone(new DateTimeZone($realTimezone));
  273. return $date->format("Y-m-d");
  274. }
  275. catch (Exception $e) {
  276. return $e->getMessage();
  277. }
  278. }
  279. }
  280. if(!function_exists('friendly_date')) {
  281. function friendly_date($value) {
  282. if(!$value || empty($value)) return '';
  283. try {
  284. $result = strtotime($value);
  285. $result = date("m/d/Y", $result);
  286. return $result;
  287. }
  288. catch (Exception $e) {
  289. return $value;
  290. }
  291. }
  292. }
  293. if(!function_exists('friendly_date_month_year')) {
  294. function friendly_date_month_year($value) {
  295. if(!$value || empty($value)) return '';
  296. try {
  297. $result = strtotime($value);
  298. $result = date("M Y", $result);
  299. return $result;
  300. }
  301. catch (Exception $e) {
  302. return $value;
  303. }
  304. }
  305. }
  306. if(!function_exists('friendlier_date')) {
  307. function friendlier_date($value) {
  308. if(!$value || empty($value)) return '';
  309. try {
  310. $result = strtotime($value);
  311. $result = date("m/d/Y", $result);
  312. return $result;
  313. }
  314. catch (Exception $e) {
  315. return $value;
  316. }
  317. }
  318. }
  319. if(!function_exists('relative_friendly_date')) {
  320. function relative_friendly_date($value) {
  321. if(!$value || empty($value)) return '';
  322. try {
  323. $result = date_diff(date_create($value), date_create('now'))->days;
  324. if ($result > 30) $result = date('F Y', strtotime($value));
  325. else if ($result > 1) $result .= ' days ago';
  326. else if ($result === 1) $result = 'Yesterday';
  327. else if ($result === 0) $result = 'Today';
  328. return $result;
  329. }
  330. catch (Exception $e) {
  331. return $value;
  332. }
  333. }
  334. }
  335. if(!function_exists('unfriendly_date')) {
  336. function unfriendly_date($value) {
  337. if(!$value || empty($value)) return '';
  338. try {
  339. $result = strtotime($value);
  340. $result = date("Y-m-d", $result);
  341. return $result;
  342. }
  343. catch (Exception $e) {
  344. return $value;
  345. }
  346. }
  347. }
  348. if(!function_exists('friendly_time')) {
  349. function friendly_time($value, $default = '-') {
  350. if(!$value || empty($value)) return $default;
  351. try {
  352. $result = strtotime($value);
  353. $result = date("h:i a", $result);
  354. return $result;
  355. }
  356. catch (Exception $e) {
  357. return $value;
  358. }
  359. }
  360. }
  361. if(!function_exists('military_time')) {
  362. function military_time($value, $tz='UTC', $default = '-') {
  363. if(!$value || empty($value)) return $default;
  364. try {
  365. $realTimezone = resolve_timezone($tz);
  366. $date = new DateTime($value);
  367. $date->setTimezone(new DateTimeZone($realTimezone));
  368. return $date->format("H:i");
  369. }
  370. catch (Exception $e) {
  371. return $value;
  372. }
  373. }
  374. }
  375. if(!function_exists('resolve_timezone')) {
  376. function resolve_timezone($value) {
  377. try {
  378. switch ($value) {
  379. case 'ALASKA': {
  380. return 'US/Alaska';
  381. }
  382. case 'CENTRAL': {
  383. return 'US/Central';
  384. }
  385. case 'EASTERN': {
  386. return 'US/Eastern';
  387. }
  388. case 'HAWAII': {
  389. return 'US/Hawaii';
  390. }
  391. case 'MOUNTAIN': {
  392. return 'US/Mountain';
  393. }
  394. case 'PACIFIC': {
  395. return 'US/Pacific';
  396. }
  397. case 'PUERTO_RICO': {
  398. return 'America/Puerto_Rico';
  399. }
  400. case 'UTC': {
  401. return 'UTC';
  402. }
  403. }
  404. }
  405. catch (Exception $e) {
  406. return $value;
  407. }
  408. }
  409. }
  410. // $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
  411. // echo $date->format('Y-m-d H:i:sP') . "\n";
  412. if(!function_exists('friendly_month')) {
  413. function friendly_month($value) {
  414. if(!$value || empty($value)) return "-";
  415. try {
  416. $result = strtotime($value);
  417. $result = date("F o", $result);
  418. return $result;
  419. }
  420. catch (Exception $e) {
  421. return $value;
  422. }
  423. }
  424. }
  425. if(!function_exists('day_part_from_date')) {
  426. function day_part_from_date($value) {
  427. if(!$value || empty($value)) return "-";
  428. try {
  429. $result = strtotime($value);
  430. $result = date("d", $result);
  431. return $result;
  432. }
  433. catch (Exception $e) {
  434. return $value;
  435. }
  436. }
  437. }
  438. if(!function_exists('month_part_from_date')) {
  439. function month_part_from_date($value) {
  440. if(!$value || empty($value)) return "-";
  441. try {
  442. $result = strtotime($value);
  443. $result = date("m", $result);
  444. return $result;
  445. }
  446. catch (Exception $e) {
  447. return $value;
  448. }
  449. }
  450. }
  451. if(!function_exists('year_part_from_date')) {
  452. function year_part_from_date($value) {
  453. if(!$value || empty($value)) return "-";
  454. try {
  455. $result = strtotime($value);
  456. $result = date("Y", $result);
  457. return $result;
  458. }
  459. catch (Exception $e) {
  460. return $value;
  461. }
  462. }
  463. }
  464. if(!function_exists('friendly_money')){
  465. function friendly_money($value){
  466. return number_format((float)$value, 2, '.', '');
  467. }
  468. }
  469. if(!function_exists('time_in_hrminsec')) {
  470. function time_in_hrminsec($value, $default = '-') {
  471. if(!$value || empty($value)) return $default;
  472. $value = intval($value);
  473. $minutes = intval($value / 60);
  474. $seconds = $value % 60;
  475. $hours = 0;
  476. if($minutes >= 60) {
  477. $hours = intval($minutes / 60);
  478. $minutes = $minutes % 60;
  479. }
  480. $output = [];
  481. if($hours > 0) {
  482. $output[] = "{$hours}h";
  483. }
  484. if($minutes > 0) {
  485. $output[] = "{$minutes}m";
  486. }
  487. if($seconds > 0) {
  488. $output[] = "{$seconds}s";
  489. }
  490. return implode(" ", $output);
  491. }
  492. }
  493. if(!function_exists('sanitize_field_name')) {
  494. function sanitize_field_name($name) {
  495. $result = strtolower($name);
  496. return preg_replace("/[^0-9a-z]/i", "_", $result);
  497. }
  498. }
  499. if(!function_exists('sanitize_state_name')) {
  500. function sanitize_state_name($name) {
  501. $result = strtolower($name);
  502. return ucwords(preg_replace("/_/i", " ", $result));
  503. }
  504. }
  505. if(!function_exists('renderNoteTemplate')) {
  506. function renderNoteTemplate($template, $topLevel)
  507. {
  508. echo
  509. '<div class="note-template-item" ' .
  510. 'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
  511. 'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
  512. '>' .
  513. '<div class="note-template-text d-flex align-items-center">' .
  514. '<span class="label">' .
  515. '<input type="checkbox" />' .
  516. '<span>' . $template->text . '</span>' .
  517. '</span>';
  518. if (isset($template->type) && $template->type === 'plus-minus') {
  519. echo '<div class="ml-auto mr-2 text-nowrap">';
  520. echo '<a href="#" class="plus-trigger"><i class="fa fa-plus-circle"></i></a>';
  521. echo '<a href="#" class="minus-trigger ml-1"><i class="fa fa-minus-circle"></i></a>';
  522. echo '</div>';
  523. }
  524. echo '</div>';
  525. if (isset($template->children) && count($template->children)) {
  526. echo '<i class="fa fa-chevron-right has-children"></i>';
  527. echo '<div class="note-template-children">';
  528. foreach ($template->children as $t) {
  529. renderNoteTemplate($t, false);
  530. }
  531. echo '</div>';
  532. } else if (isset($template->type) && $template->type !== 'plus-minus') {
  533. echo '<i class="fa fa-chevron-right has-children"></i>';
  534. echo '<div class="note-template-children">';
  535. if ($template->type === 'alpha') {
  536. echo '<textarea class="form-control form-control-sm"></textarea>';
  537. } else {
  538. echo '<input type="' . $template->type . '" class="form-control form-control-sm">';
  539. }
  540. echo '</div>';
  541. }
  542. echo '</div>';
  543. }
  544. }
  545. if(!function_exists('renderNoteTemplates')) {
  546. function renderNoteTemplates($path)
  547. {
  548. $templates = json_decode(file_get_contents($path));
  549. foreach ($templates->templates as $template) {
  550. renderNoteTemplate($template, true);
  551. }
  552. }
  553. }
  554. if(!function_exists('renderNoteExamTemplates')) {
  555. function renderNoteExamTemplates($parentPath, $childPath)
  556. {
  557. $templates = json_decode(file_get_contents($parentPath));
  558. $templates = $templates->templates;
  559. // override as needed with what is in template set
  560. if(file_exists($childPath)) {
  561. $orTemplates = json_decode(file_get_contents($parentPath));
  562. $orTemplates = $orTemplates->templates;
  563. for ($i = 0; $i < count($templates); $i++) {
  564. for ($j = 0; $j < count($orTemplates); $j++) {
  565. if($templates[$i]->text === $orTemplates[$j]->text) {
  566. $templates[$i] = $orTemplates[$j];
  567. }
  568. }
  569. }
  570. }
  571. foreach ($templates as $template) {
  572. renderNoteTemplate($template, true);
  573. }
  574. }
  575. }
  576. if(!function_exists('getVal')) {
  577. function getVal($object, $prop)
  578. {
  579. if (isset($object->$prop)) {
  580. return $object->$prop;
  581. } else {
  582. return '';
  583. }
  584. }
  585. }
  586. if(!function_exists('appTZtoPHPTZ')) {
  587. function appTZtoPHPTZ($_timezone)
  588. {
  589. switch ($_timezone) {
  590. case 'ALASKA':
  591. $timezone = "US/Alaska";
  592. break;
  593. case 'CENTRAL':
  594. $timezone = "US/Central";
  595. break;
  596. case 'HAWAII':
  597. $timezone = "US/Hawaii";
  598. break;
  599. case 'MOUNTAIN':
  600. $timezone = "US/Mountain";
  601. break;
  602. case 'PACIFIC':
  603. $timezone = "US/Pacific";
  604. break;
  605. case 'PUERTO_RICO':
  606. $timezone = "America/Puerto_Rico";
  607. break;
  608. default:
  609. $timezone = "US/Eastern";
  610. break;
  611. }
  612. return $timezone;
  613. }
  614. }
  615. if(!function_exists('convertToTimezone')) {
  616. function convertToTimezone($_dateTime, $_targetTimezone, $_sourceTimezone = 'UTC', $_returnRaw = false)
  617. {
  618. if (!$_dateTime) return $_dateTime;
  619. $date = new \DateTime($_dateTime, new \DateTimeZone($_sourceTimezone));
  620. $date->setTimezone(new \DateTimeZone(appTZtoPHPTZ($_targetTimezone)));
  621. return $_returnRaw ? $date : $date->format('Y-m-d H:i:s');
  622. }
  623. }
  624. if(!function_exists('minutes_to_hhmm')) {
  625. function minutes_to_hhmm($_minutes)
  626. {
  627. $h = intval(floor($_minutes / 60));
  628. $m = $_minutes;
  629. if($h > 0) {
  630. $m = $_minutes - $h * 60;
  631. }
  632. $h = ($h < 10 ? '0' : '') . $h;
  633. $m = ($m < 10 ? '0' : '') . $m;
  634. return $h . ':' . $m;
  635. }
  636. }
  637. if(!function_exists('vsValue')) {
  638. function vsValue($_v, $patient = null, $_direct = false)
  639. {
  640. if ($_direct) {
  641. return $_v ? $_v : '<span class="font-weight-normal text-info font-italic">empty</span>';
  642. }
  643. return @($patient->{$_v}) ? $patient->{$_v} : '<span class="font-weight-normal text-info font-italic">empty</span>';
  644. }
  645. }
  646. if(!function_exists('vsElement')) {
  647. function vsElement($_v, $type, $name, $patient, $class = '')
  648. {
  649. return '<input type="' . $type . '" class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  650. 'name="' . $name . '" ' .
  651. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  652. }
  653. }
  654. if(!function_exists('vsRoElement')) {
  655. function vsRoElement($_v, $type, $name, $patient, $class = '')
  656. {
  657. return '<input type="' . $type . '" readonly class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
  658. 'name="' . $name . '" ' .
  659. 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
  660. }
  661. }
  662. if(!function_exists('str_compact')) {
  663. function str_compact($_str)
  664. {
  665. return preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($_str));
  666. }
  667. }
  668. if(!function_exists('noteMethodDisplay')) {
  669. function noteMethodDisplay($method)
  670. {
  671. if($method === 'IN_CLINIC') return 'In-Clinic';
  672. $method = str_replace('_', ' ', $method);
  673. return ucwords(strtolower($method));
  674. }
  675. }
  676. if(!function_exists('friendly_timezone')) {
  677. function friendly_timezone($tz) {
  678. $map = [
  679. 'EASTERN' => 'EST',
  680. 'CENTRAL' => 'CST',
  681. 'MOUNTAIN' => 'MST',
  682. 'PACIFIC' => 'PST',
  683. 'ALASKA' => 'AST',
  684. 'HAWAII' => 'HST',
  685. 'PUERTO_RICO' => 'PR'
  686. ];
  687. return $map[$tz] ?? str_replace("_", " ", $tz);
  688. }
  689. }
  690. if(!function_exists('segment_template_summary_value_display')) {
  691. function segment_template_summary_value_display($value, $default='________', $class = '') {
  692. if($value && strlen($value)) return '<span class="segment-template-summary-value '.$class.'">' . $value . '</span>';
  693. return $default;
  694. }
  695. }