# Upper level FHIR concepts

# Introduction

The purpose of this vignette is to explore relationships between concepts underlying FHIR foundational concepts and aspects of implementation in BiocFHIR.

This text uses R commands that will work for an R (version 4.2 or greater) in which BiocFHIR (version 0.0.14 or greater) has been installed. The source codes are always available at github and may be available for installation by other means.

# Some comments from hl7.org/fhir Executive Summary

The following are verbatim from the executive summary on Oct 5 2022. The FHIR system is said to provide

- A strong focus on implementation: fast and easy to implement (multiple developers have had simple interfaces working in a single day)
- Multiple implementation libraries, many examples available to kick-start development
- Specification is free for use with no restrictions
- Interoperability out-of-the-box: base resources can be used as is, but can also be adapted as needed - which happens a lot - for local requirements using Profiles, Extensions, Terminologies and more
- Evolutionary development path from HL7 Version 2 and CDA: standards can co-exist and leverage each other
- Strong foundation in Web standards: XML, JSON, HTTP, OAuth, etc.
- Support for RESTful architectures, seamless exchange of information using messages or documents, and service-based architectures
- Concise and easily understood specifications
- A human-readable serialization format for ease of use by developers
- Ontology-based analysis with formal mapping for correctness (under development)

End of quotation.

# FHIR JSON documents in BiocFHIR

The file located at `dir(system.file("json", package="BiocFHIR"), full=TRUE)` is a single JSON document produced in the Synthea project of the MITRE Corporation. It is an extract from a zip file provided at the Synthea web site. Usage notes include:

> ’Data hosted within SyntheticMass has been generated by SyntheaTM, an open-source patient population simulation made available by The MITRE Corporation.

> The data is free from cost, privacy, and security restrictions. It can be used without restriction for a variety of secondary uses in academia, research, industry, and government.

> Please cite SyntheaTM or SyntheticMass as:

> Jason Walonoski, Mark Kramer, Joseph Nichols, Andre Quina, Chris Moesel, Dylan Hall, Carlton Duffett, Kudakwashe Dube, Thomas Gallagher, Scott McLachlan, Synthea: An approach, method, and software mechanism for generating synthetic patients and the synthetic electronic health care record, Journal of the American Medical Informatics Association, Volume 25, Issue 3, March 2018, Pages 230–238, https://doi.org/10.1093/jamia/ocx079’“)

A collection of 50 documents, randomly sampled from over 1100 provides at Synthea, is available using the command `BiocFHIR::make_test_json_set()`; the documents will be written to a temporary folder.

# Examining sample data

    peek = jsonlite::fromJSON(dir(system.file("json", package="BiocFHIR"), full=TRUE))
    names(peek)

    ## [1] "resourceType" "type"         "entry"

    peek$resourceType

    ## [1] "Bundle"

    names(peek$entry)

    ## [1] "fullUrl"  "resource" "request"

    length(names(peek$entry$resource))

    ## [1] 72

    class(peek$entry$resource)

    ## [1] "data.frame"

    dim(peek$entry$resource)

    ## [1] 301  72

    head(names(peek$entry$resource))

    ## [1] "resourceType" "id"           "text"         "extension"    "identifier"
    ## [6] "name"

There are many concepts covered in `peek$entry$resource`, but in this document, most of them will have no content.

It is significant to note that the `resourceType` has value “Bundle”. The meaning of this term is provided at http://hl7.org/fhir/bundle.html.

Drilling down a bit further, we see that the 301 records collected in this Bundle have resource types indicative of a clinical focus.

    table(peek$entry$resource$resourceType)

    ##
    ##   AllergyIntolerance             CarePlan             CareTeam
    ##                    8                    3                    3
    ##                Claim            Condition     DiagnosticReport
    ##                   46                   15                    3
    ##            Encounter ExplanationOfBenefit         Immunization
    ##                   37                   37                   10
    ##    MedicationRequest          Observation         Organization
    ##                    9                  114                    3
    ##              Patient         Practitioner            Procedure
    ##                    1                    3                    9

More details on these types can be examined at http://hl7.org/fhir/clinicalsummary-module.html.

# Session information

    sessionInfo()

    ## R version 4.5.2 (2025-10-31)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.3 LTS
    ##
    ## Matrix products: default
    ## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    ##
    ## locale:
    ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C
    ##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    ##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    ##  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
    ##
    ## time zone: Etc/UTC
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] jsonlite_2.0.0   DT_0.34.0        BiocFHIR_1.12.0  BiocStyle_2.39.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] dplyr_1.1.4          compiler_4.5.2       BiocManager_1.30.26
    ##  [4] BiocBaseUtils_1.13.0 promises_1.5.0       tidyselect_1.2.1
    ##  [7] Rcpp_1.1.0           tidyr_1.3.1          later_1.4.4
    ## [10] jquerylib_0.1.4      yaml_2.3.10          fastmap_1.2.0
    ## [13] mime_0.13            R6_2.6.1             generics_0.1.4
    ## [16] knitr_1.50           htmlwidgets_1.6.4    visNetwork_2.1.4
    ## [19] BiocGenerics_0.57.0  graph_1.89.0         tibble_3.3.0
    ## [22] maketools_1.3.2      shiny_1.11.1         bslib_0.9.0
    ## [25] pillar_1.11.1        rlang_1.1.6          cachem_1.1.0
    ## [28] httpuv_1.6.16        xfun_0.54            sass_0.4.10
    ## [31] sys_3.4.3            otel_0.2.0           cli_3.6.5
    ## [34] magrittr_2.0.4       digest_0.6.37        xtable_1.8-4
    ## [37] lifecycle_1.0.4      vctrs_0.6.5          evaluate_1.0.5
    ## [40] glue_1.8.0           buildtools_1.0.0     stats4_4.5.2
    ## [43] purrr_1.2.0          rmarkdown_2.30       tools_4.5.2
    ## [46] pkgconfig_2.0.3      htmltools_0.5.8.1