uwrit / leaf

Leaf Clinical Data Explorer
https://www.youtube.com/watch?v=ZuKKC7B8mHI
Other
88 stars 47 forks source link

Duplicate columns on Patient List export #558

Closed olayemiibrahim closed 1 year ago

olayemiibrahim commented 2 years ago

Hello everyone,

Is anyone else experiencing an issue with Leafs export? It looks like when we export patient information from the patient list tab all the columns are duplicated without their column headers.

Screen Shot 2022-08-31 at 2 26 17 PM

I had attempted to follow the export function in the dataExport.ts to see where the columns are being duplicated. It looks like the error would be in the getMultirowDatasetCSV function call on line 55, which leads to the patientListWebWorker.ts file. Going through the addMultiRowDataset function (assuming that is the correct one to look at) there doesn't seem to be any flaws in the logic.

Has anyone seen this issue and been able to fix it?

ndobb commented 2 years ago

Thanks for pointing this out, @olayemiibrahim .

TLDR;

The problem is in the duplicate for loop in the WebWorkerContext.ts file. This only happens when the user is exporting a dataset with a one-to-many relationship with patients (i.e., a patient can have more than one row of data).

Background

Basically, web workers are odd. Especially when using npm and webpack compilation and so on, things get wonky. You've probably noticed that everything under /ui-client/src/providers has both a *WebWorker.ts file and a *WebWorkerContext.ts file.

The *WebWorker.ts workerContext() function is written in TypeScript, but not actually used in the app.

Why? Well, writing it in TypeScript allows us to get type checking and helpful stuff like that. However due to oddities of how the browser initializes webworkers (specifically, you just send a big blob of code as a string), basically that won't work. This causes all sorts of headaches. I've seen quite a few workarounds in the past (and maybe there are better, more recent, solutions), but to my knowledge none really do a reliable job of making this easier.

Anyway, I've never felt that the way we do this with Leaf as ideal or the best solution (clearly, given this issue and possible others, it's not), but I convert the TypeScript workerContext() function into a big string, then plop that in the *WebWorkerContext.ts file. That's what is actually run in the webworker.

If you look at the line linked above, you can see that the for loop gets unnecessarily repeated, but only in the *WebWorkerContext.ts file. It must have been a copy/paste error or something I missed.

I'll make a fix for this of course, but in the meantime, if necessary, you can just manually cut out those 4 unnecessary lines of the for loop, then recompile and redeploy. That should fix it.

ndobb commented 1 year ago

Fixed in 3.11.3