Source: https://github.com/aipoch/medical-research-skills
Clinical Data Cleaner
Clean, validate, and standardize clinical trial data to meet CDISC SDTM standards for regulatory submissions to FDA or EMA.
Quick Check
Use this command to verify that the packaged script entry point can be parsed before deeper execution.
python -m py_compile scripts/main.py
Audit-Ready Commands
Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
python -m py_compile scripts/main.py
python scripts/main.py --help
python scripts/main.py --input "Audit validation sample with explicit symptoms, history, assessment, and next-step plan."
When to Use
- Use this skill when the task needs Use when cleaning clinical trial data, preparing data for FDA/EMA submission, standardizing SDTM datasets, handling missing values in clinical studies, detecting outliers in lab results, or converting raw CRF data to CDISC format. Cleans and standardizes clinical trial data for regulatory compliance with audit trails.
- Use this skill for data analysis 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.
Workflow
- 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.
Quick Start
from scripts.main import ClinicalDataCleaner
# Initialize for Demographics domain
cleaner = ClinicalDataCleaner(domain='DM')
# Clean data with default settings
cleaned = cleaner.clean(raw_data)
# Save with audit trail
cleaner.save_report('output.csv')
Core Capabilities
1. SDTM Domain Validation
cleaner = ClinicalDataCleaner(domain='DM') # or 'LB', 'VS'
is_valid, missing = cleaner.validate_domain(data)
Required Fields:
- DM: STUDYID, USUBJID, SUBJID, RFSTDTC, RFENDTC, SITEID, AGE, SEX, RACE
- LB: STUDYID, USUBJID, LBTESTCD, LBCAT, LBORRES, LBORRESU, LBSTRESC, LBDTC
- VS: STUDYID, USUBJID, VSTESTCD, VSORRES, VSORRESU, VSSTRESC, VSDTC
2. Missing Value Handling
cleaner = ClinicalDataCleaner(
domain='DM',
missing_strategy='median' # mean, median, mode, forward, drop
)
cleaned = cleaner.handle_missing_values(data)
3. Outlier Detection
cleaner = ClinicalDataCleaner(
domain='LB',
outlier_method='domain', # iqr, zscore, domain
outlier_action='flag' # flag, remove, cap
)
flagged = cleaner.detect_outliers(data)
Clinical Thresholds:
| Parameter |
Range |
Unit |
| Glucose |
50-500 |
mg/dL |
| Hemoglobin |
5-20 |
g/dL |
| Systolic BP |
70-220 |
mmHg |
4. Date Standardization
standardized = cleaner.standardize_dates(data)
# Converts to ISO 8601: 2023-01-15T09:30:00
5. Complete Pipeline
cleaner = ClinicalDataCleaner(
domain='DM',
missing_strategy='median',
outlier_method='iqr',
outlier_action='flag'
)
cleaned_data = cleaner.clean(data)
cleaner.save_report('output.csv')
Output Files:
output.csv - Cleaned SDTM data
output.report.json - Audit trail for regulatory submission
CLI Usage
# Clean demographics
python scripts/main.py \
--input dm_raw.csv \
--domain DM \
--output dm_clean.csv \
--missing-strategy median \
--outlier-method iqr \
--outlier-action flag
# Clean lab data with clinical thresholds
python scripts/main.py \
--input lb_raw.csv \
--domain LB \
--output lb_clean.csv \
--outlier-method domain
Common Patterns
See references/common-patterns.md for detailed examples:
- Regulatory Submission Preparation
- Interim Analysis Data Preparation
- Database Migration Cleanup
- External Lab Data Integration
Troubleshooting
See references/troubleshooting.md for solutions to:
- Validation failures
- Date parsing errors
- Memory errors with large datasets
- Outlier detection issues
Quality Checklist
Pre-Cleaning:
Post-Cleaning:
References
references/sdtm_ig_guide.md - CDISC SDTM Implementation Guide
references/domain_specs.json - Domain-specific field requirements
references/outlier_thresholds.json - Clinical outlier thresholds
references/common-patterns.md - Detailed usage patterns
references/troubleshooting.md - Problem-solving guide
Skill ID: 189 | Version: 2.0 | License: MIT
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 clinical-data-cleaner 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:
clinical-data-cleaner only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
Response Template
Use the following fixed structure for non-trivial requests:
- 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.
When Not to Use
- Do not proceed when required input files, identifiers, parameters, or context are missing — ask the user to provide them first.
- Do not assume capabilities beyond this skill's declared scope when the user requests external operations or inferences.
- Do not proceed without user confirmation when overwriting existing results, executing high-cost batch operations, or expanding task scope.
Required Inputs
| Field |
Required |
Format/Source |
Example |
If Missing |
| User task description |
Yes |
Text |
Research question, writing goal, analysis objective |
Stop and ask user to provide |
| Primary input material |
Depends on task |
Text, file path, ID, table, or literature |
PMID, PDF, CSV, DOCX, keywords, etc. |
Specify which material type is missing |
| Output preference |
No |
Text |
Language, format, target journal, template |
Use skill default format |
Output Contract
- Primary output: Structured result or target file aligned with this skill's objective.
- Optional output: Intermediate check notes, issue list, supplementary suggestions, or generated file paths.
- Format requirement: Unless the user specifies otherwise, prefer stable, reviewable Markdown or JSON; if the skill's bundled script requires a fixed format, use that format.
- If partially complete: Must explicitly mark as PARTIAL and state which steps are completed and which remain.
Failure Handling
- Missing critical input: Explicitly state which fields, files, or identifiers are missing and pause.
- Script, template, or resource execution failure: Report the failing step, likely cause, and recovery suggestions — do not silently degrade.
- Partial completion only: Return the verified portion first, then list remaining blockers and suggested next steps.
User Checkpoints
- Before executing batch processing, overwriting files, long-running searches, or multi-stage generation, confirm scope and output format with the user.
- Before proceeding when a key judgment is ambiguous, evidence is insufficient, or the workflow is entering the next stage, confirm with the user.
Quick Validation
- Check that key scripts, templates, or reference file paths this skill depends on exist.
- Check that the final output contains the core fields, sections, or files specified for this task.
- Check that results clearly mark assumptions, limitations, and incomplete items.
1---2name: clinical-data-cleaner3description: Use when cleaning clinical trial data, preparing data for FDA/EMA submission, standardizing SDTM datasets, handling missing values in clinical studies, detecting outliers in lab results, or converting raw CRF data to CDISC format. Cleans and standardizes clinical trial data fo...4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8# Clinical Data Cleaner
9
10Clean, validate, and standardize clinical trial data to meet CDISC SDTM standards for regulatory submissions to FDA or EMA.
11
12## Quick Check
13
14Use this command to verify that the packaged script entry point can be parsed before deeper execution.
15
16```bash
17python -m py_compile scripts/main.py
18```
19
20## Audit-Ready Commands
21
22Use these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.
23
24```bash
25python -m py_compile scripts/main.py
26python scripts/main.py --help
27python scripts/main.py --input "Audit validation sample with explicit symptoms, history, assessment, and next-step plan."
28```
29
30## When to Use
31
32- Use this skill when the task needs Use when cleaning clinical trial data, preparing data for FDA/EMA submission, standardizing SDTM datasets, handling missing values in clinical studies, detecting outliers in lab results, or converting raw CRF data to CDISC format. Cleans and standardizes clinical trial data for regulatory compliance with audit trails.
33- Use this skill for data analysis tasks that require explicit assumptions, bounded scope, and a reproducible output format.
34- Use this skill when you need a documented fallback path for missing inputs, execution errors, or partial evidence.
35
36## Workflow
37
381. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
392. Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
403. Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
414. Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
425. If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.
43
44## Quick Start
45
46```python
47from scripts.main import ClinicalDataCleaner
48
49# Initialize for Demographics domain
50cleaner = ClinicalDataCleaner(domain='DM')
51
52# Clean data with default settings
53cleaned = cleaner.clean(raw_data)
54
55# Save with audit trail
56cleaner.save_report('output.csv')
57```
58
59## Core Capabilities
60
61### 1. SDTM Domain Validation
62
63```python
64cleaner = ClinicalDataCleaner(domain='DM') # or 'LB', 'VS'
65is_valid, missing = cleaner.validate_domain(data)
66```
67
68**Required Fields:**
69- **DM**: STUDYID, USUBJID, SUBJID, RFSTDTC, RFENDTC, SITEID, AGE, SEX, RACE
70- **LB**: STUDYID, USUBJID, LBTESTCD, LBCAT, LBORRES, LBORRESU, LBSTRESC, LBDTC
71- **VS**: STUDYID, USUBJID, VSTESTCD, VSORRES, VSORRESU, VSSTRESC, VSDTC
72
73### 2. Missing Value Handling
74
75```python
76cleaner = ClinicalDataCleaner(
77 domain='DM',
78 missing_strategy='median' # mean, median, mode, forward, drop
79)
80cleaned = cleaner.handle_missing_values(data)
81```
82
83### 3. Outlier Detection
84
85```python
86cleaner = ClinicalDataCleaner(
87 domain='LB',
88 outlier_method='domain', # iqr, zscore, domain
89 outlier_action='flag' # flag, remove, cap
90)
91flagged = cleaner.detect_outliers(data)
92```
93
94**Clinical Thresholds:**
95| Parameter | Range | Unit |
96|-----------|-------|------|
97| Glucose | 50-500 | mg/dL |
98| Hemoglobin | 5-20 | g/dL |
99| Systolic BP | 70-220 | mmHg |
100
101### 4. Date Standardization
102
103```python
104standardized = cleaner.standardize_dates(data)
105# Converts to ISO 8601: 2023-01-15T09:30:00
106```
107
108### 5. Complete Pipeline
109
110```python
111cleaner = ClinicalDataCleaner(
112 domain='DM',
113 missing_strategy='median',
114 outlier_method='iqr',
115 outlier_action='flag'
116)
117cleaned_data = cleaner.clean(data)
118cleaner.save_report('output.csv')
119```
120
121**Output Files:**
122- `output.csv` - Cleaned SDTM data
123- `output.report.json` - Audit trail for regulatory submission
124
125## CLI Usage
126
127```text
128# Clean demographics
129python scripts/main.py \
130 --input dm_raw.csv \
131 --domain DM \
132 --output dm_clean.csv \
133 --missing-strategy median \
134 --outlier-method iqr \
135 --outlier-action flag
136
137# Clean lab data with clinical thresholds
138python scripts/main.py \
139 --input lb_raw.csv \
140 --domain LB \
141 --output lb_clean.csv \
142 --outlier-method domain
143```
144
145## Common Patterns
146
147See [references/common-patterns.md](references/common-patterns.md) for detailed examples:
148- Regulatory Submission Preparation
149- Interim Analysis Data Preparation
150- Database Migration Cleanup
151- External Lab Data Integration
152
153## Troubleshooting
154
155See [references/troubleshooting.md](references/troubleshooting.md) for solutions to:
156- Validation failures
157- Date parsing errors
158- Memory errors with large datasets
159- Outlier detection issues
160
161## Quality Checklist
162
163**Pre-Cleaning:**
164- [ ] IACUC approval obtained (animal studies)
165- [ ] Sample size adequately powered
166- [ ] Randomization method documented
167
168**Post-Cleaning:**
169- [ ] Validate against CDISC SDTM IG
170- [ ] Review all cleaning actions in audit trail
171- [ ] Test import to analysis software
172
173## References
174
175- `references/sdtm_ig_guide.md` - CDISC SDTM Implementation Guide
176- `references/domain_specs.json` - Domain-specific field requirements
177- `references/outlier_thresholds.json` - Clinical outlier thresholds
178- `references/common-patterns.md` - Detailed usage patterns
179- `references/troubleshooting.md` - Problem-solving guide
180
181---
182
183**Skill ID**: 189 | **Version**: 2.0 | **License**: MIT
184
185## Output Requirements
186
187Every final response should make these items explicit when they are relevant:
188
189- Objective or requested deliverable
190- Inputs used and assumptions introduced
191- Workflow or decision path
192- Core result, recommendation, or artifact
193- Constraints, risks, caveats, or validation needs
194- Unresolved items and next-step checks
195
196## Error Handling
197
198- If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.
199- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
200- If `scripts/main.py` fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback.
201- Do not fabricate files, citations, data, search results, or execution outcomes.
202
203## Input Validation
204
205This skill accepts requests that match the documented purpose of `clinical-data-cleaner` and include enough context to complete the workflow safely.
206
207Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
208
209> `clinical-data-cleaner` only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
210
211## Response Template
212
213Use the following fixed structure for non-trivial requests:
214
2151. Objective
2162. Inputs Received
2173. Assumptions
2184. Workflow
2195. Deliverable
2206. Risks and Limits
2217. Next Checks
222
223If the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.
224
225## When Not to Use
226
227- Do not proceed when required input files, identifiers, parameters, or context are missing — ask the user to provide them first.
228- Do not assume capabilities beyond this skill's declared scope when the user requests external operations or inferences.
229- Do not proceed without user confirmation when overwriting existing results, executing high-cost batch operations, or expanding task scope.
230
231## Required Inputs
232
233| Field | Required | Format/Source | Example | If Missing |
234|---|---|---|---|---|
235| User task description | Yes | Text | Research question, writing goal, analysis objective | Stop and ask user to provide |
236| Primary input material | Depends on task | Text, file path, ID, table, or literature | PMID, PDF, CSV, DOCX, keywords, etc. | Specify which material type is missing |
237| Output preference | No | Text | Language, format, target journal, template | Use skill default format |
238
239## Output Contract
240
241- Primary output: Structured result or target file aligned with this skill's objective.
242- Optional output: Intermediate check notes, issue list, supplementary suggestions, or generated file paths.
243- Format requirement: Unless the user specifies otherwise, prefer stable, reviewable Markdown or JSON; if the skill's bundled script requires a fixed format, use that format.
244- If partially complete: Must explicitly mark as PARTIAL and state which steps are completed and which remain.
245
246## Failure Handling
247
248- Missing critical input: Explicitly state which fields, files, or identifiers are missing and pause.
249- Script, template, or resource execution failure: Report the failing step, likely cause, and recovery suggestions — do not silently degrade.
250- Partial completion only: Return the verified portion first, then list remaining blockers and suggested next steps.
251
252## User Checkpoints
253
254- Before executing batch processing, overwriting files, long-running searches, or multi-stage generation, confirm scope and output format with the user.
255- Before proceeding when a key judgment is ambiguous, evidence is insufficient, or the workflow is entering the next stage, confirm with the user.
256
257## Quick Validation
258
259- Check that key scripts, templates, or reference file paths this skill depends on exist.
260- Check that the final output contains the core fields, sections, or files specified for this task.
261- Check that results clearly mark assumptions, limitations, and incomplete items.