Review ask

As a clinical trial statistician or programmer, challenge anything in this benchmark: describe a problem in Comments, or propose a fix with the Edit button on any source file.

  1. Task: Would a real study need this derivation, specified this way? Does it follow CDISC ADaM: variable names, controlled terms, record structure? Flag any rule that is ambiguous or that a sponsor would handle differently.
  2. Inputs: Do they look like data collected in a real trial, and do they include the situations you would expect to meet in one?
  3. Expected output: Would independent QC programming reproduce every value from these inputs and rules?

The other tabs beside Comments are background for assessment, not under review.

Summary

Lifecycle: draftEditUnder review
What this benchmark means
README.md

Goal: mark each subject's end-of-treatment record for every laboratory test (EOTFL), carrying the protocol endpoint qualifier it rests on (ENDPOINT).

Input: laboratory (LB) records carry a numeric sequence number, a test code (LBTESTCD), a visit number (VISITNUM), and a numeric result. Supplemental laboratory qualifier (SUPPLB) records carry the same sequence as eight-character, space-padded text, one qualifier name and value per record; only the protocol endpoint qualifier is read.

Variables:

  • AVAL is the numeric laboratory result.
  • ENDPOINT is Y when a supplemental endpoint qualifier with the same study, subject, and sequence number marks the record; empty otherwise.
  • EOTFL is Y on one record per subject and test: the endpoint-marked record when there is one, otherwise the record from the latest visit. Every other record is empty.

Note: the endpoint qualifier decides the choice even when a later visit exists, so the flag can sit before the subject's last visit. A record wins the flag even when its result is missing, and a group with a single record still gets the flag. Other qualifiers on the same record, and endpoint qualifiers for records the laboratory data does not hold, change nothing.

Inputs

Under review
2 source files

input/lb.csv

Edit
12 rows
input/lb.csv
STUDYIDUSUBJIDLBSEQLBTESTCDVISITNUMLBSTRESN
YAMAA-011ALB14
YAMAA-012ALB24.2
YAMAA-013ALB34.1
YAMAA-014CREAT180
YAMAA-015CREAT282
YAMAA-016CREAT385
YAMAA-011ALB13.9
YAMAA-012ALB24
YAMAA-011ALB14.3
YAMAA-011ALB1—
YAMAA-012ALB24.4
YAMAA-011CREAT395

input/supplb.csv

Edit
6 rows
input/supplb.csv
STUDYIDRDOMAINUSUBJIDIDVARIDVARVALQNAMQLABELQVAL
YAMAA-01LBLBSEQ 2ENDPOINTProtocol Endpoint RecordY
YAMAA-01LBLBSEQ 2LBTMSHIResult to Upper Limit Ratio0.9
YAMAA-01LBLBSEQ 1LBTMSHIResult to Upper Limit Ratio0.8
YAMAA-01LBLBSEQ 7ENDPOINTProtocol Endpoint RecordY
YAMAA-01LBLBSEQ 1ENDPOINTProtocol Endpoint RecordY
YAMAA-01LBLBSEQ 1ENDPOINTProtocol Endpoint RecordY

Expected output

Under review
12 expected rows

expected/adlb.csv

Edit
12 rows
expected/adlb.csv
STUDYIDUSUBJIDLBSEQLBTESTCDVISITNUMAVALENDPOINTEOTFL
YAMAA-011ALB14——
YAMAA-012ALB24.2YY
YAMAA-013ALB34.1——
YAMAA-014CREAT180——
YAMAA-015CREAT282——
YAMAA-016CREAT385—Y
YAMAA-011ALB13.9——
YAMAA-012ALB24—Y
YAMAA-011ALB14.3—Y
YAMAA-011ALB1—YY
YAMAA-012ALB24.4——
YAMAA-011CREAT395YY
Shaded columns are derived— = missing value

Comments and assessment materials

Comments

Signed in with GitHub; saved in repository Discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Dataset NameVariable NameVariable LabelTypeCodelist/Controlled TermsCoreComputational MethodOrigin
ADLBSTUDYIDStudy IdentifiercharacterCopy value from LB.STUDYID.Predecessor
ADLBUSUBJIDUnique Subject IdentifiercharacterCopy value from LB.USUBJID.Predecessor
ADLBLBSEQSequence NumbernumericCopy value from LB.LBSEQ.Predecessor
ADLBLBTESTCDLab Test or Examination Short NamecharacterCopy value from LB.LBTESTCD.Predecessor
ADLBVISITNUMVisit NumbernumericCopy value from LB.VISITNUM.Predecessor
ADLBAVALAnalysis ValuenumericCopy value from LB.LBSTRESN.Predecessor
ADLBENDPOINTProtocol Endpoint RecordcharacterTake ENDPOINT from the LB record matching on STUDYID, USUBJID and LBSEQ, where ENDPOINT is derived as QVAL from the SUPPLB record whose STUDYID equals LB.STUDYID, USUBJID equals LB.USUBJID and IDVARVAL equals LB.LBSEQ padded on the left with spaces to at least 8 characters, where SUPPLB.QNAM = 'ENDPOINT', blank when unmatched, and a row with no match is an error.Derived
ADLBEOTFLEnd of Treatment Record Flagcharacter"Y" when EOT_SEQ = 1, with EOT_SEQ taken from the LB record matching on STUDYID, USUBJID and LBSEQ, where EOT_SEQ is derived as row number within each group of LB.USUBJID, LB.LBTESTCD, ordered by ENDPOINT descending then LB.VISITNUM descending, and a row with no match is an error; blank otherwise.Derived
VersionDateAuthorDescriptionReviewerSign-off
1.32026-09-29yamaa docs buildShow study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata
1.22026-09-29yamaa docs buildClassify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived
1.12026-09-29yamaa docs buildResolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML
1.0yamaa docs buildInitial generation from spec.yaml

