Review ask

As a clinical trial statistician or programmer, answer three short questions in Your review: the task, the inputs and outputs, and the AI-assisted review. Agreeing with all three approves this benchmark; disagreeing with any needs a comment. Propose a fix with the Edit button on any source file, or add it to your comments.

We suggest spending no more than 5 minutes on a review. The other tabs beside Your review are background for assessment, not under review.

Summary

Lifecycle: draftEditUnder review
What this benchmark means
README.md

Public entries: Python and R. Passing coverage requires an installed inventory.

Goal: carry each collected vital-signs result with its actual collection datetime, and add the planned time point it was scheduled for and the dose it is timed from: VSTESTCD, VSORRES, VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSDTC, and VSDY.

Input: long-form Operational Data Model (ODM) data with one row per collected item, carrying the collection form (FormOID), the item (ItemOID), and the stored value (Value); a small test dictionary (vs_mapping.csv) translating each vital-signs item into its test short name, test name, and unit; plus demographics rows carrying the reference start date. Each planned time point arrives as its own vital-signs form, so the form tells which scheduled reading a result belongs to. The first-dose datetime rides along on the dosing form FO.EX.

Variables:

  • VSSEQ numbers the records per subject in schedule order, then pulse, systolic, and diastolic blood pressure within each time point.
  • VSTPT is the planned time point name for the collection form: PRE-DOSE, 30 MIN POST-DOSE, 1 H POST-DOSE, or 4 H POST-DOSE.
  • VSTPTNUM is the planned time point number for the form: 1 through 4 in schedule order.
  • VSELTM is the planned elapsed time since the first dose for the form, in ISO 8601 duration form: -PT15M before the dose, then PT30M, PT1H, and PT4H after it.
  • VSTPTREF names the reference time point the planned elapsed time counts from: FIRST DOSE on every record.
  • VSRFTDTC is the date and time of that reference time point, the first-dose datetime from the subject's dosing form.
  • VSTESTCD is the test short name, looked up from the test dictionary by item: PULSE, SYSBP, or DIABP. Items with no dictionary entry (the datetime and dosing items) give no record.
  • VSORRES is the result in original units, the value on the test's item row within the form.
  • VSORRESU is the original unit from the test dictionary: beats/min or mmHg.
  • VSSTRESN is the numeric result in standard units; pulse and blood pressure were collected in standard units, so it equals the original result.
  • VSSTRESU is the standard unit, carried from the original unit.
  • VSDTC is the actual collection datetime from the form's datetime item row, shared by every result on that form; a form with no datetime item stops the run.
  • VSDY is the study day of the collection datetime, counted from the subject's reference start date: that date is day 1, there is no day zero, and dates before it count back from -1; missing when the subject has no reference start date.

Note: the planned elapsed time stays in duration form next to the actual collection datetime, so a reading taken later than planned keeps its late actual datetime and the gap shows when the two are compared. Each reading is also checked against the first-dose datetime in VSRFTDTC: a post-dose reading dated before the dose, or a pre-dose reading dated after it, stops the run.

Inputs

Under review
3 source files

input/dm.csv

Edit
2 rows
input/dm.csv
STUDYIDUSUBJIDRFSTDTC
YAMAA-012025-01-08
YAMAA-012025-01-15

input/odm.csv

Edit
34 rows
input/odm.csv
StudyOIDMetaDataVersionOIDSubjectKeyStudyEventOIDStudyEventRepeatKeyFormOIDFormRepeatKeyItemGroupOIDItemGroupRepeatKeyItemOIDValue
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.VSDTC2025-01-08T08:45:00
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.PULSE72
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.SYSBP118
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.DIABP76
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_30MIN1IG.VS1IT.VS.VSDTC2025-01-08T09:31:00
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_30MIN1IG.VS1IT.VS.PULSE74
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_30MIN1IG.VS1IT.VS.SYSBP120
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_30MIN1IG.VS1IT.VS.DIABP78
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_1H1IG.VS1IT.VS.VSDTC2025-01-08T10:02:00
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_1H1IG.VS1IT.VS.PULSE70
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_1H1IG.VS1IT.VS.SYSBP116
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_1H1IG.VS1IT.VS.DIABP74
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_4H1IG.VS1IT.VS.VSDTC2025-01-08T13:05:00
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_4H1IG.VS1IT.VS.PULSE68
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_4H1IG.VS1IT.VS.SYSBP114
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.VS_4H1IG.VS1IT.VS.DIABP72
YAMAA-01MDV.1YAMAA-01-001SE.D11FO.EX1IG.EX1IT.EX.EXSTDTC2025-01-08T09:00:00
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.VSDTC2025-01-15T08:44:00
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.PULSE80
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.SYSBP124
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_PREDOSE1IG.VS1IT.VS.DIABP82
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_30MIN1IG.VS1IT.VS.VSDTC2025-01-15T09:52:00
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_30MIN1IG.VS1IT.VS.PULSE88
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_30MIN1IG.VS1IT.VS.SYSBP128
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_30MIN1IG.VS1IT.VS.DIABP84
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_1H1IG.VS1IT.VS.VSDTC2025-01-15T10:03:00
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_1H1IG.VS1IT.VS.PULSE78
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_1H1IG.VS1IT.VS.SYSBP122
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_1H1IG.VS1IT.VS.DIABP80
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_4H1IG.VS1IT.VS.VSDTC2025-01-15T13:01:00
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_4H1IG.VS1IT.VS.PULSE76
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_4H1IG.VS1IT.VS.SYSBP120
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.VS_4H1IG.VS1IT.VS.DIABP78
YAMAA-01MDV.1YAMAA-01-002SE.D11FO.EX1IG.EX1IT.EX.EXSTDTC2025-01-15T09:00:00

input/vs_mapping.csv

Edit
3 rows
input/vs_mapping.csv
ItemOIDVSTESTCDVSTESTUNIT
IT.VS.PULSEPULSEPulsebeats/min
IT.VS.SYSBPSYSBPSystolic Blood PressuremmHg
IT.VS.DIABPDIABPDiastolic Blood PressuremmHg

Expected output

Under review
24 expected rows

expected/vs.csv

Edit
24 rows
expected/vs.csv
DOMAINSTUDYIDUSUBJIDVSSEQVISITVSTPTVSTPTNUMVSELTMVSTPTREFVSRFTDTCVSTESTCDVSORRESVSORRESUVSSTRESNVSSTRESUVSDTCVSDY
VSYAMAA-011DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-08T09:00:00PULSE72beats/min72beats/min2025-01-08T08:45:001
VSYAMAA-012DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-08T09:00:00SYSBP118mmHg118mmHg2025-01-08T08:45:001
VSYAMAA-013DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-08T09:00:00DIABP76mmHg76mmHg2025-01-08T08:45:001
VSYAMAA-014DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-08T09:00:00PULSE74beats/min74beats/min2025-01-08T09:31:001
VSYAMAA-015DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-08T09:00:00SYSBP120mmHg120mmHg2025-01-08T09:31:001
VSYAMAA-016DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-08T09:00:00DIABP78mmHg78mmHg2025-01-08T09:31:001
VSYAMAA-017DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-08T09:00:00PULSE70beats/min70beats/min2025-01-08T10:02:001
VSYAMAA-018DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-08T09:00:00SYSBP116mmHg116mmHg2025-01-08T10:02:001
VSYAMAA-019DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-08T09:00:00DIABP74mmHg74mmHg2025-01-08T10:02:001
VSYAMAA-0110DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-08T09:00:00PULSE68beats/min68beats/min2025-01-08T13:05:001
VSYAMAA-0111DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-08T09:00:00SYSBP114mmHg114mmHg2025-01-08T13:05:001
VSYAMAA-0112DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-08T09:00:00DIABP72mmHg72mmHg2025-01-08T13:05:001
VSYAMAA-011DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-15T09:00:00PULSE80beats/min80beats/min2025-01-15T08:44:001
VSYAMAA-012DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-15T09:00:00SYSBP124mmHg124mmHg2025-01-15T08:44:001
VSYAMAA-013DAY 1PRE-DOSE1-PT15MFIRST DOSE2025-01-15T09:00:00DIABP82mmHg82mmHg2025-01-15T08:44:001
VSYAMAA-014DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-15T09:00:00PULSE88beats/min88beats/min2025-01-15T09:52:001
VSYAMAA-015DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-15T09:00:00SYSBP128mmHg128mmHg2025-01-15T09:52:001
VSYAMAA-016DAY 130 MIN POST-DOSE2PT30MFIRST DOSE2025-01-15T09:00:00DIABP84mmHg84mmHg2025-01-15T09:52:001
VSYAMAA-017DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-15T09:00:00PULSE78beats/min78beats/min2025-01-15T10:03:001
VSYAMAA-018DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-15T09:00:00SYSBP122mmHg122mmHg2025-01-15T10:03:001
VSYAMAA-019DAY 11 H POST-DOSE3PT1HFIRST DOSE2025-01-15T09:00:00DIABP80mmHg80mmHg2025-01-15T10:03:001
VSYAMAA-0110DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-15T09:00:00PULSE76beats/min76beats/min2025-01-15T13:01:001
VSYAMAA-0111DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-15T09:00:00SYSBP120mmHg120mmHg2025-01-15T13:01:001
VSYAMAA-0112DAY 14 H POST-DOSE4PT4HFIRST DOSE2025-01-15T09:00:00DIABP78mmHg78mmHg2025-01-15T13:01:001
Shaded columns are derived— = missing value

