Custom plugin integration specification
Developer-ready brief for the Sara Care plugin (Phase 2b). Written against the Phase 1–3 preview pages, so every screen already exists as a design to implement.
1. Scope, status and what exists today
| Area | In the preview today | Needs the plugin |
|---|---|---|
| Public pages, branding, navigation | Built and complete | Nothing |
| 5-step booking form | Working form (Kreebi), saves submissions, emails admin | Server-side ID generation, patient lookup, real test catalogue, status writes |
| Test selection | Free-text field plus the published catalogue page | Dynamic checkbox selection bound to the catalogue table |
| Reception, patients, visits, reports, billing, staff, portal | Static prototypes with demo data | Every data operation, auth and file storage |
2. Required database tables
Use dbDelta() with {$wpdb->prefix}sc_ tables. Times stored as datetime in site timezone (Asia/Kolkata), never as strings.
| Table | Key columns | Relationships |
|---|---|---|
sc_patients | id, patient_code (UNIQUE), full_name, mobile, mobile_norm, email, age, gender, address, notes, created_at, created_by, updated_at, updated_by | 1→many visits, bookings, invoices |
sc_bookings | id, booking_ref (UNIQUE), patient_id, source (online/walkin/reception), status, requested_date, requested_slot, visit_type, collection_address, collection_slot, contact_person, collection_instructions, notes, categories_json, consent_at, created_at, created_by, updated_at, updated_by | patient_id → sc_patients; 0..1 → visits |
sc_visits | id, visit_code (UNIQUE), patient_id, booking_id (NULL for walk-in), visit_type, visit_status, workflow_colour (orange/blue/green), scheduled_at, sample_collected_at, collected_by, created_at, updated_at, updated_by | patient_id, booking_id; 1→many test_orders; 1→many status_history |
sc_test_orders | id, order_code (UNIQUE), visit_id, test_id, category, price_snapshot, status, report_status, sample_status, ordered_at, performed_by, authorised_by, authorised_at | visit_id → sc_visits; test_id → sc_tests |
sc_tests | id, test_code, name, category, description, preparation, report_time, price, is_package, is_active, enquiry_only (bool), updated_by, updated_at | referenced by test_orders and packages |
sc_packages / sc_package_items | package id, name, price, description, is_active / package_id, test_id | Many-to-many with sc_tests |
sc_status_history | id, visit_id, test_order_id (NULL), from_status, to_status, colour, note, staff_id, created_at | visit_id, staff_id |
sc_reports | id, test_order_id, version, file_path (private), mime, file_size, uploaded_by, uploaded_at, review_status, authorised_by, authorised_at, published_at, replaces_id, is_current | test_order_id; was replaced by another row |
sc_report_handover | id, report_id, receiver_name, receiver_type, handed_by, handed_at, print_count, last_printed_at, remarks | report_id → sc_reports |
sc_invoices / sc_invoice_items / sc_payments | invoice id, invoice_no, patient_id, visit_id, subtotal, discount, total, paid, balance, method, created_by / item lines / payment rows with txn ref | patient_id, visit_id |
sc_staff_log | id, staff_id, action, object_type, object_id, detail_json, ip, created_at | staff_id → wp_users |
sc_login_log | id, staff_id, event (login/logout/failed), ip, user_agent, created_at | staff_id |
sc_messages | id, booking_id/visit_id, channel (whatsapp/email), template, body, queued_at, sent_at, status (queued/sent/failed), provider_ref, staff_id | booking_id, visit_id |
3. Identifiers (server-generated only)
- Patient ID
SC-{YYYY}-{000001}— sequence per calendar year, allocated in the same DB transaction as the patient insert, retried on unique-key collision. Never generated in the browser. - Booking Reference
SCB-{YYYY}-{000001} - Visit ID
SCV-{YYYY}-{000001} - Test Order ID
TO-{YYYY}-{000001} - Invoice number
INV-{YYYY}-{000001} - Use a dedicated
sc_sequencesrow per prefix/year withSELECT … FOR UPDATE, or MySQL auto-increment plus a formatted code column. Return 409 and retry on collision.
4. Staff roles and permissions
| Capability | Receptionist | Technician | Clinical reviewer | Administrator |
|---|---|---|---|---|
| Register patient / walk-in | Yes | No | No | Yes |
| Confirm, reschedule, cancel booking | Yes | No | No | Yes |
| Update sample status | Yes | Yes | No | Yes |
| Upload report | No | Yes | Yes | Yes |
| Clinically authorise / publish report | No | No | Yes (only) | Yes with reviewer flag |
| Hand over report, reprint | Yes | No | No | Yes |
| Billing, receipts, daily closing | Yes | No | No | Yes |
| Test catalogue and prices | No | No | No | Yes |
| Staff management, roles, logs | No | No | No | Yes |
Map to sc_receptionist, sc_technician, sc_reviewer, sc_admin. Enforce with current_user_can() on every admin-post/REST callback plus a nonce; never hide UI only. Authorisation additionally requires a stored qualification flag on the user (registration number of the medical council) that an administrator sets.
5. Booking form wiring (existing Kreebi form)
The live form is the Kreebi form test-booking on page /book-a-test/. Kreebi emails submissions; the plugin must additionally capture them.
| Kreebi field label (exact) | Type | Maps to | Rule |
|---|---|---|---|
| Which services do you need? | checkbox | bookings.categories_json | Required; multiple allowed; X-Ray stored as enquiry only |
| I am not sure which test I need. Please contact me. | checkbox | bookings.contact_me_only | If set, test selection not required |
| Tests or package you need | text | bookings.tests_free_text | Kept as fallback; replaced by test_ids when the dynamic picker lands |
| Doctor's advice or notes about the test | textarea | bookings.notes | Optional |
| Full name | text | patients.full_name | Required |
| Mobile number | text | patients.mobile / mobile_norm | Required; normalise to E.164; reject invalid Indian numbers |
| Email address | patients.email | Optional everywhere; never block submission | |
| Age | number | patients.age | Optional, 0–120 |
| Gender | dropdown | patients.gender | Optional |
| Existing Patient ID | text | bookings.claimed_patient_code | Look up; if found attach to patient, else create new patient and flag for staff review |
| Additional notes | textarea | patients.notes | Optional |
| Preferred appointment date | text (currently) | bookings.requested_date | Change to a date field in Kreebi; store as date, must be today or later |
| Preferred appointment time | dropdown | bookings.requested_slot | Slot enum: 8-11, 11-14, 14-17, 17-20 |
| Visit type | radio | bookings.visit_type | Required: centre | home_collection |
| Collection address / Preferred collection time / Contact person at address / Additional instructions for our collector | textarea, dropdown, text, textarea | bookings.collection_* | Required when visit_type = home_collection; availability confirmed by staff |
| Consent checkbox (privacy) | checkbox | bookings.consent_at | Required; store timestamp and the wording version |
| Requests-until-confirmed checkbox | checkbox | bookings.ack_request_only | Required |
Other Kreebi forms to integrate: report-request on /download-report/ (fields: Patient full name, Registered mobile number, Lab, bill or registration number, Date of sample collection, Tests done, How would you like the report, Email address, Who is requesting the report, Additional notes) and contact on /contact-us/.
6. Endpoints
REST namespace sara-care/v1, all requiring a valid session plus nonce or an application password. Every write validates with a schema and writes an audit row.
| Method + route | Purpose | Permission |
|---|---|---|
POST /bookings | Create booking from the public form: create/match patient, allocate codes, status pending_confirmation | public + rate limit + honeypot |
GET /bookings | Filtered list for the dashboard (date, status, source, search) | receptionist |
PATCH /bookings/{ref} | Confirm, reschedule, cancel, add reception note | receptionist |
GET /catalogue | Active tests and packages for the picker, grouped by category | public (no prices unless configured) |
POST /patients, GET /patients?q= | Register and search patients | receptionist |
POST /visits | Create visit + test orders (walk-in or from a confirmed booking) | receptionist |
PATCH /visits/{code}/status | Sample and workflow transitions with staff name and timestamp | receptionist / technician |
POST /reports, POST /reports/{id}/authorise | Upload a version; authorise and publish | technician uploads; reviewer authorises |
POST /invoices, GET /reports/daily | Billing and daily collection summary | receptionist |
POST /portal/verify, GET /portal/summary | Identity check then booking/visit/report summary | patient, verified per request |
POST /messages/whatsapp | Build a wa.me deep link for a verified mobile number; log queued/sent | receptionist |
7. Status workflows
| Stage | States | Colour | Who sets it |
|---|---|---|---|
| Booking | pending_confirmation → confirmed → rescheduled / cancelled / completed / no_show | Grey → orange on arrival | Receptionist |
| Sample | sample_pending, collected, rejected, recollection_required, outside_lab_dispatch | Orange #D97706 | Receptionist / technician |
| Processing | received, processing, report_pending, partial_report | Blue #2563EB | Technician |
| Report | uploaded → pending_review → authorised → published → handed_over | Green #16A34A when every order on the visit is published | Reviewer publishes; receptionist hands over |
Store workflow state on the visit and each test order, never on the patient. The visit colour is derived: orange while any order is sample pending, blue while any order is processing or report pending, green only when every required order is authorised and published. Every transition inserts into sc_status_history with the logged-in staff id and timestamp.
8. Report files, privacy and patient access
- Upload to
wp-content/uploads/sara-care-reports/outside the public media library, or to a bucket; serve only through a PHP endpoint that checks capability or a short-lived signed token. - Accept PDF only, verify MIME by content, max 20 MB, randomise filenames, block PHP execution in that directory (.htaccess deny or nginx rule).
- Never reuse a file row: replacing a report inserts a new version with
replaces_idand keeps the old row as history. - Authorisation is a separate action from upload and requires the reviewer role plus the qualification flag; store reviewer id, timestamp and version.
- Patient access: verify identity with booking reference + registered mobile (+ optional date of birth) before returning anything; rate limit to 5 attempts per 15 minutes per IP and per mobile; issue a token valid 15 minutes; log every access attempt.
- Handover records receiver name, receiver type, staff, timestamp, version and remarks; reprints increment a counter rather than overwriting history.
9. WhatsApp and email
- Phase 1 uses click-to-chat only: the plugin builds
https://wa.me/91<verified mobile>?text=<urlencoded message>and the receptionist sends it manually. No automated WhatsApp sending is assumed. - Templates: booking received, appointment confirmed, reminder, report ready, rescheduled, cancellation, payment reminder. Message text includes patient name, Patient ID, booking reference, requested date/time, status and the centre's phone number.
- Log every generated message with staff id and status queued/sent/failed; treat "opened in WhatsApp" as queued, since delivery cannot be confirmed by click-to-chat.
- Email: use
wp_mail()and record the actual return value and provider response. Acknowledgement email only when the patient supplied an address and delivery is configured; a missing or failed email never blocks a booking.
10. X-Ray and clinical safeguards
- X-Ray rows carry
enquiry_only = 1: the public form can record an enquiry but must not create a confirmed appointment or take payment. - Guard with a setting the administrator enables only after AERB authorisation and operational readiness; the UI keeps showing the enquiry path meanwhile.
- No clinical interpretation is generated anywhere on the site; reports are uploaded documents authorised by a qualified reviewer.
- Prices are shown only where an administrator has configured them; an empty price renders "Price on enquiry".
11. Security checklist
- Nonces on every state change, capability checks server-side, prepared statements through
$wpdb->prepare(), sanitise on input and escape on output. - Never trust a client-supplied patient id, status or price; re-read from the database inside the transaction.
- Two-factor optional for staff, forced password reset on first login, lockout after 5 failures, session expiry, full login/logout log.
- Rate limit the public booking and portal endpoints; honeypot plus time-trap on the public form.
- Daily database backup before go-live, and a staging copy for testing; keep medical data retention rules documented in the privacy policy.
12. Files, slugs and components to hand over
| File | What it is | Integration note |
|---|---|---|
pages/index.html | Public home page | No data binding |
pages/book-a-test.html | Booking page + Kreebi form marker | Replace free-text test field with the picker component |
pages/laboratory-tests.html | Published test catalogue | Drive from sc_tests when dynamic |
pages/download-report.html | Report request form | Route to plugin instead of email only |
pages/staff-login.html | Staff sign-in design | Use wp_login_form() or a custom login with rate limiting |
pages/reception-dashboard.html | Dashboard prototype | Replace demo rows with GET /bookings |
pages/patient-registration.html | Add patient, search, profile, walk-in, visit | Bind to patient and visit endpoints |
pages/visit-status.html | Sample and visit board | Bind to visit status transitions |
pages/report-management.html | Upload, versions, review, handover | Bind to report endpoints and private storage |
pages/billing.html | Bill, receipt, daily closing, WhatsApp | Bind to invoice endpoints; INR formatting |
pages/patient-portal.html | Public patient status and reports | Public page; data only after verification |
pages/admin-dashboard.html | Admin, staff, roles, logs | Map to WordPress users and capabilities |
pages/test-catalogue.html | Picker demo + catalogue admin UI | Reference implementation for the picker |
assets/staff.css, assets/staff.js | Staff styling and picker behaviour | Reuse inside plugin admin screens |
forms/test-booking.json, report-request.json, contact.json | Kreebi form definitions with exact field labels | Map labels per section 5 |
Suggested plugin layout: sara-care-core/ with sara-care-core.php, includes/db.php, includes/ids.php, includes/roles.php, includes/rest-bookings.php, includes/rest-reports.php, includes/audit.php, admin/dashboard.php, assets/. Page templates for the staff area should be reachable only to logged-in staff.
13. Suggested build order
- Tables, roles and the ID allocator, with unit tests for collision behaviour.
- Patient create/search and booking intake hooked to the Kreebi form.
- Reception dashboard list plus confirm/reschedule/cancel.
- Visit and test order creation, including walk-ins.
- Sample and workflow status transitions with history.
- Report upload, review, publish, handover and version history.
- Billing, receipts and daily closing.
- Patient portal verification and report access.
- Staff management, activity log and login history.
- Dynamic test picker replacing the free-text field on the public form.
Acceptance for go-live: no personal or clinical data is reachable without a capability check or a verified portal session; every write appears in the audit log with a staff id; and X-Ray stays enquiry-only until an administrator enables it.