Skip to content

Commit

Permalink
Merge pull request #10 from smart-on-fhir/mikix/sorted
Browse files Browse the repository at this point in the history
docs: clarify that sort order is guaranteed
  • Loading branch information
mikix authored Jan 6, 2025
2 parents 76bfc63 + db04f0f commit c58fd6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import cumulus_fhir_support

cumulus_fhir_support.list_multiline_json_in_dir("/")
# {
# "/random.jsonl": None,
# "/con1.ndjson": "Condition",
# "/pat1.jsonl": "Patient",
# "/random.jsonl": None,
# }

cumulus_fhir_support.list_multiline_json_in_dir("/", "Patient")
Expand Down Expand Up @@ -77,10 +77,10 @@ import cumulus_fhir_support

list(cumulus_fhir_support.read_multiline_json_from_dir("/"))
# [
# {"description": "not a fhir object"},
# {"resourceType": "Condition", "id": "con1", "onsetDateTime": "2011-11-24"},
# {"resourceType": "Patient", "id": "pat1", "birthDate": "2020-10-16"},
# {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# {"description": "not a fhir object"},
# ]

list(cumulus_fhir_support.read_multiline_json_from_dir("/", "Condition"))
Expand Down
7 changes: 4 additions & 3 deletions cumulus_fhir_support/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def list_multiline_json_in_dir(
- Will return an empty dict if the path does not exist.
- Passing None as the resource filter (the default) will return all multi-line JSON found.
- Returned filenames will be full paths.
- The order of filenames will be consistent across calls.
- The order of returned filenames will be consistent across calls (Python sort order).
- This function will notice both JSON Lines (.jsonl) and NDJSON (.ndjson) files.
Examples:
Expand Down Expand Up @@ -105,7 +105,7 @@ def list_multiline_json_in_dir(

# Now grab filenames for all target resource types
results = {}
for child in sorted(children): # sort for reproducibility
for child in sorted(children): # sorted as an API promise
results.update(_get_resource_type(child, resource, fsspec_fs=fsspec_fs))
return results

Expand Down Expand Up @@ -229,7 +229,8 @@ def read_multiline_json_from_dir(
- Will return an empty result if the path does not exist or is not readable.
- Passing None as the resource filter (the default) will return all multi-line JSON found.
- The lines of JSON are not required to be dictionaries.
- The order of results will be consistent across calls.
- The order of results will be consistent across calls (filenames are Python-sorted first,
then rows are returned from each file in order, top to bottom)
- This function will notice both JSON Lines (.jsonl) and NDJSON (.ndjson) files.
:param path: the folder to scan
Expand Down

0 comments on commit c58fd6e

Please sign in to comment.