Consolidated a bunch of queries #3

Merged
bgcarlisle merged 1 commits from dev-optimize-pageview into master 2 years ago
  1. 106
      functions.php
  2. 199
      plot-viewer.php

106
functions.php

@ -494,7 +494,79 @@ function ctv_get_applications_for_query ( $query ) {
}
function ctv_get_products_for_application ( $applno ) {
function ctv_get_apps_and_products_for_query ( $query ) {
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("SELECT * FROM `fda_Products`, `fda_Applications`, `fda_MarketingStatus`, `fda_MarketingStatus_Lookup` WHERE (`fda_Products`.`ApplNo` = `fda_Applications`.`ApplNo`) AND (`DrugName` LIKE :query OR `ActiveIngredient` LIKE :query) AND (`fda_Products`.`ApplNo` = `fda_MarketingStatus`.`ApplNo` and `fda_Products`.`ProductNo` = `fda_MarketingStatus`.`ProductNo`) AND (`fda_MarketingStatus`.`MarketingStatusID` = `fda_MarketingStatus_Lookup`.`MarketingStatusID`)");
$stmt->bindParam(':query', $quer);
$quer = "%" . $query . "%";
if ($stmt->execute()) {
$result = $stmt->fetchAll();
return $result;
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
}
function ctv_get_apps_and_subs_for_query ( $query ) {
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("SELECT * FROM `fda_Products`, `fda_Applications`, `fda_Submissions`, `fda_SubmissionClass_Lookup` WHERE (`fda_Products`.`ApplNo` = `fda_Applications`.`ApplNo`) AND (`DrugName` LIKE :query OR `ActiveIngredient` LIKE :query) AND (`fda_Submissions`.`ApplNo` = `fda_Products`.`ApplNo`) AND (`fda_Submissions`.`SubmissionClassCodeID` = `fda_SubmissionClass_Lookup`.`SubmissionClassCodeID`) GROUP BY `fda_Submissions`.`ApplNo`, `fda_Submissions`.`SubmissionType`, `fda_Submissions`.`SubmissionNo` ORDER BY `fda_Submissions`.`SubmissionStatusDate`");
$stmt->bindParam(':query', $quer);
$quer = "%" . $query . "%";
if ($stmt->execute()) {
$result = $stmt->fetchAll();
return $result;
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
}
function ctv_get_apps_and_docs_for_query ( $query ) { // ***
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("SELECT * FROM `fda_Products`, `fda_Applications`, `fda_ApplicationDocs`, `fda_ApplicationsDocsType_Lookup` WHERE (`fda_Products`.`ApplNo` = `fda_Applications`.`ApplNo`) AND (`fda_Products`.`DrugName` LIKE :query OR `fda_Products`.`ActiveIngredient` LIKE :query) AND (`fda_ApplicationDocs`.`ApplNo` = `fda_Products`.`ApplNo`) AND (`fda_ApplicationDocs`.`ApplicationDocsTypeID` = `fda_ApplicationsDocsType_Lookup`.`ApplicationDocsType_Lookup_ID`) GROUP BY `fda_ApplicationDocs`.`ApplicationDocsURL` ORDER BY `fda_ApplicationDocs`.`ApplicationDocsDate`");
$stmt->bindParam(':query', $quer);
$quer = "%" . $query . "%";
if ($stmt->execute()) {
$result = $stmt->fetchAll();
return $result;
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
}
function ctv_get_products_for_application ( $applno ) { // This function may no longer be needed
try {
@ -566,9 +638,7 @@ function ctv_get_submissions_for_product ( $applno ) {
}
function ctv_get_first_start_for_address ( $address ) {
$ctviewer = ctv_get_ctviewer_for_address ( $address );
function ctv_get_first_start_for_address ( $address, $ctviewer ) {
// get the first start date
@ -699,9 +769,7 @@ function ctv_get_first_start_for_address ( $address ) {
}
function ctv_get_last_end_for_address ( $address ) {
$ctviewer = ctv_get_ctviewer_for_address ( $address );
function ctv_get_last_end_for_address ( $address, $ctviewer ) {
// get the first start date
@ -888,4 +956,28 @@ function ctv_get_pmc_for_nda ( $nda_number ) {
}
function ctv_get_apps_and_pmcs_for_query ( $query ) {
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("SELECT * FROM `fda_Products`, `fda_Applications`, `pmc_commitments`, `pmc_cmt_status` WHERE (`fda_Products`.`ApplNo` = `fda_Applications`.`ApplNo`) AND (`DrugName` LIKE :query OR `ActiveIngredient` LIKE :query) AND (`pmc_commitments`.`NDA_NUMBER` = `fda_Products`.`ApplNo`) AND (`pmc_commitments`.`CMT_STATUS` = `pmc_cmt_status`.`CMT_Status`)");
$stmt->bindParam(':query', $quer);
$quer = "%" . $query . "%";
if ($stmt->execute()) {
$result = $stmt->fetchAll();
return $result;
} else {
return FALSE;
}
} catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
}
?>

199
plot-viewer.php

@ -2,21 +2,28 @@
$ctviewer = ctv_get_ctviewer_for_address ( $_GET['address'] );
$firststart = ctv_get_first_start_for_address ( $_GET['address'] );
$lastend = ctv_get_last_end_for_address ( $_GET['address'] );
$firststart = ctv_get_first_start_for_address ( $_GET['address'], $ctviewer );
$lastend = ctv_get_last_end_for_address ( $_GET['address'], $ctviewer );
$viewerwidth = ctv_get_width_of_display ($firststart, $lastend);
$ctgtrials = ctv_get_trials_for_address ( $_GET['address'] );
$fdaapps = ctv_get_applications_for_query ( $ctviewer['query'] );
if ( count ($fdaapps) > 0 ) {
$fdaproducts = ctv_get_apps_and_products_for_query ($ctviewer['query']);
$pmcs = ctv_get_apps_and_pmcs_for_query ($ctviewer['query']);
$fdasubs = ctv_get_apps_and_subs_for_query ( $ctviewer['query'] );
$fdadocs = ctv_get_apps_and_docs_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 urldecode ($ctviewer['query']); ?></a></h1>
<?php
if (! is_null ($ctviewer['indication'])) {
?><p>Indication: <?php echo urldecode ($ctviewer['indication']); ?></p><?php
echo "<p>Indication: " . urldecode ($ctviewer['indication']) . "</p>";
}
?>
@ -94,21 +101,24 @@ $fdaapps = ctv_get_applications_for_query ( $ctviewer['query'] );
echo count (ctv_get_documents_for_product ($fdaapp['ApplNo'])) . " document(s)</td>";
echo "</tr>";
$fdaproducts = ctv_get_products_for_application ( $fdaapp['ApplNo'] );
// $fdaproducts = ctv_get_products_for_application ( $fdaapp['ApplNo'] );
$refstandardfound = 0;
foreach ($fdaproducts as $fdaproduct) {
echo "<tr><td colspan=\"4\">";
echo $fdaproduct['ApplNo'] . "-" . $fdaproduct['ProductNo'];
if ($fdaproduct['ReferenceStandard'] == 1) {
echo "*";
$refstandardfound++;
if ( $fdaproduct['ApplNo'] == $fdaapp['ApplNo'] ) {
echo "<tr><td colspan=\"4\">";
echo $fdaproduct['ApplNo'] . "-" . $fdaproduct['ProductNo'];
if ($fdaproduct['ReferenceStandard'] == 1) {
echo "*";
$refstandardfound++;
}
echo " " . $fdaproduct['Form'] . ", ";
echo $fdaproduct['Strength'] . "<br>";
echo "Marketing status: " . $fdaproduct['MarketingStatusDescription'];
echo "</td></tr>";
}
echo " " . $fdaproduct['Form'] . ", ";
echo $fdaproduct['Strength'] . "<br>";
echo "Marketing status: " . $fdaproduct['MarketingStatusDescription'];
echo "</td></tr>";
}
if ($refstandardfound > 0) {
@ -202,61 +212,55 @@ $fdaapps = ctv_get_applications_for_query ( $ctviewer['query'] );
if ( count ($fdaapps) > 0 ) {
foreach ($fdaapps as $fdaapp) {
$pmcs = ctv_get_pmc_for_nda ($fdaapp['ApplNo']);
foreach ($pmcs as $pmc) {
foreach ($pmcs as $pmc) {
echo "<div class=\"ctvSticky ctvTrialDetails ctvHidden\" id=\"ctvDetails-PMC" . $pmc['CMT_ID'] . "\">";
echo "<a href=\"#\" onclick=\"event.preventDefault();hide_trial_details();\" style=\"margin: 0 1px 4px 10px; float: right;\">[Close]</a>";
echo "<h2>";
echo "<div class=\"ctvSticky ctvTrialDetails ctvHidden\" id=\"ctvDetails-PMC" . $pmc['CMT_ID'] . "\">";
echo "<a href=\"#\" onclick=\"event.preventDefault();hide_trial_details();\" style=\"margin: 0 1px 4px 10px; float: right;\">[Close]</a>";
echo "<h2>";
if ( $pmc['SUBPART_FLAG'] == "" ) {
echo "Postmarketing commitment ";
} else {
echo "Postmarketing requirement ";
}
echo $pmc['CMT_ID'] . "-" . $pmc['CMT_NUMBER'] . " [" . $fdaapp['ApplNo'] . "]</h2>";
echo "<p>Supplement number: " . $pmc['CMT_DOC_TYPE'] . "-" . $pmc['CMT_DOC_TYPE_NO'] . "</p>";
if ( $pmc['SUBPART_FLAG'] != "" ) {
switch ($pmc['SUBPART_FLAG']) {
case "H":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q13\" target=\"_blank\">Accelerated approval</a></p>";
break;
case "F":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q16\" target=\"_blank\">FDAAA section 505(o)(3)</a></p>";
break;
case "P":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q15\" target=\"_blank\">Pediatric research equity act</a></p>";
break;
case "E":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q14\" target=\"_blank\">Animal efficacy rule</a></p>";
break;
}
}
if ( $pmc['SUBPART_FLAG'] == "" ) {
echo "Postmarketing commitment ";
} else {
echo "Postmarketing requirement ";
}
echo "<p>Original projected completion date: " . substr($pmc['ORIG_PROJ_COMPL_DATE'], 0, 10 ) . "</p>";
echo "<p>Status: " . $pmc['Status_Desc'] . "</p>";
if ( $pmc['CMT_STATUS_DESC'] != "" ) {
echo "<p>Status description: ";
echo $pmc['CMT_STATUS_DESC'];
echo "</p>";
echo $pmc['CMT_ID'] . "-" . $pmc['CMT_NUMBER'] . " [" . $fdaapp['ApplNo'] . "]</h2>";
echo "<p>Supplement number: " . $pmc['CMT_DOC_TYPE'] . "-" . $pmc['CMT_DOC_TYPE_NO'] . "</p>";
if ( $pmc['SUBPART_FLAG'] != "" ) {
switch ($pmc['SUBPART_FLAG']) {
case "H":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q13\" target=\"_blank\">Accelerated approval</a></p>";
break;
case "F":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q16\" target=\"_blank\">FDAAA section 505(o)(3)</a></p>";
break;
case "P":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q15\" target=\"_blank\">Pediatric research equity act</a></p>";
break;
case "E":
echo "<p>Required under: <a href=\"http://www.fda.gov/Drugs/GuidanceComplianceRegulatoryInformation/Post-marketingPhaseIVCommitments/ucm070766.htm#q14\" target=\"_blank\">Animal efficacy rule</a></p>";
break;
}
}
echo "<p>Description: " . $pmc['CMT_DESC'] . "</p>";
echo "<p>Applicant: " . $pmc['APPLICANT'] . "</p>";
echo "<p>Product: " . $pmc['PRODUCT'] . " [" . $fdaapp['ApplNo'] . "]</p>";
echo "</div>";
echo "<p>Original projected completion date: " . substr($pmc['ORIG_PROJ_COMPL_DATE'], 0, 10 ) . "</p>";
echo "<p>Status: " . $pmc['Status_Desc'] . "</p>";
if ( $pmc['CMT_STATUS_DESC'] != "" ) {
echo "<p>Status description: ";
echo $pmc['CMT_STATUS_DESC'];
echo "</p>";
}
echo "<p>Description: " . $pmc['CMT_DESC'] . "</p>";
echo "<p>Applicant: " . $pmc['APPLICANT'] . "</p>";
echo "<p>Product: " . $pmc['PRODUCT'] . " [" . $fdaapp['ApplNo'] . "]</p>";
echo "</div>";
}
}
@ -296,55 +300,66 @@ $fdaapps = ctv_get_applications_for_query ( $ctviewer['query'] );
echo "<div id=\"fdaInfoContainer\">";
foreach ($fdaapps as $fdaapp) {
foreach ($fdaapps as $fdaapp) { // Need to optimize ***
// submissions
$fdasubs = ctv_get_submissions_for_product ($fdaapp['ApplNo']);
// $fdasubs = ctv_get_submissions_for_product ($fdaapp['ApplNo']);
foreach ( $fdasubs as $fdasub ) {
if ( $fdaapp['ApplNo'] == $fdasub['ApplNo'] ) {
$subleftyears = ( substr($fdasub['SubmissionStatusDate'], 0, 4) - substr($firststart, 0, 4) ) * 120;
$subleftmonths = substr($fdasub['SubmissionStatusDate'], 5, 2) * 10 - 10;
$subleft = $subleftyears + $subleftmonths;
$subleftyears = ( substr($fdasub['SubmissionStatusDate'], 0, 4) - substr($firststart, 0, 4) ) * 120;
$subleftmonths = substr($fdasub['SubmissionStatusDate'], 5, 2) * 10 - 10;
$subleft = $subleftyears + $subleftmonths;
echo "<div class=\"fdaSubmission fdaSubmissionFlat\" style=\"left: ";
echo $subleft;
echo "px;\" fdaSortDate=\"";
echo $fdasub['ApplNo'] . "-" . $fdasub['SubmissionStatusDate'] . "-1\">";
echo $fdasub['SubmissionType'] . "-" . $fdasub['SubmissionNo'];
echo " (";
echo $fdasub['ReviewPriority'] . " " . $fdasub['SubmissionClassCode'] . " " . $fdasub['SubmissionClassCodeDescription'];
echo ")<br>";
echo "<span class=\"fdaDocApplNo\">" . $fdasub['ApplNo'] . "</span>";
echo "</div>";
echo "<div class=\"fdaSubmission fdaSubmissionFlat\" style=\"left: ";
echo $subleft;
echo "px;\" fdaSortDate=\"";
echo $fdasub['ApplNo'] . "-" . $fdasub['SubmissionStatusDate'] . "-1\">";
echo $fdasub['SubmissionType'] . "-" . $fdasub['SubmissionNo'];
echo " (";
echo $fdasub['ReviewPriority'] . " " . $fdasub['SubmissionClassCode'] . " " . $fdasub['SubmissionClassCodeDescription'];
echo ")<br>";
echo "<span class=\"fdaDocApplNo\">" . $fdasub['ApplNo'] . "</span>";
// echo "-";
// echo "<span class=\"fdaProdNo\">" . $fdasub['ProductNo'] . "</span>";
echo "</div>";
}
}
// documents
$fdadocs = ctv_get_documents_for_product ($fdaapp['ApplNo']);
// $fdadocs = ctv_get_documents_for_product ($fdaapp['ApplNo']);
foreach ($fdadocs as $fdadoc) {
if ( $fdaapp['ApplNo'] == $fdadoc['ApplNo'] ) {
$docleftyears = ( substr($fdadoc['ApplicationDocsDate'], 0, 4) - substr($firststart, 0, 4) ) * 120;
$docleftmonths = substr($fdadoc['ApplicationDocsDate'], 5, 2) * 10 - 10;
$docleft = $docleftyears + $docleftmonths;
echo "<div class=\"fdaDocument fdaDocumentFlat\" style=\"left: " . $docleft . "px;\" fdaSortDate=\"" . $fdasub['ApplNo'] . "-" . $fdadoc['ApplicationDocsDate'] . "-2\">";
echo "<a href=\"" . $fdadoc['ApplicationDocsURL'] . "\" target=\"_blank\">";
echo $fdadoc['ApplicationDocsType_Lookup_Description'] . " (" . $fdadoc['SubmissionType'] . "-" . $fdadoc['SubmissionNo'] . ")";
echo "</a>";
echo "<br>";
echo "<span class=\"fdaDocApplNo\">" . $fdadoc['ApplNo'] . "</span>";
echo "</div>";
}
$docleftyears = ( substr($fdadoc['ApplicationDocsDate'], 0, 4) - substr($firststart, 0, 4) ) * 120;
$docleftmonths = substr($fdadoc['ApplicationDocsDate'], 5, 2) * 10 - 10;
$docleft = $docleftyears + $docleftmonths;
echo "<div class=\"fdaDocument fdaDocumentFlat\" style=\"left: " . $docleft . "px;\" fdaSortDate=\"" . $fdasub['ApplNo'] . "-" . $fdadoc['ApplicationDocsDate'] . "-2\">";
echo "<a href=\"" . $fdadoc['ApplicationDocsURL'] . "\" target=\"_blank\">";
echo $fdadoc['ApplicationDocsType_Lookup_Description'] . " (" . $fdadoc['SubmissionType'] . "-" . $fdadoc['SubmissionNo'] . ")";
echo "</a>";
echo "<br>";
echo "<span class=\"fdaDocApplNo\">" . $fdadoc['ApplNo'] . "</span>";
echo "</div>";
}
// postmarketing commitments
$pmcs = ctv_get_pmc_for_nda ($fdaapp['ApplNo']);
// $pmcs = ctv_get_pmc_for_nda ($fdaapp['ApplNo']);
foreach ($pmcs as $pmc) {

Loading…
Cancel
Save