# stefanotrv/simple_icd_10_cm architecture

> Architecture diagram of the GitHub repository stefanotrv/simple_icd_10_cm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stefanotrv/simple_icd_10_cm
- Repository: https://github.com/stefanotrv/simple_icd_10_cm

## Overview

##### Project Type and Purpose
- Type: Stand-alone Python library / CLI tool
- Purpose: Load ICD-10-CM classification data (XML + TXT), build an in-memory classification tree, and expose helper functions (e.g., `is_valid_item`, `get_ancestors`, `get_full_data`, etc.).
- Key indicators:
– `simple_icd_10_cm.py` as the single-file source version
– `data/` directory with raw ICD files
– `package-files/` containing `setup.py`, `build/`, `dist/` for pip/conda distribution
– A test script `test_simple_icd_10_cm.py` and a Jupyter notebook for demos

##### File Structure
Top level:
- `.gitattributes`, `LICENSE`, `README.md`, `Instructional Notations.md`, `_config.yml`
- `data/`
– raw data: `icd10cm-order-Jan-2021.txt`, `icd10cm_tabular_2021.xml`
- `simple_icd_10_cm.py` (single-file entry point alternative)
- `test_simple_icd_10_cm.py` (unit tests)
- `Showcase notebook.ipynb` (demo)
- `package-files/` (distribution scaffolding)
– `setup.py`, built artifacts, source tree under `simple_icd_10_CM/`

##### README for Additional Insights
- No external services or databases—everything is file-based.
- Core functionality: load data, build classification tree, offer tree-traversal and metadata lookups.
- Packaging: supports pip/conda install, or raw-file usage.

##### Main Components & Interactions
a. Data Layer
– **Raw Data Files** (XML + TXT) stored under `data/`
– **Data Loader** code in `simple_icd_10_cm.py` (and its package equivalent) that parses XML, reads TXT, and constructs in-memory structures (nodes for chapters, blocks, categories, subcategories)

b. Core Logic / API Layer
– **Classification Tree**: internal representation (e.g., dictionaries or objects linking parent/child relationships)
– **API Functions**: all functions listed in README (`is_valid_item()`, `get_children()`, `get_full_data()`, etc.) that operate on the in-memory model

c. Test & Demo
– **Unit Tests** in `test_simple_icd_10_cm.py` exercising the API
– **Showcase Notebook** for interactive demonstration

d. Packaging / Distribution
– **package-files/setup.py** configures build
– **build/** and **dist/** directories containing `.whl` and `.tar.gz` artifacts
– **Publishing**: `pip install simple-icd-10-cm` or `conda install -c stefanotrv simple_icd_10_cm`

e. Consumer / Runtime Environment
– A Python interpreter (`py3`)
– Optionally Jupyter (for the notebook)
– `execute_unit_test.cmd` on Windows to run tests

##### Architectural Patterns & Principles
- **Single-process in-memory model**—no external services
- **Module + Data separation**—clear boundary between raw data files and code that loads them
- **API-first design**—all functionality exposed through well-named functions
- **Packaging pipeline**—source package → build → distribution

##### Essential Elements
- **Clear component labels**: Data files, Parser, In-memory model, API functions, Tests, Notebook, Packaging

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Files"
        Raw1["icd10cm-order-Jan-2021.txt"]:::data
        Raw2["icd10cm_tabular_2021.xml"]:::data
    end

    subgraph "Source Code"
        Parser["simple_icd_10_cm.py (Loader & Core API)"]:::parser
    end

    Raw1 -->|"reads"| Parser
    Raw2 -->|"reads"| Parser

    Parser -->|"builds in-memory tree"| Model["In-Memory Model"]:::api
    Model -->|"exposes API"| API["API Functions"]:::api

    subgraph "Testing & Demo"
        Tests["test_simple_icd_10_cm.py"]:::tests
        Notebook["Showcase notebook.ipynb"]:::tests
        Runner["execute_unit_test.cmd"]:::tests
    end

    API -.->|"calls"| Tests
    API -.->|"calls"| Notebook
    Tests -->|"runs via"| Runner

    subgraph "Packaging Pipeline"
        Setup["setup.py"]:::packaging
        BuildLib["build/lib/simple_icd_10_CM"]:::packaging
        subgraph "Packaged Source"
            PackParser["simple_icd_10_CM/simple_icd_10_cm.py"]:::parser
            PackData1["data/icd10cm-order-Jan-2021.txt"]:::data
            PackData2["data/icd10cm_tabular_2021.xml"]:::data
        end
        DistW["simple_icd_10_cm-1.2.0-py3-none-any.whl"]:::artifacts
        DistT["simple_icd_10_cm-1.2.0.tar.gz"]:::artifacts
    end

    Parser -->|"packaged into"| BuildLib
    Model -->|"includes data files"| BuildLib
    Setup -->|"configures"| BuildLib
    BuildLib --> PackParser
    BuildLib --> PackData1
    BuildLib --> PackData2
    BuildLib -->|"generates"| DistW
    BuildLib -->|"generates"| DistT

    subgraph "Consumer"
        Consumer["Python App / REPL"]:::consumer
    end

    DistW -->|"install"| Consumer
    DistT -->|"install"| Consumer

    click Raw1 "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/data/icd10cm-order-Jan-2021.txt"
    click Raw2 "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/data/icd10cm_tabular_2021.xml"
    click Parser "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/simple_icd_10_cm.py"
    click PackParser "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/simple_icd_10_CM/simple_icd_10_cm.py"
    click PackData1 "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/simple_icd_10_CM/data/icd10cm-order-Jan-2021.txt"
    click PackData2 "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/simple_icd_10_CM/data/icd10cm_tabular_2021.xml"
    click Tests "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/test_simple_icd_10_cm.py"
    click Notebook "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/Showcase notebook.ipynb"
    click Runner "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/execute_unit_test.cmd"
    click Setup "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/setup.py"
    click BuildLib "https://github.com/stefanotrv/simple_icd_10_cm/tree/master/package-files/build/lib/simple_icd_10_CM/"
    click DistW "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/dist/simple_icd_10_cm-1.2.0-py3-none-any.whl"
    click DistT "https://github.com/stefanotrv/simple_icd_10_cm/blob/master/package-files/dist/simple_icd_10_cm-1.2.0.tar.gz"

    classDef data fill:#bbdefb,stroke:#1e88e5;
    classDef parser fill:#c8e6c9,stroke:#388e3c;
    classDef api fill:#e8f5e9,stroke:#66bb6a;
    classDef tests fill:#ffe0b2,stroke:#fb8c00;
    classDef packaging fill:#e1bee7,stroke:#8e24aa;
    classDef artifacts fill:#ce93d8,stroke:#7e57c2;
    classDef consumer fill:#f5f5f5,stroke:#9e9e9e;
```
