Skip to content
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

Allow users to specify Content Label and ensure the value is formatted correctly #130

Merged
merged 7 commits into from
Nov 5, 2021

Conversation

hackermd
Copy link
Collaborator

This PR adds a content_label attribute to the Segmentation, ParametricMap and MicroscopyBulkSimplyAnnotation SOP classes to allow users to set the value of the Content Label attribute.

Since the meaning of that attribute is not immediately obvious (thanks @dclunie for clarification), this PR further adds enumerated values for specific SOP classes. However, users do not have to choose a value from the enum, but can also supply custom values. To ensure the values are formatted correctly, a check_code_string() function is added that asserts values are formatted according to the constraints of the CS VR.

Also ensure the value is formatted according to VR CS
@hackermd hackermd added bug Something isn't working enhancement New feature or request labels Oct 25, 2021
@hackermd hackermd self-assigned this Oct 25, 2021
@hackermd hackermd linked an issue Oct 25, 2021 that may be closed by this pull request
@CPBridge
Copy link
Collaborator

@hackermd could you please clarify where the set of values you are using comes from? Is it from the standard or is it something you are proposing?

@hackermd
Copy link
Collaborator Author

@hackermd could you please clarify where the set of values you are using comes from? Is it from the standard or is it something you are proposing?

There are no enumerated values defined in the standard for this attribute. This is something I am proposing after a conversation with @dclunie. I hope that these enumerated values give users some idea of what values could be used (note that users can specify their own custom values).

@dclunie
Copy link

dclunie commented Oct 26, 2021

I might avoid using the term "Enumerated Values" to describe these, since that implies that it does come from the standard and further that it is a required and fixed set of values, as opposed to being a set that is specific to this implementation, and only a suggestion.


class ContentLabelValues(Enum):

"""Enumerated values for attribute Content Label."""
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 it would be a good idea to make it clear in the documentation that these are suggested values and not part of the standard

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed enumerations via fa56561

src/highdicom/ann/enum.py Outdated Show resolved Hide resolved
src/highdicom/pm/enum.py Outdated Show resolved Hide resolved

class ContentLabelValues(Enum):

"""Enumerated values for attribute Content Label."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, I think it would be a good idea to make it clear in the documentation that these are suggested values and not part of the standard

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed enumerations via fa56561

src/highdicom/seg/enum.py Outdated Show resolved Hide resolved
src/highdicom/seg/enum.py Outdated Show resolved Hide resolved
src/highdicom/valuerep.py Outdated Show resolved Hide resolved
src/highdicom/valuerep.py Outdated Show resolved Hide resolved
'Code string must not start with a number of an underscore.'
)

if re.match(r'[A-Z0-9_]+[^-]$', value) is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

From my reading of the standard, whitespace is allowed too:

Uppercase characters, "0"-"9", the SPACE character, and underscore "_", of the Default Character Repertoire

Also, I don't understand the need for the [^-], this will allow any non-hyphen character at the end, for example !, @, %, etc, which is not correct. I.e. INSTANCE_SEG!, INSTANCE_SEG?, INSTANCE_SEGs would match this currently...

Therefore I think it's something like

Suggested change
if re.match(r'[A-Z0-9_]+[^-]$', value) is None:
if re.match(r'[A-Z0-9_\s]+$', value) is None:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Further question: where is the requirement "Code string must not start with a number or an underscore" specified? It seems sensible, it's just not in Table 6.2-1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a note to the function in c39000d.

I think we should encode those values such that they could be used as fields of an enumeration (in C or syntactically similar languages).

src/highdicom/valuerep.py Outdated Show resolved Hide resolved
@hackermd
Copy link
Collaborator Author

@CPBridge after further considerations, I removed the enumerations for the Content Label attribute, since these opinionated options may be more misleading than helpful.

Copy link
Collaborator

@CPBridge CPBridge 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

@hackermd hackermd merged commit 682f2f0 into master Nov 5, 2021
@hackermd hackermd deleted the bugfix/content-label branch November 5, 2021 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Malformed values of Content Label attribute
3 participants