vignettes/ramses-objects.Rmd
ramses-objects.Rmd
This article introduces the way Ramses
handles entities
such as patients, prescriptions, or therapy episodes. Each of these
entities is associated with specific data analysis operations, and is
represented in their own type of records in the backend database.
To ensure users can access the relevant records and perform the
desired analytical operations, Ramses
employs a object
model that consists of S4 classes representing each of these
entities, and giving access to relevant functions or methods.
More information on, objects, classes, and methods in R
is available from the Object-oriented programming
section by Wickham (2019).
Ramses
objects are S4 classes. They all conform to the
RamsesObject
virtual class specification:
id
slot corresponding to a primary key
in the database backendconn
slot corresponding to the database
backend connection, currently either of duckdb_connection
or PqConnection
class (see database objects)compute()
in order to compute the
corresponding database records (faster to retrieve)collect()
in order to retrieve
the corresponding database records (returns a tbl_df
object)Patient()
in order to retrieve
the corresponding patient entity (returns a Patient
object).MedicationRequest
objects, which represent a single
drug-dose order, which may or may not participate in combination therapy
(2 or more drugs). MedicationRequest
objects are associated
with one episode of antimicrobial therapy (represented by
TherapyEpisode
objects). It is possible to retrieve the
TherapyEpisode
entity from any
MedicationRequest
object x
by passing it to
the TherapyEpisode()
function.
Ramses
uses other objects for backend database
connections and tables. They follow the dbplyr
architecture:
DBIConnection
.
Currently, duckdb_connection
(package duckdb) and
PqConnection
(package RPostgres) are supportedtbl()
function and
are represented by tbl_sql
objects which, although they
inherit from the tbl
class, are distinct from the common
tbl_df
tibble class.