cumulus-etl 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. cumulus_etl-2.1.0/LICENSE +201 -0
  2. cumulus_etl-2.1.0/PKG-INFO +82 -0
  3. cumulus_etl-2.1.0/README.md +42 -0
  4. cumulus_etl-2.1.0/cumulus_etl/__init__.py +3 -0
  5. cumulus_etl-2.1.0/cumulus_etl/batching.py +118 -0
  6. cumulus_etl-2.1.0/cumulus_etl/cli.py +94 -0
  7. cumulus_etl-2.1.0/cumulus_etl/cli_utils.py +252 -0
  8. cumulus_etl-2.1.0/cumulus_etl/common.py +377 -0
  9. cumulus_etl-2.1.0/cumulus_etl/completion/__init__.py +21 -0
  10. cumulus_etl-2.1.0/cumulus_etl/completion/schema.py +69 -0
  11. cumulus_etl-2.1.0/cumulus_etl/deid/__init__.py +6 -0
  12. cumulus_etl-2.1.0/cumulus_etl/deid/codebook.py +293 -0
  13. cumulus_etl-2.1.0/cumulus_etl/deid/ms-config.json +495 -0
  14. cumulus_etl-2.1.0/cumulus_etl/deid/mstool.py +102 -0
  15. cumulus_etl-2.1.0/cumulus_etl/deid/philter-config.toml +1904 -0
  16. cumulus_etl-2.1.0/cumulus_etl/deid/philter.py +43 -0
  17. cumulus_etl-2.1.0/cumulus_etl/deid/scrubber.py +459 -0
  18. cumulus_etl-2.1.0/cumulus_etl/errors.py +90 -0
  19. cumulus_etl-2.1.0/cumulus_etl/etl/__init__.py +3 -0
  20. cumulus_etl-2.1.0/cumulus_etl/etl/cli.py +407 -0
  21. cumulus_etl-2.1.0/cumulus_etl/etl/config.py +121 -0
  22. cumulus_etl-2.1.0/cumulus_etl/etl/context.py +71 -0
  23. cumulus_etl-2.1.0/cumulus_etl/etl/convert/__init__.py +3 -0
  24. cumulus_etl-2.1.0/cumulus_etl/etl/convert/cli.py +220 -0
  25. cumulus_etl-2.1.0/cumulus_etl/etl/init/__init__.py +3 -0
  26. cumulus_etl-2.1.0/cumulus_etl/etl/init/cli.py +70 -0
  27. cumulus_etl-2.1.0/cumulus_etl/etl/studies/__init__.py +0 -0
  28. cumulus_etl-2.1.0/cumulus_etl/etl/studies/covid_symptom/__init__.py +8 -0
  29. cumulus_etl-2.1.0/cumulus_etl/etl/studies/covid_symptom/covid_ctakes.py +126 -0
  30. cumulus_etl-2.1.0/cumulus_etl/etl/studies/covid_symptom/covid_tasks.py +431 -0
  31. cumulus_etl-2.1.0/cumulus_etl/etl/studies/hftest/__init__.py +3 -0
  32. cumulus_etl-2.1.0/cumulus_etl/etl/studies/hftest/hf_tasks.py +100 -0
  33. cumulus_etl-2.1.0/cumulus_etl/etl/tasks/__init__.py +4 -0
  34. cumulus_etl-2.1.0/cumulus_etl/etl/tasks/base.py +458 -0
  35. cumulus_etl-2.1.0/cumulus_etl/etl/tasks/basic_tasks.py +207 -0
  36. cumulus_etl-2.1.0/cumulus_etl/etl/tasks/nlp_task.py +102 -0
  37. cumulus_etl-2.1.0/cumulus_etl/etl/tasks/task_factory.py +120 -0
  38. cumulus_etl-2.1.0/cumulus_etl/export/__init__.py +3 -0
  39. cumulus_etl-2.1.0/cumulus_etl/export/cli.py +75 -0
  40. cumulus_etl-2.1.0/cumulus_etl/fhir/__init__.py +13 -0
  41. cumulus_etl-2.1.0/cumulus_etl/fhir/fhir_auth.py +278 -0
  42. cumulus_etl-2.1.0/cumulus_etl/fhir/fhir_client.py +409 -0
  43. cumulus_etl-2.1.0/cumulus_etl/fhir/fhir_utils.py +316 -0
  44. cumulus_etl-2.1.0/cumulus_etl/formats/__init__.py +5 -0
  45. cumulus_etl-2.1.0/cumulus_etl/formats/base.py +90 -0
  46. cumulus_etl-2.1.0/cumulus_etl/formats/batch.py +26 -0
  47. cumulus_etl-2.1.0/cumulus_etl/formats/batched_files.py +96 -0
  48. cumulus_etl-2.1.0/cumulus_etl/formats/deltalake.py +256 -0
  49. cumulus_etl-2.1.0/cumulus_etl/formats/factory.py +19 -0
  50. cumulus_etl-2.1.0/cumulus_etl/formats/ndjson.py +56 -0
  51. cumulus_etl-2.1.0/cumulus_etl/inliner/__init__.py +4 -0
  52. cumulus_etl-2.1.0/cumulus_etl/inliner/cli.py +61 -0
  53. cumulus_etl-2.1.0/cumulus_etl/inliner/inliner.py +224 -0
  54. cumulus_etl-2.1.0/cumulus_etl/inliner/reader.py +73 -0
  55. cumulus_etl-2.1.0/cumulus_etl/inliner/writer.py +46 -0
  56. cumulus_etl-2.1.0/cumulus_etl/loaders/__init__.py +5 -0
  57. cumulus_etl-2.1.0/cumulus_etl/loaders/base.py +63 -0
  58. cumulus_etl-2.1.0/cumulus_etl/loaders/fhir/__init__.py +0 -0
  59. cumulus_etl-2.1.0/cumulus_etl/loaders/fhir/bulk_export.py +443 -0
  60. cumulus_etl-2.1.0/cumulus_etl/loaders/fhir/export_log.py +335 -0
  61. cumulus_etl-2.1.0/cumulus_etl/loaders/fhir/ndjson_loader.py +181 -0
  62. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/__init__.py +0 -0
  63. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/external_mappings.py +105 -0
  64. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/extract.py +51 -0
  65. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/icd.json +119476 -0
  66. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/loader.py +215 -0
  67. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/oracle/__init__.py +0 -0
  68. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/oracle/connect.py +45 -0
  69. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/oracle/extract.py +101 -0
  70. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/oracle/query.py +157 -0
  71. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/schema.py +314 -0
  72. cumulus_etl-2.1.0/cumulus_etl/loaders/i2b2/transform.py +383 -0
  73. cumulus_etl-2.1.0/cumulus_etl/nlp/__init__.py +11 -0
  74. cumulus_etl-2.1.0/cumulus_etl/nlp/extract.py +90 -0
  75. cumulus_etl-2.1.0/cumulus_etl/nlp/huggingface.py +90 -0
  76. cumulus_etl-2.1.0/cumulus_etl/nlp/utils.py +61 -0
  77. cumulus_etl-2.1.0/cumulus_etl/nlp/watcher.py +167 -0
  78. cumulus_etl-2.1.0/cumulus_etl/store.py +107 -0
  79. cumulus_etl-2.1.0/cumulus_etl/upload_notes/__init__.py +3 -0
  80. cumulus_etl-2.1.0/cumulus_etl/upload_notes/cli.py +432 -0
  81. cumulus_etl-2.1.0/cumulus_etl/upload_notes/downloader.py +133 -0
  82. cumulus_etl-2.1.0/cumulus_etl/upload_notes/labelstudio.py +242 -0
  83. cumulus_etl-2.1.0/cumulus_etl/upload_notes/selector.py +78 -0
  84. cumulus_etl-2.1.0/docs/README.md +6 -0
  85. cumulus_etl-2.1.0/docs/architecture/cumulus-arch-regional-cluster.svg +1 -0
  86. cumulus_etl-2.1.0/docs/architecture/cumulus-arch-single-hospital.svg +1 -0
  87. cumulus_etl-2.1.0/docs/bulk-exports.md +250 -0
  88. cumulus_etl-2.1.0/docs/chart-review.md +274 -0
  89. cumulus_etl-2.1.0/docs/deid.md +192 -0
  90. cumulus_etl-2.1.0/docs/index.md +32 -0
  91. cumulus_etl-2.1.0/docs/local-setup.md +106 -0
  92. cumulus_etl-2.1.0/docs/manual-review.md +51 -0
  93. cumulus_etl-2.1.0/docs/nlp.md +237 -0
  94. cumulus_etl-2.1.0/docs/performance.md +139 -0
  95. cumulus_etl-2.1.0/docs/setup/aws.md +84 -0
  96. cumulus_etl-2.1.0/docs/setup/cumulus-aws-template.yaml +270 -0
  97. cumulus_etl-2.1.0/docs/setup/index.md +93 -0
  98. cumulus_etl-2.1.0/docs/setup/initialization.md +125 -0
  99. cumulus_etl-2.1.0/docs/studies/covid-symptom.md +88 -0
  100. cumulus_etl-2.1.0/docs/studies/index.md +21 -0
  101. cumulus_etl-2.1.0/docs/vendors.md +18 -0
  102. cumulus_etl-2.1.0/pyproject.toml +106 -0
  103. cumulus_etl-2.1.0/tests/__init__.py +0 -0
  104. cumulus_etl-2.1.0/tests/conftest.py +15 -0
  105. cumulus_etl-2.1.0/tests/convert/__init__.py +0 -0
  106. cumulus_etl-2.1.0/tests/convert/test_convert_cli.py +271 -0
  107. cumulus_etl-2.1.0/tests/covid_symptom/__init__.py +0 -0
  108. cumulus_etl-2.1.0/tests/covid_symptom/test_covid_gpt.py +253 -0
  109. cumulus_etl-2.1.0/tests/covid_symptom/test_covid_results.py +331 -0
  110. cumulus_etl-2.1.0/tests/ctakesmock.py +292 -0
  111. cumulus_etl-2.1.0/tests/data/codebook0/codebook.json +64 -0
  112. cumulus_etl-2.1.0/tests/data/covid/codebook.json +1 -0
  113. cumulus_etl-2.1.0/tests/data/covid/input/DocumentReference.ndjson +2 -0
  114. cumulus_etl-2.1.0/tests/data/covid/output/covid_symptom__nlp_results/covid_symptom__nlp_results.000.meta +6 -0
  115. cumulus_etl-2.1.0/tests/data/covid/output/covid_symptom__nlp_results/covid_symptom__nlp_results.000.ndjson +4 -0
  116. cumulus_etl-2.1.0/tests/data/covid/output/etl__completion/etl__completion.000.ndjson +1 -0
  117. cumulus_etl-2.1.0/tests/data/covid/term-exists/covid_symptom__nlp_results_term_exists/covid_symptom__nlp_results_term_exists.000.meta +6 -0
  118. cumulus_etl-2.1.0/tests/data/covid/term-exists/covid_symptom__nlp_results_term_exists/covid_symptom__nlp_results_term_exists.000.ndjson +2 -0
  119. cumulus_etl-2.1.0/tests/data/covid/term-exists/etl__completion/etl__completion.000.ndjson +1 -0
  120. cumulus_etl-2.1.0/tests/data/hftest/codebook.json +1 -0
  121. cumulus_etl-2.1.0/tests/data/hftest/input/DocumentReference.ndjson +2 -0
  122. cumulus_etl-2.1.0/tests/data/hftest/output/etl__completion/etl__completion.000.ndjson +1 -0
  123. cumulus_etl-2.1.0/tests/data/hftest/output/hftest__summary/hftest__summary.000.ndjson +2 -0
  124. cumulus_etl-2.1.0/tests/data/i2b2/codebook.json +1 -0
  125. cumulus_etl-2.1.0/tests/data/i2b2/export/Patient.ndjson +2 -0
  126. cumulus_etl-2.1.0/tests/data/i2b2/input/observation_fact_diagnosis.csv +3 -0
  127. cumulus_etl-2.1.0/tests/data/i2b2/input/observation_fact_lab_views.csv +3 -0
  128. cumulus_etl-2.1.0/tests/data/i2b2/input/observation_fact_medications.csv +3 -0
  129. cumulus_etl-2.1.0/tests/data/i2b2/input/observation_fact_notes.csv +3 -0
  130. cumulus_etl-2.1.0/tests/data/i2b2/input/observation_fact_vitals.csv +7 -0
  131. cumulus_etl-2.1.0/tests/data/i2b2/input/patient_dimension.csv +3 -0
  132. cumulus_etl-2.1.0/tests/data/i2b2/input/visit_dimension.csv +3 -0
  133. cumulus_etl-2.1.0/tests/data/i2b2/output/condition/condition.000.ndjson +2 -0
  134. cumulus_etl-2.1.0/tests/data/i2b2/output/documentreference/documentreference.000.ndjson +2 -0
  135. cumulus_etl-2.1.0/tests/data/i2b2/output/encounter/encounter.000.ndjson +2 -0
  136. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.000.ndjson +1 -0
  137. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.001.ndjson +1 -0
  138. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.002.ndjson +1 -0
  139. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.003.ndjson +1 -0
  140. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.004.ndjson +2 -0
  141. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion/etl__completion.005.ndjson +1 -0
  142. cumulus_etl-2.1.0/tests/data/i2b2/output/etl__completion_encounters/etl__completion_encounters.000.ndjson +2 -0
  143. cumulus_etl-2.1.0/tests/data/i2b2/output/medication/medication.000.ndjson +0 -0
  144. cumulus_etl-2.1.0/tests/data/i2b2/output/medicationrequest/medicationrequest.000.ndjson +2 -0
  145. cumulus_etl-2.1.0/tests/data/i2b2/output/observation/observation.000.ndjson +8 -0
  146. cumulus_etl-2.1.0/tests/data/i2b2/output/patient/patient.000.ndjson +2 -0
  147. cumulus_etl-2.1.0/tests/data/mstool/input/AllergyIntolerance.ndjson +27 -0
  148. cumulus_etl-2.1.0/tests/data/mstool/input/AllergyIntolerance.onsetString.ndjson +5 -0
  149. cumulus_etl-2.1.0/tests/data/mstool/input/Condition.1.json +118 -0
  150. cumulus_etl-2.1.0/tests/data/mstool/input/Condition.2.json +7 -0
  151. cumulus_etl-2.1.0/tests/data/mstool/input/Condition.3.json +17 -0
  152. cumulus_etl-2.1.0/tests/data/mstool/input/Device.ndjson +50 -0
  153. cumulus_etl-2.1.0/tests/data/mstool/input/DiagnosticReport.ndjson +24 -0
  154. cumulus_etl-2.1.0/tests/data/mstool/input/DocumentReference.1.json +89 -0
  155. cumulus_etl-2.1.0/tests/data/mstool/input/Encounter.1.json +196 -0
  156. cumulus_etl-2.1.0/tests/data/mstool/input/Immunization.ndjson +49 -0
  157. cumulus_etl-2.1.0/tests/data/mstool/input/Immunization.occurrenceString.ndjson +4 -0
  158. cumulus_etl-2.1.0/tests/data/mstool/input/Medication.1.json +70 -0
  159. cumulus_etl-2.1.0/tests/data/mstool/input/MedicationRequest.1.json +210 -0
  160. cumulus_etl-2.1.0/tests/data/mstool/input/MedicationRequest.2.json +21 -0
  161. cumulus_etl-2.1.0/tests/data/mstool/input/Observation.1.json +160 -0
  162. cumulus_etl-2.1.0/tests/data/mstool/input/Patient.1.json +243 -0
  163. cumulus_etl-2.1.0/tests/data/mstool/input/Patient.2.json +160 -0
  164. cumulus_etl-2.1.0/tests/data/mstool/input/Patient.3.json +164 -0
  165. cumulus_etl-2.1.0/tests/data/mstool/input/Procedure.1.json +99 -0
  166. cumulus_etl-2.1.0/tests/data/mstool/input/Procedure.2.json +5 -0
  167. cumulus_etl-2.1.0/tests/data/mstool/input/ServiceRequest.1.json +77 -0
  168. cumulus_etl-2.1.0/tests/data/mstool/output/AllergyIntolerance.ndjson +30 -0
  169. cumulus_etl-2.1.0/tests/data/mstool/output/AllergyIntolerance.onsetString.ndjson +11 -0
  170. cumulus_etl-2.1.0/tests/data/mstool/output/Condition.1.json +113 -0
  171. cumulus_etl-2.1.0/tests/data/mstool/output/Condition.2.json +12 -0
  172. cumulus_etl-2.1.0/tests/data/mstool/output/Condition.3.json +17 -0
  173. cumulus_etl-2.1.0/tests/data/mstool/output/Device.ndjson +53 -0
  174. cumulus_etl-2.1.0/tests/data/mstool/output/DiagnosticReport.ndjson +28 -0
  175. cumulus_etl-2.1.0/tests/data/mstool/output/DocumentReference.1.json +86 -0
  176. cumulus_etl-2.1.0/tests/data/mstool/output/Encounter.1.json +197 -0
  177. cumulus_etl-2.1.0/tests/data/mstool/output/Immunization.ndjson +53 -0
  178. cumulus_etl-2.1.0/tests/data/mstool/output/Immunization.occurrenceString.ndjson +10 -0
  179. cumulus_etl-2.1.0/tests/data/mstool/output/Medication.1.json +71 -0
  180. cumulus_etl-2.1.0/tests/data/mstool/output/MedicationRequest.1.json +207 -0
  181. cumulus_etl-2.1.0/tests/data/mstool/output/MedicationRequest.2.json +21 -0
  182. cumulus_etl-2.1.0/tests/data/mstool/output/Observation.1.json +111 -0
  183. cumulus_etl-2.1.0/tests/data/mstool/output/Patient.1.json +153 -0
  184. cumulus_etl-2.1.0/tests/data/mstool/output/Patient.2.json +79 -0
  185. cumulus_etl-2.1.0/tests/data/mstool/output/Patient.3.json +93 -0
  186. cumulus_etl-2.1.0/tests/data/mstool/output/Procedure.1.json +100 -0
  187. cumulus_etl-2.1.0/tests/data/mstool/output/Procedure.2.json +11 -0
  188. cumulus_etl-2.1.0/tests/data/mstool/output/ServiceRequest.1.json +76 -0
  189. cumulus_etl-2.1.0/tests/data/nlp-regression/expected-output/covid_symptom__nlp_results.000.meta +9 -0
  190. cumulus_etl-2.1.0/tests/data/nlp-regression/expected-output/covid_symptom__nlp_results.000.ndjson +16 -0
  191. cumulus_etl-2.1.0/tests/data/nlp-regression/input/DocumentReference.ndjson +5 -0
  192. cumulus_etl-2.1.0/tests/data/nlp-regression/input/README.md +8 -0
  193. cumulus_etl-2.1.0/tests/data/nlp-regression/phi/codebook.json +1 -0
  194. cumulus_etl-2.1.0/tests/data/simple/README.txt +7 -0
  195. cumulus_etl-2.1.0/tests/data/simple/batched-output/condition/condition.000.ndjson +1 -0
  196. cumulus_etl-2.1.0/tests/data/simple/batched-output/condition/condition.001.ndjson +1 -0
  197. cumulus_etl-2.1.0/tests/data/simple/batched-output/documentreference/documentreference.000.ndjson +1 -0
  198. cumulus_etl-2.1.0/tests/data/simple/batched-output/documentreference/documentreference.001.ndjson +1 -0
  199. cumulus_etl-2.1.0/tests/data/simple/batched-output/encounter/encounter.000.ndjson +1 -0
  200. cumulus_etl-2.1.0/tests/data/simple/batched-output/encounter/encounter.001.ndjson +1 -0
  201. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.000.ndjson +1 -0
  202. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.001.ndjson +1 -0
  203. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.002.ndjson +1 -0
  204. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.003.ndjson +1 -0
  205. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.004.ndjson +2 -0
  206. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.005.ndjson +1 -0
  207. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.006.ndjson +1 -0
  208. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion/etl__completion.007.ndjson +1 -0
  209. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion_encounters/etl__completion_encounters.000.ndjson +1 -0
  210. cumulus_etl-2.1.0/tests/data/simple/batched-output/etl__completion_encounters/etl__completion_encounters.001.ndjson +1 -0
  211. cumulus_etl-2.1.0/tests/data/simple/batched-output/medication/medication.000.ndjson +0 -0
  212. cumulus_etl-2.1.0/tests/data/simple/batched-output/medicationrequest/medicationrequest.000.ndjson +1 -0
  213. cumulus_etl-2.1.0/tests/data/simple/batched-output/medicationrequest/medicationrequest.001.ndjson +1 -0
  214. cumulus_etl-2.1.0/tests/data/simple/batched-output/observation/observation.000.ndjson +1 -0
  215. cumulus_etl-2.1.0/tests/data/simple/batched-output/observation/observation.001.ndjson +1 -0
  216. cumulus_etl-2.1.0/tests/data/simple/batched-output/patient/patient.000.ndjson +1 -0
  217. cumulus_etl-2.1.0/tests/data/simple/batched-output/patient/patient.001.ndjson +1 -0
  218. cumulus_etl-2.1.0/tests/data/simple/batched-output/procedure/procedure.000.ndjson +1 -0
  219. cumulus_etl-2.1.0/tests/data/simple/batched-output/procedure/procedure.001.ndjson +1 -0
  220. cumulus_etl-2.1.0/tests/data/simple/batched-output/servicerequest/servicerequest.000.ndjson +1 -0
  221. cumulus_etl-2.1.0/tests/data/simple/batched-output/servicerequest/servicerequest.001.ndjson +1 -0
  222. cumulus_etl-2.1.0/tests/data/simple/codebook.json +1 -0
  223. cumulus_etl-2.1.0/tests/data/simple/input/AllergyIntolerance.ndjson +2 -0
  224. cumulus_etl-2.1.0/tests/data/simple/input/Condition.ndjson +2 -0
  225. cumulus_etl-2.1.0/tests/data/simple/input/Device.ndjson +2 -0
  226. cumulus_etl-2.1.0/tests/data/simple/input/DiagnosticReport.ndjson +2 -0
  227. cumulus_etl-2.1.0/tests/data/simple/input/DocumentReference.ndjson +2 -0
  228. cumulus_etl-2.1.0/tests/data/simple/input/Encounter.ndjson +2 -0
  229. cumulus_etl-2.1.0/tests/data/simple/input/Immunization.ndjson +2 -0
  230. cumulus_etl-2.1.0/tests/data/simple/input/MedicationRequest.ndjson +2 -0
  231. cumulus_etl-2.1.0/tests/data/simple/input/Observation.ndjson +2 -0
  232. cumulus_etl-2.1.0/tests/data/simple/input/Patient.ndjson +2 -0
  233. cumulus_etl-2.1.0/tests/data/simple/input/Procedure.ndjson +2 -0
  234. cumulus_etl-2.1.0/tests/data/simple/input/ServiceRequest.ndjson +2 -0
  235. cumulus_etl-2.1.0/tests/data/simple/input/log.ndjson +2 -0
  236. cumulus_etl-2.1.0/tests/data/simple/output/allergyintolerance/allergyintolerance.000.ndjson +2 -0
  237. cumulus_etl-2.1.0/tests/data/simple/output/condition/condition.000.ndjson +2 -0
  238. cumulus_etl-2.1.0/tests/data/simple/output/device/device.000.ndjson +2 -0
  239. cumulus_etl-2.1.0/tests/data/simple/output/diagnosticreport/diagnosticreport.000.ndjson +2 -0
  240. cumulus_etl-2.1.0/tests/data/simple/output/documentreference/documentreference.000.ndjson +2 -0
  241. cumulus_etl-2.1.0/tests/data/simple/output/encounter/encounter.000.ndjson +2 -0
  242. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.000.ndjson +1 -0
  243. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.001.ndjson +1 -0
  244. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.002.ndjson +1 -0
  245. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.003.ndjson +1 -0
  246. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.004.ndjson +1 -0
  247. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.005.ndjson +1 -0
  248. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.006.ndjson +1 -0
  249. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.007.ndjson +1 -0
  250. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.008.ndjson +2 -0
  251. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.009.ndjson +1 -0
  252. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.010.ndjson +1 -0
  253. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion/etl__completion.011.ndjson +1 -0
  254. cumulus_etl-2.1.0/tests/data/simple/output/etl__completion_encounters/etl__completion_encounters.000.ndjson +2 -0
  255. cumulus_etl-2.1.0/tests/data/simple/output/immunization/immunization.000.ndjson +2 -0
  256. cumulus_etl-2.1.0/tests/data/simple/output/medication/medication.000.ndjson +0 -0
  257. cumulus_etl-2.1.0/tests/data/simple/output/medicationrequest/medicationrequest.000.ndjson +2 -0
  258. cumulus_etl-2.1.0/tests/data/simple/output/observation/observation.000.ndjson +2 -0
  259. cumulus_etl-2.1.0/tests/data/simple/output/patient/patient.000.ndjson +2 -0
  260. cumulus_etl-2.1.0/tests/data/simple/output/procedure/procedure.000.ndjson +2 -0
  261. cumulus_etl-2.1.0/tests/data/simple/output/servicerequest/servicerequest.000.ndjson +2 -0
  262. cumulus_etl-2.1.0/tests/deid/__init__.py +0 -0
  263. cumulus_etl-2.1.0/tests/deid/test_deid_codebook.py +190 -0
  264. cumulus_etl-2.1.0/tests/deid/test_deid_mstool.py +144 -0
  265. cumulus_etl-2.1.0/tests/deid/test_deid_philter.py +40 -0
  266. cumulus_etl-2.1.0/tests/deid/test_deid_scrubber.py +320 -0
  267. cumulus_etl-2.1.0/tests/etl/__init__.py +3 -0
  268. cumulus_etl-2.1.0/tests/etl/base.py +175 -0
  269. cumulus_etl-2.1.0/tests/etl/test_etl_cli.py +714 -0
  270. cumulus_etl-2.1.0/tests/etl/test_etl_config.py +23 -0
  271. cumulus_etl-2.1.0/tests/etl/test_etl_context.py +65 -0
  272. cumulus_etl-2.1.0/tests/etl/test_tasks.py +645 -0
  273. cumulus_etl-2.1.0/tests/export/__init__.py +0 -0
  274. cumulus_etl-2.1.0/tests/export/test_export_cli.py +113 -0
  275. cumulus_etl-2.1.0/tests/fhir/__init__.py +0 -0
  276. cumulus_etl-2.1.0/tests/fhir/test_fhir_client.py +681 -0
  277. cumulus_etl-2.1.0/tests/fhir/test_fhir_utils.py +218 -0
  278. cumulus_etl-2.1.0/tests/formats/__init__.py +0 -0
  279. cumulus_etl-2.1.0/tests/formats/test_deltalake.py +511 -0
  280. cumulus_etl-2.1.0/tests/formats/test_ndjson.py +75 -0
  281. cumulus_etl-2.1.0/tests/hftest/test_hftask.py +155 -0
  282. cumulus_etl-2.1.0/tests/i2b2_mock_data.py +111 -0
  283. cumulus_etl-2.1.0/tests/init/__init__.py +0 -0
  284. cumulus_etl-2.1.0/tests/init/test_init_cli.py +41 -0
  285. cumulus_etl-2.1.0/tests/inliner/__init__.py +0 -0
  286. cumulus_etl-2.1.0/tests/inliner/test_inline_cli.py +82 -0
  287. cumulus_etl-2.1.0/tests/inliner/test_inliner.py +252 -0
  288. cumulus_etl-2.1.0/tests/inliner/test_reader.py +99 -0
  289. cumulus_etl-2.1.0/tests/inliner/test_writer.py +31 -0
  290. cumulus_etl-2.1.0/tests/loaders/__init__.py +0 -0
  291. cumulus_etl-2.1.0/tests/loaders/i2b2/__init__.py +0 -0
  292. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_etl.py +42 -0
  293. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_loader.py +60 -0
  294. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_oracle_connect.py +56 -0
  295. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_oracle_extract.py +118 -0
  296. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_oracle_query.py +123 -0
  297. cumulus_etl-2.1.0/tests/loaders/i2b2/test_i2b2_transform.py +195 -0
  298. cumulus_etl-2.1.0/tests/loaders/ndjson/__init__.py +0 -0
  299. cumulus_etl-2.1.0/tests/loaders/ndjson/test_bulk_export.py +1013 -0
  300. cumulus_etl-2.1.0/tests/loaders/ndjson/test_log_parser.py +113 -0
  301. cumulus_etl-2.1.0/tests/loaders/ndjson/test_ndjson_loader.py +439 -0
  302. cumulus_etl-2.1.0/tests/nlp/test_watcher.py +61 -0
  303. cumulus_etl-2.1.0/tests/s3mock.py +74 -0
  304. cumulus_etl-2.1.0/tests/test_batching.py +106 -0
  305. cumulus_etl-2.1.0/tests/test_cli.py +72 -0
  306. cumulus_etl-2.1.0/tests/test_common.py +142 -0
  307. cumulus_etl-2.1.0/tests/test_store.py +19 -0
  308. cumulus_etl-2.1.0/tests/upload_notes/__init__.py +0 -0
  309. cumulus_etl-2.1.0/tests/upload_notes/test_upload_cli.py +628 -0
  310. cumulus_etl-2.1.0/tests/upload_notes/test_upload_labelstudio.py +300 -0
  311. cumulus_etl-2.1.0/tests/utils.py +344 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: cumulus-etl
