Clinical lab unit harmonization

From XuShuwenn/RedAct · View interactive version

Clinical lab unit harmonization is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Standardize multi-source clinical lab CSVs by normalizing numeric formats, dropping incomplete rows, converting alternate units into target US conventional units using physiological ranges, and writing values as X.XX.

How to use this skill

Skill file

Clinical Lab Unit Harmonization

This skill provides a robust workflow to harmonize clinical laboratory datasets sourced from multiple systems that may use mixed numeric formats and measurement units. It cleans numeric strings (including scientific notation and decimal commas), removes incomplete records, converts alternate units into target US conventional units based on physiological ranges, and writes all numeric values in exactly two-decimal X.XX format while preserving IDs and column structure.

When to Use

Activate this skill when you have a tabular clinical lab dataset that:

Core Workflow

  1. Inspect Inputs
  1. Define Target Units and Physiological Ranges
  1. Drop Incomplete Rows
  1. Normalize Numeric Text
  1. Range-Guided Unit Conversion
  1. Formatting and Output

Configuration Schema (JSON)

Provide a JSON file to guide conversions. Example structure (illustrative only; replace with actual features and units you expect):

{

"columns": {

"CREAT": {

"target_unit": "mg/dL",

"target_range": [0.4, 12.0],

"alternates": [

{"src_unit": "umol/L", "factor": 0.0113, "src_range": [20, 2000]}

]

},

"HGB": {

"target_unit": "g/dL",

"target_range": [5.0, 20.0],

"alternates": [

{"src_unit": "g/L", "factor": 0.1, "src_range": [50, 250]}

]

}

}

}

Notes:

Verification

Perform these checks on the output:

You can use the provided validator script to check formatting and ranges.

Common Pitfalls and How to Avoid Them

Optional Script Usage

1) Harmonize a dataset

Example:

--input /path/to/input.csv \

--output /path/to/output.csv \

--config /path/to/conversions.json \

--id-columns patient_id \

--tol-pct 0.02

Behavior:

2) Validate output formatting and ranges

Example:

--input /path/to/output.csv \

--config /path/to/conversions.json \

--id-columns patient_id

The validator prints any issues and exits non-zero if problems are found.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.