Human review and assessment

Your review

3 questions and your comments · View benchmark discussions

Mapping spec

Generated from the benchmark YAML; do not edit by hand

Variable NameVariable LabelTypeLengthControlled Terms or FormatOriginCoreConversion DefinitionVariable TypeVariable OrderComments for Define
DOMAINDomain AbbreviationCharAssignedSet constant value "VS".SDTM1
STUDYIDStudy IdentifierCharCollectedCopy value from ODM.StudyOID.SDTM2
USUBJIDUnique Subject IdentifierCharCollectedCopy value from ODM.SubjectKey.SDTM3
VISITVisit NameCharCollectedRecode ODM.StudyEventOID: "SE.D1" → "DAY 1"; missing values stay missing; unlisted values are errors.SDTM4
VSTPTPlanned Time Point NameCharCollectedRecode ODM.FormOID: "FO.VS_PREDOSE" → "PRE-DOSE", "FO.VS_30MIN" → "30 MIN POST-DOSE", "FO.VS_1H" → "1 H POST-DOSE", "FO.VS_4H" → "4 H POST-DOSE"; missing values stay missing; unlisted values are errors.SDTM5
VSTPTNUMPlanned Time Point NumberNumCollectedRecode ODM.FormOID: "FO.VS_PREDOSE" → "1", "FO.VS_30MIN" → "2", "FO.VS_1H" → "3", "FO.VS_4H" → "4"; missing values stay missing; unlisted values are errors.SDTM6
VSELTMPlanned Elapsed TimeCharCollectedRecode ODM.FormOID: "FO.VS_PREDOSE" → "-PT15M", "FO.VS_30MIN" → "PT30M", "FO.VS_1H" → "PT1H", "FO.VS_4H" → "PT4H"; missing values stay missing; unlisted values are errors.SDTM7
VSTPTREFTime Point ReferenceCharAssignedSet constant value "FIRST DOSE".SDTM8
VSRFTDTCDate/Time of Reference Time PointCharISO 8601DerivedTake Value from the ODM record whose StudyOID equals STUDYID and SubjectKey equals USUBJID, where ODM.FormOID = 'FO.EX' AND ODM.ItemOID = 'IT.EX.EXSTDTC', and a row with no match is an error.SDTM9
VSTESTCDVital Signs Test Short NameCharPULSE, SYSBP, DIABPDerivedSet per constructed row; see the Row construction sheet.SDTM10
VSSEQSequence NumberNumDerivedRow number within each group of STUDYID, USUBJID, ordered by VSTPTNUM then ORD_TEST.SDTM11
VSORRESResult or Finding in Original UnitsCharDerivedSet per constructed row; see the Row construction sheet.SDTM12
VSORRESUOriginal UnitsCharbeats/min, mmHgDerivedSet per constructed row; see the Row construction sheet.SDTM13
VSSTRESNNumeric Result/Finding in Standard UnitsNumDerivedCopy value from VSORRES.SDTM14
VSSTRESUStandard UnitsCharDerivedCopy value from VSORRESU.SDTM15
VSDTCDate/Time of MeasurementsCharISO 8601DerivedAggregate ONLY(ODM.Value) over records whose StudyOID equals ODM.StudyOID, SubjectKey equals ODM.SubjectKey, StudyEventOID equals ODM.StudyEventOID and FormOID equals ODM.FormOID, where ODM.ItemOID = 'IT.VS.VSDTC'.SDTM16
VSDYStudy Day of Vital SignsNumDerivedCDISC study day of VSDT against RFSTDTC as day 1; there is no day zero.SDTM17
TemplateInclude whenVSTESTCDVSORRESVSORRESU
vs_readingVSTESTCD IS NOT NULLCopy VSTESTCD from the VS_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blankAggregate ONLY(ODM.Value) over records matching on the shared output keysCopy UNIT from the VS_MAPPING record whose ItemOID equals ODM.ItemOID, and no match yields blank
VariablePermitted values
VSTESTCDPULSE, SYSBP, DIABP
VSORRESUbeats/min, mmHg
VersionDateAuthorDescriptionReviewerSign-off
1.72026-10-20yamaa docs buildRead a specification in the 1.0 surface as its 0.5 counterpart; state that missing values stay missing where a mapping declares no missing handler, and leave out a declared missing answer that restates a handler's default
1.62026-10-17yamaa docs buildDescribe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight
1.52026-10-17yamaa docs buildName collected precision in words instead of letter codes; state imputation fallbacks, minimum source precision, bounds ignored outside the collected period, and invalid text with no handler as an error; describe date and datetime shifts, imputation flag codes, and partial text giving no date part
1.42026-10-15yamaa docs buildState datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks
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/sdtm-vs-planned-time-points/full.md

