$videos = $names + $eggs; } else { $videos = $names; } $output = array(); if (isset($_GET["filenames"])) { foreach ($videos as $key => $opening) { $output[] = $key; } } else { foreach ($videos as $key => $opening) { $output[] = array("title" => $opening["title"], "source" => $opening["source"], "song" => isset($opening["song"]) ? $opening["song"] : 0, "subtitles" => isset($opening["subtitles"]) ? $opening["subtitles"] : 0, "file" => $key); } } if (isset($_GET["shuffle"])) { shuffle($output); } // move $_GET["first"] to the front of $output if (isset($_GET["first"])) { if (isset($_GET["filenames"])) { $key = array_search($_GET["first"], $output); unset($output[$key]); array_unshift($output, $_GET["first"]); } else { $key = keySearch($output, "file", $_GET["first"]); $first = $output[$key]; unset($output[$key]); array_unshift($output, $first); } } echo json_encode($output);
function doSubs($s) { global $ptrow, $hisrow, $enrow, $nextLocation, $keyLocation, $keyLength; global $groupLevel, $groupCount, $itemSeparator, $pid, $encounter; $nextLocation = 0; $groupLevel = 0; $groupCount = 0; while (($keyLocation = strpos($s, '{', $nextLocation)) !== FALSE) { $nextLocation = $keyLocation + 1; if (keySearch($s, '{PatientName}')) { $tmp = $ptrow['fname']; if ($ptrow['mname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['mname']; } if ($ptrow['lname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['lname']; } $s = keyReplace($s, dataFixup($tmp, xl('Name'))); } else { if (keySearch($s, '{PatientID}')) { $s = keyReplace($s, dataFixup($ptrow['pubpid'], xl('Chart ID'))); } else { if (keySearch($s, '{Address}')) { $s = keyReplace($s, dataFixup($ptrow['street'], xl('Street'))); } else { if (keySearch($s, '{City}')) { $s = keyReplace($s, dataFixup($ptrow['city'], xl('City'))); } else { if (keySearch($s, '{State}')) { $s = keyReplace($s, dataFixup(getListItemTitle('state', $ptrow['state']), xl('State'))); } else { if (keySearch($s, '{Zip}')) { $s = keyReplace($s, dataFixup($ptrow['postal_code'], xl('Postal Code'))); } else { if (keySearch($s, '{PatientPhone}')) { $ptphone = $ptrow['phone_contact']; if (empty($ptphone)) { $ptphone = $ptrow['phone_home']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_cell']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_biz']; } if (preg_match("/([2-9]\\d\\d)\\D*(\\d\\d\\d)\\D*(\\d\\d\\d\\d)/", $ptphone, $tmp)) { $ptphone = '(' . $tmp[1] . ')' . $tmp[2] . '-' . $tmp[3]; } $s = keyReplace($s, dataFixup($ptphone, xl('Phone'))); } else { if (keySearch($s, '{PatientDOB}')) { $s = keyReplace($s, dataFixup(oeFormatShortDate($ptrow['DOB']), xl('Birth Date'))); } else { if (keySearch($s, '{PatientSex}')) { $s = keyReplace($s, dataFixup(getListItemTitle('sex', $ptrow['sex']), xl('Sex'))); } else { if (keySearch($s, '{DOS}')) { $s = keyReplace($s, dataFixup(oeFormatShortDate(substr($enrow['date'], 0, 10)), xl('Service Date'))); } else { if (keySearch($s, '{ChiefComplaint}')) { $cc = $enrow['reason']; $patientid = $ptrow['pid']; $DOS = substr($enrow['date'], 0, 10); // Prefer appointment comment if one is present. $evlist = fetchEvents($DOS, $DOS, " AND pc_pid = ? ", null, false, 0, array($patientid)); foreach ($evlist as $tmp) { if ($tmp['pc_pid'] == $pid && !empty($tmp['pc_hometext'])) { $cc = $tmp['pc_hometext']; } } $s = keyReplace($s, dataFixup($cc, xl('Chief Complaint'))); } else { if (keySearch($s, '{ReferringDOC}')) { $tmp = empty($ptrow['ur_fname']) ? '' : $ptrow['ur_fname']; if (!empty($ptrow['ur_mname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_mname']; } if (!empty($ptrow['ur_lname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_lname']; } $s = keyReplace($s, dataFixup($tmp, xl('Referer'))); } else { if (keySearch($s, '{Allergies}')) { $tmp = generate_plaintext_field(array('data_type' => '24', 'list_id' => ''), ''); $s = keyReplace($s, dataFixup($tmp, xl('Allergies'))); } else { if (keySearch($s, '{Medications}')) { $s = keyReplace($s, dataFixup(getIssues('medication'), xl('Medications'))); } else { if (keySearch($s, '{ProblemList}')) { $s = keyReplace($s, dataFixup(getIssues('medical_problem'), xl('Problem List'))); } else { if (keySearch($s, '{GRP}')) { ++$groupLevel; $groupCount = 0; $s = keyReplace($s, ''); } else { if (keySearch($s, '{/GRP}')) { if ($groupLevel > 0) { --$groupLevel; } $s = keyReplace($s, ''); } else { if (preg_match('/^\\{ITEMSEP\\}(.*?)\\{\\/ITEMSEP\\}/', substr($s, $keyLocation), $matches)) { $itemSeparator = $matches[1]; $keyLength = strlen($matches[0]); $s = keyReplace($s, ''); } else { if (preg_match('/^\\{(LBF\\w+):(\\w+)\\}/', substr($s, $keyLocation), $matches)) { $formname = $matches[1]; $fieldid = $matches[2]; $keyLength = 3 + strlen($formname) + strlen($fieldid); $data = ''; $currvalue = ''; $title = ''; $frow = sqlQuery("SELECT * FROM layout_options " . "WHERE form_id = ? AND field_id = ? LIMIT 1", array($formname, $fieldid)); if (!empty($frow)) { $ldrow = sqlQuery("SELECT ld.field_value " . "FROM lbf_data AS ld, forms AS f WHERE " . "f.pid = ? AND f.encounter = ? AND f.formdir = ? AND f.deleted = 0 AND " . "ld.form_id = f.form_id AND ld.field_id = ? " . "ORDER BY f.form_id DESC LIMIT 1", array($pid, $encounter, $formname, $fieldid)); if (!empty($ldrow)) { $currvalue = $ldrow['field_value']; $title = $frow['title']; } if ($currvalue !== '') { $data = generate_plaintext_field($frow, $currvalue); } } $s = keyReplace($s, dataFixup($data, $title)); } else { if (preg_match('/^\\{(DEM|HIS):(\\w+)\\}/', substr($s, $keyLocation), $matches)) { $formname = $matches[1]; $fieldid = $matches[2]; $keyLength = 3 + strlen($formname) + strlen($fieldid); $data = ''; $currvalue = ''; $title = ''; $frow = sqlQuery("SELECT * FROM layout_options " . "WHERE form_id = ? AND field_id = ? LIMIT 1", array($formname, $fieldid)); if (!empty($frow)) { $tmprow = $formname == 'DEM' ? $ptrow : $hisrow; if (isset($tmprow[$fieldid])) { $currvalue = $tmprow[$fieldid]; $title = $frow['title']; } if ($currvalue !== '') { $data = generate_plaintext_field($frow, $currvalue); } } $s = keyReplace($s, dataFixup($data, $title)); } } } } } } } } } } } } } } } } } } } } } // End if { character found. return $s; }
function doSubs($s) { global $ptrow, $enrow; // $loopcount avoids infinite looping if we screw up. // for ($loopcount = 0; $loopcount < 500; ++$loopcount) { if (keySearch($s, '{PatientName}')) { $tmp = $ptrow['fname']; if ($ptrow['mname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['mname']; } if ($ptrow['lname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['lname']; } $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{PatientID}')) { $s = keyReplace($s, $ptrow['pubpid']); } else { if (keySearch($s, '{Address}')) { $s = keyReplace($s, $ptrow['street']); } else { if (keySearch($s, '{City}')) { $s = keyReplace($s, $ptrow['city']); } else { if (keySearch($s, '{State}')) { $s = keyReplace($s, getListItemTitle('state', $ptrow['state'])); } else { if (keySearch($s, '{Zip}')) { $s = keyReplace($s, $ptrow['postal_code']); } else { if (keySearch($s, '{PatientPhone}')) { $ptphone = $ptrow['phone_contact']; if (empty($ptphone)) { $ptphone = $ptrow['phone_home']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_cell']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_biz']; } if (preg_match("/([2-9]\\d\\d)\\D*(\\d\\d\\d)\\D*(\\d\\d\\d\\d)/", $ptphone, $tmp)) { $ptphone = '(' . $tmp[1] . ')' . $tmp[2] . '-' . $tmp[3]; } $s = keyReplace($s, $ptphone); } else { if (keySearch($s, '{PatientDOB}')) { $s = keyReplace($s, oeFormatShortDate($ptrow['DOB'])); } else { if (keySearch($s, '{PatientSex}')) { $s = keyReplace($s, getListItemTitle('sex', $ptrow['sex'])); } else { if (keySearch($s, '{DOS}')) { $s = keyReplace($s, oeFormatShortDate(substr($enrow['date'], 0, 10))); } else { if (keySearch($s, '{ChiefComplaint}')) { $cc = $enrow['reason']; $patientid = $ptrow['pid']; $DOS = substr($enrow['date'], 0, 10); // Prefer appointment comment if one is present. $evlist = fetchEvents($DOS, $DOS, " AND pc_pid = '{$patientid}' "); foreach ($evlist as $tmp) { if ($tmp['pc_pid'] == $pid && !empty($tmp['pc_hometext'])) { $cc = $tmp['pc_hometext']; } } $s = keyReplace($s, $cc); } else { if (keySearch($s, '{ReferringDOC}')) { $tmp = empty($ptrow['ur_fname']) ? '' : $ptrow['ur_fname']; if (!empty($ptrow['ur_mname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_mname']; } if (!empty($ptrow['ur_lname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_lname']; } $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{Allergies}')) { $tmp = generate_plaintext_field(array('data_type' => '24', 'list_id' => ''), ''); $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{ProblemList}')) { $tmp = ''; $query = "SELECT title FROM lists WHERE " . "pid = ? AND type = 'medical_problem' AND enddate IS NULL " . "ORDER BY begdate"; $lres = sqlStatement($query, array($GLOBALS['pid'])); $count = 0; while ($lrow = sqlFetchArray($lres)) { if ($count++) { $tmp .= "; "; } $tmp .= $lrow['title']; } $s = keyReplace($s, $tmp); } else { break; } } } } } } } } } } } } } } } return $s; }