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.

79 lines
2.5KB

  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 = "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::left_join(mensurations) %>%
  52. dplyr::select(patient_ide, encounter_ide, provider_id, start_date = rum_start, end_date = rum_end, poids, taille, IMC) %>%
  53. tidyr::gather(concept_cd, nval_num, poids, taille, IMC) %>%
  54. dplyr::filter(!is.na(nval_num)) %>%
  55. dplyr::mutate(concept_cd = stringr::str_c("HOS:", concept_cd),
  56. modifier_cd = "@",
  57. valtype_cd = "N",
  58. tval_char = "E",
  59. nval_num = nval_num %>% str_replace(",", ".")) %>%
  60. add_observations(project)
  61. }
  62. import_bios <- function(bios, patients, project)
  63. {
  64. bios %>%
  65. dplyr::left_join(patients, by = c("patient_ide", "encounter_ide")) %>%
  66. dplyr::filter(start_date >= rum_start & start_date <= rum_end) %>%
  67. dplyr::select(-rum_start, -rum_end) %>%
  68. dplyr::mutate(modifier_cd = "@",
  69. valtype_cd = "N",
  70. tval_char = "E",
  71. nval_num = nval_num %>% stringr::str_replace(",", ".")) %>%
  72. add_observations(project)
  73. }