Edit
38 lines

Following CDISC SDTM standards, use the provided DM, ODM, and VS_MAPPING datasets to create a VS dataset with one record per collected vital-signs result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, VSSEQ, VISIT, VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSTESTCD, VSORRES, VSORRESU, VSSTRESN, VSSTRESU, VSDTC, VSDY

DOMAIN is "VS". STUDYID is the ODM study OID and USUBJID is the ODM subject key, each as given. VISIT is "DAY 1" on every record. Each planned time point is collected on its own vital-signs form, and the form fixes the planned time point of every result on it: VSTPT is "PRE-DOSE", "30 MIN POST-DOSE", "1 H POST-DOSE", or "4 H POST-DOSE" for the form. VSTPTNUM is the planned time point number for the form: 1, 2, 3, or 4 in schedule order. VSELTM is the planned elapsed time since the first dose for the form, in ISO 8601 duration form: "-PT15M" before the dose, then "PT30M", "PT1H", and "PT4H" after it. VSTPTREF is "FIRST DOSE" on every record, the reference time point VSELTM counts from. VSRFTDTC is the datetime of that first dose, the start datetime on the subject's dosing form, as given. VSTESTCD is the test short name the test dictionary gives for the result's item: "PULSE", "SYSBP", or "DIABP". An item with no dictionary entry, such as the collection datetime item or a dosing item, gives no record. VSORRES is the result in original units, the value on the test's item row within the form. VSORRESU is the original unit from the test dictionary: "beats/min" for pulse and "mmHg" for blood pressure. VSSTRESN is the numeric result in standard units; pulse and blood pressure were collected in standard units, so it equals the original result. VSSTRESU is the standard unit, the same as the original unit. VSDTC is the actual collection datetime from the form's datetime item row, the same for every result on that form. VSDY is the study day of the collection datetime, counted from the subject's reference start date in DM, and has no value when the subject has no reference start date. VSSEQ numbers each subject's records from 1 in schedule order by planned time point, then pulse, systolic blood pressure, and diastolic blood pressure within each time point. The planned elapsed time stays next to the actual collection datetime, so a reading taken later than planned keeps its late actual datetime.

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

