import os
import sys
import polars as pl
from pathlib import Path
sys.path.insert(0, 'src')
from rtflite import LibreOfficeConverter
try:
converter = LibreOfficeConverter()
except Exception:
converter = None
print("WARNING: LibreOffice not found. PDF conversion will be skipped.")
from csrlite import load_plan, study_plan_to_mh_listing
from csrlite.mh.mh_listing import mh_listing12 Medical History Listing
Objectives
This guide demonstrates Medical History (MH) listing.
12.1 Setup
12.2 Medical History Listing
Detailed listing of each subject’s medical history.
12.3 StudyPlan-Driven Workflow
study_plan = load_plan("studies/xyz123/yaml/plan_xyz123.yaml")
study_plan.get_plan_df().filter(pl.col("analysis") == "mh_listing")2026-02-03 15:27:29,543 - csrlite.common.plan - INFO - Successfully loaded dataset 'adsl' from 'studies/xyz123/yaml/../../../data/adsl.parquet'
2026-02-03 15:27:29,547 - csrlite.common.plan - INFO - Successfully loaded dataset 'adae' from 'studies/xyz123/yaml/../../../data/adae.parquet'
2026-02-03 15:27:29,548 - csrlite.common.plan - INFO - Successfully loaded dataset 'adie' from 'studies/xyz123/yaml/../../../data/adie.parquet'
2026-02-03 15:27:29,549 - csrlite.common.plan - INFO - Successfully loaded dataset 'adpd' from 'studies/xyz123/yaml/../../../data/adpd.parquet'
shape: (0, 5)
| analysis | population | observation | parameter | group |
|---|---|---|---|---|
| str | str | str | str | str |
output_files = study_plan_to_mh_listing(study_plan)12.4 Complete Pipeline
# Load data
data_path = Path("data") if Path("data").exists() else Path("../data")
adsl = pl.read_parquet(data_path / "adsl.parquet")
admh = pl.read_parquet(data_path / "admh.parquet")
# Define output path for listing
output_listing_rtf = "studies/xyz123/rtf/mh_listing_manual.rtf"
# Ensure directory exists
Path(output_listing_rtf).parent.mkdir(parents=True, exist_ok=True)
listing_path = mh_listing(
population=adsl,
observation=admh,
population_filter="SAFFL = 'Y'",
observation_filter="MHOCCUR = 'Y'",
id=("USUBJID", "Subject ID"),
title=[
"Listing of Medical History",
"(Safety Population)"
],
footnote=["Sorted by Treatment, Subject, and Start Date."],
source=["Source: ADSL and ADMH datasets"],
output_file=output_listing_rtf,
sort_columns=["TRT01A", "USUBJID", "MHSTDTC"]
)
print(f"Generated: {listing_path}")studies/xyz123/rtf/mh_listing_manual.rtf
Generated: studies/xyz123/rtf/mh_listing_manual.rtf