---
title: "Introduction to ciecl: Chilean ICD-10 in R"
author: "Rodolfo Tasso Suazo"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to ciecl: Chilean ICD-10 in R}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 5
)
library(ciecl)
```

> **Version 0.9.3**: Available on CRAN with SQLite optimizations and XLSX support.

## About the dataset

The package includes **39,877 ICD-10 codes** from the official MINSAL/DEIS v2018 catalog,
including categories (3 digits) and subcategories (4+ digits).

## Installation

```{r eval=FALSE}
# From GitHub (beta version)
pak::pak("RodoTasso/ciecl")

# Alternative with devtools
devtools::install_github("RodoTasso/ciecl")
```

## Fast SQL search

```{r}
# All type 2 diabetes codes
cie10_sql("SELECT codigo, descripcion FROM cie10 WHERE codigo LIKE 'E11%' LIMIT 5")
```

## Search by code

```{r}
# Single code search
cie_lookup("E11.0")

# Vectorized search - multiple codes at once
codes <- c("E11.0", "I10", "Z00", "J44.0")
cie_lookup(codes)

# Hierarchical expansion
cie_lookup("E11", expandir = TRUE)
```

## Fuzzy search with typos

```{r}
# Finds even if misspelled
cie_search("diabetis with coma", threshold = 0.75)
```

## Charlson Comorbidities

```{r eval=FALSE}
# Requires: install.packages("comorbidity")
patient_df <- data.frame(
  patient_id = c(1, 1, 2, 2, 3),
  diagnosis = c("E11.0", "I50.9", "C50.9", "N18.5", "J44.0")
)

cie_comorbid(patient_df, id = "patient_id", code = "diagnosis", map = "charlson")
```

## Interactive tables

```{r eval=FALSE}
# Requires: install.packages("gt")
cie_table("E11")  # Full GT visualization
```

## Data source

Official ICD-10 Chile data MINSAL/DEIS v2018:

- FIC Chile Center: <https://deis.minsal.cl/centrofic/>
- DEIS Repository: <https://deis.minsal.cl>

## More information

- Report issues: <https://github.com/RodoTasso/ciecl/issues>
- Repository: <https://github.com/RodoTasso/ciecl>
