- The medicine database is now much bigger and has a real update path.
Added: Live source updater for RxNorm, DailyMed, and openFDA. Admin dashboard panel to refresh medicine sources. CLI updater for periodic jobs: [scripts/update_medicine_catalog.php](/Users/tyemeclifford/Documents/GH/workout/scripts/update_medicine_catalog.php) Update history table: medication_source_updates. Curl fallback for external fetches when PHP stream DNS fails. README instructions for periodic updates. I also ran the imports: Current medication catalog count: 6,002. Latest source imports:RxNorm: 3,875 inserted, 1,125 updated. openFDA: 912 inserted, 88 updated. DailyMed: 95 inserted. Periodic update command: /Users/tyemeclifford/frankenphp php-cli scripts/update_medicine_catalog.php 5000 all
This commit is contained in:
@@ -31,6 +31,21 @@ require __DIR__ . '/partials/site-header.php';
|
||||
|
||||
<section class="admin-panel site-admin-panel" id="adminPanel" hidden>
|
||||
<div class="admin-stats" id="adminStats"></div>
|
||||
|
||||
<section class="admin-source-panel">
|
||||
<div class="site-section-heading">
|
||||
<p class="site-eyebrow">Medicine source updater</p>
|
||||
<h2>Refresh the medication catalog from public sources.</h2>
|
||||
<p>Pull medicine concepts from RxNorm, DailyMed, and openFDA. Use a smaller limit for quick checks or a larger limit for periodic maintenance.</p>
|
||||
</div>
|
||||
<form class="admin-source-form" id="medicineSourceRefreshForm">
|
||||
<label class="site-field"><span>Source</span><select name="source"><option value="all">All sources</option><option>RxNorm</option><option>DailyMed</option><option>openFDA</option></select></label>
|
||||
<label class="site-field"><span>Max rows per source</span><input name="limit" type="number" min="25" max="5000" step="25" value="1000"></label>
|
||||
<button class="site-primary" type="submit">Refresh medicines</button>
|
||||
</form>
|
||||
<div class="source-refresh-result" id="medicineSourceRefreshResult" role="status" aria-live="polite"></div>
|
||||
</section>
|
||||
|
||||
<div class="admin-layout">
|
||||
<div class="admin-user-list" id="adminUserList"></div>
|
||||
<form class="admin-editor" id="adminUserForm">
|
||||
|
||||
@@ -45,6 +45,7 @@ try {
|
||||
'create_allergy_record' => 'create_allergy_record',
|
||||
'create_appointment' => 'create_appointment',
|
||||
'create_immunization_record' => 'create_immunization_record',
|
||||
'refresh_medication_sources' => 'refresh_medication_sources',
|
||||
];
|
||||
|
||||
if (!isset($routes[$action])) {
|
||||
|
||||
@@ -186,6 +186,22 @@ function adminFormPayload(form) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
function renderRefreshResult(result) {
|
||||
const target = admin$("#medicineSourceRefreshResult");
|
||||
if (!target) return;
|
||||
const rows = (result.sources || []).map((source) => `
|
||||
<article>
|
||||
<strong>${adminEscape(source.source)}: ${adminEscape(source.status)}</strong>
|
||||
<span>${adminNumber(source.inserted)} inserted / ${adminNumber(source.updated)} updated</span>
|
||||
<small>${adminEscape(source.message || "")}</small>
|
||||
</article>
|
||||
`).join("");
|
||||
target.innerHTML = `
|
||||
<p>${adminNumber(result.catalog_count)} medicines in catalog after refresh.</p>
|
||||
<div class="source-refresh-list">${rows}</div>
|
||||
`;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
admin$("#adminProfileSelect").addEventListener("change", async (event) => {
|
||||
adminState.userId = event.target.value;
|
||||
@@ -248,6 +264,27 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
const refreshForm = admin$("#medicineSourceRefreshForm");
|
||||
if (refreshForm) {
|
||||
refreshForm.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const payload = adminFormPayload(refreshForm);
|
||||
const button = refreshForm.querySelector("button[type='submit']");
|
||||
if (button) button.disabled = true;
|
||||
admin$("#medicineSourceRefreshResult").textContent = "Refreshing medicine sources...";
|
||||
try {
|
||||
const result = await adminApi("refresh_medication_sources", payload);
|
||||
renderRefreshResult(result);
|
||||
adminToast("Medicine sources refreshed");
|
||||
} catch (error) {
|
||||
admin$("#medicineSourceRefreshResult").textContent = error.message;
|
||||
adminToast(error.message);
|
||||
} finally {
|
||||
if (button) button.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await loadAdminState();
|
||||
} catch (error) {
|
||||
|
||||
+106
-1
@@ -394,6 +394,64 @@ figcaption a {
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.library-search {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||
gap: 10px;
|
||||
align-items: end;
|
||||
margin: 12px 0 18px;
|
||||
}
|
||||
|
||||
.library-search label {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 0.82rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.library-search input {
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: color-mix(in srgb, var(--panel-2), transparent 6%);
|
||||
color: var(--text);
|
||||
padding: 12px 14px;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.library-search input:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 76%);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.library-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.library-stats article {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: color-mix(in srgb, var(--panel-2), transparent 6%);
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.library-stats strong {
|
||||
display: block;
|
||||
color: var(--accent);
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.library-stats span {
|
||||
color: var(--muted);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.site-split,
|
||||
.detail-hero,
|
||||
.signup-layout {
|
||||
@@ -555,6 +613,47 @@ textarea:focus {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.admin-source-panel {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: color-mix(in srgb, var(--panel-2), transparent 5%);
|
||||
padding: 14px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.admin-source-form {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 190px auto;
|
||||
gap: 10px;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.source-refresh-result {
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.source-refresh-list {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.source-refresh-list article {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: color-mix(in srgb, var(--panel), transparent 10%);
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.source-refresh-list span,
|
||||
.source-refresh-list small {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.admin-layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
|
||||
@@ -718,7 +817,8 @@ textarea:focus {
|
||||
.site-split,
|
||||
.detail-hero,
|
||||
.signup-layout,
|
||||
.admin-layout {
|
||||
.admin-layout,
|
||||
.admin-source-form {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -753,11 +853,16 @@ textarea:focus {
|
||||
.feature-grid,
|
||||
.detail-grid,
|
||||
.admin-stats,
|
||||
.library-stats,
|
||||
.signup-row,
|
||||
.form-grid.two {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.library-search {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.admin-access-row,
|
||||
.admin-user-main,
|
||||
.panel-heading {
|
||||
|
||||
+35
-8
@@ -6,19 +6,40 @@ $pdo = app_db();
|
||||
|
||||
$pageTitle = 'Medical Terminology Database | Neon Medical Tracker';
|
||||
$activePage = 'terminology';
|
||||
$terms = db_all($pdo, 'SELECT * FROM medical_terms ORDER BY category, term');
|
||||
$conditions = db_all($pdo, 'SELECT * FROM medical_conditions ORDER BY category, name');
|
||||
$medicines = db_all($pdo, 'SELECT * FROM medication_catalog ORDER BY generic_name');
|
||||
$studies = db_all($pdo, 'SELECT * FROM research_studies ORDER BY category, related_medicine, title');
|
||||
$searchQuery = trim((string) ($_GET['q'] ?? ''));
|
||||
$library = library_search_payload(['q' => $searchQuery, 'limit' => 500]);
|
||||
$terms = $library['medicalTerms'];
|
||||
$conditions = $library['medicalConditions'];
|
||||
$medicines = $library['medicationCatalog'];
|
||||
$studies = $library['researchStudies'];
|
||||
$totalMedicines = (int) db_value($pdo, 'SELECT COUNT(*) FROM medication_catalog');
|
||||
|
||||
require __DIR__ . '/partials/site-header.php';
|
||||
?>
|
||||
<main>
|
||||
<section class="admin-public-shell">
|
||||
<div class="site-section-heading">
|
||||
<p class="site-eyebrow">Medical terminology database</p>
|
||||
<h1>Terms, conditions, medicines, and NIH/NLM study links.</h1>
|
||||
<p>Entries are concise app-authored summaries with links to NIH/NLM systems such as MedlinePlus, RxNorm, PubMed, and ClinicalTrials.gov. This is a tracking/reference aid, not medical advice.</p>
|
||||
<p class="site-eyebrow">Searchable medical library</p>
|
||||
<h1>Search terms, conditions, medicines, chemical names, and brands.</h1>
|
||||
<p>Entries are concise app-authored summaries with links to NIH/NLM systems such as MedlinePlus, RxNorm, DailyMed, PubChem, PubMed, and ClinicalTrials.gov. This is a tracking/reference aid, not medical advice.</p>
|
||||
</div>
|
||||
|
||||
<form class="library-search" method="get" action="/medical.php">
|
||||
<label>
|
||||
<span>Search medical library</span>
|
||||
<input name="q" value="<?= htmlspecialchars($searchQuery, ENT_QUOTES) ?>" placeholder="Try Lipitor, atorvastatin, blood pressure, CBC, metformin">
|
||||
</label>
|
||||
<button class="site-primary" type="submit">Search</button>
|
||||
<?php if ($searchQuery !== ''): ?>
|
||||
<a class="site-secondary" href="/medical.php">Clear</a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
|
||||
<div class="library-stats" aria-label="Search result counts">
|
||||
<article><strong><?= count($medicines) ?></strong><span><?= $searchQuery === '' ? 'medicines shown of ' . number_format($totalMedicines) : 'medicine results' ?></span></article>
|
||||
<article><strong><?= count($terms) ?></strong><span>terms</span></article>
|
||||
<article><strong><?= count($conditions) ?></strong><span>conditions</span></article>
|
||||
<article><strong><?= count($studies) ?></strong><span>study links</span></article>
|
||||
</div>
|
||||
|
||||
<div class="detail-grid">
|
||||
@@ -57,17 +78,23 @@ require __DIR__ . '/partials/site-header.php';
|
||||
<section class="admin-public-shell">
|
||||
<div class="site-section-heading">
|
||||
<p class="site-eyebrow">Medication catalog</p>
|
||||
<h2>Medicines with RxNorm, PubMed, and ClinicalTrials.gov links</h2>
|
||||
<h2>Medicines with chemical, brand, RxNorm, DailyMed, and PubChem links</h2>
|
||||
</div>
|
||||
<div class="detail-grid">
|
||||
<?php foreach ($medicines as $medicine): ?>
|
||||
<article>
|
||||
<h2><?= htmlspecialchars(ucfirst($medicine['generic_name']), ENT_QUOTES) ?></h2>
|
||||
<p><strong><?= htmlspecialchars($medicine['class_name'], ENT_QUOTES) ?></strong></p>
|
||||
<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>
|
||||
<p><strong>Common brands:</strong> <?= htmlspecialchars($medicine['brand_names'] ?: 'Brand names vary by market', ENT_QUOTES) ?></p>
|
||||
<p><strong>Generic/alternate names:</strong> <?= htmlspecialchars($medicine['generic_brands'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p>
|
||||
<p><?= htmlspecialchars($medicine['common_use'], ENT_QUOTES) ?></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>
|
||||
|
||||
+28
-3
@@ -6,7 +6,10 @@ $pdo = app_db();
|
||||
|
||||
$pageTitle = 'Medicine Catalog | Neon Medical Tracker';
|
||||
$activePage = 'medicines';
|
||||
$medicines = db_all($pdo, 'SELECT * FROM medication_catalog ORDER BY generic_name');
|
||||
$searchQuery = trim((string) ($_GET['q'] ?? ''));
|
||||
$library = library_search_payload(['q' => $searchQuery, 'limit' => 500]);
|
||||
$medicines = $library['medicationCatalog'];
|
||||
$totalMedicines = (int) db_value($pdo, 'SELECT COUNT(*) FROM medication_catalog');
|
||||
$photo = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/A_large_mixed_salad.jpg/1024px-A_large_mixed_salad.jpg';
|
||||
require __DIR__ . '/partials/site-header.php';
|
||||
?>
|
||||
@@ -21,21 +24,43 @@ require __DIR__ . '/partials/site-header.php';
|
||||
</figure>
|
||||
<div>
|
||||
<p class="site-eyebrow">Medicine catalog</p>
|
||||
<h1>Track medicines with source links beside every catalog entry.</h1>
|
||||
<p>The starter catalog includes common medicines and links each one to RxNorm, MedlinePlus, PubMed, and ClinicalTrials.gov searches.</p>
|
||||
<h1>Search medicines by generic, chemical, brand, and alternate names.</h1>
|
||||
<p>The catalog includes common medicines and links each one to RxNorm, DailyMed, PubChem, MedlinePlus, PubMed, and ClinicalTrials.gov searches.</p>
|
||||
<a class="site-primary" href="/tracker.php">Open medical tracker</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="admin-public-shell">
|
||||
<form class="library-search" method="get" action="/nutrition.php">
|
||||
<label>
|
||||
<span>Search medicine catalog</span>
|
||||
<input name="q" value="<?= htmlspecialchars($searchQuery, ENT_QUOTES) ?>" placeholder="Try Zoloft, sertraline, insulin, acetaminophen, blood pressure">
|
||||
</label>
|
||||
<button class="site-primary" type="submit">Search</button>
|
||||
<?php if ($searchQuery !== ''): ?>
|
||||
<a class="site-secondary" href="/nutrition.php">Clear</a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<div class="library-stats" aria-label="Medicine result count">
|
||||
<article><strong><?= count($medicines) ?></strong><span><?= $searchQuery === '' ? 'shown of ' . number_format($totalMedicines) . ' medicines' : 'medicine results' ?></span></article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="detail-grid">
|
||||
<?php foreach ($medicines as $medicine): ?>
|
||||
<article>
|
||||
<h2><?= htmlspecialchars(ucfirst($medicine['generic_name']), ENT_QUOTES) ?></h2>
|
||||
<p><strong><?= htmlspecialchars($medicine['class_name'], ENT_QUOTES) ?></strong></p>
|
||||
<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>
|
||||
<p><strong>Common brands:</strong> <?= htmlspecialchars($medicine['brand_names'] ?: 'Brand names vary by market', ENT_QUOTES) ?></p>
|
||||
<p><strong>Generic/alternate names:</strong> <?= htmlspecialchars($medicine['generic_brands'] ?: $medicine['generic_name'], ENT_QUOTES) ?></p>
|
||||
<p><?= htmlspecialchars($medicine['common_use'], ENT_QUOTES) ?></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>
|
||||
|
||||
Reference in New Issue
Block a user