Skip to content

Add state normalization as part of PIIRecord construction#240

Merged
m-goggins merged 17 commits into
mainfrom
feature/202-parse-state-values
Mar 10, 2025
Merged

Add state normalization as part of PIIRecord construction#240
m-goggins merged 17 commits into
mainfrom
feature/202-parse-state-values

Conversation

@m-goggins

@m-goggins m-goggins commented Mar 6, 2025

Copy link
Copy Markdown
Collaborator

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. 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.

Related Issues

Fixes #202

Additional Notes

@codecov

codecov Bot commented Mar 6, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.75%. Comparing base (a2798c1) to head (e3b0240).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@m-goggins m-goggins marked this pull request as ready for review March 7, 2025 17:55
Comment thread src/recordlinker/schemas/pii.py Outdated
Comment thread src/recordlinker/schemas/pii.py Outdated
Comment thread src/recordlinker/schemas/pii.py Outdated
@m-goggins m-goggins requested a review from ericbuckley March 7, 2025 23:41
Comment thread src/recordlinker/schemas/pii.py Outdated
Comment thread tests/unit/schemas/test_pii.py
@m-goggins m-goggins requested a review from ericbuckley March 10, 2025 15:28
Comment thread src/recordlinker/schemas/pii.py Outdated
@m-goggins m-goggins requested a review from ericbuckley March 10, 2025 16:32
@m-goggins m-goggins merged commit f41e4af into main Mar 10, 2025
@m-goggins m-goggins deleted the feature/202-parse-state-values branch March 10, 2025 16:56
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.
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.

parse state values

2 participants