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
README.mdPublic entries: Python and R. Passing coverage requires an installed inventory.
Goal: build one Disposition (DS) record per subject
for each of four study events carried in a single ODM
item extract: informed consent and randomization as
protocol milestones, and end of treatment and end of
study as disposition events. Each event gives its own
reported term (DSTERM), controlled term (DSDECOD),
category (DSCAT), subcategory (DSSCAT) and date
(DSSTDTC), with DSSEQ numbering each subject's
records in the order they happened.
Input: one ODM file (input/odm.csv) with one row
per collected item value, keyed by study, subject,
study event, form and item. The four study events are
CONSENT, RAND, EOT and EOS; every form carries
a date item (IT.DS.DTC), and the treatment and study
forms also carry a completion status (IT.DS.COMP), a
reported reason (IT.DS.REASON) and a standardized
reason (IT.DS.REASONCD).
Variables:
DSSEQnumbers each subject's records in the order they happened, byDSSTDTCand then byDSTERM, so records on the same day keep a fixed order. WithSTUDYIDandUSUBJIDit identifies the record.DSTERMholds the reported term: the controlled term for a milestone;COMPLETEDwhen the completion status says so, orSCREEN FAILUREat end of study when it says so; else the collected reason.DSDECODholds the controlled term: the same term asDSTERMfor a milestone, a completion or a screen failure, else the collected standardized reason.DSCATfollows the event, not the term:PROTOCOL MILESTONEfor consent and randomization,DISPOSITION EVENTfor end of treatment and end of study.DSSCATnames the event:INFORMED CONSENT,RANDOMIZATION,END OF TREATMENTorEND OF STUDY.DSSTDTCis the collected date item for that record.
Note: each collected form gives one record and an event with no form gives none, so a screen failure has only its consent and end-of-study records.
Provenance: DSCAT/DSSCAT/DSTERM/DSDECOD follow
the CDISC SDTMIG DS assumptions (protocol milestones
carry the same value in DSTERM and DSDECOD), and the
controlled terms follow the FDA Technical Conformance
Guide DS guidance. All subjects, dates and reasons are
invented fixtures.
Inputs
Under review1 source fileinput/odm.csv
Edit40 rows| StudyOID | MetaDataVersionOID | SubjectKey | StudyEventOID | StudyEventRepeatKey | ItemGroupOID | ItemGroupRepeatKey | ItemOID | Value |
|---|---|---|---|---|---|---|---|---|
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-05 |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-05 |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | RAND | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-06-10 |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.COMP | COMPLETED |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | EOT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-07-15 |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | COMPLETED |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 001 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-08 |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 002 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-09 |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 002 | RAND | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-03-20 |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.COMP | DISCONTINUED |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.REASON | Severe nausea |
| YAMAA-01 | MDV.1 | 002 | EOT | 1 | IG.DS | 1 | IT.DS.REASONCD | ADVERSE EVENT |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-03-25 |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | DISCONTINUED |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | Subject moved |
| YAMAA-01 | MDV.1 | 002 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | LOST TO FOLLOW-UP |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-12 |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.COMP | — |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 003 | CONSENT | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.DTC | 2024-01-14 |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.COMP | SCREEN FAILURE |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.REASON | — |
| YAMAA-01 | MDV.1 | 003 | EOS | 1 | IG.DS | 1 | IT.DS.REASONCD | — |
Expected output
Under review10 expected rowsexpected/ds.csv
Edit10 rows| DOMAIN | STUDYID | USUBJID | DSSEQ | DSTERM | DSDECOD | DSCAT | DSSCAT | DSSTDTC |
|---|---|---|---|---|---|---|---|---|
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-05 | |
| DS | YAMAA-01 | 2 | RANDOMIZED | RANDOMIZED | PROTOCOL MILESTONE | RANDOMIZATION | 2024-01-05 | |
| DS | YAMAA-01 | 3 | COMPLETED | COMPLETED | DISPOSITION EVENT | END OF TREATMENT | 2024-06-10 | |
| DS | YAMAA-01 | 4 | COMPLETED | COMPLETED | DISPOSITION EVENT | END OF STUDY | 2024-07-15 | |
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-08 | |
| DS | YAMAA-01 | 2 | RANDOMIZED | RANDOMIZED | PROTOCOL MILESTONE | RANDOMIZATION | 2024-01-09 | |
| DS | YAMAA-01 | 3 | Severe nausea | ADVERSE EVENT | DISPOSITION EVENT | END OF TREATMENT | 2024-03-20 | |
| DS | YAMAA-01 | 4 | Subject moved | LOST TO FOLLOW-UP | DISPOSITION EVENT | END OF STUDY | 2024-03-25 | |
| DS | YAMAA-01 | 1 | INFORMED CONSENT OBTAINED | INFORMED CONSENT OBTAINED | PROTOCOL MILESTONE | INFORMED CONSENT | 2024-01-12 | |
| DS | YAMAA-01 | 2 | SCREEN FAILURE | SCREEN FAILURE | DISPOSITION EVENT | END OF STUDY | 2024-01-14 |
Human review and assessment
| Variable Name | Variable Label | Type | Length | Controlled Terms or Format | Origin | Core | Conversion Definition | Variable Type | Variable Order | Comments for Define |
|---|---|---|---|---|---|---|---|---|---|---|
| DOMAIN | Domain Abbreviation | Char | DS | Assigned | Set constant value "DS". | SDTM | 1 | |||
| STUDYID | Study Identifier | Char | Collected | Copy value from ODM.StudyOID. | SDTM | 2 | ||||
| USUBJID | Unique Subject Identifier | Char | Derived | Fill the template "{STUDYID}-{SUBJKEY}". | SDTM | 3 | ||||
| DSTERM | Reported Term for the Disposition Event | Char | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 4 | ||||
| DSDECOD | Standardized Disposition Term | Char | INFORMED CONSENT OBTAINED, RANDOMIZED, COMPLETED, ADVERSE EVENT, LOST TO FOLLOW-UP, SCREEN FAILURE | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 5 | |||
| DSCAT | Category for Disposition Event | Char | PROTOCOL MILESTONE, DISPOSITION EVENT | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 6 | |||
| DSSCAT | Subcategory for Disposition Event | Char | INFORMED CONSENT, RANDOMIZATION, END OF TREATMENT, END OF STUDY | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 7 | |||
| DSSTDTC | Start Date/Time of Disposition Event | Char | ISO 8601 | Derived | Set per constructed row; see the Row construction sheet. | SDTM | 8 | |||
| DSSEQ | Sequence Number | Num | Derived | Row number within each group of STUDYID, USUBJID, ordered by DSSTDTC then DSTERM. | SDTM | 9 |
| Template | Include when | EVENT | COMPSTAT | DSTERM | DSDECOD | DSCAT | DSSCAT | DSSTDTC |
|---|---|---|---|---|---|---|---|---|
| consent | EVENT = 'CONSENT' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | Constant "INFORMED CONSENT OBTAINED" | Constant "INFORMED CONSENT OBTAINED" | Constant "PROTOCOL MILESTONE" | Constant "INFORMED CONSENT" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| randomization | EVENT = 'RAND' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | Constant "RANDOMIZED" | Constant "RANDOMIZED" | Constant "PROTOCOL MILESTONE" | Constant "RANDOMIZATION" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| end_of_treatment | EVENT = 'EOT' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASON' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASONCD' | Constant "DISPOSITION EVENT" | Constant "END OF TREATMENT" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| end_of_study | EVENT = 'EOS' | Copy ODM.StudyEventOID | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.COMP' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; If COMPSTAT = 'SCREEN FAILURE' then "SCREEN FAILURE"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASON' | If COMPSTAT = 'COMPLETED' then "COMPLETED"; If COMPSTAT = 'SCREEN FAILURE' then "SCREEN FAILURE"; otherwise aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.REASONCD' | Constant "DISPOSITION EVENT" | Constant "END OF STUDY" | Aggregate ONLY(ODM.Value) over records matching on the shared output keys, where ODM.ItemOID = 'IT.DS.DTC' |
| Variable | Permitted values |
|---|---|
| DOMAIN | DS |
| DSDECOD | INFORMED CONSENT OBTAINED, RANDOMIZED, COMPLETED, ADVERSE EVENT, LOST TO FOLLOW-UP, SCREEN FAILURE |
| DSCAT | PROTOCOL MILESTONE, DISPOSITION EVENT |
| DSSCAT | INFORMED CONSENT, RANDOMIZATION, END OF TREATMENT, END OF STUDY |
| Version | Date | Author | Description | Reviewer | Sign-off |
|---|---|---|---|---|---|
| 1.7 | 2026-10-20 | yamaa docs build | Read 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.6 | 2026-10-17 | yamaa docs build | Describe collected date parts written as ISO 8601 date text and times of day counted in seconds since midnight | ||
| 1.5 | 2026-10-17 | yamaa docs build | Name 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.4 | 2026-10-15 | yamaa docs build | State datetime precision codes through the hour and minute, and complete only the time parts a collected datetime lacks | ||
| 1.3 | 2026-09-29 | yamaa docs build | Show study codelist names, external dictionaries, and ISO 8601 formats in variable rows; list the document's codelist values and metadata | ||
| 1.2 | 2026-09-29 | yamaa docs build | Classify ADaM copies from a declared input as Predecessor and recodes as Derived, and SDTM recodes of locally derived columns as Derived | ||
| 1.1 | 2026-09-29 | yamaa docs build | Resolve lookups into the donor record they select, and give every derivation shape a plain-language rule instead of its raw YAML | ||
| 1.0 | yamaa docs build | Initial generation from spec.yaml |
prompts/sdtm-ds-multi-form-disposition/full.md
Edit29 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
DOMAIN is "DS". STUDYID is the ODM study OID, and USUBJID is the study OID and the subject key joined with a hyphen. Each collected form gives one record, and a study event with no form gives none. The study event names the event: "CONSENT" is informed consent, "RAND" is randomization, "EOT" is end of treatment and "EOS" is end of study. DSCAT is "PROTOCOL MILESTONE" for informed consent and randomization and "DISPOSITION EVENT" for end of treatment and end of study. DSSCAT is "INFORMED CONSENT" for informed consent, "RANDOMIZATION" for randomization, "END OF TREATMENT" for end of treatment and "END OF STUDY" for end of study. For a protocol milestone, DSTERM and DSDECOD both hold the controlled term, "INFORMED CONSENT OBTAINED" for informed consent and "RANDOMIZED" for randomization. For end of treatment and end of study, DSTERM is "COMPLETED" when the form's completion status is "COMPLETED", and at end of study it is "SCREEN FAILURE" when the completion status is "SCREEN FAILURE"; otherwise DSTERM is the reason reported on the form. DSDECOD holds the same term as DSTERM for a milestone, a completion or a screen failure, and otherwise the standardized reason collected on the form. DSSTDTC is the date collected on the form. DSSEQ numbers each subject's records from 1 in the order they happened, by DSSTDTC and then by DSTERM, so records on the same day keep a fixed order.
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
prompts/sdtm-ds-multi-form-disposition/conventions.md
Edit14 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
DOMAIN is "DS". DSCAT is "PROTOCOL MILESTONE" or "DISPOSITION EVENT". DSSCAT is "INFORMED CONSENT", "RANDOMIZATION", "END OF TREATMENT" or "END OF STUDY". DSTERM and DSDECOD take the controlled terms "INFORMED CONSENT OBTAINED" and "RANDOMIZED", and DSTERM also takes "COMPLETED" and "SCREEN FAILURE".
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
prompts/sdtm-ds-multi-form-disposition/brief.md
Edit8 linesFollowing CDISC SDTM standards, use the provided ODM dataset to create a DS dataset with one record per subject per study event.
The output dataset should contain the following columns in this order: DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC
Read the source datasets from /app/input and save the completed dataset as /app/output/ds.csv.
R
Edit3 lineslibrary(yamaa)yamaa_spec("spec.yaml")$run()$outputPython
Edit3 linesimport yamaayamaa.spec("spec.yaml").run().outputsolutions/sdtm-ds-multi-form-disposition/result.R
Edit79 lines# Reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition (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(tidyr)odm <- read_csv( "/app/input/odm.csv", col_types = cols(.default = col_character()))wide <- odm |> group_by(StudyOID, SubjectKey, StudyEventOID) |> summarise( DTC = Value[ItemOID == "IT.DS.DTC"][1], COMP = Value[ItemOID == "IT.DS.COMP"][1], REASON = Value[ItemOID == "IT.DS.REASON"][1], REASONCD = Value[ItemOID == "IT.DS.REASONCD"][1], .groups = "drop" )ds <- wide |> rowwise() |> mutate( DSTERM = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT OBTAINED", StudyEventOID == "RAND" ~ "RANDOMIZED", StudyEventOID == "EOT" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOT" ~ REASON, StudyEventOID == "EOS" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOS" & COMP == "SCREEN FAILURE" ~ "SCREEN FAILURE", StudyEventOID == "EOS" ~ REASON, .default = NA_character_ ), DSDECOD = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT OBTAINED", StudyEventOID == "RAND" ~ "RANDOMIZED", StudyEventOID == "EOT" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOT" ~ REASONCD, StudyEventOID == "EOS" & COMP == "COMPLETED" ~ "COMPLETED", StudyEventOID == "EOS" & COMP == "SCREEN FAILURE" ~ "SCREEN FAILURE", StudyEventOID == "EOS" ~ REASONCD, .default = NA_character_ ), DSCAT = case_when( StudyEventOID %in% c("CONSENT", "RAND") ~ "PROTOCOL MILESTONE", StudyEventOID %in% c("EOT", "EOS") ~ "DISPOSITION EVENT", .default = NA_character_ ), DSSCAT = case_when( StudyEventOID == "CONSENT" ~ "INFORMED CONSENT", StudyEventOID == "RAND" ~ "RANDOMIZATION", StudyEventOID == "EOT" ~ "END OF TREATMENT", StudyEventOID == "EOS" ~ "END OF STUDY", .default = NA_character_ ) ) |> ungroup() |> filter(StudyEventOID %in% c("CONSENT", "RAND", "EOT", "EOS")) |> mutate( DOMAIN = "DS", STUDYID = StudyOID, USUBJID = paste(StudyOID, SubjectKey, sep = "-"), DSSTDTC = suppressWarnings(as.Date(na_if(DTC, ""))), DSTERM = na_if(DSTERM, ""), DSDECOD = na_if(DSDECOD, "") ) |> arrange(USUBJID, DSSTDTC, DSTERM) |> group_by(USUBJID) |> mutate(DSSEQ = row_number()) |> ungroup() |> select(DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC)dir.create("/app/output", showWarnings = FALSE)write_csv(ds, "/app/output/ds.csv", na = "")solutions/sdtm-ds-multi-form-disposition/result.py
Edit93 lines# Reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition (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 DS dataset from the collected ODM extract.One record per subject per collected form (study event). Reads/app/input/odm.csv (long EAV form: one row per collected item) andwrites /app/output/ds.csv."""import csvimport osfrom collections import OrderedDictINPUT_DIR = "/app/input"OUTPUT_DIR = "/app/output"# StudyEventOID -> (DSCAT, DSSCAT, controlled term for a milestone)EVENT_INFO = { "CONSENT": ("PROTOCOL MILESTONE", "INFORMED CONSENT", "INFORMED CONSENT OBTAINED"), "RAND": ("PROTOCOL MILESTONE", "RANDOMIZATION", "RANDOMIZED"), "EOT": ("DISPOSITION EVENT", "END OF TREATMENT", None), "EOS": ("DISPOSITION EVENT", "END OF STUDY", None),}COLUMNS = ["DOMAIN", "STUDYID", "USUBJID", "DSSEQ", "DSTERM", "DSDECOD", "DSCAT", "DSSCAT", "DSSTDTC"]def main(): with open(os.path.join(INPUT_DIR, "odm.csv"), newline="") as f: rows = list(csv.DictReader(f)) # Group the EAV rows into forms: one form per subject, study event # and repeat keys. A study event with no form gives no record. forms = OrderedDict() for row in rows: key = (row["StudyOID"], row["SubjectKey"], row["StudyEventOID"], row["StudyEventRepeatKey"], row["ItemGroupOID"], row["ItemGroupRepeatKey"]) forms.setdefault(key, {})[row["ItemOID"]] = row["Value"] or "" records = [] for (study_oid, subject_key, event_oid, *_), items in forms.items(): dscat, dsscat, milestone_term = EVENT_INFO[event_oid] completion = items.get("IT.DS.COMP", "") if milestone_term is not None: dsterm = dsdecod = milestone_term elif completion == "COMPLETED": dsterm = dsdecod = "COMPLETED" elif event_oid == "EOS" and completion == "SCREEN FAILURE": dsterm = dsdecod = "SCREEN FAILURE" else: dsterm = items.get("IT.DS.REASON", "") dsdecod = items.get("IT.DS.REASONCD", "") records.append({ "DOMAIN": "DS", "STUDYID": study_oid, "USUBJID": "{}-{}".format(study_oid, subject_key), "DSTERM": dsterm, "DSDECOD": dsdecod, "DSCAT": dscat, "DSSCAT": dsscat, "DSSTDTC": items.get("IT.DS.DTC", ""), }) # DSSEQ numbers each subject's records from 1 in the order they # happened, by DSSTDTC and then by DSTERM. by_subject = OrderedDict() for record in records: by_subject.setdefault(record["USUBJID"], []).append(record) out_rows = [] for subject_records in by_subject.values(): subject_records.sort(key=lambda r: (r["DSSTDTC"], r["DSTERM"])) for seq, record in enumerate(subject_records, start=1): record["DSSEQ"] = seq out_rows.append(record) os.makedirs(OUTPUT_DIR, exist_ok=True) with open(os.path.join(OUTPUT_DIR, "ds.csv"), "w", newline="") as f: writer = csv.DictWriter(f, fieldnames=COLUMNS) writer.writeheader() for record in out_rows: writer.writerow({col: record[col] for col in COLUMNS})if __name__ == "__main__": main()solutions/sdtm-ds-multi-form-disposition/result.sas
Edit44 lines/* opensas reference solution for the yamaa benchmark sdtm-ds-multi-form-disposition. Reads the benchmark inputs and derives the requested output. Execute with the existing opensas runtime: opensas /app/output/result.sas. */data odm; length StudyOID MetaDataVersionOID SubjectKey StudyEventOID StudyEventRepeatKey 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. ItemGroupOID : $char1024. ItemGroupRepeatKey : $char1024. ItemOID : $char1024. Value : $char1024.;run;proc sort data=odm out=ordered; by StudyOID SubjectKey StudyEventOID; run;data wide; length COMP DTC REASON REASONCD $1024; retain COMP DTC REASON REASONCD; set ordered; by StudyOID SubjectKey StudyEventOID; if first.StudyEventOID then do; COMP=''; DTC=''; REASON=''; REASONCD=''; end; if ItemOID='IT.DS.COMP' then COMP=Value; if ItemOID='IT.DS.DTC' then DTC=Value; if ItemOID='IT.DS.REASON' then REASON=Value; if ItemOID='IT.DS.REASONCD' then REASONCD=Value; if last.StudyEventOID then output;run;data prepared; set wide; length DOMAIN $2 STUDYID USUBJID DSTERM DSDECOD DSCAT DSSCAT DSSTDTC $1024;DOMAIN='DS'; STUDYID=StudyOID; USUBJID=SubjectKey; DSCAT='DISPOSITION EVENT'; DSSTDTC=DTC; DSTERM=REASON; DSDECOD=REASONCD;if COMP='COMPLETED' then do; DSTERM='COMPLETED'; DSDECOD='COMPLETED'; end;USUBJID=catx('-',StudyOID,SubjectKey);if StudyEventOID='CONSENT' then do; DSTERM='INFORMED CONSENT OBTAINED'; DSDECOD=DSTERM; DSCAT='PROTOCOL MILESTONE'; DSSCAT='INFORMED CONSENT'; end;if StudyEventOID='RAND' then do; DSTERM='RANDOMIZED'; DSDECOD=DSTERM; DSCAT='PROTOCOL MILESTONE'; DSSCAT='RANDOMIZATION'; end;if StudyEventOID='EOT' then DSSCAT='END OF TREATMENT';if StudyEventOID='EOS' then do; DSSCAT='END OF STUDY'; if COMP='SCREEN FAILURE' then do; DSTERM='SCREEN FAILURE'; DSDECOD=DSTERM; end; end; run;proc sort data=prepared; by STUDYID USUBJID DSSTDTC DSTERM; run;data result; set prepared; by STUDYID USUBJID; retain DSSEQ; if first.USUBJID then DSSEQ=0; DSSEQ+1;run;proc sql; create table final as select DOMAIN, STUDYID, USUBJID, DSSEQ, DSTERM, DSDECOD, DSCAT, DSSCAT, DSSTDTC from result;quit;proc export data=final outfile="/app/output/ds.csv" dbms=csv replace; run;
yamaa