-- v0.5.9.8.53 services/facilities completeness and allergy normalization.
-- The PHP updater performs the comprehensive idempotent seeding. This SQL file
-- keeps the migration ledger explicit and repairs legacy NA allergy values.

UPDATE `{{prefix}}medical_histories`
SET `allergies`=NULL
WHERE LOWER(REPLACE(REPLACE(REPLACE(TRIM(COALESCE(`allergies`,'')),'.',''),'/',''),' ','')) IN ('na','n/a','none','noallergy','noallergies','noknownallergy','noknownallergies','noknowndrugallergy','noknowndrugallergies','nkda','notapplicable','nil');

UPDATE `{{prefix}}patient_intakes`
SET `allergy_changes`=NULL
WHERE LOWER(REPLACE(REPLACE(REPLACE(TRIM(COALESCE(`allergy_changes`,'')),'.',''),'/',''),' ','')) IN ('na','n/a','none','noallergy','noallergies','noknownallergy','noknownallergies','noknowndrugallergy','noknowndrugallergies','nkda','notapplicable','nil');

UPDATE `{{prefix}}appointment_requests`
SET `allergies`=NULL
WHERE LOWER(REPLACE(REPLACE(REPLACE(TRIM(COALESCE(`allergies`,'')),'.',''),'/',''),' ','')) IN ('na','n/a','none','noallergy','noallergies','noknownallergy','noknownallergies','noknowndrugallergy','noknowndrugallergies','nkda','notapplicable','nil');
