Skip to content

Conversation

@em-baggie
Copy link
Collaborator

@em-baggie em-baggie commented Jun 14, 2025

closes #90

From what I could gather through a bit of research, the rules for CTV3 are:

  • 5 characters in length
  • Characters are A-Z (case insensitive) or 0-9, and dots are used to make the string up to 5 characters if needed

E.g. valid codes:
ABCDE
abCdE
A....
ab9..

E.g. invalid codes:
ABC
ABCDEF
..jk0
KL..0

Have also added validation rules to docs (for all but CTV3 I copied the rules stated in the tre-tools code)
Also added a missing test to ICD10 validator to check letters are uppercase

Copy link
Collaborator

@oylenshpeegul oylenshpeegul left a comment

Choose a reason for hiding this comment

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

This looks great! The new CTV3 stuff is very much parallel with the other codelist types. The new documentation is fantastic.

I only spotted one tiny change in a test.

assert!(matches!(CodeListType::from_str("ICD10"), Ok(CodeListType::ICD10)));
assert!(matches!(CodeListType::from_str("SNOMED"), Ok(CodeListType::SNOMED)));
assert!(matches!(CodeListType::from_str("OPCS"), Ok(CodeListType::OPCS)));
assert!(matches!(CodeListType::from_str("ctv3"), Ok(CodeListType::CTV3)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one was meant to be "CTV3" (upper case), right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes great spot! Will change this now.

@em-baggie em-baggie requested a review from oylenshpeegul June 15, 2025 21:27
Copy link
Collaborator

@CarolineMorton CarolineMorton left a comment

Choose a reason for hiding this comment

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

Looks good! Nice work on this.

Approving but added one small comment on the Metadata::default()

Comment on lines +1 to +6
//! CTV3 validator for validating CTV3 codes in a codelist
//!
//! Validation Rules
//! 1. The code must be exactly 5 characters in length.
//! 2. Only alphanumeric characters (a-z, A-Z, 0-9) and dots (.) are allowed.
//! 3. The code starts with 0-5 alphanumeric characters followed by dots to pad to 5 characters.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Excellent documentation. Thanks for the effort here. It is always nice to have this right off the bat.

Comment on lines 83 to 88
fn create_test_metadata() -> Metadata {
Metadata::new(
Provenance::new(Source::ManuallyCreated, None),
CategorisationAndUsage::new(None, None, None),
PurposeAndContext::new(None, None, None),
ValidationAndReview::new(None, None, None, None, None),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can simplify this with the changes from #68 that @oylenshpeegul added. We should be able to do

Metadata::default(),

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes will change this now, thanks!

Comment on lines +143 to +147
fn test_validate_invalid_code_dot_middle_character_between_letters() -> Result<(), CodeListError>
{
let codelist = create_test_codelist()?;
let validator = Ctv3Validator(&codelist);
let code = "10a.f";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great set of tests.

Comment on lines +1 to +7
//! OPCS validator for validating OPCS codes in a codelist
//!
//! Validation Rules
//! 1. The code must be 3-5 characters long.
//! 2. The first character must be a letter.
//! 3. The second and third characters must be numbers.
//! 4. If there is a fourth character and it is a dot, there must be a number after the dot.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really appreciate this.

@em-baggie em-baggie merged commit fe224dd into main Jun 16, 2025
7 checks passed
@em-baggie em-baggie deleted the add_ctv3 branch June 16, 2025 19:14
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.

Add CTV3 as a new CodelistType

4 participants