Repository navigation
feat(sources): format fhir reads each FHIR file by its extension - #44
Open
Gordex2014 wants to merge 4 commits into
Open
Gordex2014 wants to merge 4 commits into
Gordex2014 wants to merge 4 commits into
Conversation
A file source with format: fhir reads each loose file and zip entry by its extension: .ndjson and .jsonl as NDJSON, .json as a Bundle or a single resource. A bulk export manifest is skipped in a zip and is an empty load as a loose file; a loose file with another extension is unreadable, alerted and archived. The definition needs the passthrough transform and refuses bulk_from: source_objects; auto resolves to transformed. Content dedup counts an earlier file only when both names are read the same way, so a file renamed to an extension that reads it is taken again.
Sources, delivery, transforms and development docs, a decision entry, the roadmap line and an example source for a zipped FHIR export.
…-ups A fhir zip keeps only the entries a reader takes, so one named just ndjson or json is skipped rather than read and refused. Tests for zip-entry dedup by reader, for admit_file with a name predicate, and for Format::as_str against its serde name. Docs: when NDJSON saved as .json fails, the manifest shape, the default pattern, the example link and the fhir exception to content dedup in the API docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A FHIR bulk export can arrive as a zip, or as loose files, that mixes NDJSON files (one per resource type) with Bundle files. A file source has one
format, and a zip loads only the entries that fit it, so no single source could take the whole drop. This PR addsformat: fhirfor folder and S3 sources: each file is read by its extension.What changes
A new format value,
fhir.format: fhirand returned by the API as"format": "fhir"..ndjsonand.jsonlare read as NDJSON,.jsonas a Bundle (or a single resource, asfhir_bundlealready allows).ndjson, say) is skipped too.A bulk export manifest is recognised.
.jsonobject with no stringresourceType, a stringtransactionTimeand an arrayoutput: the FHIR Bulk Data manifest shape..jsonwithoutresourceType(a Bundle that lost it, for one) is still unreadable and alerted.A loose file with another extension is unreadable.
patternbut has no reader, like any file today that cannot be read.unreadablewith the reasonnot an NDJSON (.ndjson, .jsonl) or JSON (.json) file, raisesunreadable_file, and is archived.processed/. A read-only bucket leaves it in place.The definition is checked.
format: fhirneeds the passthrough transform (fhir_passthrough.py, the file name the engine already uses for bulkauto). Any other transform is refused.bulk_from: source_objectsis refused: HFS would get the Bundle bytes in an NDJSON manifest, without the rewritten references.400 invalid_definition).fhir_server,databaseandmllpsources the format is forced, as it already is for any declared value.Bulk delivery.
autoresolves totransformedforfhir. The passthrough runs, and the resources go out as NDJSON per type with their ids and rewritten references.delivery.stamp_sourceis on.autowas alreadytransformedoutsidendjson/fhir_bundle. A test pins it.Dedup takes the reader into account, in
fhirsources only..ndjsonand.jsonltogether), Bundle (.json) or other.sha256keeps its meaning. Other formats run the same query as before.Smaller changes.
Docs.
docs/sources.md:hl7v2;.txtfor HL7 and is reworded so it claims the manifest skip only where it is true;autobullet.docs/running.md,docs/transforms.md,docs/development.mdanddocs/api.md(the dedup exception).ROADMAP.md.sources/fhir-export.yaml.example.In plain words
Drop a FHIR export zip in one folder and it all goes in. The NDJSON files are read as NDJSON and the Bundles as Bundles, and anything that is not FHIR JSON is skipped or reported.
Side effects checked
csv,ndjson,fhir_bundleandhl7v2sources are unchanged. They keep the same reader, zip filter and dedup query.fhir_bundlewithautostill takessource_objects.format: fhir, so that file has to be changed or removed first. This is recorded in decision 48.fhir_bundle:idstaysurn:uuid:….fhir_bundlewithsource_objectshands HFS the Bundle bytes in an NDJSON manifest, as it does today. This PR leaves that alone.How to verify
src/config.rs):source_objectsrefused;databasesource givenformat: fhiris accepted asndjson;auto→transformed;tests/zip_drop.rs), holding NDJSON, JSONL, a Bundle with aurn:uuidreference, a manifest, a README and an entry with no extension:Patient/p3;.jsonentry that is not a manifest and has noresourceTypeis unreadable, with one alert.tests/zip_drop.rs):.ndjsonand.jsonare sent;manifest.jsonis an empty load with no alert;notes.txtis unreadable, with the reason and one alert, and moved toprocessed/.tests/zip_drop.rs, loose and in a zip):x.txtis unreadable;x.ndjsonare read and sent;y.jsonlthey are a duplicate.tests/events.rs):Db::admit_filewith the name predicate returns the later file of the same reader group, not the earlier one of another group. It runs on both stores.tests/api.rs):400 invalid_definitionnaming the passthrough, then201with"format": "fhir".af87306: the whole CI test job passed. That was fmt, both clippy runs, the Python tests,cargo testand the--no-default-featurestests.tests/worker.rscases that fail on macOS also fail onmain(the/privatepath prefix and__CF_USER_TEXT_ENCODING), and they pass on Linux.tests/events.rs,tests/zip_drop.rsandtests/loads.rsalso passed against PostgreSQL 17, usingHIE_TEST_DATABASE_URL.af87306changes two lines of docs only.docker buildanddocker run --rm <image> check, as in the image job, which does not run for a pull request from a fork.Review notes
The plan had two rounds of review, and so did the code.
The plan's last corrections came after its second review round:
The code review then covered all three.
Considered and not taken:
fhirto a built-in copy of the passthrough instead of checking its file name. The file name is how the engine already identifies the passthrough. The check is meant to catch a configuration mistake; it is not a security boundary.$bulk-submittest for a mixed zip. Thetransformedpath is already tested, and the config test pinsfhirto it.