Skip to content

Cleanse medication names to title case and normalize legacy rows - #150

Merged
replicant1 merged 1 commit into
mainfrom
feature/medication-title-case-cleansing
Jul 23, 2026
Merged

replicant1 merged 1 commit into
mainfrom
feature/medication-title-case-cleansing

Conversation

@replicant1

Copy link
Copy Markdown
Owner

What this PR does

  • Cleanses medication brandName and activeIngredient into trimmed, single-spaced title case.
  • Applies cleansing in both add flows:
    • Add Medication
    • Add Script (including OCR-prefill and resolution path)
  • Enforces cleansing at the data boundary in MedicationRepository.add(...).
  • Adds retrospective cleanup for existing rows via cleanseExistingMedicationNames() on app startup.
  • Refines edge-case casing rules for medication tokens:
    • release abbreviations: XR, SR, CR, MR, IR, ER, XL, LA, EC, DR, CD, OD, PR
    • chemical abbreviations: HCl, HBr
    • units: mg, mcg, g, kg, ml, l
    • roman numerals: I..X

Files touched

  • app/src/main/java/com/example/aitoui/data/Medication.kt
  • app/src/main/java/com/example/aitoui/data/MedicationDao.kt
  • app/src/main/java/com/example/aitoui/data/MedicationRepository.kt
  • app/src/main/java/com/example/aitoui/medication/MedicationViewModel.kt
  • app/src/main/java/com/example/aitoui/script/AddScriptViewModel.kt
  • app/src/main/java/com/example/aitoui/AitouiApp.kt
  • app/src/test/java/com/example/aitoui/data/MedicationNameCleaningTest.kt

Verification

  • Ran focused JVM tests:
    • :app:testDebugUnitTest --tests "com.example.aitoui.data.MedicationNameCleaningTest"
  • Installed updated debug build on attached Pixel 3 and launched app to trigger startup cleanup.
  • Verified medication rows are title-cased after cleanup.

Copilot AI review requested due to automatic review settings July 23, 2026 03:20
@replicant1
replicant1 merged commit c041575 into main Jul 23, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how medication brandName and activeIngredient are stored/displayed by normalizing them to trimmed, single-spaced title case, and retroactively cleaning legacy rows on app startup to keep existing data consistent.

Changes:

  • Added String.cleanMedicationName() and Medication.cleaned() to normalize medication name fields (including special-case tokens like XR/SR, HCl/HBr, units, roman numerals).
  • Enforced normalization at the repository boundary (MedicationRepository.add(...)) and added a startup cleanup pass for existing rows.
  • Applied normalization in add flows (Medication + Script, including OCR-prefill) and added unit tests for the normalization rules.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/src/main/java/com/example/aitoui/data/Medication.kt Adds medication-name normalization logic and a Medication.cleaned() helper.
app/src/main/java/com/example/aitoui/data/MedicationDao.kt Adds DAO methods to fetch all rows and update medication name fields.
app/src/main/java/com/example/aitoui/data/MedicationRepository.kt Cleanses names on insert and adds legacy-row cleanup method.
app/src/main/java/com/example/aitoui/medication/MedicationViewModel.kt Applies name cleansing in Medication entry flow.
app/src/main/java/com/example/aitoui/script/AddScriptViewModel.kt Applies name cleansing in Script entry/resolution flow (including prefill).
app/src/main/java/com/example/aitoui/AitouiApp.kt Runs legacy medication-name cleanup on app startup.
app/src/test/java/com/example/aitoui/data/MedicationNameCleaningTest.kt Adds focused unit tests for the cleansing rules and Medication.cleaned().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 54 to +58
is MedicationAction.BrandNameChanged ->
_state.update { it.copy(brandName = action.value) }
_state.update { it.copy(brandName = action.value.cleanMedicationName()) }

is MedicationAction.ActiveIngredientChanged ->
_state.update { it.copy(activeIngredient = action.value) }
_state.update { it.copy(activeIngredient = action.value.cleanMedicationName()) }
Comment on lines +185 to +188
is AddScriptAction.BrandNameChanged ->
_state.update { it.copy(brandName = action.value.cleanMedicationName()) }
is AddScriptAction.ActiveIngredientChanged ->
_state.update { it.copy(activeIngredient = action.value.cleanMedicationName()) }
Comment on lines +90 to +92
applicationScope.launch {
medicationRepository.cleanseExistingMedicationNames()
}
@RodneyBaileyNCS
RodneyBaileyNCS deleted the feature/medication-title-case-cleansing branch July 31, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants