Skip to content

x12sdk 1.2.0

Choose a tag to compare

@owgreen-dev owgreen-dev released this 24 Oct 10:56
· 61 commits to main since this release
7cc34d6

pip install x12sdk==1.2.0

Correction, added after publishing: the line below originally read "every supported transaction set". That was wrong — seven of the eight generate. The institutional claim, 837I, is parsed and has accessors but has no generator yet. The PyPI description for 1.2.0 cannot be edited after upload, so it still carries the original wording.

Seven of the eight supported transaction sets can now be generated, and every set that branches on subscriber versus dependent has an accessor that hides it.

set generator accessor
835 generate_835 claims()
837P generate_837p claims(), subscribers()
837I none yet claims(), subscribers()
270 / 271 generate_270 / generate_271 members()
276 / 277 generate_276 / generate_277 claims()
834 generate_834 no hierarchy to hide

Why this matters

Real claims, remittances and eligibility files contain PHI, and there is no public X12 corpus. Anyone testing an X12 pipeline has nowhere to get files. Now:

from x12sdk.generate import generate_271, generate_276

response = generate_271(seed=7, members=25)
inquiry = generate_276(seed=7, patients=25)

The same seed reproduces the same bytes, and generation never touches the global random state, so it is safe inside someone else's test suite.

The branch that loses data

In an 837, a 270, a 271, a 276 and a 277, a patient sits at one of two depths: under the subscriber when the patient is the subscriber, and under a dependent when they are not. Code written against one path runs without error on a file that uses the other and reports nothing. Nothing raises; the count is just wrong.

Generated files contain both branches by default, so the trap is testable. The accessors walk both, so it stops being a trap:

for member in eligibility.members():
    print(member.name, member.is_dependent, member.service_type_codes)

Inquiry and response pairs are generated from one specification and stay in step on a seed, so a 270 and the 271 answering it describe the same people.

Three defects fixed

None is reachable by parsing, which is why the inherited corpus never caught any of them.

  • validate_hierarchy_ids made a second subscriber impossible on a 270 or 271. It required every HL segment to be parented by the previous HL in the file, which is not an X12 rule and contradicts the check beside it. A provider checking eligibility for a list of patients is the ordinary use of a 270.
  • _validate_duplicate_codes crashed on any constructed loop without REF. It read a key that is always present and set to None using a get() default. This is shared code, so it affected every transaction set using the duplicate-REF or duplicate-AMT checks.
  • The 834 alone had its segment-count check commented out, so it was the one transaction set that accepted a wrong SE01 in silence.

Behaviour change

The 834 now validates SE01, like the other seven sets always have. All ten inherited samples were verified correct before enabling it, so nothing in the corpus changes. If you parse 834 files from a partner who miscounts SE01, they will now be rejected rather than parsed.

Full detail in CHANGELOG.md.

750 tests on Python 3.10 through 3.13, 96% coverage. Sample corpus 72 files to 87, every one round-tripped byte for byte.