ConceptQL Crash Course
What is ConceptQL?
ConceptQL (pronounced concept-Q-L) is a high-level language that allows researchers to unambiguously define their research algorithms. ConceptQL is at the heart of the Jigsaw algorithm builder.
In this post, we’ll briefly introduce ConceptQL and give a couple of trivial examples on how it works. For much further detail, please see the ConceptQL Specification.
Motivation Behind ConceptQL
From its inception, ConceptQL was designed to be a simple, powerful language for representing search criteria to find specific information in healthcare data. Extracting information for research purposes is a tedious, opaque process, often requiring several skilled professionals to hand-write code in languages like SAS, R, or Stata. With a diversity of programming languages and programming styles, sharing algorithms becomes very challenging.
ConceptQL eliminates the need for hand-written code and increases the transparency of the criteria used to extract the relevant records from the data. ConceptQL uses a simple, high-level, declarative language to structure search criteria into statements. The ConceptQL interpreter then parses these statements and translates them into SQL that can be run directly against the data stored in a relational database management system (RDBMS) to extract events that match the selection criteria.
The language is rather simple. Here is the statement to find ICD-9-CM diagnoses of diabetes:
["icd9", "250.01"]
That’s it. (Note that there are actually many ICD-9-CM and ICD-10-CM codes to identify diabetes but we are using a single code for our example here.)
The ConceptQL translator would read this statement and produce this SQL query, designed to run against the Generalized Data Model (GDM):
SELECT *
FROM gdm_data.clinical_codes AS cc
WHERE cc.clinical_code_concept_id IN (
SELECT id
FROM concepts
WHERE vocabulary_id = 'ICD9CM'
AND concept_code = '250.01'
)
(As an aside, while we do our work using PostgreSQL and GDM, in theory, ConceptQL can generate SQL to run against different databases and even against different data models. But that is the subject of future development.)
Not only can the ConceptQL interpreter produce SQL queries, it produces visualizations of ConceptQL statements as well. For this post, we used ConceptQL’s built-in visualization tool which shows us the number of records (rows) and the number of individuals (n) that are passed through a particular operator in our synthetic test 250-person dataset. This is very useful for clarifying how the algorithm works. To illustrate this, below is a simple diagram of the above statement showing that there are 82 records from 45 people:
Composing ConceptQL
Operations in ConceptQL are designed to be composable, much the same as Unix pipes. Each ConceptQL operator is designed to ingest and produce the same set of structured results (i.e., there is a common table structure underlying each operation). This means any operator in ConceptQL can be applied to the output of any other operator. For example, the following ConceptQL statement:
["first", ["cpt", "99214"]]
looks like the following:
This yields the first office visit for each patient in the database. There are 1,073 records of an office visit from 175 individuals after the initial operation. Then the “first” operation is applied, and the data is refined to include only the first record for those 175 people. (Again, there are many codes for office visits and we are using a single code here for simplicity.)
There are many other operations in ConceptQL including operators for temporal operations (e.g., before, after, overlap), filtering (e.g., first, last, nth), and domain-specific operations (e.g., 1 inpatient or 2 outpatient).
Creating Algorithms with ConceptQL
Algorithms could be written by hand using ConceptQL. However, anything more than a simple algorithm might be challenging. Therefore, we created a visual editor for creating and editing algorithms. We discussed this in our previous post on Jigsaw’s two builders. And, in a future blog post and/or video, we plan to go into more detail on how it works.
Where to Learn More
This is a very brief introduction to ConceptQL. For more details on how it works and the features it has, please read the ConceptQL Specification.