12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109 |
- <?php
- /**
- * Created by PhpStorm.
- * User: tatu
- * Date: 6/23/20
- * Time: 12:10 AM
- */
- use App\Models\AppSession;
- use App\Models\Client;
- use App\Models\Pro;
- use App\Models\Bill;
- //require_once './class.Diff.php';
- use Illuminate\Support\Facades\Http;
- use Soundasleep\Html2Text as Html2Text;
- if(!function_exists('chargeForCPT')) {
- function chargeForCPT($cpt) {
- switch($cpt) {
- case "99202": return '$' . 172;
- case "99203": return '$' . 262;
- case "99204": return '$' . 387;
- case "99205": return '$' . 512;
- case "99211": return '$' . 56;
- case "99212": return '$' . 133;
- case "99213": return '$' . 212;
- case "99214": return '$' . 297;
- case "99215": return '$' . 418;
- case "99354": return '$' . 289;
- case "G0506": return '$' . 144;
- case "99441": return '$' . 132;
- case "99442": return '$' . 211;
- case "99443": return '$' . 297;
- case "99454": return '$' . 138;
- case "99457": return '$' . 117;
- case "99458": return '$' . 93;
- case "90791": return '$' . 394;
- case "90792": return '$' . 444;
- case "90832": return '$' . 171;
- case "90834": return '$' . 226;
- case "90837": return '$' . 332;
- case "90833": return '$' . 158;
- case "90836": return '$' . 199;
- case "90838": return '$' . 261;
- case "99355": return '$' . 130;
- case "97802": return '$' . 60;
- case "97803": return '$' . 50;
- case "99495": return '$' . 275;
- case "99406": return '$' . 35.56;
- case "99091": return '$' . 75;
- case "99453": return '$' . 40;
- }
-
- return '-';
- }
- }
- if(!function_exists('currentSortForKey')) {
- function currentSortForKey($current, $key) {
- $found = false;
- $current = $current ? $current : [];
- for ($i = 0; $i < count($current); $i++) {
- if($current[$i]['key'] === $key) { // if exists, reverse
- return ["index" => ($i + 1), "order" => $current[$i]['order']];
- }
- }
- return FALSE;
- }
- }
- if(!function_exists('includeOrReverseInMultiSort')) {
- function includeOrReverseInMultiSort($current, $key) {
- $found = false;
- $current = $current ? $current : [];
- for ($i = 0; $i < count($current); $i++) {
- if($current[$i]['key'] === $key) { // if exists, reverse
- $current[$i]['order'] = ($current[$i]['order'] === 'DESC' ? 'ASC' : 'DESC');
- $found = true;
- break;
- }
- }
- if (!$found) { // if not exists, include
- $current[] = ["key" => $key, "order" => 'ASC'];
- }
- return $current;
- }
- }
- if(!function_exists('removeFromMultiSort')) {
- function removeFromMultiSort($current, $key) {
- $found = false;
- $current = $current ? $current : [];
- $current = array_filter($current, function($_x) use ($key) {
- return $_x['key'] !== $key;
- });
- return array_values($current);
- }
- }
- if(!function_exists('toFeetAndInches')) {
- function toFeetAndInches($value, $ftLabel = ' ft.', $inLabel = ' in.') {
- if(!$value) return '-';
- $value = round($value);
- $ft = round(floor($value / 12));
- $in = $value % 12;
- return "$ft$ftLabel $in$inLabel";
- }
- }
- if(!function_exists('callJava')) {
- function callJava($endPoint, $data, $sessionKey) {
- $url = config('stag.backendUrl') . $endPoint;
- $response = Http::asForm()
- ->withHeaders([
- 'sessionKey' => $sessionKey
- ])
- ->post($url, $data)
- ->body();
- return $response;
- }
- }
- if(!function_exists('feetFromInches')) {
- function feetFromInches($value) {
- if(!$value) return 0;
- $value = round($value);
- return round(floor($value / 12));
- }
- }
- if(!function_exists('inchesAfterFeetFromInches')) {
- function inchesAfterFeetFromInches($value) {
- if(!$value) return 0;
- $value = round($value);
- return round($value % 12);
- }
- }
- if(!function_exists('genericBills')) {
- function genericBills(Pro $performerPro, $patient,$careMonth, $entityType, $entityUid) {
- $genericBills = Bill::where('bill_service_type', 'GENERIC');
- if($performerPro->pro_type !== 'ADMIN') {
- $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
- }
- if($patient) {
- $genericBills = $genericBills->where('client_id', $patient->id);
- }
-
- if($careMonth){
- $genericBills = $genericBills->where('care_month_id', $careMonth->id);
- }
- if($entityType && $entityUid) {
-
- $genericBills = $genericBills
- ->where('generic_target_entity_type', $entityType)
- ->where('generic_target_entity_uid', $entityUid);
-
-
- }
- return $genericBills->orderBy('created_at', 'DESC')->get();
- }
- }
- if(!function_exists('hasActiveGenericBill')) {
- function hasActiveGenericBill(Pro $performerPro, $patient, $entityType, $entityUid) {
- $genericBills = Bill::where('bill_service_type', 'GENERIC')->where('is_cancelled', false);
- if($performerPro->pro_type !== 'ADMIN') {
- $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
- }
- if($patient) {
- $genericBills = $genericBills->where('client_id', $patient->id);
- }
- if($entityType && $entityUid) {
- $genericBills = $genericBills
- ->where('generic_target_entity_type', $entityType)
- ->where('generic_target_entity_uid', $entityUid);
- }
- return $genericBills->count() > 0;
- }
- }
- if(!function_exists('queryLineExcept')) {
- function queryLineExcept($except = []) {
- $params = request()->all();
- $final = [];
- foreach ($params as $k => $v) {
- if(in_array($k, $except) === FALSE) {
- if(is_array($v)) $v = implode(',', $v);
- $final[] = "$k=" . urlencode($v);
- }
- }
- return implode('&', $final);
- }
- }
- if(!function_exists('sortColumnHead')) {
- function sortColumnHead($url, $label, $sortKey, $defaultDirection = 'ASC') {
- $currentSortKey = request()->input('sort');
- $currentDir = request()->input('dir');
- $targetDir = $currentDir ? ($currentDir === 'ASC' ? 'DESC' : 'ASC') : $defaultDirection;
- echo '<a href="' . $url . '?sort=' . $sortKey . '&dir=' . $targetDir . '&' . queryLineExcept(['sort', 'dir']) . '">' . $label . '</a>';
- if($currentSortKey === $sortKey) {
- if($currentDir === 'ASC') {
- echo " ↑";
- }
- elseif($currentDir === 'DESC') {
- echo " ↓";
- }
- }
- }
- }
- if(!function_exists('html2Text')) {
- function html2Text($old, $new){
- }
- }
- if(!function_exists('diff')) {
- function diff($old, $new){
- // return Diff::toHTML(Diff::compare($old, $new));
- }
- }
- if(!function_exists('get_current_session')) {
- function get_current_session(){
- return AppSession::where('session_key', request()->cookie('sessionKey'))->first();
- }
- }
- if(!function_exists('get_current_date')) {
- function get_current_date($timezone = null){
- if(!$timezone){
- $timezone = 'US\Eastern';
- }
- $date = new DateTime("now", new DateTimeZone('US/Eastern') );
- return $date->format('Y-m-d');
- }
- }
- if(!function_exists('friendly_date_est')) {
- function friendly_date_est($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone('EASTERN');
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date_est_compact')) {
- function friendly_date_est_compact($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone('EASTERN');
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format('y') === date('y') ? $date->format("m/d") : $date->format("m/d/y");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date_time')) {
- function friendly_date_time($value, $includeTime = true, $default = '-', $long_year=false) {
- if(!$value || empty($value)) return $default;
- try {
- if($includeTime) {
- $realTimezone = 'US/Eastern';
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y" . ($includeTime ? ", h:ia" : "")) . ($includeTime ? ' EST' : '');
- }
- else {
- $result = strtotime($value);
- if($long_year){
- $result = date("m/d/Y" . ($includeTime ? ", h:ia" : ""), $result);
- }else{
- $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
- }
- return $result;
- }
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_time_with_seconds')) {
- function friendly_date_time_with_seconds($value, $includeTime = true, $default = '-', $long_year=false) {
- if(!$value || empty($value)) return $default;
- try {
- if($includeTime) {
- $realTimezone = 'US/Eastern';
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y" . ($includeTime ? ", h:i:sa" : "")) . ($includeTime ? ' EST' : '');
- }
- else {
- $result = strtotime($value);
- if($long_year){
- $result = date("m/d/Y" . ($includeTime ? ", h:i:sa" : ""), $result);
- }else{
- $result = date("m/d/y" . ($includeTime ? ", h:i:sa" : ""), $result);
- }
- return $result;
- }
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_month_year')) {
- function friendly_date_month_year($value, $default = '-', $long_year=true) {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- if($long_year){
- $result = date("m/Y", $result);
- }else{
- $result = date("m/y", $result);
- }
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendlier_date_time')) {
- function friendlier_date_time($value, $includeTime = true, $default = '-') {
- return friendly_date_time($value, $includeTime, $default);
- }
- }
- if(!function_exists('friendly_date_time_short')) {
- function friendly_date_time_short($value, $includeTime = true, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- $result = date("m/d/y" . ($includeTime ? ", h:ia" : ""), $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_time_short_with_tz')) {
- function friendly_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y" . ($includeTime ? ", h:iA" : ""));
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date_time_short_with_tz_from_timestamp')) {
- function friendly_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime("@$value");
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y, h:iA");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('postgres_date_time_short_with_tz')) {
- function postgres_date_time_short_with_tz($value, $includeTime = true, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("Y-m-d" . ($includeTime ? " h:i:s" : ""));
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('postgres_date_time_short_with_tz_from_timestamp')) {
- function postgres_date_time_short_with_tz_from_timestamp($value, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime("@$value");
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("Y-m-d h:i:s");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date_time_short_with_tz_from_timestamp_divide1000')) {
- function friendly_date_time_short_with_tz_from_timestamp_divide1000($value, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $value = (floor($value / 1000));
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime("@$value");
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y, h:iA");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date_short_with_tz_from_timestamp_divide1000')) {
- function friendly_date_short_with_tz_from_timestamp_divide1000($value, $tz='EASTERN', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $value = (floor($value / 1000));
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime("@$value");
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("m/d/y");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('date_short_with_tz_from_timestamp_divide1000')) {
- function date_short_with_tz_from_timestamp_divide1000($value, $tz='EASTERN', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $value = (floor($value / 1000));
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime("@$value");
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("Y-m-d");
- }
- catch (Exception $e) {
- return $e->getMessage();
- }
- }
- }
- if(!function_exists('friendly_date')) {
- function friendly_date($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("m/d/Y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_short')) {
- function friendly_date_short($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("m/d/y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_date_month_year')) {
- function friendly_date_month_year($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("M Y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendlier_date')) {
- function friendlier_date($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("m/d/Y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('relative_friendly_date')) {
- function relative_friendly_date($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = date_diff(date_create($value), date_create('now'))->days;
- if ($result > 30) $result = date('F Y', strtotime($value));
- else if ($result > 1) $result .= ' days ago';
- else if ($result === 1) $result = 'Yesterday';
- else if ($result === 0) $result = 'Today';
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('unfriendly_date')) {
- function unfriendly_date($value) {
- if(!$value || empty($value)) return '';
- try {
- $result = strtotime($value);
- $result = date("Y-m-d", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_time')) {
- function friendly_time($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $result = strtotime($value);
- $result = date("h:i a", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('military_time')) {
- function military_time($value, $tz='UTC', $default = '-') {
- if(!$value || empty($value)) return $default;
- try {
- $realTimezone = resolve_timezone($tz);
- $date = new DateTime($value);
- $date->setTimezone(new DateTimeZone($realTimezone));
- return $date->format("H:i");
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('resolve_timezone')) {
- function resolve_timezone($value) {
- try {
- switch ($value) {
- case 'ALASKA': {
- return 'US/Alaska';
- }
- case 'CENTRAL': {
- return 'US/Central';
- }
- case 'EASTERN': {
- return 'US/Eastern';
- }
- case 'HAWAII': {
- return 'US/Hawaii';
- }
- case 'MOUNTAIN': {
- return 'US/Mountain';
- }
- case 'PACIFIC': {
- return 'US/Pacific';
- }
- case 'PUERTO_RICO': {
- return 'America/Puerto_Rico';
- }
- case 'UTC': {
- return 'UTC';
- }
- }
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- // $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
- // echo $date->format('Y-m-d H:i:sP') . "\n";
- if(!function_exists('friendly_month')) {
- function friendly_month($value) {
- if(!$value || empty($value)) return "-";
- try {
- $result = strtotime($value);
- $result = date("F o", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('day_part_from_date')) {
- function day_part_from_date($value) {
- if(!$value || empty($value)) return "-";
- try {
- $result = strtotime($value);
- $result = date("d", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('month_part_from_date')) {
- function month_part_from_date($value) {
- if(!$value || empty($value)) return "-";
- try {
- $result = strtotime($value);
- $result = date("m", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('year_part_from_date')) {
- function year_part_from_date($value) {
- if(!$value || empty($value)) return "-";
- try {
- $result = strtotime($value);
- $result = date("Y", $result);
- return $result;
- }
- catch (Exception $e) {
- return $value;
- }
- }
- }
- if(!function_exists('friendly_money')){
- function friendly_money($value, $decimals = 2) {
- // if($decimals === 0) return intval($value);
- return number_format((float)$value, $decimals, '.', '');
- }
- }
- if(!function_exists('time_in_hrminsec')) {
- function time_in_hrminsec($value, $default = '-') {
- if(!$value || empty($value)) return $default;
- $value = intval($value);
- $minutes = intval($value / 60);
- $seconds = $value % 60;
- $hours = 0;
- if($minutes >= 60) {
- $hours = intval($minutes / 60);
- $minutes = $minutes % 60;
- }
- $output = [];
- if($hours > 0) {
- $output[] = "{$hours}h";
- }
- if($minutes > 0) {
- $output[] = "{$minutes}m";
- }
- if($seconds > 0) {
- $output[] = "{$seconds}s";
- }
- return implode(" ", $output);
- }
- }
- if(!function_exists('sanitize_field_name')) {
- function sanitize_field_name($name) {
- $result = strtolower($name);
- return preg_replace("/[^0-9a-z]/i", "_", $result);
- }
- }
- if(!function_exists('sanitize_state_name')) {
- function sanitize_state_name($name) {
- $result = strtolower($name);
- return ucwords(preg_replace("/_/i", " ", $result));
- }
- }
- if(!function_exists('renderNoteTemplate')) {
- function renderNoteTemplate($template, $topLevel)
- {
- echo
- '<div class="note-template-item" ' .
- 'template="' . (isset($template->template) ? $template->template : $template->text) . '" ' .
- 'type="' . (isset($template->type) ? $template->type : "value") . '" ' .
- '>' .
- '<div class="note-template-text d-flex align-items-center">' .
- '<span class="label">' .
- '<input type="checkbox" />' .
- '<span>' . $template->text . '</span>' .
- '</span>';
- if (isset($template->type) && $template->type === 'plus-minus') {
- echo '<div class="ml-auto mr-2 text-nowrap">';
- echo '<a href="#" class="plus-trigger"><i class="fa fa-plus-circle"></i></a>';
- echo '<a href="#" class="minus-trigger ml-1"><i class="fa fa-minus-circle"></i></a>';
- echo '</div>';
- }
- echo '</div>';
- if (isset($template->children) && count($template->children)) {
- echo '<i class="fa fa-chevron-right has-children"></i>';
- echo '<div class="note-template-children">';
- foreach ($template->children as $t) {
- renderNoteTemplate($t, false);
- }
- echo '</div>';
- } else if (isset($template->type) && $template->type !== 'plus-minus') {
- echo '<i class="fa fa-chevron-right has-children"></i>';
- echo '<div class="note-template-children">';
- if ($template->type === 'alpha') {
- echo '<textarea class="form-control form-control-sm"></textarea>';
- } else {
- echo '<input type="' . $template->type . '" class="form-control form-control-sm">';
- }
- echo '</div>';
- }
- echo '</div>';
- }
- }
- if(!function_exists('renderNoteTemplates')) {
- function renderNoteTemplates($path)
- {
- $templates = json_decode(file_get_contents($path));
- foreach ($templates->templates as $template) {
- renderNoteTemplate($template, true);
- }
- }
- }
- if(!function_exists('renderNoteExamTemplates')) {
- function renderNoteExamTemplates($parentPath, $childPath)
- {
- $templates = json_decode(file_get_contents($parentPath));
- $templates = $templates->templates;
- // override as needed with what is in template set
- if(file_exists($childPath)) {
- $orTemplates = json_decode(file_get_contents($parentPath));
- $orTemplates = $orTemplates->templates;
- for ($i = 0; $i < count($templates); $i++) {
- for ($j = 0; $j < count($orTemplates); $j++) {
- if($templates[$i]->text === $orTemplates[$j]->text) {
- $templates[$i] = $orTemplates[$j];
- }
- }
- }
- }
- foreach ($templates as $template) {
- renderNoteTemplate($template, true);
- }
- }
- }
- if(!function_exists('getVal')) {
- function getVal($object, $prop)
- {
- if (isset($object->$prop)) {
- return $object->$prop;
- } else {
- return '';
- }
- }
- }
- if(!function_exists('appTZtoPHPTZ')) {
- function appTZtoPHPTZ($_timezone)
- {
- switch ($_timezone) {
- case 'ALASKA':
- $timezone = "US/Alaska";
- break;
- case 'CENTRAL':
- $timezone = "US/Central";
- break;
- case 'HAWAII':
- $timezone = "US/Hawaii";
- break;
- case 'MOUNTAIN':
- $timezone = "US/Mountain";
- break;
- case 'PACIFIC':
- $timezone = "US/Pacific";
- break;
- case 'PUERTO_RICO':
- $timezone = "America/Puerto_Rico";
- break;
- default:
- $timezone = "US/Eastern";
- break;
- }
- return $timezone;
- }
- }
- if(!function_exists('convertToTimezone')) {
- function convertToTimezone($_dateTime, $_targetTimezone, $_sourceTimezone = 'UTC', $_returnRaw = false)
- {
- if (!$_dateTime) return $_dateTime;
- $date = new \DateTime($_dateTime, new \DateTimeZone($_sourceTimezone));
- $date->setTimezone(new \DateTimeZone(appTZtoPHPTZ($_targetTimezone)));
- return $_returnRaw ? $date : $date->format('Y-m-d H:i:s');
- }
- }
- if(!function_exists('minutes_to_hhmm')) {
- function minutes_to_hhmm($_minutes)
- {
- $h = intval(floor($_minutes / 60));
- $m = $_minutes;
- if($h > 0) {
- $m = $_minutes - $h * 60;
- }
- $h = ($h < 10 ? '0' : '') . $h;
- $m = ($m < 10 ? '0' : '') . $m;
- return $h . ':' . $m;
- }
- }
- if(!function_exists('vsValue')) {
- function vsValue($_v, $patient = null, $_direct = false)
- {
- if ($_direct) {
- return $_v ? $_v : '<span class="font-weight-normal text-info font-italic">empty</span>';
- }
- return @($patient->{$_v}) ? $patient->{$_v} : '<span class="font-weight-normal text-info font-italic">empty</span>';
- }
- }
- if(!function_exists('vsElement')) {
- function vsElement($_v, $type, $name, $patient, $class = '')
- {
- return '<input type="' . $type . '" class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
- 'name="' . $name . '" ' .
- 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
- }
- }
- if(!function_exists('vsRoElement')) {
- function vsRoElement($_v, $type, $name, $patient, $class = '')
- {
- return '<input type="' . $type . '" readonly class="form-control form-control-sm min-width-unset rounded-0 ' . $class . '" ' .
- 'name="' . $name . '" ' .
- 'value="' . (@($patient->{$_v}) ? $patient->{$_v} : '') . '">';
- }
- }
- if(!function_exists('str_compact')) {
- function str_compact($_str)
- {
- return preg_replace("/[^a-zA-Z0-9]/", "", strip_tags($_str));
- }
- }
- if(!function_exists('noteMethodDisplay')) {
- function noteMethodDisplay($method)
- {
- if($method === 'IN_CLINIC') return 'In-Clinic';
- $method = str_replace('_', ' ', $method);
- return ucwords(strtolower($method));
- }
- }
- if(!function_exists('friendly_timezone')) {
- function friendly_timezone($tz) {
- $map = [
- 'EASTERN' => 'EST',
- 'CENTRAL' => 'CST',
- 'MOUNTAIN' => 'MST',
- 'PACIFIC' => 'PST',
- 'ALASKA' => 'AST',
- 'HAWAII' => 'HST',
- 'PUERTO_RICO' => 'PR'
- ];
- return $map[$tz] ?? str_replace("_", " ", $tz);
- }
- }
- if(!function_exists('segment_template_summary_value_display')) {
- function segment_template_summary_value_display($value, $default='________', $class = '') {
- if($value && strlen($value)) return '<span class="segment-template-summary-value '.$class.'">' . $value . '</span>';
- return $default;
- }
- }
- if(!function_exists('starts_with')) {
- function starts_with($haystack, $needle) {
- $length = strlen($needle);
- return substr($haystack, 0, $length) === $needle;
- }
- }
- if(!function_exists('get_doc_templates')){
- function get_doc_templates(){
- $basePath = 'views/document-templates-generic';
- $dir = opendir(resource_path($basePath));
- $templates = [];
- if($dir) {
- while ( $entry = readdir($dir) ) {
- if($entry !== '.' && $entry !== '..' && is_dir(resource_path($basePath . '/' . $entry))) {
- $spec = json_decode(file_get_contents(resource_path($basePath . '/' . $entry) . '/spec.json'));
- if(isset($spec->active) && $spec->active) {
- $html = file_get_contents(resource_path($basePath . '/' . $entry) . '/content.blade.php');
- // get fields
- $proVariables = [];
- $htmlDisplay = preg_replace_callback(
- '/{([^}]+)}/',
- function ($match) use (&$proVariables) {
- $token = $match[1];
- $replacement = '';
- if(strpos($token, '.') === FALSE) {
- $adminField = false;
- if($token[0] === '@') {
- // $token = substr($token, 1);
- $adminField = true;
- }
- switch ($token) {
- case 'TODAY':
- $replacement = date('m/d/Y');
- break;
- default:
- $replacement = '<span class="text-info document-variable" data-variable="' . $token . '">' .
- ($token[0] === '@' ? substr($token, 1) : $token) .
- '</span>';
- if (!isset($proVariables[$token])) {
- $proVariables[$token] = [
- 'token' => $token,
- 'adminField' => $adminField
- ];
- }
- break;
- }
- }
- return $replacement;
- },
- $html
- );
- $templates[] = [
- "name" => $entry,
- "title" => $spec->title,
- "html" => $html,
- "htmlDisplay" => $htmlDisplay,
- "proVariables" => $proVariables
- ];
- }
- }
- }
- }
- closedir($dir);
- // sort by document name
- $names = array_column($templates, 'title');
- array_multisort($names, SORT_ASC, $templates);
- return $templates;
- }
- }
- if(!function_exists('format_phone_number')) {
- function format_phone_number($number, $default = '-') {
- if(empty($number)) return $default;
- return preg_replace('~.*(\d{3})[^\d]{0,7}(\d{3})[^\d]{0,7}(\d{4}).*~', '($1) $2-$3', $number). "\n";
- }
- }
- if(!function_exists('format_number')) {
- function format_number($number, $places = 2) {
- return number_format((float)$number, $places, '.', '');
- }
- }
- if(!function_exists('toHumanReadable')) {
- function toHumanReadable($name) {
- return ucwords(preg_replace("/[^0-9a-z]/i", " ", $name));
- }
- }
- if(!function_exists('parseRender')) {
- function parseRender($_data) {
- if($_data) {
- $type = gettype($_data);
- if(is_string($_data) || is_numeric($_data)) {
- echo $_data;
- }
- else {
- echo "<table class='table table-sm border w-100'>";
- foreach($_data as $k => $v) {
- echo "<tr>";
- echo "<td><b class='text-secondary'>" . toHumanReadable($k) . "</b></td>";
- echo "<td>";
- if(is_object($v)) {
- parseRender($v);
- }
- elseif(is_array($v)) {
- foreach($v as $k2 => $v2) {
- parseRender($v2);
- }
- }
- else {
- echo $v;
- }
- echo "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- }
- }
- }
- if(!function_exists('mask_string')) {
- function mask_string($string, $mask = "*", $lengthFromLastCharacter = null) {
- if(!$lengthFromLastCharacter){
- return str_repeat($mask, strlen($string));
- }
- $firstCharacters = substr($string, ($lengthFromLastCharacter));
- $lastCharacters = substr($string, -$lengthFromLastCharacter);
- $maskedFirstCharacters = str_repeat($mask, strlen($firstCharacters));
-
- return $maskedFirstCharacters . $lastCharacters;
- }
- }
|