Medical Unit Converter
Convert laboratory values between clinical units with formula transparency and reference range context. Supports glucose, cholesterol, creatinine, and hemoglobin.
When to Use
- - Converting glucose, cholesterol, creatinine, or hemoglobin lab values between unit systems
- Verifying unit conversions for clinical documentation or research
- Batch-converting lab result tables between mg/dL and mmol/L conventions
- Providing reference ranges alongside converted values
Workflow
- 1. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
- Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
- Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
- Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
- If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
Supported Conversions
| Analyte | From | To | Factor | Reference Range (target unit) |
|---|
| Glucose | mg/dL | mmol/L | 0.0555 | 3.9–5.6 mmol/L (fasting) |
| Glucose |
mmol/L | mg/dL | 18.018 | 70–100 mg/dL (fasting) |
| Cholesterol | mg/dL | mmol/L | 0.02586 | < 5.2 mmol/L (desirable) |
| Cholesterol | mmol/L | mg/dL | 38.67 | < 200 mg/dL (desirable) |
| Creatinine | mg/dL | μmol/L | 88.4 | 62–115 μmol/L (male) |
| Creatinine | μmol/L | mg/dL | 0.01131 | 0.7–1.3 mg/dL (male) |
| Hemoglobin | g/dL | g/L | 10 | 130–175 g/L (male) |
| Hemoglobin | g/L | g/dL | 0.1 | 13–17.5 g/dL (male) |
Input Parameters
| Parameter | Type | Required | Description |
|---|
| INLINECODE0 , INLINECODE1 | float | Yes | Numeric value to convert |
| INLINECODE2 |
str | Yes | Source unit (e.g.,
mg_dl,
mmol_l,
umol_l,
g_dl,
g_l) |
|
--to-unit | str | Yes | Target unit |
|
--analyte,
-a | str | No | Analyte name for reference range lookup (e.g.,
glucose,
cholesterol,
creatinine,
hemoglobin) |
Output Format
CODEBLOCK0
Quick Check
CODEBLOCK1
Implementation Notes (for script developer)
The script must:
- 1. Parse CLI args — use argparse with
--value, --from-unit, --to-unit, --analyte. Pass parsed args to conv.convert(). Do not hardcode demo values in main(). - CONVERSIONS dict — include all 8 conversion pairs above, each with
factor and reference_range fields. Keys must be (analyte, from_unit, to_unit) tuples or equivalent nested structure. - convert() method — return a dict with
converted_value, formula, from_unit, to_unit, analyte, reference_range. - Unsupported pair — if the unit pair is not in CONVERSIONS, print the supported conversions list and exit with code 1.
- Fallback Partial result — when an unsupported unit pair is requested, always populate the
Partial result field in the Fallback Template with: "Manual formula not available for this unit pair".
Input Validation
This skill accepts: numeric laboratory values with a source unit and target unit for conversion between recognized clinical measurement systems.
If the request does not involve converting a specific numeric lab value between units — for example, asking to interpret clinical results, diagnose conditions, or convert non-laboratory quantities — do not proceed. Instead respond:
"medical-unit-converter is designed to convert medical laboratory values between unit systems. Your request appears to be outside this scope. Please provide a numeric value with source and target units, or use a more appropriate tool for your task."
Error Handling
- - If
--value, --from-unit, or --to-unit is missing, state exactly which fields are missing and request only those. - If the unit pair is not supported, list the supported conversions and stop.
- If
--value is not a valid number, reject with: INLINECODE36 - If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
- If
scripts/main.py fails, report the failure point and provide the manual conversion formula as fallback. - Do not fabricate conversion factors or reference ranges.
Fallback Template
When execution fails or inputs are incomplete, respond with this structure:
CODEBLOCK2
Response Template
- 1. Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits
- Next Checks
Prerequisites
No additional Python packages required beyond the standard library.
医学单位转换器
在临床单位之间转换实验室数值,提供公式透明度和参考范围上下文。支持葡萄糖、胆固醇、肌酐和血红蛋白。
使用场景
- - 在单位系统之间转换葡萄糖、胆固醇、肌酐或血红蛋白的实验室数值
- 验证临床文档或研究中的单位转换
- 在mg/dL和mmol/L标准之间批量转换实验室结果表格
- 提供与转换值并行的参考范围
工作流程
- 1. 在进行详细工作前,确认用户目标、所需输入和不可协商的限制条件。
- 验证请求是否在文档规定的范围内,如果任务需要不支持的假设,则提前停止。
- 使用打包的脚本路径或文档化的推理路径,仅使用实际可用的输入。
- 返回结构化的结果,区分假设、交付物、风险和未解决项。
- 如果执行失败或输入不完整,切换到备用路径并明确指出阻止完整完成的原因。
支持的转换
| 分析物 | 从 | 到 | 系数 | 参考范围(目标单位) |
|---|
| 葡萄糖 | mg/dL | mmol/L | 0.0555 | 3.9–5.6 mmol/L(空腹) |
| 葡萄糖 |
mmol/L | mg/dL | 18.018 | 70–100 mg/dL(空腹) |
| 胆固醇 | mg/dL | mmol/L | 0.02586 | < 5.2 mmol/L(理想值) |
| 胆固醇 | mmol/L | mg/dL | 38.67 | < 200 mg/dL(理想值) |
| 肌酐 | mg/dL | μmol/L | 88.4 | 62–115 μmol/L(男性) |
| 肌酐 | μmol/L | mg/dL | 0.01131 | 0.7–1.3 mg/dL(男性) |
| 血红蛋白 | g/dL | g/L | 10 | 130–175 g/L(男性) |
| 血红蛋白 | g/L | g/dL | 0.1 | 13–17.5 g/dL(男性) |
输入参数
| 参数 | 类型 | 必需 | 描述 |
|---|
| --value, -v | 浮点数 | 是 | 要转换的数值 |
| --from-unit |
字符串 | 是 | 源单位(例如:mg
dl、mmoll、umol
l、gdl、g_l) |
| --to-unit | 字符串 | 是 | 目标单位 |
| --analyte, -a | 字符串 | 否 | 用于参考范围查询的分析物名称(例如:glucose、cholesterol、creatinine、hemoglobin) |
输出格式
json
{
converted_value: 5.55,
formula: 100 × 0.0555,
fromunit: mgdl,
tounit: mmoll,
analyte: glucose,
reference_range: 3.9–5.6 mmol/L(空腹血糖)
}
快速检查
bash
python -m py_compile scripts/main.py
python scripts/main.py --value 100 --from-unit mgdl --to-unit mmoll --analyte glucose
实现说明(供脚本开发者参考)
脚本必须:
- 1. 解析CLI参数 — 使用argparse处理--value、--from-unit、--to-unit、--analyte。将解析后的参数传递给conv.convert()。不要在main()中硬编码演示值。
- CONVERSIONS字典 — 包含上述所有8个转换对,每个转换对包含factor和referencerange字段。键必须为(analyte, fromunit, tounit)元组或等效的嵌套结构。
- convert()方法 — 返回包含convertedvalue、formula、fromunit、tounit、analyte、reference_range的字典。
- 不支持的转换对 — 如果单位对不在CONVERSIONS中,打印支持的转换列表并以退出码1退出。
- 备用部分结果 — 当请求不支持的转换对时,始终在备用模板的Partial result字段中填入:Manual formula not available for this unit pair。
输入验证
本技能接受:带有源单位和目标单位的数值型实验室值,用于在认可的临床测量系统之间进行转换。
如果请求不涉及在单位之间转换特定的数值型实验室值——例如,要求解读临床结果、诊断病情或转换非实验室数量——则不要继续。而是回复:
medical-unit-converter旨在在单位系统之间转换医学实验室数值。您的请求似乎超出了此范围。请提供带有源单位和目标单位的数值,或使用更适合您任务的工具。
错误处理
- - 如果缺少--value、--from-unit或--to-unit,明确指出缺少哪些字段,并仅请求这些字段。
- 如果不支持该单位对,列出支持的转换并停止。
- 如果--value不是有效数字,拒绝并返回:Error: --value must be a numeric value.
- 如果任务超出文档范围,停止而不是猜测或静默扩大任务范围。
- 如果scripts/main.py失败,报告失败点并提供手动转换公式作为备用。
- 不要编造转换系数或参考范围。
备用模板
当执行失败或输入不完整时,使用以下结构回复:
备用报告
───────────────────────────────────────
目标 : [重述转换目标]
阻塞原因 : [确切缺少的输入或错误]
部分结果 : [如果转换系数已知则提供手动公式;如果不支持该单位对则填写Manual formula not available for this unit pair]
下一步 : [解除阻塞所需的最小操作]
───────────────────────────────────────
回复模板
- 1. 目标
- 收到的输入
- 假设
- 工作流程
- 交付物
- 风险和限制
- 后续检查
前置条件
除标准库外,无需额外的Python包。