=== CNX Medical Lite - Clinic EHR & Appointments ===
Contributors: joerocknpc
Donate link: https://cnxmedical.com
Tags: clinic, ehr, patient management, appointments, medical records
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 8.0
Stable tag: 0.19.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Self-hosted clinic management for WordPress by CNX Medical — patient records (EHR), appointments, screening, treatment, labs, X-ray and billing in one app.

== Description ==

CNX Medical turns your WordPress site into a complete, **self-hosted** clinic management system (EHR). All data stays in your own WordPress database — nothing is sent to any third-party service.

The whole clinic workflow runs inside one fast single-page app, opened from your site at `/cnxmedical/`. It is fully **bilingual (Thai / English)** with a one-click language switch, and a configurable display currency.

= Complete outpatient workflow =

* **Patients** — full medical records: HN, national ID, demographics, allergies, chronic disease, current medication, emergency contact.
* **Appointments** — schedule with status tracking (pending / arrived / postponed / cancelled).
* **Screening** — open a visit, record vital signs (BP, pulse, temp, weight/height with auto-BMI), chief complaint and history; alert the doctor.
* **Treatment room** — diagnose (ICD-10), order examinations, prescribe drugs with stock awareness, add procedures, and order labs / X-rays, then send to billing. Order follows clinical flow: diagnosis → examination → drugs → procedure → lab → X-ray.
* **Lab room** — enter results for single-value, choice and multi-detail (panel) labs with sex/age reference ranges.
* **X-ray room** — read studies and attach images (PNG/JPG).
* **Billing** — auto-generated invoices from the visit, take payment (cash / transfer / QR / card) with change calculation and payment history.
* **Dashboard** — today's appointments, visits, queues, pending invoices, revenue and low-stock alerts at a glance.

= Master data you control =

A built-in **Settings** area lets the clinic owner manage everything: doctors, rooms, lab tests (with reference ranges), X-ray items, drugs & stock, ICD-10 diagnosis codes, medical procedures, examination/service fees, and the display currency.

= Privacy & self-hosting =

* No external API calls, trackers, or analytics.
* Fonts are bundled and served from your own server (no Google Fonts / CDN requests).
* All patient and clinical data lives in your WordPress database.

= Pro version =

