helpers.php 24 KB

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