Add state normalization as part of PIIRecord construction#240
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #240 +/- ##
==========================================
+ Coverage 97.72% 97.75% +0.02%
==========================================
Files 32 32
Lines 1674 1689 +15
==========================================
+ Hits 1636 1651 +15
Misses 38 38 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ericbuckley
reviewed
Mar 7, 2025
ericbuckley
reviewed
Mar 7, 2025
ericbuckley
reviewed
Mar 7, 2025
ericbuckley
reviewed
Mar 8, 2025
ericbuckley
reviewed
Mar 8, 2025
ericbuckley
reviewed
Mar 10, 2025
ericbuckley
approved these changes
Mar 10, 2025
bamader
pushed a commit
that referenced
this pull request
Mar 19, 2025
## Description This PR adds a method on the `Address` class to normalize states in a `PIIRecord` to the 2-digit USPS code if the provided state is valid. in order for the normalization to apply when the PIIRecord is constructed or initialized via `schemas.PIIRecord(**val)` as it is in `fhir_record_to_pii_record`, I needed to add the method as a `field_validator` on the Address class. We may want to update the other normalization functions, e.g., `phone_number` and `email` to ensure that the same normalization occurs for those fields as well. While working on this PR, I realized that we may also want to update the `field_validators` that are part of `PIIRecord`. For example, `parse_birth_date` returns a datetime object when we run `.model_construct` (see tests in `TestPIIRecord`) but returns the date as a string when we `schemas.PIIRecord(**val)` (see tests in `test_fhir_record_to_pii_record`. I propose we ensure that the normalization and validation are consistent for handling a PIIRecord with incoming FHIR data. I also changed the way that we initialize the PIIRecord in `model_construct`. I'm not clear how the old approach worked since it seemed to be calling itself, but with the new approach we are now able to apply both field validators on the PIIRecord and within the fields, e.g., the new validator I added to Address. ## Related Issues Fixes #202 ## Additional Notes <--------------------- REMOVE THE LINES BELOW BEFORE MERGING ---------------------> ## Checklist Please review and complete the following checklist before submitting your pull request: - [ ] I have ensured that the pull request is of a manageable size, allowing it to be reviewed within a single session. - [ ] I have reviewed my changes to ensure they are clear, concise, and well-documented. - [ ] I have updated the documentation, if applicable. - [ ] I have added or updated test cases to cover my changes, if applicable. - [ ] I have minimized the number of reviewers to include only those essential for the review. ## Checklist for Reviewers Please review and complete the following checklist during the review process: - [ ] The code follows best practices and conventions. - [ ] The changes implement the desired functionality or fix the reported issue. - [ ] The tests cover the new changes and pass successfully. - [ ] Any potential edge cases or error scenarios have been considered.
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.
Description
This PR adds a method on the
Addressclass to normalize states in aPIIRecordto the 2-digit USPS code if the provided state is valid. We may want to update the other normalization functions, e.g.,phone_numberandemailto ensure that the same normalization occurs for those fields as well.Related Issues
Fixes #202
Additional Notes