Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link_ae_inpatient breaks when using the record_id argument #7

Open
andreamazzella opened this issue Nov 12, 2024 · 0 comments
Open

Comments

@andreamazzella
Copy link

I tried using link_ae_inpatient to join some ecds data with sus data. I have an incident-specific patient identifier that I would like to keep in the linked dataset, so I used the record_id = argument.

hoslink <- link_ae_inpatient(
    ae = list(
        data = ecds,
        record_id = "patient_id",
        arrival_date = 'arrival_date',
        departure_date = 'departure_date',
        nhs_number = 'nhs_number',
        patient_dob = 'patient_birth_date',
        hospital_number = 'local_patient_identifier',
        org_code = 'organisation_code_of_provider'
    ),
    inp = list(
        data = sus,
        record_id = "patient_id",
        spell_start_date = 'spell_start_date',
        spell_id = 'mega_spell_id',
        nhs_number = 'nhs_number',
        patient_dob = 'birth_date',
        hospital_number = 'local_patient_identifier',
        org_code = 'organisation_code_code_of_provider'
    ),
    .forceCopy = FALSE
)

This results in the following error:

Error in data.table::fifelse(is.na(NULL), NULL, NULL) :
attempt to set an attribute on NULL

This seems to be because within the function code, line 474 (copied below) is expecting list ae to be 7-element long, but in this case we include also record_id, so it's an 8-element list.

ids <- as.vector(unlist(lapply(ae[c(4:length(ae))],`[[`,1)))

ids returns:

"departure_date" "nhs_number" "patient_birth_date" "local_patient_identifier" "organisation_code_of_provider"

So then in the for loop that follows (copied below), fifelse(is.na(departure_date.ae), ... doesn't find departure_date.ae and the function breaks.

  for(i in ids){
    link[,(i) := data.table::fifelse(is.na(v1),v2,v1),
         env = list(
           v1 = linknames[[i]][1],
           v2 = linknames[[i]][2]
         )
    ]
  }

I patched this in my code by changing line 474 to the following:

ids <- as.vector(unlist(lapply(ae[c(5:length(ae))],`[[`,1)))

But it would be good for this line of code to be robust enough to cover scenarios with and without record_id = argument in the link_ae_inpatient lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant