Files
medicaltracker/public/term.php
T
Ty Clifford c1cb93083e - Fixed. Medicines now show “what it is used for” from official label data when available, with curated/common-use text as the fallback.
Changed:
Added official_use, source name, and source URL fields to the medicine 
schema in [app/bootstrap.php (line 
200)](/Users/tyemeclifford/Documents/GH/workout/app/bootstrap.php:200).
Added shared display helpers and API used_for output in 
[app/bootstrap.php (line 
1848)](/Users/tyemeclifford/Documents/GH/workout/app/bootstrap.php:1848).
Updated openFDA imports to pull indications_and_usage first, then 
purpose, and store source links in [app/bootstrap.php (line 
3060)](/Users/tyemeclifford/Documents/GH/workout/app/bootstrap.php:3060).
Updated the medicine detail page to show “What It Is Used For” plus the 
openFDA label link in [public/medicine.php (line 
72)](/Users/tyemeclifford/Documents/GH/workout/public/medicine.php:72).
Updated catalog/list contexts to use the same helper, including 
[public/nutrition.php (line 
66)](/Users/tyemeclifford/Documents/GH/workout/public/nutrition.php:66).
Updated docs/counts in [README.md (line 
45)](/Users/tyemeclifford/Documents/GH/workout/README.md:45) and 
[CHANGELOG.md (line 
15)](/Users/tyemeclifford/Documents/GH/workout/CHANGELOG.md:15).
Database is updated to 7,646 medicines, with 200 openFDA label-derived 
use summaries, 8,077 medicine-condition links, and 10,590 
medicine-symptom links.
Verified:
Refreshed openFDA label-use data with 
scripts/update_medicine_catalog.php 200 openFDA.
/medicine.php?id=7644, /medicine.php?id=6, 
/nutrition.php?q=serdexmethylphenidate, 
/api.php?action=library_search&q=ADHD&limit=5, and / all returned 200.
Confirmed the page shows “What It Is Used For”, “Used for: ...”, and an 
openFDA label source link.
Stock php -l was not available in this workspace, but the FrankenPHP 
bootstrap and route/API smoke tests executed successfully.
Sources used: openFDA drug label fields and openFDA query parameters.
2026-07-03 16:34:31 -04:00

129 lines
6.4 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../app/bootstrap.php';
$pdo = app_db();
$term = find_medical_term_item($pdo, $_GET);
$pageTitle = $term
? (string) $term['term'] . ' | Medical Term | Neon Medical Tracker'
: 'Medical Term Not Found | Neon Medical Tracker';
$activePage = 'terminology';
$relatedMedicines = [];
$relatedConditions = [];
$relatedStudies = [];
if ($term) {
$related = library_search_payload(['q' => (string) $term['term'], 'limit' => 8]);
$relatedMedicines = $related['medicationCatalog'];
$relatedConditions = $related['medicalConditions'];
$relatedStudies = $related['researchStudies'];
} else {
http_response_code(404);
}
require __DIR__ . '/partials/site-header.php';
?>
<main>
<?php if (!$term): ?>
<section class="admin-public-shell record-shell">
<p class="site-eyebrow">Medical terminology</p>
<h1>Term not found.</h1>
<p>The requested terminology link does not match a current database record.</p>
<a class="site-primary" href="/medical.php">Search terminology</a>
</section>
<?php else: ?>
<section class="admin-public-shell record-shell">
<div class="record-heading">
<div>
<p class="site-eyebrow">Medical term</p>
<h1><?= htmlspecialchars((string) $term['term'], ENT_QUOTES) ?></h1>
<p><?= htmlspecialchars((string) $term['plain_language_definition'], ENT_QUOTES) ?></p>
</div>
<div class="record-actions">
<a class="site-primary" href="/tracker.php">Open tracker</a>
<a class="site-secondary" href="/medical.php?q=<?= rawurlencode((string) $term['term']) ?>">Library search</a>
</div>
</div>
<div class="record-meta">
<span><?= htmlspecialchars((string) $term['category'], ENT_QUOTES) ?></span>
<span>ID <?= htmlspecialchars((string) $term['id'], ENT_QUOTES) ?></span>
</div>
</section>
<section class="admin-public-shell">
<div class="record-detail-grid">
<article class="record-field wide">
<span>Clinical Context</span>
<p><?= htmlspecialchars((string) $term['clinical_context'], ENT_QUOTES) ?></p>
</article>
<article class="record-field wide">
<span>Source</span>
<div class="source-links">
<a href="<?= htmlspecialchars((string) $term['source_url'], ENT_QUOTES) ?>"><?= htmlspecialchars((string) $term['source_name'], ENT_QUOTES) ?></a>
</div>
</article>
</div>
</section>
<?php if ($relatedConditions || $relatedMedicines || $relatedStudies): ?>
<section class="admin-public-shell">
<div class="site-section-heading">
<p class="site-eyebrow">Connected records</p>
<h2>Database matches for this term</h2>
</div>
<div class="library-list">
<?php foreach ($relatedConditions as $condition): ?>
<article class="library-row">
<div class="library-row-main">
<h3><?= htmlspecialchars((string) $condition['name'], ENT_QUOTES) ?></h3>
<p><?= htmlspecialchars((string) $condition['overview'], ENT_QUOTES) ?></p>
<div class="library-row-meta">
<span><?= htmlspecialchars((string) $condition['category'], ENT_QUOTES) ?></span>
</div>
</div>
<div class="library-row-actions">
<a class="site-secondary" href="<?= htmlspecialchars(condition_detail_path($condition), ENT_QUOTES) ?>">View condition</a>
</div>
</article>
<?php endforeach; ?>
<?php foreach ($relatedMedicines as $medicine): ?>
<article class="library-row">
<div class="library-row-main">
<h3><?= htmlspecialchars(ucfirst((string) $medicine['generic_name']), ENT_QUOTES) ?></h3>
<p><?= htmlspecialchars(medicine_used_for_text($medicine), ENT_QUOTES) ?></p>
<div class="library-row-meta">
<span><?= htmlspecialchars((string) ($medicine['class_name'] ?: 'Medication'), ENT_QUOTES) ?></span>
<span><?= htmlspecialchars((string) ($medicine['brand_names'] ?: 'Brands vary'), ENT_QUOTES) ?></span>
</div>
</div>
<div class="library-row-actions">
<a class="site-secondary" href="<?= htmlspecialchars(medicine_detail_path($medicine), ENT_QUOTES) ?>">View medicine</a>
</div>
</article>
<?php endforeach; ?>
<?php foreach ($relatedStudies as $study): ?>
<article class="library-row">
<div class="library-row-main">
<h3><?= htmlspecialchars((string) $study['title'], ENT_QUOTES) ?></h3>
<p><?= htmlspecialchars((string) $study['summary'], ENT_QUOTES) ?></p>
<div class="library-row-meta">
<span><?= htmlspecialchars((string) $study['category'], ENT_QUOTES) ?></span>
<span><?= htmlspecialchars((string) $study['related_medicine'], ENT_QUOTES) ?></span>
</div>
</div>
<div class="library-row-actions">
<a class="site-secondary" href="<?= htmlspecialchars((string) $study['source_url'], ENT_QUOTES) ?>">Study link</a>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php endif; ?>
</main>
<?php require __DIR__ . '/partials/site-footer.php'; ?>