Skip to content

feat: add issue category infrastructure for STIX and PHIX - #85

Open
TiaTuinstra wants to merge 3 commits into
mainfrom
feat/phix-issue-types
Open

TiaTuinstra wants to merge 3 commits into
mainfrom
feat/phix-issue-types

Conversation

@TiaTuinstra

Copy link
Copy Markdown
Contributor

Summary

Introduces a shared issue category layer in lib/issueCategories.ts that maps every validation rule ID to one of 14 workflow-agnostic categories. Wires categories into the STIX summarizeValidation output so each entry in the types array now carries a category field alongside its existing ruleId, field, and severity counts.

Motivation

The validators emit dozens of distinct rule IDs. Without grouping, the quality assessment page can only show per-rule-ID subtotals, which are noisy and hard to act on. Categories enable:

  • Subtotals by category on the quality assessment page ("14 address issues across 3 schools")
  • Browsing all issues of a type without needing to know specific rule IDs
  • A natural navigation hierarchy: severity → category → rule

Categories

Key Label Populated by Description
parse Parse & Structure PHIX only The file could not be read. Either the CSV structure is invalid, required column headers are absent, or the file contains no data rows. These errors block all further validation.
metadata File Metadata STIX only Problems with file- or submission-level fields that describe the upload itself rather than individual records — school number, board number, upload type, submission date, contact information.
required Required Fields Both A field that must contain a value is empty or absent.
dates Dates Both A date field is malformed, out of range, set in the future, or logically inconsistent with another date on the same record.
identity Identity & Duplicates Both Problems that relate to identifying a specific person — invalid or duplicate OEN, duplicate HCN, suspected duplicate students, or records that may represent the same individual across schools.
vaccine Vaccine / Immunizing Agent PHIX only Issues with the immunizing agent or trade name — invalid, unrecognized, conflicting, or missing when one or the other is required.
coded-values Coded Values Both A field that must contain a value from a defined list contains something unrecognized — province, gender, grade, language, country, relationship, route, site, reason, and similar administrative codes.
address Address Both Problems with the physical address — invalid street type or direction, a unit number in the wrong field, a delivery designation in a street field, a rural route format issue, or a city/province mismatch.
postal-code Postal Code Both The postal code is missing, invalid, or can be normalized to a canonical format.
contact Contact Both Problems with contact information — malformed or unrecognizable phone numbers, invalid phone type codes, and malformed email addresses.
field-length Field Length Both A value exceeds the maximum permitted character count for that field.
character-policy Character Policy STIX only A free-text field contains a character the receiving system does not accept — typically a curly apostrophe, quotation mark, accented letter, or other non-ASCII character. Many of these have suggested auto-fixes.
service-delivery Service Delivery PHIX only Issues with the public health unit organization or service delivery location associated with an immunization record.
other Other Fallback Rule ID not mapped to any of the above categories. Serves as a fallback and should not appear under normal circumstances.

Categories that are currently only populated by one workflow are defined in the shared type from day one so both workflows can grow into them without changing the infrastructure.

Design decisions

Single shared type, workflow-specific mapping. IssueCategory and CATEGORY_LABELS live in lib/ and are workflow-agnostic. The issueCategory(ruleId, workflow) function dispatches to a flat Record<string, IssueCategory> for each workflow. Both fall back to "other" for unmapped rule IDs.

One category per issue. Issues belong to exactly one category. Multi-tagging would make category subtotals unreliable — an issue tagged ["address", "coded-values"] would inflate both counts. This could be adjusted to allow multiple categories to be associated with each issue (i.e. coded-value and contact), depending on intended count handling.

Explicit flat Record's for both workflows. STIX generates allowed-value rule IDs dynamically at runtime as ${field.toUpperCase()}_ALLOWED_VALUE, but the set of source fields is a fixed list in validator.ts. Using a flat Record (the same approach as PHIX) keeps both lookups uniform and makes every mapping greppable.

Files changed

  • lib/issueCategories.ts — new; exports IssueCategory, CATEGORY_LABELS, and
    issueCategory(ruleId, workflow)
  • workflows/stix/validation/overview.ts — adds category field to each entry in the
    types array returned by summarizeValidation
  • tests/issueCategories.test.ts — new; covers STIX and PHIX mappings, fallback,
    cross-workflow isolation, and CATEGORY_LABELS exhaustiveness
  • tests/validationOverview.test.ts — adds integration assertions that summarizeValidation
    wires category correctly

@TiaTuinstra TiaTuinstra linked an issue Sep 25, 2026 that may be closed by this pull request
1 task done
@jangevaare

Copy link
Copy Markdown
Member

Sorry, I missed this @TiaTuinstra , but I can get behind something like this as our taxonomy!

Couple tweaks I'd suggest:

  • Stick to all as singular in names (e.g. date/dates)
  • Some category name variations to reduce ambiguity (but matter of opinion and we can debate)
  • Fold postal-code into address
  • combine field length and character policy into a text-constraints category (or another encompassing name)
  • consider service-delivery rules a subcategory of coded-values rules, maybe something like "selection" as an alternative category name
  • maybe file-structure instead of parse

But I think it's good and we can go ahead

…till goes to its own category when it has one
@TiaTuinstra
TiaTuinstra marked this pull request as ready for review October 16, 2026 20:25