Agent prompt

The request an agent receives with the input files; each tier states no more than the one above

prompts/adam-adlb-end-of-treatment/full.md

Edit
22 lines

Following CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL

AVAL is the numeric laboratory result.

ENDPOINT is Y when a supplemental endpoint qualifier with the same study, subject, and sequence number marks the record; it has no value otherwise. Only the protocol endpoint qualifier is read; other qualifiers change nothing.

EOTFL is Y on one record per subject and test: the endpoint-marked record when there is one, otherwise the record from the latest visit. Every other record has no value. The endpoint qualifier decides even when a later visit exists, and a record wins the flag even when its result is missing.

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

prompts/adam-adlb-end-of-treatment/conventions.md

Edit
13 lines

Following CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL

ENDPOINT is Y or has no value.

EOTFL is Y or has no value.

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

prompts/adam-adlb-end-of-treatment/brief.md

Edit
9 lines

Following CDISC ADaM standards, use the provided LB and SUPPLB datasets to create an ADLB dataset with one record per laboratory record.

The output dataset should contain the following columns in this order: STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL

Read the source datasets from /app/input and save the completed dataset as /app/output/adlb.csv.

yamaa code

Runs the yamaa specification; its result must match the expected output

run.R

Edit
4 lines
library(yamaa)adlb <- yamaa_domain("spec.yaml")$outputadlb

run.py

Edit
4 lines
import yamaaadlb = yamaa.yamaa_domain("spec.yaml").outputadlb

Solution without yamaa

Written from the full prompt and the inputs alone; CI checks it reproduces the expected output

solutions/adam-adlb-end-of-treatment/result.R

Edit
67 lines
# Reference solution for the yamaa benchmark adam-adlb-end-of-treatment (R track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.library(dplyr, warn.conflicts = FALSE)library(readr)library(stringr)lb <- read_csv(  "/app/input/lb.csv",  col_types = cols(    LBSEQ = col_integer(),    VISITNUM = col_integer(),    LBSTRESN = col_double(),    .default = col_character()  ))supp <- read_csv(  "/app/input/supplb.csv",  col_types = cols(.default = col_character()))# ENDPOINT is Y when a supplemental endpoint qualifier with the same# study, subject, and sequence number marks the record. Only the protocol# endpoint qualifier is read.endpoint_keys <- supp |>  filter(QNAM %in% "ENDPOINT") |>  transmute(    STUDYID, USUBJID,    SEQ_TRIM = str_trim(IDVARVAL),    ENDPOINT = "Y"  )marked <- lb |>  mutate(SEQ_TRIM = as.character(LBSEQ), AVAL = LBSTRESN) |>  left_join(endpoint_keys, by = c("STUDYID", "USUBJID", "SEQ_TRIM")) |>  select(-SEQ_TRIM)# EOTFL is Y on one record per subject and test: the endpoint-marked# record when there is one, otherwise the record from the latest visit.endpoint_winners <- marked |>  filter(ENDPOINT %in% "Y") |>  group_by(STUDYID, USUBJID, LBTESTCD) |>  summarise(WIN_ENDPOINT = min(LBSEQ), .groups = "drop")latest_winners <- marked |>  arrange(desc(VISITNUM), desc(LBSEQ)) |>  distinct(STUDYID, USUBJID, LBTESTCD, .keep_all = TRUE) |>  transmute(STUDYID, USUBJID, LBTESTCD, WIN_LATEST = LBSEQ)winners <- latest_winners |>  left_join(endpoint_winners, by = c("STUDYID", "USUBJID", "LBTESTCD")) |>  mutate(WIN_LBSEQ = coalesce(WIN_ENDPOINT, WIN_LATEST), EOTFL = "Y") |>  select(STUDYID, USUBJID, LBTESTCD, WIN_LBSEQ, EOTFL)adlb <- marked |>  left_join(    winners,    by = c("STUDYID", "USUBJID", "LBTESTCD", "LBSEQ" = "WIN_LBSEQ")  ) |>  arrange(USUBJID, LBTESTCD, LBSEQ) |>  select(STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL)dir.create("/app/output", showWarnings = FALSE)write_csv(adlb, "/app/output/adlb.csv", na = "")

solutions/adam-adlb-end-of-treatment/result.py

