# Medical Tracker

A dependency-free PHP, HTML5, JavaScript, and SQLite web app for multi-user medical tracking, searchable medical reference data, medication catalog lookup, common-use and official-label medicine context, terminology, symptoms, conditions, NIH/NLM study links, and admin-managed profiles.

This app is a personal tracking and reference tool. It is not medical advice, diagnosis, treatment guidance, emergency guidance, or a substitute for a clinician or pharmacist.

## Run

```sh
frankenphp php-server --root public --listen 127.0.0.1:8080
```

Then open:

```text
http://127.0.0.1:8080
```

## Public Routes

- `/` - medical reference hub with search, database totals, and links to tracker/admin tools.
- `/nutrition.php` - searchable medicine catalog.
- `/medicine.php?id=46` - dynamic medicine detail page backed by SQLite.
- `/symptoms.php` - searchable symptom reference database.
- `/symptom.php?id=24` - dynamic symptom detail page backed by SQLite.
- `/workouts.php` - searchable condition reference database.
- `/condition.php?id=2` - dynamic condition detail page backed by SQLite.
- `/medical.php` - combined search for symptoms, terminology, conditions, medicines, and study links.
- `/term.php?id=1` - dynamic medical terminology detail page backed by SQLite.
- `/recovery.php` - NIH/NLM research and study-link categories.
- `/tracker.php` - profile-scoped medical tracker dashboard.
- `/admin.php` - admin user-management dashboard and medicine-source updater.
- `/signup.php` - legacy route that redirects to `/tracker.php`; public signup has been removed.

## Current Data

SQLite is created automatically at:

```text
data/health_tracker.sqlite
```

The current SQLite snapshot includes:

- 7,646 medicine catalog records.
- 200 openFDA label-derived medicine use summaries.
- 308 symptom reference records.
- 283 condition reference records.
- 23 medical terminology records.
- 9 NIH/NLM research-link categories.
- 8,077 medicine-to-condition links.
- 10,590 medicine-to-symptom links.

The database also stores user profiles, medication logs, vitals, lab results, symptom logs, allergies, appointments, immunizations, optional legacy workout/nutrition/supplement data, theme preferences, and admin state.

## Included

- Multi-user profiles with separate medical records and theme preferences.
- First user in a database is automatically promoted to `admin`; later users default to `member`.
- Admin dashboard for creating, editing, activating/deactivating, and deleting profiles.
- Admin medicine-source updater for refreshing catalog data from RxNorm, DailyMed, and openFDA.
- Profile-scoped tracker for medication logs, vitals, lab results, symptoms, allergies, appointments, immunizations, notes, and older wellness data.
- Searchable medicine catalog by generic name, active ingredient, chemical name, common brand names, generic/alternate names, class, family, what the medicine is used for, linked conditions, linked symptoms, and source terms.
- Dynamic medicine pages with active ingredient, chemical name, brand names, what the medicine is used for, openFDA label-use source links when available, linked conditions, linked symptom contexts, tracking notes, RxNorm, DailyMed, PubChem, MedlinePlus, PubMed, and ClinicalTrials.gov links.
- Searchable symptom database with body-system categories, tracking notes, urgency-context notes, MedlinePlus links, and dynamic detail pages.
- Searchable condition database with category summaries, tracking notes, MedlinePlus links, and dynamic detail pages.
- Dynamic condition and symptom pages with commonly linked medicines generated from therapeutic-use categories.
- Medical terminology database with plain-language definitions, clinical context, source links, and dynamic detail pages.
- Combined medical library search across symptoms, conditions, terminology, medicines, and research links.
- NIH/NLM study-link categories related to listed medicines and conditions.
- Dark neon theme by default, light mode option, and green, blue, red, pink, and orange accents.

## Medicine Catalog Updates

The medicine catalog ships with a curated starter set and the current SQLite snapshot includes thousands of imported medicine concepts. It can be refreshed from public sources, then re-linked to conditions and symptom contexts.

From the admin dashboard, use the medicine source updater and choose `All sources`, `RxNorm`, `DailyMed`, or `openFDA`.

From the command line:

```sh
frankenphp php-cli scripts/update_medicine_catalog.php 1000 all
```

For periodic maintenance, run the same command nightly or weekly. The first argument is the max rows per source, from `25` to `5000`; the second argument is `all`, `RxNorm`, `DailyMed`, or `openFDA`.

The updater imports RxNorm ingredient concepts, DailyMed drug names, and openFDA label records. openFDA rows prefer official label `indications_and_usage` text and fall back to label `purpose` text when available, then continue filling generic, brand, and substance buckets for broader catalog coverage. Imported rows are also enriched with rule-based common-use context when the medicine name, class, family, official use text, or source terms clearly match a therapeutic category.

## API

Main API endpoint:

```text
public/api.php
```

Useful actions:

- `GET api.php?action=state` - tracker/admin state payload.
- `GET api.php?action=library_search&q=chest&limit=20` - combined reference search.
- `POST api.php?action=create_user` - create a user profile from admin/tracker tools.
- `POST api.php?action=update_user` - update a user profile.
- `POST api.php?action=delete_user` - delete a user profile.
- `POST api.php?action=refresh_medication_sources` - refresh the medicine catalog from configured public sources.

The old `public_signup` action has been removed.

## Reference Sources

- MedlinePlus health topics, symptoms, conditions, labs, and drug information: `https://medlineplus.gov/`
- RxNorm and RxNav from the U.S. National Library of Medicine: `https://www.nlm.nih.gov/research/umls/rxnorm/index.html`
- DailyMed label search from the U.S. National Library of Medicine: `https://dailymed.nlm.nih.gov/dailymed/`
- PubChem chemical and compound search from NCBI: `https://pubchem.ncbi.nlm.nih.gov/`
- PubMed research search: `https://pubmed.ncbi.nlm.nih.gov/`
- ClinicalTrials.gov study search: `https://clinicaltrials.gov/`
- openFDA drug label data: `https://open.fda.gov/apis/drug/label/`
- openFDA drug label searchable fields, including `indications_and_usage` and `purpose`: `https://open.fda.gov/apis/drug/label/searchable-fields/`

## Notes

- This project intentionally avoids a public signup funnel. Profiles are managed through `/admin.php` and `/tracker.php`.
- Dynamic detail pages use shared PHP endpoints and pull records from SQLite; individual medicine, symptom, condition, and term pages do not need to exist as separate files.
- Legacy workout, nutrition, and supplement tracker data remains in the schema as wellness context, but the public app focus is now medical tracking and reference lookup.