prompts/sdtm-vs-planned-time-points/conventions.md

Edit
17 lines

Following CDISC SDTM standards, use the provided DM, ODM, and VS_MAPPING datasets to create a VS dataset with one record per collected vital-signs result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, VSSEQ, VISIT, VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSTESTCD, VSORRES, VSORRESU, VSSTRESN, VSSTRESU, VSDTC, VSDY

DOMAIN is "VS". VISIT is "DAY 1" on every record. VSTPT is "PRE-DOSE", "30 MIN POST-DOSE", "1 H POST-DOSE", or "4 H POST-DOSE". VSTPTNUM is 1, 2, 3, or 4 in schedule order. VSELTM is in ISO 8601 duration form: "-PT15M", "PT30M", "PT1H", or "PT4H". VSTPTREF is "FIRST DOSE". VSTESTCD is "PULSE", "SYSBP", or "DIABP". VSDY is the study day of the collection datetime, counted from the subject's reference start date in DM, or has no value.

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

prompts/sdtm-vs-planned-time-points/brief.md

Edit
10 lines

Following CDISC SDTM standards, use the provided DM, ODM, and VS_MAPPING datasets to create a VS dataset with one record per collected vital-signs result.

The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, VSSEQ, VISIT, VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSTESTCD, VSORRES, VSORRESU, VSSTRESN, VSSTRESU, VSDTC, VSDY

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

yamaa code

Public calls generated from benchmark.yaml; results must match the expected output

R

Edit
3 lines
library(yamaa)yamaa_spec("spec.yaml")$run()$output

Python

Edit
3 lines
import yamaayamaa.spec("spec.yaml").run().output

Solution without yamaa

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

solutions/sdtm-vs-planned-time-points/result.R

Edit
114 lines
# Reference solution for the yamaa benchmark sdtm-vs-planned-time-points (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(lubridate)library(readr)library(tidyr)study_day <- function(ref, coll) {  if (is.na(ref) || is.na(coll)) {    return(NA_integer_)  }  delta <- as.integer(coll - ref)  if (delta >= 0L) delta + 1L else delta}time_point <- function(form) {  name <- toupper(form)  if (grepl("PREDOSE", name, fixed = TRUE)) {    list(vstpt = "PRE-DOSE", vstptnum = 1L, vseltm = "-PT15M")  } else if (grepl("30MIN", name, fixed = TRUE)) {    list(vstpt = "30 MIN POST-DOSE", vstptnum = 2L, vseltm = "PT30M")  } else if (grepl("1H", name, fixed = TRUE)) {    list(vstpt = "1 H POST-DOSE", vstptnum = 3L, vseltm = "PT1H")  } else if (grepl("4H", name, fixed = TRUE)) {    list(vstpt = "4 H POST-DOSE", vstptnum = 4L, vseltm = "PT4H")  } else {    NULL  }}dm <- read_csv(  "/app/input/dm.csv",  col_types = cols(.default = col_character()))odm <- read_csv(  "/app/input/odm.csv",  col_types = cols(.default = col_character()))mapping <- read_csv(  "/app/input/vs_mapping.csv",  col_types = cols(.default = col_character()))ref_map <- setNames(suppressWarnings(ymd(dm$RFSTDTC)), dm$USUBJID)# The first-dose datetime on each subject's dosing form is the reference# time point every planned elapsed time counts from.doses <- odm |>  filter(FormOID == "FO.EX", ItemOID == "IT.EX.EXSTDTC") |>  select(SubjectKey, VSRFTDTC = Value)test_map <- setNames(mapping$VSTESTCD, mapping$ItemOID)unit_map <- setNames(mapping$UNIT, mapping$ItemOID)forms <- odm |>  filter(StudyEventOID == "SE.D1", grepl("^FO\\.VS_", FormOID)) |>  group_by(SubjectKey, FormOID, StudyOID) |>  summarise(    vsdtc = Value[ItemOID == "IT.VS.VSDTC"][1],    .groups = "drop"  )results <- odm |>  filter(    StudyEventOID == "SE.D1",    grepl("^FO\\.VS_", FormOID),    ItemOID %in% names(test_map),    !is.na(Value) & Value != ""  ) |>  left_join(forms, by = c("SubjectKey", "FormOID", "StudyOID")) |>  left_join(doses, by = "SubjectKey") |>  rowwise() |>  mutate(    point = list(time_point(FormOID)),    VSTPT = point$vstpt,    VSTPTNUM = point$vstptnum,    VSELTM = point$vseltm,    VSTPTREF = "FIRST DOSE",    VSTESTCD = test_map[[ItemOID]],    VSORRES = Value,    VSORRESU = unit_map[[ItemOID]],    VSSTRESN = suppressWarnings(as.numeric(Value)),    VSSTRESU = VSORRESU,    VSDTC = vsdtc,    ref = ref_map[[SubjectKey]],    VSDY = study_day(ref, suppressWarnings(as_date(ymd_hms(VSDTC)))),    test_ord = case_when(      VSTESTCD == "PULSE" ~ 1L,      VSTESTCD == "SYSBP" ~ 2L,      .default = 3L    )  ) |>  ungroup() |>  filter(!is.na(VSTPT), !is.na(VSDTC) & VSDTC != "") |>  arrange(SubjectKey, VSTPTNUM, test_ord) |>  group_by(SubjectKey) |>  mutate(VSSEQ = row_number()) |>  ungroup() |>  arrange(SubjectKey, VSSEQ) |>  transmute(    DOMAIN = "VS",    STUDYID = StudyOID,    USUBJID = SubjectKey,    VSSEQ,    VISIT = "DAY 1",    VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSTESTCD, VSORRES, VSORRESU,    VSSTRESN, VSSTRESU, VSDTC, VSDY  )dir.create("/app/output", showWarnings = FALSE)write_csv(results, "/app/output/vs.csv", na = "")