@Lespernater Lespernater left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Besides some work once updating the base branch, only some smaller suggestions for testing/guards and a question about the intent from me. Well done!

Comment thread docs/validation-rules.md

---

## Issue Categories

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great taxonomy proposed here!

Comment thread lib/issueCategories.ts
OEN_FORMAT: "identity", OEN_DUPLICATE: "identity", OEN_DUAL_ENROLLMENT: "identity",
NAME_DOB_DUPLICATE: "identity", IDENTITY_REVIEW: "identity",
// contact — phone format rules and per-record phone-type allowed-value rules
// (PHONE_TYPE_ALLOWED_VALUE is the file-level contact phone on the submission header; that stays "metadata")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice catch on PHONE_TYPE_ALLOWED_VALUE vs PHONETYPE_ALLOWED_VALUE!

Comment thread lib/issueCategories.ts
};

export function issueCategory(ruleId: string, workflow: "stix" | "phix"): IssueCategory {
return (workflow === "stix" ? stixCategories : phixCategories)[ruleId] ?? "other";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-blocking issue:

New rule IDs will drop into other silently + this mapping isn't yet tied to what the validators emit.

  • main now contains POSTAL_CODE_US_ZIP and PO_BOX_NUMBER_FORMAT from work after this branched. They got labels in overview.ts but will land in other after a rebase instead of address.
  • XML_PARSE_OR_NAMESPACE - non parse-able STIX file - lands in other currently but PHIX parse failure lands in file-structure
  • PR description says no other under normal circumstances but no flag to highlight unmapped rules in CI or otherwise
  • Also on main - lib/issueDescription.ts rule-ID switch that gives each issue a description so with this PR, introducing new STIX rules need edits in 3 places - label record, description switch and category map -> drift/maintenance risk, maybe this can be consolidated

Suggestions:

  1. After main rebase/merge - map POSTAL_CODE_US_ZIP and PO_BOX_NUMBER_FORMAT to address.
  2. Map XML_PARSE_OR_NAMESPACE to file-structure and widen docs/validation-rules.md.
  3. Possibly add a test that every labelled rule ID has a category so new rules fail CI until it is mapped? This may make other redundant? Maybe just add a flag that an issue is unmapped? Would need labels map exported from overview.ts:
it("maps every labelled STIX rule ID", () => {
  for (const ruleId of Object.keys(ISSUE_TYPE_LABELS)) expect(issueCategory(ruleId, "stix")).not.toBe("other");
});
  1. Alternatively, move the category next to label in one record per rule ID to reduce hand-edit sync burden.

it("CATEGORY_LABELS has an entry for every IssueCategory", () => {
const categories: IssueCategory[] = [
"file-structure", "metadata", "required", "date", "identity", "vaccine",
"coded-value", "address", "contact", "text-constraint", "other",

@Lespernater Lespernater Nov 23, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit:

Avoid repeating union build here, consider looping over CATEGORY_LABELS because adding a new 12th category to issueCategory and CATEGORY_LABELS but not to this list means the test still passes. Plus, I think a missing label is already caught by npm run typecheck, because CATEGORY_LABELS is typed Record<IssueCategory, string>. Consider:

for (const [category, label] of Object.entries(CATEGORY_LABELS)) expect(label.trim(), category).not.toBe("");

Alternatively, export stixCategories and phixCategories to build a test here that also includes defined but unused categories and loop over categories instead of using CATEGORY_LABELS workaround.

const used = new Set([...Object.values(stixCategories), ...Object.values(phixCategories)]);
for (const category of Object.keys(CATEGORY_LABELS)) if (category !== "other") expect(used.has(category as IssueCategory), category).toBe(true);

...count(result.issues), students: records.size,
schools: [...schools.values()].map(({ issues, ...entry }) => ({ ...entry, ...count(issues) })).sort((a, b) => b.errors - a.errors || b.total - a.total || a.schoolNumber.localeCompare(b.schoolNumber)),
types: [...types.values()].map(({ issues, ...entry }) => ({ ...entry, ...count(issues) })).sort((a, b) => b.total - a.total || a.ruleId.localeCompare(b.ruleId)),
types: [...types.values()].map(({ issues, ...entry }) => ({ ...entry, category: issueCategory(entry.ruleId, "stix"), ...count(issues) })).sort((a, b) => b.total - a.total || a.ruleId.localeCompare(b.ruleId)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Question about intention:

types rows are keyed by rule ID and field but category only looks at rule ID. FIELD_LENGTH on StreetName, City or PostalCode counts as text-constraint, and a REQUIRED_FIELD on an address field from a custom ruleset counts as required. Versus on PHIX, PHIX_STREET_NAME_REQUIRED: "address".

In the case of a FIELD_LENGTH issue with an address field, is the planned "address issues" subtotal meant to leave those out, or should the field be able to steer the category for the generic rules like FIELD_LENGTH and REQUIRED_FIELD?

This matters more for downstream dashboard building of subtotals after these issue maps are merged because nothing reads category yet.

Considerations:

  1. Option: issueCategory(ruleId, workflow, field?) returns a field-based category for FIELD_LENGTH and REQUIRED_FIELD when the field belongs to a group.
  2. Another option: leave the rule as is and have the dashboard show text-constraint and required rows with their field.

This branch has not been deployed

No deployments
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.

[Feature]: Issue type taxonomy

3 participants