Title: CRF To SDTM Mapping Specification
Domain: health_medicine — Clinical Research & Trial Operations

Summary: Create a field-level mapping CSV from clinical CRF and define.xml source documents to SDTM domain variables. The task has CM, VS, and DS variants with matching supplemental qualifier datasets.

Task prompt:
You are preparing a field-level CRF-to-SDTM mapping specification on Linux.

## Your Task
Create the Concomitant Medications mapping for study C4591001.

## Visible Inputs
- Task brief: `base/input/task_brief.md`
- Output contract: `base/input/output_contract.json`
- Source documents directory: `base/input/source_documents`
- Optional Python runtime manifest: `base/input/runtime_env`

The source documents include the sample CRF PDF, annotated CRF PDF, SDTM define.xml,
and supplemental define.xml material. Use those files to identify form fields and
their target SDTM variables for `CM` and, where applicable,
`SUPPCM` supplemental qualifiers.

## Required Output
Save exactly one CSV file:

```text
base/output/cm_mapping.csv
```

The CSV must contain exactly these columns in this order:

```text
crf_form, crf_field_label, crf_item_or_placeholder, sdtm_dataset, sdtm_variable, role, origin, mapping_rule, controlled_terms_or_expected_values, goes_to_suppqual, notes
```

## Example Row

The following shows one correctly formatted CSV row to illustrate the expected
schema (header + data). Include only rows for CRF-sourced fields; omit derived
or protocol-level variables (e.g. STUDYID, DOMAIN, USUBJID) that have no
corresponding CRF field.

```csv
crf_form,crf_field_label,crf_item_or_placeholder,sdtm_dataset,sdtm_variable,role,origin,mapping_rule,controlled_terms_or_expected_values,goes_to_suppqual,notes
CONCOMITANT MEDICATIONS - BASELINE (CONMED BSL),What is the medication identifier?,Sponsor-Defined Identifier,CM,CMSPID,Identifier,CRF,Map the sponsor-defined medication identifier to CMSPID.,,NO,aCRF page 15 annotates Sponsor-Defined Identifier to CMSPID for baseline concomitant medications.
```

## Constraints
- Produce a mapping specification only, not subject-level records or XPT datasets.
- Keep all generated files inside `base/output`.
- Do not modify files under `base/input`.
- Use the visible task files only; do not use external web sources.

## Canonical Row and Text Conventions

- Include one row for every collected CRF field-to-SDTM target mapping supported by the annotated CRF and define.xml; do not add purely derived, assigned, protocol-level, or structural SUPPQUAL rows without a corresponding collected field.
- Use the full descriptive form title with its short code in parentheses exactly as shown in the source metadata.
- Copy CRF field labels and annotated item/placeholder text verbatim. Use bare placeholder text without square brackets or invented suffixes.
- Represent a collected supplemental qualifier as its target `SUPPCM` mapping row; do not add separate infrastructure rows for RDOMAIN, IDVAR, IDVARVAL, QNAM, QLABEL, QORIG, or QEVAL unless that item is itself collected.
- Make every `mapping_rule` and `notes` value field-specific: explicitly name the target variable and cite the applicable source form/page or metadata evidence.


The agent must:
Read the variant's task brief and output contract.
Inspect the sample CRF, annotated CRF, SDTM define.xml, and supplemental define.xml source documents.
Identify CRF field-level mappings for the variant's primary SDTM dataset and supplemental qualifier dataset.
Write exactly one mapping CSV with the required columns in the selected output directory.

Software: Python
uv
pandas
pypdf
lxml

Input files:
name: task_brief.md
format: md
path: input/task_brief.md
description: Variant-specific instructions and output filename.
name: output_contract.json
format: json
path: input/output_contract.json
description: Required CSV columns, allowed datasets, and format constraints.
name: source_documents
format: pdf/xml
path: input/source_documents/
description: Sample CRF, annotated CRF, SDTM define.xml, and supplemental define.xml files.
name: runtime_env
format: pyproject/uv.lock
path: input/runtime_env/
description: Optional Python dependency manifest for agents that want pandas, pypdf, or lxml.