- The medicine and terminology directories are now organized as compact rows, and each item links to a dynamic database-backed detail page:

Medicines: /medicine.php?id=46
Terms: /term.php?id=13
Key files:
Dynamic medicine page: [public/medicine.php (line 
1)](/Users/tyemeclifford/Documents/GH/workout/public/medicine.php:1)
Dynamic term page: [public/term.php (line 
1)](/Users/tyemeclifford/Documents/GH/workout/public/term.php:1)
Shared lookup/link helpers: [app/bootstrap.php (line 
1220)](/Users/tyemeclifford/Documents/GH/workout/app/bootstrap.php:1220)
Reworked medicine directory: [public/nutrition.php (line 
49)](/Users/tyemeclifford/Documents/GH/workout/public/nutrition.php:49)
Reworked terminology page: [public/medical.php (line 
64)](/Users/tyemeclifford/Documents/GH/workout/public/medical.php:64)
Overflow-safe layout CSS: [public/assets/site.css (line 
344)](/Users/tyemeclifford/Documents/GH/workout/public/assets/site.css:344)
This commit is contained in:
Ty Clifford
2026-06-30 15:41:55 -04:00
parent 96de47be43
commit b8045eb068
7 changed files with 567 additions and 56 deletions
+2
View File
@@ -21,8 +21,10 @@ http://127.0.0.1:8080
- `/` - public homepage for the medical tracker service. - `/` - public homepage for the medical tracker service.
- `/workouts.php` - condition-tracking feature page. - `/workouts.php` - condition-tracking feature page.
- `/nutrition.php` - medicine catalog feature page. - `/nutrition.php` - medicine catalog feature page.
- `/medicine.php?id=46` - dynamic medicine detail page backed by the SQLite catalog.
- `/recovery.php` - NIH/NLM research links page. - `/recovery.php` - NIH/NLM research links page.
- `/medical.php` - medical terminology, conditions, medicines, and study-link database. - `/medical.php` - medical terminology, conditions, medicines, and study-link database.
- `/term.php?id=1` - dynamic medical-terminology detail page backed by the SQLite catalog.
- `/signup.php` - public profile signup. - `/signup.php` - public profile signup.
- `/tracker.php` - the medical tracker dashboard. - `/tracker.php` - the medical tracker dashboard.
- `/admin.php` - admin user-management dashboard. - `/admin.php` - admin user-management dashboard.
+78
View File
@@ -1217,6 +1217,84 @@ function db_value(PDO $pdo, string $sql, array $params = []): mixed
return $stmt->fetchColumn(); return $stmt->fetchColumn();
} }
function medicine_detail_path(array $medicine): string
{
return '/medicine.php?id=' . rawurlencode((string) ($medicine['id'] ?? ''));
}
function term_detail_path(array $term): string
{
return '/term.php?id=' . rawurlencode((string) ($term['id'] ?? ''));
}
function find_medication_catalog_item(PDO $pdo, array $query): ?array
{
$id = filter_var($query['id'] ?? null, FILTER_VALIDATE_INT);
if ($id !== false && $id > 0) {
return db_one($pdo, 'SELECT * FROM medication_catalog WHERE id = ?', [$id]);
}
$name = trim((string) ($query['name'] ?? $query['q'] ?? ''));
if ($name === '') {
return null;
}
return db_one(
$pdo,
"SELECT *
FROM medication_catalog
WHERE lower(generic_name) = lower(?)
OR lower(active_ingredient) = lower(?)
OR lower(chemical_name) = lower(?)
ORDER BY
CASE
WHEN lower(generic_name) = lower(?) THEN 0
WHEN lower(active_ingredient) = lower(?) THEN 1
ELSE 2
END,
generic_name
LIMIT 1",
[$name, $name, $name, $name, $name]
);
}
function find_medical_term_item(PDO $pdo, array $query): ?array
{
$id = filter_var($query['id'] ?? null, FILTER_VALIDATE_INT);
if ($id !== false && $id > 0) {
return db_one($pdo, 'SELECT * FROM medical_terms WHERE id = ?', [$id]);
}
$term = trim((string) ($query['term'] ?? $query['q'] ?? ''));
if ($term === '') {
return null;
}
return db_one(
$pdo,
"SELECT *
FROM medical_terms
WHERE lower(term) = lower(?)
ORDER BY term
LIMIT 1",
[$term]
);
}
function medicine_reference_links(array $medicine): array
{
$links = [
'RxNorm' => $medicine['rxnorm_url'] ?? '',
'PubChem' => $medicine['pubchem_url'] ?? '',
'DailyMed' => $medicine['dailymed_url'] ?? '',
'MedlinePlus' => $medicine['medlineplus_url'] ?? '',
'PubMed' => $medicine['pubmed_url'] ?? '',
'Studies' => $medicine['clinicaltrials_url'] ?? '',
];
return array_filter($links, static fn ($url) => trim((string) $url) !== '');
}
function db_key_values(PDO $pdo, string $sql, array $params = []): array function db_key_values(PDO $pdo, string $sql, array $params = []): array
{ {
$rows = db_all($pdo, $sql, $params); $rows = db_all($pdo, $sql, $params);
+149 -1
View File
@@ -324,6 +324,9 @@ figcaption a {
.site-metric-stack article, .site-metric-stack article,
.signup-steps article, .signup-steps article,
.term-table article, .term-table article,
.library-row,
.record-field,
.empty-state,
.admin-denied, .admin-denied,
.admin-stat, .admin-stat,
.admin-user-card, .admin-user-card,
@@ -338,6 +341,18 @@ figcaption a {
min-height: 190px; min-height: 190px;
} }
.feature-grid article,
.detail-grid article,
.term-table article,
.library-row,
.record-field,
.empty-state,
.source-links,
.library-row-main {
min-width: 0;
overflow-wrap: anywhere;
}
.feature-grid span { .feature-grid span {
display: inline-flex; display: inline-flex;
color: var(--accent); color: var(--accent);
@@ -390,8 +405,130 @@ figcaption a {
.source-links a { .source-links a {
border: 1px solid var(--line); border: 1px solid var(--line);
border-radius: 999px; border-radius: 999px;
max-width: 100%;
padding: 4px 8px; padding: 4px 8px;
font-size: 0.78rem; font-size: 0.78rem;
white-space: normal;
overflow-wrap: anywhere;
}
.library-list {
display: grid;
gap: 10px;
}
.library-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 14px;
align-items: start;
}
.library-row-main {
display: grid;
gap: 7px;
}
.library-row-main h3 {
line-height: 1.25;
overflow-wrap: anywhere;
}
.library-row-main p,
.record-field p,
.empty-state p {
color: var(--muted);
font-size: 0.9rem;
}
.library-row-meta,
.record-meta,
.record-actions,
.library-row-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.library-row-meta {
min-width: 0;
}
.library-row-meta span,
.record-meta span {
max-width: 100%;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted-2);
background: rgba(255, 255, 255, 0.035);
padding: 5px 8px;
font-size: 0.76rem;
line-height: 1.25;
overflow-wrap: anywhere;
}
.library-row-actions {
justify-content: flex-end;
min-width: 0;
}
.record-shell {
display: grid;
gap: 16px;
}
.record-heading {
display: flex;
justify-content: space-between;
gap: 18px;
align-items: flex-start;
}
.record-heading > div:first-child {
display: grid;
gap: 10px;
min-width: 0;
max-width: 820px;
}
.record-heading h1 {
overflow-wrap: anywhere;
}
.record-actions {
justify-content: flex-end;
}
.record-meta {
min-width: 0;
}
.record-detail-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.record-field {
display: grid;
gap: 8px;
}
.record-field.wide {
grid-column: 1 / -1;
}
.record-field > span {
color: var(--accent);
font-size: 0.78rem;
font-weight: 800;
line-height: 1.2;
text-transform: uppercase;
}
.empty-state {
display: grid;
gap: 8px;
} }
.library-search { .library-search {
@@ -863,13 +1000,24 @@ textarea:focus {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.library-row,
.record-detail-grid {
grid-template-columns: 1fr;
}
.admin-access-row, .admin-access-row,
.admin-user-main, .admin-user-main,
.panel-heading { .panel-heading,
.record-heading {
align-items: stretch; align-items: stretch;
flex-direction: column; flex-direction: column;
} }
.record-actions,
.library-row-actions {
justify-content: flex-start;
}
.admin-badges { .admin-badges {
justify-content: flex-start; justify-content: flex-start;
} }
+55 -35
View File
@@ -53,6 +53,12 @@ require __DIR__ . '/partials/site-header.php';
</article> </article>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php if (!$conditions): ?>
<article class="empty-state">
<h3>No conditions found.</h3>
<p>Try another medicine, symptom, lab, or tracking term.</p>
</article>
<?php endif; ?>
</section> </section>
<section class="admin-public-shell"> <section class="admin-public-shell">
@@ -60,19 +66,30 @@ require __DIR__ . '/partials/site-header.php';
<p class="site-eyebrow">Terminology</p> <p class="site-eyebrow">Terminology</p>
<h2>Plain-language medical terms</h2> <h2>Plain-language medical terms</h2>
</div> </div>
<div class="term-table"> <?php if (!$terms): ?>
<?php foreach ($terms as $term): ?> <article class="empty-state">
<article> <h3>No terms found.</h3>
<div> <p>Try a broader medical word, lab name, symptom, or abbreviation.</p>
<h3><?= htmlspecialchars($term['term'], ENT_QUOTES) ?></h3> </article>
<span><?= htmlspecialchars($term['category'], ENT_QUOTES) ?></span> <?php else: ?>
</div> <div class="library-list">
<p><?= htmlspecialchars($term['plain_language_definition'], ENT_QUOTES) ?></p> <?php foreach ($terms as $term): ?>
<p><?= htmlspecialchars($term['clinical_context'], ENT_QUOTES) ?></p> <article class="library-row">
<a href="<?= htmlspecialchars($term['source_url'], ENT_QUOTES) ?>"><?= htmlspecialchars($term['source_name'], ENT_QUOTES) ?></a> <div class="library-row-main">
</article> <h3><?= htmlspecialchars((string) $term['term'], ENT_QUOTES) ?></h3>
<?php endforeach; ?> <p><?= htmlspecialchars((string) $term['plain_language_definition'], ENT_QUOTES) ?></p>
</div> <div class="library-row-meta">
<span><?= htmlspecialchars((string) $term['category'], ENT_QUOTES) ?></span>
<span><?= htmlspecialchars((string) $term['source_name'], ENT_QUOTES) ?></span>
</div>
</div>
<div class="library-row-actions">
<a class="site-primary" href="<?= htmlspecialchars(term_detail_path($term), ENT_QUOTES) ?>">View term</a>
</div>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section> </section>
<section class="admin-public-shell"> <section class="admin-public-shell">
@@ -80,28 +97,31 @@ require __DIR__ . '/partials/site-header.php';
<p class="site-eyebrow">Medication catalog</p> <p class="site-eyebrow">Medication catalog</p>
<h2>Medicines with chemical, brand, RxNorm, DailyMed, and PubChem links</h2> <h2>Medicines with chemical, brand, RxNorm, DailyMed, and PubChem links</h2>
</div> </div>
<div class="detail-grid"> <?php if (!$medicines): ?>
<?php foreach ($medicines as $medicine): ?> <article class="empty-state">
<article> <h3>No medicines found.</h3>
<h2><?= htmlspecialchars(ucfirst($medicine['generic_name']), ENT_QUOTES) ?></h2> <p>Try a generic name, brand name, chemical name, or medication class.</p>
<p><strong><?= htmlspecialchars($medicine['class_name'], ENT_QUOTES) ?></strong></p> </article>
<p><strong>Active ingredient:</strong> <?= htmlspecialchars($medicine['active_ingredient'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p> <?php else: ?>
<p><strong>Chemical name:</strong> <?= htmlspecialchars($medicine['chemical_name'] ?: $medicine['active_ingredient'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p> <div class="library-list">
<p><strong>Common brands:</strong> <?= htmlspecialchars($medicine['brand_names'] ?: 'Brand names vary by market', ENT_QUOTES) ?></p> <?php foreach ($medicines as $medicine): ?>
<p><strong>Generic/alternate names:</strong> <?= htmlspecialchars($medicine['generic_brands'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p> <article class="library-row">
<p><?= htmlspecialchars($medicine['common_use'], ENT_QUOTES) ?></p> <div class="library-row-main">
<p><?= htmlspecialchars($medicine['tracking_note'], ENT_QUOTES) ?></p> <h3><?= htmlspecialchars(ucfirst((string) $medicine['generic_name']), ENT_QUOTES) ?></h3>
<div class="source-links"> <p><?= htmlspecialchars((string) ($medicine['common_use'] ?: $medicine['tracking_note'] ?: 'Medicine reference entry.'), ENT_QUOTES) ?></p>
<a href="<?= htmlspecialchars($medicine['rxnorm_url'], ENT_QUOTES) ?>">RxNorm</a> <div class="library-row-meta">
<a href="<?= htmlspecialchars($medicine['pubchem_url'], ENT_QUOTES) ?>">PubChem</a> <span><?= htmlspecialchars((string) ($medicine['class_name'] ?: 'Medication'), ENT_QUOTES) ?></span>
<a href="<?= htmlspecialchars($medicine['dailymed_url'], ENT_QUOTES) ?>">DailyMed</a> <span>Active: <?= htmlspecialchars((string) ($medicine['active_ingredient'] ?: $medicine['generic_name']), ENT_QUOTES) ?></span>
<a href="<?= htmlspecialchars($medicine['medlineplus_url'], ENT_QUOTES) ?>">MedlinePlus</a> <span>Brands: <?= htmlspecialchars((string) ($medicine['brand_names'] ?: 'Vary by market'), ENT_QUOTES) ?></span>
<a href="<?= htmlspecialchars($medicine['pubmed_url'], ENT_QUOTES) ?>">PubMed</a> </div>
<a href="<?= htmlspecialchars($medicine['clinicaltrials_url'], ENT_QUOTES) ?>">Studies</a> </div>
</div> <div class="library-row-actions">
</article> <a class="site-primary" href="<?= htmlspecialchars(medicine_detail_path($medicine), ENT_QUOTES) ?>">View medicine</a>
<?php endforeach; ?> </div>
</div> </article>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section> </section>
<section class="admin-public-shell"> <section class="admin-public-shell">
+125
View File
@@ -0,0 +1,125 @@
<?php
declare(strict_types=1);
require __DIR__ . '/../app/bootstrap.php';
$pdo = app_db();
$medicine = find_medication_catalog_item($pdo, $_GET);
$pageTitle = $medicine
? ucfirst((string) $medicine['generic_name']) . ' | Medicine Detail | Neon Medical Tracker'
: 'Medicine Not Found | Neon Medical Tracker';
$activePage = 'medicines';
$relatedStudies = [];
$referenceLinks = [];
if ($medicine) {
$genericName = (string) $medicine['generic_name'];
$like = '%' . $genericName . '%';
$relatedStudies = db_all(
$pdo,
"SELECT *
FROM research_studies
WHERE related_medicine LIKE ? OR title LIKE ? OR summary LIKE ?
ORDER BY category, title
LIMIT 6",
[$like, $like, $like]
);
$referenceLinks = medicine_reference_links($medicine);
} else {
http_response_code(404);
}
require __DIR__ . '/partials/site-header.php';
?>
<main>
<?php if (!$medicine): ?>
<section class="admin-public-shell record-shell">
<p class="site-eyebrow">Medicine catalog</p>
<h1>Medicine not found.</h1>
<p>The requested medicine link does not match a current catalog record.</p>
<a class="site-primary" href="/nutrition.php">Search medicines</a>
</section>
<?php else: ?>
<section class="admin-public-shell record-shell">
<div class="record-heading">
<div>
<p class="site-eyebrow">Medicine detail</p>
<h1><?= htmlspecialchars(ucfirst((string) $medicine['generic_name']), ENT_QUOTES) ?></h1>
<p><?= htmlspecialchars((string) ($medicine['common_use'] ?: 'Medicine reference entry.'), ENT_QUOTES) ?></p>
</div>
<div class="record-actions">
<a class="site-primary" href="/tracker.php">Open tracker</a>
<a class="site-secondary" href="/nutrition.php?q=<?= rawurlencode((string) $medicine['generic_name']) ?>">Catalog search</a>
</div>
</div>
<div class="record-meta">
<span><?= htmlspecialchars((string) ($medicine['class_name'] ?: 'Medication'), ENT_QUOTES) ?></span>
<span><?= htmlspecialchars((string) ($medicine['drug_family'] ?: $medicine['source_name'] ?: 'Reference catalog'), ENT_QUOTES) ?></span>
<span>ID <?= htmlspecialchars((string) $medicine['id'], ENT_QUOTES) ?></span>
</div>
</section>
<section class="admin-public-shell">
<div class="record-detail-grid">
<article class="record-field">
<span>Active Ingredient</span>
<p><?= htmlspecialchars((string) ($medicine['active_ingredient'] ?: $medicine['generic_name']), ENT_QUOTES) ?></p>
</article>
<article class="record-field">
<span>Chemical Name</span>
<p><?= htmlspecialchars((string) ($medicine['chemical_name'] ?: $medicine['active_ingredient'] ?: $medicine['generic_name']), ENT_QUOTES) ?></p>
</article>
<article class="record-field">
<span>Common Brands</span>
<p><?= htmlspecialchars((string) ($medicine['brand_names'] ?: 'Brand names vary by market.'), ENT_QUOTES) ?></p>
</article>
<article class="record-field">
<span>Generic / Alternate Names</span>
<p><?= htmlspecialchars((string) ($medicine['generic_brands'] ?: $medicine['generic_name']), ENT_QUOTES) ?></p>
</article>
<article class="record-field wide">
<span>Tracking Note</span>
<p><?= htmlspecialchars((string) ($medicine['tracking_note'] ?: 'Track dose, frequency, route, prescriber, status, side effects, and patient-specific notes.'), ENT_QUOTES) ?></p>
</article>
<article class="record-field wide">
<span>Reference Links</span>
<div class="source-links">
<?php foreach ($referenceLinks as $label => $url): ?>
<a href="<?= htmlspecialchars((string) $url, ENT_QUOTES) ?>"><?= htmlspecialchars($label, ENT_QUOTES) ?></a>
<?php endforeach; ?>
</div>
</article>
</div>
</section>
<?php if ($relatedStudies): ?>
<section class="admin-public-shell">
<div class="site-section-heading">
<p class="site-eyebrow">Research</p>
<h2>Related NIH/NLM study links</h2>
</div>
<div class="library-list">
<?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['study_type'], ENT_QUOTES) ?></span>
</div>
</div>
<div class="source-links library-row-actions">
<a href="<?= htmlspecialchars((string) $study['source_url'], ENT_QUOTES) ?>"><?= htmlspecialchars((string) $study['nih_source'], ENT_QUOTES) ?></a>
<a href="<?= htmlspecialchars((string) $study['pubmed_url'], ENT_QUOTES) ?>">PubMed</a>
<a href="<?= htmlspecialchars((string) $study['clinicaltrials_url'], ENT_QUOTES) ?>">ClinicalTrials.gov</a>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php endif; ?>
</main>
<?php require __DIR__ . '/partials/site-footer.php'; ?>
+30 -20
View File
@@ -46,27 +46,37 @@ require __DIR__ . '/partials/site-header.php';
</div> </div>
</section> </section>
<section class="detail-grid"> <section class="admin-public-shell">
<?php foreach ($medicines as $medicine): ?> <div class="site-section-heading">
<article> <p class="site-eyebrow">Catalog directory</p>
<h2><?= htmlspecialchars(ucfirst($medicine['generic_name']), ENT_QUOTES) ?></h2> <h2>Medicine records</h2>
<p><strong><?= htmlspecialchars($medicine['class_name'], ENT_QUOTES) ?></strong></p> </div>
<p><strong>Active ingredient:</strong> <?= htmlspecialchars($medicine['active_ingredient'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p>
<p><strong>Chemical name:</strong> <?= htmlspecialchars($medicine['chemical_name'] ?: $medicine['active_ingredient'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p> <?php if (!$medicines): ?>
<p><strong>Common brands:</strong> <?= htmlspecialchars($medicine['brand_names'] ?: 'Brand names vary by market', ENT_QUOTES) ?></p> <article class="empty-state">
<p><strong>Generic/alternate names:</strong> <?= htmlspecialchars($medicine['generic_brands'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p> <h3>No medicines found.</h3>
<p><?= htmlspecialchars($medicine['common_use'], ENT_QUOTES) ?></p> <p>Try a generic name, brand name, chemical name, or medication class.</p>
<p><?= htmlspecialchars($medicine['tracking_note'], ENT_QUOTES) ?></p>
<div class="source-links">
<a href="<?= htmlspecialchars($medicine['rxnorm_url'], ENT_QUOTES) ?>">RxNorm</a>
<a href="<?= htmlspecialchars($medicine['pubchem_url'], ENT_QUOTES) ?>">PubChem</a>
<a href="<?= htmlspecialchars($medicine['dailymed_url'], ENT_QUOTES) ?>">DailyMed</a>
<a href="<?= htmlspecialchars($medicine['medlineplus_url'], ENT_QUOTES) ?>">MedlinePlus</a>
<a href="<?= htmlspecialchars($medicine['pubmed_url'], ENT_QUOTES) ?>">PubMed</a>
<a href="<?= htmlspecialchars($medicine['clinicaltrials_url'], ENT_QUOTES) ?>">Studies</a>
</div>
</article> </article>
<?php endforeach; ?> <?php else: ?>
<div class="library-list">
<?php foreach ($medicines as $medicine): ?>
<article class="library-row">
<div class="library-row-main">
<h3><?= htmlspecialchars(ucfirst((string) $medicine['generic_name']), ENT_QUOTES) ?></h3>
<p><?= htmlspecialchars((string) ($medicine['common_use'] ?: $medicine['tracking_note'] ?: 'Medicine reference entry.'), ENT_QUOTES) ?></p>
<div class="library-row-meta">
<span><?= htmlspecialchars((string) ($medicine['class_name'] ?: 'Medication'), ENT_QUOTES) ?></span>
<span>Active: <?= htmlspecialchars((string) ($medicine['active_ingredient'] ?: $medicine['generic_name']), ENT_QUOTES) ?></span>
<span>Brands: <?= htmlspecialchars((string) ($medicine['brand_names'] ?: 'Vary by market'), ENT_QUOTES) ?></span>
</div>
</div>
<div class="library-row-actions">
<a class="site-primary" href="<?= htmlspecialchars(medicine_detail_path($medicine), ENT_QUOTES) ?>">View medicine</a>
</div>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section> </section>
</main> </main>
<?php require __DIR__ . '/partials/site-footer.php'; ?> <?php require __DIR__ . '/partials/site-footer.php'; ?>
+128
View File
@@ -0,0 +1,128 @@
<?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((string) $condition['source_url'], ENT_QUOTES) ?>">Source</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((string) ($medicine['common_use'] ?: $medicine['class_name']), 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'; ?>