From 1e099555a32d3d30fa569f08168c531b4145b7f6 Mon Sep 17 00:00:00 2001
From: Michael Boniface <m.j.boniface@soton.ac.uk>
Date: Thu, 6 Mar 2025 08:49:37 +0000
Subject: [PATCH] (refactor) Changed codes to concepts directory for alignment
 with OMOP. Closes #52

---
 acmc/phen.py                                    |  16 ++++++++--------
 .../Where this code list comes from .docx       | Bin
 .../res52-cardiovascular-events-icd10.csv       |   0
 .../Where this code list comes from .docx       | Bin
 .../res201-did-not-attend-appointment.csv       |   0
 .../Where this code list comes from .docx       | Bin
 .../Abdominal pain/res176-abdominal-pain.csv    |   0
 .../Falls/Where this code list comes from .docx | Bin
 .../Symptom code lists/Falls/res178-fall.csv    |   0
 .../Falls/res202-falls-outcome.csv              |   0
 .../Where this code list comes from .docx       | Bin
 .../Fatigue/res175-fatigue.csv                  |   0
 .../Where this code list comes from .docx       | Bin
 .../Headache/res175-headache.csv                |   0
 .../Where this code list comes from .docx       | Bin
 .../Incontinence/res11-incontinence.csv         |   0
 .../Where this code list comes from .docx       | Bin
 .../Musculoskeletal pain/res175-msk-pain.csv    |   0
 .../Where this code list comes from .docx       | Bin
 .../Neuropathic pain/res55-neuropathic_pain.csv |   0
 .../Where this code list comes from .docx       | Bin
 .../Sleep problems/res175-sleep-problems.csv    |   0
 .../Where this code list comes from .docx       | Bin
 .../Symptom code lists/Stress/res175-stress.csv |   0
 .../hanlon/Hanlon_drug_read_codes.csv           |   0
 .../hanlon/MM_code_names.csv                    |   0
 .../hanlon/Read_codes_for_diagnoses.csv         |   0
 .../Read_codes_for_drug_mm_count_diagnoses.csv  |   0
 tests/test_acmc.py                              |   6 +++---
 29 files changed, 11 insertions(+), 11 deletions(-)
 rename examples/{codes => concepts}/clinical-codes-org/Cardiovascular events (ICD10)/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Cardiovascular events (ICD10)/res52-cardiovascular-events-icd10.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Non-attendance codes/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Non-attendance codes/res201-did-not-attend-appointment.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Abdominal pain/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Abdominal pain/res176-abdominal-pain.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Falls/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Falls/res178-fall.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Falls/res202-falls-outcome.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Fatigue/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Fatigue/res175-fatigue.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Headache/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Headache/res175-headache.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Incontinence/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Incontinence/res11-incontinence.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Musculoskeletal pain/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Musculoskeletal pain/res175-msk-pain.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Neuropathic pain/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Neuropathic pain/res55-neuropathic_pain.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Sleep problems/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Sleep problems/res175-sleep-problems.csv (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Stress/Where this code list comes from .docx (100%)
 rename examples/{codes => concepts}/clinical-codes-org/Symptom code lists/Stress/res175-stress.csv (100%)
 rename examples/{codes => concepts}/hanlon/Hanlon_drug_read_codes.csv (100%)
 rename examples/{codes => concepts}/hanlon/MM_code_names.csv (100%)
 rename examples/{codes => concepts}/hanlon/Read_codes_for_diagnoses.csv (100%)
 rename examples/{codes => concepts}/hanlon/Read_codes_for_drug_mm_count_diagnoses.csv (100%)

diff --git a/acmc/phen.py b/acmc/phen.py
index 4ef51e6..86675bf 100644
--- a/acmc/phen.py
+++ b/acmc/phen.py
@@ -29,12 +29,12 @@ pd.set_option("mode.chained_assignment", None)
 PHEN_DIR = "phen"
 DEFAULT_PHEN_PATH = Path("./workspace") / PHEN_DIR
 
-CODES_DIR = "codes"
+CONCEPTS_DIR = "concepts"
 MAP_DIR = "map"
 CONCEPT_SET_DIR = "concept-set"
 CSV_PATH = Path(CONCEPT_SET_DIR) / "csv"
 OMOP_PATH = Path(CONCEPT_SET_DIR) / "omop"
-DEFAULT_PHEN_DIR_LIST = [CODES_DIR, MAP_DIR, CONCEPT_SET_DIR]
+DEFAULT_PHEN_DIR_LIST = [CONCEPTS_DIR, MAP_DIR, CONCEPT_SET_DIR]
 CONFIG_FILE = "config.yaml"
 VOCAB_VERSION_FILE = "vocab_version.yaml"
 
@@ -327,10 +327,10 @@ def validate(phen_dir):
             f"Error: phen configuration file '{config_path}' does not exist."
         )
 