3
+ Version: 2.1.0
4
+ Summary: Turns FHIR data into de-identified & aggregated records
5
+ Author-email: "Andy McMurry, PhD" <andrew.mcmurry@childrens.harvard.edu>, Michael Terry <michael.terry@childrens.harvard.edu>
6
+ Requires-Python: >= 3.10
7
+ Description-Content-Type: text/markdown
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ License-File: LICENSE
13
+ Requires-Dist: ctakesclient >= 5.1, < 6
14
+ Requires-Dist: cumulus-fhir-support >= 1.2, < 2
15
+ Requires-Dist: delta-spark >= 3.2.1, < 4
16
+ Requires-Dist: httpx < 1
17
+ Requires-Dist: inscriptis < 3
18
+ Requires-Dist: jwcrypto < 2
19
+ Requires-Dist: label-studio-sdk < 2
20
+ Requires-Dist: nltk >= 3.9, < 4
21
+ Requires-Dist: openai < 2
22
+ Requires-Dist: oracledb < 4
23
+ Requires-Dist: philter-lite < 1
24
+ Requires-Dist: pyarrow < 20
25
+ Requires-Dist: rich < 14
26
+ Requires-Dist: s3fs
27
+ Requires-Dist: pre-commit ; extra == "dev"
28
+ Requires-Dist: ruff < 0.10 ; extra == "dev"
29
+ Requires-Dist: coverage ; extra == "tests"
30
+ Requires-Dist: ddt ; extra == "tests"
31
+ Requires-Dist: moto[server, s3] >= 5.0 ; extra == "tests"
32
+ Requires-Dist: pytest ; extra == "tests"
33
+ Requires-Dist: pytest-cov ; extra == "tests"
34
+ Requires-Dist: respx ; extra == "tests"
35
+ Requires-Dist: time-machine ; extra == "tests"
36
+ Project-URL: Homepage, https://github.com/smart-on-fhir/cumulus-etl
37
+ Provides-Extra: dev
38
+ Provides-Extra: tests
39
+
40
+ # Cumulus ETL
41
+
42
+ [Cumulus](https://docs.smarthealthit.org/cumulus/)
43
+ is an entire healthcare pipeline for population-scale clinical investigations.
44
+
45
+ Cumulus ETL is the first critical piece of that pipeline.
46
+ - It **extracts** bulk patient data from your EHR.
47
+ - It **transforms** that data by anonymizing it and running NLP on clinical notes
48
+ - It **loads** that data onto the cloud to be queried by
49
+ [Cumulus Library](https://github.com/smart-on-fhir/cumulus-library) SQL
50
+
51
+ ## Documentation
52
+
53
+ For guides on installing & using Cumulus ETL,
54
+ [read our documentation](https://docs.smarthealthit.org/cumulus/etl/).
55
+
56
+ ## Example
57
+
58
+ A simple run of Cumulus ETL might look something like:
59
+ ```shell
60
+ docker compose run \
61
+ cumulus-etl \
62
+ s3://my-input-bucket/bulk-export/ \
63
+ s3://my-output-bucket/delta-lakes/ \
64
+ s3://my-phi-bucket/build-and-phi-artifacts/
65
+ ```
66
+
67
+ This line would read ndjson files from the input bucket,
68
+ drop the result as [Delta Lakes](https://delta.io/) into the output bucket,
69
+ and save some bookkeeping configuration to a build/phi bucket.
70
+
71
+ ## Contributing
72
+
73
+ We love 💖 contributions!
74
+
75
+ If you have a good suggestion 💡 or found a bug 🐛,
76
+ [read our brief contributors guide](CONTRIBUTING.md)
77
+ for pointers to filing issues and what to expect.
78
+
79
+ If you're a programmer ⌨ and are looking for a starting place to help, we keep a
80
+ [list of good bite-size issues](https://github.com/smart-on-fhir/cumulus-etl/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
81
+ for first-time contributions.
82
+
@@ -0,0 +1,42 @@
1
+ # Cumulus ETL
2
+
3
+ [Cumulus](https://docs.smarthealthit.org/cumulus/)
4
+ is an entire healthcare pipeline for population-scale clinical investigations.
5
+
6
+ Cumulus ETL is the first critical piece of that pipeline.
7
+ - It **extracts** bulk patient data from your EHR.
8
+ - It **transforms** that data by anonymizing it and running NLP on clinical notes
9
+ - It **loads** that data onto the cloud to be queried by
10
+ [Cumulus Library](https://github.com/smart-on-fhir/cumulus-library) SQL
11
+
12
+ ## Documentation
13
+
14
+ For guides on installing & using Cumulus ETL,
15
+ [read our documentation](https://docs.smarthealthit.org/cumulus/etl/).
16
+
17
+ ## Example
18
+
19
+ A simple run of Cumulus ETL might look something like:
20
+ ```shell
21
+ docker compose run \
22
+ cumulus-etl \
23
+ s3://my-input-bucket/bulk-export/ \
24
+ s3://my-output-bucket/delta-lakes/ \
25
+ s3://my-phi-bucket/build-and-phi-artifacts/
26
+ ```
27
+
28
+ This line would read ndjson files from the input bucket,
29
+ drop the result as [Delta Lakes](https://delta.io/) into the output bucket,
30
+ and save some bookkeeping configuration to a build/phi bucket.
31
+
32
+ ## Contributing
33
+
34
+ We love 💖 contributions!
35
+
36
+ If you have a good suggestion 💡 or found a bug 🐛,
37
+ [read our brief contributors guide](CONTRIBUTING.md)
38
+ for pointers to filing issues and what to expect.
39
+
40
+ If you're a programmer ⌨ and are looking for a starting place to help, we keep a
41
+ [list of good bite-size issues](https://github.com/smart-on-fhir/cumulus-etl/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
42
+ for first-time contributions.
@@ -0,0 +1,3 @@
1
+ """Turns FHIR data into de-identified & aggregated records"""
2
+
3
+ __version__ = "2.1.0"
@@ -0,0 +1,118 @@
1
+ """Iteration utilities to support batching values."""
2
+
3
+ from collections.abc import AsyncIterable, AsyncIterator, Iterable
4
+ from typing import TypeVar
5
+
6
+ Item = TypeVar("Item")
7
+ Atom = Item | list[Item] | None # one single item (or group of items that can't be broken up)
8
+ AtomStreams = Atom | tuple[Atom, ...] # separated streams of atoms (which should be kept separated)
9
+ ItemBatch = list[Item]
10
+ ItemBatchStreams = tuple[ItemBatch, ...] # separated lists of items
11
+
12
+
13
+ async def _batch_slice(iterable: AsyncIterable[AtomStreams], n: int) -> ItemBatchStreams | None:
14
+ """
15
+ Returns the first n elements of iterable, flattening lists.
16
+
17
+ But include an entire list if we would end in middle.
18
+ For example, list(_batch_slice([1, [2.1, 2.1], 3], 2)) returns [1, 2.1, 2.2]
19
+
20
+ Note that this will only flatten elements that are actual Python lists (isinstance list is True)
21
+ """
22
+ count = 0
23
+ slices = None
24
+
25
+ async for atom_streams in iterable:
26
+ if not isinstance(atom_streams, tuple):
27
+ atom_streams = (atom_streams,) # ensure that we are always dealing with a streams tuple
28
+
29
+ if slices is None: # Create a tuple of empty lists that we will fill with slice data
30
+ slices = tuple([] for _ in range(len(atom_streams)))
31
+
32
+ for index, atom in enumerate(atom_streams):
33
+ if isinstance(atom, list):
34
+ slices[index].extend(atom)
35
+ count += len(atom)
36
+ elif atom is not None:
37
+ slices[index].append(atom)
38
+ count += 1
39
+
40
+ if count >= n:
41
+ break
42
+
43
+ return slices
44
+
45
+
46
+ async def _force_aiter(iterable: AsyncIterable[Item] | Iterable[Item]) -> AsyncIterator[Item]:
47
+ """A version of aiter() that also promotes sync iterables into async iterables"""
48
+ if hasattr(iterable, "__aiter__"):
49
+ async for item in iterable:
50
+ yield item
51
+ else:
52
+ for item in iterable:
53
+ yield item
54
+
55
+
56
+ async def batch_iterate_streams(
57
+ iterable: AsyncIterable[AtomStreams] | Iterable[AtomStreams], size: int
58
+ ) -> AsyncIterator[ItemBatchStreams]:
59
+ """
60
+ Yields batches of items, each roughly {size} elements from iterable.
61
+
62
+ This is similar to itertools.batched() from Python 3.12, with a few major changes:
63
+ - this is fully async, accepting async (or sync) iteratables, and returning an async iterable
64
+ - lists are returned, rather than tuples
65
+ - batches might be larger than the batch size, if a list is encountered inside the source
66
+ iterable. In that case, all elements of the list are included in the same sub-iterator batch,
67
+ which might put us over size. See the comments for the EtlTask.group_field class attribute
68
+ for why we support this.
69
+ - this accepts an iterator of tuples, where all the items in the tuple count against the batch
70
+ size and lists inside the tuple get expanded like above. This allows batching parallel streams
71
+ of data, like we do in ETL tasks that generate multiple output tables (see MedicationRequest).
72
+ All elements in a tuple will be in the same batch. The return value is always given in tuple
73
+ form, even if the input was not tupled.
74
+
75
+ The whole iterable is never fully loaded into memory. Rather we load only one element at a time.
76
+
77
+ Example of sub-lists:
78
+ async for batch in _batch_iterate_streams([1, [2.1, 2.2], 3, 4, 5], 2):
79
+ print(batch)
80
+ # ([1, 2.1, 2.2],)
81
+ # ([3, 4],)
82
+ # ([5],)
83
+
84
+ Example of multiple streams, tupled together:
85
+ items = [(1, "a"), ([2.1, 2.2], "b"), (None, ["c", "d"])]
86
+ async for batch in _batch_iterate_streams(items, 3):
87
+ print(batch)
88
+ # ([1, 2.1, 2.2], ["a", "b"]),
89
+ # ([], ["c", "d"]),
90
+ """
91
+ if size < 1:
92
+ raise ValueError("Must iterate by at least a batch of 1")
93
+
94
+ # get a real once-through iterable (we want to iterate only once)
95
+ true_iterable = _force_aiter(iterable)
96
+ while batches := await _batch_slice(true_iterable, size):
97
+ yield batches
98
+
99
+
100
+ async def batch_iterate(
101
+ iterable: AsyncIterable[Atom] | Iterable[Atom], size: int
102
+ ) -> AsyncIterator[ItemBatch]:
103
+ """
104
+ A version of batch_iterate_streams that simplifies the common "one stream" case.
105
+
106
+ That is, this does not support accepting an iterator of tuples.
107
+
108
+ Read its documentation for the full explanation.
109
+
110
+ Example of sub-lists:
111
+ async for batch in _batch_iterate([1, [2.1, 2.2], 3, 4, 5], 2):
112
+ print(batch)
113
+ # [1, 2.1, 2.2]
114
+ # [3, 4]
115
+ # [5]
116
+ """
117
+ async for batch in batch_iterate_streams(iterable, size):
118
+ yield batch[0]
@@ -0,0 +1,94 @@
1
+ """The command line interface to cumulus-etl"""
2
+
3
+ import argparse
4
+ import asyncio
5
+ import enum
6
+ import logging
7
+ import sys
8
+ import tempfile
9
+
10
+ import rich.logging
11
+
12
+ from cumulus_etl import common, etl, export, inliner, upload_notes
13
+ from cumulus_etl.etl import convert, init
14
+
15
+
16
+ class Command(enum.Enum):
17
+ """Subcommand strings"""
18
+
19
+ CONVERT = "convert"
20
+ ETL = "etl"
21
+ EXPORT = "export"
22
+ INIT = "init"
23
+ INLINE = "inline"
24
+ UPLOAD_NOTES = "upload-notes"
25
+
26
+ # Why isn't this part of Enum directly...?
27
+ @classmethod
28
+ def values(cls):
29
+ return [e.value for e in cls]
30
+
31
+
32
+ def get_subcommand(argv: list[str]) -> str | None:
33
+ """
34
+ Determines which subcommand was requested by the given command line.
35
+
36
+ Python's argparse has no good way of setting a default sub-parser.
37
+ (i.e. one that parses the command line if no sub parser subcommand is specified)
38
+ So instead, this method inspects the first positional argument.
39
+ If it's a recognized command, we return it. Else None.
40
+ """
41
+ for i, arg in enumerate(argv):
42
+ if arg in Command.values():
43
+ return argv.pop(i) # remove it to make later parsers' jobs easier
44
+ elif not arg.startswith("-"):
45
+ # first positional arg did not match a known command, assume default command
46
+ return None
47
+
48
+
49
+ async def main(argv: list[str]) -> None:
50
+ # Use RichHandler for logging because it works better when interacting with other rich components
51
+ # (e.g. I've seen the default logger lose the last warning emitted when progress bars are also active).
52
+ # But also turn off all the complex bits - we just want the message.
53
+ logging.basicConfig(
54
+ format="%(message)s",
55
+ handlers=[rich.logging.RichHandler(show_time=False, show_level=False, show_path=False)],
56
+ )
57
+
58
+ subcommand = get_subcommand(argv)
59
+
60
+ prog = "cumulus-etl"
61
+ if subcommand:
62
+ prog += f" {subcommand}" # to make --help look nicer
63
+ parser = argparse.ArgumentParser(prog=prog)
64
+
65
+ if subcommand == Command.UPLOAD_NOTES.value:
66
+ run_method = upload_notes.run_upload_notes
67
+ elif subcommand == Command.CONVERT.value:
68
+ run_method = convert.run_convert
69
+ elif subcommand == Command.EXPORT.value:
70
+ run_method = export.run_export
71
+ elif subcommand == Command.INIT.value:
72
+ run_method = init.run_init
73
+ elif subcommand == Command.INLINE.value:
74
+ run_method = inliner.run_inline
75
+ else:
76
+ parser.description = "Extract, transform, and load FHIR data."
77
+ if not subcommand:
78
+ # Add a note about other subcommands we offer, and tell argparse not to wrap our formatting
79
+ parser.formatter_class = argparse.RawDescriptionHelpFormatter
80
+ parser.description += "\n\nother commands available:\n"
81
+ parser.description += " convert\n export\n init\n inline\n upload-notes"
82
+ run_method = etl.run_etl
83
+
84
+ with tempfile.TemporaryDirectory() as tempdir:
85
+ common.set_global_temp_dir(tempdir)
86
+ await run_method(parser, argv)
87
+
88
+
89
+ def main_cli():
90
+ asyncio.run(main(sys.argv[1:])) # pragma: no cover
91
+
92
+
93
+ if __name__ == "__main__":
94
+ main_cli() # pragma: no cover