# The MC field is a skeleton for constructing new modules
MC:
  # Module informaiton
  module:
    type: "CTS"
    # internal R Object: module ID used in deployment
    depends:
      id_ASM: "ASM"
      id_MB:  "MB"
  element_object_name: "CTS_obj"
# The include section is optional. You can use this section to copy files
# from the directory where you are running the app to the user directory to be
# used in the app and when saved. The source and dest options can be a path
# command like below or a double
# quoted string: '"/path/to/file"'
# The dest should be relative to user directory (think the root of the zip
# file that is exported). See formods.yaml for examples.
#
# include:
#   files:
#   - file:
#       source: 'file.path(system.file(package="onbrand"), "templates", "report.docx")'
#       dest:   'file.path("config","report.docx")'
  code: # module specific code options
    packages: [ "rxode2", "nonmem2rx", "nlmixr2lib"]
    readOnly: TRUE
    mode:     r
  # Controls what is shown in the compact ui mode:
  compact:
    code:    TRUE
    clip:    TRUE
  # This is where you put reporting options. The expected options are shown
  # here, but module-specific options can also be added if needed:
  reporting:
    enabled: TRUE
    # Priority of reporting relative to other modules
    # (higher numbers are reported first)
    priority: 2
    # The following placeholders can be used bu surrounding them with ===. For
    # example to include the total number of figures you would use
    # ===FIGTOT===:
    #
    # CHTDESC               Description of the cohort provided by the
    #                       user in the UI (tables and figures).
    #
    # FIGNUM                Number of the current figure for figures that span
    #                       multiple pages (figures only).
    #
    # FIGTOT                Total number of figures for figures that span
    #                       multiple pages (figures only).
    figures:
      tc:
        caption_single:     "===CHTDESC=== (Time-course)"
        caption_multiple:   "===CHTDESC=== (Time-course, panel ===FIGNUM=== of ===FIGTOT===)"
        title_single:       "===CHTDESC=== (Time-course)"
        title_multiple:     "===CHTDESC=== (Time-course)"
        sub_title_single:   ""
        sub_title_multiple: "===FIGNUM=== of ===FIGTOT==="
      ev:
        caption_single:     "===CHTDESC=== (Event Table)"
        caption_multiple:   "===CHTDESC=== (Event Table, ===FIGNUM=== of ===FIGTOT===)"
        title_single:       "===CHTDESC=== (Event Table)"
        title_multiple:     "===CHTDESC=== (Event Table)"
        sub_title_single:   ""
        sub_title_multiple: "===FIGNUM=== of ===FIGTOT==="
  formatting:
    # Dimensions of code snippet box
    code:
      width:  800
      height: 300
    current_element:
      width:  "200px"
    source_model:
      width:  "200px"
    element_name:
      width:  "200px"
    preview:
      width:  "800px"
      height: "500px"
    input:
    button_clk_run:
      size: "sm"
      block: TRUE
    button_clk_del:
      size: "sm"
      block: TRUE
      tooltip: "Delete the current cohort."
      tooltip_position: "right"
    button_clk_save:
      size: "sm"
      block: TRUE
      tooltip: "Save the name for the current cohort."
      tooltip_position: "right"
    button_clk_runsim:
      size: "sm"
      block: TRUE
      tooltip: "Simulate or resimulate the cohort with the current rules applied."
      tooltip_position: "right"
    button_clk_update_plot:
      size: "sm"
      block: TRUE
      tooltip: "Update timecourse figures."
      tooltip_position: "top"
    button_clk_clip:
      size: "sm"
      block: TRUE
      tooltip: "Copy the code to generate the current cohort to the clipboard."
      tooltip_position: "right"
    button_clk_copy:
      size: "sm"
      block: TRUE
      tooltip: "Make a copy of the current cohort."
      tooltip_position: "right"
    button_clk_new:
      size: "sm"
      block: TRUE
      tooltip: "Create a new cohort."
      tooltip_position: "right"
    button_clk_add_rule:
      size: "sm"
      block: TRUE
      tooltip: "Add a new rule."
      tooltip_position: "right"
    button_clk_add_cov:
      width:  "456px"
      size: "sm"
      block: TRUE
      tooltip: "Define covariate."
      tooltip_position: "right"
    rule_condition:
      width:  300
      height: 100
      tooltip: "This is a condition that should evaluate to either TRUE (if the action should be taken) or FALSE (if it should be skipped)."
      tooltip_position: "bottom"
      placeholder: "examples: TRUE will run the action at at every visit or (time > 0) & (Ac < 10) will be more selective."
    action_dosing_state:
      width:  400
      choices:
        dosing: "Dosing Compartments"
        other:  "Other Compartments"
    action_dosing_values:
      width:  400
      placeholder: "c(1, 1, 1)"
      tooltip: "Expression defining dosing amounts that will evaluate as a numeric vector of numbers."
    action_dosing_times:
      width:  400
      placeholder: "c(0, 7, 14)"
      tooltip: "Expression defining dosing times that will evaluate as a numeric vector of numbers."
      tooltip_position: "bottom"
    action_dosing_durations:
      width:  400
      placeholder: "c(0, 0, 0)"
      tooltip: "Expression containing dosing duration that will evaluate as a numeric vector of numbers (zeros for bolus dosing)."
      tooltip_position: "bottom"
    action_set_state_state:
      width:  400
    action_set_state_value:
      width:  400
      placeholder: "A value like 20 or an expression in terms of a system element such as Ac/2"
      tooltip: "An expression that evaluates to a new number."
    action_manual_code:
      width:  400
      height: 200
      placeholder: |-
        SI_interval_ev = etRbind(SI_interval_ev,
          et(cmt  = 'Ac',
             id   = id,
             amt  = 10,
             evid = 4,
             time = time))
      tooltip: "Expression with code to manually update the event table."
    rule_type:
      width: 300
      options:
        dose:
          choice:      "Dosing"
          subtext:     "Add bolus or infusion dosing"
          value:       "dose"
        state_reset:
          choice:      "Set State"
          subtext:     "Reset the named state or compartment to a specified value"
          value:       "set state"
        manual:
          choice:      "Manual"
          subtext:     "Alter the event table directly."
          value:       "manual"
    config_text:
      width: 150
    config_select:
      width: 150
    config_textarea:
      width:    456
      height:   150
    hot_current_rules:
      width:  800
      height: 400
      no_rules: "No Rules Defined"
    hot_current_covariates:
      width:  800
      height: 400
      no_covariates: "Covariate not yet defined"
    nsub:
      value:  10
      width:  50
      placeholder: 10
      tooltip: "Number of sujbects in the current cohort. Set to 1 to simulate only the typical value."
      tooltip_position: "bottom"
    visit_times:
      value:  0
      width:  150
      placeholder: "c(0, 7, 14, 21)"
      tooltip: "Study visit times."
      tooltip_position: "bottom"
    trial_end:
      value:  100
      width:  150
      placeholder: "100"
      tooltip: "Final simulation time point in simulation units."
      tooltip_position: "bottom"
    covariates:
      none_found: "There were no coviaraites found in this model"
    selected_covariate:
      width:  200
      tooltip: "Pick covariate to define."
      tooltip_position: "right"
    rule_name:
      width:  300
      placeholder: "first_dose"
      tooltip: "This is a unique identifier for the current rule. It should start with a letter and can contain letters, numbers and underscores."
      tooltip_position: "bottom"
    time_scale:
      width:  75
      tooltip: "Select the timescale to plot."
      tooltip_position: "top"
    tc_dim:
      width:  75
      default: "d2x4"
      tooltip: "rows x cols for figures"
      tooltip_position: "top"
      choices:
        d4x4:
          verb: "4x4"
          nrow: 4
          ncol: 4
        d2x4:
          verb: "2x4"
          nrow: 2
          ncol: 4
        d2x2:
          verb: "2x2"
          nrow: 2
          ncol: 2
        d1x1:
          verb: "1x1"
          nrow: 1
          ncol: 1
    dvcols:
      width: 150
      size: 10
      tooltip: "Select the different model outputs, states, etc to plot"
      tooltip_position: "top"
      choices:
        outputs:
          verb: "Outputs"
        states:
          verb: "States"
        parameters:
          verb: "Parameters"
        secondary:
          verb: "Secondary Parameters"
        covariates:
          verb: "Covariates"
    evplot:
      width: 150
      tooltip: "Select the events to plot"
      tooltip_position: "top"
      default: "dose"
      choices:
        dose:
          value: 1
          verb: "Dose"
        set_state:
          value: 4
          verb: "State Resets"
    fpage:
      width:  50
      tooltip: "Go to the selected output page"
      tooltip_position: "top"
  labels:
    current_element:     "Select cohort"
    element_name :       NULL # "cohort name"
    save_btn:            "Save"
    runsim_btn:          "Simulate Cohort"
    running_sim:         "Running simulation. Be patient!"
    update_plot_btn:     "Update Plots"
    clip_btn:            "Code"
    copy_btn:            "Copy"
    del_btn:             "Delete"
    add_rule_btn:        "Add Rule"
    add_cov_btn:         "Add Covariate Details"
    new_btn:             "New"
    source_model:        "Source Model"
    dvcols:              NULL
    evplot:              NULL
    time_scale:          NULL
    rule_type:           "Type of rule"
    rule_condition:      "Condition to trigger rule"
    action_dosing_state: "Dosing into"
    action_dosing_values:    "Values"
    action_dosing_times:     "Times"
    action_manual_code:      "Code to evaluate"
    action_dosing_durations: "Durations"
    action_set_state_state:  "State/compartment to reset"
    action_set_state_value:  "New value for state/compartment"
    nsub:                    "N Subs"
    visit_times:             "Visit Times"
    trial_end:               "End of Trial"
    covariate_values:        "Current values"
    selected_covariate:      "Covariate"
    covariate_type:          "Type/Distribution"
    covariate_value:         "Values"
    switch_output_interactive:  "Interactive"
    switch_output_report:       "Report Preview"
    tab_res_tc_figure:        "Timecourse"
    tab_res_events_figure:    "Events"
    tab_sim_env:              "Simulation Environment"
    tab_chrt_ele_covs:        "Covariates"
    tab_chrt_ele_rules:       "Create Rules"
    tab_chrt_ele_trial:       "Trial Options"
    tab_chrt_ele_sim:         "Simulation Options"
    ds_tc:                    "Timecourse"
    ds_ev:                    "Events"
  errors:
    no_sim_found: "No simulation available, you need to run the simulation first."
    bad_sim:      "There was a problem with the simulation."
    bad_plot:     "There was a problem plotting the simulation results."
    cts_no_fig:   "There are no figures to display. You must run the simulation first"
    no_mdl_found: "There are no source models to use. You need to create a model to use this module."
