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

Add support for array input for all constraints in HangingProtocolService validator #3322

Merged
merged 9 commits into from Jun 29, 2023

Conversation

Sofien-Sellami
Copy link
Contributor

@Sofien-Sellami Sofien-Sellami commented Apr 12, 2023

Context

This PR updates the validator.js file in the Hanging Protocol Service library to allow constraints to accept an array of values. Previously, only the contains constraint could accept an array.

Changes & Results

-Updated functions to accept an array of values.
-Made changes to ensure all constraints accept an array of values for consistency.

Constraint Rules

Rule Single Value Array Value Example
equals === All members are === in same order value = ['abc', 'def', 'GHI']
testValue = 'abc' (Fail)
= ['abc'] (Fail)
= ['abc', 'def', 'GHI'] (Valid)
= ['abc', 'GHI', 'def'] (Fail)
= ['abc', 'def'] (Fail)
value = 'Attenuation Corrected'
testValue = 'Attenuation Corrected' (Valid)
= 'Attenuation' (Fail)
value = ['Attenuation Corrected']
testValue = ['Attenuation Corrected'] (Valid)
= 'Attenuation Corrected' (Valid)
= 'Attenuation' (Fail)
doesNotEqual !== Any member is !== for the array, either in value, order, or length value = ['abc', 'def', 'GHI']
testValue = 'abc' (Valid)
= ['abc'] (Valid)
= ['abc', 'def', 'GHI'] (Fail)
= ['abc', 'GHI', 'def'] (Valid)
= ['abc', 'def'] (Valid)
value = 'Attenuation Corrected'
testValue = 'Attenuation Corrected' (Fail)
Valid
= 'Attenuation' (Valid)
value = ['Attenuation Corrected']
testValue = ['Attenuation Corrected'] (Fail)
= 'Attenuation Corrected' (Fail)
= 'Attenuation' (Fail)
includes Not allowed Value is equal to one of the values of the array value = ['abc', 'def', 'GHI']
testValue = ['abc'] (Valid)
= ‘abc’ (Fail)
= [‘abc’] (Fail)
= ‘dog’ (Fail)
= = [‘att’, ‘abc’] (Valid)
= ['abc', 'def', 'dog'] (Valid)
= ['cat', 'dog'] (Fail)
value = 'Attenuation Corrected'
testValue = ['Attenuation Corrected', 'Corrected'] (Valid)
= ['Attenuation', 'Corrected'] (Fail)
value = ['Attenuation Corrected']
testValue = 'Attenuation Corrected' (Fail)
= ['Attenuation Corrected', 'Corrected'] (Valid)
= ['Attenuation', 'Corrected'] (Fail)
doesNotInclude Not allowed Value is not in one of the values of the array value = ['abc', 'def', 'GHI']
testValue = ‘Corr’ (Valid)
= ‘abc’ (Fail)
= [‘att’, ‘cor’] (Valid)
= ['abc', 'def', 'dog'] (Fail)
value = 'Attenuation Corrected'
testValue = ['Attenuation Corrected', 'Corrected'] (Fail)
= ['Attenuation', 'Corrected'] (Valid)
value = ['Attenuation Corrected']
testValue = 'Attenuation' (Fail)
= ['Attenuation Corrected', 'Corrected'] (Fail)
= ['Attenuation', 'Corrected'] (Valid)
containsI String containment (case insensitive) String containment (case insensitive) is OK for one of the rule values value = 'Attenuation Corrected'
testValue = ‘Corr’ (Valid)
= ‘corr’ (Valid)
= [‘att’, ‘cor’] (Valid)
= [‘Att’, ‘Wall’] (Valid)
= [‘cat’, ‘dog’] (Fail)
value = ['abc', 'def', 'GHI']
testValue = 'def' (Valid)
= 'dog' (Fail)
= ['gh', 'de'] (Valid)
= ['cat', 'dog'] (Fail)
contains String containment (case sensitive) String containment (case sensitive) is OK for one of the rule values value = 'Attenuation Corrected'
testValue = ‘Corr’ (Valid)
= ‘corr’ (Fail)
= [‘att’, ‘cor’] (Fail)
= [‘Att’, ‘Wall’] (Valid)
= [‘cat’, ‘dog’] (Fail)
value = ['abc', 'def', 'GHI']
testValue = 'def' (Valid)
= 'dog' (Fail)
= ['cat', 'de'] (Valid)
= ['cat', 'dog'] (Fail)
doesNotContain String containment is false String containment is false for all values of the array value = 'Attenuation Corrected'
testValue = ‘Corr’ (Fail)
= ‘corr’ (Valid)
= [‘att’, ‘cor’] (Valid)
= [‘Att’, ‘Wall’] (Fail)
= [‘cat’, ‘dog’] (Valid)
value = ['abc', 'def', 'GHI']
testValue = 'def' (Fail)
= 'dog' (Valid)
= ['cat', 'de'] (Fail)
= ['cat', 'dog'] (Valid)
doesNotContainI String containment is false (case insensitive) String containment (case insensitive) is false for all values of the array value = 'Attenuation Corrected'
testValue = ‘Corr’ (Fail)
= ‘corr’ (Fail)
= [‘att’, ‘cor’] (Fail)
= [‘Att’, ‘Wall’] (Fail)
= [‘cat’, ‘dog’] (Valid)
value = ['abc', 'def', 'GHI']
testValue = 'DEF' (Fail)
= 'dog' (Valid)
= ['cat', 'gh'] (Fail)
= ['cat', 'dog'] (Valid)
startsWith Value begins with characters Starts with one of the values of the array value = 'Attenuation Corrected'
testValue = ‘Corr’ (Fail)
= ‘Att’ (Fail)
= ['cat', 'dog', 'Att'] (Valid)
= [‘cat’, ‘dog’] (Fail)
endsWith Value ends with characters ends with one of the value of the array value = 'Attenuation Corrected'
testValue = ‘TED’ (Fail)
= ‘ted’ (Valid)
= ['cat', 'dog', 'ted'] (Valid)
= [‘cat’, ‘dog’] (Fail)
greaterThan value is => to rule Not applicable value = 30
testValue = 20 (Valid)
= 40 (Fail)
lessThan value is <= to rule Not applicable value = 30
testValue = 40 (Valid)
= 20 (Fail)
range Not applicable 2 value requested (min and max) value = 50
testValue = [10,60] (Valid)
= [60, 10] (Valid)
= [0, 10] (Fail)
= [70, 80] (Fail)
= 45 (Fail)
= [45] (Fail)
notNull Not Applicable Not Applicable No value

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS:
  • "Node version:
  • "Browser:

