Cleanse medication names to title case and normalize legacy rows - #150
Merged
Merged
Conversation
There was a problem hiding this comment.
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()andMedication.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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
brandNameandactiveIngredientinto trimmed, single-spaced title case.Add MedicationAdd Script(including OCR-prefill and resolution path)MedicationRepository.add(...).cleanseExistingMedicationNames()on app startup.XR,SR,CR,MR,IR,ER,XL,LA,EC,DR,CD,OD,PRHCl,HBrmg,mcg,g,kg,ml,lI..XFiles touched
app/src/main/java/com/example/aitoui/data/Medication.ktapp/src/main/java/com/example/aitoui/data/MedicationDao.ktapp/src/main/java/com/example/aitoui/data/MedicationRepository.ktapp/src/main/java/com/example/aitoui/medication/MedicationViewModel.ktapp/src/main/java/com/example/aitoui/script/AddScriptViewModel.ktapp/src/main/java/com/example/aitoui/AitouiApp.ktapp/src/test/java/com/example/aitoui/data/MedicationNameCleaningTest.ktVerification
:app:testDebugUnitTest --tests "com.example.aitoui.data.MedicationNameCleaningTest"