"""Registry mapping FHIR codes (LOINC, SNOMED, RxNorm, CVX) to snake_case column names.

AUTO-GENERATED by scripts/sync_fhir_spec.py — do not edit manually.
To update, re-run: python scripts/sync_fhir_spec.py
"""

from __future__ import annotations

import json
from dataclasses import dataclass
from typing import Optional


@dataclass
class ColumnMapping:
    code: str
    system: str
    column_name: str
    sheet: str
    display: str = ""
    unit: str = ""


class Registry:
    def __init__(self):
        self._by_code: dict[str, ColumnMapping] = {}
        self._by_column: dict[str, ColumnMapping] = {}
        self._load_defaults()

    def _load_defaults(self):
        """Load built-in LOINC/SNOMED/CVX mappings."""
        for m in _DEFAULT_MAPPINGS:
            self._register(m)

    def _register(self, m: ColumnMapping):
        key = f"{m.system}|{m.code}"
        self._by_code[key] = m
        self._by_column[m.column_name] = m

    def add(self, code: str, column_name: str, sheet: str,
            system: str = "http://loinc.org", display: str = "", unit: str = ""):
        m = ColumnMapping(code=code, system=system, column_name=column_name,
                          sheet=sheet, display=display, unit=unit)
        self._register(m)

    def lookup_code(self, system: str, code: str) -> Optional[ColumnMapping]:
        return self._by_code.get(f"{system}|{code}")

    def lookup_column(self, column_name: str) -> Optional[ColumnMapping]:
        return self._by_column.get(column_name)

    def list(self) -> list[dict]:
        return [
            {"code": m.code, "system": m.system, "column": m.column_name,
             "sheet": m.sheet, "display": m.display, "unit": m.unit}
            for m in self._by_code.values()
        ]

    def load(self, path: str):
        """Load custom mappings from a JSON file."""
        with open(path) as f:
            data = json.load(f)
        for item in data:
            self.add(**item)


# --- Code system URIs ---

LOINC = "http://loinc.org"
SNOMED = "http://snomed.info/sct"
CVX = "http://hl7.org/fhir/sid/cvx"
ICD10 = "http://hl7.org/fhir/sid/icd-10-cm"
RXNORM = "http://www.nlm.nih.gov/research/umls/rxnorm"


# --- Default mappings (219 LOINC codes) ---
# Generated from FHIR R4 spec + Synthea sample data

