# Creating ADOE

# Introduction

This article describes creating an ADOE ADaM with Ophthalmology Exam Analysis data for ophthalmology endpoints. It is to be used in conjunction with the article on creating a BDS dataset from SDTM. As such, derivations and processes that are not specific to ADOE are absent, and the user is invited to consult the aforementioned article for guidance.

As the current release of `{admiralophtha}` does not contain any functionality specific to ADOE, this article only showcases how to map parameters from OE in order to set up the basic structure of ADOE. For the following steps, the user is invited to consult the above-linked article on BDS datasets. This article will be updated for future releases to showcase and explain any `{admiralophtha}`-specific functionality.

Note: All examples assume CDISC SDTM and/or ADaM format as input unless otherwise specified.

## Dataset Contents

`{admiralophtha}` suggests to populate ADOE with general miscellaneous ophthalmology parameters. Any efficacy endpoint-related parameters (eg. BCVA tests) should be placed in separate datasets (eg. ADBCVA).

## Required Packages

The examples of this vignette require the following packages.

    library(dplyr)
    library(admiral)
    library(admiral.test)
    library(admiraldev)
    library(admiralophtha)

# Programming Workflow

- Initial Set Up of ADOE
- Further Derivations of Standard BDS Variables
- Example Script

## Initial set up of ADOE

As with all BDS ADaM datasets, one should start from the OE SDTM, where only the general ophthalmology records are of interest. For the purposes of the next two sections, we shall be using the `{admiral}` OE and ADSL test data. We will also require a lookup table for the mapping of parameter codes.

Note: to simulate an ophthalmology study, we add a randomly generated `STUDYEYE` variable to ADSL, but in practice `STUDYEYE` will already have been derived using `derive_var_studyeye()`.

    data("admiral_oe")
    data("admiral_adsl")

    # Add STUDYEYE to ADSL to simulate an ophtha dataset
    adsl <- admiral_adsl %>%
      as.data.frame() %>%
      mutate(STUDYEYE = sample(c("LEFT", "RIGHT"), n(), replace = TRUE)) %>%
      convert_blanks_to_na()

    oe <- convert_blanks_to_na(admiral_oe) %>%
      ungroup()

    # ---- Lookup table ----

    # Assign PARAMCD, PARAM, and PARAMN
    param_lookup <- tibble::tribble(
      ~OETESTCD, ~AFEYE, ~PARAMCD, ~PARAM, ~PARAMN,
      "CSUBTH", "Study Eye", "SCSUBTH", "Study Eye Center Subfield Thickness (um)", 1,
      "CSUBTH", "Fellow Eye", "FCSUBTH", "Fellow Eye Center Subfield Thickness (um)", 2,
      "DRSSR", "Study Eye", "SDRSSR", "Study Eye Diabetic Retinopathy Severity", 3,
      "DRSSR", "Fellow Eye", "FDRSSR", "Fellow Eye Diabetic Retinopathy Severity", 4,
    )

Following this setup, the programmer can start constructing ADOE. The first step is to subset OE to only general ophthalmology parameters. Then, one can merge the resulting dataset with ADSL. This is required for two reasons: firstly, `STUDYEYE` is crucial in the mapping of `AFEYE` and `PARAMCD`’s. Secondly, the treatment start date (`TRTSDT`) is also a prerequisite for the derivation of variables such as Analysis Day (`ADY`).

    adsl_vars <- exprs(TRTSDT, TRTEDT, TRT01A, TRT01P, STUDYEYE)

    adoe <- oe %>%
      filter(
        OETESTCD %in% c("CSUBTH", "DRSSR")
      ) %>%
      derive_vars_merged(
        dataset_add = adsl,
        new_vars = adsl_vars,
        by_vars = exprs(STUDYID, USUBJID)
      )

## Further Derivations of Standard BDS Variables

The user is invited to consult the article on creating a BDS dataset from SDTM to learn how to add standard BDS variables to ADOE.

## Example Script

ADaM | Sample Code
--- | ---
ADOE | ad_adoe.R