@netlify
Copy link

netlify bot commented Apr 12, 2023

Deploy Preview for ohif-platform-viewer canceled.

Name Link
🔨 Latest commit 6b0e4dc
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-viewer/deploys/6478a78e28280800071f9d03

@netlify
Copy link

netlify bot commented Apr 12, 2023

Deploy Preview for ohif-platform-docs ready!

Name Link
🔨 Latest commit 81d788d
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/649d97935342fb00081d0f5e
😎 Deploy Preview https://deploy-preview-3322--ohif-platform-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

}
// We need to compare each element in the array
else {
if (JSON.stringify(testValue) !== JSON.stringify(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please iterate over each item and return the information about which element is different. Also, stringify is slow and this can be called many times in order to determine which stage and which hanging display set to apply.

if (testValue[0] === value) {
return `${key} must not be ${testValue}`;
}
} else if (JSON.stringify(testValue) === JSON.stringify(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto about stringify.

@codecov
Copy link

codecov bot commented Jun 1, 2023

Codecov Report

Merging #3322 (81d788d) into master (b5b7d32) will increase coverage by 4.53%.
The diff coverage is 92.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3322      +/-   ##
==========================================
+ Coverage   38.27%   42.81%   +4.53%     
==========================================
  Files          82       82              
  Lines        1348     1448     +100     
  Branches      303      337      +34     
==========================================
+ Hits          516      620     +104     
  Misses        666      666              
+ Partials      166      162       -4     
Impacted Files Coverage Δ
...c/services/HangingProtocolService/lib/validator.js 93.54% <92.00%> (+19.00%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa37593...81d788d. Read the comment docs.

@Sofien-Sellami Sofien-Sellami changed the base branch from v3-stable to master June 1, 2023 14:35
@sedghi sedghi requested a review from wayfarer3130 June 1, 2023 14:49
* = ['abc', 'def', 'dog'] (Valid)
* = ['cat', 'dog'] (Fail)
*
* value = 'Attenuation Corrected' (Fail)
Copy link
Contributor

Choose a reason for hiding this comment

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

This case should be equivalent to ['Attenuation Corrected'], which should pass if the testValue contains the same identical string.

Copy link
Contributor

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

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

Could you add the two edge cases I described - the issue is that for the DICOM library we are using, it converts to/from single item arrays, so on the equals and the other one I commented on,
['abc'] and 'abc'
should be treated equivalently, both for the test value and the original value.

…COM is always an array and fix includes and doesNotIncludes validators
…lidator

# Conflicts:
#	platform/core/src/services/HangingProtocolService/lib/validator.js
#	platform/core/src/services/HangingProtocolService/lib/validator.test.js
@netlify
Copy link

netlify bot commented Jun 5, 2023

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 81d788d
🔍 Latest deploy log https://app.netlify.com/sites/ohif-dev/deploys/649d9793a0517d00095b151d
😎 Deploy Preview https://deploy-preview-3322--ohif-dev.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


- | Rule | Single Value | Array Value | Example |
|--- |--- |--- |--- |
| equals | === | All members are === in same order | value = ['abc', 'def', 'GHI']<br>testValue = 'abc' (Fail)<br><br> = ['abc'] (Fail)<br><br> = ['abc', 'def', 'GHI'] (Valid)<br><br> = ['abc', 'GHI', 'def'] (Fail)<br><br> = ['abc', 'def'] (Fail)<br><br>value = 'Attenuation Corrected'<br>testValue = 'Attenuation Corrected' (Valid)<br> = 'Attenuation' (Fail)<br> |
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the tests are failing on how the <br> tag is used - I suspect you need to use
as a closed tag value (XHTML syntax). Try building hte docs locally to test.

Copy link
Contributor

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

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

Will approve as soon as hte build is fixed.

@salimkanoun
Copy link
Contributor

Dear @wayfarer3130 should be good ?

Copy link
Contributor

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

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

Now passing the tests so good to go.

@wayfarer3130 wayfarer3130 merged commit e653961 into OHIF:master Jun 29, 2023
9 of 10 checks passed
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.

None yet

3 participants