cehrbert-data 0.0.7__tar.gz → 0.0.9__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 (145) hide show
  1. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/PKG-INFO +1 -1
  2. cehrbert_data-0.0.9/scripts/extract_features_bert.sh +232 -0
  3. cehrbert_data-0.0.9/scripts/extract_features_gpt.sh +230 -0
  4. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/apps/generate_included_concept_list.py +23 -17
  5. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/apps/generate_training_data.py +80 -74
  6. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/death.py +15 -2
  7. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/spark_app_base.py +40 -17
  8. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/const/common.py +2 -0
  9. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/clinical_event_decorator.py +11 -4
  10. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/prediction_token_decorator.py +1 -1
  11. cehrbert_data-0.0.9/src/cehrbert_data/prediction_cohorts/readmission.py +65 -0
  12. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/extract_features.py +95 -24
  13. cehrbert_data-0.0.9/src/cehrbert_data/tools/sample_omop_tables.py +54 -0
  14. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/utils/spark_parse_args.py +13 -2
  15. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/utils/spark_utils.py +317 -807
  16. cehrbert_data-0.0.9/src/cehrbert_data/utils/vocab_utils.py +361 -0
  17. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data.egg-info/PKG-INFO +1 -1
  18. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data.egg-info/SOURCES.txt +5 -4
  19. cehrbert_data-0.0.7/src/cehrbert_data/apps/generate_concept_similarity_table.py +0 -423
  20. cehrbert_data-0.0.7/src/cehrbert_data/apps/generate_hierarchical_bert_training_data.py +0 -238
  21. cehrbert_data-0.0.7/src/cehrbert_data/apps/generate_information_content.py +0 -131
  22. cehrbert_data-0.0.7/src/cehrbert_data/apps/generate_required_labs.py +0 -140
  23. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/.github/workflows/python-build.yml +0 -0
  24. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/.github/workflows/tests.yml +0 -0
  25. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/.gitignore +0 -0
  26. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/.pre-commit-config.yaml +0 -0
  27. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/LICENSE +0 -0
  28. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/README.md +0 -0
  29. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/pyproject.toml +0 -0
  30. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/._SUCCESS.crc +0 -0
  31. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/.part-00000-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet.crc +0 -0
  32. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/.part-00003-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet.crc +0 -0
  33. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/.part-00010-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet.crc +0 -0
  34. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/_SUCCESS +0 -0
  35. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/part-00000-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet +0 -0
  36. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/part-00003-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet +0 -0
  37. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept/part-00010-4b12270c-f6c8-4b59-8e0f-fd588bd79386-c000.snappy.parquet +0 -0
  38. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/._SUCCESS.crc +0 -0
  39. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/.part-00000-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet.crc +0 -0
  40. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/.part-00002-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet.crc +0 -0
  41. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/.part-00006-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet.crc +0 -0
  42. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/.part-00011-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet.crc +0 -0
  43. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/.part-00013-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet.crc +0 -0
  44. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/_SUCCESS +0 -0
  45. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/part-00000-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet +0 -0
  46. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/part-00002-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet +0 -0
  47. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/part-00006-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet +0 -0
  48. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/part-00011-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet +0 -0
  49. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_ancestor/part-00013-eafbd8be-3337-46da-89d3-20f79c2565d4-c000.snappy.parquet +0 -0
  50. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/._SUCCESS.crc +0 -0
  51. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/.part-00000-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet.crc +0 -0
  52. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/.part-00002-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet.crc +0 -0
  53. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/.part-00007-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet.crc +0 -0
  54. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/.part-00012-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet.crc +0 -0
  55. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/_SUCCESS +0 -0
  56. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/part-00000-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet +0 -0
  57. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/part-00002-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet +0 -0
  58. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/part-00007-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet +0 -0
  59. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/concept_relationship/part-00012-5752b472-8ba7-4189-ab69-8c92e46443aa-c000.snappy.parquet +0 -0
  60. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/condition_occurrence/._SUCCESS.crc +0 -0
  61. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/condition_occurrence/.part-00000-4eff03a1-cdcf-4c89-b0cd-9ce590b9b1eb-c000.snappy.parquet.crc +0 -0
  62. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/condition_occurrence/_SUCCESS +0 -0
  63. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/condition_occurrence/part-00000-4eff03a1-cdcf-4c89-b0cd-9ce590b9b1eb-c000.snappy.parquet +0 -0
  64. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/drug_exposure/._SUCCESS.crc +0 -0
  65. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/drug_exposure/.part-00000-10bbf1a4-a7da-416e-9703-58609c7edfad-c000.snappy.parquet.crc +0 -0
  66. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/drug_exposure/_SUCCESS +0 -0
  67. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/drug_exposure/part-00000-10bbf1a4-a7da-416e-9703-58609c7edfad-c000.snappy.parquet +0 -0
  68. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/observation_period/._SUCCESS.crc +0 -0
  69. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/observation_period/.part-00000-694316e5-cc95-49f1-9fad-5a7f377e2602-c000.snappy.parquet.crc +0 -0
  70. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/observation_period/_SUCCESS +0 -0
  71. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/observation_period/part-00000-694316e5-cc95-49f1-9fad-5a7f377e2602-c000.snappy.parquet +0 -0
  72. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/person/._SUCCESS.crc +0 -0
  73. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/person/.part-00000-7d789011-f361-48da-af6f-cfe102978b3a-c000.snappy.parquet.crc +0 -0
  74. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/person/_SUCCESS +0 -0
  75. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/person/part-00000-7d789011-f361-48da-af6f-cfe102978b3a-c000.snappy.parquet +0 -0
  76. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/procedure_occurrence/._SUCCESS.crc +0 -0
  77. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/procedure_occurrence/.part-00000-e73003c1-aed5-41c0-b2d4-eaccaccf044a-c000.snappy.parquet.crc +0 -0
  78. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/procedure_occurrence/_SUCCESS +0 -0
  79. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/procedure_occurrence/part-00000-e73003c1-aed5-41c0-b2d4-eaccaccf044a-c000.snappy.parquet +0 -0
  80. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/visit_occurrence/._SUCCESS.crc +0 -0
  81. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/visit_occurrence/.part-00000-e874b5f1-bf9e-4cb9-93bf-c309a47b0476-c000.snappy.parquet.crc +0 -0
  82. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/visit_occurrence/_SUCCESS +0 -0
  83. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/sample_data/omop_sample/visit_occurrence/part-00000-e874b5f1-bf9e-4cb9-93bf-c309a47b0476-c000.snappy.parquet +0 -0
  84. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/setup.cfg +0 -0
  85. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/__init__.py +0 -0
  86. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/__init__.py +0 -0
  87. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/apps/__init__.py +0 -0
  88. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/__init__.py +0 -0
  89. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/atrial_fibrillation.py +0 -0
  90. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/cabg.py +0 -0
  91. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/coronary_artery_disease.py +0 -0
  92. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/covid.py +0 -0
  93. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/covid_inpatient.py +0 -0
  94. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/heart_failure.py +0 -0
  95. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/ischemic_stroke.py +0 -0
  96. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/last_visit_discharged_home.py +0 -0
  97. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/query_builder.py +0 -0
  98. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/type_two_diabietes.py +0 -0
  99. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/cohorts/ventilation.py +0 -0
  100. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/config/__init__.py +0 -0
  101. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/config/output_names.py +0 -0
  102. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/const/__init__.py +0 -0
  103. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/const/__pycache__/__init__.cpython-311.pyc +0 -0
  104. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/const/__pycache__/common.cpython-311.pyc +0 -0
  105. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/const/artificial_tokens.py +0 -0
  106. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/__init__.py +0 -0
  107. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/artificial_time_token_decorator.py +0 -0
  108. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/death_event_decorator.py +0 -0
  109. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/demographic_event_decorator.py +0 -0
  110. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/patient_event_decorator_base.py +0 -0
  111. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/decorators/token_priority.py +0 -0
  112. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/__init__.py +0 -0
  113. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/afib_ischemic_stroke.py +0 -0
  114. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/cad_cabg_cohort.py +0 -0
  115. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/cad_hf_cohort.py +0 -0
  116. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/copd_readmission.py +0 -0
  117. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/covid_death.py +0 -0
  118. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/covid_ventilation.py +0 -0
  119. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/discharge_home_death.py +0 -0
  120. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/hf_readmission.py +0 -0
  121. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/hospitalization.py +0 -0
  122. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/hospitalization_mortality.py +0 -0
  123. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/prediction_cohorts/t2dm_hf_cohort.py +0 -0
  124. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/queries/__init__.py +0 -0
  125. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/queries/measurement_queries.py +0 -0
  126. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/__init__.py +0 -0
  127. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/connect_omop_visit.py +0 -0
  128. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/download_omop_tables.py +0 -0
  129. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/ehrshot_to_omop.py +0 -0
  130. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/prepare_ehrshot_cohorts.py +0 -0
  131. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/tools/update_omop_visit.py +0 -0
  132. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/utils/__init__.py +0 -0
  133. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data/utils/logging_utils.py +0 -0
  134. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data.egg-info/dependency_links.txt +0 -0
  135. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data.egg-info/requires.txt +0 -0
  136. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/src/cehrbert_data.egg-info/top_level.txt +0 -0
  137. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/__init__.py +0 -0
  138. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/integration_tests/__init__.py +0 -0
  139. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/integration_tests/test_generate_training_data.py +0 -0
  140. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/integration_tests/test_hf_readmission.py +0 -0
  141. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/integration_tests/test_hf_readmission_cohort_meds.py +0 -0
  142. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/pyspark_test_base.py +0 -0
  143. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/unit_tests/__init__.py +0 -0
  144. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/unit_tests/test_ehrshot_to_omop.py +0 -0
  145. {cehrbert_data-0.0.7 → cehrbert_data-0.0.9}/tests/unit_tests/test_spark_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cehrbert_data
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: The Spark ETL tools for generating the CEHR-BERT and CEHR-GPT pre-training and finetuning data
5
5
  Author-email: Chao Pang <chaopang229@gmail.com>, Xinzhuo Jiang <xj2193@cumc.columbia.edu>, Krishna Kalluri <kk3326@cumc.columbia.edu>, Nishanth Parameshwar Pavinkurve <np2689@cumc.columbia.edu>, Karthik Natarajan <kn2174@cumc.columbia.edu>
