Skip to content

Rework form generation around incidents and templates instead of extractions #619

Description

@chetanr25

Rework form generation around incidents and templates instead of extractions

Background

Form generation still pointed at extract_id and a closed form_type enum, both left over from before templates were user-registered and before extraction fed into a stored incident. It also had two separate endpoints for generating one form versus all forms, which no longer makes sense once generation is just a lookup against the incident's contract document.

What needs to change

  • Merge generate/all and generate/{form_type} into one POST /forms/generate that takes an incident_id and a list of template_ids. Omitting template_ids generates everything the readiness matrix reports as ready.
  • Point generation at incident_id instead of extract_id, since the contract document now lives on the incident row, not the extraction.
  • Since generation is pure lookup and draw (schema fields read the contract path, static fields stamp saved text, manual and open fields read custom_fields), no LLM runs here at all, so a whole batch should complete in seconds even for many templates.
  • Templates that are not ready get skipped with a reason instead of failing the whole batch, unless force_partial is set.
  • Unify the response shapes so a single form and a batch form both return the same FormRecord, with template_id, form_type, and batch_id all present.
  • Add GET /forms/batch/{batch_id}/download so a batch of generated forms can be pulled as one archive instead of fetching each form's PDF individually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions