`-BundleToResources` silently loses resources (duplicate ids, id-less entries, unparseable bundles), then `-db=true` deletes the source

Open
#602 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend, tooling

Research direction

Start with tooling/src/main/java/org/opencds/cqf/tooling/operation/BundleToResources.java and trace bundle discovery, resource naming and writing, extraction counts, and the -db=true deletion path. Reproduce the reported cases with the sample command and inspect the output and exit status. Done means duplicate and id-less entries cannot be silently overwritten, parse failures are reported, counts reflect written and skipped resources, and source bundles are deleted only after successful extraction.

Written by the indexing model from the issue text.

Description

-BundleToResources (tooling/src/main/java/org/opencds/cqf/tooling/operation/BundleToResources.java, unchanged
on master e50dc913) can lose resources without any error, report a count that includes them, and then, with
-db=true, delete the only copy. The IG template's _extractBundleResources.sh runs it with -db=true, so this
affects the standard test-case workflow in content IGs.

Reproduced with tooling-cli-3.9.1.jar, the version the template scripts pin.

  1. Resources with the same resourceType/id overwrite each other. The output file name is
    <resourceType>-<idPart>.json, written with a plain FileOutputStream, so the last entry wins. The extraction
    count still counts every entry. A bundle with two Encounter/e1 entries reports "4 resources extracted" and
    writes 3 files; only the second Encounter survives. Output tasks run in parallel, so collisions across bundles
    in the same output folder are also last-writer-wins, in no defined order.
  2. Entries without an id are named from the entry and overwrite each other. An entry with a urn:uuid
    fullUrl and no id is written as null-urn:uuid:<uuid>.json. That's not a valid file name on Windows. With no
    fullUrl, every id-less entry is written to null-null.json. In a bundle with an id-less Observation and an
    id-less Condition, only the Condition survives.
  3. Files that fail to parse are skipped silently. discoverBundlesRecursively catches every exception and
    returns null. A bundle with an invalid value (for example "birthDate": "not-a-date") is never counted or
    reported. The run ends "Process complete." with no mention of it.
  4. -db=true deletes the source bundle regardless of 1–3. After a lossy extraction, the bundle, which is the
    only copy of the lost resources, is deleted.

Steps to reproduce:

mkdir -p t/c
echo '{"resourceType":"Bundle","type":"collection","entry":[
 {"fullUrl":"urn:uuid:a","resource":{"resourceType":"Patient","id":"p1"}},
 {"fullUrl":"urn:uuid:b","resource":{"resourceType":"Encounter","id":"e1","status":"finished","class":{"code":"AMB"}}},
 {"fullUrl":"urn:uuid:c","resource":{"resourceType":"Encounter","id":"e1","status":"finished","class":{"code":"IMP"}}},
 {"fullUrl":"urn:uuid:d","resource":{"resourceType":"Observation","status":"final","code":{"text":"x"}}}]}' > t/c/bundle.json
java -jar tooling-cli-3.9.1.jar -BundleToResources -p=t -v=r4 -op=t -db=true
# "4 resources extracted"; files: Encounter-e1.json (IMP only), Patient-p1.json, null-urn:uuid:d.json; bundle.json deleted

Expected behaviour:

  • Fail the bundle, with a clear message, when two entries share a resourceType/id. Name the bundle and the id.
    Never overwrite silently.
  • Fail an entry with no id, or offer an explicit option to assign one. Never write null-* files.
  • Report every file that couldn't be parsed, with the parser's message, and end with a non-zero exit code.
  • Make the count report what was written and what was skipped.
  • With -db=true, delete a bundle only when all of its entries were written.

🤖 Generated with Claude Code

Dominant language
Java
Stars
22
Forks
26
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/cqf-tooling

All issues in cqframework/cqf-tooling

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.