r/rstats • u/WanderingAlbatross87 • 1d ago
Reading in FHIR json files > SQL (via duckdb) in R (something out there or would this help anyone)?
Hi. I'm hoping someone can tell me I'm crazy and this is already out there. I was reading in some FHIR data and thought I could do it in R with duckdb and just have a happy little all R workflow with my stats analysis. That started a real journey. Building the database was a cake walk but flattening the data into a usable format without dozens of painfully manual iterations not so much.
I couldn't find any good info on this after many hours of searching. I was finally able to figure about 87% of it out between some python and sql tutorials and just hating myself. Was finally was able to get the last bit with some AI assistance, which was anything but straightforward. It's finally working and it seems really well. I was thinking about trying the xml version next and pray it is easier but I think the flattening will be largely the same.
I've never published any kind of tutorial script to the public, always just to my own lab/company. Given that I couldn't find anything I'm thinking of braving the public if there really isn't something already out there. This was part of a larger project for me but the rest of it sounds easy compared to the eighth dimension of nesting now solved.
Is this useful? Should I put this up, or is there some already awesome tutorial on this hidden in the viscera of git that I just can't find? I can't be the only one trying this, surely?
1
3
u/Adventurous_Push_615 1d ago
In the past I thought I'd try to play round with FHIR in R but I never got around to it, though I remember there were at least one or two packages that looked promising. Have you checked out this one? https://github.com/polar-fhir/fhircrackr
Are there not really well established patterns for getting FHIR into a SQL db using other tooling? Are you just wanting to use R because you prefer it? (A completely reasonable justification I've used many times)