#   mdl_missing:  "The source model ===MDLLABEL=== (===MDLID===) for ===CHTLABEL=== (===CHTID===) \nwas not found, choose a new source model and simulate."
#   mdl_changed:  "The source model for ===CHTLABEL=== (===CHTID===) has changed. \nYou need to update the simulation"
  tooltips:
    # Set to FALSE to disable tool tips for this module
    include: TRUE
    elements:     "Show cohort rules"
    show_code:    "Show cohort code"
    # Set urls to NULL to disable the icon links.
    url_manual:   "https://ruminate.ubiquity.tools/articles/clinical_trial_simulation.html#example-manual-code-evaluation"
    url_rule_env: "https://ruminate.ubiquity.tools/articles/clinical_trial_simulation.html#rule-evaluation-environment"
  # This is the content in the app that describes the rule evaluation
  # environment. THis code is evaluated in the app. You can use any html tags
  # you like. You also have access to the current state as well as the output
  # of fetch_rxinfo for the current source model (found in the rx_details
  # object).
  rule_env_content: |-
    uiele = tagList(tags$b("Simulation environment"),
                    icon_link(href=state[["MC"]][["tooltips"]][["url_rule_env"]]),
                    tags$br(),
                    "The condition and actions (e.g., dose times, amounts,
                    durations) that are triggered are all
                    evaluated in an environment with different objects that
                    you can use. For details on this see the Clinical Trial Simulation vignette ",
                    icon_link(href=state[["MC"]][["tooltips"]][["url_rule_env"]]),
                    " for more information.")
    uiele = tagList(uiele,
                    tags$br(),
                    tags$br(),
                    "For the current system the following are available:",
                    tags$br())
    uiele = tagList(uiele, tags$br())
    uiele = tagList(uiele, rx_details[["ht_info"]])
  # For details on the simulation options see the help rxode2::rxSolve
  # https://billdenney.github.io/pknca/articles/v40-options-for-controlling-PKNCA.html
  # This section contains information about different options, metadata about
  # them, default values, etc. Using this, the options UI for an analysis is
  # generated automatically. Each configuration option has the following:
  #
  # group        - This is how configuration options will be grouped in the app
  # label        - Short textual description
  # tooltip      - More detailed description of the option and what goes into it.
  #                Set to NULL to not display a tool tip.
  # uitype       - Type of ui to generate can be either text, select, or textarea
  # type         - List of possible types. For example if you have "numeric" then
  #                "character" the value will be evaluated as numeric, if this is
  #                NA then it will be evaluated as character. Allowed types:
  #                  - numeric
  #                  - character
  #                  - logical (TRUE or FALSE)
  # value        - Default value in the UI if it is NULL you need to set it as
  #                "NULL" with quotes. If you want it to be empty set it as
  #                NULL without quotes.
  # options      - These are the options if uitype is set to select
  # use          - This idicates where the configuration is being used. Allowed types:
  #                  - rxSolve
  sim_config:
    atol:
      group:         "ODE Solver"
      label:         "Absolute tolerance"
      tooltip:       "Absolute tolerance used by the ODE solver to determine if a good solution has been achieved; This is also used in the solved linear model to check if prior doses do not add anything to the solution."
      uitype:        "text"
      type:          "numeric"
      value:         1e-8
      options:       NULL
      use:           "rxSolve"
      placeholder:   "1e-8"
    rtol:
      group:         "ODE Solver"
      label:         "Relative tolerance"
      tooltip:       "Relative tolerance used by the ODE solver to determine if a good solution has been achieved. This is also used in the solved linear model to check if prior doses do not add anything to the solution."
      uitype:        "text"
      type:          "numeric"
      value:         1e-6
      options:       NULL
      use:           "rxSolve"
      placeholder:   "1e-6"
    sigdig:
      group:         "ODE Solver"
      label:         "Significant digits"
      tooltip:       'Specifies the "significant digits" that the ode solving requests. When specified this controls the relative and absolute tolerances of the ODE solvers. By default the tolerance is 0.5*10^(-sigdig-2) for regular ODEs. For the sensitivity equations the default is ⁠0.5*10\^(-sigdig-1.5)⁠ (sensitivity changes only applicable for liblsoda). This also controls the atol/rtol of the steady state solutions. The ssAtol/ssRtol is ⁠0.5*10\^(-sigdig)⁠ and for the sensitivities ⁠0.5*10\^(-sigdig+0.625)⁠. By default this is unspecified (NULL) and uses the standard atol/rtol.'
      uitype:        "text"
      type:          "numeric"
      value:         "NULL"
      options:       NULL
      use:           "rxSolve"
      placeholder:   "NULL"