solutions/sdtm-vs-planned-time-points/result.py

Edit
152 lines
# Reference solution for the yamaa benchmark sdtm-vs-planned-time-points (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."""Build the SDTM VS dataset from DM, ODM, and VS_MAPPING.One record per collected vital-signs result. Each vital-signs form fixesthe planned time point of every result on it; the form's datetime itemgives the actual collection datetime for all results on that form."""import csvfrom datetime import date, datetimefrom pathlib import PathINPUT = Path("/app/input")OUTPUT = Path("/app/output")# Form OID -> (VSTPT, VSTPTNUM, VSELTM)FORM_TIMEPOINTS = {    "FO.VS_PREDOSE": ("PRE-DOSE", 1, "-PT15M"),    "FO.VS_30MIN": ("30 MIN POST-DOSE", 2, "PT30M"),    "FO.VS_1H": ("1 H POST-DOSE", 3, "PT1H"),    "FO.VS_4H": ("4 H POST-DOSE", 4, "PT4H"),}# Test order within a time point for VSSEQ.TEST_ORDER = {"PULSE": 0, "SYSBP": 1, "DIABP": 2}COLUMNS = [    "DOMAIN", "STUDYID", "USUBJID", "VSSEQ", "VISIT", "VSTPT",    "VSTPTNUM", "VSELTM", "VSTPTREF", "VSRFTDTC", "VSTESTCD", "VSORRES",    "VSORRESU", "VSSTRESN", "VSSTRESU", "VSDTC", "VSDY",]def read_csv(path):    with open(path, newline="", encoding="utf-8") as handle:        return list(csv.DictReader(handle))def study_day(collection, reference):    """SDTM study day: reference day is day 1, no day zero."""    if not collection or not reference:        return ""    delta = (collection - reference).days    return delta + 1 if delta >= 0 else deltadef numeric_text(value):    number = float(value)    return str(int(number)) if number == int(number) else str(number)def main():    dm_rows = read_csv(INPUT / "dm.csv")    odm_rows = read_csv(INPUT / "odm.csv")    mapping_rows = read_csv(INPUT / "vs_mapping.csv")    reference_start = {}    for row in dm_rows:        value = (row.get("RFSTDTC") or "").strip()        reference_start[row["USUBJID"]] = (            datetime.strptime(value[:10], "%Y-%m-%d").date() if value else None        )    dictionary = {        row["ItemOID"]: (row["VSTESTCD"], row["UNIT"]) for row in mapping_rows    }    # The first-dose datetime on each subject's dosing form is the reference    # time point every planned elapsed time counts from.    first_dose = {        row["SubjectKey"]: row["Value"].strip()        for row in odm_rows        if row["FormOID"] == "FO.EX" and row["ItemOID"] == "IT.EX.EXSTDTC"    }    # Group ODM item rows by subject and form occurrence.    forms = {}    for row in odm_rows:        form_oid = row["FormOID"]        if form_oid not in FORM_TIMEPOINTS:            continue        key = (            row["StudyOID"],            row["SubjectKey"],            row["StudyEventOID"],            row["StudyEventRepeatKey"],            form_oid,            row["FormRepeatKey"],            row["ItemGroupOID"],            row["ItemGroupRepeatKey"],        )        forms.setdefault(key, {})[row["ItemOID"]] = row["Value"]    records = []    for key, items in forms.items():        study_id, subject = key[0], key[1]        vstpt, vstptnum, vseltm = FORM_TIMEPOINTS[key[4]]        vsdtc = (items.get("IT.VS.VSDTC") or "").strip()        collection_date = (            datetime.strptime(vsdtc[:10], "%Y-%m-%d").date() if vsdtc else None        )        vsdy = study_day(collection_date, reference_start.get(subject))        for item_oid, (testcd, unit) in dictionary.items():            if item_oid not in items:                continue            value = items[item_oid]            records.append(                {                    "DOMAIN": "VS",                    "STUDYID": study_id,                    "USUBJID": subject,                    "VISIT": "DAY 1",                    "VSTPT": vstpt,                    "VSTPTNUM": vstptnum,                    "VSELTM": vseltm,                    "VSTPTREF": "FIRST DOSE",                    "VSRFTDTC": first_dose.get(subject, ""),                    "VSTESTCD": testcd,                    "VSORRES": value,                    "VSORRESU": unit,                    "VSSTRESN": numeric_text(value),                    "VSSTRESU": unit,                    "VSDTC": vsdtc,                    "VSDY": vsdy,                    "_test_order": TEST_ORDER[testcd],                }            )    records.sort(        key=lambda r: (r["USUBJID"], r["VSTPTNUM"], r["_test_order"])    )    counters = {}    for record in records:        subject = record["USUBJID"]        counters[subject] = counters.get(subject, 0) + 1        record["VSSEQ"] = counters[subject]        del record["_test_order"]    OUTPUT.mkdir(parents=True, exist_ok=True)    with open(OUTPUT / "vs.csv", "w", newline="", encoding="utf-8") as handle:        writer = csv.DictWriter(handle, fieldnames=COLUMNS)        writer.writeheader()        writer.writerows(records)if __name__ == "__main__":    main()