_DEFAULT_MAPPINGS = [
    # ===================================================================
    # VITALS (23 codes)
    # ===================================================================
    ColumnMapping(code="2708-6", system=LOINC, column_name="oxygen_saturation_pct",
                  sheet="vitals", display="Oxygen saturation", unit="%"),
    ColumnMapping(code="29463-7", system=LOINC, column_name="body_weight_kg",
                  sheet="vitals", display="Body Weight", unit="kg"),
    ColumnMapping(code="3141-9", system=LOINC, column_name="body_weight_measured",
                  sheet="vitals", display="Body Weight Measured", unit=""),
    ColumnMapping(code="39156-5", system=LOINC, column_name="bmi_kg_m2",
                  sheet="vitals", display="Body Mass Index", unit="kg/m2"),
    ColumnMapping(code="55284-4", system=LOINC, column_name="blood_pressure_panel",
                  sheet="vitals", display="Blood Pressure", unit=""),
    ColumnMapping(code="59408-5", system=LOINC, column_name="oxygen_saturation_pulse_ox_pct",
                  sheet="vitals", display="Oxygen saturation in Arterial blood by Pulse oximetry", unit="%"),
    ColumnMapping(code="59576-9", system=LOINC, column_name="bmi_percentile_pct",
                  sheet="vitals", display="Body mass index (BMI) [Percentile] Per age and gender", unit="%"),
    ColumnMapping(code="72106-8", system=LOINC, column_name="mmse_total_score",
                  sheet="vitals", display="Total score [MMSE]", unit=""),
    ColumnMapping(code="72166-2", system=LOINC, column_name="tobacco_smoking_status",
                  sheet="vitals", display="Tobacco smoking status NHIS", unit=""),
    ColumnMapping(code="72514-3", system=LOINC, column_name="pain_severity_score",
                  sheet="vitals", display="Pain severity - 0-10 verbal numeric rating [Score] - Reported", unit=""),
    ColumnMapping(code="77606-2", system=LOINC, column_name="weight_for_length_percentile_pct",
                  sheet="vitals", display="Weight-for-length Per age and sex", unit="%"),
    ColumnMapping(code="8302-2", system=LOINC, column_name="body_height_cm",
                  sheet="vitals", display="Body Height", unit="cm"),
    ColumnMapping(code="8306-3", system=LOINC, column_name="body_height_lying",
                  sheet="vitals", display="Body Height - Lying", unit=""),
    ColumnMapping(code="8310-5", system=LOINC, column_name="body_temperature_c",
                  sheet="vitals", display="Body temperature", unit="Cel"),
    ColumnMapping(code="8331-1", system=LOINC, column_name="body_temperature_oral_c",
                  sheet="vitals", display="Oral temperature", unit="Cel"),
    ColumnMapping(code="8462-4", system=LOINC, column_name="blood_pressure_diastolic_mmhg",
                  sheet="vitals", display="Diastolic Blood Pressure", unit="mmHg"),
    ColumnMapping(code="8478-0", system=LOINC, column_name="mean_blood_pressure_mmhg",
                  sheet="vitals", display="", unit="mmHg"),
    ColumnMapping(code="8480-6", system=LOINC, column_name="blood_pressure_systolic_mmhg",
                  sheet="vitals", display="Systolic Blood Pressure", unit="mmHg"),
    ColumnMapping(code="85353-1", system=LOINC, column_name="vital_signs_panel",
                  sheet="vitals", display="", unit=""),
    ColumnMapping(code="85354-9", system=LOINC, column_name="blood_pressure_panel",
                  sheet="vitals", display="Blood pressure panel", unit=""),
    ColumnMapping(code="8867-4", system=LOINC, column_name="heart_rate_bpm",
                  sheet="vitals", display="Heart rate", unit="/min"),
    ColumnMapping(code="9279-1", system=LOINC, column_name="respiratory_rate_bpm",
                  sheet="vitals", display="Respiratory rate", unit="/min"),
    ColumnMapping(code="9843-4", system=LOINC, column_name="head_circumference_cm",
                  sheet="vitals", display="", unit="cm"),
    # ===================================================================
    # LABS (196 codes)
    # ===================================================================
    ColumnMapping(code="10197-2", system=LOINC, column_name="physical_findings_of_eye_narrative",
                  sheet="labs", display="Physical Findings of Eye Narrative", unit=""),
    ColumnMapping(code="10230-1", system=LOINC, column_name="left_ventricular_ejection_fraction",
                  sheet="labs", display="Left ventricular Ejection fraction", unit=""),
    ColumnMapping(code="10834-0", system=LOINC, column_name="globulin_g_dl",
                  sheet="labs", display="Globulin [Mass/volume] in Serum by calculation", unit="g/dL"),
    ColumnMapping(code="10839-9", system=LOINC, column_name="troponin_i_ng_ml",
                  sheet="labs", display="Troponin I Ng Ml", unit="ng/mL"),
    ColumnMapping(code="11397-7", system=LOINC, column_name="physical_findings_of_foot_narrative",
                  sheet="labs", display="Physical Findings of Foot Narrative", unit=""),
    ColumnMapping(code="11428-0", system=LOINC, column_name="physical_findings_of_foot_nominal",
                  sheet="labs", display="Physical Findings of Foot (Nominal)", unit=""),
    ColumnMapping(code="11557-6", system=LOINC, column_name="co2_meq_l",
                  sheet="labs", display="Co2 Meq L", unit="mEq/L"),
    ColumnMapping(code="11580-8", system=LOINC, column_name="tsh_miu_l",
                  sheet="labs", display="Tsh Miu L", unit="mIU/L"),
    ColumnMapping(code="13457-7", system=LOINC, column_name="ldl_cholesterol_calculated_mg_dl",
                  sheet="labs", display="Cholesterol in LDL [Mass/volume] in Serum or Plasma", unit="mg/dL"),
    ColumnMapping(code="13654-9", system=LOINC, column_name="epithelial_cells_squamous",
                  sheet="labs", display="Epithelial cells.squamous [#/volume] in Urine sediment", unit=""),
    ColumnMapping(code="13959-2", system=LOINC, column_name="calcium_ionized",
                  sheet="labs", display="Calcium.ionized [Moles/volume] in Serum or Plasma by calculation", unit=""),
    ColumnMapping(code="14629-0", system=LOINC, column_name="bilirubin_direct",
                  sheet="labs", display="Bilirubin.direct [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14631-6", system=LOINC, column_name="bilirubin_total",
                  sheet="labs", display="Bilirubin.total [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14682-9", system=LOINC, column_name="creatinine",
                  sheet="labs", display="Creatinine [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14749-6", system=LOINC, column_name="glucose",
                  sheet="labs", display="Glucose [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14879-1", system=LOINC, column_name="phosphate",
                  sheet="labs", display="Phosphate [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14933-6", system=LOINC, column_name="urate",
                  sheet="labs", display="Urate [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14937-7", system=LOINC, column_name="urea_nitrogen",
                  sheet="labs", display="Urea nitrogen [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="14957-5", system=LOINC, column_name="microalbumin",
                  sheet="labs", display="Microalbumin [Mass/volume] in Urine", unit=""),
    ColumnMapping(code="14959-1", system=LOINC, column_name="microalbumin_creatinine_ratio",
                  sheet="labs", display="Microalbumin Creatinine Ratio", unit="mg/g"),
    ColumnMapping(code="15074-8", system=LOINC, column_name="glucose",
                  sheet="labs", display="Glucose [Moles/volume] in Blood", unit=""),
    ColumnMapping(code="1558-6", system=LOINC, column_name="blood_glucose_fasting_mg_dl",
                  sheet="labs", display="Fasting glucose", unit="mg/dL"),
    ColumnMapping(code="1742-6", system=LOINC, column_name="alt_u_l",
                  sheet="labs", display="Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma", unit="U/L"),
    ColumnMapping(code="1751-7", system=LOINC, column_name="albumin_g_dl",
                  sheet="labs", display="Albumin [Mass/volume] in Serum or Plasma", unit="g/dL"),
    ColumnMapping(code="17861-6", system=LOINC, column_name="calcium_mg_dl",
                  sheet="labs", display="Calcium Mg Dl", unit="mg/dL"),
    ColumnMapping(code="1798-2", system=LOINC, column_name="amylase_u_l",
                  sheet="labs", display="Amylase U L", unit="U/L"),
    ColumnMapping(code="1798-8", system=LOINC, column_name="vitamin_d_ng_ml",
                  sheet="labs", display="Vitamin D Ng Ml", unit="ng/mL"),
    ColumnMapping(code="18262-6", system=LOINC, column_name="ldl_cholesterol_direct_mg_dl",
                  sheet="labs", display="Low Density Lipoprotein Cholesterol", unit="mg/dL"),
    ColumnMapping(code="1863-0", system=LOINC, column_name="anion_gap_4",
                  sheet="labs", display="Anion gap 4 in Serum or Plasma", unit=""),
    ColumnMapping(code="1920-8", system=LOINC, column_name="ast_u_l",
                  sheet="labs", display="Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma", unit="U/L"),
    ColumnMapping(code="1925-7", system=LOINC, column_name="base_excess_meq_l",
                  sheet="labs", display="Base Excess Meq L", unit="mEq/L"),
    ColumnMapping(code="1960-4", system=LOINC, column_name="bicarbonate_meq_l",
                  sheet="labs", display="Bicarbonate Meq L", unit="mEq/L"),
    ColumnMapping(code="1963-8", system=LOINC, column_name="bicarbonate",
                  sheet="labs", display="Bicarbonate [Moles/volume] in Serum", unit=""),
    ColumnMapping(code="1968-7", system=LOINC, column_name="direct_bilirubin_mg_dl",
                  sheet="labs", display="Direct Bilirubin Mg Dl", unit="mg/dL"),
    ColumnMapping(code="1975-2", system=LOINC, column_name="total_bilirubin_mg_dl",
                  sheet="labs", display="Bilirubin.total [Mass/volume] in Serum or Plasma", unit="mg/dL"),
    ColumnMapping(code="1988-5", system=LOINC, column_name="crp_mg_l",
                  sheet="labs", display="Crp Mg L", unit="mg/L"),
    ColumnMapping(code="19926-5", system=LOINC, column_name="fev1_fvc",
                  sheet="labs", display="FEV1/FVC", unit=""),
    ColumnMapping(code="2000-8", system=LOINC, column_name="calcium",
                  sheet="labs", display="Calcium [Moles/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="2019-8", system=LOINC, column_name="pco2_mmhg",
                  sheet="labs", display="Pco2 Mmhg", unit="mmHg"),
    ColumnMapping(code="2028-9", system=LOINC, column_name="co2_meq_l",
                  sheet="labs", display="Co2 Meq L", unit="mEq/L"),
    ColumnMapping(code="20454-5", system=LOINC, column_name="urine_protein_presence",
                  sheet="labs", display="Protein [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="20505-4", system=LOINC, column_name="urine_bilirubin_mg_dl",
                  sheet="labs", display="Bilirubin.total [Mass/volume] in Urine by Test strip", unit="mg/dL"),
    ColumnMapping(code="20565-8", system=LOINC, column_name="co2_meq_l",
                  sheet="labs", display="Carbon Dioxide", unit="mEq/L"),
    ColumnMapping(code="20570-8", system=LOINC, column_name="hematocrit_pct",
                  sheet="labs", display="Hematocrit [Volume Fraction] of Blood", unit="%"),
    ColumnMapping(code="2069-3", system=LOINC, column_name="chloride_meq_l",
                  sheet="labs", display="Chloride", unit="mEq/L"),
    ColumnMapping(code="2075-0", system=LOINC, column_name="chloride_meq_l",
                  sheet="labs", display="Chloride [Moles/volume] in Serum or Plasma", unit="mEq/L"),
    ColumnMapping(code="2085-9", system=LOINC, column_name="hdl_cholesterol_mg_dl",
                  sheet="labs", display="High Density Lipoprotein Cholesterol", unit="mg/dL"),
    ColumnMapping(code="2089-1", system=LOINC, column_name="ldl_cholesterol_mg_dl",
                  sheet="labs", display="Cholesterol in LDL [Mass/volume] in Serum or Plasma", unit="mg/dL"),
    ColumnMapping(code="2093-3", system=LOINC, column_name="total_cholesterol_mg_dl",
                  sheet="labs", display="Total Cholesterol", unit="mg/dL"),
    ColumnMapping(code="21000-5", system=LOINC, column_name="rdw_pct",
                  sheet="labs", display="Erythrocyte distribution width [Entitic volume] by Automated count", unit="%"),
    ColumnMapping(code="2132-9", system=LOINC, column_name="vitamin_b12_pg_ml",
                  sheet="labs", display="Vitamin B12 Pg Ml", unit="pg/mL"),
    ColumnMapping(code="2160-0", system=LOINC, column_name="creatinine_mg_dl",
                  sheet="labs", display="Creatinine [Mass/volume] in Serum or Plasma", unit="mg/dL"),
    ColumnMapping(code="2161-8", system=LOINC, column_name="creatinine",
                  sheet="labs", display="Creatinine [Mass/volume] in Urine", unit=""),
    ColumnMapping(code="2284-8", system=LOINC, column_name="folate_ng_ml",
                  sheet="labs", display="Folate Ng Ml", unit="ng/mL"),
    ColumnMapping(code="2324-2", system=LOINC, column_name="gamma_glutamyl_transferase",
                  sheet="labs", display="Gamma glutamyl transferase [Enzymatic activity/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="2339-0", system=LOINC, column_name="glucose_mg_dl",
                  sheet="labs", display="Glucose", unit="mg/dL"),
    ColumnMapping(code="2345-7", system=LOINC, column_name="glucose_mg_dl",
                  sheet="labs", display="Glucose Mg Dl", unit="mg/dL"),
    ColumnMapping(code="2349-9", system=LOINC, column_name="glucose",
                  sheet="labs", display="Glucose [Presence] in Urine", unit=""),
    ColumnMapping(code="24323-8", system=LOINC, column_name="comprehensive_metabolic_2000_panel_serum_or",
                  sheet="labs", display="Comprehensive metabolic 2000 panel - Serum or Plasma", unit=""),
    ColumnMapping(code="24357-6", system=LOINC, column_name="urinalysis_macro_dipstick_panel_urine",
                  sheet="labs", display="Urinalysis macro (dipstick) panel - Urine", unit=""),
    ColumnMapping(code="2498-4", system=LOINC, column_name="iron_ug_dl",
                  sheet="labs", display="Iron Ug Dl", unit="ug/dL"),
    ColumnMapping(code="2500-7", system=LOINC, column_name="ferritin_ng_ml",
                  sheet="labs", display="Ferritin Ng Ml", unit="ng/mL"),
    ColumnMapping(code="2514-8", system=LOINC, column_name="urine_ketones_presence",
                  sheet="labs", display="Ketones [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="2519-7", system=LOINC, column_name="lipase_u_l",
                  sheet="labs", display="Lipase U L", unit="U/L"),
    ColumnMapping(code="2532-0", system=LOINC, column_name="lactate_dehydrogenase",
                  sheet="labs", display="Lactate dehydrogenase [Enzymatic activity/volume] in Serum or Plasma", unit=""),
    ColumnMapping(code="25428-4", system=LOINC, column_name="urine_glucose_presence",
                  sheet="labs", display="Glucose [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="2571-8", system=LOINC, column_name="triglycerides_mg_dl",
                  sheet="labs", display="Triglycerides", unit="mg/dL"),
    ColumnMapping(code="26499-4", system=LOINC, column_name="neutrophils",
                  sheet="labs", display="Neutrophils [#/volume] in Blood", unit=""),
    ColumnMapping(code="26515-7", system=LOINC, column_name="platelets_k_ul",
                  sheet="labs", display="Platelets [#/volume] in Blood", unit="K/uL"),
    ColumnMapping(code="2703-7", system=LOINC, column_name="po2_mmhg",
                  sheet="labs", display="Po2 Mmhg", unit="mmHg"),
    ColumnMapping(code="2713-6", system=LOINC, column_name="lactate_mmol_l",
                  sheet="labs", display="Lactate Mmol L", unit="mmol/L"),
    ColumnMapping(code="2744-1", system=LOINC, column_name="ph_arterial",
                  sheet="labs", display="Ph Arterial", unit=""),
    ColumnMapping(code="2756-5", system=LOINC, column_name="ph_of_urine",
                  sheet="labs", display="pH of Urine", unit=""),
    ColumnMapping(code="2823-3", system=LOINC, column_name="potassium_meq_l",
                  sheet="labs", display="Potassium [Moles/volume] in Serum or Plasma", unit="mEq/L"),
    ColumnMapping(code="28245-9", system=LOINC, column_name="abuse_status",
                  sheet="labs", display="Abuse Status [OMAHA]", unit=""),
    ColumnMapping(code="2885-2", system=LOINC, column_name="total_protein_g_dl",
                  sheet="labs", display="Protein [Mass/volume] in Serum or Plasma", unit="g/dL"),
    ColumnMapping(code="2887-8", system=LOINC, column_name="protein",
                  sheet="labs", display="Protein [Presence] in Urine", unit=""),
    ColumnMapping(code="2947-0", system=LOINC, column_name="sodium_meq_l",
                  sheet="labs", display="Sodium", unit="mEq/L"),
    ColumnMapping(code="2951-2", system=LOINC, column_name="sodium_meq_l",
                  sheet="labs", display="Sodium [Moles/volume] in Serum or Plasma", unit="mEq/L"),
    ColumnMapping(code="2965-2", system=LOINC, column_name="specific_gravity_of_urine",
                  sheet="labs", display="Specific gravity of Urine", unit=""),
    ColumnMapping(code="3016-3", system=LOINC, column_name="tsh_miu_l",
                  sheet="labs", display="Thyrotropin [Units/volume] in Serum or Plasma", unit="mIU/L"),
    ColumnMapping(code="3024-7", system=LOINC, column_name="free_t4_ng_dl",
                  sheet="labs", display="Thyroxine (T4) free [Mass/volume] in Serum or Plasma", unit="ng/dL"),
    ColumnMapping(code="30391-7", system=LOINC, column_name="erythocytes",
                  sheet="labs", display="Erythocytes [#/volume] in Urine", unit=""),
    ColumnMapping(code="30405-5", system=LOINC, column_name="leukocytes",
                  sheet="labs", display="Leukocytes [#/volume] in Urine", unit=""),
    ColumnMapping(code="3051-0", system=LOINC, column_name="free_t3_pg_ml",
                  sheet="labs", display="Free T3 Pg Ml", unit="pg/mL"),
    ColumnMapping(code="30522-7", system=LOINC, column_name="crp_hs_mg_l",
                  sheet="labs", display="Crp Hs Mg L", unit="mg/L"),
    ColumnMapping(code="3084-1", system=LOINC, column_name="uric_acid_mg_dl",
                  sheet="labs", display="Uric Acid Mg Dl", unit="mg/dL"),
    ColumnMapping(code="30934-4", system=LOINC, column_name="bnp_pg_ml",
                  sheet="labs", display="Bnp Pg Ml", unit="pg/mL"),
    ColumnMapping(code="3094-0", system=LOINC, column_name="bun_mg_dl",
                  sheet="labs", display="Bun Mg Dl", unit="mg/dL"),
    ColumnMapping(code="3173-2", system=LOINC, column_name="aptt_sec",
                  sheet="labs", display="Aptt Sec", unit="s"),
    ColumnMapping(code="32167-9", system=LOINC, column_name="urine_clarity",
                  sheet="labs", display="Clarity of Urine", unit=""),
    ColumnMapping(code="32207-3", system=LOINC, column_name="platelet_distribution_width_fl",
                  sheet="labs", display="Platelet distribution width [Entitic volume] in Blood by Automated count", unit="fL"),
    ColumnMapping(code="3255-7", system=LOINC, column_name="fibrinogen_mg_dl",
                  sheet="labs", display="Fibrinogen Mg Dl", unit="mg/dL"),
    ColumnMapping(code="32623-1", system=LOINC, column_name="mean_platelet_volume_fl",
                  sheet="labs", display="Platelet mean volume [Entitic volume] in Blood by Automated count", unit="fL"),
    ColumnMapping(code="33051-4", system=LOINC, column_name="erythrocytes",
                  sheet="labs", display="Erythrocytes [Presence] in Urine", unit=""),
    ColumnMapping(code="33052-2", system=LOINC, column_name="leukocytes",
                  sheet="labs", display="Leukocytes [Presence] in Urine", unit=""),
    ColumnMapping(code="33756-8", system=LOINC, column_name="polyp_size_greatest_dimension",
                  sheet="labs", display="Polyp size greatest dimension by CAP cancer protocols", unit=""),
    ColumnMapping(code="33762-6", system=LOINC, column_name="nt_pro_bnp_pg_ml",
                  sheet="labs", display="NT-proBNP", unit="pg/mL"),
    ColumnMapping(code="33914-3", system=LOINC, column_name="egfr_ml_min",
                  sheet="labs", display="Glomerular filtration rate/1.73 sq M.predicted", unit="mL/min/1.73m2"),
    ColumnMapping(code="38265-5", system=LOINC, column_name="dxa_bone_density",
                  sheet="labs", display="DXA [T-score] Bone density", unit=""),
    ColumnMapping(code="38483-4", system=LOINC, column_name="creatinine_mg_dl",
                  sheet="labs", display="Creatinine", unit="mg/dL"),
    ColumnMapping(code="41981-2", system=LOINC, column_name="calories_burned",
                  sheet="labs", display="Calories burned", unit=""),
    ColumnMapping(code="42798-9", system=LOINC, column_name="age_at_menarche",
                  sheet="labs", display="Age at menarche", unit=""),
    ColumnMapping(code="4537-7", system=LOINC, column_name="esr_mm_hr",
                  sheet="labs", display="Esr Mm Hr", unit="mm/hr"),
    ColumnMapping(code="4544-3", system=LOINC, column_name="hematocrit_pct",
                  sheet="labs", display="Hematocrit [Volume Fraction] of Blood by Automated count", unit="%"),
    ColumnMapping(code="4548-4", system=LOINC, column_name="hba1c_pct",
                  sheet="labs", display="Hemoglobin A1c/Hemoglobin.total in Blood", unit="%"),
    ColumnMapping(code="46240-8", system=LOINC, column_name="history_of_hospitalizations_outpatient_visits",
                  sheet="labs", display="History of Hospitalizations+Outpatient visits", unit=""),
    ColumnMapping(code="46241-6", system=LOINC, column_name="unknown",
                  sheet="labs", display="", unit=""),
    ColumnMapping(code="48065-7", system=LOINC, column_name="d_dimer_ng_ml",
                  sheet="labs", display="D Dimer Ng Ml", unit="ng/mL"),
    ColumnMapping(code="49563-0", system=LOINC, column_name="troponin_t_hs_ng_l",
                  sheet="labs", display="Troponin T Hs Ng L", unit="ng/L"),
    ColumnMapping(code="49765-1", system=LOINC, column_name="calcium_mg_dl",
                  sheet="labs", display="Calcium", unit="mg/dL"),
    ColumnMapping(code="55277-8", system=LOINC, column_name="hiv_status",
                  sheet="labs", display="HIV status", unit=""),
    ColumnMapping(code="55423-8", system=LOINC, column_name="number_of_steps",
                  sheet="labs", display="Number of steps in unspecified time Pedometer", unit=""),
    ColumnMapping(code="5767-9", system=LOINC, column_name="urine_appearance",
                  sheet="labs", display="Appearance of Urine", unit=""),
    ColumnMapping(code="5770-3", system=LOINC, column_name="urine_bilirubin_presence",
                  sheet="labs", display="Bilirubin.total [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="5778-6", system=LOINC, column_name="urine_color",
                  sheet="labs", display="Color of Urine", unit=""),
    ColumnMapping(code="57905-2", system=LOINC, column_name="stool_hemoglobin_presence",
                  sheet="labs", display="Hemoglobin.gastrointestinal [Presence] in Stool by Immunologic method", unit=""),
    ColumnMapping(code="5792-7", system=LOINC, column_name="urine_glucose_mg_dl",
                  sheet="labs", display="Glucose [Mass/volume] in Urine by Test strip", unit="mg/dL"),
    ColumnMapping(code="5794-3", system=LOINC, column_name="urine_blood_presence",
                  sheet="labs", display="Hemoglobin [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="5797-6", system=LOINC, column_name="urine_ketones_mg_dl",
                  sheet="labs", display="Ketones [Mass/volume] in Urine by Test strip", unit="mg/dL"),
    ColumnMapping(code="5799-2", system=LOINC, column_name="urine_leukocyte_esterase_presence",
                  sheet="labs", display="Leukocyte esterase [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="5802-4", system=LOINC, column_name="urine_nitrite_presence",
                  sheet="labs", display="Nitrite [Presence] in Urine by Test strip", unit=""),
    ColumnMapping(code="5803-2", system=LOINC, column_name="urine_ph",
                  sheet="labs", display="pH of Urine by Test strip", unit=""),
    ColumnMapping(code="5804-0", system=LOINC, column_name="urine_protein_mg_dl",
                  sheet="labs", display="Protein [Mass/volume] in Urine by Test strip", unit="mg/dL"),
    ColumnMapping(code="5811-5", system=LOINC, column_name="urine_specific_gravity",
                  sheet="labs", display="Specific gravity of Urine by Test strip", unit=""),
    ColumnMapping(code="58410-2", system=LOINC, column_name="complete_blood_count_hemogram_panel_blood",
                  sheet="labs", display="Complete blood count (hemogram) panel - Blood by Automated count", unit=""),
    ColumnMapping(code="58448-2", system=LOINC, column_name="microalbumin_mg_min",
                  sheet="labs", display="Microalbumin mg/min [Mass/time] in 24 hour Urine", unit=""),
    ColumnMapping(code="5902-2", system=LOINC, column_name="pt_sec",
                  sheet="labs", display="Pt Sec", unit="s"),
    ColumnMapping(code="5905-5", system=LOINC, column_name="monocytes_100_leukocytes",
                  sheet="labs", display="Monocytes/100 leukocytes in Blood by Automated count", unit=""),
    ColumnMapping(code="59261-8", system=LOINC, column_name="hba1c_ifcc_mmol_mol",
                  sheet="labs", display="Hba1C Ifcc Mmol Mol", unit="mmol/mol"),
    ColumnMapping(code="6075-6", system=LOINC, column_name="cladosporium_ige_ku_l",
                  sheet="labs", display="Cladosporium herbarum IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6082-2", system=LOINC, column_name="codfish_ige_ku_l",
                  sheet="labs", display="Codfish IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6085-5", system=LOINC, column_name="common_ragweed_ige_ku_l",
                  sheet="labs", display="Common Ragweed IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6095-4", system=LOINC, column_name="house_dust_mite_ige_ku_l",
                  sheet="labs", display="American house dust mite IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="61008-9", system=LOINC, column_name="body_surface_temperature",
                  sheet="labs", display="Body surface temperature", unit=""),
    ColumnMapping(code="6106-9", system=LOINC, column_name="egg_white_ige_ku_l",
                  sheet="labs", display="Egg white IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6158-0", system=LOINC, column_name="latex_ige_ku_l",
                  sheet="labs", display="Latex IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6189-5", system=LOINC, column_name="white_oak_ige_ku_l",
                  sheet="labs", display="White oak IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6206-7", system=LOINC, column_name="peanut_ige_ku_l",
                  sheet="labs", display="Peanut IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6246-3", system=LOINC, column_name="shrimp_ige_ku_l",
                  sheet="labs", display="Shrimp IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6248-9", system=LOINC, column_name="soybean_ige_ku_l",
                  sheet="labs", display="Soybean IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6273-7", system=LOINC, column_name="walnut_ige_ku_l",
                  sheet="labs", display="Walnut IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6276-0", system=LOINC, column_name="wheat_ige_ku_l",
                  sheet="labs", display="Wheat IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6298-4", system=LOINC, column_name="potassium_meq_l",
                  sheet="labs", display="Potassium", unit="mEq/L"),
    ColumnMapping(code="6299-2", system=LOINC, column_name="bun_mg_dl",
                  sheet="labs", display="Urea Nitrogen", unit="mg/dL"),
    ColumnMapping(code="6301-6", system=LOINC, column_name="inr",
                  sheet="labs", display="Inr", unit=""),
    ColumnMapping(code="63513-6", system=LOINC, column_name="are_you_covered",
                  sheet="labs", display="Are you covered by health insurance or some other kind of health care plan [PhenX]", unit=""),
    ColumnMapping(code="6598-7", system=LOINC, column_name="troponin_t_ng_ml",
                  sheet="labs", display="Troponin T Ng Ml", unit="ng/mL"),
    ColumnMapping(code="66519-0", system=LOINC, column_name="percentage_area_affected",
                  sheet="labs", display="Percentage area affected by eczema Head and Neck", unit=""),
    ColumnMapping(code="66524-0", system=LOINC, column_name="percentage_area_affected",
                  sheet="labs", display="Percentage area affected by eczema Upper extremitiy - bilateral", unit=""),
    ColumnMapping(code="66529-9", system=LOINC, column_name="percentage_area_affected",
                  sheet="labs", display="Percentage area affected by eczema Trunk", unit=""),
    ColumnMapping(code="66534-9", system=LOINC, column_name="percentage_area_affected",
                  sheet="labs", display="Percentage area affected by eczema Lower extremitiy - bilateral", unit=""),
    ColumnMapping(code="6690-2", system=LOINC, column_name="wbc_k_ul",
                  sheet="labs", display="Leukocytes [#/volume] in Blood by Automated count", unit="K/uL"),
    ColumnMapping(code="6768-6", system=LOINC, column_name="alkaline_phosphatase_u_l",
                  sheet="labs", display="Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma", unit="U/L"),
    ColumnMapping(code="6833-8", system=LOINC, column_name="cat_dander_ige_ku_l",
                  sheet="labs", display="Cat dander IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="6844-5", system=LOINC, column_name="honey_bee_ige_ku_l",
                  sheet="labs", display="Honey bee IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="69405-9", system=LOINC, column_name="glomerular_filtration_rate_1_73_sq",
                  sheet="labs", display="Glomerular filtration rate/1.73 sq M.predicted", unit=""),
    ColumnMapping(code="69453-9", system=LOINC, column_name="cause_of_death",
                  sheet="labs", display="Cause of Death [US Standard Certificate of Death]", unit=""),
    ColumnMapping(code="704-7", system=LOINC, column_name="basophils",
                  sheet="labs", display="Basophils [#/volume] in Blood by Automated count", unit=""),
    ColumnMapping(code="706-2", system=LOINC, column_name="basophils_100_leukocytes",
                  sheet="labs", display="Basophils/100 leukocytes in Blood by Automated count", unit=""),
    ColumnMapping(code="711-2", system=LOINC, column_name="eosinophils",
                  sheet="labs", display="Eosinophils [#/volume] in Blood by Automated count", unit=""),
    ColumnMapping(code="713-8", system=LOINC, column_name="eosinophils_100_leukocytes",
                  sheet="labs", display="Eosinophils/100 leukocytes in Blood by Automated count", unit=""),
    ColumnMapping(code="718-7", system=LOINC, column_name="hemoglobin_g_dl",
                  sheet="labs", display="Hemoglobin [Mass/volume] in Blood", unit="g/dL"),
    ColumnMapping(code="71802-3", system=LOINC, column_name="housing_status",
                  sheet="labs", display="Housing status", unit=""),
    ColumnMapping(code="7258-7", system=LOINC, column_name="cow_milk_ige_ku_l",
                  sheet="labs", display="Cow milk IgE Ab in Serum", unit="kU/L"),
    ColumnMapping(code="731-0", system=LOINC, column_name="lymphocytes",
                  sheet="labs", display="Lymphocytes [#/volume] in Blood by Automated count", unit=""),
    ColumnMapping(code="736-9", system=LOINC, column_name="lymphocytes_100_leukocytes",
                  sheet="labs", display="Lymphocytes/100 leukocytes in Blood by Automated count", unit=""),
    ColumnMapping(code="73708-0", system=LOINC, column_name="body_fat_calculated",
                  sheet="labs", display="Body fat [Mass] Calculated", unit=""),
    ColumnMapping(code="742-7", system=LOINC, column_name="monocytes",
                  sheet="labs", display="Monocytes [#/volume] in Blood by Automated count", unit=""),
    ColumnMapping(code="751-8", system=LOINC, column_name="neutrophils",
                  sheet="labs", display="Neutrophils [#/volume] in Blood by Automated count", unit=""),
    ColumnMapping(code="76690-7", system=LOINC, column_name="sexual_orientation",
                  sheet="labs", display="Sexual orientation", unit=""),
    ColumnMapping(code="770-8", system=LOINC, column_name="neutrophils_100_leukocytes",
                  sheet="labs", display="Neutrophils/100 leukocytes in Blood by Automated count", unit=""),
    ColumnMapping(code="777-3", system=LOINC, column_name="platelets_k_ul",
                  sheet="labs", display="Platelets [#/volume] in Blood by Automated count", unit="K/uL"),
    ColumnMapping(code="785-6", system=LOINC, column_name="mch_pg",
                  sheet="labs", display="MCH [Entitic mass] by Automated count", unit="pg"),
    ColumnMapping(code="786-4", system=LOINC, column_name="mchc_g_dl",
                  sheet="labs", display="MCHC [Mass/volume] by Automated count", unit="g/dL"),
    ColumnMapping(code="787-2", system=LOINC, column_name="mcv_fl",
                  sheet="labs", display="MCV [Entitic volume] by Automated count", unit="fL"),
    ColumnMapping(code="788-0", system=LOINC, column_name="rdw_pct",
                  sheet="labs", display="Rdw Pct", unit="%"),
    ColumnMapping(code="789-8", system=LOINC, column_name="rbc_m_ul",
                  sheet="labs", display="Erythrocytes [#/volume] in Blood by Automated count", unit="M/uL"),
    ColumnMapping(code="80382-5", system=LOINC, column_name="influenza_virus_a_ag",
                  sheet="labs", display="Influenza virus A Ag [Presence] in Nasopharynx by Rapid immunoassay", unit=""),
    ColumnMapping(code="80383-3", system=LOINC, column_name="influenza_virus_b_ag",
                  sheet="labs", display="Influenza virus B Ag [Presence] in Nasopharynx by Rapid immunoassay", unit=""),
    ColumnMapping(code="81663-7", system=LOINC, column_name="diet",
                  sheet="labs", display="Diet [Type]", unit=""),
    ColumnMapping(code="8665-2", system=LOINC, column_name="last_menstrual_period_start_date",
                  sheet="labs", display="Last menstrual period start date", unit=""),
    ColumnMapping(code="8699-1", system=LOINC, column_name="physical_findings_of_eye_nominal",
                  sheet="labs", display="Physical Findings of Eye (Nominal)", unit=""),
    ColumnMapping(code="8999-5", system=LOINC, column_name="fluid_intake_oral_estimated",
                  sheet="labs", display="Fluid intake oral Estimated", unit=""),
    ColumnMapping(code="9052-2", system=LOINC, column_name="calorie_intake_total",
                  sheet="labs", display="Calorie intake total", unit=""),
    ColumnMapping(code="92130-4", system=LOINC, column_name="rhinovirus_rna",
                  sheet="labs", display="Rhinovirus RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92131-2", system=LOINC, column_name="respiratory_syncytial_virus_rna",
                  sheet="labs", display="Respiratory syncytial virus RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92134-6", system=LOINC, column_name="human_metapneumovirus_rna",
                  sheet="labs", display="Human metapneumovirus RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92138-7", system=LOINC, column_name="parainfluenza_virus_3_rna",
                  sheet="labs", display="Parainfluenza virus 3 RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92139-5", system=LOINC, column_name="parainfluenza_virus_2_rna",
                  sheet="labs", display="Parainfluenza virus 2 RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92140-3", system=LOINC, column_name="parainfluenza_virus_1_rna",
                  sheet="labs", display="Parainfluenza virus 1 RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92141-1", system=LOINC, column_name="influenza_virus_b_rna",
                  sheet="labs", display="Influenza virus B RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="92142-9", system=LOINC, column_name="influenza_virus_a_rna",
                  sheet="labs", display="Influenza virus A RNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="93832-4", system=LOINC, column_name="sleep_duration",
                  sheet="labs", display="Sleep duration", unit=""),
    ColumnMapping(code="94040-3", system=LOINC, column_name="adenovirus_a_b_c_d_e",
                  sheet="labs", display="Adenovirus A+B+C+D+E DNA [Presence] in Respiratory specimen by NAA with probe detection", unit=""),
    ColumnMapping(code="94531-1", system=LOINC, column_name="sars_cov_2_rna_pnl_resp",
                  sheet="labs", display="SARS-CoV-2 RNA Pnl Resp NAA+probe", unit=""),
]

# Singleton instance
_registry = Registry()

# Module-level convenience functions
add = _registry.add
lookup_code = _registry.lookup_code
lookup_column = _registry.lookup_column
list = _registry.list
load = _registry.load