#   method:
#     group:         "ODE Solver"
#     label:         "Solver method"
#     tooltip:       |-
#       The method for solving ODEs currently supports:
#       "liblsoda"- thread safe lsoda. This supports parallel thread-based solving, and ignores user Jacobian specification.
#       "lsoda"  - LSODA solver. Does not support parallel thread-based solving, but allows user Jacobian specification.
#       "dop853" -  DOP853 solver. Does not support parallel thread-based solving nor user Jacobian specification
#       "indLin" -  Solving through inductive linearization. The rxode2 dll must be setup specially to use this solving routine.
#     uitype:        "select"
#     type:          "character"
#     value:         "liblsoda"
#     choices:       ["liblsoda", "lsoda", "dop853", "indLin"]
#     use:           "rxSolve"
#     placeholder:   NULL
    seed:
      group:         "Misc"
      label:         "Random Seed"
      tooltip:       'Integer value to set the seed for the random number generator'
      uitype:        "text"
      type:          "numeric"
      value:         "5446"
      options:       NULL
      use:           "Misc"
      placeholder:   "5446"
    nsteps:
      group:         "Misc"
      label:         "Time Steps"
      tooltip:       'Integer value representing the number of time steps to add between zero and the end of trial. A larger value will give smoother curves but it will also take more time to simulate.'
      uitype:        "text"
      type:          "numeric"
      value:         "200"
      options:       NULL
      use:           "Misc"
      placeholder:   "200"
    preamble:
      group:         "Rule Environment Preamble"
      label:         NULL
      tooltip:       'Optional user-defined code to be executed in the rule-evaluation environment. You can create user-defined functions here.'
      uitype:        "textarea"
      type:          "character"
      value:         NULL
      options:       NULL
      use:           "rules"
      placeholder: |-
        my_func = function(id=NULL){

        }
  covariate_generation:
    tooltip_position: "right"
    width:             200
    # These are the types of covariates that can be constructed. You should
    # only change the placeholder, choice, and tooltip options. The rest are used
    # internally and should not be changed.
    types:
      discrete:
        choice:      "Select from discrete values"
        type:        "discrete"
        placeholder: "0, 1, 2"
        tooltip:    "Provide a list of possible discrete values and these will be randomly selected when genreating subjects."
      fixed:
        choice:      "Fix at value"
        type:        "fixed"
        placeholder: "1"
        tooltip:    "Fix the covariate at a specific value."
      cont_random:
        choice:      "Continuous/random in range"
        type:        "continuous"
        sampling:    "random"
        placeholder: "0,1"
        tooltip:    "Sample randomly from within the specified range."
      cont_normal:
        choice:      "Sample normally"
        type:        "continuous"
        sampling:    "normal"
        placeholder: "mean, variance"
        tooltip:    "Sample from normal distribution provided a mean and variance"
      cont_lognormal:
        choice:      "Sample log-normally"
        type:        "continuous"
        sampling:    "log-normal"
        placeholder: "mean, variance"
        tooltip:    "Sample from log-normal distribution provided a mean and variance"
#   method:
#     group:         "ODE Solver"
#     label:         "Solver method"
#     tooltip:       "Relative tolerance used by the ODE solver to determine if a good solution has been achieved. This is also used in the solved linear model to check if prior doses do not add anything to the solution."
#     uitype:        "select"
#     type:          "numeric"
#     value:         1e-6
#     options:       ["liblsoda", "lsoda", "dop853", "indLin"]
#     use:           "rxSolve"