solutions/sdtm-vs-planned-time-points/result.sas

Edit
55 lines
/* opensas reference solution for the yamaa benchmark sdtm-vs-planned-time-points.   Reads the benchmark inputs and derives the requested output.   Execute with the existing opensas runtime: opensas /app/output/result.sas. */data dm;  length STUDYID USUBJID RFSTDTC $1024;  infile "/app/input/dm.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input STUDYID : $char1024. USUBJID : $char1024. RFSTDTC : $char1024.;run;data odm;  length StudyOID MetaDataVersionOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey ItemGroupOID ItemGroupRepeatKey ItemOID Value $1024;  infile "/app/input/odm.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input StudyOID : $char1024. MetaDataVersionOID : $char1024. SubjectKey : $char1024. StudyEventOID : $char1024. StudyEventRepeatKey : $char1024. FormOID : $char1024. FormRepeatKey : $char1024. ItemGroupOID : $char1024. ItemGroupRepeatKey : $char1024. ItemOID : $char1024. Value : $char1024.;run;data vs_mapping;  length ItemOID VSTESTCD VSTEST UNIT $1024;  infile "/app/input/vs_mapping.csv" dsd dlm="," firstobs=2 truncover lrecl=32767;  input ItemOID : $char1024. VSTESTCD : $char1024. VSTEST : $char1024. UNIT : $char1024.;run;proc sort data=odm out=ordered; by StudyOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey; run;data dates;  length VSDTC $1024;  retain VSDTC;  set ordered;  where ItemGroupOID='IG.VS';  by StudyOID SubjectKey StudyEventOID StudyEventRepeatKey FormOID FormRepeatKey;  if first.FormRepeatKey then do;    VSDTC='';  end;    if ItemOID='IT.VS.VSDTC' then VSDTC=Value;  if last.FormRepeatKey then output;run;/* The first-dose datetime on the dosing form is the reference time point. */data doses; set odm; where FormOID='FO.EX' and ItemOID='IT.EX.EXSTDTC'; length VSRFTDTC $1024; VSRFTDTC=Value; keep StudyOID SubjectKey VSRFTDTC; run;proc sql; create table joined as select a.*,b.VSDTC,c.VSTESTCD,c.UNIT,d.RFSTDTC,e.VSRFTDTC from odm a inner join dates b on a.StudyOID=b.StudyOID and a.SubjectKey=b.SubjectKey and a.StudyEventOID=b.StudyEventOID and a.StudyEventRepeatKey=b.StudyEventRepeatKey and a.FormOID=b.FormOID and a.FormRepeatKey=b.FormRepeatKey inner join vs_mapping c on a.ItemOID=c.ItemOID left join dm d on a.StudyOID=d.STUDYID and a.SubjectKey=d.USUBJID left join doses e on a.StudyOID=e.StudyOID and a.SubjectKey=e.SubjectKey; quit;data prepared; set joined; length DOMAIN $2 STUDYID USUBJID VISIT VSTPT VSELTM VSTPTREF VSORRES VSORRESU VSSTRESU $1024; DOMAIN='VS'; VSTPTREF='FIRST DOSE'; STUDYID=StudyOID; USUBJID=SubjectKey; VISIT='DAY 1'; VSTPT=''; VSELTM=''; VSTPTNUM=.;if FormOID='FO.VS_PREDOSE' then do; VSTPT='PRE-DOSE'; VSTPTNUM=1; VSELTM='-PT15M'; end;if FormOID='FO.VS_30MIN' then do; VSTPT='30 MIN POST-DOSE'; VSTPTNUM=2; VSELTM='PT30M'; end;if FormOID='FO.VS_1H' then do; VSTPT='1 H POST-DOSE'; VSTPTNUM=3; VSELTM='PT1H'; end;if FormOID='FO.VS_4H' then do; VSTPT='4 H POST-DOSE'; VSTPTNUM=4; VSELTM='PT4H'; end;VSORRES=Value; VSORRESU=UNIT; VSSTRESU=UNIT; VSSTRESN=input(Value,best32.); VSDY=.; if lengthn(VSDTC)>=10 and lengthn(RFSTDTC)>=10 then do; VSDY=input(substr(VSDTC,1,10),yymmdd10.)-input(substr(RFSTDTC,1,10),yymmdd10.); if VSDY>=0 then VSDY+1; end;TESTORD=3; if VSTESTCD='PULSE' then TESTORD=1; if VSTESTCD='SYSBP' then TESTORD=2; run;proc sort data=prepared; by STUDYID USUBJID VSTPTNUM TESTORD; run;data result; set prepared; by STUDYID USUBJID; retain VSSEQ;  if first.USUBJID then VSSEQ=0;  VSSEQ+1;run;proc sql;  create table final as select DOMAIN, STUDYID, USUBJID, VSSEQ, VISIT, VSTPT, VSTPTNUM, VSELTM, VSTPTREF, VSRFTDTC, VSTESTCD, VSORRES, VSORRESU, VSSTRESN, VSSTRESU, VSDTC, VSDY from result;quit;proc export data=final outfile="/app/output/vs.csv" dbms=csv replace; run;