ctsit / rcc.billing

Automated, data-driven service billing implemented on REDCap Custodian
https://ctsit.github.io/rcc.billing/
Apache License 2.0
0 stars 3 forks source link

Mark pro-bono service request records #207

Closed pbchase closed 3 months ago

pbchase commented 5 months ago

Create an ETL to mark records as pro-bono. This script will run every two hours from 7 a.m. - 9 p.m. name the etl update_probono_service_request_records or something better if you can thing of one.


# Convert this code block into a function named get_probono_service_request_updates() or some such
# Add a test for this function. 
probono_updates <- service_requests |>
  arrange(record_id, redcap_repeat_instrument, redcap_repeat_instance) |>
  # fill project ids on each record group
  group(record_id) |>
  fill(project_id, .direction = "updown") |>
  ungroup() |>
  filter(!is.na(project_id)) |>
  # Compute time, and time total for each project_id-probono group
  mutate(time = service_request_time(time2, time_more)) |>
  mutate(probono = (billable_rate == 0)) |>
  select(
    record_id,
    redcap_repeat_instrument,
    redcap_repeat_instance,
    project_id,
    probono,
    time,
    billable_rate
    ) |>
  group_by(project_id, probono) |>
  mutate(total_time = sum(time)) |>
  ungroup() |>
  # Copy probono time to each record across a project_id group
  group(project_id) |>
  mutate(probono_time = case_when(
    probono ~ total_time,
    TRUE ~ 0
  )) |>
  mutate(probono_time = max(probono_time)) |>
  # Mark additional records as probono as needed
  filter(probono_time < 1) |>
  arrange(time) |>
  mutate(additional_time = cumsum(time)) |>
  filter(additional_time + probono_time >= 1) |>
  filter(additional_time == min(additional_time)) |>
  mutate(billable_rate = 0) |>
  ungroup() |>
  # keep only enough columns to update the service request DB
  select(
    record_id,
    redcap_repeat_instrument,
    redcap_repeat_instance,
    billable_rate
  )

# update the service request DB
# Log the changes
ljwoodley commented 5 months ago

mutate(probono = (billable_rate == 0))

What's the billable_rate. This column does not exist in service_requests

pbchase commented 5 months ago

What's the billable_rate. This column does not exist in service_requests

It's a draft column in this project: https://redcap.ctsi.ufl.edu/redcap/redcap_v14.3.0/Design/data_dictionary_codebook.php?pid=14952. Sorry I need to merge some of this into the production service request project.

I wrote upon this work as Issues #217

pbchase commented 4 months ago

I wrote upon this work as Issues #217

Issues #217 is now done and closed

pbchase commented 3 months ago

addressed by #218