Add an export command for writing FHIR resources back out to NDJSON
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
The CLI can load NDJSON into SQL Server, but there is no way to get the data back out. Add an export command that is the inverse of load: read rows from the resource table and write them to {ResourceType}.ndjson files, so that an exported directory can be fed straight back into sof-mssql load.
Proposed usage:
npx sof-mssql export ./out --host localhost --user sa --password pass --database fhir
npx sof-mssql export ./out --resource-type Patient
npx sof-mssql export ./out --dry-run
Behaviour:
- One file per distinct
resource_typevalue in[schema].[table], named{ResourceType}.ndjsonto match the naming conventionloadexpects. - Write the
jsoncolumn verbatim, one resource per line, so a load/export round trip is lossless. - Stream rows and append incrementally rather than buffering a resource type in memory; the table can be much larger than available RAM.
- Reuse the existing connection handling, environment configuration and progress reporting in
src/loader/rather than duplicating them. - Work with both
NVARCHAR(MAX)and the SQL Server 2025 nativeJSONcolumn type.
Options should mirror load where they make sense: the database options (--host, --port, --user, --password, --database, --trust-server-certificate), --table-name, --schema-name, --resource-type to export a single type, and the output options --dry-run, --verbose, --progress, --quiet. Existing output files should cause a failure unless --overwrite is passed.
Tests come first: unit tests covering option building and file naming, plus one integration test that loads a fixture directory, exports it, and asserts the round trip preserves every resource. README.md and CONTRIBUTING.md need updating to document the command.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing load implementation and shared connection, environment, and progress handling under src/loader/. Review the proposed CLI options and add unit tests for option building and file naming, then add an integration test covering load/export round-trip preservation. Done means the export command streams each resource type to the expected NDJSON files, respects overwrite and selection options, and the README.md and CONTRIBUTING.md document it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- cli, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100