dev-searchbyindication #2

Manually merged
bgcarlisle merged 5 commits from dev-searchbyindication into master 2 years ago
  1. 4
      ctviewer.css
  2. 99
      functions.php
  3. 2
      install/writeconfig.php
  4. 3
      page.php
  5. 9
      plot-viewer.php
  6. 2
      query.php
  7. 31
      search-field.php

4
ctviewer.css

@ -222,3 +222,7 @@ div.NoDates {
.fdaPMCStaggered {
position: relative;
}
.card {
color: #333;
}

99
functions.php

@ -17,7 +17,7 @@ function ctv_update_fda_info () {
$zip->extractTo( ABS_PATH . "dl/fda/" );
$zip->close();
echo "Extracted FDA zipped folder<br>";
exec ("dos2unix " . ABS_PATH . "dl/fda/*");
try {
@ -38,7 +38,7 @@ function ctv_update_fda_info () {
);
if ($stmt->execute()) {
echo "Successfully cleared old FDA data from db<br><br>";
} else {
echo "Error clearing old FDA data<br><br>";
}
@ -89,7 +89,7 @@ function ctv_update_fda_info () {
if ($stmt->execute()) {
echo "File " . $file . " has been added to the database<br>";
} else {
echo "File " . $file . " has not been added to the db due to a MySQL error with code ";
@ -97,11 +97,11 @@ function ctv_update_fda_info () {
$errorInfo = $stmt->errorInfo();
echo $errorInfo[1] . "<br>";
echo $errorInfo[2] . "<br>";
}
$dbh = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
@ -198,7 +198,7 @@ function ctv_update_pmc_info () {
if ($stmt->execute()) {
echo "File " . $file . " has been added to the database<br>";
} else {
echo "File " . $file . " has not been added to the db due to a MySQL error with code ";
@ -206,11 +206,11 @@ function ctv_update_pmc_info () {
$errorInfo = $stmt->errorInfo();
echo $errorInfo[1] . "<br>";
echo $errorInfo[2] . "<br>";
}
$dbh = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
@ -235,7 +235,7 @@ function ctv_update_pmc_info () {
if ($stmt->execute()) {
echo "File " . $file . " has been added to the database<br>";
} else {
echo "File " . $file . " has not been added to the db due to a MySQL error with code ";
@ -243,11 +243,11 @@ function ctv_update_pmc_info () {
$errorInfo = $stmt->errorInfo();
echo $errorInfo[1] . "<br>";
echo $errorInfo[2] . "<br>";
}
$dbh = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
@ -271,15 +271,15 @@ function ctv_update_pmc_info () {
unlink (ABS_PATH . "dl/pmc.zip");
}
function ctv_query_ct_dot_gov ( $query, $paeds ) {
function ctv_query_ct_dot_gov ( $query, $indication, $paeds ) {
// Make a new address
$haveuniqueaddress = 0;
$haveuniqueaddress = 0;
while ( $haveuniqueaddress == 0 ) {
while ( $haveuniqueaddress == 0 ) {
$address = md5(uniqid(rand(), true));
$address = md5(uniqid(rand(), true));
try {
@ -310,17 +310,24 @@ function ctv_query_ct_dot_gov ( $query, $paeds ) {
}
}
}
$query = urlencode ($query);
$indication = urlencode ($indication);
$query = str_replace (" ", "%20", $query);
if ( $_POST['indication'] == "" ) { // If no indication is entered
$indication_url = "";
} else {
$indication_url = "cond=" . $indication . "&";
}
if ( $paeds == "false" ) { // Paeds box not checked
$ct_dot_gov_url = "https://clinicaltrials.gov/ct2/results/download_fields?down_count=10000&down_flds=all&down_fmt=tsv&intr=" . $query . "&flds=a&flds=b&flds=y";
$ct_dot_gov_url = "https://clinicaltrials.gov/ct2/results/download_fields?down_count=10000&down_flds=all&down_fmt=tsv&" . $indication_url . "intr=" . $query . "&flds=a&flds=b&flds=y";
} else { // Paeds box checked
$ct_dot_gov_url = "https://clinicaltrials.gov/ct2/results/download_fields?down_count=10000&down_flds=all&down_fmt=tsv&intr=" . $query . "&age=0&flds=a&flds=b&flds=y";
$ct_dot_gov_url = "https://clinicaltrials.gov/ct2/results/download_fields?down_count=10000&down_flds=all&down_fmt=tsv&" . $indication_url . "intr=" . $query . "&age=0&flds=a&flds=b&flds=y";
}
if ( file_put_contents( ABS_PATH . "dl/" . $address . ".tsv", file_get_contents($ct_dot_gov_url)) ) {
@ -334,13 +341,23 @@ function ctv_query_ct_dot_gov ( $query, $paeds ) {
try {
$dbh = new PDO('mysql:dbname=' . DB_NAME . ';host=' . DB_HOST, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$stmt = $dbh->prepare("INSERT INTO `ctviewers` (`address`, `query`, `paeds`) VALUES (:address, :query, :paeds);");
if ( $indication == "" ) {
$stmt = $dbh->prepare("INSERT INTO `ctviewers` (`address`, `query`, `paeds`) VALUES (:address, :query, :paeds);");
} else {
$stmt = $dbh->prepare("INSERT INTO `ctviewers` (`address`, `query`, `indication`, `paeds`) VALUES (:address, :query, :indication, :paeds);");
}
$stmt->bindParam(':address', $addy);
$stmt->bindParam(':query', $quer);
if ( $indication != "" ) {
$stmt->bindParam(':indication', $indi);
}
$stmt->bindParam(':paeds', $pae);
$quer = $query;
$indi = $indication;
$addy = $address;
if ( $paeds == "true" ) {
@ -389,9 +406,9 @@ function ctv_query_ct_dot_gov ( $query, $paeds ) {
$errorInfo = $stmt->errorInfo();
echo $errorInfo[1] . "<br>";
echo $errorInfo[2] . "<br>";
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -423,7 +440,7 @@ function ctv_get_ctviewer_for_address ( $address ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -446,7 +463,7 @@ function ctv_get_trials_for_address ( $address ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -470,7 +487,7 @@ function ctv_get_applications_for_query ( $query ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -494,7 +511,7 @@ function ctv_get_products_for_application ( $applno ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -518,7 +535,7 @@ function ctv_get_documents_for_product ( $applno ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -542,7 +559,7 @@ function ctv_get_submissions_for_product ( $applno ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -671,7 +688,7 @@ function ctv_get_first_start_for_address ( $address ) {
if ( count($result) > 0 && $first_fda_application_doc != "0000-00-00" ) {
$all_dates[] = $first_fda_application_doc;
}
} catch (PDOException $e) {
echo $e->getMessage();
}
@ -799,24 +816,24 @@ function ctv_get_last_end_for_address ( $address ) {
function ctv_get_width_of_display ($start, $end) {
$function_name = "ctg_get_width_of_display";
$function_name = "ctg_get_width_of_display";
$startyear = substr ($start, 0, 4);
$endyear = substr ($end, 0, 4);
$startyear = substr ($start, 0, 4);
$endyear = substr ($end, 0, 4);
$difference = $endyear - $startyear + 1;
$difference = $endyear - $startyear + 1;
$width = 120 * $difference;
$width = 120 * $difference;
if ( $width < 940) {
if ( $width < 940) {
return 940;
return 940;
} else {
} else {
return $width;
return $width;
}
}
}
@ -840,7 +857,7 @@ function ctv_sort_by ( $sortcolumn, $address ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
@ -864,7 +881,7 @@ function ctv_get_pmc_for_nda ( $nda_number ) {
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}

2
install/writeconfig.php

@ -128,7 +128,7 @@ catch (PDOException $e) {
try { // add ctviewers table
$dbh = new PDO('mysql:dbname=' . $_POST['dbname'] . ';host=' . $_POST['dbhost'], $_POST['dbusername'], $_POST['dbpassword'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$stmt = $dbh->prepare("DROP TABLE IF EXISTS `ctviewers`; CREATE TABLE `ctviewers` ( `id` int(11) NOT NULL, `address` varchar(32) COLLATE latin1_general_ci NOT NULL, `query` varchar(500) COLLATE latin1_general_ci NOT NULL, `paeds` int(11) NOT NULL DEFAULT '0', `searchdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `show_fda_dates` int(11) NOT NULL DEFAULT '1', `colour_by` varchar(10) COLLATE latin1_general_ci NOT NULL DEFAULT 'sponsor', `enrol_view` int(11) NOT NULL DEFAULT '0', `sort_by` varchar(20) COLLATE latin1_general_ci NOT NULL DEFAULT 'ctvSortStartDate', `password` varchar(64) COLLATE latin1_general_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;");
$stmt = $dbh->prepare("DROP TABLE IF EXISTS `ctviewers`; CREATE TABLE `ctviewers` ( `id` int(11) NOT NULL, `address` varchar(32) COLLATE latin1_general_ci NOT NULL, `query` varchar(500) COLLATE latin1_general_ci NOT NULL, `indication` varchar(500) COLLATE latin1_general_ci DEFAULT NULL, `paeds` int(11) NOT NULL DEFAULT '0', `searchdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `show_fda_dates` int(11) NOT NULL DEFAULT '1', `colour_by` varchar(10) COLLATE latin1_general_ci NOT NULL DEFAULT 'sponsor', `enrol_view` int(11) NOT NULL DEFAULT '0', `sort_by` varchar(20) COLLATE latin1_general_ci NOT NULL DEFAULT 'ctvSortStartDate', `password` varchar(64) COLLATE latin1_general_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;");
if ( $stmt-> execute() ) {
echo "<p>Viewers table created &#x2713;</p>";

3
page.php

@ -99,6 +99,7 @@ author = {Carlisle, Benjamin Gregory}
url: ctviewerurl + 'query.php',
type: 'post',
data: {
drug: $('#drug-query').val(),
indication: $('#indication-query').val(),
paeds: $('#paeds-checkbox').prop('checked')
},
@ -171,7 +172,7 @@ author = {Carlisle, Benjamin Gregory}
}
$('#indication-query').bind('keypress', function(e) {
$('#drug-query, #indication-query').bind('keypress', function(e) {
if (e.keyCode == 13) {
ctviewer_search();
}

9
plot-viewer.php

@ -12,7 +12,14 @@ $fdaapps = ctv_get_applications_for_query ( $ctviewer['query'] );
?><div style="position: fixed; margin-top: 30px; z-index: 700;">
<div class="ctvSticky">
<h1><a href="<?php echo SITE_URL; echo $ctviewer['address']; ?>/">Search term: <?php echo $ctviewer['query']; ?></a></h1>
<h1><a href="<?php echo SITE_URL; echo $ctviewer['address']; ?>/">Search term: <?php echo urldecode ($ctviewer['query']); ?></a></h1>
<?php
if (! is_null ($ctviewer['indication'])) {
?><p>Indication: <?php echo urldecode ($ctviewer['indication']); ?></p><?php
}
?>
<p><?php echo count ( $ctgtrials ); ?> record(s) found on clinicaltrials.gov</p>
<?php if ( count ($fdaapps) > 0 ) { ?>
<p>Expand or flatten:</p>

2
query.php

@ -2,6 +2,6 @@
include_once ("config.php");
ctv_query_ct_dot_gov ( $_POST['indication'], $_POST['paeds'] )
ctv_query_ct_dot_gov ( $_POST['drug'], $_POST['indication'], $_POST['paeds'] )
?>

31
search-field.php

@ -3,16 +3,33 @@
<div class="col-md-8 offset-md-2">
<div id="search-form">
<h1>Search for clinical trials and FDA info</h1>
<div class="form-group">
<label for="indication-query">Enter a drug name</label>
<input type="text" class="form-control" id="indication-query" aria-describedby="indication-query-help" placeholder="Drug name">
<small id="indication-query-help" class="form-text text-muted">E.g. "sunitinib," "pembrolizumab," etc.</small>
<label for="drug-query">Enter a drug name</label>
<div class="input-group">
<input type="text" class="form-control" id="drug-query" aria-describedby="drug-query-help" placeholder="Drug name">
<div class="input-group-append">
<button type="button" class="btn btn-primary" onclick="ctviewer_search();">Search</button>
</div>
</div>
<small id="drug-query-help" class="form-text text-muted">E.g. "sunitinib," "pembrolizumab," etc.</small>
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="paeds-checkbox">
<label class="form-check-label" for="paeds-checkbox">Search paediatric only</label>
<div class="card ctvHidden" id="ctvAdvancedSearchOptions" style="margin-top: 20px;">
<h2 class="card-header">Show advanced search options</h2>
<div class="card-body">
<div class="form-group">
<label for="indication-query">Narrow results by indication</label>
<input type="text" class="form-control" id="indication-query" aria-describedby="indication-help" placeholder="Indication">
<small id="indication-help" class="form-text text-muted">E.g. "breast cancer"; leave this field blank to search for any indication</small>
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="paeds-checkbox">
<label class="form-check-label" for="paeds-checkbox">Search paediatric only</label>
</div>
<button class="btn btn-primary btn-sm" onclick="$('#ctvAdvancedSearchOptions').slideUp();$('#ctvAdvancedSearchButton').slideDown();">Close advanced search options</button>
</div>
</div>
<button class="btn btn-primary btn-block" onclick="ctviewer_search();">Search</button>
<button class="btn btn-primary btn-sm" id="ctvAdvancedSearchButton" onclick="$('#ctvAdvancedSearchOptions').slideDown();$(this).slideUp(0);">Advanced search options</button>
</div>
<div id="search-progress" style="display: none;"></div>
</div>

Loading…
Cancel
Save