# umessen/fhir-pyrate architecture

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

- Interactive diagram: https://gitdiagram.com/umessen/fhir-pyrate
- Repository: https://github.com/umessen/fhir-pyrate

## Overview

##### Main Components

a. Core Components:
- Authentication Module (Ahoy)
- FHIR Query Engine (Pirate)
- Text Mining Module (Miner)
- DICOM Download Module (DicomDownloader)
- Utility Components (under fhir_pyrate/util)

b. External Systems:
- FHIR Server
- DICOM Web Adapter/PACS System
- Authentication Server

##### Component Relationships

**[Authentication Server] <---> [Ahoy Module]**
- ^                      |
- v
**[FHIR Server] <-------------> [Pirate Module] <---> [Pandas DataFrame]**
- ^                      ^

**[DICOM Web/PACS] <------> [DicomDownloader]**

**[Pandas DataFrame] <---> [Miner Module]**

##### Detailed Component Descriptions

a. Ahoy Module:
- Input: Authentication credentials (username/password/token)
- Output: Authentication token
- Supported methods: password, token, environment variables
- Connection to authentication server

b. Pirate Module:
- Input: FHIR queries, authentication token
- Output: FHIR bundles, pandas DataFrames
- Key features:
- Multiprocessing support
- Bundle caching
- FHIRPath processing
- Multiple resource handling

c. Miner Module:
- Input: DataFrame with text data
- Output: Filtered/processed DataFrame
- Features: RegEx search, SpaCy integration
- Text processing capabilities

d. DicomDownloader:
- Input: Study/Series UIDs
- Output: DICOM/NIfTI files
- Connection to DICOM Web Adapter
- Download management and error handling

##### Important Implementation Details
- Multiprocessing capabilities
- Caching mechanisms
- Authentication flow
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Systems"]
        AuthServer[Authentication Server]
        FHIRServer[FHIR Server]
        PACS["DICOM Web/PACS"]
    end

    subgraph Core["Core Components"]
        Ahoy["Authentication Module (Ahoy)"]:::auth
        Pirate["FHIR Query Engine (Pirate)"]:::core
        Miner["Text Mining Module (Miner)"]:::core
        DicomDL["DICOM Download Module"]:::core
    end

    subgraph Utils["Utility Components"]
        BundleProc["Bundle Processing"]:::util
        FHIRObj["FHIR Object Handler"]:::util
        TokenAuth["Token Authentication"]:::util
        GenUtils["General Utilities"]:::util
    end

    subgraph Data["Data Layer"]
        DataFrame["Pandas DataFrame"]:::data
        Cache["Bundle Cache"]:::data
    end

    subgraph Examples["Example Implementations"]
        Ex1["Simple JSON to DataFrame"]:::example
        Ex2["Condition to Imaging Study"]:::example
        Ex3["Observation for Condition"]:::example
        Ex4["Patient Diagnostic Reports"]:::example
    end

    AuthServer <--> Ahoy
    FHIRServer <--> Pirate
    PACS <--> DicomDL

    Ahoy --> Pirate
    Pirate <--> DataFrame
    Pirate <--> Cache
    DataFrame <--> Miner
    
    Pirate --> BundleProc
    Pirate --> FHIRObj
    Ahoy --> TokenAuth
    Pirate --> GenUtils

    DataFrame --> Ex1
    DataFrame --> Ex2
    DataFrame --> Ex3
    DataFrame --> Ex4

    classDef auth fill:#90EE90
    classDef core fill:#87CEEB
    classDef util fill:#D3D3D3
    classDef data fill:#DDA0DD
    classDef external fill:#FFA500
    classDef example fill:#FFE4B5

    click Ahoy "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/ahoy.py"
    click Pirate "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/pirate.py"
    click Miner "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/miner.py"
    click DicomDL "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/dicom_downloader.py"
    click BundleProc "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/util/bundle_processing_templates.py"
    click FHIRObj "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/util/fhirobj.py"
    click TokenAuth "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/util/token_auth.py"
    click GenUtils "https://github.com/UMEssen/FHIR-PYrate/blob/main/fhir_pyrate/util/util.py"
    click Ex1 "https://github.com/UMEssen/FHIR-PYrate/blob/main/examples/1-simple-json-to-df.ipynb"
    click Ex2 "https://github.com/UMEssen/FHIR-PYrate/blob/main/examples/2-condition-to-imaging-study.ipynb"
    click Ex3 "https://github.com/UMEssen/FHIR-PYrate/blob/main/examples/3-observation-for-condition.ipynb"
    click Ex4 "https://github.com/UMEssen/FHIR-PYrate/blob/main/examples/4-patients-for-diagnostic-report.ipynb"
```