Edit
82 lines
# Reference solution for the yamaa benchmark adam-adlb-end-of-treatment (Python track).## Written from the benchmark's full prompt and its inputs alone, as an agent# would write it. Harbor's oracle agent runs it to check that the prompt can# be solved and that the grader scores a correct answer 1.from pathlib import Pathimport polars as pllb = pl.read_csv("/app/input/lb.csv", infer_schema=False).with_columns(    pl.col("LBSEQ").cast(pl.Int64),    pl.col("VISITNUM").cast(pl.Int64, strict=False),    pl.col("LBSTRESN").cast(pl.Float64, strict=False).alias("AVAL"),)supp = pl.read_csv("/app/input/supplb.csv", infer_schema=False)# ENDPOINT is Y when a supplemental endpoint qualifier with the same# study, subject, and sequence number marks the record. Only the protocol# endpoint qualifier is read. IDVARVAL is space-padded, so compare on the# trimmed sequence number.endpoint_keys = (    supp.filter(pl.col("QNAM") == "ENDPOINT")    .with_columns(pl.col("IDVARVAL").str.strip_chars().alias("SEQ_TRIM"))    .select("STUDYID", "USUBJID", "SEQ_TRIM")    .with_columns(pl.lit("Y").alias("ENDPOINT")))marked = (    lb.with_columns(SEQ_TRIM=pl.col("LBSEQ").cast(pl.String))    .join(        endpoint_keys,        on=["STUDYID", "USUBJID", "SEQ_TRIM"],        how="left",        maintain_order="left",    )    .drop("SEQ_TRIM"))# EOTFL is Y on one record per subject and test: the endpoint-marked# record when there is one, otherwise the record from the latest visit.endpoint_winners = (    marked.filter(pl.col("ENDPOINT") == "Y")    .group_by("STUDYID", "USUBJID", "LBTESTCD")    .agg(pl.col("LBSEQ").min().alias("WIN_ENDPOINT")))latest_winners = (    marked.sort(["VISITNUM", "LBSEQ"], descending=[True, True], nulls_last=True)    .unique(["STUDYID", "USUBJID", "LBTESTCD"], keep="first", maintain_order=True)    .select("STUDYID", "USUBJID", "LBTESTCD", WIN_LATEST="LBSEQ"))winners = (    latest_winners.join(        endpoint_winners, on=["STUDYID", "USUBJID", "LBTESTCD"], how="left"    )    .with_columns(WIN_LBSEQ=pl.coalesce("WIN_ENDPOINT", "WIN_LATEST"))    .select("STUDYID", "USUBJID", "LBTESTCD", "WIN_LBSEQ")    .with_columns(pl.lit("Y").alias("EOTFL")))adlb = (    marked.join(        winners,        left_on=["STUDYID", "USUBJID", "LBTESTCD", "LBSEQ"],        right_on=["STUDYID", "USUBJID", "LBTESTCD", "WIN_LBSEQ"],        how="left",    )    .select(        "STUDYID",        "USUBJID",        "LBSEQ",        "LBTESTCD",        "VISITNUM",        "AVAL",        "ENDPOINT",        "EOTFL",    )    .sort(["USUBJID", "LBTESTCD", "LBSEQ"]))Path("/app/output").mkdir(exist_ok=True)adlb.write_csv("/app/output/adlb.csv")

solutions/adam-adlb-end-of-treatment/result.sas

Edit
29 lines
/* opensas reference solution for the yamaa benchmark adam-adlb-end-of-treatment.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data lb;  length STUDYID USUBJID LBTESTCD $1024;  infile "/app/input/lb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. LBSEQ LBTESTCD : $char1024. VISITNUM LBSTRESN;run;data supplb;  length STUDYID RDOMAIN USUBJID IDVAR IDVARVAL QNAM QLABEL QVAL $1024;  infile "/app/input/supplb.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. RDOMAIN : $char1024. USUBJID : $char1024. IDVAR : $char1024. IDVARVAL : $char1024. QNAM : $char1024. QLABEL : $char1024. QVAL : $char1024.;run;data supplb_key; set supplb; PARENTSEQ=input(IDVARVAL,?? best32.); run;proc sql;  create table joined as select a.*,a.LBSTRESN as AVAL,b.QVAL as ENDPOINT from lb as a left join supplb_key as b    on a.STUDYID=b.STUDYID and a.USUBJID=b.USUBJID and b.RDOMAIN='LB' and b.IDVAR='LBSEQ' and a.LBSEQ=b.PARENTSEQ and b.QNAM='ENDPOINT';quit;data ordered; set joined; priority=0; if ENDPOINT='Y' then priority=1; run;proc sort data=ordered; by STUDYID USUBJID LBTESTCD descending priority descending VISITNUM LBSEQ; run;data result; length EOTFL $1; set ordered; by STUDYID USUBJID LBTESTCD; if first.LBTESTCD then EOTFL='Y'; run;proc sql;  create table final as select STUDYID, USUBJID, LBSEQ, LBTESTCD, VISITNUM, AVAL, ENDPOINT, EOTFL from result;quit;proc export data=final outfile="/app/output/adlb.csv" dbms=csv replace; run;