-    codes_path = phen_path / CODES_DIR
-    if not codes_path.is_dir():
+    concepts_path = phen_path / CONCEPTS_DIR
+    if not concepts_path.is_dir():
         raise FileNotFoundError(
-            f"Error: source codes directory {source_codes_dir} does not exist."
+            f"Error: source concepts directory {concepts_path} does not exist."
         )
 
     # Calidate the directory is a git repo
@@ -384,7 +384,7 @@ def validate(phen_dir):
     # check codes definition
     for item in phenotype["concept_sets"]:
         # check concepte code file exists
-        concept_code_file_path = codes_path / item["file"]["path"]
+        concept_code_file_path = concepts_path / item["file"]["path"]
         if not concept_code_file_path.exists():
             validation_errors.append(
                 f"Coding file {str(concept_code_file_path.resolve())} does not exist"
@@ -683,7 +683,7 @@ def map(phen_dir, target_code_type):
 
 def map_target_code_type(phen_path, phenotype, target_code_type):
     logger.debug(f"Target coding format: {target_code_type}")
-    codes_path = phen_path / CODES_DIR
+    concepts_path = phen_path / CONCEPTS_DIR
     # Create output dataframe
     out = pd.DataFrame([])
     code_errors = []
@@ -693,7 +693,7 @@ def map_target_code_type(phen_path, phenotype, target_code_type):
         logger.debug(f"--- {concept_set['file']} ---")
 
         # Load code file
-        codes_file_path = Path(codes_path / concept_set["file"]["path"])
+        codes_file_path = Path(concepts_path / concept_set["file"]["path"])
         df = read_table_file(codes_file_path)
 
         # process structural actions
diff --git a/examples/codes/clinical-codes-org/Cardiovascular events (ICD10)/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Cardiovascular events (ICD10)/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Cardiovascular events (ICD10)/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Cardiovascular events (ICD10)/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Cardiovascular events (ICD10)/res52-cardiovascular-events-icd10.csv b/examples/concepts/clinical-codes-org/Cardiovascular events (ICD10)/res52-cardiovascular-events-icd10.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Cardiovascular events (ICD10)/res52-cardiovascular-events-icd10.csv
rename to examples/concepts/clinical-codes-org/Cardiovascular events (ICD10)/res52-cardiovascular-events-icd10.csv
diff --git a/examples/codes/clinical-codes-org/Non-attendance codes/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Non-attendance codes/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Non-attendance codes/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Non-attendance codes/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Non-attendance codes/res201-did-not-attend-appointment.csv b/examples/concepts/clinical-codes-org/Non-attendance codes/res201-did-not-attend-appointment.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Non-attendance codes/res201-did-not-attend-appointment.csv
rename to examples/concepts/clinical-codes-org/Non-attendance codes/res201-did-not-attend-appointment.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Abdominal pain/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Abdominal pain/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Abdominal pain/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Abdominal pain/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Abdominal pain/res176-abdominal-pain.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Abdominal pain/res176-abdominal-pain.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Abdominal pain/res176-abdominal-pain.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Abdominal pain/res176-abdominal-pain.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Falls/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Falls/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Falls/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Falls/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Falls/res178-fall.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Falls/res178-fall.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Falls/res178-fall.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Falls/res178-fall.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Falls/res202-falls-outcome.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Falls/res202-falls-outcome.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Falls/res202-falls-outcome.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Falls/res202-falls-outcome.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Fatigue/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Fatigue/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Fatigue/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Fatigue/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Fatigue/res175-fatigue.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Fatigue/res175-fatigue.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Fatigue/res175-fatigue.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Fatigue/res175-fatigue.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Headache/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Headache/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Headache/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Headache/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Headache/res175-headache.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Headache/res175-headache.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Headache/res175-headache.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Headache/res175-headache.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Incontinence/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Incontinence/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Incontinence/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Incontinence/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Incontinence/res11-incontinence.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Incontinence/res11-incontinence.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Incontinence/res11-incontinence.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Incontinence/res11-incontinence.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Musculoskeletal pain/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Musculoskeletal pain/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Musculoskeletal pain/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Musculoskeletal pain/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Musculoskeletal pain/res175-msk-pain.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Musculoskeletal pain/res175-msk-pain.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Musculoskeletal pain/res175-msk-pain.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Musculoskeletal pain/res175-msk-pain.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Neuropathic pain/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Neuropathic pain/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Neuropathic pain/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Neuropathic pain/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Neuropathic pain/res55-neuropathic_pain.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Neuropathic pain/res55-neuropathic_pain.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Neuropathic pain/res55-neuropathic_pain.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Neuropathic pain/res55-neuropathic_pain.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Sleep problems/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Sleep problems/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Sleep problems/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Sleep problems/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Sleep problems/res175-sleep-problems.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Sleep problems/res175-sleep-problems.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Sleep problems/res175-sleep-problems.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Sleep problems/res175-sleep-problems.csv
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Stress/Where this code list comes from .docx b/examples/concepts/clinical-codes-org/Symptom code lists/Stress/Where this code list comes from .docx
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Stress/Where this code list comes from .docx
rename to examples/concepts/clinical-codes-org/Symptom code lists/Stress/Where this code list comes from .docx
diff --git a/examples/codes/clinical-codes-org/Symptom code lists/Stress/res175-stress.csv b/examples/concepts/clinical-codes-org/Symptom code lists/Stress/res175-stress.csv
similarity index 100%
rename from examples/codes/clinical-codes-org/Symptom code lists/Stress/res175-stress.csv
rename to examples/concepts/clinical-codes-org/Symptom code lists/Stress/res175-stress.csv
diff --git a/examples/codes/hanlon/Hanlon_drug_read_codes.csv b/examples/concepts/hanlon/Hanlon_drug_read_codes.csv
similarity index 100%
rename from examples/codes/hanlon/Hanlon_drug_read_codes.csv
rename to examples/concepts/hanlon/Hanlon_drug_read_codes.csv
diff --git a/examples/codes/hanlon/MM_code_names.csv b/examples/concepts/hanlon/MM_code_names.csv
similarity index 100%
rename from examples/codes/hanlon/MM_code_names.csv
rename to examples/concepts/hanlon/MM_code_names.csv
diff --git a/examples/codes/hanlon/Read_codes_for_diagnoses.csv b/examples/concepts/hanlon/Read_codes_for_diagnoses.csv
similarity index 100%
rename from examples/codes/hanlon/Read_codes_for_diagnoses.csv
rename to examples/concepts/hanlon/Read_codes_for_diagnoses.csv
diff --git a/examples/codes/hanlon/Read_codes_for_drug_mm_count_diagnoses.csv b/examples/concepts/hanlon/Read_codes_for_drug_mm_count_diagnoses.csv
similarity index 100%
rename from examples/codes/hanlon/Read_codes_for_drug_mm_count_diagnoses.csv
rename to examples/concepts/hanlon/Read_codes_for_drug_mm_count_diagnoses.csv
diff --git a/tests/test_acmc.py b/tests/test_acmc.py
index 4b7e82d..a9bda40 100644
--- a/tests/test_acmc.py
+++ b/tests/test_acmc.py
@@ -5,7 +5,7 @@ import shutil
 import logging
 from pathlib import Path
 
-from acmc import trud, omop, main, logging_config as lc
+from acmc import trud, omop, main, phen, logging_config as lc
 
 # setup logging
 lc.setup_logger()
@@ -71,7 +71,7 @@ def test_phen_workflow(tmp_dir, monkeypatch, caplog, config_file):
     with caplog.at_level(logging.DEBUG):
         # validate phenotype
         # copy examples across
-        shutil.rmtree(phen_path / "codes")
+        shutil.rmtree(phen_path / phen.CONCEPTS_DIR)
         ex_path = Path("./examples").resolve()
         for item in ex_path.iterdir():
             source = ex_path / item.name
@@ -182,7 +182,7 @@ def test_diff(tmp_dir, monkeypatch, caplog):
     main.main()
 
     # copy example codes
-    shutil.rmtree(phen_path / "codes")
+    shutil.rmtree(phen_path / phen.CONCEPTS_DIR)
     ex_path = Path("./examples").resolve()
     for item in ex_path.iterdir():
         source = ex_path / item.name
-- 
GitLab