Skip to content

[survey2ddi 1/6] xlsform2ddi CLI: emit the response-data CSV and a real caseQnty #10

Description

@jstet

Step 1 of 6 in this repo for the survey2ddi retirement. Plan: HANDOVER_SURVEY2DDI.md. No blockers — this is the smallest issue and it gates the deprecation notices in CorrelAid/survey2ddi.

Problem

buildDataCsv shipped in #8, but the CLI cannot reach it. cmdXlsform2ddi in src/cli.ts passes no submissions to buildDdiXml, so:

  • <caseQnty> is always 0
  • <fileDscr URI="data.csv"> names a file the CLI never writes
  • getting a data CSV requires writing TypeScript against the library

The Python kobo2ddi transform does both halves in one command. Until the CLI does too, nothing in survey2ddi can be deprecated.

What to add

formtransform xlsform2ddi form.xlsx -o codebook.xml --data responses.csv
# writes codebook.xml + data.csv (caseQnty = row count)
  • --data <path> — response records. Accept both shapes: a flat CSV (header row of question names) and Kobo's submissions JSON array (kobo2ddi pull writes submissions.json). Detect by extension, fall back to sniffing the first non-whitespace byte for [/{.
  • --data-out <path> — default: data.csv beside the XML output, matching the datasetFilename recorded in <fileDscr>. If --dataset-filename is also given, the default follows it, so the XML and the file on disk cannot disagree.
  • Wire the parsed records into buildDdiXml's submissions option so <caseQnty> is correct, and into buildDataCsv(extractVariables(...), submissions) for the CSV.
  • Writing to stdout: with --data and no -o, the XML goes to stdout and the CSV needs an explicit --data-out — erroring on that combination is fine, silently dropping the CSV is not.

Notes

  • select_multiple values are expected space-joined; that is what both Kobo exports produce and what buildDataCsv parses.
  • Submission keys may be bare question names or group/name paths — readCell in src/pipelines/xlsform2ddi/data.ts already accepts either.
  • lstsv2ddi needs the same flag, but its response keying is a separate port — see the LimeSurvey response-normalization issue.

Acceptance criteria

  • --data accepts a flat CSV and a Kobo submissions JSON array
  • <caseQnty> equals the record count
  • The written CSV's filename matches <fileDscr URI> / <fileName>
  • CSV header order equals <var name=""> order in the emitted XML (already guaranteed by buildDataCsv — assert it in a CLI-level test)
  • --help documents both new flags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions