diff --git a/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/README.md b/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/README.md index 3a1097b..63b9426 100644 --- a/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/README.md +++ b/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/README.md @@ -7,7 +7,7 @@ Scripts to fill `MEASUREMENT.unit_concept_id` from the AI-READI concept map (`.. | `USAGE.md` | **Step-by-step usage** | | `00_load_concept_map.sql` | Loads the mapping file as `concept_map` (only needed for option B; set the file path) | | `unit_concept_lookup.csv` | **The ready-made lookup table** (114 rows): load it and skip building it | -| `unit_concept_lookup_extended.csv` | **Reference view** of the 89 field keys (v1.8.2): per measurement field, its lab/measurement concept (ID, name, vocabulary, code) and its unit concept (ID, name, unit text), with the concept map lines they come from. Not needed by the join; rebuilt with `build_unit_concept_lookup_extended.py` | +| `unit_concept_lookup_extended.csv` | **Reference view** of the 89 field keys (v1.8.2): per measurement field, its measurement (target) concept (ID, name, vocabulary, code) and its unit concept (ID, name, unit text), with the concept map lines they come from. Not needed by the join; rebuilt with `build_unit_concept_lookup_extended.py` | | `01a_load_unit_concept_lookup_csv.sql` | Option A: creates `unit_lookup` from `unit_concept_lookup.csv` | | `01_create_unit_lookup.sql` | Option B: **one query** that builds `unit_lookup` from the concept map (same 114 rows) | | `02_view_unit_lookup.sql` | Review `unit_lookup`: counts, field and unit-text lists, duplicate check | @@ -19,14 +19,14 @@ Scripts to fill `MEASUREMENT.unit_concept_id` from the AI-READI concept map (`.. ## Extended lookup (`unit_concept_lookup_extended.csv`) -One row per field key of `unit_concept_lookup.csv` (89 rows), for review and for joining units to measurement concepts. "Lab" columns cover every measurement field with a unit: labs, CBC, vital signs, autorefractor and MoCA. +One row per field key of `unit_concept_lookup.csv` (89 rows), for review and for joining units to measurement concepts. The target concept columns cover every measurement field with a unit: labs, CBC, vital signs, autorefractor and MoCA. | Column | Meaning | |---|---| | `lookup_key` | Measurement field name (REDCap field ID), the same key as `unit_concept_lookup.csv` | | `form_name` | REDCap form | -| `lab_name` | REDCap label (imported labs: the short label, e.g. `HbA1c`) | -| `lab_concept_id`, `lab_concept_name`, `lab_vocabulary_id`, `lab_concept_code` | Measurement concept of the field's question row (`measurement_concept_id`) | +| `source_concept_name` | REDCap label (imported labs: the short label, e.g. `HbA1c`) | +| `target_concept_id`, `target_concept_name`, `target_vocabulary_id`, `target_concept_code` | Measurement concept of the field's question row (`measurement_concept_id`) | | `unit_concept_id`, `unit_concept_name`, `unit_source_value` | Unit concept of the field's unit row (`unit_concept_id`) | | `map_line_lab`, `map_line_unit` | Line numbers of those rows in the concept map | | `note` | The LDL exception (unit field `import_ldl_cholesterol_u`) | diff --git a/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/build_unit_concept_lookup_extended.py b/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/build_unit_concept_lookup_extended.py index 9097788..67aa297 100644 --- a/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/build_unit_concept_lookup_extended.py +++ b/redCapDataDictionaryWithExtension/value-set-mapping-common/scripts/build_unit_concept_lookup_extended.py @@ -21,7 +21,7 @@ NOTE = {'import_ldl_cholesterol': 'Key from unit field import_ldl_cholesterol_u; the measurement field is import_ldl_cholesterol_calculation', 'import_ldl_cholesterol_calculation': 'Unit field is import_ldl_cholesterol_u (different name)'} lk = [x for x in csv.DictReader(open(f'{D}/scripts/unit_concept_lookup.csv', encoding='utf-8')) if x['key_type'] == 'field'] -cols = ['lookup_key', 'form_name', 'lab_name', 'lab_concept_id', 'lab_concept_name', 'lab_vocabulary_id', 'lab_concept_code', +cols = ['lookup_key', 'form_name', 'source_concept_name', 'target_concept_id', 'target_concept_name', 'target_vocabulary_id', 'target_concept_code', 'unit_concept_id', 'unit_concept_name', 'unit_source_value', 'map_line_lab', 'map_line_unit', 'note'] out = [] for k in lk: @@ -30,7 +30,7 @@ un, ux = u[UNIT_FIELD.get(key, key + '_u')] assert g(ux, 'TARGET_CONCEPT_ID') == k['unit_concept_id'] and g(ux, 'SRC_CODE') == k['unit_source_value'], key assert g(qx, 'TARGET_DOMAIN_ID') == 'Measurement', key - # lab name: imported labs keep the short REDCap label in SRC_CODE_ID (SRC_CD_DESCRIPTION is the LOINC name) + # source_concept_name: imported labs keep the short REDCap label in SRC_CODE_ID (SRC_CD_DESCRIPTION is the LOINC name) name = g(qx, 'SRC_CODE_ID') if g(qx, 'FIELD_ID') and g(qx, 'SRC_CODE_ID') else g(qx, 'SRC_CD_DESCRIPTION') out.append([key, g(qx, 'FORM_NAME'), name, g(qx, 'TARGET_CONCEPT_ID'), g(qx, 'TARGET_CONCEPT_NAME'), g(qx, 'TARGET_VOCABULARY_ID'), g(qx, 'TARGET_CONCEPT_CODE'), k['unit_concept_id'], g(ux, 'TARGET_CONCEPT_NAME'),