Title: | Illustration of FHIR ingestion and transformation using R |
---|---|
Description: | FHIR R4 bundles in JSON format are derived from https://synthea.mitre.org/downloads. Transformation inspired by a kaggle notebook published by Dr Alexander Scarlat, https://www.kaggle.com/code/drscarlat/fhir-starter-parse-healthcare-bundles-into-tables. This is a very limited illustration of some basic parsing and reorganization processes. Additional tooling will be required to move beyond the Synthea data illustrations. |
Authors: | Vincent Carey [aut, cre] |
Maintainer: | Vincent Carey <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.9.0 |
Built: | 2024-11-29 03:53:44 UTC |
Source: | https://github.com/bioc/BiocFHIR |
update a fhir graph on patients and conditions with procedures
add_procedures(fhirgraph, listOfProcessedBundles)
add_procedures(fhirgraph, listOfProcessedBundles)
fhirgraph |
instance of BiocFHIR.FHIRgraph |
listOfProcessedBundles |
list |
instance of BiocFHIR.FHIRgraph
data("allin") g <- make_condition_graph(allin) g <- add_procedures(g, allin) g
data("allin") g <- make_condition_graph(allin) g <- add_procedures(g, allin) g
collection of synthea FHIR documents ingested
data("allin", package = "BiocFHIR")
data("allin", package = "BiocFHIR")
list
data("allin", package="BiocFHIR") allin[[1]]
data("allin", package="BiocFHIR") allin[[1]]
list available 'retention schemas'
available_retention_schemas()
available_retention_schemas()
character vector
available_retention_schemas()
available_retention_schemas()
build graph with patients, conditions and procedures
build_proccond_igraph(listOfBundles)
build_proccond_igraph(listOfBundles)
listOfBundles |
list of processed FHIR bundles, processed with 'process_fhir_bundle' |
instance of visIgraph from visNetworks
data("allin") build_proccond_igraph( allin )
data("allin") build_proccond_igraph( allin )
make network visualization
display_proccond_igraph(igraph)
display_proccond_igraph(igraph)
igraph |
instance of igraph produced by 'build_procond_igraph' |
visIGraph instance
data("allin") g <- build_proccond_igraph( allin ) if (interactive()) { display_proccond_igraph( g ) }
data("allin") g <- build_proccond_igraph( allin ) if (interactive()) { display_proccond_igraph( g ) }
FHIR Resource types recognized in package
FHIR_ResourceTypes()
FHIR_ResourceTypes()
vector of strings
FHIR_ResourceTypes() # Oct 2022
FHIR_ResourceTypes() # Oct 2022
collection of FHIR Resource components to be retained
FHIR_retention_schemas()
FHIR_retention_schemas()
list of vectors of strings
FHIR_retention_schemas() # Oct 2022
FHIR_retention_schemas() # Oct 2022
table app
FHIRtabs()
FHIRtabs()
No value returned.
if (interactive()) { FHIRtabs() }
if (interactive()) { FHIRtabs() }
produce interactive tables with FHIR resources from a list of ingested bundles
freq_app(blist)
freq_app(blist)
blist |
list of ingested bundles |
side-effects of shiny app invocation
if (interactive()) { tset = make_test_json_set() bl = lapply(tset, process_fhir_bundle) freq_app(bl) }
if (interactive()) { tset = make_test_json_set() bl = lapply(tset, process_fhir_bundle) freq_app(bl) }
get human name from a BiocFHIR.Patient instance
getHumanName(Patient)
getHumanName(Patient)
Patient |
BiocFHIR.Patient instance |
string with name components concatenated
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) getHumanName(tbun$Patient)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) getHumanName(tbun$Patient)
create graph with links from patients to conditions
make_condition_graph(listOfProcessedBundles, keep_with_condition_only = TRUE)
make_condition_graph(listOfProcessedBundles, keep_with_condition_only = TRUE)
listOfProcessedBundles |
list with elements generated by 'process_fhir_bundle' |
keep_with_condition_only |
logical(1) omit bundles that lack a "Condition" element, defaults to TRUE |
instance of BiocFHIR.FHIRgraph
data("allin") make_condition_graph(allin, TRUE)
data("allin") make_condition_graph(allin, TRUE)
produce 50 json FHIR files in a folder
make_test_json_set(target = paste0(tempdir(), "/jsontest"), reuse = TRUE)
make_test_json_set(target = paste0(tempdir(), "/jsontest"), reuse = TRUE)
target |
character(1) a path, defaults to 'jsontest' under 'tempdir()'; the contents of synthfhir.zip, in inst/zip of BiocFHIR, will be deposted there. |
reuse |
logical(1) if TRUE, just use what is there, if folder already exists |
a vector of paths to FHIR JSON, invisibly
z <- make_test_json_set() z[1:3]
z <- make_test_json_set() z[1:3]
show a combination of graph and patient attributes
## S3 method for class 'BiocFHIR.FHIRgraph' print(x, ...)
## S3 method for class 'BiocFHIR.FHIRgraph' print(x, ...)
x |
instance of BiocFHIR.FHIRgraph |
... |
not used |
print method
data("allin") make_condition_graph(allin)
data("allin") make_condition_graph(allin)
print method
## S3 method for class 'FHIR.bundle' print(x, ...)
## S3 method for class 'FHIR.bundle' print(x, ...)
x |
BiocFHIR FHIR.bundle instance |
... |
not used |
print method
extract information from retained fields in AllergyIntolerance component of FHIR Bundle, produce simple data.frame
process_AllergyIntolerance(AllergyIntolerance)
process_AllergyIntolerance(AllergyIntolerance)
AllergyIntolerance |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_AllergyIntolerance(tbun$AllergyIntolerance)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_AllergyIntolerance(tbun$AllergyIntolerance)
extract information from retained fields in CarePlan component of FHIR Bundle, produce simple data.frame
process_CarePlan(CarePlan)
process_CarePlan(CarePlan)
CarePlan |
component of FHIR.bundle instance |
data.frame
Nov 13 2022, added code to refine the 'category' data processing.
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_CarePlan(tbun$CarePlan)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_CarePlan(tbun$CarePlan)
extract information from retained fields in Claim component of FHIR Bundle, produce simple data.frame
process_Claim(Claim)
process_Claim(Claim)
Claim |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Claim(tbun$Claim)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Claim(tbun$Claim)
extract information from retained fields in Condition component of FHIR Bundle, produce simple data.frame
process_Condition(Condition)
process_Condition(Condition)
Condition |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Condition(tbun$Condition)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Condition(tbun$Condition)
extract information from retained fields in Encounter component of FHIR Bundle, produce simple data.frame
process_Encounter(Encounter)
process_Encounter(Encounter)
Encounter |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Encounter(tbun$Encounter)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Encounter(tbun$Encounter)
process a bundle of FHIR R4 JSON
process_fhir_bundle(json_file, schemas = FHIR_retention_schemas())
process_fhir_bundle(json_file, schemas = FHIR_retention_schemas())
json_file |
character(1) path to text in JSON format |
schemas |
list of character vectors defining expected fields, defaults to FHIR_retention_schemas() |
instance of FHIR.bundle, extending list
If one encounters the error "Element ... lacks field", the schemas argument can be modified by removing the noted field from the schema.
testf = system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun = process_fhir_bundle(testf) tbun
testf = system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun = process_fhir_bundle(testf) tbun
extract information from retained fields in Immunization component of FHIR Bundle, produce simple data.frame
process_Immunization(Immunization)
process_Immunization(Immunization)
Immunization |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Immunization(tbun$Immunization)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Immunization(tbun$Immunization)
extract information from retained fields in MedicationRequest component of FHIR Bundle, produce simple data.frame
process_MedicationRequest(MedicationRequest)
process_MedicationRequest(MedicationRequest)
MedicationRequest |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_MedicationRequest(tbun$MedicationRequest)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_MedicationRequest(tbun$MedicationRequest)
extract information from retained fields in Observation component of FHIR Bundle, produce simple data.frame
process_Observation(Observation)
process_Observation(Observation)
Observation |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Observation(tbun$Observation)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Observation(tbun$Observation)
flatten information in Patient component of a bundle to a one-line data.frame
process_Patient(Patient)
process_Patient(Patient)
Patient |
element of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) tpat <- process_Patient(tbun$Patient) head(names(tpat)) tags <- c("identifier.system3", "identifier.value3") tpat[tags,,FALSE] tags2 <- grep("extension.extension", rownames(tpat), value=TRUE) tpat[tags2,,FALSE]
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) tpat <- process_Patient(tbun$Patient) head(names(tpat)) tags <- c("identifier.system3", "identifier.value3") tpat[tags,,FALSE] tags2 <- grep("extension.extension", rownames(tpat), value=TRUE) tpat[tags2,,FALSE]
extract information from retained fields in Procedure component of FHIR Bundle, produce simple data.frame
process_Procedure(Procedure)
process_Procedure(Procedure)
Procedure |
component of FHIR.bundle instance |
data.frame
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Procedure(tbun$Procedure)
testf <- system.file("json/Vince741_Rogahn59_6fa3d4ab-c0b6-424a-89d8-7d9105129296.json", package="BiocFHIR") tbun <- process_fhir_bundle(testf) process_Procedure(tbun$Procedure)
convert data of a given FHIR type in a list of bundles to a data.frame
stack_fhir(blist, type, droperr = TRUE)
stack_fhir(blist, type, droperr = TRUE)
blist |
list of FHIR bundles imported with process_fhir_bundle |
type |
character(1) type, in names(blist[[1]]), e.g. |
droperr |
logical(1) exclude records for which process_[type] fails, defaults to TRUE |
data.frame
jj = make_test_json_set() b2 = lapply(jj[1:2], process_fhir_bundle) ss = stack_fhir(b2, "Procedure") head(ss,2)
jj = make_test_json_set() b2 = lapply(jj[1:2], process_fhir_bundle) ss = stack_fhir(b2, "Procedure") head(ss,2)
produce tables summarizing FHIR data
summarise_bundles( blist, resource = "Condition", selection_map = summary_selections() )
summarise_bundles( blist, resource = "Condition", selection_map = summary_selections() )
blist |
list of ingested bundles |
resource |
character(1) FHIR resource name |
selection_map |
character() named vector of single strings selected for summarisation |
data.frame
vector of fields to be selected for summarization
summary_selections()
summary_selections()
named vector of strings