You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.3KB

  1. #' Import patients and their visits
  2. #'
  3. #' Import patients and their visits
  4. #'
  5. #' Import the patient_dimension and visit_dimension death_data
  6. #' As well as creating the mappings and add visit age observations
  7. #'
  8. #' Structure for patient dataframe:
  9. #' - patient_ide : character
  10. #' - encounter_ide : character
  11. #' - start_date : Date
  12. #' - end_date : Date
  13. #' - rum_start : Date
  14. #' - rum_end : Date
  15. #' - birth_date : Date
  16. #' - death_date : Date
  17. #' - sex_cd : char, 'M' or 'F'
  18. #' - provider_id : char, 'STRUCT:xxx'
  19. #'
  20. #' @param patients A formatted dataframe with correctly named columns
  21. #' @param project The project to add the data to
  22. #' @export
  23. import_patients_visits <- function(patients, project)
  24. {
  25. # Patients
  26. patients %>%
  27. dplyr::select(patient_ide, birth_date, death_date, sex_cd) %>%
  28. dplyr::distinct() %>%
  29. add_patients_demodata(project)
  30. # Encounters
  31. patients %>%
  32. dplyr::select(patient_ide, encounter_ide, start_date, end_date) %>%
  33. dplyr::distinct() %>%
  34. dplyr::mutate(inout_cd = "I") %>%
  35. add_encounters(project)
  36. # Observations : Age à l'hospitalisation
  37. patients %>%
  38. dplyr::select(patient_ide, encounter_ide, start_date = rum_start, birth_date, provider_id) %>%
  39. dplyr::distinct() %>%
  40. dplyr::mutate(concept_cd = "HOS:age_hospit",
  41. modifier_cd = "@",
  42. valtype_cd = "N",
  43. tval_char = "E",
  44. nval_num = as.numeric(start_date - birth_date)/365.25) %>%
  45. dplyr::select(-birth_date) %>%
  46. add_observations(project)
  47. }
  48. import_mensurations <- function(mensurations, patients, project)
  49. {
  50. patients %>%
  51. dplyr::inner_join(mensurations) %>%
  52. dplyr::select(patient_ide, encounter_ide, start_date = rum_start, end_date = rum_end, provider_id, concept_cd, nval_num, modifier_cd, valtype_cd, tval_char) %>%
  53. add_observations(project)
  54. }
  55. import_bios <- function(bios, patients, project)
  56. {
  57. bios %>%
  58. dplyr::inner_join(patients, by = c("patient_ide", "encounter_ide")) %>%
  59. dplyr::rename(start_date = start_date.x) %>%
  60. dplyr::filter(start_date >= rum_start & start_date <= rum_end) %>%
  61. dplyr::select(-rum_start, -rum_end, -start_date.y, -sex_cd, -birth_date, -death_date, -project) %>%
  62. dplyr::mutate(modifier_cd = "@",
  63. valtype_cd = "N",
  64. tval_char = "E",
  65. nval_num = nval_num %>% stringr::str_replace(",", ".")) %>%
  66. add_observations(project)
  67. }