Unstructured Medical Text Miner (ID: 213)
When to Use
- - Use this skill when the task needs Mine unstructured clinical text from MIMIC-IV to extract diagnostic logic.
- Use this skill for evidence insight tasks that require explicit assumptions, bounded scope, and a reproducible output format.
- Use this skill when you need a documented fallback path for missing inputs, execution errors, or partial evidence.
Key Features
See ## Features above for related details.
- - Scope-focused workflow aligned to: Mine unstructured clinical text from MIMIC-IV to extract diagnostic logic.
- Packaged executable path(s):
scripts/__init__.py plus 1 additional script(s). - Reference material available in
references/ for task-specific guidance. - Structured execution path designed to keep outputs consistent and reviewable.
Dependencies
CODEBLOCK0
Example Usage
See ## Usage above for related details.
CODEBLOCK1
Example run plan:
- 1. Confirm the user input, output path, and any required config values.
- Edit the in-file
CONFIG block or documented parameters if the script uses fixed settings. - Run
python scripts/main.py with the validated inputs. - Review the generated output and return the final artifact with any assumptions called out.
Implementation Details
See ## Workflow above for related details.
- - Execution model: validate the request, choose the packaged workflow, and produce a bounded deliverable.
- Input controls: confirm the source files, scope limits, output format, and acceptance criteria before running any script.
- Primary implementation surface:
scripts/__init__.py with additional helper scripts under scripts/. - Reference guidance:
references/ contains supporting rules, prompts, or checklists. - Parameters to clarify first: input path, output path, scope filters, thresholds, and any domain-specific constraints.
- Output discipline: keep results reproducible, identify assumptions explicitly, and avoid undocumented side effects.
Quick Check
Use this command to verify that the packaged script entry point can be parsed before deeper execution.
CODEBLOCK2
Audit-Ready Commands
Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
CODEBLOCK3
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.
Overview
Mine "text data" that has been long overlooked in MIMIC-IV, extracting unstructured diagnostic logic, order details, and progress notes.
Purpose
The MIMIC-IV database contains large amounts of structured data (vital signs, laboratory results, etc.), but its true clinical value is often hidden in unstructured text:
- - Diagnostic reasoning chains in discharge summaries
- Subtle finding descriptions in imaging reports
- Treatment decision logic in progress notes
- Personalized medication considerations in orders
This Skill provides a complete text mining toolchain to transform raw medical text into analyzable structured insights.
Features
1. Text Extraction
- - NOTEEVENTS: Extract clinical notes from MIMIC-IV NOTE module
- Radiology Reports: Extract imaging diagnostic text
- ECG Reports: Parse ECG interpretation text
- Discharge Summaries: Extract complete diagnostic and treatment course
2. Information Extraction
- - Entity Recognition: Diseases, symptoms, medications, procedures, anatomical sites
- Relation Extraction: Medication-disease treatment relationships, symptom-disease diagnostic relationships
- Timeline Extraction: Event occurrence times, disease progression sequence
- Negation Detection: Identify negated clinical findings (e.g., "no fever")
3. Clinical Logic Parsing
- - Diagnostic Reasoning Chain: Reasoning path from symptoms → examination → diagnosis
- Treatment Decision Tree: Clinical basis for medication selection and dosage adjustment
- Disease Progression: Disease progression and outcome descriptions
4. Structured Output
- - FHIR-compatible clinical document format
- Knowledge graph-friendly triple format
- Temporal event sequences
Usage
CODEBLOCK4
Input
Data Sources
- - MIMIC-IV NOTEEVENTS table (csv/parquet format)
- Discharge summary files
- Imaging report files
- Custom medical text
Field Requirements
| Field Name | Description | Required |
|---|
| subjectid | Patient unique identifier | Yes |
| hadmid |
Hospital admission record identifier | No |
| note_type | Note type (DS/RR/ECG, etc.) | Yes |
| note_text | Note text content | Yes |
| charttime | Record time | No |
Output
Entity Extraction Results
CODEBLOCK5
Clinical Logic Graph
CODEBLOCK6
Temporal Events
CODEBLOCK7
Configuration
CODEBLOCK8
CLI Usage
CODEBLOCK9
References
- 1. MIMIC-IV Clinical Database: https://physionet.org/content/mimiciv/
- scispacy: https://allenai.github.io/scispacy/
- NegEx/negspacy for negation detection
- FHIR Clinical Document specifications
Author
Skill ID: 213
Category: Medical Data Mining
Complexity: Advanced
Risk Assessment
| Risk Indicator | Assessment | Level |
|---|
| Code Execution | Python/R scripts executed locally | Medium |
| Network Access |
No external API calls | Low |
| File System Access | Read input files, write output files | Medium |
| Instruction Tampering | Standard prompt guidelines | Low |
| Data Exposure | Output files saved to workspace | Low |
Security Checklist
- - [ ] No hardcoded credentials or API keys
- [ ] No unauthorized file system access (../)
- [ ] Output does not expose sensitive information
- [ ] Prompt injection protections in place
- [ ] Input file paths validated (no ../ traversal)
- [ ] Output directory restricted to workspace
- [ ] Script execution in sandboxed environment
- [ ] Error messages sanitized (no stack traces exposed)
- [ ] Dependencies audited
Prerequisites
CODEBLOCK10
Evaluation Criteria
Success Metrics
- - [ ] Successfully executes main functionality
- [ ] Output meets quality standards
- [ ] Handles edge cases gracefully
- [ ] Performance is acceptable
Test Cases
- 1. Basic Functionality: Standard input → Expected output
- Edge Case: Invalid input → Graceful error handling
- Performance: Large dataset → Acceptable processing time
Output Requirements
Every final response should make these items explicit when they are relevant:
- - Objective or requested deliverable
- Inputs used and assumptions introduced
- Workflow or decision path
- Core result, recommendation, or artifact
- Constraints, risks, caveats, or validation needs
- Unresolved items and next-step checks
Error Handling
- - If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
- 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, summarize what still can be completed safely, and provide a manual fallback. - Do not fabricate files, citations, data, search results, or execution outcomes.
Input Validation
This skill accepts requests that match the documented purpose of unstructured-medical-text-miner and include enough context to complete the workflow safely.
Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
INLINECODE12 only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
References
Response Template
Use the following fixed structure for non-trivial requests:
- 1. Objective
- Inputs Received
- Assumptions
- Workflow
- Deliverable
- Risks and Limits
- Next Checks
If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
非结构化医学文本挖掘器(ID:213)
使用时机
- - 当任务需要挖掘MIMIC-IV中的非结构化临床文本来提取诊断逻辑时使用此技能。
- 用于需要明确假设、限定范围和可重复输出格式的证据洞察任务。
- 当需要为缺失输入、执行错误或部分证据提供有文档记录的备用路径时使用此技能。
主要特性
相关详情请参见上方## 特性部分。
- - 范围聚焦的工作流程,针对:挖掘MIMIC-IV中的非结构化临床文本来提取诊断逻辑。
- 打包的可执行路径:scripts/init.py 外加1个附加脚本。
- references/目录中提供参考资料,用于任务特定指导。
- 结构化执行路径,旨在保持输出一致且可审查。
依赖项
pandas>=1.3.0
spacy>=3.4.0
scispacy>=0.5.1
radlex(用于放射学术语)
negspacy(用于否定检测)
使用示例
相关详情请参见上方## 用法部分。
bash
cd 20260318/scientific-skills/Evidence Insight/unstructured-medical-text-miner
python -m py_compile scripts/main.py
python scripts/main.py --help
示例运行计划:
- 1. 确认用户输入、输出路径以及任何必需的配置值。
- 如果脚本使用固定设置,编辑文件内的CONFIG块或文档化参数。
- 使用验证后的输入运行python scripts/main.py。
- 审查生成的输出,并返回最终产物,同时注明任何假设。
实现细节
相关详情请参见上方## 工作流程部分。
- - 执行模型:验证请求,选择打包的工作流程,并生成限定范围的可交付成果。
- 输入控制:在运行任何脚本之前,确认源文件、范围限制、输出格式和验收标准。
- 主要实现界面:scripts/init.py,scripts/下包含额外的辅助脚本。
- 参考指南:references/包含支持规则、提示或检查清单。
- 需优先明确的参数:输入路径、输出路径、范围过滤器、阈值以及任何领域特定约束。
- 输出规范:保持结果可重复,明确标识假设,避免未文档化的副作用。
快速检查
在深入执行之前,使用此命令验证打包脚本入口点是否可解析。
bash
python -m py_compile scripts/main.py
审计就绪命令
使用这些具体命令进行验证。它们特意设计为自包含,避免使用占位符路径。
bash
python -m py_compile scripts/main.py
python scripts/main.py --help
python scripts/main.py -h
工作流程
- 1. 在进行详细工作之前,确认用户目标、必需输入和不可协商的约束条件。
- 验证请求是否与文档化范围匹配,如果任务需要不支持的假设,则尽早停止。
- 仅使用实际可用的输入,使用打包脚本路径或文档化的推理路径。
- 返回结构化结果,将假设、可交付成果、风险和未解决事项分开。
- 如果执行失败或输入不完整,切换到备用路径,并明确说明阻止完整完成的具体原因。
概述
挖掘MIMIC-IV中长期被忽视的文本数据,提取非结构化的诊断逻辑、医嘱详情和病程记录。
目的
MIMIC-IV数据库包含大量结构化数据(生命体征、实验室结果等),但其真正的临床价值往往隐藏在非结构化文本中:
- - 出院小结中的诊断推理链
- 影像报告中的细微发现描述
- 病程记录中的治疗决策逻辑
- 医嘱中的个性化用药考量
本技能提供完整的文本挖掘工具链,将原始医学文本转化为可分析的结构化洞察。
特性
1. 文本提取
- - NOTEEVENTS:从MIMIC-IV NOTE模块提取临床记录
- 放射报告:提取影像诊断文本
- 心电图报告:解析心电图解读文本
- 出院小结:提取完整的诊断和治疗过程
2. 信息提取
- - 实体识别:疾病、症状、药物、手术、解剖部位
- 关系提取:药物-疾病治疗关系、症状-疾病诊断关系
- 时间线提取:事件发生时间、疾病进展序列
- 否定检测:识别否定的临床发现(例如无发热)
3. 临床逻辑解析
- - 诊断推理链:从症状→检查→诊断的推理路径
- 治疗决策树:药物选择和剂量调整的临床依据
- 疾病进展:疾病进展和结果描述
4. 结构化输出
- - FHIR兼容的临床文档格式
- 知识图谱友好的三元组格式
- 时间事件序列
用法
python
from skills.unstructuredmedicaltext_miner.scripts.main import MedicalTextMiner
初始化挖掘器
miner = MedicalTextMiner()
加载MIMIC-IV记录数据
miner.load
notes(notespath=path/to/noteevents.csv)
提取特定患者的所有文本记录
patient
texts = miner.getpatient
texts(subjectid=10000032)
执行完整信息提取
insights = miner.extract_insights(
text=patient_texts,
extract_entities=True,
extract_relations=True,
extract_timeline=True
)
输入
数据源
- - MIMIC-IV NOTEEVENTS表(csv/parquet格式)
- 出院小结文件
- 影像报告文件
- 自定义医学文本
字段要求
| 字段名 | 描述 | 必需 |
|---|
| subjectid | 患者唯一标识符 | 是 |
| hadmid |
住院记录标识符 | 否 |
| note_type | 记录类型(DS/RR/ECG等) | 是 |
| note_text | 记录文本内容 | 是 |
| charttime | 记录时间 | 否 |
输出
实体提取结果
json
{
entities: [
{
text: 急性心肌梗死,
type: DISEASE,
start: 156,
end: 183,
confidence: 0.94
},
{
text: 阿司匹林81mg,
type: MEDICATION,
start: 245,
end: 257,
attributes: {
dose: 81mg,
frequency: 每日一次
}
}
]
}
临床逻辑图
json
{
clinical_logic: {
presenting_complaint: 胸痛,
differential_diagnoses: [ACS, PE, 主动脉夹层],
workup: [心电图, 肌钙蛋白, 胸部CTA],
final_diagnosis: STEMI,
treatment_plan: [PCI, 双联抗血小板]
}
}
时间事件
json
{
timeline: [
{
time: 2020-03-15 08:30,
event: 入院,
description: 表现为胸痛
},
{
time: 2020-03-15 09:15,
event: 心电图,
description: V1-V4导联ST段抬高
}
]
}
配置
yaml
config.yaml
extraction:
entity_types: [DISEASE, SYMPTOM, MEDICATION, PROCEDURE, ANATOMY]
relation
types: [TREATS, CAUSES, CONTRAINDICATEDWITH]
enable
negationdetection: true
models:
nermodel: encorescilg # 或 encoresci_scibert
relationmodel: customrelation_extractor
output:
format: json # json/fhir/kg
includerawtext: false
CLI用法
text
处理单个文件
python -m skills.unstructured
medicaltext_miner.scripts.main \
--input notes.csv \
--output extracted.json \
--extract all
处理特定患者
python -m skills.unstructured
medicaltext_miner.scripts.main \
--subject-id 10000032 \
--db-path mimic_iv.db \
--output patient_insights.json
参考文献
- 1. MIMIC-IV临床数据库:https://physionet.org/content/mimiciv/
- scispacy:https://allenai.github.io/scispacy/
- 用于否定检测的NegEx/negspacy
- FHIR临床文档规范
作者
技能ID:213
类别:医学数据挖掘
复杂度:高级
风险评估
Python/R脚本在