6
6
  License: MIT License
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # cohort_processor.sh - Process multiple cohort directories using a data extraction script
4
+ #
5
+ # This script processes each cohort directory within a specified folder
6
+ # using a Python script for data extraction.
7
+
8
+ set -e # Exit immediately if a command exits with a non-zero status
9
+
10
+ # Display help documentation
11
+ function display_help() {
12
+ echo "Usage: $0 [options]"
13
+ echo ""
14
+ echo "This script processes each cohort directory found within a specified cohort folder"
15
+ echo "using a Python script for data extraction."
16
+ echo ""
17
+ echo "Options:"
18
+ echo " -h, --help Display this help message and exit"
19
+ echo " -v, --verbose Enable verbose output"
20
+ echo " -c, --cohort-folder DIR Specify the cohort folder (default: \$COHORT_FOLDER env variable)"
21
+ echo " -i, --input-dir DIR Specify the input directory (default: \$INPUT_DIR env variable)"
22
+ echo " -o, --output-dir DIR Specify the output directory (default: \$OUTPUT_DIR env variable)"
23
+ echo " -p, --patient-splits-folder DIR Specify the patient splits folder (default: \$PATIENT_SPLITS_FOLDER env variable)"
24
+ echo " -e, --ehr-tables LIST Specify the EHR tables as a space-separated list in quotes"
25
+ echo " (default: \$EHR_TABLES env variable)"
26
+ echo " -ov, --observation-window DAYS Specify the observation window in days (default: 0)"
27
+ echo ""
28
+ echo "Environment Variables (used as defaults if parameters not provided):"
29
+ echo " COHORT_FOLDER Base directory for cohorts"
30
+ echo " INPUT_DIR Base input directory"
31
+ echo " OUTPUT_DIR Base output directory"
32
+ echo " PATIENT_SPLITS_FOLDER Patient splits folder"
33
+ echo " EHR_TABLES Space-separated list of EHR tables to process"
34
+ echo ""
35
+ echo "Example:"
36
+ echo " $0 -c /path/to/cohorts -i /path/to/input -o /path/to/output"
37
+ echo ""
38
+ echo "Note: This script must be run from the root of the project directory."
39
+ }
40
+
41
+ # Check if required environment variables are set or provided via command line args
42
+ # (We'll check after parsing command line arguments)
43
+
44
+ # Parse command line arguments
45
+ VERBOSE=false
46
+ OBSERVATION_WINDOW=0
47
+ while [[ "$#" -gt 0 ]]; do
48
+ case $1 in
49
+ -h|--help)
50
+ display_help
51
+ exit 0
52
+ ;;
53
+ -v|--verbose)
54
+ VERBOSE=true
55
+ shift
56
+ ;;
57
+ -c|--cohort-folder)
58
+ COHORT_FOLDER="$2"
59
+ shift 2
60
+ ;;
61
+ -i|--input-dir)
62
+ INPUT_DIR="$2"
63
+ shift 2
64
+ ;;
65
+ -o|--output-dir)
66
+ OUTPUT_DIR="$2"
67
+ shift 2
68
+ ;;
69
+ -p|--patient-splits-folder)
70
+ PATIENT_SPLITS_FOLDER="$2"
71
+ shift 2
72
+ ;;
73
+ -e|--ehr-tables)
74
+ EHR_TABLES="$2"
75
+ shift 2
76
+ ;;
77
+ -ov|--observation-window)
78
+ OBSERVATION_WINDOW="$2"
79
+ shift 2
80
+ ;;
81
+ *)
82
+ echo "Error: Unknown parameter: $1"
83
+ display_help
84
+ exit 1
85
+ ;;
86
+ esac
87
+ done
88
+
89
+ # Verify that all required parameters are provided
90
+ missing_params=""
91
+
92
+ if [ -z "$COHORT_FOLDER" ]; then
93
+ missing_params="$missing_params COHORT_FOLDER (--cohort-folder)"
94
+ fi
95
+
96
+ if [ -z "$INPUT_DIR" ]; then
97
+ missing_params="$missing_params INPUT_DIR (--input-dir)"
98
+ fi
99
+
100
+ if [ -z "$OUTPUT_DIR" ]; then
101
+ missing_params="$missing_params OUTPUT_DIR (--output-dir)"
102
+ fi
103
+
104
+ if [ -z "$PATIENT_SPLITS_FOLDER" ]; then
105
+ missing_params="$missing_params PATIENT_SPLITS_FOLDER (--patient-splits-folder)"
106
+ fi
107
+
108
+ if [ -z "$EHR_TABLES" ]; then
109
+ missing_params="$missing_params EHR_TABLES (--ehr-tables)"
110
+ fi
111
+
112
+ # If any required parameters are missing, show error and exit
113
+ if [ -n "$missing_params" ]; then
114
+ echo "Error: Missing required parameters:"
115
+ for param in $missing_params; do
116
+ echo " - $param"
117
+ done
118
+ echo ""
119
+ echo "Please provide these values either as environment variables or command-line parameters."
120
+ echo "Run '$0 --help' for usage information."
121
+ exit 1
122
+ fi
123
+
124
+ # Display configured directories
125
+ if [ "$VERBOSE" = true ]; then
126
+ echo "Using the following directories:"
127
+ echo " COHORT_FOLDER: $COHORT_FOLDER"
128
+ echo " INPUT_DIR: $INPUT_DIR"
129
+ echo " OUTPUT_DIR: $OUTPUT_DIR"
130
+ echo " PATIENT_SPLITS_FOLDER: $PATIENT_SPLITS_FOLDER"
131
+ echo " EHR_TABLES: $EHR_TABLES"
132
+ echo " Observation Window: $OBSERVATION_WINDOW days"
133
+ fi
134
+
135
+ # Check if required directories exist
136
+ if [ ! -d "$COHORT_FOLDER" ]; then
137
+ echo "Error: Cohort folder does not exist: $COHORT_FOLDER"
138
+ exit 1
139
+ fi
140
+
141
+ if [ ! -d "$INPUT_DIR" ]; then
142
+ echo "Error: Input directory does not exist: $INPUT_DIR"
143
+ exit 1
144
+ fi
145
+
146
+ # Create output directory if it doesn't exist
147
+ if [ ! -d "$OUTPUT_DIR" ]; then
148
+ echo "Creating output directory: $OUTPUT_DIR"
149
+ mkdir -p "$OUTPUT_DIR"
150
+ fi
151
+
152
+ if [ ! -d "$PATIENT_SPLITS_FOLDER" ]; then
153
+ echo "Error: Patient splits folder does not exist: $PATIENT_SPLITS_FOLDER"
154
+ exit 1
155
+ fi
156
+
157
+ # Count the number of cohort directories
158
+ COHORT_COUNT=$(find "$COHORT_FOLDER" -mindepth 1 -maxdepth 1 -type d | wc -l)
159
+ if [ "$COHORT_COUNT" -eq 0 ]; then
160
+ echo "Warning: No cohort directories found in $COHORT_FOLDER"
161
+ exit 0
162
+ fi
163
+
164
+ echo "Found $COHORT_COUNT cohort directories to process"
165
+ echo "Starting processing at $(date)"
166
+
167
+ # Process counter
168
+ PROCESSED=0
169
+ FAILED=0
170
+
171
+ # Loop through each sub-directory in the cohort folder
172
+ for cohort_dir in "$COHORT_FOLDER"/*; do
173
+ if [ -d "$cohort_dir" ]; then
174
+ COHORT_NAME=$(basename "$cohort_dir")
175
+ echo "[$((PROCESSED+1))/$COHORT_COUNT] Processing cohort: $COHORT_NAME (output to $COHORT_OUTPUT_DIR)"
176
+
177
+ # Display verbose information if enabled
178
+ if [ "$VERBOSE" = true ]; then
179
+ echo " Input directory: $INPUT_DIR"
180
+ echo " Output directory: $OUTPUT_DIR"
181
+ echo " Cohort directory: $cohort_dir"
182
+ echo " Observation Window: $OBSERVATION_WINDOW days"
183
+ fi
184
+
185
+ # Get the basename of the cohort directory to use as the cohort name
186
+ COHORT_NAME=$(basename "$cohort_dir")
187
+
188
+ # Run the Python script with the directory-specific arguments
189
+ if python -u -m cehrbert_data.tools.extract_features \
190
+ -c "$COHORT_NAME" \
191
+ -i "$INPUT_DIR" \
192
+ -o "$OUTPUT_DIR" \
193
+ -dl 1985-01-01 \
194
+ -du 2023-12-31 \
195
+ --cohort_dir "$cohort_dir" \
196
+ --person_id_column subject_id \
197
+ --index_date_column prediction_time \
198
+ --label_column boolean_value \
199
+ -ip \
200
+ --att_type cehr_bert \
201
+ --inpatient_att_type mix \
202
+ -iv \
203
+ --ehr_table_list $EHR_TABLES \
204
+ --patient_splits_folder "$PATIENT_SPLITS_FOLDER" \
205
+ --cache_events \
206
+ --should_construct_artificial_visits \
207
+ --include_concept_list \
208
+ --keep_samples_with_no_features \
209
+ --observation_window "$OBSERVATION_WINDOW"; then
210
+
211
+ echo "✅ Successfully processed cohort: $COHORT_NAME"
212
+ PROCESSED=$((PROCESSED+1))
213
+ else
214
+ echo "❌ Failed to process cohort: $COHORT_NAME"
215
+ FAILED=$((FAILED+1))
216
+ fi
217
+
218
+ echo "--------------------------------------"
219
+ fi
220
+ done
221
+
222
+ # Print summary
223
+ echo "Processing complete at $(date)"
224
+ echo "Summary: $PROCESSED cohorts processed successfully, $FAILED failed"
225
+
226
+ if [ $FAILED -gt 0 ]; then
227
+ echo "Warning: Some cohorts failed to process"
228
+ exit 1
229
+ else
230
+ echo "All cohorts have been processed successfully"
231
+ exit 0
232
+ fi
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # cohort_processor.sh - Process multiple cohort directories using a data extraction script
4
+ #
5
+ # This script processes each cohort directory within a specified folder
6
+ # using a Python script for data extraction.
7
+
8
+ set -e # Exit immediately if a command exits with a non-zero status
9
+
10
+ # Display help documentation
11
+ function display_help() {
12
+ echo "Usage: $0 [options]"
13
+ echo ""
14
+ echo "This script processes each cohort directory found within a specified cohort folder"
15
+ echo "using a Python script for data extraction."
16
+ echo ""
17
+ echo "Options:"
18
+ echo " -h, --help Display this help message and exit"
19
+ echo " -v, --verbose Enable verbose output"
20
+ echo " -c, --cohort-folder DIR Specify the cohort folder (default: \$COHORT_FOLDER env variable)"
21
+ echo " -i, --input-dir DIR Specify the input directory (default: \$INPUT_DIR env variable)"
22
+ echo " -o, --output-dir DIR Specify the output directory (default: \$OUTPUT_DIR env variable)"
23
+ echo " -p, --patient-splits-folder DIR Specify the patient splits folder (default: \$PATIENT_SPLITS_FOLDER env variable)"
24
+ echo " -e, --ehr-tables LIST Specify the EHR tables as a space-separated list in quotes"
25
+ echo " (default: \$EHR_TABLES env variable)"
26
+ echo " -ov, --observation-window DAYS Specify the observation window in days (default: 0)"
27
+ echo ""
28
+ echo "Environment Variables (used as defaults if parameters not provided):"
29
+ echo " COHORT_FOLDER Base directory for cohorts"
30
+ echo " INPUT_DIR Base input directory"
31
+ echo " OUTPUT_DIR Base output directory"
32
+ echo " PATIENT_SPLITS_FOLDER Patient splits folder"
33
+ echo " EHR_TABLES Space-separated list of EHR tables to process"
34
+ echo ""
35
+ echo "Example:"
36
+ echo " $0 -c /path/to/cohorts -i /path/to/input -o /path/to/output"
37
+ echo ""
38
+ echo "Note: This script must be run from the root of the project directory."
39
+ }
40
+
41
+ # Check if required environment variables are set or provided via command line args
42
+ # (We'll check after parsing command line arguments)
43
+
44
+ # Parse command line arguments
45
+ VERBOSE=false
46
+ OBSERVATION_WINDOW=0
47
+ while [[ "$#" -gt 0 ]]; do
48
+ case $1 in
49
+ -h|--help)
50
+ display_help
51
+ exit 0
52
+ ;;
53
+ -v|--verbose)
54
+ VERBOSE=true
55
+ shift
56
+ ;;
57
+ -c|--cohort-folder)
58
+ COHORT_FOLDER="$2"
59
+ shift 2
60
+ ;;
61
+ -i|--input-dir)
62
+ INPUT_DIR="$2"
63
+ shift 2
64
+ ;;
65
+ -o|--output-dir)
66
+ OUTPUT_DIR="$2"
67
+ shift 2
68
+ ;;
69
+ -p|--patient-splits-folder)
70
+ PATIENT_SPLITS_FOLDER="$2"
71
+ shift 2
72
+ ;;
73
+ -e|--ehr-tables)
74
+ EHR_TABLES="$2"
75
+ shift 2
76
+ ;;
77
+ -ov|--observation-window)
78
+ OBSERVATION_WINDOW="$2"
79
+ shift 2
80
+ ;;
81
+ *)
82
+ echo "Error: Unknown parameter: $1"
83
+ display_help
84
+ exit 1
85
+ ;;
86
+ esac
87
+ done
88
+
89
+ # Verify that all required parameters are provided
90
+ missing_params=""
91
+
92
+ if [ -z "$COHORT_FOLDER" ]; then
93
+ missing_params="$missing_params COHORT_FOLDER (--cohort-folder)"
94
+ fi
95
+
96
+ if [ -z "$INPUT_DIR" ]; then
97
+ missing_params="$missing_params INPUT_DIR (--input-dir)"
98
+ fi
99
+
100
+ if [ -z "$OUTPUT_DIR" ]; then
101
+ missing_params="$missing_params OUTPUT_DIR (--output-dir)"
102
+ fi
103
+
104
+ if [ -z "$PATIENT_SPLITS_FOLDER" ]; then
105
+ missing_params="$missing_params PATIENT_SPLITS_FOLDER (--patient-splits-folder)"
106
+ fi
107
+
108
+ if [ -z "$EHR_TABLES" ]; then
109
+ missing_params="$missing_params EHR_TABLES (--ehr-tables)"
110
+ fi
111
+
112
+ # If any required parameters are missing, show error and exit
113
+ if [ -n "$missing_params" ]; then
114
+ echo "Error: Missing required parameters:"
115
+ for param in $missing_params; do
116
+ echo " - $param"
117
+ done
118
+ echo ""
119
+ echo "Please provide these values either as environment variables or command-line parameters."
120
+ echo "Run '$0 --help' for usage information."
121
+ exit 1
122
+ fi
123
+
124
+ # Display configured directories
125
+ if [ "$VERBOSE" = true ]; then
126
+ echo "Using the following directories:"
127
+ echo " COHORT_FOLDER: $COHORT_FOLDER"
128
+ echo " INPUT_DIR: $INPUT_DIR"
129
+ echo " OUTPUT_DIR: $OUTPUT_DIR"
130
+ echo " PATIENT_SPLITS_FOLDER: $PATIENT_SPLITS_FOLDER"
131
+ echo " EHR_TABLES: $EHR_TABLES"
132
+ echo " Observation Window: $OBSERVATION_WINDOW days"
133
+ fi
134
+
135
+ # Check if required directories exist
136
+ if [ ! -d "$COHORT_FOLDER" ]; then
137
+ echo "Error: Cohort folder does not exist: $COHORT_FOLDER"
138
+ exit 1
139
+ fi
140
+
141
+ if [ ! -d "$INPUT_DIR" ]; then
142
+ echo "Error: Input directory does not exist: $INPUT_DIR"
143
+ exit 1
144
+ fi
145
+
146
+ # Create output directory if it doesn't exist
147
+ if [ ! -d "$OUTPUT_DIR" ]; then
148
+ echo "Creating output directory: $OUTPUT_DIR"
149
+ mkdir -p "$OUTPUT_DIR"
150
+ fi
151
+
152
+ if [ ! -d "$PATIENT_SPLITS_FOLDER" ]; then
153
+ echo "Error: Patient splits folder does not exist: $PATIENT_SPLITS_FOLDER"
154
+ exit 1
155
+ fi
156
+
157
+ # Count the number of cohort directories
158
+ COHORT_COUNT=$(find "$COHORT_FOLDER" -mindepth 1 -maxdepth 1 -type d | wc -l)
159
+ if [ "$COHORT_COUNT" -eq 0 ]; then
160
+ echo "Warning: No cohort directories found in $COHORT_FOLDER"
161
+ exit 0
162
+ fi
163
+
164
+ echo "Found $COHORT_COUNT cohort directories to process"
165
+ echo "Starting processing at $(date)"
166
+
167
+ # Process counter
168
+ PROCESSED=0
169
+ FAILED=0
170
+
171
+ # Loop through each sub-directory in the cohort folder
172
+ for cohort_dir in "$COHORT_FOLDER"/*; do
173
+ if [ -d "$cohort_dir" ]; then
174
+ COHORT_NAME=$(basename "$cohort_dir")
175
+ echo "[$((PROCESSED+1))/$COHORT_COUNT] Processing cohort: $COHORT_NAME"
176
+
177
+ # Display verbose information if enabled
178
+ if [ "$VERBOSE" = true ]; then
179
+ echo " Input directory: $INPUT_DIR"
180
+ echo " Output directory: $OUTPUT_DIR"
181
+ echo " Cohort directory: $cohort_dir"
182
+ echo " Observation Window: $OBSERVATION_WINDOW days"
183
+ fi
184
+
185
+ # Run the Python script with the directory-specific arguments
186
+ if python -u -m cehrbert_data.tools.extract_features \
187
+ -c "$COHORT_NAME" \
188
+ -i "$INPUT_DIR" \
189
+ -o "$OUTPUT_DIR" \
190
+ -dl 1985-01-01 \
191
+ -du 2023-12-31 \
192
+ --cohort_dir "$cohort_dir" \
193
+ --person_id_column subject_id \
194
+ --index_date_column prediction_time \
195
+ --label_column boolean_value \
196
+ -ip \
197
+ --gpt_patient_sequence \
198
+ --att_type day \
199
+ --inpatient_att_type day \
200
+ -iv \
201
+ --ehr_table_list $EHR_TABLES \
202
+ --patient_splits_folder "$PATIENT_SPLITS_FOLDER" \
203
+ --cache_events \
204
+ --should_construct_artificial_visits \
205
+ --include_concept_list \
206
+ --keep_samples_with_no_features \
207
+ --observation_window "$OBSERVATION_WINDOW"; then
208
+
209
+ echo "✅ Successfully processed cohort: $COHORT_NAME"
210
+ PROCESSED=$((PROCESSED+1))
211
+ else
212
+ echo "❌ Failed to process cohort: $COHORT_NAME"
213
+ FAILED=$((FAILED+1))
214
+ fi
215
+
216
+ echo "--------------------------------------"
217
+ fi
218
+ done
219
+
220
+ # Print summary
221
+ echo "Processing complete at $(date)"
222
+ echo "Summary: $PROCESSED cohorts processed successfully, $FAILED failed"
223
+
224
+ if [ $FAILED -gt 0 ]; then
225
+ echo "Warning: Some cohorts failed to process"
226
+ exit 1
227
+ else
228
+ echo "All cohorts have been processed successfully"
229
+ exit 0
230
+ fi
@@ -24,8 +24,8 @@ from pyspark.sql import SparkSession
24
24
  from pyspark.sql import functions as F
25
25
 
26
26
  from cehrbert_data.config.output_names import QUALIFIED_CONCEPT_LIST_PATH
27
- from cehrbert_data.const.common import MEASUREMENT
28
- from cehrbert_data.utils.spark_utils import join_domain_tables, preprocess_domain_table
27
+ from cehrbert_data.const.common import CONCEPT
28
+ from cehrbert_data.utils.spark_utils import extract_events_by_domain, preprocess_domain_table
29
29
 
30
30
  DOMAIN_TABLE_LIST = ["condition_occurrence", "procedure_occurrence", "drug_exposure"]
31
31
 
@@ -55,32 +55,38 @@ def main(
55
55
  """
56
56
  spark = SparkSession.builder.appName("Generate concept list").getOrCreate()
57
57
 
58
- domain_tables = []
59
58
  # Exclude measurement from domain_table_list if exists because we need to process measurement
60
59
  # in a different way
61
60
  domain_table_list = ehr_table_list if ehr_table_list else DOMAIN_TABLE_LIST
61
+ concept = preprocess_domain_table(spark, input_folder, CONCEPT)
62
+ patient_ehr_events = None
62
63
  for domain_table_name in domain_table_list:
63
- if domain_table_name != MEASUREMENT:
64
- domain_tables.append(
65
- preprocess_domain_table(
66
- spark,
67
- input_folder,
68
- domain_table_name,
69
- with_drug_rollup=with_drug_rollup,
70
- )
71
- )
72
-
73
- # Union all domain table records
74
- patient_events = join_domain_tables(domain_tables)
64
+ domain_table = preprocess_domain_table(
65
+ spark=spark,
66
+ input_folder=input_folder,
67
+ domain_table_name=domain_table_name,
68
+ with_drug_rollup=with_drug_rollup
69
+ )
70
+ ehr_events = extract_events_by_domain(
71
+ domain_table,
72
+ spark=spark,
73
+ concept=concept,
74
+ aggregate_by_hour=False,
75
+ refresh=False,
76
+ persistence_folder=input_folder
77
+ )
78
+ if patient_ehr_events is None:
79
+ patient_ehr_events = ehr_events
80
+ else:
81
+ patient_ehr_events = patient_ehr_events.unionByName(ehr_events)
75
82
 
76
83
  # Filter out concepts that are linked to less than 100 patients
77
84
  qualified_concepts = (
78
- patient_events.where("visit_occurrence_id IS NOT NULL")
85
+ patient_ehr_events.where("visit_occurrence_id IS NOT NULL")
79
86
  .groupBy("standard_concept_id")
80
87
  .agg(F.countDistinct("person_id").alias("freq"))
81
88
  .where(F.col("freq") >= min_num_of_patients)
82
89
  )
83
-
84
90
  qualified_concepts.write.mode("overwrite").parquet(os.path.join(output_folder, QUALIFIED_CONCEPT_LIST_PATH))
85
91
 
86
92