jackwasey / icd

Fast ICD-10 and ICD-9 comorbidities, decoding and validation in R. NB use main instead of master for default branch.
https://jackwasey.github.io/icd/
GNU General Public License v3.0
242 stars 60 forks source link

Hierarchy in HCC is not respected #188

Open VolodymyrClarify opened 5 years ago

VolodymyrClarify commented 5 years ago

Hello!

In the following example Hierarchy is not respected for diabetes (with ICD10 codes as inputs):

pts <- data.frame( patient_id = c( "1", "1", "1" ),
                   icd_code = c( "E099", "E08638", "E13641" ),
                   date = as.Date(c("2019-01-01", "2019-01-01", "2019-01-01" ) ) )

pts

comorbid_hcc( pts )  

Output:

      patient_id       date                  hcc
          1                2019-01-01        17
          1                2019-01-01        18
          1                2019-01-01        19

####################################### Update: It is a bug somewhere in date parameter of the function.

In the following example the hierarchy is working:

pts <- data.frame( patient_id = c( "1", "1", "1" ),
                   icd_code = c( "E099", "E08638", "E13641" ),
                   date = as.Date(c("2018-01-01", "2018-01-01", "2018-01-01" ) ) )

comorbid_hcc( pts )  

# Output
  patient_id       date               hcc
       1               2018-01-01      17
bokov commented 4 years ago

I think the problem might be here:

https://github.com/jackwasey/icd/blob/e54bb247da2e4128c1ba91598767a18160cbff1d/R/hcc.R#L81

x$year is set from the data without validation. Also if the dates are before 2014 or after 2019 you get an empty result.

There should be a way for the user to override the year auto-guessing and apply the same year for all visits because: