aaronhuggins / node-x12

ASC X12 parser, generator, query engine, and mapper; now with support for streams.
https://aaronhuggins.github.io/node-x12/
MIT License
49 stars 14 forks source link

Update ST header layout #21

Closed boxfoot closed 3 years ago

boxfoot commented 3 years ago

Add support for ST03 element (Implementation Convention Reference)

I'm working with a TP who requires the ST03 element for validation, but adding that element causes a validation error because it's not in the layout. I've added it manually in my own project but thought it could be helpful to submit here, too.

sonarcloud[bot] commented 3 years ago

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

ahuggins-nhs commented 3 years ago

@boxfoot Not all industries support ST03 in their EDI exchanges, nor is ST03 consistently a minimum 35 chars in length. I think it might maybe always match the GS08 when present?

For example, two different implementation docs which have differing min/max: https://tuftshealthplan.com/documents/employers/guides/834-999-companion-guide-version-5010 https://files.nc.gov/ncdor/documents/files/motorfuels_edi_guide.pdf?qn9wmFdW8vQFYYmTIvwx9UUv4tZksA4E

Regardless, another user had a similar case and graciously provided options to provide custom segment headers. https://github.com/ahuggins-nhs/node-x12/pull/13

My recommendation would be to use the custom segment header functionality. If that's not sufficient, do you have a recommendation on how to improve the validation, or code changes to the ST segment validation logic?

boxfoot commented 3 years ago

@ahuggins-nhs thanks for the quick reply. Looks like I swapped MIN and MAX.

I've been using the custom segment header functionality already and can continue doing that -- especially since this change isn't universally relevant.

Re: validation, I think it might make sense to eventually have a validation system that tracks more information about each element, including min, max, required, format etc -- I've built out something similar for my own project for all of the industry-specific segments. While we can't for license reasons include a spec like that in the node-x12 library, there could be script which generates that information from the XSD schema -- in fact, it looks from other issues like some folks are already doing something like that.

For my limited purposes, the main problem was really the COUNT attribute, because it requires a specific value. So a more limited approach for just ST and just here could be to replace COUNT with COUNT_MIN (===2) and COUNT_MAX (===3).

ahuggins-nhs commented 3 years ago

@boxfoot I decided to get this in while I'm fixing a different issue. Branch is https://github.com/ahuggins-nhs/node-x12/tree/patch-1

PR is https://github.com/ahuggins-nhs/node-x12/pull/27