Add remote SQL script for investigation category backfill

This commit is contained in:
DevSoftTech Server 2026-07-02 19:09:36 +05:30
parent 681bb947b3
commit c832b3a3e2
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,25 @@
-- Backfill blank investigation.category_name values using name-based rules.
-- Safe to run multiple times: updates only rows where category_name is NULL/blank.
START TRANSACTION;
UPDATE investigation
SET category_name = CASE
WHEN LOWER(Name) REGEXP '(^|[^a-z])(x[[:space:]]*[-]?[[:space:]]*ray|xray|radiograph|radiology)([^a-z]|$)' THEN 'X-Ray'
WHEN LOWER(Name) REGEXP '(^|[^a-z])(ultra[[:space:]]*sound|ultrasound|u\\.?s\\.?g\\.?|usg|sonography|doppler)([^a-z]|$)' THEN 'Ultra Sound'
WHEN LOWER(Name) REGEXP '(^|[^a-z])(ct[[:space:]]*[-]?[[:space:]]*scan|cect|hrct|ncct|computed tomography)([^a-z]|$)' THEN 'CT-Scan'
WHEN LOWER(Name) REGEXP '(^|[^a-z])(mri|mr[[:space:]]*i|magnetic resonance)([^a-z]|$)' THEN 'MRI'
WHEN LOWER(Name) REGEXP '(^|[^a-z])(echo|echocardiography|2d[[:space:]]*echo|doppler[[:space:]]*echo)([^a-z]|$)' THEN 'ECHO'
WHEN LOWER(Name) REGEXP '(^|[^a-z])(ecg|electrocardiogram|tmt|holter)([^a-z]|$)' THEN 'Cardiology'
ELSE 'Pathology'
END
WHERE category_name IS NULL OR TRIM(category_name) = '';
SELECT ROW_COUNT() AS updated_rows;
SELECT category_name, COUNT(*) AS total_rows
FROM investigation
GROUP BY category_name
ORDER BY total_rows DESC, category_name ASC;
COMMIT;

View File

@ -0,0 +1,28 @@
# Investigation Category Backfill (Remote)
Run this SQL on remote DB:
scripts/sql/2026-07-02_backfill_investigation_category.sql
## Example (MySQL CLI)
```bash
mysql -u <db_user> -p <db_name> < scripts/sql/2026-07-02_backfill_investigation_category.sql
```
## What it does
- Updates only blank category values in investigation.category_name
- Uses name-based rules to map into:
- Pathology
- X-Ray
- Ultra Sound
- CT-Scan
- MRI
- ECHO
- Cardiology
- Prints updated row count and final category distribution
## Idempotency
Safe to re-run. It only touches rows where category_name is blank/null.