Skip to main content

openEHR with SQL and graph traversal

· 2 min read
Borut Jures
Author of ArcEHR

I made some progress with SQL queries using graph traversal over openEHR data:

COMPOSITION.encounter.v1 has OBSERVATION.blood_pressure.v2

Since ArcEHR maps openEHR Reference Model (RM) to the graph database, we can use graph traversal to query the openEHR data. The data stored in the graph database is much more efficient than the relational database. No joins are needed to retrieve the data. We use out('has_openEHR-EHR-OBSERVATION.blood_pressure.v2') to get all the blood pressure records for a given COMPOSITION or EHR.

Simple SELECT with one archetype

Let's say we want to get the blood pressure data for a given encounter.

We can use the out() function to get all the blood pressure records for a given encounter. The out() function takes an edge type name as an argument. The out() function returns a list of all the records that have the specified edge type. The out() function can be used to traverse the graph database to get the data.

SQL Query

Result:

Result of the SQL Query

SELECT with multiple archetypes

Let's say we want to get the blood pressure and pulse data for a given encounter. We can use the out() function to get all the blood pressure and pulse records for a given encounter. We can use the CONTAINS operator to filter the records. The CONTAINS operator takes a sub-query as an argument. The CONTAINS operator returns a list of all the records that satisfy the sub-query.

Result:

SQL Query

Result:

Result of the SQL Query