utility = $utility; } public function setHash($destination='') { return $this->utility->setHash($destination); } public function setSortableCol($label='', $destination, $field, $dir) { $currentField = isset($_POST['orderField']) ? $_POST['orderField'] : null; $currentDir = isset($_POST['orderDir']) ? $_POST['orderDir'] : null; $pageNumb = isset($_POST['pageNumb']) ? $_POST['pageNumb'] : 1; $icon = ''; if ($field == $currentField) { if ($currentDir == 'desc') $dir = 'asc'; else $dir = 'desc'; if ($dir == 'asc') $icon = ''; else $icon = ''; } return ''.$label.' '.$icon; } public function wrapVector($vector, $start, $end='', $space=' ') { $string = ''; if (is_array($vector)) { foreach($vector as $value) { $string .= $start.$value.$end.$space; } } return $string; } public function setCommaList($vector=[], $sep=', ') { return is_array($vector) ? implode($sep, $vector) : ''; } public function dateIntervalString($date) { $start = date_create($date); $end = date_create(); $diff = date_diff($start, $end); if ($diff->y > 0) { if ($diff->m > 0) { return vsprintf(_('%sy %smo'), [$diff->y, $diff->m]); } else { return vsprintf(_('%sy'), [$diff->y]); } } if ($diff->y <= 0 && $diff->m > 0) { if ($diff->d > 0) { return vsprintf(_('%smo %sd'), [$diff->m, $diff->d]); } else { return vsprintf(_('%smo'), [$diff->m]); } } if ($diff->y <= 0 && $diff->m <= 0 && $diff->d > 0) { if ($diff->h > 0) { return vsprintf(_('%sd %sh'), [$diff->d, $diff->h]); } else { return vsprintf(_('%sd'), [$diff->d]); } } if ($diff->y <= 0 && $diff->m <= 0 && $diff->d <= 0) { if ($diff->h > 0) { return vsprintf(_('%sh %smi'), [$diff->h, $diff->i]); } else { if ($diff->i > 0) { return vsprintf(_('%smi'), [$diff->i]); } } } return vsprintf(_('%ss'), [$diff->s]); } public function setYesNo($number=0) { return $number==1 ? _('Yes') : _('No'); } public function getDateString($date=null, $withTime=true) { if ($withTime) { $dateString = '%d/%b/%Y %H.%M'; } else { $dateString = '%d/%b/%Y'; } if (!empty($date)) return strftime($dateString, strtotime($date)); else return ''; } public function getTimeString($date=null, $sep='.', $withSecs=false) { $secs = $withSecs ? $sep.'s' : ''; return date('H'.$sep.'i'.$secs, strtotime($date)); } public function getJsonTranslation($jsonField, $langCode=null, $default='') { $data = json_decode($jsonField, true); return is_array($data) && isset($data[$langCode]) ? $data[$langCode] : $default; } public function getRoleNameInList($string='', $roleList=[]) { $string = '{'.$string.'}'; $array = json_decode($string, true); $list = []; if (is_array($array)) { foreach($array as $roleId => $roleName) { //Role name is in English because of the query in usersController::usersList() if (isset($roleList[$roleId])) { $list[] = $roleList[$roleId]['name']; } } } return !empty($list) && is_array($list) ? implode(', ', $list) : null; } public function requestSubject($data=[]) { $surname = isset($data['patientSurname']) ? $this->cleanText($data['patientSurname']) : ''; $name = isset($data['patientName']) ? $this->cleanText($data['patientName']) : ''; $years = isset($data['ageYears']) ? (int)$data['ageYears'] : 0; $months = isset($data['ageMonths']) ? (int)$data['ageMonths'] : 0; $days = isset($data['ageDays']) ? (int)$data['ageDays'] : 0; $gender = isset($data['patientGender']) ? trim($data['patientGender']) : ''; $anonymous = isset($data['anonymous']) ? $data['anonymous'] : 0; $age = $months > AGE_MONTH_LIMIT ? $years : $months; //AGE_MONTH_LIMIT is in mainController //$ageString = $months > AGE_MONTH_LIMIT ? vsprintf(_('%s y.'), [$years]) : vsprintf(_('%s m.'), [$months]); if ($months > AGE_MONTH_LIMIT) { $ageString = vsprintf(_('%s y.'), [$years]); } else { if ($months > 0) { //if ($days == 0) { $ageString = vsprintf(_('%s m.'), [$months]); //} else { //$ageString = vsprintf(_('%s m. %s d.'), [$months, $days]); //} } else { $ageString = vsprintf(_('%s d.'), [$days]); } } $genderLabel = $gender == 'm' ? strtolower(_('Mal.'))[0] : strtolower(_('Fem.'))[0]; if ($gender == '') $genderLabel = ''; //Overwrite the value if no gender is passed if ($anonymous == 0) { $fullName = ''.$this->setDottedFullname($name, $surname, false).''; } else { $fullName = ''.$this->getObfuscateString($name.' '.$surname).''; } return $fullName.' '.$ageString.' '.$genderLabel.''; } public function patient_age($data=[]) { $years = isset($data['ageYears']) ? (int)$data['ageYears'] : 0; $months = isset($data['ageMonths']) ? (int)$data['ageMonths'] : 0; $days = isset($data['ageDays']) ? (int)$data['ageDays'] : 0; $anonymous = isset($data['anonymous']) ? $data['anonymous'] : 0; $age = $months > AGE_MONTH_LIMIT ? $years : $months; //AGE_MONTH_LIMIT is in mainController if ($months > AGE_MONTH_LIMIT) { $ageString = vsprintf(_('%s y.'), [$years]); } else { if ($months > 0) { $ageString = vsprintf(_('%s m.'), [$months]); } else { $ageString = vsprintf(_('%s d.'), [$days]); } } return $ageString; } public function getObfuscateString($string='') { //return str_repeat('●', strlen($string)); return str_repeat('●', 3); } //TODO: some cleaning operations public function cleanText($text='') { //return utf8_encode($text); return $text; } public function hashtag($text) { return preg_replace('/(?#$1', $text); } public function linkfy($label='', $href='', $class="", $target='_self', $meta='') { return ''.$label.''; } public function getExtension($file) { return pathinfo($file, PATHINFO_EXTENSION); } public function getPreviewType($fileName=null) { $images = ['gif', 'jpg', 'jpeg', 'png', 'bmp', 'tif']; $videos = ['mp4', 'm4p', 'm4v', 'mov', 'mpg', 'mpeg', 'mp2', 'mpeg', 'mpe', 'mpv', 'webm', 'ogv', 'ogg']; $audio = ['mp3', 'mpa', 'aac', 'oga']; $files = ['pdf']; $dicom = ['dcm']; if (!is_null($fileName)) { $ext = strtolower($this->getExtension($fileName)); if (in_array($ext, $images)) { return 'images'; } if (in_array($ext, $videos)) { return 'video'; } if (in_array($ext, $audio)) { return 'audio'; } if (in_array($ext, $files)) { return 'iframe'; } if (in_array($ext, $dicom)) { return 'iframe'; } } return 'download'; } public function getPreviewLink($attach=[], $showUser=true, $wrapStart=null, $wrapEnd=null, $linkClass=null) { $previewType = $this->getPreviewType($attach['file_name']); $attachId = $attach['id']; $attachTitle = $attach['file_title']; $attachExt = $attach['file_ext']; $attachSize = $attach['file_size']; $titleLength = 20; $wrapStart = is_null($wrapStart) ? '