MedRepository
Overview
MedRepository
and its extension MedPidRepository
are core classes in the InfraMed library, designed to facilitate reading, managing, and querying repository data. Familiarity with these classes is essential for effective use of the library.
MedRepository vs. MedPidRepository
MedPidRepository
builds on MedRepository
by providing APIs to load a complete patient record (PidRec
). This is particularly useful when iterating over patient IDs and needing all associated data for each one.
Initializing and Loading Data
There are several ways to initialize and load data into a MedRepository
:
-
Using
read_all()
Loads the repository configuration, a list of signal names (or all signals if the list is empty), and a list of patient IDs (or all if empty). The function loads the full cartesian product of requested pids and signals into memory, making the repository ready for queries. -
Using
init()
Initializes the repository with the configuration file, loading signals, dictionaries, and file locations, but not the actual data. Data can be loaded later usingload()
and released withfree()
. -
Using
load()
andfree()
load()
loads data for a specific signal and list of pids (or all if the list is empty).
free()
releases memory for a specific signal, which is useful for handling large datasets.
Example: Initializing and Loading a Repository
Accessing Data in MedRepository
Once data is loaded, you can access it using the get()
function (Old API), which returns a time-sorted vector of values for a specific pid and signal. The result is a void pointer that should be cast to the appropriate signal type.
Please use uget()
instead and get a generic signal of type UniversalSigVec
Example: Accessing Data
MedPidRepository: Initialization and Usage
MedPidRepository
enables loading data for individual pids into memory, which is useful for scanning large repositories with minimal memory usage. Each thread can hold data for a single patient, rather than all data at once.
To use MedPidRepository
, ensure the repository is transposed during its creation. After setup, use a PidRec
object to store data for a specific patient ID and access signals with either get()
or uget()
.
Example: Using MedPidRepository and PidRec
You can also initialize a PidRec
from an existing MedRepository
using init_from_rep()
. This copies the patient record and allows for dynamic modifications.
Example: Initializing PidRec from MedRepository
Performance Tips
- Store repositories locally (e.g.,
/home/Repositories
on Linux) for optimal speed. - When processing many patient IDs, use signal IDs instead of names for faster lookups:
- Load only the signals you need