-
Notifications
You must be signed in to change notification settings - Fork 3
Truncate drop_term #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -412,12 +412,19 @@ impl CodeList { | |
|
|
||
| // The term and comment that goes with it to make the | ||
| // entry depends on the term_management | ||
| let comment = match term_management { | ||
| TermManagement::First => Some(format!("{code} truncated to 3 digits")), | ||
| let (term, comment) = match term_management { | ||
| TermManagement::DropTerm => { | ||
| (None, Some("Truncated to 3 digits, term discarded".to_string())) | ||
| } | ||
|
|
||
| TermManagement::First => ( | ||
| term.clone(), | ||
| Some(format!("{code} truncated to 3 digits, term first encountered")), | ||
| ), | ||
| }; | ||
|
|
||
| // We'll add this one later | ||
| adds.push((truncated_code, term.clone(), comment)); | ||
| adds.push((truncated_code, term, comment)); | ||
| } | ||
|
|
||
| // Add the new three-digit codes | ||
|
|
@@ -479,6 +486,7 @@ impl CodeList { | |
|
|
||
| #[derive(Clone, Copy, PartialEq, Eq)] | ||
| pub enum TermManagement { | ||
| DropTerm, | ||
| First, | ||
| } | ||
|
|
||
|
|
@@ -488,6 +496,7 @@ impl FromStr for TermManagement { | |
| /// Map TermManagement from a string | ||
| fn from_str(s: &str) -> Result<Self, CodeListError> { | ||
| match s.to_lowercase().as_str() { | ||
| "drop_term" => Ok(TermManagement::DropTerm), | ||
| "first" => Ok(TermManagement::First), | ||
| _ => Err(CodeListError::TermManagementNotKnown { term_management: s.to_string() }), | ||
| } | ||
|
|
@@ -989,15 +998,76 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| fn test_truncate_to_3_digits_icd10_4_digits() -> Result<(), CodeListError> { | ||
| fn test_truncate_to_3_digits_icd10_4_digits_drop_term() -> Result<(), CodeListError> { | ||
| let metadata: Metadata = Default::default(); | ||
|
|
||
| let mut expected_codelist = | ||
| CodeList::new("test_codelist".to_string(), CodeListType::ICD10, metadata.clone(), None); | ||
| expected_codelist.add_entry( | ||
| "B01".to_string(), | ||
| None, | ||
| Some("Truncated to 3 digits, term discarded".to_string()), | ||
| )?; | ||
|
|
||
| let mut observed_codelist = | ||
| CodeList::new("test_codelist".to_string(), CodeListType::ICD10, metadata, None); | ||
|
|
||
| observed_codelist.add_entry( | ||
| "B012".to_string(), | ||
| Some("Varicella pneumonia".to_string()), | ||
| None, | ||
| )?; | ||
|
|
||
| observed_codelist.truncate_to_3_digits(TermManagement::DropTerm)?; | ||
|
|
||
| assert_eq!(observed_codelist, expected_codelist); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice clear tests, I like how you set it up as observed vs expected codelist, it's very easy to read |
||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_truncate_to_3_digits_3_and_4_digits_drop_term() -> Result<(), CodeListError> { | ||
| let metadata: Metadata = Default::default(); | ||
|
|
||
| let mut expected_codelist = | ||
| CodeList::new("test_codelist".to_string(), CodeListType::ICD10, metadata.clone(), None); | ||
| expected_codelist.add_entry( | ||
| "B01".to_string(), | ||
| Some("Varicella [chickenpox]".to_string()), | ||
| None, | ||
| )?; | ||
|
|
||
| let mut observed_codelist = | ||
| CodeList::new("test_codelist".to_string(), CodeListType::ICD10, metadata, None); | ||
|
|
||
| observed_codelist.add_entry( | ||
| "B01".to_string(), | ||
| Some("Varicella [chickenpox]".to_string()), | ||
| None, | ||
| )?; | ||
| observed_codelist.add_entry( | ||
| "B012".to_string(), | ||
| Some("Varicella pneumonia".to_string()), | ||
| None, | ||
| )?; | ||
|
|
||
| observed_codelist.truncate_to_3_digits(TermManagement::DropTerm)?; | ||
|
|
||
| assert_eq!(observed_codelist, expected_codelist); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_truncate_to_3_digits_icd10_4_digits_first() -> Result<(), CodeListError> { | ||
| let metadata: Metadata = Default::default(); | ||
|
|
||
| let mut expected_codelist = | ||
| CodeList::new("test_codelist".to_string(), CodeListType::ICD10, metadata.clone(), None); | ||
| expected_codelist.add_entry( | ||
| "B01".to_string(), | ||
| Some("Varicella pneumonia".to_string()), | ||
| Some("B012 truncated to 3 digits".to_string()), | ||
| Some("B012 truncated to 3 digits, term first encountered".to_string()), | ||
| )?; | ||
|
|
||
| let mut observed_codelist = | ||
|
|
@@ -1017,7 +1087,7 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| fn test_truncate_to_3_digits_3_and_4_digits() -> Result<(), CodeListError> { | ||
| fn test_truncate_to_3_digits_3_and_4_digits_first() -> Result<(), CodeListError> { | ||
| let metadata: Metadata = Default::default(); | ||
|
|
||
| let mut expected_codelist = | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with clear comments for each term management