A separate **CNX Medical Pro** add-on (hosted on [cnxmedical.com](https://cnxmedical.com)) extends the free plugin with advanced reporting, a patient portal, multi-branch support and more. The free plugin is fully functional on its own and never disables features to force an upgrade.

= Open-source components =

This plugin bundles the following open-source libraries (no external requests):

* Vue 3 — MIT License
* Vue Router — MIT License
* Pinia — MIT License
* Kanit font — SIL Open Font License 1.1

== Installation ==

1. Upload the `cnxmedical` folder to `/wp-content/plugins/`, or install the ZIP via **Plugins → Add New → Upload Plugin**.
2. Activate the plugin through the **Plugins** menu in WordPress. Activation creates the database tables and seeds sample master data (rooms, doctors, labs, X-ray items, drugs, ICD-10 codes, procedures and examination fees).
3. Open the clinic app from the **"Open app"** link on the Plugins list, or visit `https://your-site.com/cnxmedical/`.
4. If you get a 404 on the app URL, go to **Settings → Permalinks** and click **Save** once to flush rewrite rules.

Requires PHP 8.0+ and WordPress 6.0+. The `mbstring` PHP extension is recommended for Thai text.

== Frequently Asked Questions ==

= Where do I open the clinic app? =
After activation, open `https://your-site.com/cnxmedical/` (or click "Open app" on the Plugins screen). It is a full-page application for clinic staff and requires a logged-in WordPress user.

= Does it send any data to external services? =
No. CNX Medical is fully self-hosted. There are no third-party API calls, trackers or analytics, and the Kanit font is served from your own server — not Google Fonts.

= Is it available in English? =
Yes. The interface is bilingual Thai / English. Use the TH / EN toggle in the top bar; the choice is remembered per browser. Thai is the default.

= Can I change the currency shown on invoices? =
Yes. Go to **Settings → General** and pick a currency symbol (฿, $, €, £, ¥ …) or enter your own. It updates across invoices and every money display instantly.

= Who can access patient data? =
Only logged-in WordPress users. Master-data settings require the `manage_options` capability (administrators).

= Where is patient data stored? =
In custom tables in your own WordPress database (prefixed `cnxmedical_`). Nothing leaves your server.

= How do I build the front-end from source? =
The Vue source lives in `src/`. Run `npm install` then `npm run build` to regenerate the compiled assets in `dist/`.

== Screenshots ==

1. Dashboard — today's clinic overview with queues, revenue and low-stock alerts.
2. Patient records list.
3. Screening — vital signs and chief complaint.
4. Treatment room — diagnosis, examinations, prescription, lab and X-ray orders.
5. Billing — invoice and payment.
6. Settings — manage doctors, rooms, labs, drugs, ICD-10 and currency.

== Source Code & Build ==

This plugin's admin app is built with Vue 3 + Vite. The full, uncompiled human-readable source is shipped inside the plugin in the `src/` directory. The production bundle in `dist/` (admin.js, admin.css) is generated from it.

To build it yourself from the plugin folder:

1. `npm install`
2. `npm run build`

This regenerates `dist/admin.js` and `dist/admin.css` from `src/`. Build configuration is in `package.json` and `vite.config.js`, both included in the plugin.

== Changelog ==

= 0.19.6 =
* Fixed the Kanit font not applying after the prefix rename (standalone body class mismatch).

= 0.19.5 =
* Renamed all internal prefixes (namespace, constants, options, database tables, asset handles) from the 3-letter `cnx`/`CNX` to `cnxmedical`/`CNXMEDICAL` to avoid collisions.
* Escaped late: hardened the self-hosted font inline style output.
* Documented the build process and bundled source in the readme.

= 0.19.4 =
* Renamed to "CNX Medical Lite - Clinic EHR & Appointments" (more distinctive).
* Dedicated capability "manage_cnxmedical" for clinic data (no longer generic edit_posts); X-ray upload also requires upload_files.
* Self-hosted fonts now enqueued via wp_add_inline_style (no inline style tag).
* Admin menu moved to a lower position.

= 0.19.3 =
* Renamed to "CNX Medical Lite" with a Lite badge in the app header.
* Blood group options simplified to A / B / AB / O.

= 0.19.2 =
* Header: the company site is now the Author URI (no separate plugin URI).

= 0.19.1 =
* Header clean-up: removed a duplicate URI.

= 0.19.0 =
* Renamed the plugin to "CNX Medical - clinic & patient management system".
* Uninstall now removes every plugin table and option for a complete clean-up.

= 0.18.2 =
* The patient list now starts empty on a fresh install (sample master data is still seeded; demo patients removed).

= 0.18.1 =
* Self-hosted the Kanit font (bundled woff2) — removed all Google Fonts / external requests.
* Treatment room: examination tab now appears before prescribing, matching clinical flow.
* Settings: new "Examinations" (service/exam fees) manager with sample data.

= 0.17.0 =
* New **Settings → General**: configurable display currency (฿ / USD / EUR / custom) used across the whole app; removed hard-coded currency.

= 0.16.0 =
* Settings: manage **ICD-10** diagnosis codes (with ~70 seeded common codes, paginated) and **medical procedures**.
* Full Thai / English bilingual UI across every page with a TH/EN switch.

= 0.14.0 =
* Appointments module.
* Dashboard with live clinic metrics.

= 0.13.0 =
* Billing / invoices with payment recording.

= 0.10.0 =
* Lab and X-ray rooms with result entry and image upload.

= 0.5.0 =
* Treatment room: diagnosis, prescriptions, procedures, examinations, lab/X-ray ordering.

= 0.1.0 =
* Initial release: patients, screening and clinic settings.

== Upgrade Notice ==

= 0.19.0 =
Plugin renamed and uninstall now fully cleans up all tables and options.
